Made the change check in Laser Relays a bit more performance-good

This commit is contained in:
Ellpeck 2016-11-03 10:49:41 +01:00
parent 0c696d96db
commit d5ee51ff46
4 changed files with 43 additions and 14 deletions

View file

@ -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!");

View file

@ -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<EnumFacing, TileEntity> old = new HashMap<EnumFacing, TileEntity>(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++;
}
}
}

View file

@ -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<EnumFacing, TileEntity> old = new HashMap<EnumFacing, TileEntity>(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++;
}
}
}

View file

@ -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<BlockPos, IItemHandler> old = new HashMap<BlockPos, IItemHandler>(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++;
}
}
}