Merge pull request #2478 from aidancbrady/networkRefactor

Network Refactor
This commit is contained in:
Aidan 2015-04-06 11:00:45 -04:00
commit 841e358ce0
49 changed files with 2475 additions and 2638 deletions

View file

@ -0,0 +1,201 @@
package mekanism.api.energy;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyReceiver;
import ic2.api.energy.tile.IEnergySink;
public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor
{
public Coord4D coord;
public static EnergyAcceptorWrapper get(TileEntity tileEntity)
{
EnergyAcceptorWrapper wrapper = null;
if(tileEntity instanceof IStrictEnergyAcceptor)
{
wrapper = new MekanismAcceptor((IStrictEnergyAcceptor)tileEntity);
}
else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver)
{
wrapper = new RFAcceptor((IEnergyReceiver)tileEntity);
}
else if(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink)
{
wrapper = new IC2Acceptor((IEnergySink)tileEntity);
}
if(wrapper != null)
{
wrapper.coord = Coord4D.get(tileEntity);
}
return wrapper;
}
public abstract double getNeeded();
public static class MekanismAcceptor extends EnergyAcceptorWrapper
{
private IStrictEnergyAcceptor acceptor;
public MekanismAcceptor(IStrictEnergyAcceptor mekAcceptor)
{
acceptor = mekAcceptor;
}
@Override
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
{
return acceptor.transferEnergyToAcceptor(side, amount);
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return acceptor.canReceiveEnergy(side);
}
@Override
public double getEnergy()
{
return acceptor.getEnergy();
}
@Override
public void setEnergy(double energy)
{
acceptor.setEnergy(energy);
}
@Override
public double getMaxEnergy()
{
return acceptor.getMaxEnergy();
}
@Override
public double getNeeded()
{
return acceptor.getMaxEnergy() - acceptor.getEnergy();
}
}
public static class RFAcceptor extends EnergyAcceptorWrapper
{
private IEnergyReceiver acceptor;
public RFAcceptor(IEnergyReceiver rfAcceptor)
{
acceptor = rfAcceptor;
}
@Override
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
{
return fromRF(acceptor.receiveEnergy(side, toRF(amount), false));
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return acceptor.canConnectEnergy(side);
}
@Override
public double getEnergy()
{
return fromRF(acceptor.getEnergyStored(ForgeDirection.UNKNOWN));
}
@Override
public void setEnergy(double energy)
{
int rfToSet = toRF(energy);
int amountToReceive = rfToSet - acceptor.getEnergyStored(ForgeDirection.UNKNOWN);
acceptor.receiveEnergy(ForgeDirection.UNKNOWN, amountToReceive, false);
}
@Override
public double getMaxEnergy()
{
return fromRF(acceptor.getMaxEnergyStored(ForgeDirection.UNKNOWN));
}
@Override
public double getNeeded()
{
return fromRF(acceptor.getMaxEnergyStored(ForgeDirection.UNKNOWN) - acceptor.getEnergyStored(ForgeDirection.UNKNOWN));
}
public int toRF(double joules)
{
return (int)Math.round(joules * general.TO_TE);
}
public double fromRF(int rf)
{
return rf * general.FROM_TE;
}
}
public static class IC2Acceptor extends EnergyAcceptorWrapper
{
private IEnergySink acceptor;
public IC2Acceptor(IEnergySink ic2Acceptor)
{
acceptor = ic2Acceptor;
}
@Override
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
{
return acceptor.injectEnergy(side, toEU(amount), 0);
}
@Override
public boolean canReceiveEnergy(ForgeDirection side)
{
return acceptor.acceptsEnergyFrom(null, side);
}
@Override
public double getEnergy()
{
return 0;
}
@Override
public void setEnergy(double energy)
{
return;
}
@Override
public double getMaxEnergy()
{
return 0;
}
@Override
public double getNeeded()
{
return fromEU(acceptor.getDemandedEnergy());
}
public double toEU(double joules)
{
return joules * general.TO_IC2;
}
public double fromEU(double eu)
{
return eu * general.FROM_IC2;
}
}
}

View file

@ -0,0 +1,14 @@
package mekanism.api.energy;
/**
* Created by ben on 27/03/15.
*/
public class EnergyStack
{
public double amount;
public EnergyStack(double newAmount)
{
amount = newAmount;
}
}

View file

@ -1,20 +1,20 @@
package mekanism.api.gas;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterNetwork;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.util.ListUtils;
import mekanism.common.Mekanism;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
@ -38,24 +38,14 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
public Gas refGas;
public GasStack gasStored;
public GasStack buffer;
public int prevStored;
public int prevTransferAmount = 0;
public GasNetwork(IGridTransmitter<GasNetwork>... varPipes)
{
transmitters.addAll(Arrays.asList(varPipes));
register();
}
public GasNetwork() {}
public GasNetwork(Collection<IGridTransmitter<GasNetwork>> collection)
{
transmitters.addAll(collection);
register();
}
public GasNetwork(Set<GasNetwork> networks)
public GasNetwork(Collection<GasNetwork> networks)
{
for(GasNetwork net : networks)
{
@ -67,32 +57,37 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
{
gasScale = net.gasScale;
refGas = net.refGas;
gasStored = net.gasStored;
buffer = net.buffer;
net.gasScale = 0;
net.refGas = null;
net.gasStored = null;
net.buffer = null;
}
}
else {
if(net.gasStored != null)
} else
{
if(net.buffer != null)
{
if(gasStored == null)
if(buffer == null)
{
gasStored = net.gasStored;
}
else {
if(gasStored.isGasEqual(net.gasStored))
buffer = net.buffer.copy();
} else
{
if(buffer.isGasEqual(net.buffer))
{
gasStored.amount += net.gasStored.amount;
buffer.amount += net.buffer.amount;
}
else if(net.buffer.amount > buffer.amount)
{
buffer = net.buffer.copy();
}
}
net.gasStored = null;
net.buffer = null;
}
}
addAllTransmitters(net.transmitters);
adoptTransmittersAndAcceptorsFrom(net);
net.deregister();
}
}
@ -103,48 +98,47 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
}
@Override
public void onNetworksCreated(List<GasNetwork> networks)
public void absorbBuffer(IGridTransmitter<IGasHandler, GasNetwork> transmitter)
{
if(gasStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer())
Object b = transmitter.getBuffer();
if(!(b instanceof GasStack) || ((GasStack)b).getGas() == null || ((GasStack)b).amount == 0)
{
int[] caps = new int[networks.size()];
int cap = 0;
for(GasNetwork network : networks)
{
caps[networks.indexOf(network)] = network.getCapacity();
cap += network.getCapacity();
}
gasStored.amount = Math.min(cap, gasStored.amount);
int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), gasStored.amount);
for(GasNetwork network : networks)
{
int index = networks.indexOf(network);
if(values[index] > 0)
{
network.gasStored = new GasStack(gasStored.getGas(), values[index]);
network.refGas = gasStored.getGas();
}
}
return;
}
gasScale = 0;
refGas = null;
gasStored = null;
GasStack gas = (GasStack)b;
if(buffer == null || buffer.getGas() == null || buffer.amount == 0)
{
buffer = gas.copy();
return;
}
if(!gas.isGasEqual(buffer)) Mekanism.logger.warn("Gas type " + gas.getGas().getName() + " of buffer doesn't match type " + buffer.getGas().getName() + " of absorbing network");
buffer.amount += gas.amount;
gas.amount = 0;
}
public synchronized int getGasNeeded()
@Override
public void clampBuffer()
{
return getCapacity()-(gasStored != null ? gasStored.amount : 0);
if(buffer != null && buffer.amount > getCapacity())
{
buffer.amount = capacity;
}
}
public synchronized int tickEmit(GasStack stack)
public int getGasNeeded()
{
List availableAcceptors = Arrays.asList(getAcceptors(stack.getGas()).toArray());
return getCapacity()-(buffer != null ? buffer.amount : 0);
}
public int tickEmit(GasStack stack)
{
List<IGasHandler> availableAcceptors = new ArrayList<>();
availableAcceptors.addAll(getAcceptors(stack.getGas()));
Collections.shuffle(availableAcceptors);
@ -157,30 +151,26 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
int remaining = toSend % divider;
int sending = (toSend-remaining)/divider;
for(Object obj : availableAcceptors)
for(IGasHandler acceptor : availableAcceptors)
{
if(obj instanceof IGasHandler)
int currentSending = sending;
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor));
if(remaining > 0)
{
IGasHandler acceptor = (IGasHandler)obj;
int currentSending = sending;
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor));
currentSending++;
remaining--;
}
if(remaining > 0)
{
currentSending++;
remaining--;
}
for(ForgeDirection side : sides)
{
int prev = toSend;
for(ForgeDirection side : sides)
toSend -= acceptor.receiveGas(side, new GasStack(stack.getGas(), currentSending), true);
if(toSend < prev)
{
int prev = toSend;
toSend -= acceptor.receiveGas(side.getOpposite(), new GasStack(stack.getGas(), currentSending), true);
if(toSend < prev)
{
break;
}
break;
}
}
}
@ -197,9 +187,9 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
return sent;
}
public synchronized int emit(GasStack stack, boolean doTransfer)
public int emit(GasStack stack, boolean doTransfer)
{
if(gasStored != null && gasStored.getGas() != stack.getGas())
if(buffer != null && buffer.getGas() != stack.getGas())
{
return 0;
}
@ -208,13 +198,13 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
if(doTransfer)
{
if(gasStored == null)
if(buffer == null)
{
gasStored = stack.copy();
gasStored.amount = toUse;
buffer = stack.copy();
buffer.amount = toUse;
}
else {
gasStored.amount += toUse;
buffer.amount += toUse;
}
}
@ -238,7 +228,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
transferDelay--;
}
int stored = gasStored != null ? gasStored.amount : 0;
int stored = buffer != null ? buffer.amount : 0;
if(stored != prevStored)
{
@ -249,20 +239,20 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
if(didTransfer != prevTransfer || needsUpdate)
{
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, gasStored, didTransfer));
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, buffer, didTransfer));
needsUpdate = false;
}
prevTransfer = didTransfer;
if(gasStored != null)
if(buffer != null)
{
prevTransferAmount = tickEmit(gasStored);
gasStored.amount -= prevTransferAmount;
prevTransferAmount = tickEmit(buffer);
buffer.amount -= prevTransferAmount;
if(gasStored.amount <= 0)
if(buffer.amount <= 0)
{
gasStored = null;
buffer = null;
}
}
}
@ -285,15 +275,15 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
if(gasScale == 0)
{
gasStored = null;
buffer = null;
}
}
}
@Override
public synchronized Set<IGasHandler> getAcceptors(Object... data)
public Set<IGasHandler> getAcceptors(Object data)
{
Gas type = (Gas)data[0];
Gas type = (Gas)data;
Set<IGasHandler> toReturn = new HashSet<IGasHandler>();
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
@ -313,7 +303,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
for(ForgeDirection side : sides)
{
if(acceptor != null && acceptor.canReceiveGas(side.getOpposite(), type))
if(acceptor != null && acceptor.canReceiveGas(side, type))
{
toReturn.add(acceptor);
break;
@ -324,47 +314,6 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
return toReturn;
}
@Override
public synchronized void refresh()
{
Set<IGridTransmitter<GasNetwork>> iterTubes = (Set<IGridTransmitter<GasNetwork>>)transmitters.clone();
Iterator<IGridTransmitter<GasNetwork>> it = iterTubes.iterator();
while(it.hasNext())
{
IGridTransmitter<GasNetwork> conductor = it.next();
if(conductor == null || conductor.getTile().isInvalid())
{
removeTransmitter(conductor);
}
else {
conductor.setTransmitterNetwork(this);
}
}
needsUpdate = true;
}
@Override
public synchronized void refresh(IGridTransmitter<GasNetwork> transmitter)
{
IGasHandler[] acceptors = GasTransmission.getConnectedAcceptors(transmitter.getTile());
clearAround(transmitter);
for(IGasHandler acceptor : acceptors)
{
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
{
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
addSide(Coord4D.get((TileEntity)acceptor), ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
}
}
}
public static class GasTransferEvent extends Event
{
public final GasNetwork gasNetwork;
@ -382,7 +331,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
public float getScale()
{
return Math.min(1, (gasStored == null || getCapacity() == 0 ? 0 : (float)gasStored.amount/getCapacity()));
return Math.min(1, (buffer == null || getCapacity() == 0 ? 0 : (float)buffer.amount/getCapacity()));
}
@Override
@ -391,64 +340,6 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
return "[GasNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
}
@Override
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks)
{
Gas found = null;
for(ITransmitterNetwork<?, ?> network : networks)
{
if(network instanceof GasNetwork)
{
GasNetwork net = (GasNetwork)network;
if(net.gasStored != null)
{
if(found != null && found != net.gasStored.getGas())
{
return false;
}
found = net.gasStored.getGas();
}
}
}
return true;
}
@Override
protected GasNetwork create(Collection<IGridTransmitter<GasNetwork>> collection)
{
GasNetwork network = new GasNetwork(collection);
network.refGas = refGas;
if(gasStored != null)
{
if(network.gasStored == null)
{
network.gasStored = gasStored;
}
else {
if(network.gasStored.isGasEqual(gasStored))
{
network.gasStored.amount += gasStored.amount;
}
}
}
network.gasScale = network.getScale();
network.updateCapacity();
return network;
}
@Override
public TransmissionType getTransmissionType()
{
return TransmissionType.GAS;
}
@Override
public String getNeededInfo()
{
@ -458,7 +349,7 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
@Override
public String getStoredInfo()
{
return gasStored != null ? gasStored.getGas().getLocalizedName() + " (" + gasStored.amount + ")" : "None";
return buffer != null ? buffer.getGas().getLocalizedName() + " (" + buffer.amount + ")" : "None";
}
@Override

View file

@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@ -18,28 +19,6 @@ import net.minecraftforge.common.util.ForgeDirection;
*/
public final class GasTransmission
{
/**
* Gets all the tubes around a tile entity.
* @param tileEntity - center tile entity
* @return array of TileEntities
*/
public static TileEntity[] getConnectedTubes(TileEntity tileEntity)
{
TileEntity[] tubes = new TileEntity[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tube = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
if(TransmissionType.checkTransmissionType(tube, TransmissionType.GAS, tileEntity))
{
tubes[orientation.ordinal()] = tube;
}
}
return tubes;
}
/**
* Gets all the acceptors around a tile entity.
* @param tileEntity - center tile entity
@ -92,7 +71,7 @@ public final class GasTransmission
*/
public static boolean canConnect(TileEntity tileEntity, ForgeDirection side)
{
if(tileEntity instanceof ITubeConnection && (!(tileEntity instanceof IGasTransmitter) || TransmissionType.checkTransmissionType(tileEntity, TransmissionType.GAS, tileEntity)))
if(tileEntity instanceof ITubeConnection && (!(tileEntity instanceof ITransmitterTile) || TransmissionType.checkTransmissionType(((ITransmitterTile)tileEntity).getTransmitter(), TransmissionType.GAS)))
{
if(((ITubeConnection)tileEntity).canTubeConnect(side.getOpposite()))
{

View file

@ -4,7 +4,7 @@ import mekanism.api.transmitters.IGridTransmitter;
import net.minecraft.tileentity.TileEntity;
public interface IGasTransmitter extends IGridTransmitter<GasNetwork>
public interface IGasTransmitter extends IGridTransmitter<IGasHandler, GasNetwork>
{
public boolean canTransferGasToTube(TileEntity tile);
}

View file

@ -3,17 +3,17 @@ package mekanism.api.transmitters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import mekanism.api.Coord4D;
import mekanism.api.IClientTicker;
import mekanism.api.Range4D;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -22,96 +22,178 @@ import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements ITransmitterNetwork<A, N>, IClientTicker, INetworkDataHandler
import scala.collection.parallel.ParIterableLike.Collect;
public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implements IClientTicker, INetworkDataHandler
{
public LinkedHashSet<IGridTransmitter<N>> transmitters = new LinkedHashSet<IGridTransmitter<N>>();
public LinkedHashSet<IGridTransmitter<A, N>> transmitters = new LinkedHashSet<>();
public LinkedHashSet<IGridTransmitter<A, N>> transmittersToAdd = new LinkedHashSet<>();
public LinkedHashSet<IGridTransmitter<A, N>> transmittersAdded = new LinkedHashSet<>();
public ConcurrentHashMap<Coord4D, A> possibleAcceptors = new ConcurrentHashMap<Coord4D, A>();
public ConcurrentHashMap<Coord4D, EnumSet<ForgeDirection>> acceptorDirections = new ConcurrentHashMap<Coord4D, EnumSet<ForgeDirection>>();
public HashMap<Coord4D, A> possibleAcceptors = new HashMap<Coord4D, A>();
public HashMap<Coord4D, EnumSet<ForgeDirection>> acceptorDirections = new HashMap<Coord4D, EnumSet<ForgeDirection>>();
public HashMap<IGridTransmitter<A, N>, EnumSet<ForgeDirection>> changedAcceptors = new HashMap<>();
private Set<DelayQueue> updateQueue = new LinkedHashSet<DelayQueue>();
private List<DelayQueue> updateQueue = new ArrayList<DelayQueue>();
protected Range4D packetRange = null;
protected int ticksSinceCreate = 0;
protected int capacity = 0;
protected double meanCapacity = 0;
protected boolean fixed = false;
protected boolean needsUpdate = false;
protected int updateDelay = 0;
protected abstract ITransmitterNetwork<A, N> create(Collection<IGridTransmitter<N>> collection);
protected boolean firstUpdate = true;
protected World worldObj = null;
protected void clearAround(IGridTransmitter<N> transmitter)
public void addNewTransmitters(Collection<IGridTransmitter<A, N>> newTransmitters)
{
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
transmittersToAdd.addAll(newTransmitters);
}
public void commit()
{
if(!transmittersToAdd.isEmpty())
{
Coord4D coord = Coord4D.get(transmitter.getTile()).getFromSide(side);
if(possibleAcceptors.containsKey(coord))
for(IGridTransmitter<A, N> transmitter : transmittersToAdd)
{
clearIfNecessary(coord, transmitter, side.getOpposite());
}
}
}
protected void clearIfNecessary(Coord4D acceptor, IGridTransmitter<N> transmitter, ForgeDirection side)
{
if(getWorld() == null)
{
return;
}
World world = getWorld();
if(acceptor.getTileEntity(world) == null || acceptor.getTileEntity(world).isInvalid() || !transmitter.canConnectToAcceptor(side, true))
{
acceptorDirections.get(acceptor).remove(side.getOpposite());
if(acceptorDirections.get(acceptor).isEmpty())
{
possibleAcceptors.remove(acceptor);
if(transmitter.isValid())
{
if(worldObj == null) 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()));
}
}
}
transmitter.setTransmitterNetwork((N)this);
absorbBuffer(transmitter);
transmitters.add(transmitter);
}
}
updateCapacity();
clampBuffer();
queueClientUpdate(new ArrayList<>(transmittersToAdd));
transmittersToAdd.clear();
}
if(!changedAcceptors.isEmpty())
{
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)
{
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);
}
}
}
}
}
changedAcceptors.clear();
}
}
public abstract void absorbBuffer(IGridTransmitter<A, N> transmitter);
public abstract void clampBuffer();
public void invalidate()
{
for(IGridTransmitter<A, N> transmitter : transmitters)
{
invalidateTransmitter(transmitter);
}
transmitters.clear();
deregister();
}
public void invalidateTransmitter(IGridTransmitter<A, N> transmitter)
{
if(!worldObj.isRemote && transmitter.isValid())
{
transmitter.takeShare();
transmitter.setTransmitterNetwork(null);
TransmitterNetworkRegistry.registerOrphanTransmitter(transmitter);
}
}
public void acceptorChanged(IGridTransmitter<A, N> transmitter, ForgeDirection side)
{
EnumSet<ForgeDirection> directions = changedAcceptors.get(transmitter);
if(directions != null)
{
directions.add(side);
} else
{
changedAcceptors.put(transmitter, EnumSet.of(side));
}
TransmitterNetworkRegistry.registerChangedNetwork(this);
}
public void adoptTransmittersAndAcceptorsFrom(N net)
{
for(IGridTransmitter<A, N> transmitter : net.transmitters)
{
transmitter.setTransmitterNetwork((N)this);
transmitters.add(transmitter);
transmittersAdded.add(transmitter);
}
possibleAcceptors.putAll(net.possibleAcceptors);
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
{
Coord4D coord = entry.getKey();
if(acceptorDirections.containsKey(coord))
{
acceptorDirections.get(coord).addAll(entry.getValue());
}
else
{
acceptorDirections.put(coord, entry.getValue());
}
}
}
public void addAllTransmitters(Set<IGridTransmitter<N>> newTransmitters)
{
transmitters.addAll(newTransmitters);
updateCapacity();
}
public boolean isFirst(IGridTransmitter<N> transmitter)
{
return transmitters.iterator().next().equals(transmitter);
}
public void addSide(Coord4D acceptor, ForgeDirection side)
{
if(acceptorDirections.get(acceptor) == null)
{
acceptorDirections.put(acceptor, EnumSet.noneOf(ForgeDirection.class));
}
acceptorDirections.get(acceptor).add(side);
}
@Override
public void fullRefresh()
{
possibleAcceptors.clear();
acceptorDirections.clear();
for(IGridTransmitter<N> transmitter : transmitters)
{
refresh(transmitter);
}
refresh();
}
public Range4D getPacketRange()
{
if(packetRange == null)
@ -122,16 +204,6 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
return packetRange;
}
public World getWorld()
{
if(getSize() == 0)
{
return null;
}
return transmitters.iterator().next().getTile().getWorldObj();
}
protected Range4D genPacketRange()
{
if(getSize() == 0)
@ -139,8 +211,9 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
deregister();
return null;
}
Coord4D initCoord = Coord4D.get(transmitters.iterator().next().getTile());
IGridTransmitter<A, N> initTransmitter = transmitters.iterator().next();
Coord4D initCoord = initTransmitter.coord();
int minX = initCoord.xCoord;
int minY = initCoord.yCoord;
@ -151,7 +224,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
for(IGridTransmitter transmitter : transmitters)
{
Coord4D coord = Coord4D.get(transmitter.getTile());
Coord4D coord = transmitter.coord();
if(coord.xCoord < minX) minX = coord.xCoord;
if(coord.yCoord < minY) minY = coord.yCoord;
@ -161,41 +234,20 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
if(coord.zCoord > maxZ) maxZ = coord.zCoord;
}
return new Range4D(minX, minY, minZ, maxX, maxY, maxZ, getWorld().provider.dimensionId);
return new Range4D(minX, minY, minZ, maxX, maxY, maxZ, initTransmitter.world().provider.dimensionId);
}
@Override
public void removeTransmitter(IGridTransmitter<N> transmitter)
public void register()
{
transmitters.remove(transmitter);
updateCapacity();
if(transmitters.size() == 0)
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
{
deregister();
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
}
else {
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte)1));
}
}
@Override
public void register()
{
try {
IGridTransmitter<N> aTransmitter = transmitters.iterator().next();
if(aTransmitter instanceof TileEntity)
{
if(!((TileEntity)aTransmitter).getWorldObj().isRemote)
{
TransmitterNetworkRegistry.getInstance().registerNetwork(this);
}
else {
MinecraftForge.EVENT_BUS.post(new ClientTickUpdate(this, (byte)1));
}
}
} catch(NoSuchElementException e) {}
}
@Override
public void deregister()
{
transmitters.clear();
@ -209,13 +261,11 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
}
@Override
public int getSize()
{
return transmitters.size();
}
@Override
public int getAcceptorSize()
{
return possibleAcceptors.size();
@ -247,38 +297,16 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
return capacity;
}
public double getMeanCapacity()
{
return meanCapacity;
}
@Override
public World getWorld()
{
return worldObj;
}
public abstract Set<A> getAcceptors(Object data);
public void tick()
{
boolean didFix = false;
if(!fixed)
{
ticksSinceCreate++;
if(transmitters.size() == 0)
{
deregister();
return;
}
if(ticksSinceCreate > 1200)
{
ticksSinceCreate = 0;
fixMessedUpNetwork(transmitters.iterator().next());
didFix = true;
}
}
if(!didFix)
{
onUpdate();
}
onUpdate();
}
public void onUpdate()
@ -287,7 +315,8 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
Iterator<DelayQueue> i = updateQueue.iterator();
try {
try
{
while(i.hasNext())
{
DelayQueue q = i.next();
@ -295,133 +324,32 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
if(q.delay > 0)
{
q.delay--;
}
else {
needsUpdate = true;
} else
{
transmittersAdded.addAll(transmitters);
updateDelay = 1;
i.remove();
}
}
} catch(Exception e) {}
} catch(Exception e)
{
}
if(updateDelay > 0)
{
updateDelay--;
if(updateDelay == 0)
{
MinecraftForge.EVENT_BUS.post(new TransmittersAddedEvent(this, firstUpdate, (Collection)transmittersAdded));
firstUpdate = false;
transmittersAdded.clear();
needsUpdate = true;
}
}
}
}
@Override
public synchronized void fixMessedUpNetwork(IGridTransmitter<N> transmitter)
{
if(transmitter instanceof TileEntity)
{
NetworkFinder finder = new NetworkFinder(((TileEntity)transmitter).getWorldObj(), getTransmissionType(), Coord4D.get((TileEntity)transmitter));
List<Coord4D> partNetwork = finder.exploreNetwork();
Set<IGridTransmitter<N>> newTransporters = new HashSet<IGridTransmitter<N>>();
for(Coord4D node : partNetwork)
{
TileEntity nodeTile = node.getTileEntity(((TileEntity)transmitter).getWorldObj());
if(TransmissionType.checkTransmissionType(nodeTile, getTransmissionType(), (TileEntity)transmitter))
{
((IGridTransmitter<N>)nodeTile).removeFromTransmitterNetwork();
newTransporters.add((IGridTransmitter<N>)nodeTile);
}
}
ITransmitterNetwork<A, N> newNetwork = create(newTransporters);
newNetwork.fullRefresh();
newNetwork.setFixed(true);
deregister();
}
}
@Override
public synchronized void split(IGridTransmitter<N> splitPoint)
{
if(splitPoint instanceof TileEntity)
{
removeTransmitter(splitPoint);
TileEntity[] connectedBlocks = new TileEntity[6];
boolean[] dealtWith = {false, false, false, false, false, false};
List<ITransmitterNetwork<A, N>> newNetworks = new ArrayList<ITransmitterNetwork<A, N>>();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity sideTile = Coord4D.get((TileEntity)splitPoint).getFromSide(side).getTileEntity(((TileEntity)splitPoint).getWorldObj());
if(sideTile != null)
{
connectedBlocks[side.ordinal()] = sideTile;
}
}
for(int count = 0; count < connectedBlocks.length; count++)
{
TileEntity connectedBlockA = connectedBlocks[count];
if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[count] && transmitters.contains(connectedBlockA))
{
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).getWorldObj(), getTransmissionType(), Coord4D.get(connectedBlockA), Coord4D.get((TileEntity)splitPoint));
List<Coord4D> partNetwork = finder.exploreNetwork();
for(int check = count; check < connectedBlocks.length; check++)
{
if(check == count)
{
continue;
}
TileEntity connectedBlockB = connectedBlocks[check];
if(TransmissionType.checkTransmissionType(connectedBlockB, getTransmissionType()) && !dealtWith[check])
{
if(partNetwork.contains(Coord4D.get(connectedBlockB)))
{
dealtWith[check] = true;
}
}
}
Set<IGridTransmitter<N>> newNetCables = new HashSet<IGridTransmitter<N>>();
for(Coord4D node : finder.iterated)
{
TileEntity nodeTile = node.getTileEntity(((TileEntity)splitPoint).getWorldObj());
if(TransmissionType.checkTransmissionType(nodeTile, getTransmissionType()))
{
if(nodeTile != splitPoint)
{
newNetCables.add((IGridTransmitter<N>)nodeTile);
}
}
}
newNetworks.add(create(newNetCables));
}
}
if(newNetworks.size() > 0)
{
onNetworksCreated((List)newNetworks);
for(ITransmitterNetwork<A, N> network : newNetworks)
{
network.fullRefresh();
}
}
deregister();
}
}
@Override
public void onNetworksCreated(List<N> networks) {}
@Override
public void setFixed(boolean value)
{
fixed = value;
}
@Override
public boolean needsTicks()
{
@ -429,21 +357,26 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
}
@Override
public void clientTick()
{
ticksSinceCreate++;
public void clientTick() {}
if(ticksSinceCreate == 5 && getSize() > 0)
{
TileEntity tile = (TileEntity)transmitters.iterator().next();
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile));
}
public void queueClientUpdate(Collection<IGridTransmitter<A, N>> newTransmitters)
{
transmittersAdded.addAll(newTransmitters);
updateDelay = 3;
}
@Override
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks)
public static class TransmittersAddedEvent extends Event
{
return true;
public DynamicNetwork<?, ?> network;
public boolean newNetwork;
public Collection<IGridTransmitter> newTransmitters;
public TransmittersAddedEvent(DynamicNetwork net, boolean newNet, Collection<IGridTransmitter> added)
{
network = net;
newNetwork = newNet;
newTransmitters = added;
}
}
public static class ClientTickUpdate extends Event
@ -473,69 +406,6 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
updateQueue.add(new DelayQueue(player));
}
public static class NetworkFinder
{
public TransmissionType transmissionType;
public World worldObj;
public Coord4D start;
public List<Coord4D> iterated = new ArrayList<Coord4D>();
public List<Coord4D> toIgnore = new ArrayList<Coord4D>();
public NetworkFinder(World world, TransmissionType type, Coord4D location, Coord4D... ignore)
{
worldObj = world;
start = location;
transmissionType = type;
if(ignore != null)
{
for(int i = 0; i < ignore.length; i++)
{
toIgnore.add(ignore[i]);
}
}
}
public void loopAll(Coord4D location)
{
if(TransmissionType.checkTransmissionType(location.getTileEntity(worldObj), transmissionType))
{
iterated.add(location);
}
else {
toIgnore.add(location);
}
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
Coord4D obj = location.getFromSide(direction);
if(!iterated.contains(obj) && !toIgnore.contains(obj))
{
TileEntity tileEntity = obj.getTileEntity(worldObj);
if(!(tileEntity instanceof IBlockableConnection) || ((IBlockableConnection)tileEntity).canConnectMutual(direction.getOpposite()))
{
if(TransmissionType.checkTransmissionType(tileEntity, transmissionType, location.getTileEntity(worldObj)))
{
loopAll(obj);
}
}
}
}
}
public List<Coord4D> exploreNetwork()
{
loopAll(start);
return iterated;
}
}
public static class DelayQueue
{
public EntityPlayer player;
@ -546,5 +416,17 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
player = p;
delay = 5;
}
@Override
public int hashCode()
{
return player.hashCode();
}
@Override
public boolean equals(Object o)
{
return o instanceof DelayQueue && ((DelayQueue)o).player.equals(this.player);
}
}
}

