Fix some client/server stuff, and fluid networks

This commit is contained in:
Ben Spiers 2015-04-03 18:04:56 +01:00
parent d14686ea2e
commit 29659ad2cd
6 changed files with 40 additions and 40 deletions

View file

@ -68,15 +68,18 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
{
if(buffer == null)
{
buffer = net.buffer;
buffer = net.buffer.copy();
} else
{
if(buffer.getGas() != net.buffer.getGas())
if(buffer.getGas() == net.buffer.getGas())
{
throw new RuntimeException("Gas types did not match when merging networks: " + buffer.getGas() + " vs. " + net.buffer.getGas());
buffer.amount += net.buffer.amount;
}
else if(net.buffer.amount > buffer.amount)
{
buffer = net.buffer.copy();
}
buffer.amount += net.buffer.amount;
}
net.buffer = null;
@ -106,12 +109,10 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
if(buffer == null || buffer.getGas() == null || buffer.amount == 0)
{
buffer = gas;
buffer = gas.copy();
return;
}
if(gas.getGas() != buffer.getGas())throw new RuntimeException("Gas Type " + gas.getGas().getName() + " of buffer does not match gas type " + buffer.getGas().getName() + " of Network");
buffer.amount += gas.amount;
gas.amount = 0;
}

View file

@ -46,6 +46,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
protected boolean needsUpdate = false;
protected int updateDelay = 0;
protected boolean firstUpdate = true;
protected World worldObj = null;
public void addNewTransmitters(Collection<IGridTransmitter<A, N>> newTransmitters)
@ -175,6 +176,7 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
{
transmitter.setTransmitterNetwork((N)this);
transmitters.add(transmitter);
transmittersAdded.add(transmitter);
}
possibleAcceptors.putAll(net.possibleAcceptors);
for(Entry<Coord4D, EnumSet<ForgeDirection>> entry : net.acceptorDirections.entrySet())
@ -338,7 +340,8 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
if(updateDelay == 0)
{
MinecraftForge.EVENT_BUS.post(new TransmittersAddedEvent(this, (Collection)transmittersAdded));
MinecraftForge.EVENT_BUS.post(new TransmittersAddedEvent(this, firstUpdate, (Collection)transmittersAdded));
firstUpdate = false;
transmittersAdded.clear();
needsUpdate = true;
}
@ -367,17 +370,19 @@ public abstract class DynamicNetwork<A, N extends DynamicNetwork<A, N>> implemen
public void queueClientUpdate(Collection<IGridTransmitter<A, N>> newTransmitters)
{
transmittersAdded.addAll(newTransmitters);
updateDelay = 2;
updateDelay = 3;
}
public static class TransmittersAddedEvent extends Event
{
public DynamicNetwork<?, ?> network;
public boolean newNetwork;
public Collection<IGridTransmitter> newTransmitters;
public TransmittersAddedEvent(DynamicNetwork net, Collection<IGridTransmitter> added)
public TransmittersAddedEvent(DynamicNetwork net, boolean newNet, Collection<IGridTransmitter> added)
{
network = net;
newNetwork = newNet;
newTransmitters = added;
}
}

View file

@ -47,37 +47,25 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
{
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;
buffer = net.buffer;
net.fluidScale = 0;
net.refFluid = null;
net.buffer = null;
buffer = net.buffer.copy();
}
}
else {
if(net.buffer != null)
{
if(buffer == null)
else {
if(buffer.getFluid() == net.buffer.getFluid())
{
buffer = net.buffer;
}
else {
if(buffer.getFluid() != net.buffer.getFluid())
{
throw new RuntimeException("Fluid types did not match when merging networks: " + buffer.getFluid().getName() + " vs. " + net.buffer.getFluid().getName());
}
buffer.amount += net.buffer.amount;
}
else if(net.buffer.amount > buffer.amount)
{
buffer = net.buffer.copy();
}
net.buffer = null;
}
net.buffer = null;
}
adoptTransmittersAndAcceptorsFrom(net);
@ -103,12 +91,10 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
if(buffer == null || buffer.getFluid() == null || buffer.amount == 0)
{
buffer = fluid;
buffer = fluid.copy();
return;
}
if(fluid.getFluid() != buffer.getFluid()) throw new RuntimeException("Fluid Type " + fluid.getFluid().getName() + " of buffer does not match fluid type " + buffer.getFluid().getName() + " of Network");
buffer.amount += fluid.amount;
fluid.amount = 0;
}

View file

@ -1280,7 +1280,7 @@ public class Mekanism
public void onTransmittersAddedEvent(TransmittersAddedEvent event)
{
try {
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.UPDATE, event.network.transmitters.iterator().next().coord(), event.newTransmitters), event.network.getPacketRange());
packetHandler.sendToReceivers(new TransmitterUpdateMessage(PacketType.UPDATE, event.network.transmitters.iterator().next().coord(), event.newNetwork, event.newTransmitters), event.network.getPacketRange());
} catch(Exception e) {}
}

View file

@ -234,7 +234,11 @@ public class PartMechanicalPipe extends PartTransmitter<IFluidHandler, FluidNetw
@Override
public void takeShare()
{
if(getTransmitter().hasTransmitterNetwork())
{
getTransmitter().getTransmitterNetwork().buffer.amount -= lastWrite.amount;
buffer.setFluid(lastWrite);
}
}
@Override

View file

@ -46,7 +46,7 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
if(tileEntity instanceof ITransmitterTile)
{
IGridTransmitter transmitter = ((ITransmitterTile)tileEntity).getTransmitter();
DynamicNetwork network = transmitter.hasTransmitterNetwork() ? transmitter.getTransmitterNetwork() : transmitter.createEmptyNetwork();
DynamicNetwork network = transmitter.hasTransmitterNetwork() && !message.newNetwork ? transmitter.getTransmitterNetwork() : transmitter.createEmptyNetwork();
transmitter.setTransmitterNetwork(network);
for(Coord4D coord : message.transmitterCoords)
{
@ -136,6 +136,7 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
public int amount;
public boolean newNetwork;
public Collection<IGridTransmitter> transmittersAdded;
public Collection<Coord4D> transmitterCoords;
@ -149,7 +150,8 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
switch(packetType)
{
case UPDATE:
transmittersAdded = (Collection<IGridTransmitter>)data[0];
newNetwork = (Boolean)data[0];
transmittersAdded = (Collection<IGridTransmitter>)data[1];
break;
case ENERGY:
power = (Double)data[0];
@ -181,6 +183,7 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
switch(packetType)
{
case UPDATE:
dataStream.writeBoolean(newNetwork);
dataStream.writeInt(transmittersAdded.size());
for(IGridTransmitter transmitter : transmittersAdded)
{
@ -214,6 +217,7 @@ public class PacketTransmitterUpdate implements IMessageHandler<TransmitterUpdat
if(packetType == PacketType.UPDATE)
{
newNetwork = dataStream.readBoolean();
transmitterCoords = new HashSet<>();
int numTransmitters = dataStream.readInt();