Added laser relay network cashing, added loadedness checks

This commit is contained in:
Ellpeck 2017-01-18 15:04:58 +01:00
parent ac13e6c243
commit cb4ebe3aaa
9 changed files with 110 additions and 66 deletions

View file

@ -145,7 +145,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
if(!world.isRemote){ if(!world.isRemote){
relay.onCompassAction(player); relay.onCompassAction(player);
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), relay.getWorld()); Network network = relay.getNetwork();
if(network != null){ if(network != null){
network.changeAmount++; network.changeAmount++;
} }

View file

@ -57,6 +57,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
firstNetwork.connections.add(secondPair); firstNetwork.connections.add(secondPair);
} }
secondNetwork.changeAmount++;
WorldData.getDataForWorld(world).laserRelayNetworks.remove(secondNetwork); WorldData.getDataForWorld(world).laserRelayNetworks.remove(secondNetwork);
//System.out.println("Merged Two Networks!"); //System.out.println("Merged Two Networks!");
} }
@ -84,6 +85,8 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
public void removeRelayFromNetwork(BlockPos relay, World world){ public void removeRelayFromNetwork(BlockPos relay, World world){
Network network = this.getNetworkFor(relay, world); Network network = this.getNetworkFor(relay, world);
if(network != null){ if(network != null){
network.changeAmount++;
//Setup new network (so that splitting a network will cause it to break into two) //Setup new network (so that splitting a network will cause it to break into two)
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network); WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
for(IConnectionPair pair : network.connections){ for(IConnectionPair pair : network.connections){

View file

@ -277,7 +277,10 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
public void saveDataOnChangeOrWorldStart(){ public void saveDataOnChangeOrWorldStart(){
for(EnumFacing side : EnumFacing.values()){ for(EnumFacing side : EnumFacing.values()){
this.tilesAround[side.ordinal()] = this.worldObj.getTileEntity(this.pos.offset(side)); BlockPos pos = this.pos.offset(side);
if(this.worldObj.isBlockLoaded(pos)){
this.tilesAround[side.ordinal()] = this.worldObj.getTileEntity(pos);
}
} }
} }

View file

@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
@ -140,9 +141,16 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
*/ */
@Override @Override
public void saveDataOnChangeOrWorldStart(){ public void saveDataOnChangeOrWorldStart(){
this.placeToPull = null;
this.placeToPut = null;
if(this.sideToPull != -1){ if(this.sideToPull != -1){
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull); EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
this.placeToPull = this.worldObj.getTileEntity(this.pos.offset(side)); BlockPos offset = this.pos.offset(side);
if(this.worldObj.isBlockLoaded(offset)){
this.placeToPull = this.worldObj.getTileEntity(offset);
if(this.slotToPullEnd <= 0 && this.placeToPull != null){ if(this.slotToPullEnd <= 0 && this.placeToPull != null){
if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){ if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
@ -151,15 +159,16 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
this.slotToPullEnd = cap.getSlots(); this.slotToPullEnd = cap.getSlots();
} }
} }
else if(this.placeToPull instanceof IInventory){
this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
} }
} }
} }
if(this.sideToPut != -1){ if(this.sideToPut != -1){
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut); EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
this.placeToPut = this.worldObj.getTileEntity(this.pos.offset(side)); BlockPos offset = this.pos.offset(side);
if(this.worldObj.isBlockLoaded(offset)){
this.placeToPut = this.worldObj.getTileEntity(offset);
if(this.slotToPutEnd <= 0 && this.placeToPut != null){ if(this.slotToPutEnd <= 0 && this.placeToPut != null){
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){ if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
@ -168,8 +177,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
this.slotToPutEnd = cap.getSlots(); this.slotToPutEnd = cap.getSlots();
} }
} }
else if(this.placeToPut instanceof IInventory){
this.slotToPutEnd = ((IInventory)this.placeToPut).getSizeInventory();
} }
} }
} }

View file