View file

@ -1,56 +1,28 @@
package mekanism.api.transmitters;
import net.minecraft.tileentity.TileEntity;
import java.util.Collection;
import mekanism.api.Coord4D;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITransmitter
public interface IGridTransmitter<A, N extends DynamicNetwork<A, N>> extends ITransmitter
{
public boolean hasTransmitterNetwork();
/**
* Gets the network currently in use by this transmitter segment.
* @return network this transmitter is using
*/
public N getTransmitterNetwork();
/**
* Gets the network currently in use by this transmitter segment.
* @param createIfNull - If true, the transmitter will try and connect to an
* adjacent network, merging several if necessary, or creating a new one
* if none is available
* @return network this transmitter is using
*/
public N getTransmitterNetwork(boolean createIfNull);
/**
* Sets this transmitter segment's network to a new value.
* @param network - network to set to
*/
public void setTransmitterNetwork(N network);
/**
* Refreshes the transmitter's network.
*/
public void refreshTransmitterNetwork();
/**
* Called when the chunk this transmitter is in is loaded.
*/
public void chunkLoad();
/**
* Remove this transmitter from its network.
*/
public void removeFromTransmitterNetwork();
public boolean canConnectToAcceptor(ForgeDirection side, boolean ignoreActive);
/**
* Call this if you're worried a transmitter's network is messed up and you want
* it to try and fix itself.
*/
public void fixTransmitterNetwork();
public boolean areTransmitterNetworksEqual(TileEntity tileEntity);
public int getTransmitterNetworkSize();
public int getTransmitterNetworkAcceptorSize();
@ -59,7 +31,33 @@ public interface IGridTransmitter<N extends DynamicNetwork<?, N>> extends ITrans
public String getTransmitterNetworkFlow();
public String getTransmitterNetworkBuffer();
public double getTransmitterNetworkCapacity();
public int getCapacity();
public World world();
public TileEntity getTile();
public Coord4D coord();
public Coord4D getAdjacentConnectableTransmitterCoord(ForgeDirection side);
public A getAcceptor(ForgeDirection side);
public boolean isValid();
public boolean isOrphan();
public void setOrphan(boolean orphaned);
public N createEmptyNetwork();
public N mergeNetworks(Collection<N> toMerge);
public N getExternalNetwork(Coord4D from);
public void takeShare();
public Object getBuffer();
}

View file

@ -1,39 +0,0 @@
package mekanism.api.transmitters;
import java.util.List;
import java.util.Set;
public interface ITransmitterNetwork<A, N extends DynamicNetwork<A, N>>
{
public void tick();
public int getSize();
public int getAcceptorSize();
public Set<A> getAcceptors(Object... data);
public void removeTransmitter(IGridTransmitter<N> transmitter);
public void refresh();
public void fullRefresh();
public void refresh(IGridTransmitter<N> transmitter);
public void split(IGridTransmitter<N> splitPoint);
public void fixMessedUpNetwork(IGridTransmitter<N> transmitter);
public void register();
public void deregister();
public void setFixed(boolean value);
public TransmissionType getTransmissionType();
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks);
public void onNetworksCreated(List<N> networks);
}

View file

@ -0,0 +1,6 @@
package mekanism.api.transmitters;
public interface ITransmitterTile<A, N extends DynamicNetwork<A, N>>
{
public IGridTransmitter<A, N> getTransmitter();
}

View file

@ -36,14 +36,14 @@ public enum TransmissionType
return StatCollector.translateToLocal("transmission." + getTransmission());
}
public static boolean checkTransmissionType(TileEntity sideTile, TransmissionType type)
public static boolean checkTransmissionType(ITransmitter sideTile, TransmissionType type)
{
return checkTransmissionType(sideTile, type, null);
return type.checkTransmissionType(sideTile);
}
public static boolean checkTransmissionType(TileEntity sideTile, TransmissionType type, TileEntity currentPipe)
public boolean checkTransmissionType(ITransmitter transmitter)
{
return type.checkTransmissionType(sideTile, currentPipe);
return transmitter.getTransmissionType() == this;
}
public boolean checkTransmissionType(TileEntity sideTile, TileEntity currentTile)

View file

@ -2,14 +2,11 @@ package mekanism.api.transmitters;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkEvent;
import mekanism.api.Coord4D;
import mekanism.common.Mekanism;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
@ -21,7 +18,11 @@ public class TransmitterNetworkRegistry
private static TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry();
private static boolean loaderRegistered = false;
private HashSet<ITransmitterNetwork> networks = new HashSet<ITransmitterNetwork>();
private HashSet<DynamicNetwork> networks = new HashSet<>();
private HashSet<DynamicNetwork> networksToChange = new HashSet<>();
private HashSet<IGridTransmitter> invalidTransmitters = new HashSet<>();
private HashMap<Coord4D, IGridTransmitter> orphanTransmitters = new HashMap<>();
public static void initiate()
{
@ -29,22 +30,44 @@ public class TransmitterNetworkRegistry
{
loaderRegistered = true;
MinecraftForge.EVENT_BUS.register(new NetworkLoader());
FMLCommonHandler.instance().bus().register(INSTANCE);
}
}
public static void reset()
{
getInstance().networks.clear();
getInstance().networksToChange.clear();
getInstance().invalidTransmitters.clear();
getInstance().orphanTransmitters.clear();
}
public static void invalidateTransmitter(IGridTransmitter transmitter)
{
getInstance().invalidTransmitters.add(transmitter);
}
public static void registerOrphanTransmitter(IGridTransmitter transmitter)
{
getInstance().orphanTransmitters.put(transmitter.coord(), transmitter);
}
public static void registerChangedNetwork(DynamicNetwork network)
{
getInstance().networksToChange.add(network);
}
public static TransmitterNetworkRegistry getInstance()
{
return INSTANCE;
}
public void registerNetwork(ITransmitterNetwork network)
public void registerNetwork(DynamicNetwork network)
{
networks.add(network);
}
public void removeNetwork(ITransmitterNetwork network)
public void removeNetwork(DynamicNetwork network)
{
if(networks.contains(network))
{
@ -52,19 +75,6 @@ public class TransmitterNetworkRegistry
}
}
public void pruneEmptyNetworks()
{
HashSet<ITransmitterNetwork> copySet = new HashSet<ITransmitterNetwork>(networks);
for(ITransmitterNetwork e : copySet)
{
if(e.getSize() == 0)
{
removeNetwork(e);
}
}
}
@SubscribeEvent
public void onTick(ServerTickEvent event)
{
@ -76,15 +86,90 @@ public class TransmitterNetworkRegistry
public void tickEnd()
{
Set<ITransmitterNetwork> iterNetworks = (Set<ITransmitterNetwork>)networks.clone();
removeInvalidTransmitters();
for(ITransmitterNetwork net : iterNetworks)
assignOrphans();
commitChanges();
for(DynamicNetwork net : networks)
{
if(networks.contains(net))
net.tick();
}
}
public void removeInvalidTransmitters()
{
if(!invalidTransmitters.isEmpty())
{
Mekanism.logger.debug("Dealing with " + invalidTransmitters.size() + " invalid Transmitters");
}
for(IGridTransmitter invalid : invalidTransmitters)
{
if(!invalid.isOrphan())
{
net.tick();
DynamicNetwork n = invalid.getTransmitterNetwork();
if(n != null)
{
n.invalidate();
}
}
}
invalidTransmitters.clear();
}
public void assignOrphans()
{
if(!orphanTransmitters.isEmpty())
{
Mekanism.logger.debug("Dealing with " + orphanTransmitters.size() + " orphan Transmitters");
}
for(IGridTransmitter orphanTransmitter : orphanTransmitters.values())
{
DynamicNetwork network = getNetworkFromOrphan(orphanTransmitter);
if(network != null)
{
networksToChange.add(network);
network.register();
}
}
orphanTransmitters.clear();
}
public <A, N extends DynamicNetwork<A, N>> DynamicNetwork<A, N> getNetworkFromOrphan(IGridTransmitter<A, N> startOrphan)
{
if(startOrphan.isValid() && startOrphan.isOrphan())
{
OrphanPathFinder<A, N> finder = new OrphanPathFinder<>(startOrphan);
finder.start();
N network;
switch(finder.networksFound.size())
{
case 0:
Mekanism.logger.debug("No networks found. Creating new network");
network = startOrphan.createEmptyNetwork();
break;
case 1:
Mekanism.logger.debug("Using single found network");
network = finder.networksFound.iterator().next();
break;
default:
Mekanism.logger.debug("Merging " + finder.networksFound.size() + " networks");
network = startOrphan.mergeNetworks(finder.networksFound);
}
network.addNewTransmitters(finder.connectedTransmitters);
return network;
}
return null;
}
public void commitChanges()
{
for(DynamicNetwork network : networksToChange)
{
network.commit();
}
networksToChange.clear();
}
@Override
@ -98,7 +183,7 @@ public class TransmitterNetworkRegistry
String[] strings = new String[networks.size()];
int i = 0;
for(ITransmitterNetwork<?, ?> network : networks)
for(DynamicNetwork network : networks)
{
strings[i] = network.toString();
++i;
@ -107,54 +192,59 @@ public class TransmitterNetworkRegistry
return strings;
}
public static class NetworkLoader
public class OrphanPathFinder<A, N extends DynamicNetwork<A, N>>
{
@SubscribeEvent
public void onChunkLoad(ChunkEvent.Load event)
public IGridTransmitter<A, N> startPoint;
public HashSet<Coord4D> iterated = new HashSet<>();
public HashSet<IGridTransmitter<A, N>> connectedTransmitters = new HashSet<>();
public HashSet<N> networksFound = new HashSet<>();
public OrphanPathFinder(IGridTransmitter<A, N> start)
{
if(event.getChunk() != null && !event.world.isRemote)
{
int x = event.getChunk().xPosition;
int z = event.getChunk().zPosition;
IChunkProvider cProvider = event.getChunk().worldObj.getChunkProvider();
Chunk[] neighbors = new Chunk[5];
neighbors[0] = event.getChunk();
if(cProvider.chunkExists(x + 1, z)) neighbors[1] = cProvider.provideChunk(x + 1, z);
if(cProvider.chunkExists(x - 1, z)) neighbors[2] = cProvider.provideChunk(x - 1, z);
if(cProvider.chunkExists(x, z + 1)) neighbors[3] = cProvider.provideChunk(x, z + 1);
if(cProvider.chunkExists(x, z - 1)) neighbors[4] = cProvider.provideChunk(x, z - 1);
for(Chunk c : neighbors)
{
refreshChunk(c);
}
}
startPoint = start;
}
public synchronized void refreshChunk(Chunk c)
public void start()
{
try {
if(c != null)
iterate(startPoint.coord(), ForgeDirection.UNKNOWN);
}
public void iterate(Coord4D from, ForgeDirection fromDirection)
{
if(iterated.contains(from))
return;
iterated.add(from);
if(orphanTransmitters.containsKey(from))
{
IGridTransmitter<A, N> transmitter = orphanTransmitters.get(from);
if(transmitter.isValid() && transmitter.isOrphan())
{
Map copy = (Map)((HashMap)c.chunkTileEntityMap).clone();
for(Iterator iter = copy.values().iterator(); iter.hasNext();)
connectedTransmitters.add(transmitter);
transmitter.setOrphan(false);
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
Object obj = iter.next();
if(obj instanceof IGridTransmitter)
if(direction != fromDirection)
{
((IGridTransmitter)obj).refreshTransmitterNetwork();
((IGridTransmitter)obj).chunkLoad();
Coord4D directionCoord = transmitter.getAdjacentConnectableTransmitterCoord(direction);
if(!(directionCoord == null || iterated.contains(directionCoord)))
{
iterate(directionCoord, direction.getOpposite());
}
}
}
}
} catch(Exception e) {
e.printStackTrace();
} else
{
addNetworkToIterated(from);
}
}
public void addNetworkToIterated(Coord4D from)
{
networksFound.add(startPoint.getExternalNetwork(from));
}
}
}

View file

