Work on dynamic rendering based on both buffer amount and average transfer
This commit is contained in:
parent
1e1eabfd5e
commit
bb8b89b7e7
4 changed files with 58 additions and 10 deletions
|
@ -27,6 +27,11 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
public boolean prevTransfer;
|
||||
|
||||
public float gasScale;
|
||||
public float prevScale;
|
||||
|
||||
/** Sent from server to client, actual stored buffer scale */
|
||||
public float definedScale;
|
||||
|
||||
public Gas refGas = null;
|
||||
|
||||
public GasStack gasStored;
|
||||
|
@ -156,9 +161,16 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
transferDelay--;
|
||||
}
|
||||
|
||||
if(Math.abs(getScale()-prevScale) > 0.01 || (getScale() != prevScale && (getScale() == 0 || getScale() == 1)))
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
prevScale = getScale();
|
||||
|
||||
if(didTransfer != prevTransfer || needsUpdate)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, refGas != null ? refGas.getID() : -1, didTransfer));
|
||||
MinecraftForge.EVENT_BUS.post(new GasTransferEvent(this, refGas != null ? refGas.getID() : -1, didTransfer, getScale()));
|
||||
needsUpdate = false;
|
||||
}
|
||||
|
||||
|
@ -183,11 +195,11 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
|
||||
if(didTransfer && gasScale < 1)
|
||||
{
|
||||
gasScale = Math.min(1, gasScale+0.02F);
|
||||
gasScale = Math.max(definedScale, Math.min(1, gasScale+0.02F));
|
||||
}
|
||||
else if(!didTransfer && gasScale > 0)
|
||||
{
|
||||
gasScale = Math.max(0, gasScale-0.02F);
|
||||
gasScale = Math.max(definedScale, Math.max(0, gasScale-0.02F));
|
||||
|
||||
if(gasScale == 0)
|
||||
{
|
||||
|
@ -275,15 +287,22 @@ public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
|
|||
|
||||
public final int transferType;
|
||||
public final boolean didTransfer;
|
||||
public final float gasScale;
|
||||
|
||||
public GasTransferEvent(GasNetwork network, int type, boolean did)
|
||||
public GasTransferEvent(GasNetwork network, int type, boolean did, float scale)
|
||||
{
|
||||
gasNetwork = network;
|
||||
transferType = type;
|
||||
didTransfer = did;
|
||||
gasScale = scale;
|
||||
}
|
||||
}
|
||||
|
||||
public float getScale()
|
||||
{
|
||||
return (gasStored != null ? gasStored.amount : 0)/getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -33,6 +33,11 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
public boolean prevTransfer;
|
||||
|
||||
public float fluidScale;
|
||||
public float prevScale;
|
||||
|
||||
/** Sent from server to client, actual stored buffer scale */
|
||||
public float definedScale;
|
||||
|
||||
public Fluid refFluid = null;
|
||||
|
||||
public FluidStack fluidStored;
|
||||
|
@ -161,9 +166,16 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
transferDelay--;
|
||||
}
|
||||
|
||||
if(Math.abs(getScale()-prevScale) > 0.01 || (getScale() != prevScale && (getScale() == 0 || getScale() == 1)))
|
||||
{
|
||||
needsUpdate = true;
|
||||
}
|
||||
|
||||
prevScale = getScale();
|
||||
|
||||
if(didTransfer != prevTransfer || needsUpdate)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, refFluid != null ? refFluid.getID() : -1, didTransfer));
|
||||
MinecraftForge.EVENT_BUS.post(new FluidTransferEvent(this, refFluid != null ? refFluid.getID() : -1, didTransfer, getScale()));
|
||||
needsUpdate = false;
|
||||
}
|
||||
|
||||
|
@ -188,11 +200,11 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
|
||||
if(didTransfer && fluidScale < 1)
|
||||
{
|
||||
fluidScale = Math.min(1, fluidScale+0.02F);
|
||||
fluidScale = Math.max(definedScale, Math.min(1, fluidScale+0.02F));
|
||||
}
|
||||
else if(!didTransfer && fluidScale > 0)
|
||||
{
|
||||
fluidScale = Math.max(0, fluidScale-0.02F);
|
||||
fluidScale = Math.max(definedScale, Math.max(0, fluidScale-0.02F));
|
||||
|
||||
if(fluidScale == 0)
|
||||
{
|
||||
|
@ -282,14 +294,21 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
|
||||
public final int fluidType;
|
||||
public final boolean didTransfer;
|
||||
public final float fluidScale;
|
||||
|
||||
public FluidTransferEvent(FluidNetwork network, int type, boolean did)
|
||||
public FluidTransferEvent(FluidNetwork network, int type, boolean did, float scale)
|
||||
{
|
||||
fluidNetwork = network;
|
||||
fluidType = type;
|
||||
didTransfer = did;
|
||||
fluidScale = scale;
|
||||
}
|
||||
}
|
||||
|
||||
public float getScale()
|
||||
{
|
||||
return (fluidStored != null ? fluidStored.amount : 0)/getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
|
|
|
@ -1340,7 +1340,7 @@ public class Mekanism
|
|||
public void onGasTransferred(GasTransferEvent event)
|
||||
{
|
||||
try {
|
||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType, event.didTransfer));
|
||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.GAS, event.gasNetwork.transmitters.iterator().next(), event.transferType, event.didTransfer, event.gasScale));
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
|
@ -1348,7 +1348,7 @@ public class Mekanism
|
|||
public void onLiquidTransferred(FluidTransferEvent event)
|
||||
{
|
||||
try {
|
||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidType, event.didTransfer));
|
||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTransmitterUpdate().setParams(PacketType.FLUID, event.fluidNetwork.transmitters.iterator().next(), event.fluidType, event.didTransfer, event.fluidScale));
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ public class PacketTransmitterUpdate implements IMekanismPacket
|
|||
public int fluidType;
|
||||
public boolean didFluidTransfer;
|
||||
|
||||
public float scale;
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
@ -51,10 +53,12 @@ public class PacketTransmitterUpdate implements IMekanismPacket
|
|||
case GAS:
|
||||
gasType = (Integer)data[2];
|
||||
didGasTransfer = (Boolean)data[3];
|
||||
scale = (Float)data[4];
|
||||
break;
|
||||
case FLUID:
|
||||
fluidType = (Integer)data[2];
|
||||
didFluidTransfer = (Boolean)data[3];
|
||||
scale = (Float)data[4];
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -96,11 +100,13 @@ public class PacketTransmitterUpdate implements IMekanismPacket
|
|||
|
||||
Gas gasType = GasRegistry.getGas(dataStream.readInt());
|
||||
didGasTransfer = dataStream.readBoolean();
|
||||
scale = dataStream.readFloat();
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().refGas = gasType;
|
||||
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().didTransfer = didGasTransfer;
|
||||
((ITransmitter<GasNetwork>)tileEntity).getTransmitterNetwork().definedScale = scale;
|
||||
}
|
||||
}
|
||||
else if(transmitterType == 3)
|
||||
|
@ -110,11 +116,13 @@ public class PacketTransmitterUpdate implements IMekanismPacket
|
|||
int type = dataStream.readInt();
|
||||
Fluid fluidType = type != -1 ? FluidRegistry.getFluid(type) : null;
|
||||
didFluidTransfer = dataStream.readBoolean();
|
||||
scale = dataStream.readFloat();
|
||||
|
||||
if(tileEntity != null)
|
||||
{
|
||||
((ITransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork().refFluid = fluidType;
|
||||
((ITransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork().didTransfer = didFluidTransfer;
|
||||
((ITransmitter<FluidNetwork>)tileEntity).getTransmitterNetwork().definedScale = scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,10 +144,12 @@ public class PacketTransmitterUpdate implements IMekanismPacket
|
|||
case GAS:
|
||||
dataStream.writeInt(gasType);
|
||||
dataStream.writeBoolean(didGasTransfer);
|
||||
dataStream.writeFloat(scale);
|
||||
break;
|
||||
case FLUID:
|
||||
dataStream.writeInt(fluidType);
|
||||
dataStream.writeBoolean(didFluidTransfer);
|
||||
dataStream.writeFloat(scale);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue