Add a bunch of loadedness checks and add network caching to Laser Relays

This commit is contained in:
Ellpeck 2017-01-18 14:26:56 +01:00
parent ccb88fd416
commit 996b997363
9 changed files with 125 additions and 78 deletions

View file

@ -10,7 +10,6 @@
package de.ellpeck.actuallyadditions.mod.blocks; package de.ellpeck.actuallyadditions.mod.blocks;
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.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
@ -167,7 +166,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

@ -293,7 +293,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.world.getTileEntity(this.pos.offset(side)); BlockPos pos = this.pos.offset(side);
if(this.world.isBlockLoaded(pos)){
this.tilesAround[side.ordinal()] = this.world.getTileEntity(pos);
}
} }
} }

View file

@ -20,6 +20,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;
@ -139,9 +140,15 @@ 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.world.getTileEntity(this.pos.offset(side)); BlockPos offset = this.pos.offset(side);
if(this.world.isBlockLoaded(offset)){
this.placeToPull = this.world.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)){
@ -152,10 +159,14 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
} }
} }
} }
}
if(this.sideToPut != -1){ if(this.sideToPut != -1){
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut); EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
this.placeToPut = this.world.getTileEntity(this.pos.offset(side)); BlockPos offset = this.pos.offset(side);
if(this.world.isBlockLoaded(offset)){
this.placeToPut = this.world.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)){
@ -167,6 +178,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
} }
} }
} }
}
@Override @Override
public void onButtonPressed(int buttonID, EntityPlayer player){ public void onButtonPressed(int buttonID, EntityPlayer player){

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.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
@ -32,7 +31,6 @@ public class TileEntityItemViewer extends TileEntityBase{
private final List<GenericItemHandlerInfo> genericInfos = new ArrayList<GenericItemHandlerInfo>(); private final List<GenericItemHandlerInfo> genericInfos = new ArrayList<GenericItemHandlerInfo>();
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(String name){ public TileEntityItemViewer(String name){
@ -45,18 +43,20 @@ public class TileEntityItemViewer extends TileEntityBase{
List<GenericItemHandlerInfo> infos = TileEntityItemViewer.this.getItemHandlerInfos(); List<GenericItemHandlerInfo> infos = TileEntityItemViewer.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 slot){ public ItemStack getStackInSlot(int slot){
SpecificItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot); SpecificItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(handler != null){ if(handler != null && handler.isLoaded()){
return handler.handler.getStackInSlot(handler.switchedIndex); return handler.handler.getStackInSlot(handler.switchedIndex);
} }
return StackUtil.getNull(); return StackUtil.getNull();
@ -65,7 +65,7 @@ public class TileEntityItemViewer extends TileEntityBase{
@Override @Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){ public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot); SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){ if(info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){
ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate); ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate);
if(!ItemStack.areItemStacksEqual(remain, stack) && !simulate){ if(!ItemStack.areItemStacksEqual(remain, stack) && !simulate){
TileEntityItemViewer.this.markDirty(); TileEntityItemViewer.this.markDirty();
@ -81,7 +81,7 @@ public class TileEntityItemViewer extends TileEntityBase{
ItemStack stackIn = this.getStackInSlot(slot); ItemStack stackIn = this.getStackInSlot(slot);
if(StackUtil.isValid(stackIn)){ if(StackUtil.isValid(stackIn)){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot); SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){ if(info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate); ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
if(StackUtil.isValid(extracted) && !simulate){ if(StackUtil.isValid(extracted) && !simulate){
TileEntityItemViewer.this.markDirty(); TileEntityItemViewer.this.markDirty();
@ -96,7 +96,7 @@ public class TileEntityItemViewer extends TileEntityBase{
@Override @Override
public int getSlotLimit(int slot){ public int getSlotLimit(int slot){
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot); SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
if(info != null){ if(info != null && info.isLoaded()){
return info.handler.getSlotLimit(info.switchedIndex); return info.handler.getSlotLimit(info.switchedIndex);
} }
else{ else{
@ -139,9 +139,9 @@ public class TileEntityItemViewer extends TileEntityBase{
private void queryAndSaveData(){ private void queryAndSaveData(){
if(this.connectedRelay != null){ if(this.connectedRelay != null){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.connectedRelay.getPos(), this.world); 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);
@ -158,7 +158,6 @@ public class TileEntityItemViewer extends TileEntityBase{
} }
} }
} }
this.oldNetwork = network;
this.lastNetworkChangeAmount = network.changeAmount; this.lastNetworkChangeAmount = network.changeAmount;
} }
@ -167,6 +166,7 @@ public class TileEntityItemViewer extends TileEntityBase{
} }
this.clearInfos(); this.clearInfos();
this.lastNetworkChangeAmount = -1;
} }
private void clearInfos(){ private void clearInfos(){
@ -196,6 +196,8 @@ public class TileEntityItemViewer extends TileEntityBase{
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.world.isBlockLoaded(pos)){
TileEntity tile = this.world.getTileEntity(pos); TileEntity tile = this.world.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelayItem){ if(tile instanceof TileEntityLaserRelayItem){
@ -209,6 +211,7 @@ public class TileEntityItemViewer extends TileEntityBase{
} }
} }
} }
}
this.connectedRelay = tileFound; this.connectedRelay = tileFound;
} }
@ -234,6 +237,10 @@ public class TileEntityItemViewer extends TileEntityBase{
this.switchedIndex = switchedIndex; this.switchedIndex = switchedIndex;
this.relayInQuestion = relayInQuestion; this.relayInQuestion = relayInQuestion;
} }
public boolean isLoaded(){
return this.relayInQuestion.hasWorld() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
}
} }
public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{ public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{
@ -245,6 +252,10 @@ public class TileEntityItemViewer extends TileEntityBase{
this.relayInQuestion = relayInQuestion; this.relayInQuestion = relayInQuestion;
} }
public boolean isLoaded(){
return this.relayInQuestion.hasWorld() && 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

@ -19,6 +19,7 @@ import net.minecraft.item.ItemStack;
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.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
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;
@ -90,23 +91,23 @@ public class TileEntityItemViewerHopping extends TileEntityItemViewer{
public void saveDataOnChangeOrWorldStart(){ public void saveDataOnChangeOrWorldStart(){
super.saveDataOnChangeOrWorldStart(); super.saveDataOnChangeOrWorldStart();
this.handlerToPullFrom = null;
this.handlerToPushTo = null;
TileEntity from = this.world.getTileEntity(this.pos.offset(EnumFacing.UP)); TileEntity from = this.world.getTileEntity(this.pos.offset(EnumFacing.UP));
if(from != null && !(from instanceof TileEntityItemViewer) && from.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)){ if(from != null && !(from instanceof TileEntityItemViewer) && from.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)){
this.handlerToPullFrom = from.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN); this.handlerToPullFrom = from.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
} }
else{
this.handlerToPullFrom = null;
}
IBlockState state = this.world.getBlockState(this.pos); IBlockState state = this.world.getBlockState(this.pos);
EnumFacing facing = state.getValue(BlockHopper.FACING); EnumFacing facing = state.getValue(BlockHopper.FACING);
TileEntity to = this.world.getTileEntity(this.pos.offset(facing)); BlockPos toPos = this.pos.offset(facing);
if(this.world.isBlockLoaded(toPos)){
TileEntity to = this.world.getTileEntity(toPos);
if(to != null && !(to instanceof TileEntityItemViewer) && to.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())){ if(to != null && !(to instanceof TileEntityItemViewer) && to.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())){
this.handlerToPushTo = to.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite()); this.handlerToPushTo = to.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
} }
else{
this.handlerToPushTo = null;
} }
} }
} }

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.apiimpl.ConnectionPair; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.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.world);
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