@ -10,6 +10,7 @@ import mekanism.client.render.MekanismRenderer.DisplayInteger;
import mekanism.client.render.MekanismRenderer.Model3D;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.item.ItemConfigurator;
import mekanism.common.multipart.MultipartTransporter;
import mekanism.common.multipart.PartDiversionTransporter;
import mekanism.common.multipart.PartHeatTransmitter;
import mekanism.common.multipart.PartLogisticalTransporter;
@ -171,14 +172,14 @@ public class RenderPartTransmitter implements IIconSelfRegister
entityItem.setPosition(transporter.x() + 0.5, transporter.y() + 0.5, transporter.z() + 0.5);
entityItem.worldObj = transporter.world();
for(TransporterStack stack : transporter.transit)
for(TransporterStack stack : transporter.getTransmitter().transit)
{
if(stack != null)
{
GL11.glPushMatrix();
entityItem.setEntityItemStack(stack.itemStack);
float[] pos = TransporterUtils.getStackPosition(transporter, stack, partialTick*transporter.tier.speed);
float[] pos = TransporterUtils.getStackPosition(transporter.getTransmitter(), stack, partialTick*transporter.tier.speed);
GL11.glTranslated(vec.x + pos[0], vec.y + pos[1] - entityItem.yOffset, vec.z + pos[2]);
GL11.glScalef(0.75F, 0.75F, 0.75F);
@ -296,7 +297,15 @@ public class RenderPartTransmitter implements IIconSelfRegister
public void renderContents(PartMechanicalPipe pipe, Vector3 pos)
{
float targetScale = pipe.getTransmitterNetwork().fluidScale;
float targetScale;
if(pipe.getTransmitter().hasTransmitterNetwork())
{
targetScale = pipe.getTransmitter().getTransmitterNetwork().fluidScale;
}
else
{
targetScale = (float)pipe.buffer.getFluidAmount() / (float)pipe.buffer.getCapacity();
}
if(Math.abs(pipe.currentScale - targetScale) > 0.01)
{
@ -306,7 +315,17 @@ public class RenderPartTransmitter implements IIconSelfRegister
pipe.currentScale = targetScale;
}
Fluid fluid = pipe.getTransmitterNetwork().refFluid;
Fluid fluid;
if(pipe.getTransmitter().hasTransmitterNetwork())
{
fluid = pipe.getTransmitter().getTransmitterNetwork().refFluid;
}
else
{
fluid = pipe.getBuffer() == null ? null : pipe.getBuffer().getFluid();
}
float scale = pipe.currentScale;
if(scale > 0.01 && fluid != null)
@ -495,7 +514,7 @@ public class RenderPartTransmitter implements IIconSelfRegister
public void renderContents(PartPressurizedTube tube, Vector3 pos)
{
if(tube.getTransmitterNetwork().refGas == null || tube.getTransmitterNetwork().gasScale == 0)
if(!tube.getTransmitter().hasTransmitterNetwork() || tube.getTransmitter().getTransmitterNetwork().refGas == null || tube.getTransmitter().getTransmitterNetwork().gasScale == 0)
{
return;
}
@ -587,19 +606,19 @@ public class RenderPartTransmitter implements IIconSelfRegister
public void renderHeatSide(ForgeDirection side, PartHeatTransmitter cable)
{
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());
renderTransparency(MekanismRenderer.heatIcon, cable.getModelForSide(side, true), ColourTemperature.fromTemperature(cable.temperature, cable.getBaseColour()));
renderTransparency(MekanismRenderer.heatIcon, cable.getModelForSide(side, true), ColourTemperature.fromTemperature(cable.getTransmitter().temperature, cable.getBaseColour()));
}
public void renderFluidInOut(ForgeDirection side, PartMechanicalPipe pipe)
{
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());
renderTransparency(pipe.getTransmitterNetwork().refFluid.getIcon(), pipe.getModelForSide(side, true), new ColourRGBA(1.0, 1.0, 1.0, pipe.currentScale));
renderTransparency(pipe.getTransmitter().getTransmitterNetwork().refFluid.getIcon(), pipe.getModelForSide(side, true), new ColourRGBA(1.0, 1.0, 1.0, pipe.currentScale));
}
public void renderGasSide(ForgeDirection side, PartPressurizedTube tube)
{
CCRenderState.changeTexture(MekanismRenderer.getBlocksTexture());
renderTransparency(tube.getTransmitterNetwork().refGas.getIcon(), tube.getModelForSide(side, true), new ColourRGBA(1.0, 1.0, 1.0, tube.currentScale));
renderTransparency(tube.getTransmitter().getTransmitterNetwork().refGas.getIcon(), tube.getModelForSide(side, true), new ColourRGBA(1.0, 1.0, 1.0, tube.currentScale));
}
public void renderPart(IIcon icon, CCModel cc, double x, double y, double z, Colour color)

View file

@ -1,25 +1,22 @@
package mekanism.common;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.energy.EnergyAcceptorWrapper;
import mekanism.api.energy.EnergyStack;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.util.ListUtils;
import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
@ -28,7 +25,11 @@ import cofh.api.energy.IEnergyReceiver;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
import cofh.api.energy.IEnergyReceiver;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.tile.IEnergySink;
public class EnergyNetwork extends DynamicNetwork<EnergyAcceptorWrapper, EnergyNetwork>
{
private double lastPowerScale = 0;
private double joulesTransmitted = 0;
@ -36,21 +37,11 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
public double clientEnergyScale = 0;
public double electricityStored;
public EnergyStack buffer = new EnergyStack(0);
public EnergyNetwork(IGridTransmitter<EnergyNetwork>... varCables)
{
transmitters.addAll(Arrays.asList(varCables));
register();
}
public EnergyNetwork() {}
public EnergyNetwork(Collection<IGridTransmitter<EnergyNetwork>> collection)
{
transmitters.addAll(collection);
register();
}
public EnergyNetwork(Set<EnergyNetwork> networks)
public EnergyNetwork(Collection<EnergyNetwork> networks)
{
for(EnergyNetwork net : networks)
{
@ -64,9 +55,9 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
lastPowerScale = net.lastPowerScale;
}
electricityStored += net.electricityStored;
buffer.amount += net.buffer.amount;
addAllTransmitters(net.transmitters);
adoptTransmittersAndAcceptorsFrom(net);
net.deregister();
}
}
@ -79,13 +70,30 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
return Math.round(d * 10000)/10000;
}
@Override
protected synchronized void updateMeanCapacity()
@Override
public void absorbBuffer(IGridTransmitter<EnergyAcceptorWrapper, EnergyNetwork> transmitter)
{
EnergyStack energy = (EnergyStack)transmitter.getBuffer();
buffer.amount += energy.amount;
energy.amount = 0;
}
@Override
public void clampBuffer()
{
if(buffer.amount > getCapacity())
{
buffer.amount = getCapacity();
}
}
@Override
protected void updateMeanCapacity()
{
int numCables = transmitters.size();
double reciprocalSum = 0;
for(IGridTransmitter<EnergyNetwork> cable : transmitters)
for(IGridTransmitter<EnergyAcceptorWrapper, EnergyNetwork> cable : transmitters)
{
reciprocalSum += 1.0/(double)cable.getCapacity();
}
@ -93,43 +101,17 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
meanCapacity = (double)numCables / reciprocalSum;
}
@Override
public void onNetworksCreated(List<EnergyNetwork> networks)
{
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
{
double[] caps = new double[networks.size()];
double cap = 0;
for(EnergyNetwork network : networks)
{
double networkCapacity = network.getCapacity();
caps[networks.indexOf(network)] = networkCapacity;
cap += networkCapacity;
}
electricityStored = Math.min(cap, electricityStored);
double[] percent = ListUtils.percent(caps);
for(EnergyNetwork network : networks)
{
network.electricityStored = round(percent[networks.indexOf(network)]*electricityStored);
}
}
}
public synchronized double getEnergyNeeded()
public double getEnergyNeeded()
{
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
{
return 0;
}
return getCapacity()-electricityStored;
return getCapacity()-buffer.amount;
}
public synchronized double tickEmit(double energyToSend)
public double tickEmit(double energyToSend)
{
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
{
@ -153,12 +135,12 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
return sent;
}
public synchronized double emit(double energyToSend, boolean doEmit)
public double emit(double energyToSend, boolean doEmit)
{
double toUse = Math.min(getEnergyNeeded(), energyToSend);
if(doEmit)
{
electricityStored += toUse;
buffer.amount += toUse;
}
return energyToSend-toUse;
}
@ -166,11 +148,12 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
/**
* @return sent
*/
public synchronized double doEmit(double energyToSend, boolean tryAgain)
public double doEmit(double energyToSend, boolean tryAgain)
{
double sent = 0;
List availableAcceptors = Arrays.asList(getAcceptors().toArray());
List<EnergyAcceptorWrapper> availableAcceptors = new ArrayList<>();
availableAcceptors.addAll(getAcceptors(null));
Collections.shuffle(availableAcceptors);
@ -180,44 +163,25 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
double remaining = energyToSend % divider;
double sending = (energyToSend-remaining)/divider;
for(Object obj : availableAcceptors)
for(EnergyAcceptorWrapper acceptor : availableAcceptors)
{
if(obj instanceof TileEntity)
double currentSending = sending+remaining;
EnumSet<ForgeDirection> sides = acceptorDirections.get(acceptor.coord);
if(sides == null || sides.isEmpty())
{
TileEntity acceptor = (TileEntity)obj;
double currentSending = sending+remaining;
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get(acceptor));
continue;
}
if(sides == null || sides.isEmpty())
{
continue;
}
for(ForgeDirection side : sides)
{
double prev = sent;
for(ForgeDirection side : sides)
sent += acceptor.transferEnergyToAcceptor(side, currentSending);
if(sent > prev)
{
double prev = sent;
if(acceptor instanceof IStrictEnergyAcceptor)
{
sent += ((IStrictEnergyAcceptor)acceptor).transferEnergyToAcceptor(side.getOpposite(), currentSending);
}
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyReceiver)
{
IEnergyReceiver handler = (IEnergyReceiver)acceptor;
int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(currentSending*general.TO_TE), false);
sent += used*general.FROM_TE;
}
else if(MekanismUtils.useIC2() && acceptor instanceof IEnergySink)
{
double toSend = Math.min(currentSending, EnergyNet.instance.getPowerFromTier(((IEnergySink)acceptor).getSinkTier())*general.FROM_IC2);
toSend = Math.min(toSend, ((IEnergySink)acceptor).getDemandedEnergy()*general.FROM_IC2);
sent += (toSend - (((IEnergySink)acceptor).injectEnergy(side.getOpposite(), toSend*general.TO_IC2, 0)*general.FROM_IC2));
}
if(sent > prev)
{
break;
}
break;
}
}
}
@ -227,9 +191,9 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
}
@Override
public synchronized Set<TileEntity> getAcceptors(Object... data)
public Set<EnergyAcceptorWrapper> getAcceptors(Object data)
{
Set<TileEntity> toReturn = new HashSet<TileEntity>();
Set<EnergyAcceptorWrapper> toReturn = new HashSet<>();
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
{
@ -239,56 +203,23 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
for(Coord4D coord : possibleAcceptors.keySet())
{
EnumSet<ForgeDirection> sides = acceptorDirections.get(coord);
TileEntity acceptor = coord.getTileEntity(getWorld());
if(sides == null || sides.isEmpty())
{
continue;
}
for(ForgeDirection side : sides)
TileEntity tile = coord.getTileEntity(getWorld());
EnergyAcceptorWrapper acceptor = EnergyAcceptorWrapper.get(tile);
if(acceptor != null)
{
if(acceptor instanceof IStrictEnergyAcceptor)
for(ForgeDirection side : sides)
{
IStrictEnergyAcceptor handler = (IStrictEnergyAcceptor)acceptor;
if(handler.canReceiveEnergy(side.getOpposite()))
if(acceptor.canReceiveEnergy(side) && acceptor.getNeeded() > 0)
{
if(handler.getMaxEnergy() - handler.getEnergy() > 0)
{
toReturn.add(acceptor);
break;
}
}
}
else if(MekanismUtils.useRF() && acceptor instanceof IEnergyReceiver)
{
IEnergyReceiver handler = (IEnergyReceiver)acceptor;
if(handler.canConnectEnergy(side.getOpposite()))
{
if(handler.receiveEnergy(side.getOpposite(), 1, true) > 0)
{
toReturn.add(acceptor);
break;
}
}
}
else if(MekanismUtils.useIC2() && acceptor instanceof IEnergySink)
{
IEnergySink handler = (IEnergySink)acceptor;
if(handler.acceptsEnergyFrom(null, side.getOpposite()))
{
double demanded = handler.getDemandedEnergy()*general.FROM_IC2;
int tier = Math.min(handler.getSinkTier(), 8);
double max = EnergyNet.instance.getPowerFromTier(tier)*general.FROM_IC2;
if(Math.min(demanded, max) > 0)
{
toReturn.add(acceptor);
break;
}
toReturn.add(acceptor);
break;
}
}
}
@ -297,47 +228,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
return toReturn;
}
@Override
public synchronized void refresh()
{
Set<IGridTransmitter<EnergyNetwork>> iterCables = (Set<IGridTransmitter<EnergyNetwork>>)transmitters.clone();
Iterator<IGridTransmitter<EnergyNetwork>> it = iterCables.iterator();
while(it.hasNext())
{
IGridTransmitter<EnergyNetwork> conductor = (IGridTransmitter<EnergyNetwork>)it.next();
if(conductor == null || conductor.getTile().isInvalid())
{
removeTransmitter(conductor);
}
else {
conductor.setTransmitterNetwork(this);
}
}
needsUpdate = true;
}
@Override
public synchronized void refresh(IGridTransmitter<EnergyNetwork> transmitter)
{
TileEntity[] acceptors = CableUtils.getConnectedEnergyAcceptors(transmitter.getTile());
clearAround(transmitter);
for(TileEntity acceptor : acceptors)
{
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
{
possibleAcceptors.put(Coord4D.get(acceptor), acceptor);
addSide(Coord4D.get(acceptor), ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
}
}
}
public static class EnergyTransferEvent extends Event
{
public final EnergyNetwork energyNetwork;
@ -380,21 +270,21 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
needsUpdate = false;
}
if(electricityStored > 0)
if(buffer.amount > 0)
{
electricityStored -= tickEmit(electricityStored);
buffer.amount -= tickEmit(buffer.amount);
}
}
}
public double getPowerScale()
{
return Math.max(jouleBufferLastTick == 0 ? 0 : Math.min(Math.ceil(Math.log10(getPower())*2)/10, 1), getCapacity() == 0 ? 0 : electricityStored/getCapacity());
return Math.max(jouleBufferLastTick == 0 ? 0 : Math.min(Math.ceil(Math.log10(getPower())*2)/10, 1), getCapacity() == 0 ? 0 : buffer.amount/getCapacity());
}
public void clearJoulesTransmitted()
{
jouleBufferLastTick = electricityStored;
jouleBufferLastTick = buffer.amount;
joulesTransmitted = 0;
}
@ -403,25 +293,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
return jouleBufferLastTick * 20;
}
@Override
protected EnergyNetwork create(Collection<IGridTransmitter<EnergyNetwork>> collection)
{
EnergyNetwork network = new EnergyNetwork(collection);
network.clientEnergyScale = clientEnergyScale;
network.jouleBufferLastTick = jouleBufferLastTick;
network.joulesTransmitted = joulesTransmitted;
network.lastPowerScale = lastPowerScale;
network.electricityStored += electricityStored;
network.updateCapacity();
return network;
}
@Override
public TransmissionType getTransmissionType()
{
return TransmissionType.ENERGY;
}
@Override
public String getNeededInfo()
{
@ -431,7 +302,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
@Override
public String getStoredInfo()
{
return MekanismUtils.getEnergyDisplay(electricityStored);
return MekanismUtils.getEnergyDisplay(buffer.amount);
}
@Override

View file

@ -1,22 +1,19 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterNetwork;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.util.ListUtils;
import mekanism.common.util.LangUtils;
import mekanism.common.util.PipeUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
@ -37,61 +34,41 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
public Fluid refFluid;
public FluidStack fluidStored;
public FluidStack buffer;
public int prevStored;
public int prevTransferAmount = 0;
public FluidNetwork(IGridTransmitter<FluidNetwork>... varPipes)
{
transmitters.addAll(Arrays.asList(varPipes));
register();
}
public FluidNetwork() {}
public FluidNetwork(Collection<IGridTransmitter<FluidNetwork>> collection)
{
transmitters.addAll(collection);
register();
}
public FluidNetwork(Set<FluidNetwork> networks)
public FluidNetwork(Collection<FluidNetwork> networks)
{
for(FluidNetwork net : networks)
{
if(net != null)
{
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
if(net.buffer != null)
{
if(net.refFluid != null && net.fluidScale > fluidScale)
if(buffer == null)
{
refFluid = net.refFluid;
fluidScale = net.fluidScale;
fluidStored = net.fluidStored;
net.fluidScale = 0;
net.refFluid = null;
net.fluidStored = null;
buffer = net.buffer.copy();
}
}
else {
if(net.fluidStored != null)
{
if(fluidStored == null)
else {
if(buffer.getFluid() == net.buffer.getFluid())
{
fluidStored = net.fluidStored;
buffer.amount += net.buffer.amount;
}
else {
if(fluidStored.isFluidEqual(net.fluidStored))
{
fluidStored.amount += net.fluidStored.amount;
}
else if(net.buffer.amount > buffer.amount)
{
buffer = net.buffer.copy();
}
net.fluidStored = null;
}
net.buffer = null;
}
addAllTransmitters(net.transmitters);
adoptTransmittersAndAcceptorsFrom(net);
net.deregister();
}
}
@ -102,12 +79,44 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
}
@Override
protected synchronized void updateMeanCapacity()
public void absorbBuffer(IGridTransmitter<IFluidHandler, FluidNetwork> transmitter)
{
Object b = transmitter.getBuffer();
if(!(b instanceof FluidStack) || ((FluidStack)b).getFluid() == null || ((FluidStack)b).amount == 0)
{
return;
}
FluidStack fluid = (FluidStack)b;
if(buffer == null || buffer.getFluid() == null || buffer.amount == 0)
{
buffer = fluid.copy();
return;
}
if(!fluid.isFluidEqual(buffer)) Mekanism.logger.warn("Fluid type " + fluid.getFluid().getName() + " of buffer doesn't match type " + buffer.getFluid().getName() + " of absorbing network");
buffer.amount += fluid.amount;
fluid.amount = 0;
}
@Override
public void clampBuffer()
{
if(buffer != null && buffer.amount > getCapacity())
{
buffer.amount = capacity;
}
}
@Override
protected void updateMeanCapacity()
{
int numCables = transmitters.size();
double sum = 0;
for(IGridTransmitter<FluidNetwork> pipe : transmitters)
for(IGridTransmitter<IFluidHandler, FluidNetwork> pipe : transmitters)
{
sum += pipe.getCapacity();
}
@ -115,50 +124,15 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
meanCapacity = sum / (double)numCables;
}
@Override
public void onNetworksCreated(List<FluidNetwork> networks)
public int getFluidNeeded()
{
if(fluidStored != null && FMLCommonHandler.instance().getEffectiveSide().isServer())
{
int[] caps = new int[networks.size()];
int cap = 0;
for(FluidNetwork network : networks)
{
caps[networks.indexOf(network)] = network.getCapacity();
cap += network.getCapacity();
}
fluidStored.amount = Math.min(cap, fluidStored.amount);
int[] values = ListUtils.calcPercentInt(ListUtils.percent(caps), fluidStored.amount);
for(FluidNetwork network : networks)
{
int index = networks.indexOf(network);
if(values[index] > 0)
{
network.fluidStored = new FluidStack(fluidStored.getFluid(), values[index]);
network.fluidScale = network.getScale();
network.refFluid = fluidStored.getFluid();
}
}
}
fluidScale = 0;
fluidStored = null;
refFluid = null;
return getCapacity()-(buffer != null ? buffer.amount : 0);
}
public synchronized int getFluidNeeded()
public int tickEmit(FluidStack fluidToSend, boolean doTransfer)
{
return getCapacity()-(fluidStored != null ? fluidStored.amount : 0);
}
public synchronized int tickEmit(FluidStack fluidToSend, boolean doTransfer)
{
List availableAcceptors = Arrays.asList(getAcceptors(fluidToSend).toArray());
List<IFluidHandler> availableAcceptors = new ArrayList<>();
availableAcceptors.addAll(getAcceptors(fluidToSend));
Collections.shuffle(availableAcceptors);
@ -170,33 +144,29 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
int remaining = fluidToSend.amount % divider;
int sending = (fluidToSend.amount-remaining)/divider;
for(Object obj : availableAcceptors)
for(IFluidHandler acceptor : availableAcceptors)
{
if(obj instanceof IFluidHandler)
{
IFluidHandler acceptor = (IFluidHandler)obj;
int currentSending = sending;
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor));
int currentSending = sending;
EnumSet<ForgeDirection> sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor));
if(remaining > 0)
if(remaining > 0)
{
currentSending++;
remaining--;
}
for(ForgeDirection side : sides)
{
int prev = fluidSent;
if(acceptor != null && fluidToSend != null)
{
currentSending++;
remaining--;
fluidSent += acceptor.fill(side, new FluidStack(fluidToSend.fluidID, currentSending), doTransfer);
}
for(ForgeDirection side : sides)
if(fluidSent > prev)
{
int prev = fluidSent;
if(acceptor != null && fluidToSend != null)
{
fluidSent += acceptor.fill(side.getOpposite(), new FluidStack(fluidToSend.fluidID, currentSending), doTransfer);
}
if(fluidSent > prev)
{
break;
}
break;
}
}
}
@ -211,9 +181,9 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
return fluidSent;
}
public synchronized int emit(FluidStack fluidToSend, boolean doTransfer)
public int emit(FluidStack fluidToSend, boolean doTransfer)
{
if(fluidToSend == null || (fluidStored != null && fluidStored.getFluid() != fluidToSend.getFluid()))
if(fluidToSend == null || (buffer != null && buffer.getFluid() != fluidToSend.getFluid()))
{
return 0;
}
@ -222,13 +192,13 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(doTransfer)
{
if(fluidStored == null)
if(buffer == null)
{
fluidStored = fluidToSend.copy();
fluidStored.amount = toUse;
buffer = fluidToSend.copy();
buffer.amount = toUse;
}
else {
fluidStored.amount += toUse;
buffer.amount += toUse;
}
}
@ -252,7 +222,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
transferDelay--;
}
int stored = fluidStored != null ? fluidStored.amount : 0;
int stored = buffer != null ? buffer.amount : 0;
if(stored != prevStored)
{
@ -263,22 +233,22 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(didTransfer != prevTransfer || needsUpdate)
{
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, fluidStored, didTransfer));
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, buffer, didTransfer));
needsUpdate = false;
}
prevTransfer = didTransfer;
if(fluidStored != null)
if(buffer != null)
{
prevTransferAmount = tickEmit(fluidStored, true);
if(fluidStored != null)
prevTransferAmount = tickEmit(buffer, true);
if(buffer != null)
{
fluidStored.amount -= prevTransferAmount;
buffer.amount -= prevTransferAmount;
if(fluidStored.amount <= 0)
if(buffer.amount <= 0)
{
fluidStored = null;
buffer = null;
}
}
}
@ -302,16 +272,16 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(fluidScale == 0)
{
fluidStored = null;
buffer = null;
}
}
}
@Override
public synchronized Set<IFluidHandler> getAcceptors(Object... data)
public Set<IFluidHandler> getAcceptors(Object data)
{
FluidStack fluidToSend = (FluidStack)data[0];
Set<IFluidHandler> toReturn = new HashSet<IFluidHandler>();
FluidStack fluidToSend = (FluidStack)data;
Set<IFluidHandler> toReturn = new HashSet<>();
if(FMLCommonHandler.instance().getEffectiveSide().isClient())
{
@ -321,16 +291,17 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
for(Coord4D coord : possibleAcceptors.keySet())
{
EnumSet<ForgeDirection> sides = acceptorDirections.get(coord);
IFluidHandler acceptor = (IFluidHandler)coord.getTileEntity(getWorld());
if(sides == null || sides.isEmpty())
{
continue;
}
IFluidHandler acceptor = (IFluidHandler)coord.getTileEntity(getWorld());
for(ForgeDirection side : sides)
{
if(acceptor != null && acceptor.canFill(side.getOpposite(), fluidToSend.getFluid()))
if(acceptor != null && acceptor.canFill(side, fluidToSend.getFluid()))
{
toReturn.add(acceptor);
break;
@ -341,47 +312,6 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
return toReturn;
}
@Override
public synchronized void refresh()
{
Set<IGridTransmitter<FluidNetwork>> iterPipes = (Set<IGridTransmitter<FluidNetwork>>)transmitters.clone();
Iterator<IGridTransmitter<FluidNetwork>> it = iterPipes.iterator();
while(it.hasNext())
{
IGridTransmitter<FluidNetwork> conductor = (IGridTransmitter<FluidNetwork>)it.next();
if(conductor == null || conductor.getTile().isInvalid())
{
removeTransmitter(conductor);
}
else {
conductor.setTransmitterNetwork(this);
}
}
needsUpdate = true;
}
@Override
public synchronized void refresh(IGridTransmitter<FluidNetwork> transmitter)
{
IFluidHandler[] acceptors = PipeUtils.getConnectedAcceptors(transmitter.getTile());
clearAround(transmitter);
for(IFluidHandler acceptor : acceptors)
{
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
{
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
addSide(Coord4D.get((TileEntity)acceptor), ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
}
}
}
public static class FluidTransferEvent extends Event
{
public final FluidNetwork fluidNetwork;
@ -399,7 +329,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
public float getScale()
{
return Math.min(1, (fluidStored == null || getCapacity() == 0 ? 0 : (float)fluidStored.amount/getCapacity()));
return Math.min(1, (buffer == null || getCapacity() == 0 ? 0 : (float)buffer.amount/getCapacity()));
}
@Override
@ -408,64 +338,6 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
return "[FluidNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
}
@Override
protected FluidNetwork create(Collection<IGridTransmitter<FluidNetwork>> collection)
{
FluidNetwork network = new FluidNetwork(collection);
network.refFluid = refFluid;
if(fluidStored != null)
{
if(network.fluidStored == null)
{
network.fluidStored = fluidStored;
}
else {
if(network.fluidStored.isFluidEqual(fluidStored))
{
network.fluidStored.amount += fluidStored.amount;
}
}
}
network.updateCapacity();
network.fluidScale = network.getScale();
return network;
}
@Override
public boolean canMerge(List<ITransmitterNetwork<?, ?>> networks)
{
Fluid found = null;
for(ITransmitterNetwork<?, ?> network : networks)
{
if(network instanceof FluidNetwork)
{
FluidNetwork net = (FluidNetwork)network;
if(net.fluidStored != null)
{
if(found != null && found != net.fluidStored.getFluid())
{
return false;
}
found = net.fluidStored.getFluid();
}
}
}
return true;
}
@Override
public TransmissionType getTransmissionType()
{
return TransmissionType.FLUID;
}
@Override
public String getNeededInfo()
{
@ -475,7 +347,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
@Override
public String getStoredInfo()
{
return fluidStored != null ? LangUtils.localizeFluidStack(fluidStored) + " (" + fluidStored.amount + " mB)" : "None";
return buffer != null ? LangUtils.localizeFluidStack(buffer) + " (" + buffer.amount + " mB)" : "None";
}
@Override

View file

@ -19,25 +19,15 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork>
public double heatLost = 0;
public double heatTransferred = 0;
public HeatNetwork(IGridTransmitter<HeatNetwork>... varPipes)
{
transmitters.addAll(Arrays.asList(varPipes));
register();
}
public HeatNetwork() {}
public HeatNetwork(Collection<IGridTransmitter<HeatNetwork>> collection)
{
transmitters.addAll(collection);
register();
}
public HeatNetwork(Set<HeatNetwork> networks)
public HeatNetwork(Collection<HeatNetwork> networks)
{
for(HeatNetwork net : networks)
{
if(net != null)
{
addAllTransmitters(net.transmitters);
adoptTransmittersAndAcceptorsFrom(net);
net.deregister();
}
}
@ -45,13 +35,6 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork>
register();
}
@Override
protected HeatNetwork create(Collection<IGridTransmitter<HeatNetwork>> collection)
{
return new HeatNetwork(collection);
}
@Override
public String getNeededInfo()
{
@ -71,50 +54,17 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork>
}
@Override
public Set<IHeatTransfer> getAcceptors(Object... data)
public void absorbBuffer(IGridTransmitter<IHeatTransfer, HeatNetwork> transmitter) {}
@Override
public void clampBuffer() {}
@Override
public Set<IHeatTransfer> getAcceptors(Object data)
{
return null;
}
@Override
public void refresh()
{
Set<IGridTransmitter<HeatNetwork>> iterPipes = (Set<IGridTransmitter<HeatNetwork>>)transmitters.clone();
Iterator<IGridTransmitter<HeatNetwork>> it = iterPipes.iterator();
boolean networkChanged = false;
while(it.hasNext())
{
IGridTransmitter<HeatNetwork> conductor = it.next();
if(conductor == null || conductor.getTile().isInvalid())
{
it.remove();
networkChanged = true;
transmitters.remove(conductor);
}
else {
conductor.setTransmitterNetwork(this);
}
}
if(networkChanged)
{
updateCapacity();
}
}
@Override
public void refresh(IGridTransmitter<HeatNetwork> transmitter)
{
}
@Override
public TransmissionType getTransmissionType()
{
return TransmissionType.HEAT;
}
@Override
public void onUpdate()
{
@ -126,7 +76,7 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork>
if(FMLCommonHandler.instance().getEffectiveSide().isServer())
{
for(IGridTransmitter<HeatNetwork> transmitter : transmitters)
for(IGridTransmitter<IHeatTransfer, HeatNetwork> transmitter : transmitters)
{
if(transmitter instanceof IHeatTransfer)
{
@ -137,7 +87,7 @@ public class HeatNetwork extends DynamicNetwork<IHeatTransfer, HeatNetwork>
}
}
for(IGridTransmitter<HeatNetwork> transmitter : transmitters)
for(IGridTransmitter<IHeatTransfer, HeatNetwork> transmitter : transmitters)
{
if(transmitter instanceof IHeatTransfer)
{

View file

@ -1,23 +1,18 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -27,25 +22,15 @@ import cpw.mods.fml.common.FMLCommonHandler;
public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwork>
{
public InventoryNetwork(IGridTransmitter<InventoryNetwork>... varPipes)
{
transmitters.addAll(Arrays.asList(varPipes));
register();
}
public InventoryNetwork() {}
public InventoryNetwork(Collection<IGridTransmitter<InventoryNetwork>> collection)
{
transmitters.addAll(collection);
register();
}
public InventoryNetwork(Set<InventoryNetwork> networks)
public InventoryNetwork(Collection<InventoryNetwork> networks)
{
for(InventoryNetwork net : networks)
{
if(net != null)
{
addAllTransmitters(net.transmitters);
adoptTransmittersAndAcceptorsFrom(net);
net.deregister();
}
}
@ -76,16 +61,16 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
for(ForgeDirection side : sides)
{
ItemStack returned = TransporterManager.getPredictedInsert((TileEntity)acceptor, color, stack, side.ordinal());
ItemStack returned = TransporterManager.getPredictedInsert((TileEntity)acceptor, color, stack, side.getOpposite().ordinal());
if(TransporterManager.didEmit(stack, returned))
{
if(data == null)
{
data = new AcceptorData(coord, returned, side);
data = new AcceptorData(coord, returned, side.getOpposite());
}
else {
data.sides.add(side);
data.sides.add(side.getOpposite());
}
}
}
@ -125,7 +110,13 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
}
@Override
public synchronized Set<IInventory> getAcceptors(Object... data)
public void absorbBuffer(IGridTransmitter<IInventory, InventoryNetwork> transmitter) {}
@Override
public void clampBuffer() {}
@Override
public Set<IInventory> getAcceptors(Object data)
{
Set<IInventory> toReturn = new HashSet<IInventory>();
@ -137,63 +128,10 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
return toReturn;
}
@Override
public synchronized void refresh()
{
Set<IGridTransmitter<InventoryNetwork>> iterPipes = (Set<IGridTransmitter<InventoryNetwork>>)transmitters.clone();
Iterator it = iterPipes.iterator();
while(it.hasNext())
{
IGridTransmitter<InventoryNetwork> conductor = (IGridTransmitter<InventoryNetwork>)it.next();
if(conductor == null || conductor.getTile().isInvalid())
{
removeTransmitter(conductor);
}
else {
conductor.setTransmitterNetwork(this);
}
}
needsUpdate = true;
}
@Override
public synchronized void refresh(IGridTransmitter<InventoryNetwork> transmitter)
{
IInventory[] acceptors = TransporterUtils.getConnectedInventories((ILogisticalTransporter)transmitter.getTile());
clearAround(transmitter);
for(IInventory acceptor : acceptors)
{
ForgeDirection side = ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor));
if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true))
{
possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor);
addSide(Coord4D.get((TileEntity)acceptor), ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor)));
}
}
}
@Override
public String toString()
{
return "[FluidNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
}
@Override
protected InventoryNetwork create(Collection<IGridTransmitter<InventoryNetwork>> collection)
{
return new InventoryNetwork(collection);
}
@Override
public TransmissionType getTransmissionType()
{
return TransmissionType.ITEM;
return "[InventoryNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
}
@Override

View file

@ -25,6 +25,7 @@ import mekanism.api.infuse.InfuseRegistry;
import mekanism.api.infuse.InfuseType;
import mekanism.api.transmitters.DynamicNetwork.ClientTickUpdate;
import mekanism.api.transmitters.DynamicNetwork.NetworkClientRequest;
import mekanism.api.transmitters.DynamicNetwork.TransmittersAddedEvent;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.client.ClientTickHandler;
import mekanism.common.EnergyNetwork.EnergyTransferEvent;
@ -57,6 +58,7 @@ import mekanism.common.integration.OreDictManager;
import mekanism.common.multiblock.MultiblockManager;
import mekanism.common.multipart.MultipartMekanism;
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
import mekanism.common.network.PacketTransmitterUpdate;
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import mekanism.common.recipe.BinRecipe;
@ -109,6 +111,8 @@ import org.apache.logging.log4j.Logger;
import rebelkeithy.mods.metallurgy.api.IOreInfo;
import rebelkeithy.mods.metallurgy.api.MetallurgyAPI;
import codechicken.multipart.handler.MultipartProxy;
import sun.reflect.annotation.ExceptionProxy;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IFuelHandler;
@ -1096,6 +1100,7 @@ public class Mekanism
FrequencyManager.reset();
TransporterManager.reset();
PathfinderCache.reset();
TransmitterNetworkRegistry.reset();
}
@EventHandler
@ -1266,7 +1271,7 @@ public class Mekanism
public void onEnergyTransferred(EnergyTransferEvent event)
{
try {
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.ENERGY, Coord4D.get((TileEntity)event.energyNetwork.transmitters.iterator().next()), event.power), event.energyNetwork.getPacketRange());
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.ENERGY, event.energyNetwork.transmitters.iterator().next().coord(), event.power), event.energyNetwork.getPacketRange());
} catch(Exception e) {}
}
@ -1274,7 +1279,7 @@ public class Mekanism
public void onGasTransferred(GasTransferEvent event)
{
try {
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.GAS, Coord4D.get((TileEntity)event.gasNetwork.transmitters.iterator().next()), event.transferType, event.didTransfer), event.gasNetwork.getPacketRange());
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.GAS, event.gasNetwork.transmitters.iterator().next().coord(), event.transferType, event.didTransfer), event.gasNetwork.getPacketRange());
} catch(Exception e) {}
}
@ -1282,7 +1287,15 @@ public class Mekanism
public void onLiquidTransferred(FluidTransferEvent event)
{
try {
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.FLUID, Coord4D.get((TileEntity)event.fluidNetwork.transmitters.iterator().next()), event.fluidType, event.didTransfer), event.fluidNetwork.getPacketRange());
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next().coord(), event.fluidType, event.didTransfer), event.fluidNetwork.getPacketRange());
} catch(Exception e) {}
}
@SubscribeEvent
public void onTransmittersAddedEvent(TransmittersAddedEvent event)
{
try {
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.UPDATE, event.network.transmitters.iterator().next().coord(), event.newNetwork, event.newTransmitters), event.network.getPacketRange());
} catch(Exception e) {}
}

View file

@ -8,11 +8,12 @@ import mekanism.common.InventoryNetwork;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.tile.TileEntityLogisticalSorter;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public interface ILogisticalTransporter extends IBlockableConnection, IGridTransmitter<InventoryNetwork>
public interface ILogisticalTransporter extends IGridTransmitter<IInventory, InventoryNetwork>, IBlockableConnection
{
public ItemStack insert(Coord4D original, ItemStack itemStack, EnumColor color, boolean doEmit, int min);

View file

@ -0,0 +1,13 @@
package mekanism.common.base;
import mekanism.api.transmitters.IBlockableConnection;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.common.InventoryNetwork;
import net.minecraft.inventory.IInventory;
public interface ITransporterTile extends ITransmitterTile<IInventory,InventoryNetwork>, IBlockableConnection
{
public ILogisticalTransporter getTransmitter();
}

View file

@ -13,6 +13,7 @@ import mekanism.api.Coord4D;
import mekanism.common.InventoryNetwork;
import mekanism.common.InventoryNetwork.AcceptorData;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.PathfinderCache.PathData;
import mekanism.common.content.transporter.TransporterPathfinder.Pathfinder.DestChecker;
import mekanism.common.content.transporter.TransporterStack.Path;
@ -235,20 +236,20 @@ 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(Coord4D.get(start.getTile()), dest, sides);
ArrayList<Coord4D> test = PathfinderCache.getCache(start.coord(), dest, sides);
if(test != null)
{
return new Destination(test, false, rejects);
}
Pathfinder p = new Pathfinder(checker, start.getTile().getWorldObj(), dest, Coord4D.get(start.getTile()), stack);
Pathfinder p = new Pathfinder(checker, start.world(), dest, start.coord(), stack);
if(p.getPath().size() >= 2)
{
if(TransporterManager.getToUse(stack.itemStack, rejects).stackSize >= min)
{
PathfinderCache.cachedPaths.put(new PathData(Coord4D.get(start.getTile()), dest, p.side), p.getPath());
PathfinderCache.cachedPaths.put(new PathData(start.coord(), dest, p.side), p.getPath());
return new Destination(p.getPath(), false, rejects);
}
@ -377,7 +378,7 @@ public final class TransporterPathfinder
for(int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
Coord4D neighbor = start.translate(direction.offsetX, direction.offsetY, direction.offsetZ);
Coord4D neighbor = start.getFromSide(direction);
if(!transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj), direction) && (!neighbor.equals(finalNode) || !destChecker.isValid(transportStack, i, neighbor.getTileEntity(worldObj))))
{
@ -424,7 +425,7 @@ public final class TransporterPathfinder
TileEntity tile = neighbor.getTileEntity(worldObj);
double tentativeG = gScore.get(currentNode) + currentNode.distanceTo(neighbor);
tentativeG += ((ILogisticalTransporter)tile).getCost();
tentativeG += ((ITransporterTile)tile).getTransmitter().getCost();
if(closedSet.contains(neighbor))
{
@ -508,7 +509,7 @@ public final class TransporterPathfinder
}
};
Pathfinder p = new Pathfinder(checker, start.getTile().getWorldObj(), stack.homeLocation, Coord4D.get(start.getTile()), stack);
Pathfinder p = new Pathfinder(checker, start.world(), stack.homeLocation, start.coord(), stack);
List<Coord4D> path = p.getPath();
if(path.size() >= 2)
@ -521,7 +522,7 @@ public final class TransporterPathfinder
}
}
IdlePath d = new IdlePath(start.getTile().getWorldObj(), Coord4D.get(start.getTile()), stack);
IdlePath d = new IdlePath(start.world(), start.coord(), stack);
Destination dest = d.find();
if(dest == null)

View file

@ -7,8 +7,10 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.transmitters.IBlockableConnection;
import mekanism.common.PacketHandler;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.TransporterPathfinder.Destination;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.util.TransporterUtils;
@ -39,7 +41,7 @@ public class TransporterStack
public Path pathType;
public void write(ILogisticalTransporter tileEntity, ArrayList data)
public void write(ILogisticalTransporter transporter, ArrayList data)
{
if(color != null)
{
@ -53,16 +55,16 @@ public class TransporterStack
originalLocation.write(data);
data.add(pathType.ordinal());
if(pathToTarget.indexOf(Coord4D.get(tileEntity.getTile())) > 0)
if(pathToTarget.indexOf(transporter.coord()) > 0)
{
data.add(true);
getNext(tileEntity).write(data);
getNext(transporter).write(data);
}
else {
data.add(false);
}
getPrev(tileEntity).write(data);
getPrev(transporter).write(data);
data.add(itemStack);
}
@ -154,9 +156,9 @@ public class TransporterStack
return pathToTarget != null && pathToTarget.size() >= 2;
}
public ItemStack recalculatePath(ILogisticalTransporter tileEntity, int min)
public ItemStack recalculatePath(ILogisticalTransporter transporter, int min)
{
Destination newPath = TransporterPathfinder.getNewBasePath(tileEntity, this, min);
Destination newPath = TransporterPathfinder.getNewBasePath(transporter, this, min);
if(newPath == null)
{
@ -171,9 +173,9 @@ public class TransporterStack
return newPath.rejected;
}
public ItemStack recalculateRRPath(TileEntityLogisticalSorter outputter, ILogisticalTransporter tileEntity, int min)
public ItemStack recalculateRRPath(TileEntityLogisticalSorter outputter, ILogisticalTransporter transporter, int min)
{
Destination newPath = TransporterPathfinder.getNewRRPath(tileEntity, this, outputter, min);
Destination newPath = TransporterPathfinder.getNewRRPath(transporter, this, outputter, min);
if(newPath == null)
{
@ -188,9 +190,9 @@ public class TransporterStack
return newPath.rejected;
}
public boolean calculateIdle(ILogisticalTransporter tileEntity)
public boolean calculateIdle(ILogisticalTransporter transporter)
{
List<Coord4D> newPath = TransporterPathfinder.getIdlePath(tileEntity, this);
List<Coord4D> newPath = TransporterPathfinder.getIdlePath(transporter, this);
if(newPath == null)
{
@ -204,22 +206,22 @@ public class TransporterStack
pathToTarget = newPath;
originalLocation = Coord4D.get(tileEntity.getTile());
originalLocation = transporter.coord();
initiatedPath = true;
return true;
}
public boolean isFinal(ILogisticalTransporter tileEntity)
public boolean isFinal(ILogisticalTransporter transporter)
{
return pathToTarget.indexOf(Coord4D.get(tileEntity.getTile())) == (pathType == Path.NONE ? 0 : 1);
return pathToTarget.indexOf(transporter.coord()) == (pathType == Path.NONE ? 0 : 1);
}
public Coord4D getNext(ILogisticalTransporter tileEntity)
public Coord4D getNext(ILogisticalTransporter transporter)
{
if(!tileEntity.getTile().getWorldObj().isRemote)
if(!transporter.world().isRemote)
{
int index = pathToTarget.indexOf(Coord4D.get(tileEntity.getTile()))-1;
int index = pathToTarget.indexOf(transporter.coord())-1;
if(index < 0)
{
@ -233,11 +235,11 @@ public class TransporterStack
}
}
public Coord4D getPrev(ILogisticalTransporter tileEntity)
public Coord4D getPrev(ILogisticalTransporter transporter)
{
if(!tileEntity.getTile().getWorldObj().isRemote)
if(!transporter.world().isRemote)
{
int index = pathToTarget.indexOf(Coord4D.get(tileEntity.getTile()))+1;
int index = pathToTarget.indexOf(transporter.coord())+1;
if(index < pathToTarget.size())
{
@ -252,27 +254,27 @@ public class TransporterStack
}
}
public int getSide(ILogisticalTransporter tileEntity)
public int getSide(ILogisticalTransporter transporter)
{
if(progress < 50)
{
if(getPrev(tileEntity) != null)
if(getPrev(transporter) != null)
{
return Coord4D.get(tileEntity.getTile()).sideDifference(getPrev(tileEntity)).ordinal();
return transporter.coord().sideDifference(getPrev(transporter)).ordinal();
}
}
else if(progress == 50)
{
if(getNext(tileEntity) != null)
if(getNext(transporter) != null)
{
return getNext(tileEntity).sideDifference(Coord4D.get(tileEntity.getTile())).ordinal();
return getNext(transporter).sideDifference(transporter.coord()).ordinal();
}
}
else if(progress > 50)
{
if(getNext(tileEntity) != null)
if(getNext(transporter) != null)
{
return getNext(tileEntity).sideDifference(Coord4D.get(tileEntity.getTile())).ordinal();
return getNext(transporter).sideDifference(transporter.coord()).ordinal();
}
}
@ -281,13 +283,24 @@ public class TransporterStack
public boolean canInsertToTransporter(TileEntity tileEntity, ForgeDirection side)
{
if(!(tileEntity instanceof ILogisticalTransporter))
if(!(tileEntity instanceof ITransporterTile))
{
return false;
}
ILogisticalTransporter transporter = (ILogisticalTransporter)tileEntity;
TileEntity from = Coord4D.get(tileEntity).getFromSide(side.getOpposite()).getTileEntity(tileEntity.getWorldObj());
ILogisticalTransporter transporter = ((ITransporterTile)tileEntity).getTransmitter();
if(!((ITransporterTile)tileEntity).canConnectMutual(side))
{
return false;
}
return transporter.getColor() == color || transporter.getColor() == null;
}
public boolean canInsertToTransporter(ILogisticalTransporter transporter, ForgeDirection side)
{
if(!transporter.canConnectMutual(side))
{
return false;

View file

@ -6,8 +6,10 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterNetwork;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.common.Mekanism;
@ -37,19 +39,19 @@ public class ItemNetworkReader extends ItemEnergized
if(getEnergy(stack) >= ENERGY_PER_USE)
{
if(tileEntity instanceof IGridTransmitter)
if(tileEntity instanceof ITransmitterTile)
{
if(drain) setEnergy(stack, getEnergy(stack)-ENERGY_PER_USE);
IGridTransmitter<?> transmitter = (IGridTransmitter<?>)tileEntity;
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
player.addChatMessage(new ChatComponentText(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------"));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Transmitters: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getSize()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Acceptors: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getAcceptorSize()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Needed: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getNeededInfo()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Buffer: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getStoredInfo()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Throughput: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getFlowInfo()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Capacity: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetwork().getCapacity()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Transmitters: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkSize()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Acceptors: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkAcceptorSize()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Needed: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkNeeded()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Buffer: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkBuffer()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Throughput: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkFlow()));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Capacity: " + EnumColor.DARK_GREY + transmitter.getTransmitterNetworkCapacity()));
if(transmitter instanceof IHeatTransfer)
player.addChatMessage(new ChatComponentText(EnumColor.GREY + " *Temperature: " + EnumColor.DARK_GREY + ((IHeatTransfer)transmitter).getTemp() + "K above ambient"));
player.addChatMessage(new ChatComponentText(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------"));
@ -70,15 +72,15 @@ public class ItemNetworkReader extends ItemEnergized
{
if(drain) setEnergy(stack, getEnergy(stack)-ENERGY_PER_USE);
Set<ITransmitterNetwork> iteratedNetworks = new HashSet<ITransmitterNetwork>();
Set<DynamicNetwork> iteratedNetworks = new HashSet<>();
for(ForgeDirection iterSide : ForgeDirection.VALID_DIRECTIONS)
{
Coord4D coord = Coord4D.get(tileEntity).getFromSide(iterSide);
if(coord.getTileEntity(world) instanceof IGridTransmitter)
if(coord.getTileEntity(world) instanceof ITransmitterTile)
{
IGridTransmitter<?> transmitter = (IGridTransmitter<?>)coord.getTileEntity(world);
IGridTransmitter transmitter = ((ITransmitterTile)coord.getTileEntity(world)).getTransmitter();
if(transmitter.getTransmitterNetwork().possibleAcceptors.containsKey(coord.getFromSide(iterSide.getOpposite())) && !iteratedNetworks.contains(transmitter.getTransmitterNetwork()))
{

View file

@ -5,8 +5,8 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterNetwork;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.MekKeyHandler;
import mekanism.client.MekanismKeyHandler;
@ -52,24 +52,24 @@ public class ItemPartTransmitter extends JItemMultiPart
{
Coord4D obj = new Coord4D(coord.x, coord.y, coord.z, world.provider.dimensionId);
List<ITransmitterNetwork<?, ?>> networks = new ArrayList<ITransmitterNetwork<?, ?>>();
List<DynamicNetwork> networks = new ArrayList<>();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = obj.getFromSide(side).getTileEntity(world);
if(tile instanceof IGridTransmitter && TransmissionType.checkTransmissionType(tile, type.getTransmission()))
if(tile instanceof ITransmitterTile && TransmissionType.checkTransmissionType(((ITransmitterTile)tile).getTransmitter(), type.getTransmission()))
{
networks.add(((IGridTransmitter)tile).getTransmitterNetwork());
networks.add(((ITransmitterTile)tile).getTransmitter().getTransmitterNetwork());
}
}
if(networks.size() > 0)
{
if(!networks.iterator().next().canMerge(networks))
/*if(!networks.iterator().next().canMerge(networks))
{
return null;
}
}*/
}
}

View file

@ -0,0 +1,115 @@
package mekanism.common.multipart;
import mekanism.api.IHeatTransfer;
import mekanism.common.HeatNetwork;
import mekanism.common.util.HeatUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.colour.Colour;
import codechicken.lib.colour.ColourRGBA;
/**
* Created by ben on 01/04/15.
*/
public class MultipartHeatTransmitter extends MultipartTransmitter<IHeatTransfer, HeatNetwork> implements IHeatTransfer
{
public double temperature = 0;
public double clientTemperature = 0;
public double heatToAbsorb = 0;
public HeatMaterial material = HeatMaterial.DEFAULT;
public MultipartHeatTransmitter(PartHeatTransmitter multiPart)
{
super(multiPart);
}
@Override
public double getTemp()
{
return temperature;
}
@Override
public double getInverseConductionCoefficient()
{
return material.inverseConduction;
}
@Override
public double getInsulationCoefficient(ForgeDirection side)
{
return material.inverseConductionInsulation;
}
@Override
public void transferHeatTo(double heat)
{
heatToAbsorb += heat;
}
@Override
public double[] simulateHeat()
{
return HeatUtils.simulate(this);
}
@Override
public double applyTemperatureChange()
{
temperature += material.inverseHeatCapacity * heatToAbsorb;
heatToAbsorb = 0;
if(Math.abs(temperature - clientTemperature) > (temperature / 100))
{
clientTemperature = temperature;
getPart().sendTemp();
}
return temperature;
}
@Override
public boolean canConnectHeat(ForgeDirection side)
{
return true;
}
@Override
public IHeatTransfer getAdjacent(ForgeDirection side)
{
if(getPart().connectionMapContainsSide(getPart().getAllCurrentConnections(), side))
{
TileEntity adj = coord().getFromSide(side).getTileEntity(world());
if(adj instanceof IHeatTransfer)
{
return (IHeatTransfer)adj;
}
}
return null;
}
@Override
public PartHeatTransmitter getPart()
{
return (PartHeatTransmitter)containingPart;
}
public static enum HeatMaterial
{
DEFAULT(5, 1, 0, new ColourRGBA(0.2, 0.2, 0.2, 1));
double inverseConduction;
double inverseHeatCapacity;
double inverseConductionInsulation;
ColourRGBA baseColour;
private HeatMaterial(double inversek, double inverseC, double insulationInversek, ColourRGBA colour)
{
inverseConduction = inversek;
inverseHeatCapacity = inverseC;
inverseConductionInsulation = insulationInversek;
baseColour = colour;
}
}
}

View file

@ -43,8 +43,8 @@ public class MultipartMekanism implements IPartFactory
MultipartGenerator.registerPassThroughInterface("mekanism.api.gas.IGasHandler");
MultipartGenerator.registerPassThroughInterface("mekanism.api.IHeatTransfer");
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IBlockableConnection");
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IGridTransmitter");
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.ITransmitter");
MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.ITransmitterTile");
MultipartGenerator.registerPassThroughInterface("mekanism.common.base.ITransporterTile");
MultipartGenerator.registerPassThroughInterface("mekanism.common.base.ILogisticalTransporter");
MultipartGenerator.registerPassThroughInterface("mekanism.common.base.ITileNetwork");
MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler");

View file

@ -0,0 +1,133 @@
package mekanism.common.multipart;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.transmitters.Transmitter;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class MultipartTransmitter<A, N extends DynamicNetwork<A,N>> extends Transmitter<A, N>
{
public PartTransmitter<A, N> containingPart;
public MultipartTransmitter(PartTransmitter<A, N> multiPart)
{
setPart(multiPart);
}
@Override
public int getCapacity()
{
return getPart().getCapacity();
}
@Override
public World world()
{
return getPart().world();
}
@Override
public Coord4D coord()
{
return new Coord4D(getPart().x(), getPart().y(), getPart().z());
}
@Override
public Coord4D getAdjacentConnectableTransmitterCoord(ForgeDirection side)
{
Coord4D sideCoord = coord().getFromSide(side);
TileEntity potentialTransmitterTile = sideCoord.getTileEntity(world());
if(!containingPart.canConnectMutual(side))
{
return null;
}
if(potentialTransmitterTile instanceof ITransmitterTile)
{
IGridTransmitter transmitter = ((ITransmitterTile)potentialTransmitterTile).getTransmitter();
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()))
{
return sideCoord;
}
}
return null;
}
@Override
public A getAcceptor(ForgeDirection side)
{
return getPart().getCachedAcceptor(side);
}
@Override
public boolean isValid()
{
return !(getPart().tile() == null || getPart().tile().isInvalid()) && coord().exists(world());
}
@Override
public N createEmptyNetwork()
{
return getPart().createNewNetwork();
}
@Override
public N getExternalNetwork(Coord4D from)
{
TileEntity tile = from.getTileEntity(world());
if(tile instanceof ITransmitterTile)
{
IGridTransmitter transmitter = ((ITransmitterTile)tile).getTransmitter();
if(TransmissionType.checkTransmissionType(transmitter, getTransmissionType()));
{
return ((IGridTransmitter<A, N>)transmitter).getTransmitterNetwork();
}
}
return null;
}
@Override
public void takeShare()
{
containingPart.takeShare();
}
@Override
public Object getBuffer()
{
return getPart().getBuffer();
}
@Override
public N mergeNetworks(Collection<N> toMerge)
{
return getPart().createNetworkByMerging(toMerge);
}
@Override
public TransmissionType getTransmissionType()
{
return getPart().getTransmissionType();
}
public PartTransmitter<A, N> getPart()
{
return containingPart;
}
public void setPart(PartTransmitter<A, N> containingPart)
{
this.containingPart = containingPart;
}
}

View file

@ -0,0 +1,398 @@
package mekanism.common.multipart;
import java.util.HashSet;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.Range4D;
import mekanism.common.HashList;
import mekanism.common.InventoryNetwork;
import mekanism.common.Mekanism;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.content.transporter.TransporterStack.Path;
import mekanism.common.multipart.PartSidedPipe.ConnectionType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class MultipartTransporter extends MultipartTransmitter<IInventory, InventoryNetwork> implements ILogisticalTransporter
{
public HashList<TransporterStack> transit = new HashList<>();
public EnumColor color;
public Set<TransporterStack> needsSync = new HashSet<>();
public MultipartTransporter(PartLogisticalTransporter multiPart)
{
super(multiPart);
}
public void update()
{
if(world().isRemote)
{
for(TransporterStack stack : transit)
{
if(stack != null)
{
stack.progress = Math.min(100, stack.progress+getPart().tier.speed);
}
}
}
else {
Set<TransporterStack> remove = new HashSet<TransporterStack>();
getPart().pullItems();
for(TransporterStack stack : transit)
{
if(!stack.initiatedPath)
{
if(stack.itemStack == null || !recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
stack.progress += getPart().tier.speed;
if(stack.progress > 100)
{
Coord4D prevSet = null;
if(stack.hasPath())
{
int currentIndex = stack.pathToTarget.indexOf(coord());
if(currentIndex == 0) //Necessary for transition reasons, not sure why
{
remove.add(stack);
continue;
}
Coord4D next = stack.pathToTarget.get(currentIndex-1);
if(!stack.isFinal(this))
{
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(world()), ForgeDirection.getOrientation(stack.getSide(this))))
{
ITransporterTile nextTile = (ITransporterTile)next.getTileEntity(world());
nextTile.getTransmitter().entityEntering(stack, stack.progress%100);
remove.add(stack);
continue;
}
else if(next != null)
{
prevSet = next;
}
}
else {
if(stack.pathType != Path.NONE)
{
if(next != null && next.getTileEntity(world()) instanceof IInventory)
{
needsSync.add(stack);
IInventory inventory = (IInventory)next.getTileEntity(world());
if(inventory != null)
{
ItemStack rejected = InventoryUtils.putStackInInventory(inventory, stack.itemStack, stack.getSide(this), stack.pathType == Path.HOME);
if(rejected == null)
{
TransporterManager.remove(stack);
remove.add(stack);
continue;
}
else {
needsSync.add(stack);
stack.itemStack = rejected;
prevSet = next;
}
}
}
}
}
}
if(!recalculate(stack, prevSet))
{
remove.add(stack);
continue;
}
else {
if(prevSet != null)
{
stack.progress = 0;
}
else {
stack.progress = 50;
}
}
}
else if(stack.progress == 50)
{
if(stack.isFinal(this))
{
if(stack.pathType == Path.DEST && (!checkSideForInsert(stack) || !InventoryUtils.canInsert(stack.getDest().getTileEntity(world()), stack.color, stack.itemStack, stack.getSide(this), false)))
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
else if(stack.pathType == Path.HOME && (!checkSideForInsert(stack) || !InventoryUtils.canInsert(stack.getDest().getTileEntity(world()), stack.color, stack.itemStack, stack.getSide(this), true)))
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
else if(stack.pathType == Path.NONE)
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
}
else {
TileEntity next = stack.getNext(this).getTileEntity(world());
boolean recalculate = false;
if(!stack.canInsertToTransporter(next, ForgeDirection.getOrientation(stack.getSide(this))))
{
recalculate = true;
}
if(recalculate)
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
}
}
}
for(TransporterStack stack : remove)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord(), getPart().getSyncPacket(stack, true)), new Range4D(coord()));
transit.remove(stack);
MekanismUtils.saveChunk(getPart().tile());
}
for(TransporterStack stack : needsSync)
{
if(transit.contains(stack))
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord(), getPart().getSyncPacket(stack, false)), new Range4D(coord()));
}
}
needsSync.clear();
}
}
private boolean checkSideForInsert(TransporterStack stack)
{
ForgeDirection side = ForgeDirection.getOrientation(stack.getSide(this));
return getPart().getConnectionType(side) == ConnectionType.NORMAL || getPart().getConnectionType(side) == ConnectionType.PUSH;
}
private boolean recalculate(TransporterStack stack, Coord4D from)
{
needsSync.add(stack);
if(stack.pathType != Path.NONE)
{
if(!TransporterManager.didEmit(stack.itemStack, stack.recalculatePath(this, 0)))
{
if(!stack.calculateIdle(this))
{
TransporterUtils.drop(this, stack);
return false;
}
}
}
else {
if(!stack.calculateIdle(this))
{
TransporterUtils.drop(this, stack);
return false;
}
}
if(from != null)
{
stack.originalLocation = from;
}
return true;
}
@Override
public ItemStack insert(Coord4D original, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
return insert_do(original, itemStack, color, doEmit, min, false);
}
private ItemStack insert_do(Coord4D original, ItemStack itemStack, EnumColor color, boolean doEmit, int min, boolean force)
{
ForgeDirection from = coord().sideDifference(original).getOpposite();
TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack;
stack.originalLocation = original;
stack.homeLocation = original;
stack.color = color;
if((force && !canReceiveFrom(original.getTileEntity(world()), from)) || !stack.canInsertToTransporter(this, from))
{
return itemStack;
}
ItemStack rejected = stack.recalculatePath(this, min);
if(TransporterManager.didEmit(stack.itemStack, rejected))
{
stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected);
if(doEmit)
{
transit.add(stack);
TransporterManager.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord(), getPart().getSyncPacket(stack, false)), new Range4D(coord()));
MekanismUtils.saveChunk(getPart().tile());
}
return rejected;
}
return itemStack;
}
@Override
public ItemStack insertRR(TileEntityLogisticalSorter outputter, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
ForgeDirection from = coord().sideDifference(Coord4D.get(outputter)).getOpposite();
TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack;
stack.originalLocation = Coord4D.get(outputter);
stack.homeLocation = Coord4D.get(outputter);
stack.color = color;
if(!canReceiveFrom(outputter, from) || !stack.canInsertToTransporter(this, from))
{
return itemStack;
}
ItemStack rejected = stack.recalculateRRPath(outputter, this, min);
if(TransporterManager.didEmit(stack.itemStack, rejected))
{
stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected);
if(doEmit)
{
transit.add(stack);
TransporterManager.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord(), getPart().getSyncPacket(stack, false)), new Range4D(coord()));
MekanismUtils.saveChunk(getPart().tile());
}
return rejected;
}
return itemStack;
}
@Override
public void entityEntering(TransporterStack stack, int progress)
{
stack.progress = progress;
transit.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord(), getPart().getSyncPacket(stack, false)), new Range4D(coord()));
MekanismUtils.saveChunk(getPart().tile());
}
@Override
public EnumColor getColor()
{
return color;
}
@Override
public void setColor(EnumColor c)
{
color = c;
}
@Override
public boolean canEmitTo(TileEntity tileEntity, ForgeDirection side)
{
if(!getPart().canConnect(side))
{
return false;
}
return getPart().getConnectionType(side) == ConnectionType.NORMAL || getPart().getConnectionType(side) == ConnectionType.PUSH;
}
@Override
public boolean canReceiveFrom(TileEntity tileEntity, ForgeDirection side)
{
if(!getPart().canConnect(side))
{
return false;
}
return getPart().getConnectionType(side) == ConnectionType.NORMAL;
}
@Override
public int getCost()
{
return getPart().getCost();
}
@Override
public boolean canConnectMutual(ForgeDirection side)
{
return getPart().canConnectMutual(side);
}
@Override
public boolean canConnect(ForgeDirection side)
{
return getPart().canConnect(side);
}
@Override
public PartLogisticalTransporter getPart()
{
return (PartLogisticalTransporter)containingPart;
}
}