@ -10,7 +10,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
@ -29,7 +28,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
private final Map<Integer, SpecificItemHandlerInfo> specificInfos = new HashMap<Integer, SpecificItemHandlerInfo>(); private final Map<Integer, SpecificItemHandlerInfo> specificInfos = new HashMap<Integer, SpecificItemHandlerInfo>();
public TileEntityLaserRelayItem connectedRelay; public TileEntityLaserRelayItem connectedRelay;
private Network oldNetwork;
private int lastNetworkChangeAmount = -1; private int lastNetworkChangeAmount = -1;
public TileEntityItemViewer(){ public TileEntityItemViewer(){
@ -76,9 +74,9 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
private void queryAndSaveData(){ private void queryAndSaveData(){
if(this.connectedRelay != null){ if(this.connectedRelay != null){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.connectedRelay.getPos(), this.worldObj); Network network = this.connectedRelay.getNetwork();
if(network != null){ if(network != null){
if(this.oldNetwork != network || this.lastNetworkChangeAmount != network.changeAmount){ if(this.lastNetworkChangeAmount != network.changeAmount){
this.clearInfos(); this.clearInfos();
this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos); this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos);
@ -96,7 +94,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
} }
} }
this.oldNetwork = network;
this.lastNetworkChangeAmount = network.changeAmount; this.lastNetworkChangeAmount = network.changeAmount;
} }
@ -105,6 +102,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
} }
this.clearInfos(); this.clearInfos();
this.lastNetworkChangeAmount = -1;
} }
private void clearInfos(){ private void clearInfos(){
@ -134,6 +132,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
for(int i = 0; i <= 5; i++){ for(int i = 0; i <= 5; i++){
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i); EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
BlockPos pos = this.getPos().offset(side); BlockPos pos = this.getPos().offset(side);
if(this.worldObj.isBlockLoaded(pos)){
TileEntity tile = this.worldObj.getTileEntity(pos); TileEntity tile = this.worldObj.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelayItem){ if(tile instanceof TileEntityLaserRelayItem){
@ -147,6 +146,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
} }
} }
} }
}
this.connectedRelay = tileFound; this.connectedRelay = tileFound;
} }
@ -158,7 +158,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override @Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){ public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){ if(handler != null && handler.isLoaded()){
if(this.isWhitelisted(handler, stack, true)){ if(this.isWhitelisted(handler, stack, true)){
if(ItemStack.areItemsEqual(handler.handler.getStackInSlot(handler.switchedIndex), stack)){ if(ItemStack.areItemsEqual(handler.handler.getStackInSlot(handler.switchedIndex), stack)){
ItemStack gaveBack = handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stack), true); ItemStack gaveBack = handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stack), true);
@ -183,7 +183,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override @Override
public boolean isItemValidForSlot(int index, ItemStack stack){ public boolean isItemValidForSlot(int index, ItemStack stack){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){ if(handler != null && handler.isLoaded()){
if(this.isWhitelisted(handler, stack, false)){ if(this.isWhitelisted(handler, stack, false)){
ItemStack gaveBack = handler.handler.insertItem(handler.switchedIndex, stack, true); ItemStack gaveBack = handler.handler.insertItem(handler.switchedIndex, stack, true);
return !ItemStack.areItemStacksEqual(gaveBack, stack); return !ItemStack.areItemStacksEqual(gaveBack, stack);
@ -203,7 +203,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
public void setInventorySlotContents(int i, ItemStack stack){ public void setInventorySlotContents(int i, ItemStack stack){
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){ if(handler != null && handler.isLoaded()){
ItemStack toInsert = stack.copy(); ItemStack toInsert = stack.copy();
ItemStack inSlot = handler.handler.getStackInSlot(handler.switchedIndex); ItemStack inSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(StackUtil.isValid(inSlot)){ if(StackUtil.isValid(inSlot)){
@ -223,18 +223,20 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
List<GenericItemHandlerInfo> infos = this.getItemHandlerInfos(); List<GenericItemHandlerInfo> infos = this.getItemHandlerInfos();
if(infos != null){ if(infos != null){
for(GenericItemHandlerInfo info : infos){ for(GenericItemHandlerInfo info : infos){
if(info.isLoaded()){
for(IItemHandler handler : info.handlers){ for(IItemHandler handler : info.handlers){
size += handler.getSlots(); size += handler.getSlots();
} }
} }
} }
}
return size; return size;
} }
@Override @Override
public ItemStack getStackInSlot(int i){ public ItemStack getStackInSlot(int i){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){ if(handler != null && handler.isLoaded()){
return handler.handler.getStackInSlot(handler.switchedIndex); return handler.handler.getStackInSlot(handler.switchedIndex);
} }
return null; return null;
@ -243,7 +245,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override @Override
public ItemStack decrStackSize(int i, int j){ public ItemStack decrStackSize(int i, int j){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(i);
if(handler != null){ if(handler != null && handler.isLoaded()){
return handler.handler.extractItem(handler.switchedIndex, j, false); return handler.handler.extractItem(handler.switchedIndex, j, false);
} }
return null; return null;
@ -252,7 +254,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
@Override @Override
public ItemStack removeStackFromSlot(int index){ public ItemStack removeStackFromSlot(int index){
SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index); SpecificItemHandlerInfo handler = this.getSwitchedIndexHandler(index);
if(handler != null){ if(handler != null && handler.isLoaded()){
ItemStack stackInSlot = handler.handler.getStackInSlot(handler.switchedIndex); ItemStack stackInSlot = handler.handler.getStackInSlot(handler.switchedIndex);
if(StackUtil.isValid(stackInSlot)){ if(StackUtil.isValid(stackInSlot)){
handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stackInSlot), false); handler.handler.extractItem(handler.switchedIndex, StackUtil.getStackSize(stackInSlot), false);
@ -273,6 +275,10 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
this.switchedIndex = switchedIndex; this.switchedIndex = switchedIndex;
this.relayInQuestion = relayInQuestion; this.relayInQuestion = relayInQuestion;
} }
public boolean isLoaded(){
return this.relayInQuestion.hasWorldObj() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
}
} }
public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{ public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{
@ -284,6 +290,10 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
this.relayInQuestion = relayInQuestion; this.relayInQuestion = relayInQuestion;
} }
public boolean isLoaded(){
return this.relayInQuestion.hasWorldObj() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
}
@Override @Override
public int compareTo(GenericItemHandlerInfo other){ public int compareTo(GenericItemHandlerInfo other){
int thisPrio = this.relayInQuestion.getPriority(); int thisPrio = this.relayInQuestion.getPriority();

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType; import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.misc.ConnectionPair; import de.ellpeck.actuallyadditions.mod.misc.ConnectionPair;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -30,6 +31,9 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
public final LaserType type; public final LaserType type;
private Network cachedNetwork;
private int changeAmountAtCaching = -1;
private Set<IConnectionPair> tempConnectionStorage; private Set<IConnectionPair> tempConnectionStorage;
public TileEntityLaserRelay(String name, LaserType type){ public TileEntityLaserRelay(String name, LaserType type){
@ -107,6 +111,21 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
} }
}*/ }*/
public Network getNetwork(){
if(this.cachedNetwork == null || this.cachedNetwork.changeAmount != this.changeAmountAtCaching){
this.cachedNetwork = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj);
if(this.cachedNetwork != null){
this.changeAmountAtCaching = this.cachedNetwork.changeAmount;
}
else{
this.changeAmountAtCaching = -1;
}
}
return this.cachedNetwork;
}
@Override @Override
public void invalidate(){ public void invalidate(){
super.invalidate(); super.invalidate();

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair; import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType; import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
@ -67,7 +66,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
private int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){ private int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){
int transmitted = 0; int transmitted = 0;
if(maxTransmit > 0 && this.mode != Mode.OUTPUT_ONLY){ if(maxTransmit > 0 && this.mode != Mode.OUTPUT_ONLY){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj); Network network = this.getNetwork();
if(network != null){ if(network != null){
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate); transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
} }
@ -93,6 +92,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
this.receiversAround.clear(); this.receiversAround.clear();
for(EnumFacing side : EnumFacing.values()){ for(EnumFacing side : EnumFacing.values()){
BlockPos pos = this.getPos().offset(side); BlockPos pos = this.getPos().offset(side);
if(this.worldObj.isBlockLoaded(pos)){
TileEntity tile = this.worldObj.getTileEntity(pos); TileEntity tile = this.worldObj.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if(tile instanceof IEnergyReceiver || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite()))){ if(tile instanceof IEnergyReceiver || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite()))){
@ -105,9 +105,10 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
} }
} }
} }
}
if(change || old.size() != this.receiversAround.size()){ if(change || old.size() != this.receiversAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); Network network = this.getNetwork();
if(network != null){ if(network != null){
network.changeAmount++; network.changeAmount++;
} }
@ -124,7 +125,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
for(IConnectionPair pair : network.connections){ for(IConnectionPair pair : network.connections){
for(BlockPos relay : pair.getPositions()){ for(BlockPos relay : pair.getPositions()){
if(relay != null && !alreadyChecked.contains(relay)){ if(relay != null && this.worldObj.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity relayTile = this.worldObj.getTileEntity(relay); TileEntity relayTile = this.worldObj.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayEnergy){ if(relayTile instanceof TileEntityLaserRelayEnergy){

View file

@ -71,6 +71,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
this.handlersAround.clear(); this.handlersAround.clear();
for(EnumFacing side : EnumFacing.values()){ for(EnumFacing side : EnumFacing.values()){
BlockPos pos = this.getPos().offset(side); BlockPos pos = this.getPos().offset(side);
if(this.worldObj.isBlockLoaded(pos)){
TileEntity tile = this.worldObj.getTileEntity(pos); TileEntity tile = this.worldObj.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if(tile instanceof net.minecraftforge.fluids.IFluidHandler || tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){ if(tile instanceof net.minecraftforge.fluids.IFluidHandler || tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){
@ -83,9 +84,10 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
} }
} }
} }
}
if(change || old.size() != this.handlersAround.size()){ if(change || old.size() != this.handlersAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); Network network = this.getNetwork();
if(network != null){ if(network != null){
network.changeAmount++; network.changeAmount++;
} }
@ -115,7 +117,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
private int transmitEnergy(EnumFacing from, FluidStack stack, boolean doFill){ private int transmitEnergy(EnumFacing from, FluidStack stack, boolean doFill){
int transmitted = 0; int transmitted = 0;
if(stack != null && this.mode != Mode.OUTPUT_ONLY){ if(stack != null && this.mode != Mode.OUTPUT_ONLY){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj); Network network = this.getNetwork();
if(network != null){ if(network != null){
transmitted = this.transferEnergyToReceiverInNeed(from, network, stack, doFill); transmitted = this.transferEnergyToReceiverInNeed(from, network, stack, doFill);
} }
@ -133,7 +135,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
for(IConnectionPair pair : network.connections){ for(IConnectionPair pair : network.connections){
for(BlockPos relay : pair.getPositions()){ for(BlockPos relay : pair.getPositions()){
if(relay != null && !alreadyChecked.contains(relay)){ if(relay != null && this.worldObj.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity relayTile = this.worldObj.getTileEntity(relay); TileEntity relayTile = this.worldObj.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayFluids){ if(relayTile instanceof TileEntityLaserRelayFluids){

View file

@ -84,7 +84,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
} }
if(change || old.size() != this.handlersAround.size()){ if(change || old.size() != this.handlersAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); Network network = this.getNetwork();
if(network != null){ if(network != null){
network.changeAmount++; network.changeAmount++;
} }
@ -97,15 +97,14 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
for(IConnectionPair pair : network.connections){ for(IConnectionPair pair : network.connections){
for(BlockPos relay : pair.getPositions()){ for(BlockPos relay : pair.getPositions()){
if(relay != null && !alreadyChecked.contains(relay)){ if(relay != null && this.worldObj.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity aRelayTile = this.worldObj.getTileEntity(relay); TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
if(aRelayTile instanceof TileEntityLaserRelayItem){ if(aRelayTile instanceof TileEntityLaserRelayItem){
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile; TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile); GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
Map<BlockPos, IItemHandler> handlersAroundTile = relayTile.handlersAround; for(Map.Entry<BlockPos, IItemHandler> handler : relayTile.handlersAround.entrySet()){
for(Map.Entry<BlockPos, IItemHandler> handler : handlersAroundTile.entrySet()){
if(!alreadyChecked.contains(handler.getKey())){ if(!alreadyChecked.contains(handler.getKey())){
alreadyChecked.add(handler.getKey()); alreadyChecked.add(handler.getKey());