diff --git a/src/main/java/techreborn/parts/CableMultipart.java b/src/main/java/techreborn/parts/CableMultipart.java index a86a92b10..0ded97b36 100644 --- a/src/main/java/techreborn/parts/CableMultipart.java +++ b/src/main/java/techreborn/parts/CableMultipart.java @@ -60,6 +60,7 @@ public abstract class CableMultipart extends Multipart implements INormallyOcclu public Map connectedSides; public int ticks = 0; public ItemStack stack; + public TRPowerNet mergeWith = null; public static final IUnlistedProperty UP = Properties.toUnlisted(PropertyBool.create("up")); public static final IUnlistedProperty 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; + } } } diff --git a/src/main/java/techreborn/power/TRPowerNet.java b/src/main/java/techreborn/power/TRPowerNet.java index a7e8e25fd..1bb1dc8ae 100644 --- a/src/main/java/techreborn/power/TRPowerNet.java +++ b/src/main/java/techreborn/power/TRPowerNet.java @@ -85,23 +85,29 @@ public class TRPowerNet { this.rebuild(); } - public void buildEndpoint(){ - for(CableMultipart cable : cables){ + public static void buildEndpoint(TRPowerNet net){ + ArrayList parts = new ArrayList<>(); + ArrayList 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() {