From d5ee51ff46e66b9d571753962b37e123ff2f4683 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 3 Nov 2016 10:49:41 +0100 Subject: [PATCH] Made the change check in Laser Relays a bit more performance-good --- .../mod/misc/LaserRelayConnectionHandler.java | 1 - .../mod/tile/TileEntityLaserRelayEnergy.java | 18 +++++++++++++---- .../mod/tile/TileEntityLaserRelayFluids.java | 18 +++++++++++++---- .../mod/tile/TileEntityLaserRelayItem.java | 20 ++++++++++++++----- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java index e08b1d18b..af33e6a17 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/LaserRelayConnectionHandler.java @@ -56,7 +56,6 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH for(IConnectionPair secondPair : secondNetwork.connections){ firstNetwork.connections.add(secondPair); } - firstNetwork.changeAmount++; WorldData.getDataForWorld(world).laserRelayNetworks.remove(secondNetwork); //System.out.println("Merged Two Networks!"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index 144f10b98..2e3d78350 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -25,6 +25,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -80,21 +81,30 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements @Override public void saveDataOnChangeOrWorldStart(){ - this.receiversAround.clear(); + Map old = new HashMap(this.receiversAround); + boolean change = false; + this.receiversAround.clear(); for(EnumFacing side : EnumFacing.values()){ BlockPos pos = this.getPos().offset(side); TileEntity tile = this.worldObj.getTileEntity(pos); if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile instanceof IEnergyReceiver || (ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite()))){ this.receiversAround.put(side, tile); + + TileEntity oldTile = old.get(side); + if(oldTile == null || !tile.equals(oldTile)){ + change = true; + } } } } - Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); - if(network != null){ - network.changeAmount++; + if(change){ + Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); + if(network != null){ + network.changeAmount++; + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java index aecab501c..ce56ee426 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java @@ -24,6 +24,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -43,21 +44,30 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements @Override public void saveDataOnChangeOrWorldStart(){ - this.receiversAround.clear(); + Map old = new HashMap(this.receiversAround); + boolean change = false; + this.receiversAround.clear(); for(EnumFacing side : EnumFacing.values()){ BlockPos pos = this.getPos().offset(side); TileEntity tile = this.worldObj.getTileEntity(pos); if(tile != null && !(tile instanceof TileEntityLaserRelay)){ if(tile instanceof net.minecraftforge.fluids.IFluidHandler || tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){ this.receiversAround.put(side, tile); + + TileEntity oldTile = old.get(side); + if(oldTile == null || !tile.equals(oldTile)){ + change = true; + } } } } - Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); - if(network != null){ - network.changeAmount++; + if(change){ + Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); + if(network != null){ + network.changeAmount++; + } } } 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 bddde08ee..3690d3451 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java @@ -24,6 +24,7 @@ import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -51,8 +52,10 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ @Override public void saveDataOnChangeOrWorldStart(){ - this.handlersAround.clear(); + Map old = new HashMap(this.handlersAround); + boolean change = false; + this.handlersAround.clear(); for(int i = 0; i <= 5; i++){ EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i); BlockPos pos = this.getPos().offset(side); @@ -60,14 +63,21 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{ if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){ IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite()); if(handler != null){ - this.handlersAround.put(tile.getPos(), handler); + this.handlersAround.put(pos, handler); + + IItemHandler oldHandler = old.get(pos); + if(oldHandler == null || !handler.equals(oldHandler)){ + change = true; + } } } } - Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); - if(network != null){ - network.changeAmount++; + if(change){ + Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld()); + if(network != null){ + network.changeAmount++; + } } }