Clean up null issues, add more annotations (#3590)

This commit is contained in:
James Mitchell authored and LexManos committed 2017-01-11 15:17:56 -08:00
1 parent 43efa3cfc4
commit c545b8ecd4
130 files changed
+629 -262

No files matched your search

@@ -22,9 +22,12 @@ package net.minecraftforge.fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.registry.RegistryDelegate;
import javax.annotation.Nullable;
/**
* ItemStack substitute for Fluids.
*
@@ -74,15 +77,20 @@ public class FluidStack
* This provides a safe method for retrieving a FluidStack - if the Fluid is invalid, the stack
* will return as null.
*/
@Nullable
public static FluidStack loadFluidStackFromNBT(NBTTagCompound nbt)
{
if (nbt == null)
{
return null;
}
String fluidName = nbt.getString("FluidName");
if (!nbt.hasKey("FluidName", Constants.NBT.TAG_STRING))
{
return null;
}
if (fluidName == null || FluidRegistry.getFluid(fluidName) == null)
String fluidName = nbt.getString("FluidName");
if (FluidRegistry.getFluid(fluidName) == null)
{
return null;
}
@@ -137,7 +145,7 @@ public class FluidStack
* The FluidStack for comparison
* @return true if the Fluids (IDs and NBT Tags) are the same
*/
public boolean isFluidEqual(FluidStack other)
public boolean isFluidEqual(@Nullable FluidStack other)
{
return other != null && getFluid() == other.getFluid() && isFluidStackTagEqual(other);
}
@@ -150,7 +158,7 @@ public class FluidStack
/**
* Determines if the NBT Tags are equal. Useful if the FluidIDs are known to be equal.
*/
public static boolean areFluidStackTagsEqual(FluidStack stack1, FluidStack stack2)
public static boolean areFluidStackTagsEqual(@Nullable FluidStack stack1, @Nullable FluidStack stack2)
{
return stack1 == null && stack2 == null ? true : stack1 == null || stack2 == null ? false : stack1.isFluidStackTagEqual(stack2);
}
@@ -161,7 +169,7 @@ public class FluidStack
* @param other
* @return true if this FluidStack contains the other FluidStack (same fluid and >= amount)
*/
public boolean containsFluid(FluidStack other)
public boolean containsFluid(@Nullable FluidStack other)
{
return isFluidEqual(other) && amount >= other.amount;
}