Experimental changes to try and fix some issues with the power net.
(cherry picked from commit ad940a7)
This commit is contained in:
parent
92acc51aaf
commit
50093455ab
2 changed files with 40 additions and 13 deletions
|
@ -200,9 +200,6 @@ public abstract class CableMultipart extends Multipart
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nearByChange() {
|
public void nearByChange() {
|
||||||
if (network == null) {
|
|
||||||
findAndJoinNetwork(getWorld(), getPos());
|
|
||||||
}
|
|
||||||
checkConnectedSides();
|
checkConnectedSides();
|
||||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||||
BlockPos blockPos = getPos().offset(direction);
|
BlockPos blockPos = getPos().offset(direction);
|
||||||
|
@ -212,14 +209,35 @@ public abstract class CableMultipart extends Multipart
|
||||||
part.checkConnectedSides();
|
part.checkConnectedSides();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (network == null) {
|
||||||
|
findAndJoinNetwork(getWorld(), getPos());
|
||||||
|
}
|
||||||
TRPowerNet.buildEndpoint(network);
|
TRPowerNet.buildEndpoint(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdded() {
|
public void onAdded() {
|
||||||
nearByChange();
|
checkConnectedSides();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void tryNetworkMerge(EnumFacing dir){
|
||||||
|
if (dir != null) {
|
||||||
|
if (internalShouldConnectTo(dir)) {
|
||||||
|
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||||
|
if (cableMultipart != null && cableMultipart.internalShouldConnectTo(dir.getOpposite())) {
|
||||||
|
if(network == null && cableMultipart.network != null){
|
||||||
|
network = cableMultipart.network;
|
||||||
|
network.addElement(this);
|
||||||
|
} else if (network != cableMultipart.network){
|
||||||
|
network = cableMultipart.network.merge(network);
|
||||||
|
network.addElement(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean shouldConnectTo(EnumFacing dir) {
|
public boolean shouldConnectTo(EnumFacing dir) {
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
if (internalShouldConnectTo(dir)) {
|
if (internalShouldConnectTo(dir)) {
|
||||||
|
@ -270,6 +288,7 @@ public abstract class CableMultipart extends Multipart
|
||||||
TileEntity te = getNeighbourTile(dir);
|
TileEntity te = getNeighbourTile(dir);
|
||||||
if (shouldConnectTo(dir)) {
|
if (shouldConnectTo(dir)) {
|
||||||
connectedSides.put(dir, te.getPos());
|
connectedSides.put(dir, te.getPos());
|
||||||
|
tryNetworkMerge(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,15 +301,21 @@ public abstract class CableMultipart extends Multipart
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if (getWorld() != null) {
|
if (getWorld() != null) {
|
||||||
|
ticks ++;
|
||||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||||
checkConnectedSides();
|
checkConnectedSides();
|
||||||
}
|
}
|
||||||
|
if(ticks == 20){ // Rebuilds the whole network just after the part has been added, we allow for some time to let the world load in.
|
||||||
|
resetNetwork();
|
||||||
|
findAndJoinNetwork(getWorld(), getPos());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
this.findAndJoinNetwork(getWorld(), getPos());
|
this.findAndJoinNetwork(getWorld(), getPos());
|
||||||
} else {
|
} else {
|
||||||
if (mergeWith != null) {
|
if (mergeWith != null) {
|
||||||
getNetwork().merge(mergeWith);
|
network = getNetwork().merge(mergeWith);
|
||||||
|
network.addElement(this);
|
||||||
mergeWith = null;
|
mergeWith = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,8 +396,13 @@ public abstract class CableMultipart extends Multipart
|
||||||
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
||||||
TRPowerNet net = cableMultipart.getNetwork();
|
TRPowerNet net = cableMultipart.getNetwork();
|
||||||
if (net != null) {
|
if (net != null) {
|
||||||
|
if(network == null){
|
||||||
network = net;
|
network = net;
|
||||||
network.addElement(this);
|
network.addElement(this);
|
||||||
|
} else {
|
||||||
|
network = net.merge(network);
|
||||||
|
network.addElement(this);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,13 +411,9 @@ public abstract class CableMultipart extends Multipart
|
||||||
network = new TRPowerNet(getCableType());
|
network = new TRPowerNet(getCableType());
|
||||||
network.addElement(this);
|
network.addElement(this);
|
||||||
}
|
}
|
||||||
for (Iterator<TRPowerNet.EnergyHandler> it = network.endpoints.iterator(); it.hasNext(); ) {
|
|
||||||
it.next();
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||||
TileEntity te = getNeighbourTile(dir);
|
TileEntity te = getNeighbourTile(dir);
|
||||||
if (te != null && te instanceof IEnergyInterfaceTile) {
|
if (te instanceof IEnergyInterfaceTile) {
|
||||||
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite());
|
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ public class TRPowerNet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void merge(TRPowerNet n) {
|
public TRPowerNet merge(TRPowerNet n) {
|
||||||
if (n != this) {
|
if (n != this) {
|
||||||
ArrayList<CableMultipart> li = new ArrayList();
|
ArrayList<CableMultipart> li = new ArrayList();
|
||||||
for (int i = 0; i < n.cables.size(); i++) {
|
for (int i = 0; i < n.cables.size(); i++) {
|
||||||
|
@ -223,6 +223,7 @@ public class TRPowerNet {
|
||||||
checkAndRemoveOldEndpoints();
|
checkAndRemoveOldEndpoints();
|
||||||
MinecraftForge.EVENT_BUS.unregister(n);
|
MinecraftForge.EVENT_BUS.unregister(n);
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnergyHandler getHandleFrom(IEnergyInterfaceTile tile) {
|
private EnergyHandler getHandleFrom(IEnergyInterfaceTile tile) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue