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

@@ -30,6 +30,7 @@ import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This is a fluid block implementation which emulates vanilla Minecraft fluid behavior.
@@ -373,6 +374,7 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
@Nullable
public FluidStack drain(World world, BlockPos pos, boolean doDrain)
{
if (!isSourceBlock(world, pos))
@@ -49,6 +49,8 @@ import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.registry.RegistryDelegate;
import javax.annotation.Nullable;
/**
* Handles Fluid registrations. Fluids MUST be registered in order to function.
*/
@@ -219,6 +221,7 @@ public abstract class FluidRegistry
return getFluidName(stack.getFluid());
}
@Nullable
public static FluidStack getFluidStack(String fluidName, int amount)
{
if (!fluids.containsKey(fluidName))
@@ -255,7 +258,9 @@ public abstract class FluidRegistry
{
if (Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION))
{
FMLLog.getLogger().log(Level.ERROR, "Trying to activate the universal filled bucket too late. Call it statically in your Mods class. Mod: {}", Loader.instance().activeModContainer().getName());
ModContainer modContainer = Loader.instance().activeModContainer();
String modContainerName = modContainer == null ? null : modContainer.getName();
FMLLog.getLogger().log(Level.ERROR, "Trying to activate the universal filled bucket too late. Call it statically in your Mods class. Mod: {}", modContainerName);
}
else
{
@@ -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;
}
@@ -237,6 +237,7 @@ public class FluidTank implements IFluidTank, IFluidHandler
* Use this method to bypass the restrictions from {@link #canDrainFluidType(FluidStack)}
* Meant for use by the owner of the tank when they have {@link #canDrain()} set to false}.
*/
@Nullable
public FluidStack drainInternal(FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(getFluid()))
@@ -250,6 +251,7 @@ public class FluidTank implements IFluidTank, IFluidHandler
* Use this method to bypass the restrictions from {@link #canDrainFluidType(FluidStack)}
* Meant for use by the owner of the tank when they have {@link #canDrain()} set to false}.
*/
@Nullable
public FluidStack drainInternal(int maxDrain, boolean doDrain)
{
if (fluid == null || maxDrain <= 0)
@@ -343,9 +345,9 @@ public class FluidTank implements IFluidTank, IFluidHandler
*
* @see IFluidTankProperties#canDrainFluidType(FluidStack)
*/
public boolean canDrainFluidType(FluidStack fluid)
public boolean canDrainFluidType(@Nullable FluidStack fluid)
{
return canDrain();
return fluid != null && canDrain();
}
protected void onContentsChanged()
@@ -23,6 +23,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Implement this interface on Block classes which represent world-placeable Fluids.
@@ -60,6 +61,7 @@ public interface IFluidBlock
* If false, the drain will only be simulated.
* @return
*/
@Nullable
FluidStack drain(World world, BlockPos pos, boolean doDrain);
/**
@@ -48,6 +48,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* A universal bucket that can hold any liquid
@@ -103,7 +104,7 @@ public class UniversalBucket extends Item
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(@Nonnull Item itemIn, @Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
public void getSubItems(@Nonnull Item itemIn, @Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
{
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values())
{
@@ -276,6 +277,7 @@ public class UniversalBucket extends Item
return bucket;
}
@Nullable
public FluidStack getFluid(@Nonnull ItemStack container)
{
return FluidStack.loadFluidStackFromNBT(container.getTagCompound());
@@ -96,7 +96,7 @@ public class FluidBucketWrapper implements IFluidHandlerItem, ICapabilityProvide
}
}
protected void setFluid(Fluid fluid) {
protected void setFluid(@Nullable Fluid fluid) {
if (fluid == null)
{
container = new ItemStack(Items.BUCKET);