Initial annotations/nullability changes (#3392)

This commit is contained in:
Shadowfacts authored and LexManos committed 2016-11-18 13:24:03 -08:00
1 parent 1fa0c0c548
commit 9cf74914e7
37 files changed
+172 -104

No files matched your search

@@ -142,6 +142,7 @@ public class ForgeHooks
}
static final List<SeedEntry> seedList = new ArrayList<SeedEntry>();
@Nonnull
public static ItemStack getGrassSeed(Random rand, int fortune)
{
SeedEntry entry = WeightedRandom.getRandomItem(rand, seedList);
@@ -207,7 +208,7 @@ public class ForgeHooks
}
}
public static boolean isToolEffective(IBlockAccess world, BlockPos pos, ItemStack stack)
public static boolean isToolEffective(IBlockAccess world, BlockPos pos, @Nonnull ItemStack stack)
{
IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos);
@@ -792,7 +793,7 @@ public class ForgeHooks
return event.isCanceled() ? -1 : event.getExpToDrop();
}
public static EnumActionResult onPlaceItemIntoWorld(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
// handle all placement events here
int meta = itemstack.getItemDamage();
@@ -883,7 +884,7 @@ public class ForgeHooks
return ret;
}
public static boolean onAnvilChange(ContainerRepair container, ItemStack left, ItemStack right, IInventory outputSlot, String name, int baseCost)
public static boolean onAnvilChange(ContainerRepair container, @Nonnull ItemStack left, @Nonnull ItemStack right, IInventory outputSlot, String name, int baseCost)
{
AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost);
if (MinecraftForge.EVENT_BUS.post(e)) return false;
@@ -1061,7 +1062,7 @@ public class ForgeHooks
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand));
}
public static void onEmptyLeftClick(EntityPlayer player, ItemStack stack)
public static void onEmptyLeftClick(EntityPlayer player, @Nonnull ItemStack stack)
{
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player, stack));
}
@@ -25,6 +25,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import javax.annotation.Nonnull;
/**
*
* This allows for mods to create there own Shear-like items
@@ -44,7 +46,7 @@ public interface IShearable
* @param pos Block's position in world.
* @return If this is shearable, and onSheared should be called.
*/
public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos);
public boolean isShearable(@Nonnull ItemStack item, IBlockAccess world, BlockPos pos);
/**
* Performs the shear function on this object.
@@ -64,5 +66,5 @@ public interface IShearable
* @param fortune The fortune level of the shears being used
* @return A ArrayList containing all items from this shearing. Possible to be null.
*/
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune);
public List<ItemStack> onSheared(@Nonnull ItemStack item, IBlockAccess world, BlockPos pos, int fortune);
}
@@ -34,6 +34,8 @@ import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
/**
* This interface is to be implemented by ItemArmor classes. It will allow to
* modify computation of damage and health loss. Computation will be called
@@ -60,7 +62,7 @@ public interface ISpecialArmor
* @param slot The armor slot the item is in.
* @return A ArmorProperties instance holding information about how the armor effects damage.
*/
public ArmorProperties getProperties(EntityLivingBase player, ItemStack armor, DamageSource source, double damage, int slot);
public ArmorProperties getProperties(EntityLivingBase player, @Nonnull ItemStack armor, DamageSource source, double damage, int slot);
/**
* Get the displayed effective armor.
@@ -70,7 +72,7 @@ public interface ISpecialArmor
* @param slot The armor slot the item is in.
* @return The number of armor points for display, 2 per shield.
*/
public abstract int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot);
public abstract int getArmorDisplay(EntityPlayer player, @Nonnull ItemStack armor, int slot);
/**
* Applies damage to the ItemStack. The mod is responsible for reducing the
@@ -84,7 +86,7 @@ public interface ISpecialArmor
* @param damage The amount of damage being applied to the armor
* @param slot The armor slot the item is in.
*/
public abstract void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot);
public abstract void damageArmor(EntityLivingBase entity, @Nonnull ItemStack stack, DamageSource source, int damage, int slot);
public static class ArmorProperties implements Comparable<ArmorProperties>
{
@@ -41,6 +41,8 @@ import net.minecraftforge.common.ForgeHooks.SeedEntry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class MinecraftForge
{
/**
@@ -67,7 +69,7 @@ public class MinecraftForge
*
* Note: These functions may be going away soon, we're looking into loot tables....
*/
public static void addGrassSeed(ItemStack seed, int weight)
public static void addGrassSeed(@Nonnull ItemStack seed, int weight)
{
addGrassSeed(new SeedEntry(seed, weight));
}
@@ -22,23 +22,20 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe {
private final ItemStack input;
private final T ingredient;
private final ItemStack output;
protected AbstractBrewingRecipe(ItemStack input, T ingredient, ItemStack output)
protected AbstractBrewingRecipe(@Nonnull ItemStack input, @Nonnull T ingredient, @Nonnull ItemStack output)
{
this.input = input;
this.ingredient = ingredient;
this.output = output;
if (this.getInput() == null || this.getIngredient() == null || this.getOutput() == null)
{
throw new IllegalArgumentException("A brewing recipe cannot have a null parameter.");
}
if (this.getInput().getMaxStackSize() != 1)
{
throw new IllegalArgumentException("Inputs must have a max size of 1 just like water bottles. Brewing Stands override the input with the output when the brewing is done, items that stack would end up getting lost.");
@@ -46,27 +43,31 @@ public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe {
}
@Override
public boolean isInput(ItemStack stack)
public boolean isInput(@Nonnull ItemStack stack)
{
return OreDictionary.itemMatches(this.getInput(), stack, false);
}
@Override
public ItemStack getOutput(ItemStack input, ItemStack ingredient)
@Nonnull
public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
{
return isInput(input) && isIngredient(ingredient) ? getOutput().copy() : null;
return isInput(input) && isIngredient(ingredient) ? getOutput().copy() : ItemStack.field_190927_a;
}
@Nonnull
public ItemStack getInput()
{
return input;
}
@Nonnull
public T getIngredient()
{
return ingredient;
}
@Nonnull
public ItemStack getOutput()
{
return output;
@@ -23,20 +23,22 @@ import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class BrewingOreRecipe extends AbstractBrewingRecipe<List<ItemStack>> {
public BrewingOreRecipe(ItemStack input, String ingredient, ItemStack output)
public BrewingOreRecipe(@Nonnull ItemStack input, @Nonnull String ingredient, @Nonnull ItemStack output)
{
super(input, OreDictionary.getOres(ingredient), output);
}
public BrewingOreRecipe(ItemStack input, List<ItemStack> ingredient, ItemStack output)
public BrewingOreRecipe(@Nonnull ItemStack input, @Nonnull List<ItemStack> ingredient, @Nonnull ItemStack output)
{
super(input, ingredient, output);
}
@Override
public boolean isIngredient(ItemStack stack)
public boolean isIngredient(@Nonnull ItemStack stack)
{
for (ItemStack target : this.getIngredient())
{
@@ -22,15 +22,17 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class BrewingRecipe extends AbstractBrewingRecipe<ItemStack> {
public BrewingRecipe(ItemStack input, ItemStack ingredient, ItemStack output)
public BrewingRecipe(@Nonnull ItemStack input, @Nonnull ItemStack ingredient, @Nonnull ItemStack output)
{
super(input, ingredient, output);
}
@Override
public boolean isIngredient(ItemStack stack)
public boolean isIngredient(@Nonnull ItemStack stack)
{
return OreDictionary.itemMatches(this.getIngredient(), stack, false);
}
@@ -50,7 +50,7 @@ public class BrewingRecipeRegistry {
* done.
* @return true if the recipe was added.
*/
public static boolean addRecipe(ItemStack input, ItemStack ingredient, ItemStack output)
public static boolean addRecipe(@Nonnull ItemStack input, @Nonnull ItemStack ingredient, @Nonnull ItemStack output)
{
return addRecipe(new BrewingRecipe(input, ingredient, output));
}
@@ -69,7 +69,7 @@ public class BrewingRecipeRegistry {
* done.
* @return true if the recipe was added.
*/
public static boolean addRecipe(ItemStack input, String ingredient, ItemStack output)
public static boolean addRecipe(@Nonnull ItemStack input, @Nonnull String ingredient, @Nonnull ItemStack output)
{
return addRecipe(new BrewingOreRecipe(input, ingredient, output));
}
@@ -85,10 +85,10 @@ public class BrewingRecipeRegistry {
/**
* Returns the output ItemStack obtained by brewing the passed input and
* ingredient. Null if no matches are found.
* ingredient.
*/
@Nonnull
public static ItemStack getOutput(@Nonnull ItemStack input, ItemStack ingredient)
public static ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
{
if (input.func_190926_b() || input.getMaxStackSize() != 1 || input.func_190916_E() != 1) return ItemStack.field_190927_a;
if (ingredient.func_190926_b()) return ItemStack.field_190927_a;
@@ -107,7 +107,7 @@ public class BrewingRecipeRegistry {
/**
* Returns true if the passed input and ingredient have an output
*/
public static boolean hasOutput(ItemStack input, ItemStack ingredient)
public static boolean hasOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
{
return !getOutput(input, ingredient).func_190926_b();
}
@@ -21,6 +21,8 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IBrewingRecipe {
/**
@@ -28,18 +30,18 @@ public interface IBrewingRecipe {
* being the item that goes in one of the three bottom slots of the brewing
* stand (e.g: water bottle)
*/
public boolean isInput(ItemStack input);
public boolean isInput(@Nonnull ItemStack input);
/**
* Returns true if the passed ItemStack is an ingredient for this recipe.
* "Ingredient" being the item that goes in the top slot of the brewing
* stand (e.g: nether wart)
*/
public boolean isIngredient(ItemStack ingredient);
public boolean isIngredient(@Nonnull ItemStack ingredient);
/**
* Returns the output when the passed input is brewed with the passed
* ingredient. Null if invalid input or ingredient.
*/
public ItemStack getOutput(ItemStack input, ItemStack ingredient);
public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient);
}
@@ -24,6 +24,8 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionHelper;
import javax.annotation.Nonnull;
/**
* Used in BrewingRecipeRegistry to maintain the vanilla behaviour.
*
@@ -35,7 +37,7 @@ public class VanillaBrewingRecipe implements IBrewingRecipe {
* Code adapted from TileEntityBrewingStand.isItemValidForSlot(int index, ItemStack stack)
*/
@Override
public boolean isInput(ItemStack stack)
public boolean isInput(@Nonnull ItemStack stack)
{
Item item = stack.getItem();
return item == Items.POTIONITEM || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION || item == Items.GLASS_BOTTLE;
@@ -45,7 +47,7 @@ public class VanillaBrewingRecipe implements IBrewingRecipe {
* Code adapted from TileEntityBrewingStand.isItemValidForSlot(int index, ItemStack stack)
*/
@Override
public boolean isIngredient(ItemStack stack)
public boolean isIngredient(@Nonnull ItemStack stack)
{
return PotionHelper.isReagent(stack);
}
@@ -56,18 +58,18 @@ public class VanillaBrewingRecipe implements IBrewingRecipe {
* or if the new potion is a splash potion when the old one wasn't.
*/
@Override
public ItemStack getOutput(ItemStack input, ItemStack ingredient)
public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
{
if (ingredient != null && input != null && isIngredient(ingredient))
if (!input.func_190926_b() && !ingredient.func_190926_b() && isIngredient(ingredient))
{
ItemStack result = PotionHelper.doReaction(ingredient, input);
if (result != input)
{
return result;
}
return null;
return ItemStack.field_190927_a;
}
return null;
return ItemStack.field_190927_a;
}
}