View file

@ -6,6 +6,7 @@ import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.Tier.TransporterTier;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.util.MekanismUtils;
@ -29,7 +30,7 @@ public class PartDiversionTransporter extends PartLogisticalTransporter
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return TransmitterType.DIVERSION_TRANSPORTER;
}
@ -43,13 +44,13 @@ public class PartDiversionTransporter extends PartLogisticalTransporter
@Override
public IIcon getSideIcon(boolean opaque)
{
return transporterIcons.getSideIcon(opaque ? 14 : (color != null ? 11 : 10));
return transporterIcons.getSideIcon(opaque ? 14 : (getTransmitter().color != null ? 11 : 10));
}
@Override
public IIcon getSideIconRotated(boolean opaque)
{
return transporterIcons.getSideIcon(opaque ? 15 : (color != null ? 13 : 12));
return transporterIcons.getSideIcon(opaque ? 15 : (getTransmitter().color != null ? 13 : 12));
}
@Override

View file

@ -1,10 +1,9 @@
package mekanism.common.multipart;
import java.util.Set;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HeatNetwork;
@ -15,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -24,59 +24,27 @@ import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.vec.Vector3;
public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements IHeatTransfer
public class PartHeatTransmitter extends PartTransmitter<IHeatTransfer, HeatNetwork>
{
public double temperature = 0;
public double clientTemperature = 0;
public double inversek = 5;
public double insulationInversek = 0;
public double inverseHeatCapacity = 1;
public ColourRGBA baseColour = new ColourRGBA(0.2, 0.2, 0.2, 1);
public double heatToAbsorb = 0;
public static TransmitterIcons heatIcons = new TransmitterIcons(1, 2);
@Override
public HeatNetwork createNetworkFromSingleTransmitter(IGridTransmitter<HeatNetwork> transmitter)
public PartHeatTransmitter()
{
return new HeatNetwork(transmitter);
transmitterDelegate = new MultipartHeatTransmitter(this);
}
@Override
public HeatNetwork createNetworkByMergingSet(Set<HeatNetwork> networks)
public HeatNetwork createNewNetwork()
{
return new HeatNetwork();
}
@Override
public HeatNetwork createNetworkByMerging(Collection networks)
{
return new HeatNetwork(networks);
}
@Override
public int getTransmitterNetworkSize()
{
return getTransmitterNetwork().getSize();
}
@Override
public int getTransmitterNetworkAcceptorSize()
{
return getTransmitterNetwork().getAcceptorSize();
}
@Override
public String getTransmitterNetworkNeeded()
{
return getTransmitterNetwork().getNeededInfo();
}
@Override
public String getTransmitterNetworkFlow()
{
return getTransmitterNetwork().getFlowInfo();
}
@Override
public int getCapacity()
{
@ -84,72 +52,14 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
}
@Override
public double getTemp()
public Object getBuffer()
{
return temperature;
}
@Override
public double getInverseConductionCoefficient()
{
return inversek;
}
@Override
public double getInsulationCoefficient(ForgeDirection side)
{
return insulationInversek;
}
@Override
public void transferHeatTo(double heat)
{
heatToAbsorb += heat;
}
@Override
public double[] simulateHeat()
{
return HeatUtils.simulate(this);
}
@Override
public double applyTemperatureChange()
{
temperature += inverseHeatCapacity * heatToAbsorb;
heatToAbsorb = 0;
if(Math.abs(temperature - clientTemperature) > (temperature / 100))
{
clientTemperature = temperature;
sendTemp();
}
return temperature;
}
@Override
public boolean canConnectHeat(ForgeDirection side)
{
return true;
}
@Override
public IHeatTransfer getAdjacent(ForgeDirection side)
{
if(connectionMapContainsSide(getAllCurrentConnections(), side))
{
TileEntity adj = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(adj instanceof IHeatTransfer)
{
return (IHeatTransfer)adj;
}
}
return null;
}
@Override
public void takeShare() {}
public static void registerIcons(IIconRegister register)
{
heatIcons.registerCenterIcons(register, new String[] {"HeatTransmitter"});
@ -175,7 +85,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return TransmitterType.HEAT_TRANSMITTER;
}
@ -201,7 +111,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
@Override
protected boolean onConfigure(EntityPlayer player, int part, int side)
{
temperature += 10000;
getTransmitter().temperature += 10000;
return true;
}
@ -220,7 +130,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
{
super.load(nbtTags);
temperature = nbtTags.getDouble("temperature");
getTransmitter().temperature = nbtTags.getDouble("temperature");
}
@Override
@ -228,14 +138,14 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
{
super.save(nbtTags);
nbtTags.setDouble("temperature", temperature);
nbtTags.setDouble("temperature", getTransmitter().temperature);
}
public void sendTemp()
{
MCDataOutput packet = getWriteStream();
packet.writeBoolean(true);
packet.writeDouble(temperature);
packet.writeDouble(getTransmitter().temperature);
}
@Override
@ -251,7 +161,7 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
{
if(packet.readBoolean())
{
temperature = packet.readDouble();
getTransmitter().temperature = packet.readDouble();
}
else {
super.readDesc(packet);
@ -260,6 +170,11 @@ public class PartHeatTransmitter extends PartTransmitter<HeatNetwork> implements
public ColourRGBA getBaseColour()
{
return baseColour;
return getTransmitter().material.baseColour;
}
public MultipartHeatTransmitter getTransmitter()
{
return (MultipartHeatTransmitter)transmitterDelegate;
}
}

View file

@ -1,18 +1,14 @@
package mekanism.common.multipart;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.Range4D;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.common.base.ITransporterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.HashList;
import mekanism.common.InventoryNetwork;
import mekanism.common.Mekanism;
import mekanism.common.Tier;
@ -22,13 +18,12 @@ import mekanism.common.content.transporter.InvStack;
import mekanism.common.content.transporter.PathfinderCache;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.content.transporter.TransporterStack.Path;
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.TransporterUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
@ -40,32 +35,31 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork> implements ILogisticalTransporter
import io.netty.buffer.ByteBuf;
import codechicken.lib.vec.Vector3;
public class PartLogisticalTransporter extends PartTransmitter<IInventory, InventoryNetwork> implements ITransporterTile
{
public Tier.TransporterTier tier = Tier.TransporterTier.BASIC;
public static TransmitterIcons transporterIcons = new TransmitterIcons(8, 16);
public int speed = 5;
public EnumColor color;
public int pullDelay = 0;
public HashList<TransporterStack> transit = new HashList<TransporterStack>();
public Set<TransporterStack> needsSync = new HashSet<TransporterStack>();
public PartLogisticalTransporter(Tier.TransporterTier transporterTier)
public PartLogisticalTransporter(TransporterTier transporterTier)
{
this();
tier = transporterTier;
}
protected PartLogisticalTransporter() {}
public PartLogisticalTransporter()
{
transmitterDelegate = new MultipartTransporter(this);
}
@Override
public String getType()
@ -74,7 +68,7 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return tier.type;
}
@ -119,9 +113,9 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
@Override
protected boolean isValidTransmitter(TileEntity tileEntity)
{
ILogisticalTransporter transporter = (ILogisticalTransporter)tileEntity;
ILogisticalTransporter transporter = ((ITransporterTile)tileEntity).getTransmitter();
if(getColor() == null || transporter.getColor() == null || getColor() == transporter.getColor())
if(getTransmitter().getColor() == null || transporter.getColor() == null || getTransmitter().getColor() == transporter.getColor())
{
return super.isValidTransmitter(tileEntity);
}
@ -132,19 +126,19 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
@Override
public IIcon getCenterIcon(boolean opaque)
{
return transporterIcons.getCenterIcon(opaque ? tier.ordinal() : (color != null ? 7 : 6));
return transporterIcons.getCenterIcon(opaque ? tier.ordinal() : (getTransmitter().color != null ? 7 : 6));
}
@Override
public IIcon getSideIcon(boolean opaque)
{
return transporterIcons.getSideIcon(opaque ? tier.ordinal() : (color != null ? 11 : 10));
return transporterIcons.getSideIcon(opaque ? tier.ordinal() : (getTransmitter().color != null ? 11 : 10));
}
@Override
public IIcon getSideIconRotated(boolean opaque)
{
return transporterIcons.getSideIcon(opaque ? 4+tier.ordinal() : (color != null ? 13 : 12));
return transporterIcons.getSideIcon(opaque ? 4+tier.ordinal() : (getTransmitter().color != null ? 13 : 12));
}
@Override
@ -164,187 +158,10 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
{
super.update();
if(world().isRemote)
{
for(TransporterStack stack : transit)
{
if(stack != null)
{
stack.progress = Math.min(100, stack.progress+tier.speed);
}
}
}
else {
Set<TransporterStack> remove = new HashSet<TransporterStack>();
pullItems();
for(TransporterStack stack : transit)
{
if(!stack.initiatedPath)
{
if(stack.itemStack == null || !recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
stack.progress += tier.speed;
if(stack.progress > 100)
{
Coord4D prevSet = null;
if(stack.hasPath())
{
int currentIndex = stack.pathToTarget.indexOf(Coord4D.get(tile()));
if(currentIndex == 0) //Necessary for transition reasons, not sure why
{
remove.add(stack);
continue;
}
Coord4D next = stack.pathToTarget.get(currentIndex-1);
if(!stack.isFinal(this))
{
if(next != null && stack.canInsertToTransporter(stack.getNext(this).getTileEntity(world()), ForgeDirection.getOrientation(stack.getSide(this))))
{
ILogisticalTransporter nextTile = (ILogisticalTransporter)next.getTileEntity(world());
nextTile.entityEntering(stack, stack.progress%100);
remove.add(stack);
continue;
}
else if(next != null)
{
prevSet = next;
}
}
else {
if(stack.pathType != Path.NONE)
{
if(next != null && next.getTileEntity(world()) instanceof IInventory)
{
needsSync.add(stack);
IInventory inventory = (IInventory)next.getTileEntity(world());
if(inventory != null)
{
ItemStack rejected = InventoryUtils.putStackInInventory(inventory, stack.itemStack, stack.getSide(this), stack.pathType == Path.HOME);
if(rejected == null)
{
TransporterManager.remove(stack);
remove.add(stack);
continue;
}
else {
needsSync.add(stack);
stack.itemStack = rejected;
prevSet = next;
}
}
}
}
}
}
if(!recalculate(stack, prevSet))
{
remove.add(stack);
continue;
}
else {
if(prevSet != null)
{
stack.progress = 0;
}
else {
stack.progress = 50;
}
}
}
else if(stack.progress == 50)
{
if(stack.isFinal(this))
{
if(stack.pathType == Path.DEST && (!checkSideForInsert(stack) || !InventoryUtils.canInsert(stack.getDest().getTileEntity(world()), stack.color, stack.itemStack, stack.getSide(this), false)))
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
else if(stack.pathType == Path.HOME && (!checkSideForInsert(stack) || !InventoryUtils.canInsert(stack.getDest().getTileEntity(world()), stack.color, stack.itemStack, stack.getSide(this), true)))
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
else if(stack.pathType == Path.NONE)
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
}
else {
TileEntity next = stack.getNext(this).getTileEntity(world());
boolean recalculate = false;
if(!stack.canInsertToTransporter(next, ForgeDirection.getOrientation(stack.getSide(this))))
{
recalculate = true;
}
if(recalculate)
{
if(!recalculate(stack, null))
{
remove.add(stack);
continue;
}
}
}
}
}
for(TransporterStack stack : remove)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getSyncPacket(stack, true)), new Range4D(Coord4D.get(tile())));
transit.remove(stack);
MekanismUtils.saveChunk(tile());
}
for(TransporterStack stack : needsSync)
{
if(transit.contains(stack))
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getSyncPacket(stack, false)), new Range4D(Coord4D.get(tile())));
}
}
needsSync.clear();
}
getTransmitter().update();
}
private boolean checkSideForInsert(TransporterStack stack)
{
ForgeDirection side = ForgeDirection.getOrientation(stack.getSide(this));
return getConnectionType(side) == ConnectionType.NORMAL || getConnectionType(side) == ConnectionType.PUSH;
}
private void pullItems()
protected void pullItems()
{
if(pullDelay == 0)
{
@ -361,7 +178,7 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
if(stack != null && stack.getStack() != null)
{
ItemStack rejects = TransporterUtils.insert(tile, this, stack.getStack(), color, true, 0);
ItemStack rejects = TransporterUtils.insert(tile, getTransmitter(), stack.getStack(), getTransmitter().getColor(), true, 0);
if(TransporterManager.didEmit(stack.getStack(), rejects))
{
@ -382,123 +199,6 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
}
}
private boolean recalculate(TransporterStack stack, Coord4D from)
{
needsSync.add(stack);
if(stack.pathType != Path.NONE)
{
if(!TransporterManager.didEmit(stack.itemStack, stack.recalculatePath(this, 0)))
{
if(!stack.calculateIdle(this))
{
TransporterUtils.drop(this, stack);
return false;
}
}
}
else {
if(!stack.calculateIdle(this))
{
TransporterUtils.drop(this, stack);
return false;
}
}
if(from != null)
{
stack.originalLocation = from;
}
return true;
}
@Override
public ItemStack insert(Coord4D original, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
return insert_do(original, itemStack, color, doEmit, min, false);
}
private ItemStack insert_do(Coord4D original, ItemStack itemStack, EnumColor color, boolean doEmit, int min, boolean force)
{
ForgeDirection from = Coord4D.get(tile()).sideDifference(original).getOpposite();
TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack;
stack.originalLocation = original;
stack.homeLocation = original;
stack.color = color;
if((force && !canReceiveFrom(original.getTileEntity(world()), from)) || !stack.canInsertToTransporter(tile(), from))
{
return itemStack;
}
ItemStack rejected = stack.recalculatePath(this, min);
if(TransporterManager.didEmit(stack.itemStack, rejected))
{
stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected);
if(doEmit)
{
transit.add(stack);
TransporterManager.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getSyncPacket(stack, false)), new Range4D(Coord4D.get(tile())));
MekanismUtils.saveChunk(tile());
}
return rejected;
}
return itemStack;
}
@Override
public ItemStack insertRR(TileEntityLogisticalSorter outputter, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
ForgeDirection from = Coord4D.get(tile()).sideDifference(Coord4D.get(outputter)).getOpposite();
TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack;
stack.originalLocation = Coord4D.get(outputter);
stack.homeLocation = Coord4D.get(outputter);
stack.color = color;
if(!canReceiveFrom(outputter, from) || !stack.canInsertToTransporter(tile(), from))
{
return itemStack;
}
ItemStack rejected = stack.recalculateRRPath(outputter, this, min);
if(TransporterManager.didEmit(stack.itemStack, rejected))
{
stack.itemStack = TransporterManager.getToUse(stack.itemStack, rejected);
if(doEmit)
{
transit.add(stack);
TransporterManager.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getSyncPacket(stack, false)), new Range4D(Coord4D.get(tile())));
MekanismUtils.saveChunk(tile());
}
return rejected;
}
return itemStack;
}
@Override
public void entityEntering(TransporterStack stack, int progress)
{
stack.progress = progress;
transit.add(stack);
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getSyncPacket(stack, false)), new Range4D(Coord4D.get(tile())));
MekanismUtils.saveChunk(tile());
}
@Override
public void onWorldJoin()
{
@ -513,6 +213,18 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
}
}
@Override
public InventoryNetwork createNewNetwork()
{
return new InventoryNetwork();
}
@Override
public InventoryNetwork createNetworkByMerging(Collection<InventoryNetwork> networks)
{
return new InventoryNetwork(networks);
}
@Override
public void handlePacketData(ByteBuf dataStream) throws Exception
{
@ -524,28 +236,28 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
{
int c = dataStream.readInt();
EnumColor prev = color;
EnumColor prev = getTransmitter().getColor();
if(c != -1)
{
color = TransporterUtils.colors.get(c);
getTransmitter().setColor(TransporterUtils.colors.get(c));
}
else {
color = null;
getTransmitter().setColor(null);
}
if(prev != color)
if(prev != getTransmitter().getColor())
{
tile().markRender();
}
transit.clear();
getTransmitter().transit.clear();
int amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{
transit.add(TransporterStack.readFromPacket(dataStream));
getTransmitter().transit.add(TransporterStack.readFromPacket(dataStream));
}
}
else if(type == 1)
@ -555,7 +267,7 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
if(kill)
{
transit.remove(index);
getTransmitter().transit.remove(index);
}
else {
TransporterStack stack = TransporterStack.readFromPacket(dataStream);
@ -565,7 +277,7 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
stack.progress = 5;
}
transit.replace(index, stack);
getTransmitter().transit.replace(index, stack);
}
}
}
@ -577,19 +289,19 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
data.add(0);
if(color != null)
if(getTransmitter().getColor() != null)
{
data.add(TransporterUtils.colors.indexOf(color));
data.add(TransporterUtils.colors.indexOf(getTransmitter().getColor()));
}
else {
data.add(-1);
}
data.add(transit.size());
data.add(getTransmitter().transit.size());
for(TransporterStack stack : transit)
for(TransporterStack stack : getTransmitter().transit)
{
stack.write(this, data);
stack.write(getTransmitter(), data);
}
return data;
@ -601,11 +313,11 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
data.add(1);
data.add(kill);
data.add(transit.indexOf(stack));
data.add(getTransmitter().transit.indexOf(stack));
if(!kill)
{
stack.write(this, data);
stack.write(getTransmitter(), data);
}
return data;
@ -620,7 +332,7 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
if(nbtTags.hasKey("color"))
{
color = TransporterUtils.colors.get(nbtTags.getInteger("color"));
getTransmitter().setColor(TransporterUtils.colors.get(nbtTags.getInteger("color")));
}
if(nbtTags.hasKey("stacks"))
@ -629,9 +341,9 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
for(int i = 0; i < tagList.tagCount(); i++)
{
TransporterStack stack = TransporterStack.readFromNBT((NBTTagCompound)tagList.getCompoundTagAt(i));
TransporterStack stack = TransporterStack.readFromNBT(tagList.getCompoundTagAt(i));
transit.add(stack);
getTransmitter().transit.add(stack);
TransporterManager.add(stack);
}
}
@ -644,14 +356,14 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
nbtTags.setInteger("tier", tier.ordinal());
if(color != null)
if(getTransmitter().getColor() != null)
{
nbtTags.setInteger("color", TransporterUtils.colors.indexOf(color));
nbtTags.setInteger("color", TransporterUtils.colors.indexOf(getTransmitter().getColor()));
}
NBTTagList stacks = new NBTTagList();
for(TransporterStack stack : transit)
for(TransporterStack stack : getTransmitter().transit)
{
NBTTagCompound tagCompound = new NBTTagCompound();
stack.write(tagCompound);
@ -667,12 +379,12 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
@Override
protected boolean onConfigure(EntityPlayer player, int part, int side)
{
TransporterUtils.incrementColor(this);
TransporterUtils.incrementColor(getTransmitter());
refreshConnections();
notifyTileChange();
PathfinderCache.onChanged(Coord4D.get(tile()));
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tile()), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(tile())));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.toggleColor") + ": " + (color != null ? color.getName() : EnumColor.BLACK + MekanismUtils.localize("gui.none"))));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.toggleColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getName() : EnumColor.BLACK + MekanismUtils.localize("gui.none"))));
return true;
}
@ -681,58 +393,22 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
public boolean onRightClick(EntityPlayer player, int side)
{
super.onRightClick(player, side);
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.viewColor") + ": " + (color != null ? color.getName() : "None")));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " " + MekanismUtils.localize("tooltip.configurator.viewColor") + ": " + (getTransmitter().getColor() != null ? getTransmitter().getColor().getName() : "None")));
return true;
}
@Override
public EnumColor getColor()
{
return color;
}
@Override
public void setColor(EnumColor c)
{
color = c;
}
@Override
public EnumColor getRenderColor(boolean post)
{
return post ? null : color;
return post ? null : getTransmitter().getColor();
}
@Override
public boolean transparencyRender()
{
return true;
}
@Override
public boolean canEmitTo(TileEntity tileEntity, ForgeDirection side)
{
if(!canConnect(side))
{
return false;
}
return getConnectionType(side) == ConnectionType.NORMAL || getConnectionType(side) == ConnectionType.PUSH;
}
@Override
public boolean canReceiveFrom(TileEntity tileEntity, ForgeDirection side)
{
if(!canConnect(side))
{
return false;
}
return getConnectionType(side) == ConnectionType.NORMAL;
}
@Override
public void onRemoved()
{
@ -740,43 +416,13 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
if(!world().isRemote)
{
for(TransporterStack stack : transit)
for(TransporterStack stack : getTransmitter().transit)
{
TransporterUtils.drop(this, stack);
TransporterUtils.drop(getTransmitter(), stack);
}
}
}
@Override
public int getCost()
{
return 1;
}
@Override
public int getTransmitterNetworkSize()
{
return getTransmitterNetwork().getSize();
}
@Override
public int getTransmitterNetworkAcceptorSize()
{
return getTransmitterNetwork().getAcceptorSize();
}
@Override
public String getTransmitterNetworkNeeded()
{
return getTransmitterNetwork().getNeededInfo();
}
@Override
public String getTransmitterNetworkFlow()
{
return getTransmitterNetwork().getFlowInfo();
}
@Override
public int getCapacity()
{
@ -784,14 +430,22 @@ public class PartLogisticalTransporter extends PartTransmitter<InventoryNetwork>
}
@Override
public InventoryNetwork createNetworkFromSingleTransmitter(IGridTransmitter<InventoryNetwork> transmitter)
public Object getBuffer()
{
return new InventoryNetwork(transmitter);
return null;
}
@Override
public InventoryNetwork createNetworkByMergingSet(Set<InventoryNetwork> networks)
public void takeShare() {}
@Override
public MultipartTransporter getTransmitter()
{
return new InventoryNetwork(networks);
return (MultipartTransporter)transmitterDelegate;
}
public int getCost()
{
return 1;
}
}

