Work on saving and loading of transmitter caches
This commit is contained in:
parent
8de6b8754f
commit
4ff79409f6
4 changed files with 182 additions and 3 deletions
|
@ -11,6 +11,7 @@ import mekanism.common.FluidNetwork;
|
|||
import mekanism.common.util.PipeUtils;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -28,7 +29,59 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
|
|||
{
|
||||
/** The fake tank used for fluid transfer calculations. */
|
||||
public FluidTank dummyTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||
|
||||
public static PartTransmitterIcons pipeIcons;
|
||||
|
||||
public FluidStack cacheFluid;
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.load(nbtTags);
|
||||
|
||||
if(nbtTags.hasKey("cacheFluid"))
|
||||
{
|
||||
cacheFluid = FluidStack.loadFluidStackFromNBT(nbtTags.getCompoundTag("cacheEnergy"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.save(nbtTags);
|
||||
|
||||
if(getTransmitterNetwork().fluidStored != null)
|
||||
{
|
||||
int remains = getTransmitterNetwork().fluidStored.amount%(int)getTransmitterNetwork().getMeanCapacity();
|
||||
int toSave = (getTransmitterNetwork().fluidStored.amount-remains)/(int)getTransmitterNetwork().getMeanCapacity();
|
||||
toSave += remains;
|
||||
|
||||
FluidStack stack = new FluidStack(getTransmitterNetwork().fluidStored.getFluid(), toSave);
|
||||
|
||||
getTransmitterNetwork().fluidStored.amount -= toSave;
|
||||
nbtTags.setCompoundTag("cacheEnergy", stack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable(TileEntity tileEntity)
|
||||
{
|
||||
if(tileEntity instanceof ITransmitter && TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
||||
{
|
||||
ITransmitter<FluidNetwork> transmitter = (ITransmitter<FluidNetwork>)tileEntity;
|
||||
|
||||
if(getTransmitterNetwork().fluidStored == null || transmitter.getTransmitterNetwork().fluidStored == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(getTransmitterNetwork().fluidStored.getFluid() == transmitter.getTransmitterNetwork().fluidStored.getFluid())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
|
@ -132,6 +185,22 @@ public class PartMechanicalPipe extends PartTransmitter<FluidNetwork> implements
|
|||
{
|
||||
if(!world().isRemote)
|
||||
{
|
||||
if(!world().isRemote)
|
||||
{
|
||||
if(cacheFluid != null)
|
||||
{
|
||||
if(getTransmitterNetwork().fluidStored == null)
|
||||
{
|
||||
getTransmitterNetwork().fluidStored = cacheFluid;
|
||||
}
|
||||
else {
|
||||
getTransmitterNetwork().fluidStored.amount += cacheFluid.amount;
|
||||
}
|
||||
|
||||
cacheFluid = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(isActive)
|
||||
{
|
||||
IFluidHandler[] connectedAcceptors = PipeUtils.getConnectedAcceptors(tile());
|
||||
|
|
|
@ -3,12 +3,14 @@ package mekanism.common.multipart;
|
|||
import java.util.Set;
|
||||
|
||||
import mekanism.api.gas.GasNetwork;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasHandler;
|
||||
import mekanism.api.transmitters.ITransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
import mekanism.client.render.PartTransmitterIcons;
|
||||
import mekanism.client.render.RenderPartTransmitter;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -19,6 +21,79 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
public class PartPressurizedTube extends PartTransmitter<GasNetwork>
|
||||
{
|
||||
public static PartTransmitterIcons tubeIcons;
|
||||
|
||||
public GasStack cacheGas;
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
super.update();
|
||||
|
||||
if(!world().isRemote)
|
||||
{
|
||||
if(cacheGas != null)
|
||||
{
|
||||
if(getTransmitterNetwork().gasStored == null)
|
||||
{
|
||||
getTransmitterNetwork().gasStored = cacheGas;
|
||||
}
|
||||
else {
|
||||
getTransmitterNetwork().gasStored.amount += cacheGas.amount;
|
||||
}
|
||||
|
||||
cacheGas = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.load(nbtTags);
|
||||
|
||||
if(nbtTags.hasKey("cacheGas"))
|
||||
{
|
||||
cacheGas = GasStack.readFromNBT(nbtTags.getCompoundTag("cacheGas"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.save(nbtTags);
|
||||
|
||||
if(getTransmitterNetwork().gasStored != null)
|
||||
{
|
||||
int remains = getTransmitterNetwork().gasStored.amount%(int)getTransmitterNetwork().getMeanCapacity();
|
||||
int toSave = (getTransmitterNetwork().gasStored.amount-remains)/(int)getTransmitterNetwork().getMeanCapacity();
|
||||
toSave += remains;
|
||||
|
||||
GasStack stack = new GasStack(getTransmitterNetwork().gasStored.getGas(), toSave);
|
||||
|
||||
getTransmitterNetwork().gasStored.amount -= toSave;
|
||||
nbtTags.setCompoundTag("cacheGas", stack.write(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectable(TileEntity tileEntity)
|
||||
{
|
||||
if(tileEntity instanceof ITransmitter && TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
||||
{
|
||||
ITransmitter<GasNetwork> transmitter = (ITransmitter<GasNetwork>)tileEntity;
|
||||
|
||||
if(getTransmitterNetwork().gasStored == null || transmitter.getTransmitterNetwork().gasStored == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if(getTransmitterNetwork().gasStored.getGas() == transmitter.getTransmitterNetwork().gasStored.getGas())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
|
@ -29,7 +104,7 @@ public class PartPressurizedTube extends PartTransmitter<GasNetwork>
|
|||
public static void registerIcons(IconRegister register)
|
||||
{
|
||||
tubeIcons = new PartTransmitterIcons(1);
|
||||
tubeIcons.registerCenterIcons(register, new String[]{"PressurizedTube"});
|
||||
tubeIcons.registerCenterIcons(register, new String[] {"PressurizedTube"});
|
||||
tubeIcons.registerSideIcon(register, "TransmitterSideSmall");
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends TM
|
|||
{
|
||||
TileEntity tileEntity = Object3D.get(tile()).getFromSide(side).getTileEntity(world());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()) && isConnectable(tileEntity))
|
||||
{
|
||||
connections |= 1 << side.ordinal();
|
||||
}
|
||||
|
@ -175,6 +175,11 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends TM
|
|||
return connections;
|
||||
}
|
||||
|
||||
public boolean isConnectable(TileEntity tileEntity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte getPossibleAcceptorConnections()
|
||||
{
|
||||
byte connections = 0x00;
|
||||
|
@ -222,7 +227,7 @@ public abstract class PartTransmitter<N extends DynamicNetwork<?, N>> extends TM
|
|||
{
|
||||
TileEntity tileEntity = Object3D.get(tile()).getFromSide(side).getTileEntity(world());
|
||||
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()))
|
||||
if(TransmissionType.checkTransmissionType(tileEntity, getTransmissionType()) && isConnectable(tileEntity))
|
||||
{
|
||||
((DynamicNetwork<?,N>)getTransmitterNetwork()).merge(((ITransmitter<N>)tileEntity).getTransmitterNetwork());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import mekanism.common.EnergyNetwork;
|
|||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.util.CableUtils;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -32,6 +33,8 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
public static PartTransmitterIcons cableIcons;
|
||||
|
||||
public double currentPower = 0;
|
||||
|
||||
public double cacheEnergy = 0;
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
|
@ -45,9 +48,36 @@ public class PartUniversalCable extends PartTransmitter<EnergyNetwork> implement
|
|||
currentPower = (9*currentPower + targetPower)/10;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(cacheEnergy > 0)
|
||||
{
|
||||
getTransmitterNetwork().electricityStored += cacheEnergy;
|
||||
}
|
||||
}
|
||||
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.load(nbtTags);
|
||||
|
||||
cacheEnergy = nbtTags.getDouble("cacheEnergy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbtTags)
|
||||
{
|
||||
super.save(nbtTags);
|
||||
|
||||
double remains = getTransmitterNetwork().electricityStored%getTransmitterNetwork().getMeanCapacity();
|
||||
double toSave = (getTransmitterNetwork().electricityStored-remains)/getTransmitterNetwork().getMeanCapacity();
|
||||
toSave += remains;
|
||||
|
||||
getTransmitterNetwork().electricityStored -= toSave;
|
||||
nbtTags.setDouble("cacheEnergy", toSave);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
|
|
Loading…
Reference in a new issue