Add in persistence code for LiquidTank. Using it should protect against liquids that get removed f.e. Closes #395
This commit is contained in:
parent
b1e7248a67
commit
8a4a62ab4e
1 changed files with 28 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package net.minecraftforge.liquids;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
|
@ -149,4 +150,31 @@ public class LiquidTank implements ILiquidTank {
|
|||
{
|
||||
return LiquidDictionary.findLiquidName(liquid) != null;
|
||||
}
|
||||
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
if (containsValidLiquid())
|
||||
{
|
||||
liquid.writeToNBT(nbt);
|
||||
}
|
||||
else
|
||||
{
|
||||
nbt.setString("emptyTank", "");
|
||||
}
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public LiquidTank readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
if (!nbt.hasKey("emptyTank"))
|
||||
{
|
||||
LiquidStack liquid = LiquidStack.loadLiquidStackFromNBT(nbt);
|
||||
if (liquid != null)
|
||||
{
|
||||
setLiquid(liquid);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue