diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index a8328d55..2d1ee89f 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -84,15 +84,6 @@ public final class Helper { return ((a & 255) << 24) | ((r & 255) << 16) | ((g & 255) << 8) | (b & 255); } - public static int getItemIndex(List list, ItemStack item, boolean nbt) { - for (int i = 0; i < list.size(); i++) { - if (areItemsEqual(list.get(i), item, nbt)) { - return i; - } - } - return -1; - } - public static boolean areItemsEqual(ItemStack first, ItemStack second, boolean nbt) { if (!ItemStack.areItemsEqual(first, second)) return false; diff --git a/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java b/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java index 13c0aecb..0b41e6cf 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java +++ b/src/main/java/de/ellpeck/naturesaura/api/recipes/AltarRecipe.java @@ -23,7 +23,11 @@ public class AltarRecipe { this.time = time; } - public AltarRecipe register(){ + public boolean matches(ItemStack found) { + return ItemStack.areItemsEqual(this.input, found) && ItemStack.areItemStackShareTagsEqual(this.input, found); + } + + public AltarRecipe register() { NaturesAuraAPI.ALTAR_RECIPES.put(this.name, this); return this; } diff --git a/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java b/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java index 492fb5c7..1f7690f8 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java +++ b/src/main/java/de/ellpeck/naturesaura/api/recipes/TreeRitualRecipe.java @@ -20,6 +20,10 @@ public class TreeRitualRecipe { this.time = time; } + public boolean matches(ItemStack expected, ItemStack found) { + return ItemStack.areItemsEqual(expected, found) && ItemStack.areItemStackShareTagsEqual(expected, found); + } + public TreeRitualRecipe register() { NaturesAuraAPI.TREE_RITUAL_RECIPES.put(this.name, this); return this; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java index 0b6d0477..87a2407b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockWoodStand.java @@ -60,16 +60,18 @@ public class BlockWoodStand extends BlockContainerImpl { TileEntityWoodStand stand = (TileEntityWoodStand) tile; ItemStack stack = stand.items.getStackInSlot(0); if (!stack.isEmpty()) { - int index = Helper.getItemIndex(required, stack, true); - if (index >= 0) { - required.remove(index); + for (int i = required.size() - 1; i >= 0; i--) { + ItemStack req = required.get(i); + if (recipe.matches(req, stack)) { + required.remove(i); - if (toPick.getValue() == null) { - toPick.setValue(stand); + if (toPick.getValue() == null) { + toPick.setValue(stand); + } + return true; } - } else { - return false; } + return false; } } return true; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index 2b855535..8379273e 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -1,6 +1,5 @@ package de.ellpeck.naturesaura.blocks.tiles; -import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; import de.ellpeck.naturesaura.api.aura.container.BasicAuraContainer; @@ -116,7 +115,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable { this.currentRecipe = getRecipeForInput(stack); } } else { - if (stack.isEmpty() || !Helper.areItemsEqual(stack, this.currentRecipe.input, true)) { + if (stack.isEmpty() || !this.currentRecipe.matches(stack)) { this.currentRecipe = null; this.timer = 0; } else if (this.hasCatalyst(this.currentRecipe.catalyst)) { @@ -181,7 +180,7 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickable { private static AltarRecipe getRecipeForInput(ItemStack input) { for (AltarRecipe recipe : NaturesAuraAPI.ALTAR_RECIPES.values()) { - if (Helper.areItemsEqual(recipe.input, input, true)) { + if (recipe.matches(input)) { return recipe; } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java index b7378c22..7d764320 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java @@ -1,12 +1,11 @@ package de.ellpeck.naturesaura.blocks.tiles; -import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; import de.ellpeck.naturesaura.blocks.multi.Multiblocks; import de.ellpeck.naturesaura.packet.PacketHandler; import de.ellpeck.naturesaura.packet.PacketParticleStream; import de.ellpeck.naturesaura.packet.PacketParticles; -import de.ellpeck.naturesaura.api.recipes.TreeRitualRecipe; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockLog; import net.minecraft.block.state.IBlockState; @@ -152,12 +151,14 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickable { if (tile instanceof TileEntityWoodStand) { ItemStack stack = ((TileEntityWoodStand) tile).items.getStackInSlot(0); if (!stack.isEmpty()) { - int index = Helper.getItemIndex(required, stack, true); - if (index >= 0) { - required.remove(index); - } else { - return false; + for (int i = required.size() - 1; i >= 0; i--) { + ItemStack req = required.get(i); + if (this.recipe.matches(req, stack)) { + required.remove(i); + return true; + } } + return false; } } return true;