This commit is contained in:
Aidan C. Brady committed 2015-04-12 17:16:21 -04:00
commit da661af41c
12 files changed
+103 -150

No files matched your search

@@ -35,8 +35,6 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
protected Range4D packetRange = null;
protected int ticksSinceCreate = 0;
protected int capacity = 0;
protected double meanCapacity = 0;
@@ -63,27 +61,10 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
worldObj = transmitter.world();
}
Coord4D coord = transmitter.coord();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
A acceptor = transmitter.getAcceptor(side);
if(acceptor != null)
{
Coord4D acceptorCoord = coord.getFromSide(side);
possibleAcceptors.put(acceptorCoord, acceptor);
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
if(directions != null)
{
directions.add(side.getOpposite());
}
else {
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
}
}
updateTransmitterOnSide(transmitter, side);
}
transmitter.setTransmitterNetwork((N)this);
@@ -103,37 +84,13 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
for(Entry<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> entry : changedAcceptors.entrySet())
{
IGridTransmitter<A, N> transmitter = entry.getKey();
EnumSet<ForgeDirection> directionsChanged = entry.getValue();
for(ForgeDirection side : directionsChanged)
if(transmitter.isValid())
{
A acceptor = transmitter.getAcceptor(side);
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
if(acceptor != null)
EnumSet<ForgeDirection> directionsChanged = entry.getValue();
for(ForgeDirection side : directionsChanged)
{
possibleAcceptors.put(acceptorCoord, acceptor);
if(directions != null)
{
directions.add(side.getOpposite());
}
else {
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
}
}
else {
if(directions != null)
{
directions.remove(side.getOpposite());
if(directions.isEmpty())
{
possibleAcceptors.remove(acceptorCoord);
acceptorDirections.remove(acceptorCoord);
}
}
updateTransmitterOnSide(transmitter, side);
}
}
}
@@ -142,6 +99,45 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
}
public void updateTransmitterOnSide(IGridTransmitter<A, N> transmitter, ForgeDirection side)
{
A acceptor = transmitter.getAcceptor(side);
Coord4D acceptorCoord = transmitter.coord().getFromSide(side);
EnumSet<ForgeDirection> directions = acceptorDirections.get(acceptorCoord);
if(acceptor != null)
{
possibleAcceptors.put(acceptorCoord, acceptor);
if(directions != null)
{
directions.add(side.getOpposite());
}
else {
acceptorDirections.put(acceptorCoord, EnumSet.of(side.getOpposite()));
}
}
else {
if(directions != null)
{
directions.remove(side.getOpposite());
if(directions.isEmpty())
{
possibleAcceptors.remove(acceptorCoord);
acceptorDirections.remove(acceptorCoord);
}
}
else
{
possibleAcceptors.remove(acceptorCoord);
acceptorDirections.remove(acceptorCoord);
}
}
}
public abstract void absorbBuffer(IGridTransmitter<A, N> transmitter);
public abstract void clampBuffer();
@@ -260,7 +260,8 @@ public class TransmitterNetworkRegistry
public void addNetworkToIterated(Coord4D from)
{
networksFound.add(startPoint.getExternalNetwork(from));
N net = startPoint.getExternalNetwork(from);
if(net != null) networksFound.add(net);
}
}
}
@@ -76,6 +76,10 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
{
buffer.amount = getCapacity();
}
if(buffer.amount < 0)
{
buffer.amount = 0;
}
}
@Override
@@ -110,12 +114,12 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
}
double sent = 0;
boolean tryAgain = false;
boolean tryAgain;
int i = 0;
do {
double prev = sent;
sent += doEmit(energyToSend-sent, tryAgain);
sent += doEmit(energyToSend-sent);
tryAgain = energyToSend-sent > 0 && sent-prev > 0 && i < 100;
@@ -139,7 +143,7 @@ public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyN
/**
* @return sent
*/
public double doEmit(double energyToSend, boolean tryAgain)
public double doEmit(double energyToSend)
{
double sent = 0;
@@ -1,6 +1,5 @@
package mekanism.common.content.transporter;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
@@ -19,20 +18,19 @@ public class PathfinderCache
reset();
}
public static ArrayList<Coord4D> getCache(Coord4D start, Coord4D end, EnumSet<ForgeDirection> sides)
public static List<Coord4D> getCache(Coord4D start, Coord4D end, EnumSet<ForgeDirection> sides)
{
ArrayList<Coord4D> ret = null;
List<Coord4D> ret = null;
for(Map.Entry<PathData, List<Coord4D>> entry : cachedPaths.entrySet())
for(ForgeDirection side : sides)
{
PathData data = entry.getKey();
PathData data = new PathData(start, end, side);
List<Coord4D> test = cachedPaths.get(data);
if(data.startTransporter.equals(start) && data.end.equals(end) && sides.contains(data.endSide))
if(ret == null || (test != null && test.size() < ret.size()))
{
if(ret == null || entry.getValue().size() < ret.size())
{
ret = (ArrayList)entry.getValue();
}
ret = test;
}
}
@@ -151,14 +151,14 @@ public final class TransporterPathfinder
public static class Destination implements Comparable<Destination>
{
public List<Coord4D> path = new ArrayList<Coord4D>();
public List<Coord4D> path;
public Path pathType;
public ItemStack rejected;
public double score;
public Destination(ArrayList<Coord4D> list, boolean inv, ItemStack rejects, double gScore)
public Destination(List<Coord4D> list, boolean inv, ItemStack rejects, double gScore)
{
path = (List<Coord4D>)list.clone();
path = new ArrayList<>(list);
if(inv)
{
@@ -253,7 +253,7 @@ public final class TransporterPathfinder
public static Destination getPath(DestChecker checker, EnumSet<ForgeDirection> sides, ILogisticalTransporter start, Coord4D dest, TransporterStack stack, ItemStack rejects, int min)
{
ArrayList<Coord4D> test = PathfinderCache.getCache(start.coord(), dest, sides);
List<Coord4D> test = PathfinderCache.getCache(start.coord(), dest, sides);
if(test != null)
{
@@ -489,7 +489,7 @@ public final class TransporterPathfinder
{
ArrayList<Coord4D> path = new ArrayList<Coord4D>();
path.add(finalNode);
path.addAll((ArrayList<Coord4D>)results.clone());
path.addAll(results);
return path;
}
@@ -37,7 +37,7 @@ public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Tran
@Override
public Coord4D coord()
{
return new Coord4D(getPart().x(), getPart().y(), getPart().z());
return new Coord4D(getPart().x(), getPart().y(), getPart().z(), getPart().world().provider.dimensionId);
}
@Override
@@ -295,4 +295,16 @@ public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork
return buffer.receive(gasStack, doEmit);
}
}
@Override
public IGasHandler getCachedAcceptor(ForgeDirection side)
{
if(cachedAcceptors[side.ordinal()] instanceof IGasHandler)
{
return super.getCachedAcceptor(side);
}
return null;
}
}
@@ -158,6 +158,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, E
super.load(nbtTags);
buffer.amount = nbtTags.getDouble("cacheEnergy");
if(buffer.amount < 0) buffer.amount = 0;
tier = Tier.CableTier.values()[nbtTags.getInteger("tier")];
}
@@ -381,6 +382,13 @@ public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, E
@Override
public EnergyAcceptorWrapper getCachedAcceptor(ForgeDirection side)
{
return EnergyAcceptorWrapper.get(cachedAcceptors[side.ordinal()]);
ConnectionType type = connectionTypes[side.ordinal()];
if(type == ConnectionType.PULL || type == ConnectionType.NONE)
{
return null;
}
return connectionMapContainsSide(currentAcceptorConnections, side) ? EnergyAcceptorWrapper.get(cachedAcceptors[side.ordinal()]) : null;
}
}
@@ -25,30 +25,6 @@ import cofh.api.energy.IEnergyReceiver;
public final class CableUtils
{
private static Set<ForgeDirection> allSides = EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN));
/**
* Gets all the connected energy acceptors, whether IC2-based or BuildCraft-based, surrounding a specific tile entity.
* @param tileEntity - center tile entity
* @return TileEntity[] of connected acceptors
*/
public static TileEntity[] getConnectedEnergyAcceptors(TileEntity tileEntity)
{
TileEntity[] acceptors = new TileEntity[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity acceptor = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
if(isEnergyAcceptor(acceptor))
{
acceptors[orientation.ordinal()] = acceptor;
}
}
return acceptors;
}
public static boolean isEnergyAcceptor(TileEntity tileEntity)
{
return (tileEntity instanceof IStrictEnergyAcceptor ||
@@ -56,28 +32,6 @@ public final class CableUtils
(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver));
}
/**
* Gets all the connected cables around a specific tile entity.
* @param tileEntity - center tile entity
* @return TileEntity[] of connected cables
*/
public static TileEntity[] getConnectedCables(TileEntity tileEntity)
{
TileEntity[] cables = new TileEntity[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity cable = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
if(isCable(cable))
{
cables[orientation.ordinal()] = cable;
}
}
return cables;
}
public static boolean isCable(TileEntity tileEntity)
{
if(tileEntity instanceof ITransmitterTile)
@@ -87,16 +41,6 @@ public final class CableUtils
return false;
}
/**
* Gets all the adjacent connections to a TileEntity.
* @param tileEntity - center TileEntity
* @return boolean[] of adjacent connections
*/
public static boolean[] getConnections(TileEntity tileEntity)
{
return getConnections(tileEntity, allSides);
}
/**
* Gets the adjacent connections to a TileEntity, from a subset of its sides.
* @param tileEntity - center TileEntity
@@ -127,6 +71,11 @@ public final class CableUtils
*/
public static boolean isValidAcceptorOnSide(TileEntity cableEntity, TileEntity tile, ForgeDirection side)
{
if(isCable(tile))
{
return false;
}
if(isEnergyAcceptor(tile) && isConnectable(cableEntity, tile, side))
{
return true;
@@ -164,24 +113,6 @@ public final class CableUtils
(MekanismUtils.useRF() && tileEntity instanceof IEnergyProvider && ((IEnergyConnection)tileEntity).canConnectEnergy(side.getOpposite()));
}
/**
* Whether or not a cable can connect to a specific acceptor.
* @param side - side to check
* @param tile - cable TileEntity
* @return whether or not the cable can connect to the specific side
*/
public static boolean canConnectToAcceptor(ForgeDirection side, TileEntity tile)
{
if(tile == null)
{
return false;
}
TileEntity tileEntity = Coord4D.get(tile).getFromSide(side).getTileEntity(tile.getWorldObj());
return isConnectable(tile, tileEntity, side);
}
public static boolean isConnectable(TileEntity orig, TileEntity tileEntity, ForgeDirection side)
{
if(tileEntity instanceof ITransmitterTile)