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

View file

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