More powernet fixes

This commit is contained in:
modmuss50 2016-03-20 16:23:30 +00:00
parent 14d22e2442
commit 4a0fd93363
2 changed files with 18 additions and 6 deletions

View file

@ -60,6 +60,7 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu
public Map<EnumFacing, BlockPos> connectedSides;
public int ticks = 0;
public ItemStack stack;
public TRPowerNet mergeWith = null;
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down"));
@ -160,7 +161,7 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu
super.onNeighborBlockChange(block);
nearByChange();
if(network != null){
network.buildEndpoint();
network.buildEndpoint(network);
}
findAndJoinNetwork(getWorld(), getPos());
}
@ -276,6 +277,11 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu
}
if (network == null) {
this.findAndJoinNetwork(getWorld(), getPos());
} else {
if(mergeWith != null){
getNetwork().merge(network);
mergeWith = null;
}
}
}

View file

@ -85,23 +85,29 @@ public class TRPowerNet {
this.rebuild();
}
public void buildEndpoint(){
for(CableMultipart cable : cables){
public static void buildEndpoint(TRPowerNet net){
ArrayList<CableMultipart> parts = new ArrayList<>();
ArrayList<CableMultipart> partsToMerge = new ArrayList<>();
parts.addAll(net.cables);
for(CableMultipart cable : parts){
for(EnumFacing facing : EnumFacing.VALUES){
BlockPos pos = cable.getPos().offset(facing);
TileEntity tile = cable.getWorld().getTileEntity(pos);
if(tile != null && tile instanceof IEnergyInterfaceTile){
IEnergyInterfaceTile eit = (IEnergyInterfaceTile) tile;
addConnection(eit, facing);
net.addConnection(eit, facing);
}
CableMultipart cableMultipart = CableMultipart.getPartFromWorld(cable.getWorld(), pos, null);
if(cableMultipart != null){
if(cableMultipart.getNetwork() != this){
cableMultipart.findAndJoinNetwork(cableMultipart.getWorld(), cableMultipart.getPos());
if(cableMultipart.getNetwork() != net){
partsToMerge.add(cableMultipart);
}
}
}
}
for(CableMultipart cableMultipart : partsToMerge){
cableMultipart.mergeWith = net;
}
}
public void rebuild() {