mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Made the change check in Laser Relays a bit more performance-good
This commit is contained in:
parent
0c696d96db
commit
d5ee51ff46
4 changed files with 43 additions and 14 deletions
|
@ -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!");
|
||||
|
|
|
@ -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,23 +81,32 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(change){
|
||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||
if(network != null){
|
||||
network.changeAmount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int transferEnergyToReceiverInNeed(EnumFacing from, Network network, int maxTransfer, boolean simulate){
|
||||
int transmitted = 0;
|
||||
|
|
|
@ -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,23 +44,32 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(change){
|
||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||
if(network != null){
|
||||
network.changeAmount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidAmountToSplitShare(){
|
||||
|
|
|
@ -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,16 +63,23 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(change){
|
||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||
if(network != null){
|
||||
network.changeAmount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getItemHandlersInNetwork(Network network, List<GenericItemHandlerInfo> storeList){
|
||||
//Keeps track of all the Laser Relays and Item Handlers that have been checked already to make nothing run multiple times
|
||||
|
|
Loading…
Reference in a new issue