View file

@ -1,8 +1,7 @@
package mekanism.common.multipart;
import java.util.Set;
import java.util.Collection;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.FluidNetwork;
@ -21,27 +20,29 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import codechicken.lib.vec.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements IFluidHandler
{
public Tier.PipeTier tier = Tier.PipeTier.BASIC;
/** The fake tank used for fluid transfer calculations. */
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
import codechicken.lib.vec.Vector3;
public class PartMechanicalPipe extends PartTransmitter<IFluidHandler, FluidNetwork> implements IFluidHandler
{
public static TransmitterIcons pipeIcons = new TransmitterIcons(4, 8);
public float currentScale;
public FluidStack cacheFluid;
public FluidTank buffer = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
public FluidStack lastWrite;
public Tier.PipeTier tier;
public PartMechanicalPipe(Tier.PipeTier pipeTier)
{
super();
tier = pipeTier;
buffer.setCapacity(getCapacity());
}
@Override
@ -49,25 +50,13 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
{
if(!world().isRemote)
{
if(cacheFluid != null)
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
if(getTransmitterNetwork().fluidStored == null)
{
getTransmitterNetwork().fluidStored = cacheFluid;
}
else {
getTransmitterNetwork().fluidStored.amount += cacheFluid.amount;
}
cacheFluid = null;
}
if(getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0)
{
int last = lastWrite != null ? lastWrite.amount : 0;
if(last != getSaveShare())
FluidStack last = getSaveShare();
if((last != null && !(lastWrite != null && lastWrite.amount == last.amount && lastWrite.getFluid() == last.getFluid())) || (last == null && lastWrite != null))
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
@ -86,7 +75,7 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
if(received != null && received.amount != 0)
{
container.drain(side.getOpposite(), getTransmitterNetwork().emit(received, true), true);
container.drain(side.getOpposite(), takeFluid(received, true), true);
}
}
}
@ -96,39 +85,36 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
super.update();
}
private int getSaveShare()
private FluidStack getSaveShare()
{
if(getTransmitterNetwork().fluidStored != null)
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetwork().buffer != null)
{
int remain = getTransmitterNetwork().fluidStored.amount%getTransmitterNetwork().transmitters.size();
int toSave = getTransmitterNetwork().fluidStored.amount/getTransmitterNetwork().transmitters.size();
int remain = getTransmitter().getTransmitterNetwork().buffer.amount%getTransmitter().getTransmitterNetwork().transmitters.size();
int toSave = getTransmitter().getTransmitterNetwork().buffer.amount/getTransmitter().getTransmitterNetwork().transmitters.size();
if(getTransmitterNetwork().isFirst((IGridTransmitter<FluidNetwork>)tile()))
if(getTransmitter().getTransmitterNetwork().transmitters.iterator().next().equals(getTransmitter()))
{
toSave += remain;
}
return toSave;
return new FluidStack(getTransmitter().getTransmitterNetwork().buffer.getFluid(), toSave);
}
return 0;
return null;
}
@Override
public void onChunkUnload()
{
if(!world().isRemote)
if(!world().isRemote && getTransmitter().hasTransmitterNetwork())
{
if(lastWrite != null)
if(lastWrite != null && getTransmitter().getTransmitterNetwork().buffer != null)
{
if(getTransmitterNetwork().fluidStored != null)
{
getTransmitterNetwork().fluidStored.amount -= lastWrite.amount;
getTransmitter().getTransmitterNetwork().buffer.amount -= lastWrite.amount;
if(getTransmitterNetwork().fluidStored.amount <= 0)
{
getTransmitterNetwork().fluidStored = null;
}
if(getTransmitter().getTransmitterNetwork().buffer.amount <= 0)
{
getTransmitter().getTransmitterNetwork().buffer = null;
}
}
}
@ -136,23 +122,6 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
super.onChunkUnload();
}
@Override
public void preSingleMerge(FluidNetwork network)
{
if(cacheFluid != null)
{
if(network.fluidStored == null)
{
network.fluidStored = cacheFluid;
}
else {
network.fluidStored.amount += cacheFluid.amount;
}
cacheFluid = null;
}
}
@Override
public void load(NBTTagCompound nbtTags)
{
@ -160,7 +129,7 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
if(nbtTags.hasKey("cacheFluid"))
{
cacheFluid = FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("cacheFluid"));
buffer.setFluid(FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("cacheFluid")));
}
tier = Tier.PipeTier.values()[nbtTags.getInteger("tier")];
@ -171,22 +140,9 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
{
super.save(nbtTags);
if(getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0 && getTransmitterNetwork(false).fluidStored != null)
if(lastWrite != null && lastWrite.amount > 0)
{
int remain = getTransmitterNetwork().fluidStored.amount%getTransmitterNetwork().transmitters.size();
int toSave = getTransmitterNetwork().fluidStored.amount/getTransmitterNetwork().transmitters.size();
if(getTransmitterNetwork().isFirst((IGridTransmitter<FluidNetwork>)tile()))
{
toSave += remain;
}
if(toSave > 0)
{
FluidStack stack = new FluidStack(getTransmitterNetwork().fluidStored.getFluid(), toSave);
lastWrite = stack;
nbtTags.setTag("cacheFluid", stack.writeToNBT(new NBTTagCompound()));
}
nbtTags.setTag("cacheFluid", lastWrite.writeToNBT(new NBTTagCompound()));
}
nbtTags.setInteger("tier", tier.ordinal());
@ -230,7 +186,7 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return tier.type;
}
@ -242,13 +198,13 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
}
@Override
public FluidNetwork createNetworkFromSingleTransmitter(IGridTransmitter<FluidNetwork> transmitter)
public FluidNetwork createNewNetwork()
{
return new FluidNetwork(transmitter);
return new FluidNetwork();
}
@Override
public FluidNetwork createNetworkByMergingSet(Set<FluidNetwork> networks)
public FluidNetwork createNetworkByMerging(Collection<FluidNetwork> networks)
{
return new FluidNetwork(networks);
}
@ -263,12 +219,34 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
}
}
@Override
public int getCapacity()
{
return tier.pipeCapacity;
}
@Override
public FluidStack getBuffer()
{
return buffer == null ? null : buffer.getFluid();
}
@Override
public void takeShare()
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetwork().buffer != null && lastWrite != null)
{
getTransmitter().getTransmitterNetwork().buffer.amount -= lastWrite.amount;
buffer.setFluid(lastWrite);
}
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
if(getConnectionType(from) == ConnectionType.NORMAL)
{
return getTransmitterNetwork().emit(resource, doFill);
return takeFluid(resource, doFill);
}
return 0;
@ -303,44 +281,25 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
{
if(getConnectionType(from) != ConnectionType.NONE)
{
return new FluidTankInfo[] {dummyTank.getInfo()};
return new FluidTankInfo[] {buffer.getInfo()};
}
return new FluidTankInfo[0];
}
@Override
public int getTransmitterNetworkSize()
{
return getTransmitterNetwork().getSize();
}
@Override
public int getTransmitterNetworkAcceptorSize()
{
return getTransmitterNetwork().getAcceptorSize();
}
@Override
public String getTransmitterNetworkNeeded()
{
return getTransmitterNetwork().getNeededInfo();
}
@Override
public String getTransmitterNetworkFlow()
{
return getTransmitterNetwork().getFlowInfo();
}
@Override
public int getCapacity()
{
return tier.pipeCapacity;
}
public int getPullAmount()
{
return tier.pipePullAmount;
}
public int takeFluid(FluidStack fluid, boolean doEmit)
{
if(getTransmitter().hasTransmitterNetwork())
{
return getTransmitter().getTransmitterNetwork().emit(fluid, doEmit);
}
else {
return buffer.fill(fluid, doEmit);
}
}
}

View file

@ -1,10 +1,12 @@
package mekanism.common.multipart;
import java.util.Collection;
import java.util.Set;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasNetwork;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasHandler;
import mekanism.api.transmitters.IGridTransmitter;
@ -18,11 +20,13 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.vec.Vector3;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements IGasHandler
import codechicken.lib.vec.Vector3;
public class PartPressurizedTube extends PartTransmitter<IGasHandler, GasNetwork> implements IGasHandler
{
public Tier.TubeTier tier = Tier.TubeTier.BASIC;
@ -30,7 +34,8 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
public float currentScale;
public GasStack cacheGas;
public GasTank buffer = new GasTank(getCapacity());
public GasStack lastWrite;
public PartPressurizedTube(Tier.TubeTier tubeTier)
@ -43,20 +48,7 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
{
if(!world().isRemote)
{
if(cacheGas != null)
{
if(getTransmitterNetwork().gasStored == null)
{
getTransmitterNetwork().gasStored = cacheGas;
}
else {
getTransmitterNetwork().gasStored.amount += cacheGas.amount;
}
cacheGas = null;
}
if(getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0)
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
int last = lastWrite != null ? lastWrite.amount : 0;
@ -80,7 +72,7 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
if(received != null && received.amount != 0)
{
container.drawGas(side.getOpposite(), getTransmitterNetwork().emit(received, true), true);
container.drawGas(side.getOpposite(), takeGas(received, true), true);
}
}
}
@ -88,7 +80,7 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
}
else {
float targetScale = getTransmitterNetwork().gasScale;
float targetScale = getTransmitter().hasTransmitterNetwork() ? getTransmitter().getTransmitterNetwork().gasScale : (float)buffer.getStored()/(float)buffer.getMaxGas();
if(Math.abs(currentScale - targetScale) > 0.01)
{
@ -101,12 +93,12 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
private int getSaveShare()
{
if(getTransmitterNetwork().gasStored != null)
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetwork().buffer != null)
{
int remain = getTransmitterNetwork().gasStored.amount%getTransmitterNetwork().transmitters.size();
int toSave = getTransmitterNetwork().gasStored.amount/getTransmitterNetwork().transmitters.size();
int remain = getTransmitter().getTransmitterNetwork().buffer.amount%getTransmitter().getTransmitterNetwork().transmitters.size();
int toSave = getTransmitter().getTransmitterNetwork().buffer.amount/getTransmitter().getTransmitterNetwork().transmitters.size();
if(getTransmitterNetwork().isFirst((IGridTransmitter<GasNetwork>)tile()))
if(getTransmitter().getTransmitterNetwork().transmitters.iterator().next().equals(getTransmitter()))
{
toSave += remain;
}
@ -117,44 +109,18 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
return 0;
}
@Override
public TransmitterType getTransmitter()
{
return tier.type;
}
@Override
public void preSingleMerge(GasNetwork network)
{
if(cacheGas != null)
{
if(network.gasStored == null)
{
network.gasStored = cacheGas;
}
else {
network.gasStored.amount += cacheGas.amount;
}
cacheGas = null;
}
}
@Override
public void onChunkUnload()
{
if(!world().isRemote)
if(!world().isRemote && getTransmitter().hasTransmitterNetwork())
{
if(lastWrite != null)
if(lastWrite != null && getTransmitter().getTransmitterNetwork().buffer != null)
{
if(getTransmitterNetwork().gasStored != null)
{
getTransmitterNetwork().gasStored.amount -= lastWrite.amount;
getTransmitter().getTransmitterNetwork().buffer.amount -= lastWrite.amount;
if(getTransmitterNetwork().gasStored.amount <= 0)
{
getTransmitterNetwork().gasStored = null;
}
if(getTransmitter().getTransmitterNetwork().buffer.amount <= 0)
{
getTransmitter().getTransmitterNetwork().buffer = null;
}
}
}
@ -171,7 +137,7 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
if(nbtTags.hasKey("cacheGas"))
{
cacheGas = GasStack.readFromNBT(nbtTags.getCompoundTag("cacheGas"));
buffer.setGas(GasStack.readFromNBT(nbtTags.getCompoundTag("cacheGas")));
}
}
@ -182,23 +148,13 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
nbtTags.setInteger("tier", tier.ordinal());
if(getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0 && getTransmitterNetwork(false).gasStored != null)
int toSave = getSaveShare();
if(toSave > 0)
{
int remain = getTransmitterNetwork().gasStored.amount%getTransmitterNetwork().transmitters.size();
int toSave = getTransmitterNetwork().gasStored.amount/getTransmitterNetwork().transmitters.size();
if(getTransmitterNetwork().isFirst((IGridTransmitter<GasNetwork>)tile()))
{
toSave += remain;
}
if(toSave > 0)
{
GasStack stack = new GasStack(getTransmitterNetwork().gasStored.getGas(), toSave);
lastWrite = stack;
nbtTags.setTag("cacheGas", stack.write(new NBTTagCompound()));
}
GasStack stack = new GasStack(getTransmitter().getTransmitterNetwork().buffer.getGas(), toSave);
lastWrite = stack;
nbtTags.setTag("cacheGas", stack.write(new NBTTagCompound()));
}
}
@ -239,6 +195,12 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
return TransmissionType.GAS;
}
@Override
public TransmitterType getTransmitterType()
{
return tier.type;
}
@Override
public boolean isValidAcceptor(TileEntity tile, ForgeDirection side)
{
@ -246,41 +208,17 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
}
@Override
public GasNetwork createNetworkFromSingleTransmitter(IGridTransmitter<GasNetwork> transmitter)
public GasNetwork createNewNetwork()
{
return new GasNetwork(transmitter);
return new GasNetwork();
}
@Override
public GasNetwork createNetworkByMergingSet(Set<GasNetwork> networks)
public GasNetwork createNetworkByMerging(Collection<GasNetwork> networks)
{
return new GasNetwork(networks);
}
@Override
public int getTransmitterNetworkSize()
{
return getTransmitterNetwork().getSize();
}
@Override
public int getTransmitterNetworkAcceptorSize()
{
return getTransmitterNetwork().getAcceptorSize();
}
@Override
public String getTransmitterNetworkNeeded()
{
return getTransmitterNetwork().getNeededInfo();
}
@Override
public String getTransmitterNetworkFlow()
{
return getTransmitterNetwork().getFlowInfo();
}
@Override
@SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float f, int pass)
@ -297,12 +235,21 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
return tier.tubeCapacity;
}
@Override
public GasStack getBuffer()
{
return buffer == null ? null : buffer.getGas();
}
@Override
public void takeShare() {}
@Override
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer)
{
if(getConnectionType(side) == ConnectionType.NORMAL || getConnectionType(side) == ConnectionType.PULL)
{
return getTransmitterNetwork().emit(stack, doTransfer);
return takeGas(stack, doTransfer);
}
return 0;
@ -337,4 +284,16 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork> implements
{
return false;
}
public int takeGas(GasStack gasStack, boolean doEmit)
{
if(getTransmitter().hasTransmitterNetwork())
{
return getTransmitter().getTransmitterNetwork().emit(gasStack, doEmit);
}
else {
return buffer.receive(gasStack, doEmit);
}
}
}

View file

@ -1,5 +1,7 @@
package mekanism.common.multipart;
import mekanism.common.Tier.TransporterTier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.IIcon;
@ -12,7 +14,7 @@ public class PartRestrictiveTransporter extends PartLogisticalTransporter
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return TransmitterType.RESTRICTIVE_TRANSPORTER;
}

View file

