diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemViewer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemViewer.java index 54a1abd6c..31026f2f9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemViewer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockItemViewer.java @@ -12,11 +12,15 @@ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem; +import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockItemViewer extends BlockContainerBase{ @@ -30,6 +34,17 @@ public class BlockItemViewer extends BlockContainerBase{ } + @Override + public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){ + if(!world.isRemote){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityItemViewer){ + ((TileEntityItemViewer)tile).saveConnectedRelay(); + System.out.println("------------Saving connected on change " + ((TileEntityItemViewer)tile).connectedRelay); + } + } + } + @Override public TileEntity createNewTileEntity(World worldIn, int meta){ return new TileEntityItemViewer(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 54f1c0c60..859c586de 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist; +import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyInteger; @@ -115,6 +116,16 @@ public class BlockLaserRelay extends BlockContainerBase{ return false; } + @Override + public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){ + if(!world.isRemote){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityLaserRelayItem){ + ((TileEntityLaserRelayItem)tile).saveAllHandlersAround(); + System.out.println("------------Saving around on change " + ((TileEntityLaserRelayItem)tile).handlersAround); + } + } + } @Override public TileEntity createNewTileEntity(World world, int i){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java index a480a4697..f667fc1c1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemViewer.java @@ -24,12 +24,27 @@ import java.util.List; public class TileEntityItemViewer extends TileEntityInventoryBase{ + public TileEntityLaserRelayItem connectedRelay; + private boolean hasCheckedRelayOnLoad; + public TileEntityItemViewer(){ super(0, "itemViewer"); } + @Override + public void updateEntity(){ + super.updateEntity(); + + if(!this.worldObj.isRemote && !this.hasCheckedRelayOnLoad){ + this.saveConnectedRelay(); + this.hasCheckedRelayOnLoad = true; + + System.out.println("------------Saving relay on load " + this.connectedRelay); + } + } + private List getItemHandlerInfos(){ - TileEntityLaserRelayItem relay = this.getConnectedRelay(); + TileEntityLaserRelayItem relay = this.connectedRelay; if(relay != null){ LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj); if(network != null){ @@ -61,7 +76,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{ return null; } - private TileEntityLaserRelayItem getConnectedRelay(){ + public void saveConnectedRelay(){ TileEntityLaserRelayItem tileFound = null; if(this.worldObj != null){ //Why is that even possible..? for(int i = 0; i <= 5; i++){ @@ -71,7 +86,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{ if(tile instanceof TileEntityLaserRelayItem){ if(tileFound != null){ - return null; + this.connectedRelay = null; + return; } else{ tileFound = (TileEntityLaserRelayItem)tile; @@ -79,7 +95,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{ } } } - return tileFound; + this.connectedRelay = tileFound; } @Override @@ -103,7 +119,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{ private boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output){ boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output); - TileEntityLaserRelayItem connected = this.getConnectedRelay(); + TileEntityLaserRelayItem connected = this.connectedRelay; if(connected != null && connected != handler.relayInQuestion){ return whitelisted && connected.isWhitelisted(stack, !output); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java index 3663f7d49..0a92b0ee5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java @@ -11,6 +11,8 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler; +import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -24,6 +26,9 @@ import java.util.List; public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ + public List handlersAround = new ArrayList(); + private boolean hasCheckedHandlersOnLoad; + public TileEntityLaserRelayItem(String name){ super(name, true); } @@ -36,8 +41,21 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ return true; } - public List getAllHandlersAround(){ - List handlers = new ArrayList(); + @Override + public void updateEntity(){ + super.updateEntity(); + + if(!this.worldObj.isRemote && !this.hasCheckedHandlersOnLoad){ + this.saveAllHandlersAround(); + this.hasCheckedHandlersOnLoad = true; + + System.out.println("------------Saving around on load " + this.handlersAround); + } + } + + public void saveAllHandlersAround(){ + this.handlersAround.clear(); + for(int i = 0; i <= 5; i++){ EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i); BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 0); @@ -45,27 +63,26 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ if(tile != null && !(tile instanceof TileEntityItemViewer)){ IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()); if(handler != null){ - handlers.add(handler); + this.handlersAround.add(handler); } } } - return handlers; } - public List getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){ - List handlers = new ArrayList(); + public List getItemHandlersInNetwork(Network network){ + List handlers = new ArrayList(); for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){ for(BlockPos relay : pair.positions){ if(relay != null){ TileEntity aRelayTile = this.worldObj.getTileEntity(relay); - if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){ - de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem relayTile = (de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem)aRelayTile; - if(!TileEntityItemViewer.GenericItemHandlerInfo.containsTile(handlers, relayTile)){ - TileEntityItemViewer.GenericItemHandlerInfo info = new TileEntityItemViewer.GenericItemHandlerInfo(relayTile); + if(aRelayTile instanceof TileEntityLaserRelayItem){ + TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile; + if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){ + GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile); - List handlersAroundTile = relayTile.getAllHandlersAround(); + List handlersAroundTile = relayTile.handlersAround; for(IItemHandler handler : handlersAroundTile){ - if(!TileEntityItemViewer.GenericItemHandlerInfo.containsHandler(handlers, handler)){ + if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){ info.handlers.add(handler); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java index 1c0910207..b090192e9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemWhitelist.java @@ -233,7 +233,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem int slotStart = output ? 12 : 0; int slotStop = slotStart+12; - List handlers = this.getAllHandlersAround(); + List handlers = this.handlersAround; for(IItemHandler handler : handlers){ for(int i = 0; i < handler.getSlots(); i++){ ItemStack stack = handler.getStackInSlot(i);