mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +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){
|
for(IConnectionPair secondPair : secondNetwork.connections){
|
||||||
firstNetwork.connections.add(secondPair);
|
firstNetwork.connections.add(secondPair);
|
||||||
}
|
}
|
||||||
firstNetwork.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!");
|
||||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -80,21 +81,30 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
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()){
|
for(EnumFacing side : EnumFacing.values()){
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
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()))){
|
||||||
this.receiversAround.put(side, tile);
|
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(change){
|
||||||
if(network != null){
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||||
network.changeAmount++;
|
if(network != null){
|
||||||
|
network.changeAmount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -43,21 +44,30 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
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()){
|
for(EnumFacing side : EnumFacing.values()){
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
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())){
|
||||||
this.receiversAround.put(side, tile);
|
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(change){
|
||||||
if(network != null){
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||||
network.changeAmount++;
|
if(network != null){
|
||||||
|
network.changeAmount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -51,8 +52,10 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
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++){
|
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);
|
||||||
|
@ -60,14 +63,21 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
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());
|
||||||
if(handler != null){
|
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(change){
|
||||||
if(network != null){
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
||||||
network.changeAmount++;
|
if(network != null){
|
||||||
|
network.changeAmount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue