diff --git a/src/main/java/appeng/parts/automation/PartSharedItemBus.java b/src/main/java/appeng/parts/automation/PartSharedItemBus.java index ee89ddf3a..7372d3317 100644 --- a/src/main/java/appeng/parts/automation/PartSharedItemBus.java +++ b/src/main/java/appeng/parts/automation/PartSharedItemBus.java @@ -33,15 +33,12 @@ import appeng.api.networking.ticking.TickRateModulation; import appeng.me.GridAccessException; import appeng.tile.inventory.AppEngInternalAEInventory; import appeng.util.InventoryAdaptor; -import appeng.util.Platform; public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable { private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 ); - private int adaptorHash = 0; - private InventoryAdaptor adaptor; private boolean lastRedstone = false; public PartSharedItemBus( final ItemStack is ) @@ -102,17 +99,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid final TileEntity self = this.getHost().getTile(); final TileEntity target = this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) ); - final int newAdaptorHash = Platform.generateTileHash( target ); - - if( this.adaptorHash == newAdaptorHash && newAdaptorHash != 0 ) - { - return this.adaptor; - } - - this.adaptorHash = newAdaptorHash; - this.adaptor = InventoryAdaptor.getAdaptor( target, this.getSide().getFacing().getOpposite() ); - - return this.adaptor; + return InventoryAdaptor.getAdaptor( target, this.getSide().getFacing().getOpposite() ); } private TileEntity getTileEntity( final TileEntity self, final BlockPos pos ) diff --git a/src/main/java/appeng/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java index fe301abcb..50e99946f 100644 --- a/src/main/java/appeng/parts/misc/PartStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartStorageBus.java @@ -22,6 +22,7 @@ package appeng.parts.misc; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -402,6 +403,25 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC } + private int createHandlerHash( TileEntity target ) + { + if( target == null ) + { + return 0; + } + final EnumFacing targetSide = this.getSide().getFacing().getOpposite(); + if( target.hasCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ) ) + { + return 0; + } + final IItemHandler itemHandler = target.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, targetSide ); + if( handler != null ) + { + return Objects.hash( target, itemHandler, itemHandler.getSlots() ); + } + return 0; + } + public MEInventoryHandler getInternalHandler() { if( this.cached ) @@ -414,9 +434,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC this.cached = true; final TileEntity self = this.getHost().getTile(); final TileEntity target = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) ); - final int newHandlerHash = Platform.generateTileHash( target ); + final int newHandlerHash = createHandlerHash( target ); - if( this.handlerHash == newHandlerHash && this.handlerHash != 0 ) + if( newHandlerHash != 0 && newHandlerHash == this.handlerHash ) { return this.handler; } @@ -603,5 +623,4 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC return MODELS_OFF; } } - } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 54bbaba20..ddd22ca23 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -46,8 +46,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -58,7 +56,6 @@ import net.minecraft.network.play.server.SPacketChunkData; import net.minecraft.server.management.PlayerChunkMap; import net.minecraft.server.management.PlayerChunkMapEntry; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; @@ -115,7 +112,6 @@ import appeng.api.storage.data.IItemList; import appeng.api.util.AEColor; import appeng.api.util.AEPartLocation; import appeng.api.util.DimensionalCoord; -import appeng.capabilities.Capabilities; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.AppEng; @@ -1342,70 +1338,6 @@ public class Platform } } - public static int generateTileHash( final TileEntity target ) - { - if( target == null ) - { - return 0; - } - - int hash = target.hashCode(); - - if( target.hasCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, null ) ) - { - return 0; - } - else if( target instanceof TileEntityChest ) - { - final TileEntityChest chest = (TileEntityChest) target; - chest.checkForAdjacentChests(); - if( chest.adjacentChestZNeg != null ) - { - hash ^= chest.adjacentChestZNeg.hashCode(); - } - else if( chest.adjacentChestZPos != null ) - { - hash ^= chest.adjacentChestZPos.hashCode(); - } - else if( chest.adjacentChestXPos != null ) - { - hash ^= chest.adjacentChestXPos.hashCode(); - } - else if( chest.adjacentChestXNeg != null ) - { - hash ^= chest.adjacentChestXNeg.hashCode(); - } - } - else if( target instanceof IInventory ) - { - hash ^= ( (IInventory) target ).getSizeInventory(); - - if( target instanceof ISidedInventory ) - { - for( final EnumFacing dir : EnumFacing.VALUES ) - { - - final int[] sides = ( (ISidedInventory) target ).getSlotsForFace( dir ); - - if( sides == null ) - { - return 0; - } - - int offset = 0; - for( final int side : sides ) - { - final int c = ( side << ( offset % 8 ) ) ^ ( 1 << dir.ordinal() ); - offset++; - hash = c + ( hash << 6 ) + ( hash << 16 ) - hash; - } - } - } - } - - return hash; - } - public static boolean securityCheck( final GridNode a, final GridNode b ) { if( a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1 )