Skip to content

Commit

Permalink
fix: 🐛 Fixed tome crafting recipe so that the tome ingredient itself …
Browse files Browse the repository at this point in the history
…checks the charge required. Fixes dupe issue with create's mixer
  • Loading branch information
P3pp3rF1y committed Oct 1, 2024
1 parent 5735229 commit b398e67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions src/main/java/reliquary/crafting/AlkahestryCraftingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit b398e67

Please sign in to comment.