@ -15,6 +15,7 @@ import mekanism.api.IConfigurable;
import mekanism.api.MekanismConfig.client;
import mekanism.api.transmitters.IBlockableConnection;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.MekanismItems;
@ -69,6 +70,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
public boolean redstoneReactive = true;
public ConnectionType[] connectionTypes = {ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL, ConnectionType.NORMAL};
public TileEntity[] cachedAcceptors = new TileEntity[6];
static
{
@ -142,6 +144,11 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
return (connections & tester) > 0;
}
public static byte setConnectionBit(byte connections, boolean toSet, ForgeDirection side)
{
return (byte)((connections & ~(byte)(1 << side.ordinal())) | (byte)((toSet?1:0) << side.ordinal()));
}
public abstract IIcon getCenterIcon(boolean opaque);
public abstract IIcon getSideIcon(boolean opaque);
@ -235,7 +242,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
{
TileEntity tileEntity = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(TransmissionType.checkTransmissionType(tileEntity, getTransmitter().getTransmission()) && isValidTransmitter(tileEntity))
if(tileEntity instanceof ITransmitterTile && TransmissionType.checkTransmissionType(((ITransmitterTile)tileEntity).getTransmitter(), getTransmitterType().getTransmission()) && isValidTransmitter(tileEntity))
{
connections |= 1 << side.ordinal();
}
@ -245,6 +252,56 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
return connections;
}
public boolean getPossibleAcceptorConnection(ForgeDirection side)
{
if(handlesRedstone() && redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())))
{
return false;
}
if(canConnectMutual(side))
{
TileEntity tileEntity = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(isValidAcceptor(tileEntity, side))
{
if(cachedAcceptors[side.ordinal()] != tileEntity)
{
cachedAcceptors[side.ordinal()] = tileEntity;
markDirtyAcceptor(side);
}
return true;
}
}
if(cachedAcceptors[side.ordinal()] != null)
{
cachedAcceptors[side.ordinal()] = null;
markDirtyAcceptor(side);
}
return false;
}
public boolean getPossibleTransmitterConnection(ForgeDirection side)
{
if(handlesRedstone() && redstoneReactive && MekanismUtils.isGettingPowered(world(), Coord4D.get(tile())))
{
return false;
}
if(canConnectMutual(side))
{
TileEntity tileEntity = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(tileEntity instanceof ITransmitterTile && TransmissionType.checkTransmissionType(((ITransmitterTile)tileEntity).getTransmitter(), getTransmitterType().getTransmission()) && isValidTransmitter(tileEntity))
{
return true;
}
}
return false;
}
public byte getPossibleAcceptorConnections()
{
byte connections = 0x00;
@ -262,9 +319,20 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
if(isValidAcceptor(tileEntity, side))
{
if(cachedAcceptors[side.ordinal()] != tileEntity)
{
cachedAcceptors[side.ordinal()] = tileEntity;
markDirtyAcceptor(side);
}
connections |= 1 << side.ordinal();
continue;
}
}
if(cachedAcceptors[side.ordinal()] != null)
{
cachedAcceptors[side.ordinal()] = null;
markDirtyAcceptor(side);
}
}
return connections;
@ -300,17 +368,17 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
if(connectionMapContainsSide(connections, side) || side == testingSide)
{
subParts.add(getTransmitter().getSize() == Size.SMALL ? smallSides[ord] : largeSides[ord]);
subParts.add(getTransmitterType().getSize() == Size.SMALL ? smallSides[ord] : largeSides[ord]);
}
}
}
subParts.add(getTransmitter().getSize() == Size.SMALL ? smallSides[6] : largeSides[6]);
subParts.add(getTransmitterType().getSize() == Size.SMALL ? smallSides[6] : largeSides[6]);
return subParts;
}
public abstract TransmitterType getTransmitter();
public abstract TransmitterType getTransmitterType();
@Override
public Iterable<Cuboid6> getCollisionBoxes()
@ -348,7 +416,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
@Override
public Cuboid6 getBounds()
{
return getTransmitter().getSize() == Size.SMALL ? smallSides[6] : largeSides[6];
return getTransmitterType().getSize() == Size.SMALL ? smallSides[6] : largeSides[6];
}
@Override
@ -358,7 +426,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
if(connectionMapContainsSide(getAllCurrentConnections(), direction) || direction == testingSide)
{
return getTransmitter().getSize().centerSize+1;
return getTransmitterType().getSize().centerSize+1;
}
return 0;
@ -507,7 +575,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return new ItemStack(MekanismItems.PartTransmitter, 1, getTransmitter().ordinal());
return new ItemStack(MekanismItems.PartTransmitter, 1, getTransmitterType().ordinal());
}
@Override
@ -516,16 +584,10 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
return true;
}
protected void onRedstoneSplit() {}
protected void onRedstoneJoin() {}
protected void onRefresh() {}
public void refreshConnections()
{
boolean prevPowered = redstonePowered;
if(redstoneReactive)
{
redstonePowered = MekanismUtils.isGettingPowered(world(), Coord4D.get(tile()));
@ -533,48 +595,60 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
else {
redstonePowered = false;
}
byte possibleTransmitters = getPossibleTransmitterConnections();
byte possibleAcceptors = getPossibleAcceptorConnections();
if(possibleTransmitters != currentTransmitterConnections)
{
if(handlesRedstone())
{
if(prevPowered != redstonePowered)
{
if(redstonePowered)
{
onRedstoneSplit();
}
else {
onRedstoneJoin();
}
notifyTileChange();
}
}
}
if(!world().isRemote)
{
if(getAllCurrentConnections() != (possibleTransmitters | possibleAcceptors))
if((possibleTransmitters | possibleAcceptors) != getAllCurrentConnections())
{
sendDesc = true;
}
currentTransmitterConnections = possibleTransmitters;
currentAcceptorConnections = possibleAcceptors;
}
}
public void refreshConnections(ForgeDirection side)
{
if(redstoneReactive)
{
redstonePowered = MekanismUtils.isGettingPowered(world(), Coord4D.get(tile()));
}
else {
redstonePowered = false;
}
boolean possibleTransmitter = getPossibleTransmitterConnection(side);
boolean possibleAcceptor = getPossibleAcceptorConnection(side);
if(!world().isRemote)
{
if((possibleTransmitter || possibleAcceptor) != connectionMapContainsSide(getAllCurrentConnections(), side))
{
sendDesc = true;
}
currentTransmitterConnections = possibleTransmitters;
currentAcceptorConnections = possibleAcceptors;
currentTransmitterConnections = setConnectionBit(currentTransmitterConnections, possibleTransmitter, side);
currentAcceptorConnections = setConnectionBit(currentAcceptorConnections, possibleAcceptor, side);
}
onRefresh();
}
protected void onModeChange(ForgeDirection side)
{
refreshConnections();
markDirtyAcceptor(side);
}
protected void markDirtyTransmitters()
{
notifyTileChange();
}
protected void markDirtyAcceptor(ForgeDirection side) {}
@Override
public void onAdded()
{
@ -595,7 +669,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
@Override
public void onNeighborTileChanged(int side, boolean weak)
{
refreshConnections();
refreshConnections(ForgeDirection.getOrientation(side));
}
@Override
@ -603,7 +677,12 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
{
if(handlesRedstone())
{
boolean prevPowered = redstonePowered;
refreshConnections();
if(prevPowered != redstonePowered)
{
markDirtyTransmitters();
}
}
}
@ -611,7 +690,12 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
public void onPartChanged(TMultiPart part)
{
super.onPartChanged(part);
byte transmittersBefore = currentTransmitterConnections;
refreshConnections();
if(transmittersBefore != currentTransmitterConnections)
{
markDirtyTransmitters();
}
}
@Override
@ -663,7 +747,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
return RenderPartTransmitter.contents_models.get(name);
}
else {
if(getTransmitter().getSize() == Size.LARGE)
if(getTransmitterType().getSize() == Size.LARGE)
{
return RenderPartTransmitter.large_models.get(name);
}
@ -689,7 +773,7 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
connectionTypes[hit.subHit] = connectionTypes[hit.subHit].next();
sendDesc = true;
onModeChange(ForgeDirection.getOrientation(side));
onModeChange(ForgeDirection.getOrientation(hit.subHit));
player.addChatMessage(new ChatComponentText("Connection type changed to " + connectionTypes[hit.subHit].toString()));
return true;
@ -727,22 +811,6 @@ public abstract class PartSidedPipe extends TMultiPart implements TSlottedPart,
return true;
}
public boolean canConnectToAcceptor(ForgeDirection side, boolean ignoreActive)
{
if(!isValidAcceptor(Coord4D.get(tile()).getFromSide(side).getTileEntity(world()), side) || !connectionMapContainsSide(currentAcceptorConnections, side))
{
return false;
}
if(!ignoreActive)
{
return getConnectionType(side) == ConnectionType.NORMAL || getConnectionType(side) == ConnectionType.PUSH;
}
else {
return connectionTypes[side.ordinal()] == ConnectionType.NORMAL || connectionTypes[side.ordinal()] == ConnectionType.PUSH;
}
}
public static enum ConnectionType
{
NORMAL,

View file

@ -1,301 +1,116 @@
package mekanism.common.multipart;
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.transmitters.DynamicNetwork.NetworkClientRequest;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmitterNetworkRegistry;
import mekanism.client.ClientTickHandler;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTransmitterUpdate.PacketType;
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends PartSidedPipe implements IGridTransmitter<N>
public abstract class PartTransmitter<A, N extends DynamicNetwork<A, N>> extends PartSidedPipe implements ITransmitterTile<A, N>
{
public N theNetwork;
public MultipartTransmitter<A, N> transmitterDelegate;
public byte newSidesMerged;
public PartTransmitter()
{
transmitterDelegate = new MultipartTransmitter<>(this);
}
@Override
public void bind(TileMultipart t)
public MultipartTransmitter<A, N> getTransmitter()
{
if(tile() != null && theNetwork != null)
return transmitterDelegate;
}
@Override
public void onWorldJoin()
{
super.onWorldJoin();
if(!world().isRemote)
{
getTransmitterNetwork().transmitters.remove(tile());
super.bind(t);
getTransmitterNetwork().transmitters.add((IGridTransmitter<N>)tile());
TransmitterNetworkRegistry.registerOrphanTransmitter(getTransmitter());
}
else {
super.bind(t);
}
}
@Override
public void refreshTransmitterNetwork()
{
getTransmitterNetwork().refresh((IGridTransmitter<N>)tile());
getTransmitterNetwork().refresh();
}
@Override
public void onRefresh()
{
refreshTransmitterNetwork();
}
@Override
public void onRedstoneSplit()
{
getTransmitterNetwork().split((IGridTransmitter<N>)tile());
setTransmitterNetwork(null);
}
@Override
public void onRedstoneJoin()
{
setTransmitterNetwork(null);
getTransmitterNetwork();
}
@Override
public void onPartChanged(TMultiPart part)
{
byte transmitterConnections = currentTransmitterConnections;
super.onPartChanged(part);
byte addedSides = (byte)(0b00111111 & (currentTransmitterConnections & ~transmitterConnections));
mergeNewSideNets(addedSides);
}
public void mergeNewSideNets(byte sides)
{
if(theNetwork != null)
else
{
HashSet<N> connectedNets = new HashSet<N>();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if(connectionMapContainsSide(sides, side))
{
TileEntity cable = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(TransmissionType.checkTransmissionType(cable, getTransmissionType()) && ((IGridTransmitter<N>)cable).getTransmitterNetwork(false) != null)
{
connectedNets.add(((IGridTransmitter<N>)cable).getTransmitterNetwork());
}
}
}
if(connectedNets.size() == 0)
{
newSidesMerged = 0x00;
return;
}
else {
connectedNets.add(theNetwork);
theNetwork = createNetworkByMergingSet(connectedNets);
theNetwork.fullRefresh();
theNetwork.updateCapacity();
newSidesMerged = sides;
sendDesc = true;
}
MinecraftForge.EVENT_BUS.post(new NetworkClientRequest(tile()));
}
}
@Override
public void setTransmitterNetwork(N network)
{
if(network != theNetwork)
{
removeFromTransmitterNetwork();
theNetwork = network;
}
}
public abstract N createNewNetwork();
@Override
public boolean areTransmitterNetworksEqual(TileEntity tileEntity)
{
return tileEntity instanceof IGridTransmitter && getTransmissionType() == ((IGridTransmitter)tileEntity).getTransmissionType();
}
@Override
public N getTransmitterNetwork()
{
return getTransmitterNetwork(true);
}
@Override
public N getTransmitterNetwork(boolean createIfNull)
{
if(theNetwork == null && createIfNull)
{
byte possibleTransmitters = getPossibleTransmitterConnections();
HashSet<N> connectedNets = new HashSet<N>();
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if(connectionMapContainsSide(possibleTransmitters, side))
{
TileEntity cable = Coord4D.get(tile()).getFromSide(side).getTileEntity(world());
if(TransmissionType.checkTransmissionType(cable, getTransmissionType()) && ((IGridTransmitter<N>)cable).getTransmitterNetwork(false) != null)
{
connectedNets.add(((IGridTransmitter<N>)cable).getTransmitterNetwork());
}
}
}
if(connectedNets.size() == 0)
{
theNetwork = createNetworkFromSingleTransmitter((IGridTransmitter<N>)tile());
theNetwork.fullRefresh();
theNetwork.updateCapacity();
}
else if(connectedNets.size() == 1)
{
N network = connectedNets.iterator().next();
preSingleMerge(network);
theNetwork = network;
theNetwork.transmitters.add((IGridTransmitter<N>)tile());
theNetwork.fullRefresh();
theNetwork.updateCapacity();
}
else {
theNetwork = createNetworkByMergingSet(connectedNets);
theNetwork.transmitters.add((IGridTransmitter<N>)tile());
theNetwork.fullRefresh();
theNetwork.updateCapacity();
}
}
return theNetwork;
}
public void preSingleMerge(N network) {}
@Override
public void removeFromTransmitterNetwork()
{
if(theNetwork != null)
{
theNetwork.removeTransmitter((IGridTransmitter<N>)tile());
}
}
@Override
public void fixTransmitterNetwork()
{
getTransmitterNetwork().fixMessedUpNetwork((IGridTransmitter<N>)tile());
}
public abstract N createNetworkFromSingleTransmitter(IGridTransmitter<N> transmitter);
public abstract N createNetworkByMergingSet(Set<N> networks);
public abstract N createNetworkByMerging(Collection<N> networks);
@Override
public void onChunkUnload()
{
super.onChunkUnload();
getTransmitterNetwork().split((IGridTransmitter<N>)tile());
if(!world().isRemote)
{
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
getTransmitter().takeShare();
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
else {
try {
ClientTickHandler.killDeadNetworks();
} catch(Exception e) {}
else
{
getTransmitter().setTransmitterNetwork(null);
}
}
@Override
public void preRemove()
{
if(tile() instanceof IGridTransmitter)
{
getTransmitterNetwork().split((IGridTransmitter<N>)tile());
if(!world().isRemote)
{
TransmitterNetworkRegistry.getInstance().pruneEmptyNetworks();
}
else {
try {
ClientTickHandler.killDeadNetworks();
} catch(Exception e) {}
}
}
super.preRemove();
}
@Override
protected void onModeChange(ForgeDirection side)
{
super.onModeChange(side);
getTransmitterNetwork().refresh((IGridTransmitter<N>)tile());
if(!world().isRemote)
{
Mekanism.packetHandler.sendToDimension(new TransmitterUpdateMessage(PacketType.UPDATE, Coord4D.get(tile())), world().provider.dimensionId);
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
else
{
getTransmitter().setTransmitterNetwork(null);
}
super.preRemove();
}
@Override
public void onNeighborTileChanged(int side, boolean weak)
{
super.onNeighborTileChanged(side, weak);
if(!world().isRemote)
{
Mekanism.packetHandler.sendToDimension(new TransmitterUpdateMessage(PacketType.UPDATE, Coord4D.get(tile())), world().provider.dimensionId);
}
}
@Override
public TileEntity getTile()
public void markDirtyTransmitters()
{
return tile();
}
@Override
public void chunkLoad() {}
@Override
public void readDesc(MCDataInput packet)
{
super.readDesc(packet);
if(packet.readBoolean())
super.markDirtyTransmitters();
if(getTransmitter().hasTransmitterNetwork())
{
mergeNewSideNets(packet.readByte());
TransmitterNetworkRegistry.invalidateTransmitter(getTransmitter());
}
}
@Override
public void writeDesc(MCDataOutput packet)
public void markDirtyAcceptor(ForgeDirection side)
{
super.writeDesc(packet);
if(newSidesMerged != 0x00)
super.markDirtyAcceptor(side);
if(getTransmitter().hasTransmitterNetwork())
{
packet.writeBoolean(true);
packet.writeByte(newSidesMerged);
newSidesMerged = 0x00;
}
else {
packet.writeBoolean(false);
getTransmitter().getTransmitterNetwork().acceptorChanged(getTransmitter(), side);
}
}
public A getCachedAcceptor(ForgeDirection side)
{
ConnectionType type = connectionTypes[side.ordinal()];
if(type == ConnectionType.PULL || type == ConnectionType.NONE)
{
return null;
}
return connectionMapContainsSide(currentAcceptorConnections, side) ? (A)cachedAcceptors[side.ordinal()] : null;
}
public abstract int getCapacity();
public abstract Object getBuffer();
public abstract void takeShare();
}

View file

@ -1,14 +1,15 @@
package mekanism.common.multipart;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import mekanism.api.MekanismConfig.client;
import mekanism.api.MekanismConfig.general;
import mekanism.api.energy.EnergyAcceptorWrapper;
import mekanism.api.energy.EnergyStack;
import mekanism.api.energy.ICableOutputter;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.energy.IStrictEnergyStorage;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.client.render.RenderPartTransmitter;
import mekanism.common.EnergyNetwork;
@ -33,19 +34,20 @@ import ic2.api.energy.tile.IEnergySource;
@InterfaceList({
@Interface(iface = "cofh.api.energy.IEnergyHandler", modid = "CoFHCore"),
})
public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implements IStrictEnergyAcceptor, IEnergyHandler
public class PartUniversalCable extends PartTransmitter<EnergyAcceptorWrapper, EnergyNetwork> implements IStrictEnergyAcceptor, IEnergyHandler
{
public Tier.CableTier tier;
public static TransmitterIcons cableIcons = new TransmitterIcons(4, 8);
public double currentPower = 0;
public double cacheEnergy = 0;
public double lastWrite = 0;
public EnergyStack buffer = new EnergyStack(0);
public PartUniversalCable(Tier.CableTier cableTier)
{
super();
tier = cableTier;
}
@ -54,32 +56,27 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
{
if(world().isRemote)
{
double targetPower = getTransmitterNetwork().clientEnergyScale;
double targetPower = getTransmitter().hasTransmitterNetwork() ? getTransmitter().getTransmitterNetwork().clientEnergyScale : 0;
if(Math.abs(currentPower - targetPower) > 0.01)
{
currentPower = (9*currentPower + targetPower)/10;
currentPower = (9 * currentPower + targetPower) / 10;
}
}
else {
if(getTransmitterNetwork(false) != null && getTransmitterNetwork(false).getSize() > 0)
} else
{
if(getTransmitter().hasTransmitterNetwork() && getTransmitter().getTransmitterNetworkSize() > 0)
{
double last = lastWrite;
double last = getSaveShare();
if(last != getSaveShare())
if(last != lastWrite)
{
lastWrite = last;
MekanismUtils.saveChunk(tile());
}
}
if(cacheEnergy > 0)
{
getTransmitterNetwork().electricityStored += cacheEnergy;
cacheEnergy = 0;
}
List<ForgeDirection> sides = getConnections(ConnectionType.PULL);
if(!sides.isEmpty())
{
TileEntity[] connectedOutputters = CableUtils.getConnectedOutputters(tile());
@ -100,20 +97,19 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
toDraw -= takeEnergy(received, true);
}
((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw);
}
}
else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider)
} else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider)
{
double received = ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)(canDraw*general.TO_TE), true) * general.FROM_TE;
double toDraw = received;
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
toDraw -= takeEnergy(received, true);
}
((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)(toDraw*general.TO_TE), false);
@ -125,9 +121,9 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
if(received > 0)
{
toDraw -= getTransmitterNetwork().emit(received, true);
toDraw -= takeEnergy(received, true);
}
((IEnergySource)outputter).drawEnergy(toDraw * general.TO_IC2);
}
}
@ -140,11 +136,17 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
private double getSaveShare()
{
return EnergyNetwork.round(getTransmitterNetwork().electricityStored*(1F/getTransmitterNetwork().transmitters.size()));
if(getTransmitter().hasTransmitterNetwork())
{
return EnergyNetwork.round(getTransmitter().getTransmitterNetwork().buffer.amount * (1F / getTransmitter().getTransmitterNetwork().transmitters.size()));
}
else {
return buffer.amount;
}
}
@Override
public TransmitterType getTransmitter()
public TransmitterType getTransmitterType()
{
return tier.type;
}
@ -154,7 +156,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
{
super.load(nbtTags);
cacheEnergy = nbtTags.getDouble("cacheEnergy");
buffer.amount = nbtTags.getDouble("cacheEnergy");
tier = Tier.CableTier.values()[nbtTags.getInteger("tier")];
}
@ -162,11 +164,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
public void save(NBTTagCompound nbtTags)
{
super.save(nbtTags);
double toSave = getSaveShare();
lastWrite = toSave;
nbtTags.setDouble("cacheEnergy", toSave);
nbtTags.setDouble("cacheEnergy", lastWrite);
nbtTags.setInteger("tier", tier.ordinal());
}
@ -178,19 +176,12 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
public static void registerIcons(IIconRegister register)
{
cableIcons.registerCenterIcons(register, new String[] {"UniversalCableBasic", "UniversalCableAdvanced",
cableIcons.registerCenterIcons(register, new String[]{"UniversalCableBasic", "UniversalCableAdvanced",
"UniversalCableElite", "UniversalCableUltimate"});
cableIcons.registerSideIcons(register, new String[] {"SmallTransmitterVerticalBasic", "SmallTransmitterVerticalAdvanced", "SmallTransmitterVerticalElite", "SmallTransmitterVerticalUltimate",
"SmallTransmitterHorizontalBasic", "SmallTransmitterHorizontalAdvanced", "SmallTransmitterHorizontalElite", "SmallTransmitterHorizontalUltimate"});
}
@Override
public void preSingleMerge(EnergyNetwork network)
{
network.electricityStored += cacheEnergy;
cacheEnergy = 0;
}
@Override
public IIcon getCenterIcon(boolean opaque)
{
@ -216,13 +207,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
}
@Override
public EnergyNetwork createNetworkFromSingleTransmitter(IGridTransmitter<EnergyNetwork> transmitter)
{
return new EnergyNetwork(transmitter);
}
@Override
public EnergyNetwork createNetworkByMergingSet(Set<EnergyNetwork> networks)
public EnergyNetwork createNetworkByMerging(Collection<EnergyNetwork> networks)
{
return new EnergyNetwork(networks);
}
@ -243,39 +228,33 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
}
}
@Override
public EnergyNetwork createNewNetwork()
{
return new EnergyNetwork();
}
@Override
public void onChunkUnload()
{
if(!world().isRemote)
{
getTransmitterNetwork().electricityStored -= lastWrite;
}
takeShare();
super.onChunkUnload();
}
@Override
public int getTransmitterNetworkSize()
public Object getBuffer()
{
return getTransmitterNetwork().getSize();
return buffer;
}
@Override
public int getTransmitterNetworkAcceptorSize()
public void takeShare()
{
return getTransmitterNetwork().getAcceptorSize();
}
@Override
public String getTransmitterNetworkNeeded()
{
return getTransmitterNetwork().getNeededInfo();
}
@Override
public String getTransmitterNetworkFlow()
{
return getTransmitterNetwork().getFlowInfo();
if(getTransmitter().hasTransmitterNetwork())
{
getTransmitter().getTransmitterNetwork().buffer.amount -= lastWrite;
buffer.amount = lastWrite;
}
}
@Override
@ -284,9 +263,9 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
{
if(canReceiveEnergy(from))
{
return maxReceive - (int)Math.round(getTransmitterNetwork().emit(maxReceive * general.FROM_TE, !simulate) * general.TO_TE);
return maxReceive - (int)Math.round(takeEnergy(maxReceive * general.FROM_TE, !simulate) * general.TO_TE);
}
return 0;
}
@ -315,7 +294,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
@Method(modid = "CoFHCore")
public int getMaxEnergyStored(ForgeDirection from)
{
return (int)Math.round(getTransmitterNetwork().getEnergyNeeded()*general.TO_TE);
return (int)Math.round(getTransmitter().getTransmitterNetwork().getEnergyNeeded() * general.TO_TE);
}
@Override
@ -332,7 +311,7 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
return 0;
}
double toUse = Math.min(getMaxEnergy()-getEnergy(), amount);
double toUse = Math.min(getMaxEnergy() - getEnergy(), amount);
setEnergy(getEnergy() + toUse);
return toUse;
@ -347,18 +326,58 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
@Override
public double getMaxEnergy()
{
return getTransmitterNetwork().getCapacity();
if(getTransmitter().hasTransmitterNetwork())
{
return getTransmitter().getTransmitterNetwork().getCapacity();
} else
{
return getCapacity();
}
}
@Override
public double getEnergy()
{
return getTransmitterNetwork().electricityStored;
if(getTransmitter().hasTransmitterNetwork())
{
return getTransmitter().getTransmitterNetwork().buffer.amount;
} else
{
return buffer.amount;
}
}
@Override
public void setEnergy(double energy)
{
getTransmitterNetwork().electricityStored = energy;
if(getTransmitter().hasTransmitterNetwork())
{
getTransmitter().getTransmitterNetwork().buffer.amount = energy;
} else
{
buffer.amount = energy;
}
}
public double takeEnergy(double energy, boolean doEmit)
{
if(getTransmitter().hasTransmitterNetwork())
{
return getTransmitter().getTransmitterNetwork().emit(energy, doEmit);
}
else {
double used = Math.min(getCapacity() - buffer.amount, energy);
if(doEmit)
{
buffer.amount += used;
}
return energy - used;
}
}
@Override
public EnergyAcceptorWrapper getCachedAcceptor(ForgeDirection side)
{
return EnergyAcceptorWrapper.get(cachedAcceptors[side.ordinal()]);
}
}

