Add support for loading legacy liquid stacks as new fluid stacks.

Requires having been written with the "liquidname" code from forge 1.5.x
This commit is contained in:
cpw 2013-07-28 00:53:23 +02:00
parent 8b78f21199
commit 31bd8d438d

View file

@ -1,6 +1,8 @@
package net.minecraftforge.fluids;
import java.util.Locale;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -53,16 +55,29 @@ public class FluidStack
*/
public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt)
{
if (nbt == null || FluidRegistry.getFluid(nbt.getString("FluidName")) == null)
if (nbt == null)
{
return null;
}
FluidStack stack = new FluidStack(FluidRegistry.getFluidID(nbt.getString("FluidName")), nbt.getInteger("Amount"));
String fluidName = nbt.getString("FluidName");
if (fluidName == null)
{
fluidName = nbt.hasKey("LiquidName") ? nbt.getString("LiquidName").toLowerCase(Locale.ENGLISH) : null;
}
if (fluidName ==null || FluidRegistry.getFluid(fluidName) == null)
{
return null;
}
FluidStack stack = new FluidStack(FluidRegistry.getFluidID(fluidName), nbt.getInteger("Amount"));
if (nbt.hasKey("Tag"))
{
stack.tag = nbt.getCompoundTag("Tag");
}
else if (nbt.hasKey("extra"))
{
stack.tag = nbt.getCompoundTag("extra");
}
return stack;
}