From 272075dd51f5022376a23ca41db7b478ede0f527 Mon Sep 17 00:00:00 2001 From: Hubry Date: Tue, 28 Aug 2018 04:30:47 +0800 Subject: [PATCH] Fix Alfheim portal storing items not used in recipes (VazkiiMods/Botania#2721) * Fix VazkiiMods/Botania#2403 (Alfheim portal storing items not used in recipes) Possibly mitigates VazkiiMods/Botania#2669, as recipe checks are a bit simplified to not create stack copies posting capability events and the portal will not check items with no uses more than once. * Don't teleport bread, Bord. --- .../botania/api/recipe/RecipeElvenTrade.java | 6 +--- .../common/block/tile/TileAlfPortal.java | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java b/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java index dbea13e86..312b65cc5 100644 --- a/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java +++ b/src/main/java/vazkii/botania/api/recipe/RecipeElvenTrade.java @@ -43,11 +43,7 @@ public class RecipeElvenTrade { List validStacks = OreDictionary.getOres((String) input); boolean found = false; for(ItemStack ostack : validStacks) { - ItemStack cstack = ostack.copy(); - if(cstack.getItemDamage() == Short.MAX_VALUE) - cstack.setItemDamage(stack.getItemDamage()); - - if(stack.isItemEqual(cstack)) { + if(OreDictionary.itemMatches(ostack, stack, false)) { if(!stacksToRemove.contains(stack)) stacksToRemove.add(stack); oredictIndex = j; diff --git a/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java b/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java index d3d475ee7..fc4356903 100644 --- a/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java +++ b/src/main/java/vazkii/botania/common/block/tile/TileAlfPortal.java @@ -16,11 +16,13 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.oredict.OreDictionary; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.lexicon.ILexicon; import vazkii.botania.api.lexicon.multiblock.Multiblock; @@ -71,6 +73,7 @@ public class TileAlfPortal extends TileMod { int ticksSinceLastItem = 0; private boolean closeNow = false; private boolean hasUnloadedParts = false; + private boolean explode = false; private static final Function CONVERTER_X_Z = new Function() { @Override @@ -142,7 +145,9 @@ public class TileAlfPortal extends TileMod { ItemStack stack = item.getEntityItem(); if(stack != null && (!(stack.getItem() instanceof IElvenItem) || !((IElvenItem) stack.getItem()).isElvenItem(stack)) && !item.getEntityData().hasKey(TAG_PORTAL_FLAG)) { item.setDead(); - addItem(stack); + if (validateItemUsage(stack)) { + addItem(stack); + } ticksSinceLastItem = 0; } } @@ -164,11 +169,35 @@ public class TileAlfPortal extends TileMod { for(int i = 0; i < 36; i++) blockParticle(meta); worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2); + } else if(explode) { + worldObj.createExplosion(null, xCoord + .5, yCoord + 2.0, zCoord + .5, 3f, true); + explode = false; } hasUnloadedParts = false; } + private boolean validateItemUsage(ItemStack inputStack) { + for(RecipeElvenTrade recipe : BotaniaAPI.elvenTradeRecipes) { + for(Object o : recipe.getInputs()) { + if(o instanceof String) { + for(ItemStack target : OreDictionary.getOres((String) o)) { + if(OreDictionary.itemMatches(target, inputStack, false)) + return true; + } + } else if(o instanceof ItemStack) { + ItemStack target = (ItemStack) o; + if(inputStack.getItem() == target.getItem() && inputStack.getItemDamage() == target.getItemDamage()) + return true; + } + } + } + if(inputStack.getItem() == Items.bread) //Don't teleport bread. (See also: #2403) + explode = true; + + return false; + } + private void blockParticle(int meta) { int i = worldObj.rand.nextInt(AIR_POSITIONS.length); double[] pos = new double[] {