View file

@ -5,6 +5,7 @@ import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.base.ITileNetwork;
@ -40,13 +41,13 @@ public class PacketDataRequest implements IMessageHandler<DataRequestMessage, IM
((TileEntityDynamicTank)tileEntity).sendStructure = true;
}
if(tileEntity instanceof IGridTransmitter)
if(tileEntity instanceof ITransmitterTile)
{
IGridTransmitter transmitter = (IGridTransmitter)tileEntity;
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
if(transmitter.getTransmitterNetwork() instanceof DynamicNetwork)
if(transmitter.hasTransmitterNetwork())
{
((DynamicNetwork)transmitter.getTransmitterNetwork()).addUpdate(player);
transmitter.getTransmitterNetwork().addUpdate(player);
}
}

View file

@ -1,11 +1,19 @@
package mekanism.common.network;
import java.util.Collection;
import java.util.HashSet;
import mekanism.api.Coord4D;
import mekanism.api.energy.EnergyAcceptorWrapper;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasNetwork;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasHandler;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.EnergyNetwork;
import mekanism.common.FluidNetwork;
@ -17,6 +25,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@ -34,56 +43,79 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
{
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
if(tileEntity instanceof IGridTransmitter)
if(tileEntity instanceof ITransmitterTile)
{
((IGridTransmitter)tileEntity).refreshTransmitterNetwork();
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
DynamicNetwork network = transmitter.hasTransmitterNetwork() && !message.newNetwork ? transmitter.getTransmitterNetwork() : transmitter.createEmptyNetwork();
network.register();
transmitter.setTransmitterNetwork(network);
for(Coord4D coord : message.transmitterCoords)
{
TileEntity tile = coord.getTileEntity(player.worldObj);
if(tile instanceof ITransmitterTile)
{
((ITransmitterTile)tile).getTransmitter().setTransmitterNetwork(network);
}
}
network.updateCapacity();
}
}
else if(message.packetType == PacketType.ENERGY)
{
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
if(tileEntity instanceof IGridTransmitter && ((IGridTransmitter)tileEntity).getTransmissionType() == TransmissionType.ENERGY)
if(tileEntity instanceof ITransmitterTile)
{
((IGridTransmitter<EnergyNetwork>)tileEntity).getTransmitterNetwork().clientEnergyScale = message.power;
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
if(transmitter.hasTransmitterNetwork() && transmitter.getTransmissionType() == TransmissionType.ENERGY)
{
((IGridTransmitter<EnergyAcceptorWrapper, EnergyNetwork>)transmitter).getTransmitterNetwork().clientEnergyScale = message.power;
}
}
}
else if(message.packetType == PacketType.GAS)
{
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
if(tileEntity instanceof IGridTransmitter && ((IGridTransmitter)tileEntity).getTransmissionType() == TransmissionType.GAS)
if(tileEntity instanceof ITransmitterTile)
{
GasNetwork net = ((IGridTransmitter<GasNetwork>)tileEntity).getTransmitterNetwork();
if(message.gasType != null)
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
if(transmitter.hasTransmitterNetwork() && transmitter.getTransmissionType() == TransmissionType.GAS)
{
net.refGas = message.gasType;
}
GasNetwork net = ((IGridTransmitter<IGasHandler, GasNetwork>)transmitter).getTransmitterNetwork();
net.gasStored = message.gasStack;
net.didTransfer = message.didGasTransfer;
if(message.gasType != null)
{
net.refGas = message.gasType;
}
net.buffer = message.gasStack;
net.didTransfer = message.didGasTransfer;
}
}
}
else if(message.packetType == PacketType.FLUID)
{
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
if(tileEntity instanceof IGridTransmitter && ((IGridTransmitter)tileEntity).getTransmissionType() == TransmissionType.FLUID)
if(tileEntity instanceof ITransmitterTile)
{
FluidNetwork net = ((IGridTransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork();
if(message.fluidType != null)
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
if(transmitter.hasTransmitterNetwork() && ((ITransmitterTile)tileEntity).getTransmitter().getTransmissionType() == TransmissionType.FLUID)
{
net.refFluid = message.fluidType;
}
FluidNetwork net = ((IGridTransmitter<IFluidHandler, FluidNetwork>)transmitter).getTransmitterNetwork();
net.fluidStored = message.fluidStack;
net.didTransfer = message.didFluidTransfer;
net.fluidScale = net.getScale();
if(message.fluidType != null)
{
net.refFluid = message.fluidType;
}
net.buffer = message.fluidStack;
net.didTransfer = message.didFluidTransfer;
}
}
}
return null;
}
@ -101,9 +133,14 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
public FluidStack fluidStack;
public Fluid fluidType;
public float fluidScale;
public boolean didFluidTransfer;
public int amount;
public boolean newNetwork;
public Collection<IGridTransmitter> transmittersAdded;
public Collection<Coord4D> transmitterCoords;
public TransmitterUpdateMessage() {}
@ -114,6 +151,10 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
switch(packetType)
{
case UPDATE:
newNetwork = (Boolean)data[0];
transmittersAdded = (Collection<IGridTransmitter>)data[1];
break;
case ENERGY:
power = (Double)data[0];
break;
@ -142,6 +183,14 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
switch(packetType)
{
case UPDATE:
dataStream.writeBoolean(newNetwork);
dataStream.writeInt(transmittersAdded.size());
for(IGridTransmitter transmitter : transmittersAdded)
{
transmitter.coord().write(dataStream);
}
break;
case ENERGY:
dataStream.writeDouble(power);
break;
@ -167,7 +216,18 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
coord4D = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
if(packetType == PacketType.ENERGY)
if(packetType == PacketType.UPDATE)
{
newNetwork = dataStream.readBoolean();
transmitterCoords = new HashSet<>();
int numTransmitters = dataStream.readInt();
for(int i = 0; i < numTransmitters; i++)
{
transmitterCoords.add(Coord4D.read(dataStream));
}
}
else if(packetType == PacketType.ENERGY)
{
power = dataStream.readDouble();
}
@ -188,7 +248,7 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
fluidType = type != -1 ? FluidRegistry.getFluid(type) : null;
amount = dataStream.readInt();
didFluidTransfer = dataStream.readBoolean();
if(fluidType != null)
{
fluidStack = new FluidStack(fluidType, amount);

View file

@ -10,6 +10,7 @@ import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.base.IActiveState;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.item.ItemBlockBasic;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
@ -194,9 +195,9 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento
{
TileEntity tile = Coord4D.get(this).getFromSide(ForgeDirection.getOrientation(0)).getTileEntity(worldObj);
if(tile instanceof ILogisticalTransporter)
if(tile instanceof ITransporterTile)
{
ILogisticalTransporter transporter = (ILogisticalTransporter)tile;
ILogisticalTransporter transporter = ((ITransporterTile)tile).getTransmitter();
ItemStack rejects = TransporterUtils.insert(this, transporter, bottomStack, null, true, 0);

View file

@ -21,6 +21,7 @@ import mekanism.common.base.IAdvancedBoundingBlock;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISustainedData;
import mekanism.common.base.ITransporterTile;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.content.miner.MItemStackFilter;
@ -296,9 +297,9 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
getTopEject(true, remains);
}
else if(getEjectInv() instanceof ILogisticalTransporter)
else if(getEjectInv() instanceof ITransporterTile)
{
ItemStack rejected = TransporterUtils.insert(getEjectTile(), (ILogisticalTransporter)getEjectInv(), getTopEject(false, null), null, true, 0);
ItemStack rejected = TransporterUtils.insert(getEjectTile(), ((ITransporterTile)getEjectInv()).getTransmitter(), getTopEject(false, null), null, true, 0);
if(TransporterManager.didEmit(getTopEject(false, null), rejected))
{

View file

@ -13,6 +13,7 @@ import java.util.EnumSet;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.common.base.IEnergyWrapper;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
@ -376,7 +377,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
@Method(modid = "IC2")
public double injectEnergy(ForgeDirection direction, double amount, double voltage)
{
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof IGridTransmitter)
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof ITransmitterTile)
{
return amount;
}

View file

@ -16,6 +16,7 @@ import mekanism.api.IConfigurable;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Range4D;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.common.Mekanism;
import mekanism.common.base.IActiveState;
import mekanism.common.base.IEnergyWrapper;
@ -392,7 +393,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement
@Method(modid = "IC2")
public double injectEnergy(ForgeDirection direction, double amount, double voltage)
{
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof IGridTransmitter)
if(Coord4D.get(this).getFromSide(direction).getTileEntity(worldObj) instanceof ITransmitterTile)
{
return amount;
}

View file

@ -15,6 +15,7 @@ import mekanism.common.base.IActiveState;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISustainedData;
import mekanism.common.base.ITransporterTile;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.content.transporter.Finder.FirstFinder;
import mekanism.common.content.transporter.InvStack;
@ -86,7 +87,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
TileEntity back = Coord4D.get(this).getFromSide(ForgeDirection.getOrientation(facing).getOpposite()).getTileEntity(worldObj);
TileEntity front = Coord4D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj);
if(back instanceof IInventory && (front instanceof ILogisticalTransporter || front instanceof IInventory))
if(back instanceof IInventory && (front instanceof ITransporterTile || front instanceof IInventory))
{
IInventory inventory = (IInventory)back;
@ -164,9 +165,9 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
{
ItemStack used = null;
if(front instanceof ILogisticalTransporter)
if(front instanceof ITransporterTile)
{
ILogisticalTransporter transporter = (ILogisticalTransporter)front;
ILogisticalTransporter transporter = ((ITransporterTile)front).getTransmitter();
if(!roundRobin)
{

View file

@ -19,6 +19,7 @@ import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.base.ITankManager;
import mekanism.common.base.ITileComponent;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.util.InventoryUtils;
@ -187,13 +188,13 @@ public class TileComponentEjector implements ITileComponent, IEjector
TileEntity tile = Coord4D.get(tileEntity).getFromSide(side).getTileEntity(tileEntity.getWorldObj());
ItemStack prev = stack.copy();
if(tile instanceof IInventory && !(tile instanceof ILogisticalTransporter))
if(tile instanceof IInventory && !(tile instanceof ITransporterTile))
{
stack = InventoryUtils.putStackInInventory((IInventory)tile, stack, side.ordinal(), false);
}
else if(tile instanceof ILogisticalTransporter)
else if(tile instanceof ITransporterTile)
{
ItemStack rejects = TransporterUtils.insert(tileEntity, (ILogisticalTransporter)tile, stack, outputColor, true, 0);
ItemStack rejects = TransporterUtils.insert(tileEntity, ((ITransporterTile)tile).getTransmitter(), stack, outputColor, true, 0);
if(TransporterManager.didEmit(stack, rejects))
{

View file

@ -0,0 +1,94 @@
package mekanism.common.transmitters;
import mekanism.api.transmitters.DynamicNetwork;
import mekanism.api.transmitters.IGridTransmitter;
public abstract class Transmitter<A, N extends DynamicNetwork<A, N>> implements IGridTransmitter<A, N>
{
public N theNetwork = null;
public boolean orphaned = true;
@Override
public N getTransmitterNetwork()
{
return theNetwork;
}
@Override
public boolean hasTransmitterNetwork()
{
return !isOrphan() && getTransmitterNetwork() != null;
}
@Override
public void setTransmitterNetwork(N network)
{
if(theNetwork == network)
{
return;
}
if(world().isRemote && theNetwork != null)
{
theNetwork.transmitters.remove(this);
if(theNetwork.transmitters.isEmpty())
{
theNetwork.deregister();
}
}
theNetwork = network;
orphaned = theNetwork == null;
if(world().isRemote && theNetwork != null)
{
theNetwork.transmitters.add(this);
}
}
@Override
public int getTransmitterNetworkSize()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getSize() : 0;
}
@Override
public int getTransmitterNetworkAcceptorSize()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getAcceptorSize() : 0;
}
@Override
public String getTransmitterNetworkNeeded()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getNeededInfo() : "No Network";
}
@Override
public String getTransmitterNetworkFlow()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getFlowInfo() : "No Network";
}
@Override
public String getTransmitterNetworkBuffer()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getStoredInfo() : "No Network";
}
@Override
public double getTransmitterNetworkCapacity()
{
return hasTransmitterNetwork() ? getTransmitterNetwork().getCapacity() : getCapacity();
}
@Override
public boolean isOrphan()
{
return orphaned;
}
@Override
public void setOrphan(boolean nowOrphaned)
{
orphaned = nowOrphaned;
}
}

View file

@ -14,10 +14,9 @@ import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.energy.ICableOutputter;
import mekanism.api.energy.IStrictEnergyAcceptor;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.base.IEnergyWrapper;
import mekanism.common.tile.TileEntityElectricBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyConnection;
@ -81,7 +80,11 @@ public final class CableUtils
public static boolean isCable(TileEntity tileEntity)
{
return TransmissionType.checkTransmissionType(tileEntity, TransmissionType.ENERGY);
if(tileEntity instanceof ITransmitterTile)
{
return TransmissionType.checkTransmissionType(((ITransmitterTile)tileEntity).getTransmitter(), TransmissionType.ENERGY);
}
return false;
}
/**
@ -181,7 +184,7 @@ public final class CableUtils
public static boolean isConnectable(TileEntity orig, TileEntity tileEntity, ForgeDirection side)
{
if(tileEntity instanceof IGridTransmitter)
if(tileEntity instanceof ITransmitterTile)
{
return false;
}

View file

@ -3,6 +3,7 @@ package mekanism.common.util;
import mekanism.api.Coord4D;
import mekanism.api.IHeatTransfer;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -24,7 +25,7 @@ public class HeatUtils
source.transferHeatTo(-heatToTransfer);
sink.transferHeatTo(heatToTransfer);
if(!(sink instanceof IGridTransmitter))
if(!(sink instanceof ITransmitterTile))
{
heatTransferred[0] += heatToTransfer;
}

View file

@ -6,8 +6,8 @@ import java.util.Collections;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.api.transmitters.ITransmitterTile;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
@ -19,31 +19,9 @@ public final class PipeUtils
{
public static final FluidTankInfo[] EMPTY = new FluidTankInfo[] {};
/**
* Gets all the pipes around a tile entity.
* @param tileEntity - center tile entity
* @return array of TileEntities
*/
public static TileEntity[] getConnectedPipes(TileEntity tileEntity)
{
TileEntity[] pipes = new TileEntity[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity pipe = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
if(TransmissionType.checkTransmissionType(pipe, TransmissionType.FLUID))
{
pipes[orientation.ordinal()] = pipe;
}
}
return pipes;
}
public static boolean isValidAcceptorOnSide(TileEntity tile, ForgeDirection side)
{
if(tile instanceof IGridTransmitter || !(tile instanceof IFluidHandler))
if(tile instanceof ITransmitterTile || !(tile instanceof IFluidHandler))
return false;
IFluidHandler container = (IFluidHandler)tile;
@ -67,65 +45,6 @@ public final class PipeUtils
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)
{
boolean[] connectable = new boolean[] {false, false, false, false, false, false};
TileEntity[] connectedPipes = PipeUtils.getConnectedPipes(tileEntity);
IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(tileEntity);
for(IFluidHandler container : connectedAcceptors)
{
if(container != null)
{
int side = Arrays.asList(connectedAcceptors).indexOf(container);
FluidTankInfo[] infoArray = container.getTankInfo(ForgeDirection.getOrientation(side).getOpposite());
if(infoArray != null && infoArray.length > 0)
{
boolean notNull = false;
for(FluidTankInfo info : container.getTankInfo(ForgeDirection.getOrientation(side).getOpposite()))
{
if(info != null)
{
notNull = true;
break;
}
}
if(notNull)
{
connectable[side] = true;
}
}
else if(container.canDrain(ForgeDirection.getOrientation(side).getOpposite(), FluidRegistry.WATER)
|| container.canFill(ForgeDirection.getOrientation(side).getOpposite(), FluidRegistry.WATER)) //I hesitate to pass null to these.
{
connectable[side] = true;
}
}
}
for(TileEntity tile : connectedPipes)
{
if(tile != null)
{
int side = Arrays.asList(connectedPipes).indexOf(tile);
connectable[side] = true;
}
}
return connectable;
}
/**
* Gets all the acceptors around a tile entity.
* @param tileEntity - center tile entity
@ -139,7 +58,7 @@ public final class PipeUtils
{
TileEntity acceptor = Coord4D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.getWorldObj());
if(acceptor instanceof IFluidHandler && !(acceptor instanceof IGridTransmitter))
if(acceptor instanceof IFluidHandler && !(acceptor instanceof ITransmitterTile))
{
acceptors[orientation.ordinal()] = (IFluidHandler)acceptor;
}

View file

@ -5,9 +5,10 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.transmitters.IGridTransmitter;
import mekanism.api.transmitters.ITransmitterTile;
import mekanism.api.util.ListUtils;
import mekanism.common.base.ILogisticalTransporter;
import mekanism.common.base.ITransporterTile;
import mekanism.common.content.transporter.TransporterManager;
import mekanism.common.content.transporter.TransporterStack;
import mekanism.common.tile.TileEntityLogisticalSorter;
@ -19,7 +20,6 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
public final class TransporterUtils
{
@ -31,21 +31,21 @@ public final class TransporterUtils
* @param tileEntity - center tile entity
* @return array of TileEntities
*/
public static TileEntity[] getConnectedTransporters(ILogisticalTransporter tileEntity)
public static ILogisticalTransporter[] getConnectedTransporters(ILogisticalTransporter tileEntity)
{
TileEntity[] transporters = new TileEntity[] {null, null, null, null, null, null};
ILogisticalTransporter[] transporters = new ILogisticalTransporter[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = Coord4D.get(tileEntity.getTile()).getFromSide(orientation).getTileEntity(tileEntity.getTile().getWorldObj());
TileEntity tile = tileEntity.coord().getFromSide(orientation).getTileEntity(tileEntity.world());
if(tile instanceof ILogisticalTransporter)
if(tile instanceof ITransporterTile)
{
ILogisticalTransporter transporter = (ILogisticalTransporter)tile;
ILogisticalTransporter otherTransporter = ((ITransporterTile)tile).getTransmitter();
if(transporter.getColor() == null || tileEntity.getColor() == null || transporter.getColor() == tileEntity.getColor())
if(otherTransporter.getColor() == null || tileEntity.getColor() == null || otherTransporter.getColor() == tileEntity.getColor())
{
transporters[orientation.ordinal()] = transporter.getTile();
transporters[orientation.ordinal()] = otherTransporter;
}
}
}
@ -55,7 +55,7 @@ public final class TransporterUtils
public static boolean isValidAcceptorOnSide(TileEntity tile, ForgeDirection side)
{
if(tile instanceof IGridTransmitter || !(tile instanceof IInventory))
if(tile instanceof ITransmitterTile || !(tile instanceof IInventory))
return false;
IInventory inventory = (IInventory)tile;
@ -74,15 +74,15 @@ public final class TransporterUtils
/**
* Gets all the adjacent connections to a TileEntity.
* @param tileEntity - center TileEntity
* @param transporter - center TileEntity
* @return boolean[] of adjacent connections
*/
public static boolean[] getConnections(ILogisticalTransporter tileEntity)
public static boolean[] getConnections(ILogisticalTransporter transporter)
{
boolean[] connectable = new boolean[] {false, false, false, false, false, false};
TileEntity[] connectedTransporters = getConnectedTransporters(tileEntity);
IInventory[] connectedInventories = getConnectedInventories(tileEntity);
ILogisticalTransporter[] connectedTransporters = getConnectedTransporters(transporter);
IInventory[] connectedInventories = getConnectedInventories(transporter);
for(IInventory inventory : connectedInventories)
{
@ -90,7 +90,7 @@ public final class TransporterUtils
{
int side = Arrays.asList(connectedInventories).indexOf(inventory);
if(!tileEntity.canConnect(ForgeDirection.getOrientation(side)))
if(!transporter.canConnect(ForgeDirection.getOrientation(side)))
{
continue;
}
@ -118,13 +118,13 @@ public final class TransporterUtils
}
}
for(TileEntity tile : connectedTransporters)
for(ILogisticalTransporter trans : connectedTransporters)
{
if(tile != null)
if(trans != null)
{
int side = Arrays.asList(connectedTransporters).indexOf(tile);
int side = Arrays.asList(connectedTransporters).indexOf(trans);
if(tileEntity.canConnectMutual(ForgeDirection.getOrientation(side)))
if(transporter.canConnectMutual(ForgeDirection.getOrientation(side)))
{
connectable[side] = true;
}
@ -136,18 +136,18 @@ public final class TransporterUtils
/**
* Gets all the inventories around a tile entity.
* @param tileEntity - center tile entity
* @param transporter - center tile entity
* @return array of IInventories
*/
public static IInventory[] getConnectedInventories(ILogisticalTransporter tileEntity)
public static IInventory[] getConnectedInventories(ILogisticalTransporter transporter)
{
IInventory[] inventories = new IInventory[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity inventory = Coord4D.get(tileEntity.getTile()).getFromSide(orientation).getTileEntity(tileEntity.getTile().getWorldObj());
TileEntity inventory = transporter.coord().getFromSide(orientation).getTileEntity(transporter.world());
if(inventory instanceof IInventory && !(inventory instanceof IGridTransmitter))
if(inventory instanceof IInventory && !(inventory instanceof ITransmitterTile))
{
inventories[orientation.ordinal()] = (IInventory)inventory;
}
@ -156,14 +156,14 @@ public final class TransporterUtils
return inventories;
}
public static ItemStack insert(TileEntity outputter, ILogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
public static ItemStack insert(TileEntity outputter, ILogisticalTransporter transporter, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
return tileEntity.insert(Coord4D.get(outputter), itemStack.copy(), color, doEmit, min);
return transporter.insert(Coord4D.get(outputter), itemStack.copy(), color, doEmit, min);
}
public static ItemStack insertRR(TileEntityLogisticalSorter outputter, ILogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
public static ItemStack insertRR(TileEntityLogisticalSorter outputter, ILogisticalTransporter transporter, ItemStack itemStack, EnumColor color, boolean doEmit, int min)
{
return tileEntity.insertRR(outputter, itemStack.copy(), color, doEmit, min);
return transporter.insertRR(outputter, itemStack.copy(), color, doEmit, min);
}
public static EnumColor increment(EnumColor color)
@ -196,7 +196,7 @@ public final class TransporterUtils
public static void drop(ILogisticalTransporter tileEntity, TransporterStack stack)
{
float[] pos = null;
float[] pos;
if(stack.pathToTarget != null)
{
@ -208,18 +208,18 @@ public final class TransporterUtils
TransporterManager.remove(stack);
EntityItem entityItem = new EntityItem(tileEntity.getTile().getWorldObj(), tileEntity.getTile().xCoord + pos[0], tileEntity.getTile().yCoord + pos[1], tileEntity.getTile().zCoord + pos[2], stack.itemStack);
EntityItem entityItem = new EntityItem(tileEntity.world(), tileEntity.coord().xCoord + pos[0], tileEntity.coord().yCoord + pos[1], tileEntity.coord().zCoord + pos[2], stack.itemStack);
entityItem.motionX = 0;
entityItem.motionY = 0;
entityItem.motionZ = 0;
tileEntity.getTile().getWorldObj().spawnEntityInWorld(entityItem);
tileEntity.world().spawnEntityInWorld(entityItem);
}
public static float[] getStackPosition(ILogisticalTransporter tileEntity, TransporterStack stack, float partial)
{
Coord4D offset = new Coord4D(0, 0, 0, tileEntity.getTile().getWorldObj().provider.dimensionId).step(ForgeDirection.getOrientation(stack.getSide(tileEntity)));
Coord4D offset = new Coord4D(0, 0, 0, tileEntity.world().provider.dimensionId).step(ForgeDirection.getOrientation(stack.getSide(tileEntity)));
float progress = (((float)stack.progress + partial) / 100F) - 0.5F;
float itemFix = 0;