Cleanup
This commit is contained in:
parent
841e358ce0
commit
ec7b0555c9
6 changed files with 64 additions and 31 deletions
|
@ -62,30 +62,39 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
{
|
{
|
||||||
if(transmitter.isValid())
|
if(transmitter.isValid())
|
||||||
{
|
{
|
||||||
if(worldObj == null) worldObj = transmitter.world();
|
if(worldObj == null)
|
||||||
|
{
|
||||||
|
worldObj = transmitter.world();
|
||||||
|
}
|
||||||
|
|
||||||
Coord4D coord = transmitter.coord();
|
Coord4D coord = transmitter.coord();
|
||||||
|
|
||||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
A acceptor = transmitter.getAcceptor(side);
|
A acceptor = transmitter.getAcceptor(side);
|
||||||
|
|
||||||
if(acceptor != null)
|
if(acceptor != null)
|
||||||
{
|
{
|
||||||
Coord4D acceptorCoord = coord.getFromSide(side);
|
Coord4D acceptorCoord = coord.getFromSide(side);
|
||||||
possibleAcceptors.put(acceptorCoord, acceptor);
|
possibleAcceptors.put(acceptorCoord, acceptor);
|
||||||
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
|
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
|
||||||
|
|
||||||
if(directions != null)
|
if(directions != null)
|
||||||
{
|
{
|
||||||
directions.add(side.getOpposite());
|
directions.add(side.getOpposite());
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
|
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
transmitter.setTransmitterNetwork((N)this);
|
transmitter.setTransmitterNetwork((N)this);
|
||||||
absorbBuffer(transmitter);
|
absorbBuffer(transmitter);
|
||||||
transmitters.add(transmitter);
|
transmitters.add(transmitter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCapacity();
|
updateCapacity();
|
||||||
clampBuffer();
|
clampBuffer();
|
||||||
queueClientUpdate(new ArrayList<>(transmittersToAdd));
|
queueClientUpdate(new ArrayList<>(transmittersToAdd));
|
||||||
|
@ -104,22 +113,24 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
A acceptor = transmitter.getAcceptor(side);
|
A acceptor = transmitter.getAcceptor(side);
|
||||||
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
|
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
|
||||||
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
|
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
|
||||||
|
|
||||||
if(acceptor != null)
|
if(acceptor != null)
|
||||||
{
|
{
|
||||||
possibleAcceptors.put(acceptorCoord, acceptor);
|
possibleAcceptors.put(acceptorCoord, acceptor);
|
||||||
|
|
||||||
if(directions != null)
|
if(directions != null)
|
||||||
{
|
{
|
||||||
directions.add(side.getOpposite());
|
directions.add(side.getOpposite());
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
|
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if(directions != null)
|
if(directions != null)
|
||||||
{
|
{
|
||||||
directions.remove(side.getOpposite());
|
directions.remove(side.getOpposite());
|
||||||
|
|
||||||
if(directions.isEmpty())
|
if(directions.isEmpty())
|
||||||
{
|
{
|
||||||
possibleAcceptors.remove(acceptorCoord);
|
possibleAcceptors.remove(acceptorCoord);
|
||||||
|
@ -129,6 +140,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changedAcceptors.clear();
|
changedAcceptors.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +155,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
{
|
{
|
||||||
invalidateTransmitter(transmitter);
|
invalidateTransmitter(transmitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
transmitters.clear();
|
transmitters.clear();
|
||||||
deregister();
|
deregister();
|
||||||
}
|
}
|
||||||
|
@ -160,13 +173,15 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side)
|
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side)
|
||||||
{
|
{
|
||||||
EnumSet<ForgeDirection> directions = changedAcceptors.get(transmitter);
|
EnumSet<ForgeDirection> directions = changedAcceptors.get(transmitter);
|
||||||
|
|
||||||
if(directions != null)
|
if(directions != null)
|
||||||
{
|
{
|
||||||
directions.add(side);
|
directions.add(side);
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
changedAcceptors.put(transmitter, EnumSet.of(side));
|
changedAcceptors.put(transmitter, EnumSet.of(side));
|
||||||
}
|
}
|
||||||
|
|
||||||
TransmitterNetworkRegistry.registerChangedNetwork(this);
|
TransmitterNetworkRegistry.registerChangedNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,16 +193,18 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
transmitters.add(transmitter);
|
transmitters.add(transmitter);
|
||||||
transmittersAdded.add(transmitter);
|
transmittersAdded.add(transmitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
possibleAcceptors.putAll(net.possibleAcceptors);
|
possibleAcceptors.putAll(net.possibleAcceptors);
|
||||||
|
|
||||||
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
|
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
|
||||||
{
|
{
|
||||||
Coord4D coord = entry.getKey();
|
Coord4D coord = entry.getKey();
|
||||||
|
|
||||||
if(acceptorDirections.containsKey(coord))
|
if(acceptorDirections.containsKey(coord))
|
||||||
{
|
{
|
||||||
acceptorDirections.get(coord).addAll(entry.getValue());
|
acceptorDirections.get(coord).addAll(entry.getValue());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
acceptorDirections.put(coord, entry.getValue());
|
acceptorDirections.put(coord, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -315,8 +332,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
{
|
{
|
||||||
Iterator<DelayQueue> i = updateQueue.iterator();
|
Iterator<DelayQueue> i = updateQueue.iterator();
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
while(i.hasNext())
|
while(i.hasNext())
|
||||||
{
|
{
|
||||||
DelayQueue q = i.next();
|
DelayQueue q = i.next();
|
||||||
|
@ -324,16 +340,14 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
|
||||||
if(q.delay > 0)
|
if(q.delay > 0)
|
||||||
{
|
{
|
||||||
q.delay--;
|
q.delay--;
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
transmittersAdded.addAll(transmitters);
|
transmittersAdded.addAll(transmitters);
|
||||||
updateDelay = 1;
|
updateDelay = 1;
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e)
|
} catch(Exception e) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if(updateDelay > 0)
|
if(updateDelay > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -127,12 +127,14 @@ public class TransmitterNetworkRegistry
|
||||||
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
|
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
|
||||||
{
|
{
|
||||||
DynamicNetwork network = getNetworkFromOrphan(orphanTransmitter);
|
DynamicNetwork network = getNetworkFromOrphan(orphanTransmitter);
|
||||||
|
|
||||||
if(network != null)
|
if(network != null)
|
||||||
{
|
{
|
||||||
networksToChange.add(network);
|
networksToChange.add(network);
|
||||||
network.register();
|
network.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
orphanTransmitters.clear();
|
orphanTransmitters.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +145,7 @@ public class TransmitterNetworkRegistry
|
||||||
OrphanPathFinder<A, N> finder = new OrphanPathFinder<>(startOrphan);
|
OrphanPathFinder<A, N> finder = new OrphanPathFinder<>(startOrphan);
|
||||||
finder.start();
|
finder.start();
|
||||||
N network;
|
N network;
|
||||||
|
|
||||||
switch(finder.networksFound.size())
|
switch(finder.networksFound.size())
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -157,9 +160,12 @@ public class TransmitterNetworkRegistry
|
||||||
Mekanism.logger.debug("Merging " + finder.networksFound.size() + " networks");
|
Mekanism.logger.debug("Merging " + finder.networksFound.size() + " networks");
|
||||||
network = startOrphan.mergeNetworks(finder.networksFound);
|
network = startOrphan.mergeNetworks(finder.networksFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
network.addNewTransmitters(finder.connectedTransmitters);
|
network.addNewTransmitters(finder.connectedTransmitters);
|
||||||
|
|
||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +175,7 @@ public class TransmitterNetworkRegistry
|
||||||
{
|
{
|
||||||
network.commit();
|
network.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
networksToChange.clear();
|
networksToChange.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +192,7 @@ public class TransmitterNetworkRegistry
|
||||||
|
|
||||||
for(DynamicNetwork network : networks)
|
for(DynamicNetwork network : networks)
|
||||||
{
|
{
|
||||||
strings[i] = network.toString();
|
strings[i++] = network.toString();
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings;
|
return strings;
|
||||||
|
@ -214,21 +220,27 @@ public class TransmitterNetworkRegistry
|
||||||
public void iterate(Coord4D from, ForgeDirection fromDirection)
|
public void iterate(Coord4D from, ForgeDirection fromDirection)
|
||||||
{
|
{
|
||||||
if(iterated.contains(from))
|
if(iterated.contains(from))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
iterated.add(from);
|
iterated.add(from);
|
||||||
|
|
||||||
if(orphanTransmitters.containsKey(from))
|
if(orphanTransmitters.containsKey(from))
|
||||||
{
|
{
|
||||||
IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);
|
IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);
|
||||||
|
|
||||||
if(transmitter.isValid() && transmitter.isOrphan())
|
if(transmitter.isValid() && transmitter.isOrphan())
|
||||||
{
|
{
|
||||||
connectedTransmitters.add(transmitter);
|
connectedTransmitters.add(transmitter);
|
||||||
transmitter.setOrphan(false);
|
transmitter.setOrphan(false);
|
||||||
|
|
||||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
if(direction != fromDirection)
|
if(direction != fromDirection)
|
||||||
{
|
{
|
||||||
Coord4D directionCoord = transmitter.getAdjacentConnectableTransmitterCoord(direction);
|
Coord4D directionCoord = transmitter.getAdjacentConnectableTransmitterCoord(direction);
|
||||||
|
|
||||||
if(!(directionCoord == null || iterated.contains(directionCoord)))
|
if(!(directionCoord == null || iterated.contains(directionCoord)))
|
||||||
{
|
{
|
||||||
iterate(directionCoord, direction.getOpposite());
|
iterate(directionCoord, direction.getOpposite());
|
||||||
|
@ -236,8 +248,8 @@ public class TransmitterNetworkRegistry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
{
|
else {
|
||||||
addNetworkToIterated(from);
|
addNetworkToIterated(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
|
||||||
return sideCoord;
|
return sideCoord;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,14 +87,17 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
|
||||||
public N getExternalNetwork(Coord4D from)
|
public N getExternalNetwork(Coord4D from)
|
||||||
{
|
{
|
||||||
TileEntity tile = from.getTileEntity(world());
|
TileEntity tile = from.getTileEntity(world());
|
||||||
|
|
||||||
if(tile instanceof ITransmitterTile)
|
if(tile instanceof ITransmitterTile)
|
||||||
{
|
{
|
||||||
IGridTransmitter transmitter = ((ITransmitterTile)tile).getTransmitter();
|
IGridTransmitter transmitter = ((ITransmitterTile)tile).getTransmitter();
|
||||||
|
|
||||||
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()));
|
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()));
|
||||||
{
|
{
|
||||||
return ((IGridTransmitter<A, N>)transmitter).getTransmitterNetwork();
|
return ((IGridTransmitter<A, N>)transmitter).getTransmitterNetwork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,5 +295,4 @@ public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork
|
||||||
return buffer.receive(gasStack, doEmit);
|
return buffer.receive(gasStack, doEmit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,7 +254,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
|
||||||
|
|
||||||
public boolean getPossibleAcceptorConnection(ForgeDirection side)
|
public boolean getPossibleAcceptorConnection(ForgeDirection side)
|
||||||
{
|
{
|
||||||
if(handlesRedstone() && redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())))
|
if(handlesRedstone() && redstoneReactive && redstonePowered)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,12 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
public void onWorldJoin()
|
public void onWorldJoin()
|
||||||
{
|
{
|
||||||
super.onWorldJoin();
|
super.onWorldJoin();
|
||||||
|
|
||||||
if(!world().isRemote)
|
if(!world().isRemote)
|
||||||
{
|
{
|
||||||
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
|
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile()));
|
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,13 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
public void onChunkUnload()
|
public void onChunkUnload()
|
||||||
{
|
{
|
||||||
super.onChunkUnload();
|
super.onChunkUnload();
|
||||||
|
|
||||||
if(!world().isRemote)
|
if(!world().isRemote)
|
||||||
{
|
{
|
||||||
getTransmitter().takeShare();
|
getTransmitter().takeShare();
|
||||||
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
getTransmitter().setTransmitterNetwork(null);
|
getTransmitter().setTransmitterNetwork(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,10 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
{
|
{
|
||||||
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
getTransmitter().setTransmitterNetwork(null);
|
getTransmitter().setTransmitterNetwork(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.preRemove();
|
super.preRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,9 +82,10 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
public void markDirtyTransmitters()
|
public void markDirtyTransmitters()
|
||||||
{
|
{
|
||||||
super.markDirtyTransmitters();
|
super.markDirtyTransmitters();
|
||||||
|
|
||||||
if(getTransmitter().hasTransmitterNetwork())
|
if(getTransmitter().hasTransmitterNetwork())
|
||||||
{
|
{
|
||||||
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +93,7 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
public void markDirtyAcceptor(ForgeDirection side)
|
public void markDirtyAcceptor(ForgeDirection side)
|
||||||
{
|
{
|
||||||
super.markDirtyAcceptor(side);
|
super.markDirtyAcceptor(side);
|
||||||
|
|
||||||
if(getTransmitter().hasTransmitterNetwork())
|
if(getTransmitter().hasTransmitterNetwork())
|
||||||
{
|
{
|
||||||
getTransmitter().getTransmitterNetwork().acceptorChanged(getTransmitter(), side);
|
getTransmitter().getTransmitterNetwork().acceptorChanged(getTransmitter(), side);
|
||||||
|
@ -101,10 +103,12 @@ public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends
|
||||||
public A getCachedAcceptor(ForgeDirection side)
|
public A getCachedAcceptor(ForgeDirection side)
|
||||||
{
|
{
|
||||||
ConnectionType type = connectionTypes[side.ordinal()];
|
ConnectionType type = connectionTypes[side.ordinal()];
|
||||||
|
|
||||||
if(type == ConnectionType.PULL || type == ConnectionType.NONE)
|
if(type == ConnectionType.PULL || type == ConnectionType.NONE)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return connectionMapContainsSide(currentAcceptorConnections, side) ? (A)cachedAcceptors[side.ordinal()] : null;
|
return connectionMapContainsSide(currentAcceptorConnections, side) ? (A)cachedAcceptors[side.ordinal()] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue