From e6a35a6a726fd0970077f259f168f61f263319e1 Mon Sep 17 00:00:00 2001 From: Robert Seifert Date: Wed, 15 May 2013 22:10:56 -0400 Subject: [PATCH] Disabled Hopper interaction due to bugs I can't explain what is going on between the crate and hopper. As far as i can see the crate works fine with pipes, and other things. However the hopper creates new bugs that i can't solve at the moment. It will keep trying to input items into the crate after the crate is full. It will then after world load trash a crates inv that its pulling from. Since i believe that the hopper is the root cause i'm going to just disable it use with crates. --- .../assemblyline/common/block/BlockCrate.java | 2 +- .../common/block/ItemBlockCrate.java | 2 +- .../common/block/TileEntityCrate.java | 71 +++++++++++-------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/minecraft/assemblyline/common/block/BlockCrate.java b/src/minecraft/assemblyline/common/block/BlockCrate.java index 9c56ddb55..79e642792 100644 --- a/src/minecraft/assemblyline/common/block/BlockCrate.java +++ b/src/minecraft/assemblyline/common/block/BlockCrate.java @@ -389,7 +389,7 @@ public class BlockCrate extends BlockALMachine { TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z); ItemStack containingStack = tileEntity.getSampleStack(); - tileEntity.buildSampleStack(); + tileEntity.buildSampleStack(false); if (containingStack != null) { diff --git a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java b/src/minecraft/assemblyline/common/block/ItemBlockCrate.java index aa628c3c5..236f8283c 100644 --- a/src/minecraft/assemblyline/common/block/ItemBlockCrate.java +++ b/src/minecraft/assemblyline/common/block/ItemBlockCrate.java @@ -131,7 +131,7 @@ public class ItemBlockCrate extends ItemBlock } } - tileEntity.buildSampleStack(); + tileEntity.buildSampleStack(false); } } } diff --git a/src/minecraft/assemblyline/common/block/TileEntityCrate.java b/src/minecraft/assemblyline/common/block/TileEntityCrate.java index 504d97b8c..7b111cd66 100644 --- a/src/minecraft/assemblyline/common/block/TileEntityCrate.java +++ b/src/minecraft/assemblyline/common/block/TileEntityCrate.java @@ -9,6 +9,11 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityHopper; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; import universalelectricity.prefab.implement.ITier; import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.PacketManager; @@ -31,7 +36,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven public long prevClickTime = -1000; - public void buildSampleStack() + public void buildSampleStack(boolean force) { int count = 0; int id = 0; @@ -41,15 +46,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven /* Similar to Init but checks so often just in case something does break */ if (worldObj != null) { - if (slots == null || slots != null && slots.length != this.getSlotCount()) - { - slots = new int[this.getSlotCount()]; - for (int i = 0; i < slots.length; i++) - { - slots[i] = i; - } - } - if (this.items != null && this.items.length != this.getSlotCount()) + if (this.items != null && this.items.length > this.getSlotCount()) { ItemStack[] itemSet = this.items.clone(); this.items = new ItemStack[this.getSlotCount()]; @@ -89,9 +86,9 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven this.sampleStack = new ItemStack(id, count, meta); } /* if one stack is over sized this rebuilds the inv to redistribute the items in the slots */ - if (rebuildBase && this.getSampleStack() != null) + if ((rebuildBase || force) && this.sampleStack != null) { - ItemStack baseStack = this.getSampleStack().copy(); + ItemStack baseStack = this.sampleStack.copy(); this.items = new ItemStack[this.getSlotCount()]; for (int slot = 0; slot < this.items.length; slot++) { @@ -111,7 +108,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven { if (this.sampleStack == null) { - this.buildSampleStack(); + this.buildSampleStack(false); } return this.sampleStack; } @@ -176,7 +173,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven @Override public Packet getDescriptionPacket() { - this.buildSampleStack(); + this.buildSampleStack(false); ItemStack stack = this.getSampleStack(); if (stack != null) { @@ -235,7 +232,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven { if (this.items[slot] != null) { - ItemStack var2 = this.items[slot]; + ItemStack var2 = this.items[slot].copy(); this.items[slot] = null; return var2; } @@ -248,20 +245,13 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven @Override public void setInventorySlotContents(int slot, ItemStack stack) { - if (stack != null) - { - this.items[slot] = stack; + this.items[slot] = stack; - if (stack.stackSize > this.getInventoryStackLimit()) - { - stack.stackSize = this.getInventoryStackLimit(); - } - } - else + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { - this.items[slot] = null; + stack.stackSize = this.getInventoryStackLimit(); } - + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { PacketManager.sendPacketToClients(this.getDescriptionPacket(), this.worldObj); @@ -328,7 +318,7 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - this.buildSampleStack(); + this.buildSampleStack(false); ItemStack stack = this.getSampleStack(); if (stack != null) { @@ -381,11 +371,11 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven @Override public boolean isStackValidForSlot(int slot, ItemStack itemstack) { - if (this.sampleStack == null) + if(slot >= this.getSlotCount()) { - return true; + return false; } - else if (itemstack != null && itemstack.equals(this.sampleStack)) + if (this.sampleStack == null || itemstack != null && itemstack.isItemEqual(this.sampleStack)) { return true; } @@ -395,18 +385,39 @@ public class TileEntityCrate extends TileEntityAdvanced implements ITier, IInven @Override public int[] getAccessibleSlotsFromSide(int side) { + if (slots == null || slots != null && slots.length != this.getSlotCount()) + { + slots = new int[this.getSlotCount()]; + for (int i = 0; i < slots.length; i++) + { + slots[i] = i; + } + } return this.slots; } @Override public boolean canInsertItem(int slot, ItemStack itemstack, int side) { + ForgeDirection dir = ForgeDirection.getOrientation(side); + TileEntity ent = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), dir); + if(ent instanceof TileEntityHopper) + { + return false; + } + return this.isStackValidForSlot(slot, itemstack); } @Override public boolean canExtractItem(int slot, ItemStack itemstack, int side) { + ForgeDirection dir = ForgeDirection.getOrientation(side); + TileEntity ent = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), dir); + if(ent instanceof TileEntityHopper) + { + return false; + } return true; } }