Skip to content

Commit

Permalink
Fix Alfheim portal storing items not used in recipes (VazkiiMods#2721)
Browse files Browse the repository at this point in the history
* Fix VazkiiMods#2403 (Alfheim portal storing items not used in recipes)

Possibly mitigates VazkiiMods#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.
  • Loading branch information
Hubry authored and Glease committed Nov 4, 2023
1 parent 56bd186 commit 272075d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public boolean matches(List<ItemStack> stacks, boolean remove) {
List<ItemStack> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
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;
Expand Down Expand Up @@ -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<int[], int[]> CONVERTER_X_Z = new Function<int[], int[]>() {
@Override
Expand Down Expand Up @@ -142,7 +145,9 @@ public void updateEntity() {
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;
}
}
Expand All @@ -164,11 +169,35 @@ public void updateEntity() {
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[] {
Expand Down

0 comments on commit 272075d

Please sign in to comment.