@ -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.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;
@ -90,7 +89,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
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.world); Network network = this.getNetwork();
if(network != null){ if(network != null){
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate); transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
} }
@ -116,6 +115,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
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.world.isBlockLoaded(pos)){
TileEntity tile = this.world.getTileEntity(pos); TileEntity tile = this.world.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if((ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite())) || tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){ if((ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite())) || tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
@ -128,9 +128,10 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
} }
} }
} }
}
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++;
} }
@ -147,7 +148,7 @@ public class TileEntityLaserRelayEnergy 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.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity relayTile = this.world.getTileEntity(relay); TileEntity relayTile = this.world.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayEnergy){ if(relayTile instanceof TileEntityLaserRelayEnergy){

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.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;
@ -96,6 +95,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
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.world.isBlockLoaded(pos)){
TileEntity tile = this.world.getTileEntity(pos); TileEntity tile = this.world.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){ if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){
@ -108,9 +108,10 @@ public class TileEntityLaserRelayFluids 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++;
} }
@ -125,7 +126,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
private int transmitFluid(EnumFacing from, FluidStack stack, boolean doFill){ private int transmitFluid(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.world); Network network = this.getNetwork();
if(network != null){ if(network != null){
transmitted = this.transferFluidToReceiverInNeed(from, network, stack, doFill); transmitted = this.transferFluidToReceiverInNeed(from, network, stack, doFill);
} }
@ -143,7 +144,7 @@ public class TileEntityLaserRelayFluids 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.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity relayTile = this.world.getTileEntity(relay); TileEntity relayTile = this.world.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayFluids){ if(relayTile instanceof TileEntityLaserRelayFluids){

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.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;
@ -69,6 +68,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
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.world.isBlockLoaded(pos)){
TileEntity tile = this.world.getTileEntity(pos); TileEntity tile = this.world.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){ if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()); IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
@ -82,9 +82,10 @@ 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 +98,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.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay); alreadyChecked.add(relay);
TileEntity aRelayTile = this.world.getTileEntity(relay); TileEntity aRelayTile = this.world.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());