mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Add in persistence code for LiquidTank. Using it should protect against liquids that get removed f.e. Closes #395
This commit is contained in:
1 parent
b1e7248a67
commit
8a4a62ab4e
1 file changed
+28
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user