diff --git a/gradle.properties b/gradle.properties index 83e6179d..6038217a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=reliquary mod_group_id=reliquary -mod_version=2.0.42 +mod_version=2.0.43 sonar_project_key=xreliquary:Reliquary github_package_url=https://maven.pkg.github.com/P3pp3rF1y/Reliquary diff --git a/src/main/java/reliquary/crafting/AlkahestryCraftingRecipe.java b/src/main/java/reliquary/crafting/AlkahestryCraftingRecipe.java index 3710f9a2..74ffdfee 100644 --- a/src/main/java/reliquary/crafting/AlkahestryCraftingRecipe.java +++ b/src/main/java/reliquary/crafting/AlkahestryCraftingRecipe.java @@ -17,9 +17,9 @@ import net.minecraftforge.common.crafting.CraftingHelper; import reliquary.init.ModItems; import reliquary.items.AlkahestryTomeItem; -import reliquary.reference.Settings; import javax.annotation.Nullable; +import java.util.stream.Stream; public class AlkahestryCraftingRecipe implements CraftingRecipe { private final Ingredient craftingIngredient; @@ -33,7 +33,7 @@ private AlkahestryCraftingRecipe(ResourceLocation id, Ingredient craftingIngredi this.id = id; this.craftingIngredient = craftingIngredient; this.chargeNeeded = chargeNeeded; - tomeIngredient = Ingredient.of(AlkahestryTomeItem.setCharge(new ItemStack(ModItems.ALKAHESTRY_TOME.get()), Settings.COMMON.items.alkahestryTome.chargeLimit.get())); + tomeIngredient = new TomeIngredient(chargeNeeded); this.resultCount = resultCount; AlkahestryRecipeRegistry.registerCraftingRecipe(this); @@ -51,7 +51,7 @@ public boolean matches(CraftingContainer inv, Level worldIn) { if (craftingIngredient.test(slotStack)) { inRecipe = true; hasIngredient = true; - } else if (!hasTome && slotStack.getItem() == ModItems.ALKAHESTRY_TOME.get() && AlkahestryTomeItem.getCharge(slotStack) >= chargeNeeded) { + } else if (!hasTome && tomeIngredient.test(slotStack)) { inRecipe = true; hasTome = true; } @@ -182,4 +182,18 @@ public void toNetwork(FriendlyByteBuf buffer, AlkahestryCraftingRecipe recipe) { buffer.writeInt(recipe.resultCount); } } + + private static class TomeIngredient extends Ingredient { + private final int chargeNeeded; + + private TomeIngredient(int chargeNeeded) { + super(Stream.of(new Ingredient.ItemValue(AlkahestryTomeItem.setCharge(new ItemStack(ModItems.ALKAHESTRY_TOME.get()), chargeNeeded)))); + this.chargeNeeded = chargeNeeded; + } + + @Override + public boolean test(@Nullable ItemStack stack) { + return stack != null && stack.is(ModItems.ALKAHESTRY_TOME.get()) && AlkahestryTomeItem.getCharge(stack) >= chargeNeeded; + } + } }