Add in persistence code for LiquidTank. Using it should protect against liquids that get removed f.e. Closes #395

This commit is contained in:
Christian 2013-03-29 16:20:40 -04:00
parent b1e7248a67
commit 8a4a62ab4e

View file

@ -1,5 +1,6 @@
package net.minecraftforge.liquids; package net.minecraftforge.liquids;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
/** /**
@ -149,4 +150,31 @@ public class LiquidTank implements ILiquidTank {
{ {
return LiquidDictionary.findLiquidName(liquid) != null; 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;
}
} }