From a2993b467c44ba12ce307948fe09720eabdac5fa Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Tue, 1 Oct 2024 22:26:26 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20tome=20charging?= =?UTF-8?q?=20recipe=20to=20properly=20check=20that=20tome=20doesn't=20get?= =?UTF-8?q?=20overcharged=20when=20using=20multiple=20charging=20ingredien?= =?UTF-8?q?ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../crafting/AlkahestryChargingRecipe.java | 34 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6038217a..b2456861 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.43 +mod_version=2.0.44 sonar_project_key=xreliquary:Reliquary github_package_url=https://maven.pkg.github.com/P3pp3rF1y/Reliquary diff --git a/src/main/java/reliquary/crafting/AlkahestryChargingRecipe.java b/src/main/java/reliquary/crafting/AlkahestryChargingRecipe.java index 47cbce70..d170f256 100644 --- a/src/main/java/reliquary/crafting/AlkahestryChargingRecipe.java +++ b/src/main/java/reliquary/crafting/AlkahestryChargingRecipe.java @@ -19,6 +19,7 @@ import reliquary.items.AlkahestryTomeItem; import javax.annotation.Nullable; +import java.util.stream.Stream; public class AlkahestryChargingRecipe implements CraftingRecipe { private final Ingredient chargingIngredient; @@ -31,7 +32,7 @@ private AlkahestryChargingRecipe(ResourceLocation id, Ingredient chargingIngredi this.id = id; this.chargingIngredient = chargingIngredient; this.chargeToAdd = chargeToAdd; - tomeIngredient = Ingredient.of(AlkahestryTomeItem.setCharge(new ItemStack(ModItems.ALKAHESTRY_TOME.get()), 0)); + tomeIngredient = new TomeIngredient(chargeToAdd); recipeOutput = new ItemStack(ModItems.ALKAHESTRY_TOME.get()); AlkahestryTomeItem.addCharge(recipeOutput, chargeToAdd); @@ -41,8 +42,8 @@ private AlkahestryChargingRecipe(ResourceLocation id, Ingredient chargingIngredi @Override public boolean matches(CraftingContainer inv, Level worldIn) { - boolean hasTome = false; - boolean hasIngredient = false; + ItemStack tome = ItemStack.EMPTY; + int numberOfIngredients = 0; for (int x = 0; x < inv.getContainerSize(); x++) { ItemStack slotStack = inv.getItem(x); @@ -51,10 +52,10 @@ public boolean matches(CraftingContainer inv, Level worldIn) { boolean inRecipe = false; if (chargingIngredient.test(slotStack)) { inRecipe = true; - hasIngredient = true; - } else if (!hasTome && slotStack.getItem() == ModItems.ALKAHESTRY_TOME.get() && AlkahestryTomeItem.getCharge(slotStack) + chargeToAdd <= AlkahestryTomeItem.getChargeLimit()) { + numberOfIngredients++; + } else if (tome.isEmpty()) { inRecipe = true; - hasTome = true; + tome = slotStack; } if (!inRecipe) { @@ -63,7 +64,7 @@ public boolean matches(CraftingContainer inv, Level worldIn) { } } - return hasIngredient && hasTome; + return numberOfIngredients > 0 && tome.is(ModItems.ALKAHESTRY_TOME.get()) && AlkahestryTomeItem.getCharge(tome) + chargeToAdd * numberOfIngredients <= AlkahestryTomeItem.getChargeLimit(); } @Override @@ -157,4 +158,23 @@ public void toNetwork(FriendlyByteBuf buffer, AlkahestryChargingRecipe recipe) { buffer.writeInt(recipe.chargeToAdd); } } + + private static class TomeIngredient extends Ingredient { + private final int chargeToAdd; + + private TomeIngredient(int chargeToAdd) { + super(Stream.of(new Ingredient.ItemValue(new ItemStack(ModItems.ALKAHESTRY_TOME.get())))); + this.chargeToAdd = chargeToAdd; + } + + @Override + public boolean test(ItemStack stack) { + return stack.is(ModItems.ALKAHESTRY_TOME.get()) && AlkahestryTomeItem.getCharge(stack) + chargeToAdd <= AlkahestryTomeItem.getChargeLimit(); + } + + @Override + public boolean isSimple() { + return false; + } + } }