Cleanup some null checks and remove deprecated methods in Item and Block (#3429)

This commit is contained in:
mezz authored and LexManos committed 2016-11-22 15:20:05 -08:00
1 parent 2823447b6e
commit 2bd8b95a3b
31 files changed
+175 -174

No files matched your search

@@ -23,6 +23,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import javax.vecmath.Quat4f;
@@ -253,7 +255,8 @@ public final class ModelDynBucket implements IModel, IModelCustomData, IRetextur
}
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
FluidStack fluidStack = FluidUtil.getFluidContained(stack);
@@ -26,6 +26,8 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.vecmath.Matrix4f;
import net.minecraft.block.state.IBlockState;
@@ -72,7 +74,8 @@ public final class MultiModel implements IModel
private final ItemOverrideList overrides = new ItemOverrideList(Lists.<ItemOverride>newArrayList())
{
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
if(originalModel != Baked.this)
{
@@ -39,6 +39,9 @@ import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import com.google.common.base.Function;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class AnimationItemOverrideList extends ItemOverrideList
{
private final IModel model;
@@ -60,14 +63,15 @@ public final class AnimationItemOverrideList extends ItemOverrideList
this.bakedTextureGetter = bakedTextureGetter;
}
@Nonnull
@Override
public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity)
{
if(stack.hasCapability(net.minecraftforge.common.model.animation.CapabilityAnimation.ANIMATION_CAPABILITY, null))
{
// TODO: caching?
IAnimationStateMachine asm = stack.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if(world == null)
if(world == null && entity != null)
{
world = entity.worldObj;
}
@@ -156,7 +156,7 @@ public class ForgeHooks
private static boolean toolInit = false;
//static HashSet<List> toolEffectiveness = new HashSet<List>();
public static boolean canHarvestBlock(Block block, EntityPlayer player, IBlockAccess world, BlockPos pos)
public static boolean canHarvestBlock(@Nonnull Block block, @Nonnull EntityPlayer player, @Nonnull IBlockAccess world, @Nonnull BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos);
@@ -165,7 +165,7 @@ public class ForgeHooks
return true;
}
ItemStack stack = player.inventory.getCurrentItem();
ItemStack stack = player.getHeldItemMainhand();
String tool = block.getHarvestTool(state);
if (stack.func_190926_b() || tool == null)
{
@@ -190,7 +190,7 @@ public class ForgeHooks
return stack.getItem().getHarvestLevel(stack, tool, null, null) >= state.getBlock().getHarvestLevel(state);
}
public static float blockStrength(IBlockState state, EntityPlayer player, World world, BlockPos pos)
public static float blockStrength(@Nonnull IBlockState state, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos)
{
float hardness = state.getBlockHardness(world, pos);
if (hardness < 0.0F)
@@ -45,25 +45,7 @@ public class ForgeInternalHandler
if (entity.getClass().equals(EntityItem.class))
{
ItemStack stack = ((EntityItem)entity).getEntityItem();
if (stack == null)
{
//entity.setDead();
//event.setCanceled(true);
return;
}
Item item = stack.getItem();
if (item == null)
{
FMLLog.warning("Attempted to add a EntityItem to the world with a invalid item at " +
"(%2.2f, %2.2f, %2.2f), this is most likely a config issue between you and the server. Please double check your configs",
entity.posX, entity.posY, entity.posZ);
entity.setDead();
event.setCanceled(true);
return;
}
if (item.hasCustomEntity(stack))
{
Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
@@ -31,6 +31,7 @@ import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
@@ -49,6 +50,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import javax.annotation.Nonnull;
/**
* This is a base implementation for Fluid blocks.
*
@@ -161,17 +164,20 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
@Nonnull
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState(this, new IProperty[] { LEVEL }, FLUID_RENDER_PROPS.toArray(new IUnlistedProperty<?>[0]));
}
@Override
public int getMetaFromState(IBlockState state)
public int getMetaFromState(@Nonnull IBlockState state)
{
return state.getValue(LEVEL);
}
@Override
@Deprecated
@Nonnull
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(LEVEL, meta);
@@ -313,19 +319,19 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
public abstract int getQuantaValue(IBlockAccess world, BlockPos pos);
@Override
public abstract boolean canCollideCheck(IBlockState state, boolean fullHit);
public abstract boolean canCollideCheck(@Nonnull IBlockState state, boolean fullHit);
public abstract int getMaxRenderHeightMeta();
/* BLOCK FUNCTIONS */
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state)
public void onBlockAdded(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state)
{
world.scheduleUpdate(pos, this, tickRate);
}
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighborBlock, BlockPos neighbourPos)
public void neighborChanged(@Nonnull IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Block neighborBlock, @Nonnull BlockPos neighbourPos)
{
world.scheduleUpdate(pos, this, tickRate);
}
@@ -338,31 +344,33 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public boolean isPassable(IBlockAccess world, BlockPos pos)
public boolean isPassable(@Nonnull IBlockAccess world, @Nonnull BlockPos pos)
{
return true;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune)
@Nonnull
public Item getItemDropped(@Nonnull IBlockState state, @Nonnull Random rand, int fortune)
{
return null;
return Items.field_190931_a;
}
@Override
public int quantityDropped(Random par1Random)
public int quantityDropped(@Nonnull Random par1Random)
{
return 0;
}
@Override
public int tickRate(World world)
public int tickRate(@Nonnull World world)
{
return tickRate;
}
@Override
public Vec3d modifyAcceleration(World world, BlockPos pos, Entity entity, Vec3d vec)
@Nonnull
public Vec3d modifyAcceleration(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull Entity entity, @Nonnull Vec3d vec)
{
if (densityDir > 0) return vec;
Vec3d vec_flow = this.getFlowVector(world, pos);
@@ -373,7 +381,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
public int getLightValue(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos)
{
if (maxScaledLight == 0)
{
@@ -384,13 +392,13 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public boolean isOpaqueCube(IBlockState state)
public boolean isOpaqueCube(@Nonnull IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
public boolean isFullCube(@Nonnull IBlockState state)
{
return false;
}
@@ -406,7 +414,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
*/
@Override
public int getPackedLightmapCoords(IBlockState state, IBlockAccess world, BlockPos pos)
public int getPackedLightmapCoords(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos)
{
int lightThis = world.getCombinedLight(pos, 0);
int lightUp = world.getCombinedLight(pos.up(), 0);
@@ -420,13 +428,14 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
@Override
@SideOnly(Side.CLIENT)
@Nonnull
public BlockRenderLayer getBlockLayer()
{
return this.renderLayer;
}
@Override
public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side)
public boolean shouldSideBeRendered(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side)
{
IBlockState neighbor = world.getBlockState(pos.offset(side));
if (neighbor.getMaterial() == state.getMaterial())
@@ -445,7 +454,8 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public IBlockState getExtendedState(IBlockState oldState, IBlockAccess worldIn, BlockPos pos)
@Nonnull
public IBlockState getExtendedState(@Nonnull IBlockState oldState, @Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos)
{
IExtendedBlockState state = (IExtendedBlockState)oldState;
state = state.withProperty(FLOW_DIRECTION, (float)getFlowDirection(worldIn, pos));
@@ -675,7 +685,7 @@ public abstract class BlockFluidBase extends Block implements IFluidBlock
}
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
public AxisAlignedBB getCollisionBoundingBox(@Nonnull IBlockState blockState, @Nonnull IBlockAccess worldIn, @Nonnull BlockPos pos)
{
return NULL_AABB;
}
@@ -29,6 +29,8 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.ForgeEventFactory;
import javax.annotation.Nonnull;
/**
* This is a fluid block implementation which emulates vanilla Minecraft fluid behavior.
*
@@ -78,7 +80,7 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
public boolean canCollideCheck(IBlockState state, boolean fullHit)
public boolean canCollideCheck(@Nonnull IBlockState state, boolean fullHit)
{
return fullHit && state.getValue(LEVEL) == 0;
}
@@ -90,7 +92,7 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
public int getLightValue(@Nonnull IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos)
{
if (maxScaledLight == 0)
{
@@ -101,7 +103,7 @@ public class BlockFluidClassic extends BlockFluidBase
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
public void updateTick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Random rand)
{
if (!isSourceBlock(world, pos) && ForgeEventFactory.canCreateFluidSource(world, pos, state, false))
{
@@ -30,6 +30,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
/**
* This is a cellular-automata based finite fluid block implementation.
*
@@ -60,7 +62,7 @@ public class BlockFluidFinite extends BlockFluidBase
}
@Override
public boolean canCollideCheck(IBlockState state, boolean fullHit)
public boolean canCollideCheck(@Nonnull IBlockState state, boolean fullHit)
{
return fullHit && state.getValue(LEVEL) == quantaPerBlock - 1;
}
@@ -72,7 +74,7 @@ public class BlockFluidFinite extends BlockFluidBase
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand)
public void updateTick(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Random rand)
{
boolean changed = false;
int quantaRemaining = state.getValue(LEVEL) + 1;
@@ -103,7 +103,7 @@ public class UniversalBucket extends Item
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> subItems)
public void getSubItems(@Nonnull Item itemIn, @Nonnull CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems)
{
for (Fluid fluid : FluidRegistry.getRegisteredFluids().values())
{
@@ -123,6 +123,7 @@ public class UniversalBucket extends Item
}
@Override
@Nonnull
public String getItemStackDisplayName(@Nonnull ItemStack stack)
{
FluidStack fluidStack = getFluid(stack);
@@ -146,7 +147,8 @@ public class UniversalBucket extends Item
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
@Nonnull
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand)
{
ItemStack itemstack = player.getHeldItem(hand);
FluidStack fluidStack = getFluid(itemstack);
@@ -27,6 +27,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
@@ -80,7 +81,8 @@ public abstract class CommandTreeBase extends CommandBase
}
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos)
@Nonnull
public List<String> getTabCompletionOptions(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args, @Nullable BlockPos pos)
{
if(args.length == 1)
{
@@ -109,7 +111,7 @@ public abstract class CommandTreeBase extends CommandBase
}
@Override
public boolean isUsernameIndex(String[] args, int index)
public boolean isUsernameIndex(@Nonnull String[] args, int index)
{
if(index > 0 && args.length > 1)
{
@@ -124,7 +126,7 @@ public abstract class CommandTreeBase extends CommandBase
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException
{
if(args.length < 1)
{