-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use AlmostUnified preferred stack for miner recipes, if mod loaded
Note: On 1.19.3. this is not yet possible due to AU not being updated yet
- Loading branch information
1 parent
1927087
commit 322ed0d
Showing
10 changed files
with
105 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/github/klikli_dev/occultism/common/misc/OutputIngredient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.klikli_dev.occultism.common.misc; | ||
|
||
import com.github.klikli_dev.occultism.integration.almostunified.AlmostUnifiedIntegration; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.crafting.Ingredient; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* A class that makes it easier to use ingredients as output and handles AlmostUnified Integration | ||
*/ | ||
public class OutputIngredient { | ||
|
||
protected Ingredient ingredient; | ||
protected ItemStack[] itemStacks; | ||
|
||
public OutputIngredient(Ingredient ingredient) { | ||
this.ingredient = ingredient; | ||
} | ||
|
||
public ItemStack getStack() { | ||
//copied from Ingredient.dissolve, but modified to handle tag ingredient preferred items | ||
if (this.itemStacks == null) { | ||
this.itemStacks = Arrays.stream(this.ingredient.values).flatMap((value) -> { | ||
if (value instanceof Ingredient.TagValue tagValue) { | ||
if (AlmostUnifiedIntegration.isLoaded()) { | ||
return Stream.of(AlmostUnifiedIntegration.getPreferredItemForTag(tagValue.tag)); | ||
} | ||
} | ||
return value.getItems().stream(); | ||
}).distinct().toArray(ItemStack[]::new); | ||
} | ||
return this.itemStacks[0]; | ||
} | ||
|
||
public Ingredient getIngredient() { | ||
return this.ingredient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...a/com/github/klikli_dev/occultism/integration/almostunified/AlmostUnifiedIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.github.klikli_dev.occultism.integration.almostunified; | ||
|
||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.fml.ModList; | ||
|
||
public class AlmostUnifiedIntegration { | ||
public static boolean isLoaded() { | ||
return ModList.get().isLoaded("almostunified"); | ||
} | ||
|
||
public static ItemStack getPreferredItemForTag(TagKey<Item> tag) { | ||
//TODO: enable once almostunified is updated | ||
// if (isLoaded()) { | ||
// return AlmostUnifiedHelper.getPreferredItemForTag(tag); | ||
// } | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
public static class AlmostUnifiedHelper { | ||
public static ItemStack getPreferredItemForTag(TagKey<Item> tag) { | ||
// var asUnifyTag = UnifyTag.item(tag.location()); | ||
// var item = AlmostUnified | ||
// .getRuntime() | ||
// .getReplacementMap() | ||
// .getPreferredItemForTag(asUnifyTag, $ -> true); | ||
// if(item == null){ | ||
// return new Ingredient.TagValue(tag).getItems().stream().findFirst().get(); | ||
// } | ||
// | ||
// return new ItemStack(ForgeRegistries.ITEMS.getValue(item)); | ||
throw new UnsupportedOperationException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters