Initial annotations/nullability changes (#3392)

This commit is contained in:
Shadowfacts 2016-11-18 16:24:03 -05:00 committed by LexManos
parent 1fa0c0c548
commit 9cf74914e7
37 changed files with 172 additions and 104 deletions

View file

@ -25,6 +25,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
/** /**
* This event is called when an item is rendered in an item frame. * This event is called when an item is rendered in an item frame.
* *
@ -44,6 +46,7 @@ public class RenderItemInFrameEvent extends Event
renderer = renderItemFrame; renderer = renderItemFrame;
} }
@Nonnull
public ItemStack getItem() public ItemStack getItem()
{ {
return item; return item;

View file

@ -5,6 +5,7 @@ import net.minecraft.util.EnumHand;
import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -23,7 +24,7 @@ public class RenderSpecificHandEvent extends Event
private final float equipProgress; private final float equipProgress;
private final ItemStack stack; private final ItemStack stack;
public RenderSpecificHandEvent(EnumHand hand, float partialTicks, float interpolatedPitch, float swingProgress, float equipProgress, ItemStack stack) public RenderSpecificHandEvent(EnumHand hand, float partialTicks, float interpolatedPitch, float swingProgress, float equipProgress, @Nonnull ItemStack stack)
{ {
this.hand = hand; this.hand = hand;
this.partialTicks = partialTicks; this.partialTicks = partialTicks;
@ -70,7 +71,7 @@ public class RenderSpecificHandEvent extends Event
/** /**
* @return The ItemStack to be rendered, or null. * @return The ItemStack to be rendered, or null.
*/ */
@Nullable @Nonnull
public ItemStack getItemStack() public ItemStack getItemStack()
{ {
return stack; return stack;

View file

@ -32,7 +32,7 @@ public abstract class RenderTooltipEvent extends Event
protected int y; protected int y;
protected FontRenderer fr; protected FontRenderer fr;
public RenderTooltipEvent(@Nullable ItemStack stack, @Nonnull List<String> lines, int x, int y, @Nonnull FontRenderer fr) public RenderTooltipEvent(@Nonnull ItemStack stack, @Nonnull List<String> lines, int x, int y, @Nonnull FontRenderer fr)
{ {
this.stack = stack; this.stack = stack;
this.lines = Collections.unmodifiableList(lines); // Leave editing to ItemTooltipEvent this.lines = Collections.unmodifiableList(lines); // Leave editing to ItemTooltipEvent
@ -44,7 +44,7 @@ public abstract class RenderTooltipEvent extends Event
/** /**
* @return The stack which the tooltip is being rendered for. As tooltips can be drawn without itemstacks, this return is {@link Nullable}. * @return The stack which the tooltip is being rendered for. As tooltips can be drawn without itemstacks, this return is {@link Nullable}.
*/ */
@Nullable @Nonnull
public ItemStack getStack() public ItemStack getStack()
{ {
return stack; return stack;

View file

@ -142,6 +142,7 @@ public class ForgeHooks
} }
static final List<SeedEntry> seedList = new ArrayList<SeedEntry>(); static final List<SeedEntry> seedList = new ArrayList<SeedEntry>();
@Nonnull
public static ItemStack getGrassSeed(Random rand, int fortune) public static ItemStack getGrassSeed(Random rand, int fortune)
{ {
SeedEntry entry = WeightedRandom.getRandomItem(rand, seedList); 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); IBlockState state = world.getBlockState(pos);
state = state.getBlock().getActualState(state, world, pos); state = state.getBlock().getActualState(state, world, pos);
@ -792,7 +793,7 @@ public class ForgeHooks
return event.isCanceled() ? -1 : event.getExpToDrop(); 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 // handle all placement events here
int meta = itemstack.getItemDamage(); int meta = itemstack.getItemDamage();
@ -883,7 +884,7 @@ public class ForgeHooks
return ret; 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); AnvilUpdateEvent e = new AnvilUpdateEvent(left, right, name, baseCost);
if (MinecraftForge.EVENT_BUS.post(e)) return false; if (MinecraftForge.EVENT_BUS.post(e)) return false;
@ -1061,7 +1062,7 @@ public class ForgeHooks
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand)); 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)); MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player, stack));
} }

View file

@ -25,6 +25,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import javax.annotation.Nonnull;
/** /**
* *
* This allows for mods to create there own Shear-like items * 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. * @param pos Block's position in world.
* @return If this is shearable, and onSheared should be called. * @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. * Performs the shear function on this object.
@ -64,5 +66,5 @@ public interface IShearable
* @param fortune The fortune level of the shears being used * @param fortune The fortune level of the shears being used
* @return A ArrayList containing all items from this shearing. Possible to be null. * @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);
} }

View file

@ -34,6 +34,8 @@ import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import javax.annotation.Nonnull;
/** /**
* This interface is to be implemented by ItemArmor classes. It will allow to * This interface is to be implemented by ItemArmor classes. It will allow to
* modify computation of damage and health loss. Computation will be called * 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. * @param slot The armor slot the item is in.
* @return A ArmorProperties instance holding information about how the armor effects damage. * @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. * Get the displayed effective armor.
@ -70,7 +72,7 @@ public interface ISpecialArmor
* @param slot The armor slot the item is in. * @param slot The armor slot the item is in.
* @return The number of armor points for display, 2 per shield. * @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 * 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 damage The amount of damage being applied to the armor
* @param slot The armor slot the item is in. * @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> public static class ArmorProperties implements Comparable<ArmorProperties>
{ {

View file

@ -41,6 +41,8 @@ import net.minecraftforge.common.ForgeHooks.SeedEntry;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class MinecraftForge public class MinecraftForge
{ {
/** /**
@ -67,7 +69,7 @@ public class MinecraftForge
* *
* Note: These functions may be going away soon, we're looking into loot tables.... * 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)); addGrassSeed(new SeedEntry(seed, weight));
} }

View file

@ -22,23 +22,20 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe { public abstract class AbstractBrewingRecipe<T> implements IBrewingRecipe {
private final ItemStack input; private final ItemStack input;
private final T ingredient; private final T ingredient;
private final ItemStack output; 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.input = input;
this.ingredient = ingredient; this.ingredient = ingredient;
this.output = output; 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) 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."); 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 @Override
public boolean isInput(ItemStack stack) public boolean isInput(@Nonnull ItemStack stack)
{ {
return OreDictionary.itemMatches(this.getInput(), stack, false); return OreDictionary.itemMatches(this.getInput(), stack, false);
} }
@Override @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() public ItemStack getInput()
{ {
return input; return input;
} }
@Nonnull
public T getIngredient() public T getIngredient()
{ {
return ingredient; return ingredient;
} }
@Nonnull
public ItemStack getOutput() public ItemStack getOutput()
{ {
return output; return output;

View file

@ -23,20 +23,22 @@ import java.util.List;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class BrewingOreRecipe extends AbstractBrewingRecipe<List<ItemStack>> { 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); 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); super(input, ingredient, output);
} }
@Override @Override
public boolean isIngredient(ItemStack stack) public boolean isIngredient(@Nonnull ItemStack stack)
{ {
for (ItemStack target : this.getIngredient()) for (ItemStack target : this.getIngredient())
{ {

View file

@ -22,15 +22,17 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class BrewingRecipe extends AbstractBrewingRecipe<ItemStack> { 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); super(input, ingredient, output);
} }
@Override @Override
public boolean isIngredient(ItemStack stack) public boolean isIngredient(@Nonnull ItemStack stack)
{ {
return OreDictionary.itemMatches(this.getIngredient(), stack, false); return OreDictionary.itemMatches(this.getIngredient(), stack, false);
} }

View file

@ -50,7 +50,7 @@ public class BrewingRecipeRegistry {
* done. * done.
* @return true if the recipe was added. * @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)); return addRecipe(new BrewingRecipe(input, ingredient, output));
} }
@ -69,7 +69,7 @@ public class BrewingRecipeRegistry {
* done. * done.
* @return true if the recipe was added. * @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)); 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 * Returns the output ItemStack obtained by brewing the passed input and
* ingredient. Null if no matches are found. * ingredient.
*/ */
@Nonnull @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 (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; 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 * 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(); return !getOutput(input, ingredient).func_190926_b();
} }

View file

@ -21,6 +21,8 @@ package net.minecraftforge.common.brewing;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IBrewingRecipe { 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 * being the item that goes in one of the three bottom slots of the brewing
* stand (e.g: water bottle) * 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. * 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 * "Ingredient" being the item that goes in the top slot of the brewing
* stand (e.g: nether wart) * 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 * Returns the output when the passed input is brewed with the passed
* ingredient. Null if invalid input or ingredient. * ingredient. Null if invalid input or ingredient.
*/ */
public ItemStack getOutput(ItemStack input, ItemStack ingredient); public ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient);
} }

View file

@ -24,6 +24,8 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionHelper; import net.minecraft.potion.PotionHelper;
import javax.annotation.Nonnull;
/** /**
* Used in BrewingRecipeRegistry to maintain the vanilla behaviour. * 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) * Code adapted from TileEntityBrewingStand.isItemValidForSlot(int index, ItemStack stack)
*/ */
@Override @Override
public boolean isInput(ItemStack stack) public boolean isInput(@Nonnull ItemStack stack)
{ {
Item item = stack.getItem(); Item item = stack.getItem();
return item == Items.POTIONITEM || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION || item == Items.GLASS_BOTTLE; 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) * Code adapted from TileEntityBrewingStand.isItemValidForSlot(int index, ItemStack stack)
*/ */
@Override @Override
public boolean isIngredient(ItemStack stack) public boolean isIngredient(@Nonnull ItemStack stack)
{ {
return PotionHelper.isReagent(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. * or if the new potion is a splash potion when the old one wasn't.
*/ */
@Override @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); ItemStack result = PotionHelper.doReaction(ingredient, input);
if (result != input) if (result != input)
{ {
return result; return result;
} }
return null; return ItemStack.field_190927_a;
} }
return null; return ItemStack.field_190927_a;
} }
} }

View file

@ -28,6 +28,8 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fml.common.eventhandler.GenericEvent; import net.minecraftforge.fml.common.eventhandler.GenericEvent;
import javax.annotation.Nonnull;
/** /**
* Fired whenever an object with Capabilities support {currently TileEntity/Item/Entity) * Fired whenever an object with Capabilities support {currently TileEntity/Item/Entity)
* is created. Allowing for the attachment of arbitrary capability providers. * is created. Allowing for the attachment of arbitrary capability providers.
@ -126,10 +128,10 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
*/ */
public static class Item extends AttachCapabilitiesEvent<net.minecraft.item.Item> public static class Item extends AttachCapabilitiesEvent<net.minecraft.item.Item>
{ {
@Deprecated
private final net.minecraft.item.ItemStack stack; private final net.minecraft.item.ItemStack stack;
@Deprecated
private final net.minecraft.item.Item item; private final net.minecraft.item.Item item;
public Item(net.minecraft.item.Item item, net.minecraft.item.ItemStack stack) public Item(net.minecraft.item.Item item, @Nonnull net.minecraft.item.ItemStack stack)
{ {
super(net.minecraft.item.Item.class, item); super(net.minecraft.item.Item.class, item);
this.item = item; this.item = item;
@ -140,6 +142,7 @@ public class AttachCapabilitiesEvent<T> extends GenericEvent<T>
{ {
return this.item; return this.item;
} }
@Nonnull
public net.minecraft.item.ItemStack getItemStack() public net.minecraft.item.ItemStack getItemStack()
{ {
return this.stack; return this.stack;

View file

@ -398,9 +398,9 @@ public class ForgeEventFactory
return event; return event;
} }
public static int onItemExpire(EntityItem entity, ItemStack item) public static int onItemExpire(EntityItem entity, @Nonnull ItemStack item)
{ {
if (item == null) return -1; if (item.func_190926_b()) return -1;
ItemExpireEvent event = new ItemExpireEvent(entity, (item.func_190926_b() ? 6000 : item.getItem().getEntityLifespan(item, entity.worldObj))); ItemExpireEvent event = new ItemExpireEvent(entity, (item.func_190926_b() ? 6000 : item.getItem().getEntityLifespan(item, entity.worldObj)));
if (!MinecraftForge.EVENT_BUS.post(event)) return -1; if (!MinecraftForge.EVENT_BUS.post(event)) return -1;
return event.getExtraLife(); return event.getExtraLife();

View file

@ -23,6 +23,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerEvent;
import javax.annotation.Nonnull;
/** /**
* This event is called when a player picks up a potion from a brewing stand. * This event is called when a player picks up a potion from a brewing stand.
*/ */
@ -30,7 +32,7 @@ public class PlayerBrewedPotionEvent extends PlayerEvent
{ {
private final ItemStack stack; private final ItemStack stack;
public PlayerBrewedPotionEvent(EntityPlayer player, ItemStack stack) public PlayerBrewedPotionEvent(EntityPlayer player, @Nonnull ItemStack stack)
{ {
super(player); super(player);
this.stack = stack; this.stack = stack;
@ -39,6 +41,7 @@ public class PlayerBrewedPotionEvent extends PlayerEvent
/** /**
* The ItemStack of the potion. * The ItemStack of the potion.
*/ */
@Nonnull
public ItemStack getStack() public ItemStack getStack()
{ {
return stack; return stack;

View file

@ -27,6 +27,8 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.HasResult; import net.minecraftforge.fml.common.eventhandler.Event.HasResult;
import javax.annotation.Nonnull;
public class PotionBrewEvent extends Event public class PotionBrewEvent extends Event
{ {
@ -37,13 +39,14 @@ public class PotionBrewEvent extends Event
this.stacks = stacks; this.stacks = stacks;
} }
@Nonnull
public ItemStack getItem(int index) public ItemStack getItem(int index)
{ {
if (index >= stacks.size()) return null; if (index >= stacks.size()) return ItemStack.field_190927_a;
return stacks.get(index); return stacks.get(index);
} }
public void setItem(int index, ItemStack stack) public void setItem(int index, @Nonnull ItemStack stack)
{ {
if (index < stacks.size()) if (index < stacks.size())
{ {

View file

@ -23,18 +23,21 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnull;
public abstract class LivingEntityUseItemEvent extends LivingEvent public abstract class LivingEntityUseItemEvent extends LivingEvent
{ {
private final ItemStack item; private final ItemStack item;
private int duration; private int duration;
private LivingEntityUseItemEvent(EntityLivingBase entity, ItemStack item, int duration) private LivingEntityUseItemEvent(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{ {
super(entity); super(entity);
this.item = item; this.item = item;
this.setDuration(duration); this.setDuration(duration);
} }
@Nonnull
public ItemStack getItem() public ItemStack getItem()
{ {
return item; return item;
@ -64,7 +67,7 @@ public abstract class LivingEntityUseItemEvent extends LivingEvent
@Cancelable @Cancelable
public static class Start extends LivingEntityUseItemEvent public static class Start extends LivingEntityUseItemEvent
{ {
public Start(EntityLivingBase entity, ItemStack item, int duration) public Start(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{ {
super(entity, item, duration); super(entity, item, duration);
} }
@ -79,7 +82,7 @@ public abstract class LivingEntityUseItemEvent extends LivingEvent
@Cancelable @Cancelable
public static class Tick extends LivingEntityUseItemEvent public static class Tick extends LivingEntityUseItemEvent
{ {
public Tick(EntityLivingBase entity, ItemStack item, int duration) public Tick(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{ {
super(entity, item, duration); super(entity, item, duration);
} }
@ -100,7 +103,7 @@ public abstract class LivingEntityUseItemEvent extends LivingEvent
@Cancelable @Cancelable
public static class Stop extends LivingEntityUseItemEvent public static class Stop extends LivingEntityUseItemEvent
{ {
public Stop(EntityLivingBase entity, ItemStack item, int duration) public Stop(EntityLivingBase entity, @Nonnull ItemStack item, int duration)
{ {
super(entity, item, duration); super(entity, item, duration);
} }
@ -119,18 +122,19 @@ public abstract class LivingEntityUseItemEvent extends LivingEvent
public static class Finish extends LivingEntityUseItemEvent public static class Finish extends LivingEntityUseItemEvent
{ {
private ItemStack result; private ItemStack result;
public Finish(EntityLivingBase entity, ItemStack item, int duration, ItemStack result) public Finish(EntityLivingBase entity, @Nonnull ItemStack item, int duration, @Nonnull ItemStack result)
{ {
super(entity, item, duration); super(entity, item, duration);
this.setResultStack(result); this.setResultStack(result);
} }
@Nonnull
public ItemStack getResultStack() public ItemStack getResultStack()
{ {
return result; return result;
} }
public void setResultStack(ItemStack result) public void setResultStack(@Nonnull ItemStack result)
{ {
this.result = result; this.result = result;
} }

View file

@ -30,6 +30,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import javax.annotation.Nonnull;
/** /**
* MinecartInteractEvent is fired when a player interacts with a minecart. <br> * MinecartInteractEvent is fired when a player interacts with a minecart. <br>
* This event is fired whenever a player interacts with a minecart in * This event is fired whenever a player interacts with a minecart in
@ -62,6 +64,7 @@ public class MinecartInteractEvent extends MinecartEvent
} }
public EntityPlayer getPlayer() { return player; } public EntityPlayer getPlayer() { return player; }
@Nonnull
public ItemStack getItem() { return player.getHeldItem(hand); } public ItemStack getItem() { return player.getHeldItem(hand); }
public EnumHand getHand() { return hand; } public EnumHand getHand() { return hand; }
} }

View file

@ -22,6 +22,8 @@ package net.minecraftforge.event.entity.player;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
/** /**
* Fired when the player removes a "repaired" item from the Anvil's Output slot. * Fired when the player removes a "repaired" item from the Anvil's Output slot.
* *
@ -37,7 +39,7 @@ public class AnvilRepairEvent extends PlayerEvent
private final ItemStack output; // Set this to set the output stack private final ItemStack output; // Set this to set the output stack
private float breakChance; // Anvil's chance to break (reduced by 1 durability) when this is complete. Default is 12% (0.12f) private float breakChance; // Anvil's chance to break (reduced by 1 durability) when this is complete. Default is 12% (0.12f)
public AnvilRepairEvent(EntityPlayer player, ItemStack left, ItemStack right, ItemStack output) public AnvilRepairEvent(EntityPlayer player, @Nonnull ItemStack left, @Nonnull ItemStack right, ItemStack output)
{ {
super(player); super(player);
this.output = output; this.output = output;
@ -69,18 +71,21 @@ public class AnvilRepairEvent extends PlayerEvent
* Get the output result from the anvil * Get the output result from the anvil
* @return the output * @return the output
*/ */
@Nonnull
public ItemStack getItemResult() { return output; } public ItemStack getItemResult() { return output; }
/** /**
* Get the first item input into the anvil * Get the first item input into the anvil
* @return the first input slot * @return the first input slot
*/ */
@Nonnull
public ItemStack getItemInput() { return left; } public ItemStack getItemInput() { return left; }
/** /**
* Get the second item input into the anvil * Get the second item input into the anvil
* @return the second input slot * @return the second input slot
*/ */
@Nonnull
public ItemStack getIngredientInput() { return right; } public ItemStack getIngredientInput() { return right; }
public float getBreakChance() { return breakChance; } public float getBreakChance() { return breakChance; }

View file

@ -27,6 +27,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull;
/** /**
* ArrowLooseEvent is fired when a player stops using a bow.<br> * ArrowLooseEvent is fired when a player stops using a bow.<br>
* This event is fired whenever a player stops using a bow in * This event is fired whenever a player stops using a bow in
@ -50,7 +52,7 @@ public class ArrowLooseEvent extends PlayerEvent
private final boolean hasAmmo; private final boolean hasAmmo;
private int charge; private int charge;
public ArrowLooseEvent(EntityPlayer player, ItemStack bow, World world, int charge, boolean hasAmmo) public ArrowLooseEvent(EntityPlayer player, @Nonnull ItemStack bow, World world, int charge, boolean hasAmmo)
{ {
super(player); super(player);
this.bow = bow; this.bow = bow;
@ -59,6 +61,7 @@ public class ArrowLooseEvent extends PlayerEvent
this.hasAmmo = hasAmmo; this.hasAmmo = hasAmmo;
} }
@Nonnull
public ItemStack getBow() { return this.bow; } public ItemStack getBow() { return this.bow; }
public World getWorld() { return this.world; } public World getWorld() { return this.world; }
public boolean hasAmmo() { return this.hasAmmo; } public boolean hasAmmo() { return this.hasAmmo; }

View file

@ -27,6 +27,8 @@ import net.minecraft.util.EnumHand;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import javax.annotation.Nonnull;
/** /**
* ArrowNockEvent is fired when a player begins using a bow.<br> * ArrowNockEvent is fired when a player begins using a bow.<br>
* This event is fired whenever a player begins using a bow in * This event is fired whenever a player begins using a bow in
@ -42,7 +44,7 @@ public class ArrowNockEvent extends PlayerEvent
private final boolean hasAmmo; private final boolean hasAmmo;
private ActionResult<ItemStack> action; private ActionResult<ItemStack> action;
public ArrowNockEvent(EntityPlayer player, ItemStack item, EnumHand hand, World world, boolean hasAmmo) public ArrowNockEvent(EntityPlayer player, @Nonnull ItemStack item, EnumHand hand, World world, boolean hasAmmo)
{ {
super(player); super(player);
this.bow = item; this.bow = item;
@ -51,6 +53,7 @@ public class ArrowNockEvent extends PlayerEvent
this.hasAmmo = hasAmmo; this.hasAmmo = hasAmmo;
} }
@Nonnull
public ItemStack getBow() { return this.bow; } public ItemStack getBow() { return this.bow; }
public World getWorld() { return this.world; } public World getWorld() { return this.world; }
public EnumHand getHand() { return this.hand; } public EnumHand getHand() { return this.hand; }

View file

@ -26,6 +26,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull;
/** /**
* This event is fired when a player attempts to use a Empty bucket, it * This event is fired when a player attempts to use a Empty bucket, it
* can be canceled to completely prevent any further processing. * can be canceled to completely prevent any further processing.
@ -46,7 +48,7 @@ public class FillBucketEvent extends PlayerEvent
private ItemStack result; private ItemStack result;
public FillBucketEvent(EntityPlayer player, ItemStack current, World world, RayTraceResult target) public FillBucketEvent(EntityPlayer player, @Nonnull ItemStack current, World world, RayTraceResult target)
{ {
super(player); super(player);
this.current = current; this.current = current;
@ -54,9 +56,11 @@ public class FillBucketEvent extends PlayerEvent
this.target = target; this.target = target;
} }
@Nonnull
public ItemStack getEmptyBucket() { return this.current; } public ItemStack getEmptyBucket() { return this.current; }
public World getWorld(){ return this.world; } public World getWorld(){ return this.world; }
public RayTraceResult getTarget() { return this.target; } public RayTraceResult getTarget() { return this.target; }
@Nonnull
public ItemStack getFilledBucket() { return this.result; } public ItemStack getFilledBucket() { return this.result; }
public void setFilledBucket(ItemStack bucket) { this.result = bucket; } public void setFilledBucket(@Nonnull ItemStack bucket) { this.result = bucket; }
} }

View file

@ -23,16 +23,19 @@ import java.util.List;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public class ItemTooltipEvent extends PlayerEvent public class ItemTooltipEvent extends PlayerEvent
{ {
private final boolean showAdvancedItemTooltips; private final boolean showAdvancedItemTooltips;
@Nonnull
private final ItemStack itemStack; private final ItemStack itemStack;
private final List<String> toolTip; private final List<String> toolTip;
/** /**
* This event is fired in {@link ItemStack#getTooltip(EntityPlayer, boolean)}, which in turn is called from it's respective GUIContainer. * This event is fired in {@link ItemStack#getTooltip(EntityPlayer, boolean)}, which in turn is called from it's respective GUIContainer.
*/ */
public ItemTooltipEvent(ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, boolean showAdvancedItemTooltips) public ItemTooltipEvent(@Nonnull ItemStack itemStack, EntityPlayer entityPlayer, List<String> toolTip, boolean showAdvancedItemTooltips)
{ {
super(entityPlayer); super(entityPlayer);
this.itemStack = itemStack; this.itemStack = itemStack;
@ -51,6 +54,7 @@ public class ItemTooltipEvent extends PlayerEvent
/** /**
* The {@link ItemStack} with the tooltip. * The {@link ItemStack} with the tooltip.
*/ */
@Nonnull
public ItemStack getItemStack() public ItemStack getItemStack()
{ {
return itemStack; return itemStack;

View file

@ -313,7 +313,7 @@ public class PlayerInteractEvent extends PlayerEvent
*/ */
public static class LeftClickEmpty extends PlayerInteractEvent public static class LeftClickEmpty extends PlayerInteractEvent
{ {
public LeftClickEmpty(EntityPlayer player, ItemStack stack) public LeftClickEmpty(EntityPlayer player, @Nonnull ItemStack stack)
{ {
super(player, EnumHand.MAIN_HAND, new BlockPos(player), null); super(player, EnumHand.MAIN_HAND, new BlockPos(player), null);
} }

View file

@ -26,6 +26,8 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
/** /**
* This event is fired when a player attempts to use a Hoe on a block, it * This event is fired when a player attempts to use a Hoe on a block, it
* can be canceled to completely prevent any further processing. * can be canceled to completely prevent any further processing.
@ -44,7 +46,7 @@ public class UseHoeEvent extends PlayerEvent
private final World world; private final World world;
private final BlockPos pos; private final BlockPos pos;
public UseHoeEvent(EntityPlayer player, ItemStack current, World world, BlockPos pos) public UseHoeEvent(EntityPlayer player, @Nonnull ItemStack current, World world, BlockPos pos)
{ {
super(player); super(player);
this.current = current; this.current = current;
@ -52,6 +54,7 @@ public class UseHoeEvent extends PlayerEvent
this.pos = pos; this.pos = pos;
} }
@Nonnull
public ItemStack getCurrent() public ItemStack getCurrent()
{ {
return current; return current;

View file

@ -95,7 +95,8 @@ public class DispenseFluidContainer extends BehaviorDefaultDispenseItem
/** /**
* Drains a filled container and places the fluid in front of the Dispenser. * Drains a filled container and places the fluid in front of the Dispenser.
*/ */
private ItemStack dumpContainer(IBlockSource source, ItemStack stack) @Nonnull
private ItemStack dumpContainer(IBlockSource source, @Nonnull ItemStack stack)
{ {
ItemStack singleStack = stack.copy(); ItemStack singleStack = stack.copy();
singleStack.func_190920_e(1); singleStack.func_190920_e(1);

View file

@ -84,13 +84,14 @@ public class UniversalBucket extends Item
} }
@Override @Override
public boolean hasContainerItem(ItemStack stack) public boolean hasContainerItem(@Nonnull ItemStack stack)
{ {
return !getEmpty().func_190926_b(); return !getEmpty().func_190926_b();
} }
@Nonnull
@Override @Override
public ItemStack getContainerItem(ItemStack itemStack) public ItemStack getContainerItem(@Nonnull ItemStack itemStack)
{ {
if (!getEmpty().func_190926_b()) if (!getEmpty().func_190926_b())
{ {
@ -122,7 +123,7 @@ public class UniversalBucket extends Item
} }
@Override @Override
public String getItemStackDisplayName(ItemStack stack) public String getItemStackDisplayName(@Nonnull ItemStack stack)
{ {
FluidStack fluidStack = getFluid(stack); FluidStack fluidStack = getFluid(stack);
if (fluidStack == null) if (fluidStack == null)
@ -272,7 +273,7 @@ public class UniversalBucket extends Item
return bucket; return bucket;
} }
public FluidStack getFluid(ItemStack container) public FluidStack getFluid(@Nonnull ItemStack container)
{ {
return FluidStack.loadFluidStackFromNBT(container.getTagCompound()); return FluidStack.loadFluidStackFromNBT(container.getTagCompound());
} }

View file

@ -25,6 +25,8 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
public class PlayerEvent extends Event { public class PlayerEvent extends Event {
public final EntityPlayer player; public final EntityPlayer player;
private PlayerEvent(EntityPlayer player) private PlayerEvent(EntityPlayer player)
@ -42,9 +44,10 @@ public class PlayerEvent extends Event {
} }
public static class ItemCraftedEvent extends PlayerEvent { public static class ItemCraftedEvent extends PlayerEvent {
@Nonnull
public final ItemStack crafting; public final ItemStack crafting;
public final IInventory craftMatrix; public final IInventory craftMatrix;
public ItemCraftedEvent(EntityPlayer player, ItemStack crafting, IInventory craftMatrix) public ItemCraftedEvent(EntityPlayer player, @Nonnull ItemStack crafting, IInventory craftMatrix)
{ {
super(player); super(player);
this.crafting = crafting; this.crafting = crafting;
@ -52,8 +55,9 @@ public class PlayerEvent extends Event {
} }
} }
public static class ItemSmeltedEvent extends PlayerEvent { public static class ItemSmeltedEvent extends PlayerEvent {
@Nonnull
public final ItemStack smelting; public final ItemStack smelting;
public ItemSmeltedEvent(EntityPlayer player, ItemStack crafting) public ItemSmeltedEvent(EntityPlayer player, @Nonnull ItemStack crafting)
{ {
super(player); super(player);
this.smelting = crafting; this.smelting = crafting;

View file

@ -67,6 +67,8 @@ import com.google.common.collect.ObjectArrays;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import javax.annotation.Nonnull;
@SuppressWarnings({"WeakerAccess", "unused"}) @SuppressWarnings({"WeakerAccess", "unused"})
public class GameRegistry public class GameRegistry
{ {
@ -220,17 +222,17 @@ public class GameRegistry
GameData.getMain().registerSubstitutionAlias(nameToSubstitute, type, object); GameData.getMain().registerSubstitutionAlias(nameToSubstitute, type, object);
} }
public static void addRecipe(ItemStack output, Object... params) public static void addRecipe(@Nonnull ItemStack output, Object... params)
{ {
addShapedRecipe(output, params); addShapedRecipe(output, params);
} }
public static IRecipe addShapedRecipe(ItemStack output, Object... params) public static IRecipe addShapedRecipe(@Nonnull ItemStack output, Object... params)
{ {
return CraftingManager.getInstance().addRecipe(output, params); return CraftingManager.getInstance().addRecipe(output, params);
} }
public static void addShapelessRecipe(ItemStack output, Object... params) public static void addShapelessRecipe(@Nonnull ItemStack output, Object... params)
{ {
CraftingManager.getInstance().addShapelessRecipe(output, params); CraftingManager.getInstance().addShapelessRecipe(output, params);
} }
@ -240,17 +242,17 @@ public class GameRegistry
CraftingManager.getInstance().getRecipeList().add(recipe); CraftingManager.getInstance().getRecipeList().add(recipe);
} }
public static void addSmelting(Block input, ItemStack output, float xp) public static void addSmelting(Block input, @Nonnull ItemStack output, float xp)
{ {
FurnaceRecipes.instance().addSmeltingRecipeForBlock(input, output, xp); FurnaceRecipes.instance().addSmeltingRecipeForBlock(input, output, xp);
} }
public static void addSmelting(Item input, ItemStack output, float xp) public static void addSmelting(Item input, @Nonnull ItemStack output, float xp)
{ {
FurnaceRecipes.instance().addSmelting(input, output, xp); FurnaceRecipes.instance().addSmelting(input, output, xp);
} }
public static void addSmelting(ItemStack input, ItemStack output, float xp) public static void addSmelting(@Nonnull ItemStack input, @Nonnull ItemStack output, float xp)
{ {
FurnaceRecipes.instance().addSmeltingRecipe(input, output, xp); FurnaceRecipes.instance().addSmeltingRecipe(input, output, xp);
} }
@ -282,7 +284,7 @@ public class GameRegistry
fuelHandlers.add(handler); fuelHandlers.add(handler);
} }
public static int getFuelValue(ItemStack itemStack) public static int getFuelValue(@Nonnull ItemStack itemStack)
{ {
int fuelValue = 0; int fuelValue = 0;
for (IFuelHandler handler : fuelHandlers) for (IFuelHandler handler : fuelHandlers)
@ -362,6 +364,7 @@ public class GameRegistry
* @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT} * @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
* @return a new itemstack * @return a new itemstack
*/ */
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString)
{ {
if (itemName == null) if (itemName == null)
@ -372,7 +375,7 @@ public class GameRegistry
if (item == null) if (item == null)
{ {
FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName); FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
return null; return ItemStack.field_190927_a;
} }
ItemStack is = new ItemStack(item, stackSize, meta); ItemStack is = new ItemStack(item, stackSize, meta);
if (!Strings.isNullOrEmpty(nbtString)) if (!Strings.isNullOrEmpty(nbtString))

View file

@ -50,9 +50,9 @@ public class ItemHandlerHelper
return stack; return stack;
} }
public static boolean canItemStacksStack(ItemStack a, ItemStack b) public static boolean canItemStacksStack(@Nonnull ItemStack a, @Nonnull ItemStack b)
{ {
if (a == null || !a.isItemEqual(b)) if (a.func_190926_b() || !a.isItemEqual(b))
return false; return false;
final NBTTagCompound aTag = a.getTagCompound(); final NBTTagCompound aTag = a.getTagCompound();
@ -64,9 +64,9 @@ public class ItemHandlerHelper
* A relaxed version of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes. * A relaxed version of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes.
* This usually only applies when players pick up items. * This usually only applies when players pick up items.
*/ */
public static boolean canItemStacksStackRelaxed(ItemStack a, ItemStack b) public static boolean canItemStacksStackRelaxed(@Nonnull ItemStack a, @Nonnull ItemStack b)
{ {
if (a == null || b == null || a.getItem() != b.getItem()) if (a.func_190926_b() || b.func_190926_b() || a.getItem() != b.getItem())
return false; return false;
if (!a.isStackable()) if (!a.isStackable())
@ -84,7 +84,7 @@ public class ItemHandlerHelper
} }
@Nonnull @Nonnull
public static ItemStack copyStackWithSize(ItemStack itemStack, int size) public static ItemStack copyStackWithSize(@Nonnull ItemStack itemStack, int size)
{ {
if (size == 0) if (size == 0)
return ItemStack.field_190927_a; return ItemStack.field_190927_a;
@ -148,7 +148,7 @@ public class ItemHandlerHelper
} }
/** giveItemToPlayer without preferred slot */ /** giveItemToPlayer without preferred slot */
public static void giveItemToPlayer(EntityPlayer player, ItemStack stack) { public static void giveItemToPlayer(EntityPlayer player, @Nonnull ItemStack stack) {
giveItemToPlayer(player, stack, -1); giveItemToPlayer(player, stack, -1);
} }
@ -159,7 +159,7 @@ public class ItemHandlerHelper
* @param player The player to give the item to * @param player The player to give the item to
* @param stack The itemstack to insert * @param stack The itemstack to insert
*/ */
public static void giveItemToPlayer(EntityPlayer player, ItemStack stack, int preferredSlot) public static void giveItemToPlayer(EntityPlayer player, @Nonnull ItemStack stack, int preferredSlot)
{ {
IItemHandler inventory = new PlayerMainInvWrapper(player.inventory); IItemHandler inventory = new PlayerMainInvWrapper(player.inventory);
World world = player.worldObj; World world = player.worldObj;
@ -172,20 +172,20 @@ public class ItemHandlerHelper
remainder = inventory.insertItem(preferredSlot, stack, false); remainder = inventory.insertItem(preferredSlot, stack, false);
} }
// then into the inventory in general // then into the inventory in general
if(remainder != null) if(!remainder.func_190926_b())
{ {
remainder = insertItemStacked(inventory, remainder, false); remainder = insertItemStacked(inventory, remainder, false);
} }
// play sound if something got picked up // play sound if something got picked up
if (remainder == null || remainder.func_190916_E() != stack.func_190916_E()) if (remainder.func_190926_b() || remainder.func_190916_E() != stack.func_190916_E())
{ {
world.playSound(player, player.posX, player.posY, player.posZ, world.playSound(player, player.posX, player.posY, player.posZ,
SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((world.rand.nextFloat() - world.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
} }
// drop remaining itemstack into the world // drop remaining itemstack into the world
if (remainder != null && !world.isRemote) if (!remainder.func_190926_b() && !world.isRemote)
{ {
EntityItem entityitem = new EntityItem(world, player.posX, player.posY + 0.5, player.posZ, stack); EntityItem entityitem = new EntityItem(world, player.posX, player.posY + 0.5, player.posZ, stack);
entityitem.setPickupDelay(40); entityitem.setPickupDelay(40);

View file

@ -154,7 +154,7 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
} }
} }
protected int getStackLimit(int slot, ItemStack stack) protected int getStackLimit(int slot, @Nonnull ItemStack stack)
{ {
return stack.getMaxStackSize(); return stack.getMaxStackSize();
} }

View file

@ -39,7 +39,7 @@ public class VanillaHopperItemHandler extends InvWrapper
@Nonnull @Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{ {
if (stack == null) if (stack.func_190926_b())
return null; return null;
// if (simulate || !hopper.mayTransfer()) // if (simulate || !hopper.mayTransfer())
// return super.insertItem(slot, stack, simulate); // return super.insertItem(slot, stack, simulate);

View file

@ -47,15 +47,15 @@ public class VanillaInventoryCodeHooks
for (int i = 0; i < handler.getSlots(); i++) for (int i = 0; i < handler.getSlots(); i++)
{ {
ItemStack extractItem = handler.extractItem(i, 1, true); ItemStack extractItem = handler.extractItem(i, 1, true);
if (extractItem != null) if (!extractItem.func_190926_b())
{ {
for (int j = 0; j < dest.getSizeInventory(); j++) for (int j = 0; j < dest.getSizeInventory(); j++)
{ {
ItemStack destStack = dest.getStackInSlot(j); ItemStack destStack = dest.getStackInSlot(j);
if (destStack == null || destStack.func_190916_E() < destStack.getMaxStackSize() && destStack.func_190916_E() < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack)) if (destStack.func_190926_b() || destStack.func_190916_E() < destStack.getMaxStackSize() && destStack.func_190916_E() < dest.getInventoryStackLimit() && ItemHandlerHelper.canItemStacksStack(extractItem, destStack))
{ {
extractItem = handler.extractItem(i, 1, false); extractItem = handler.extractItem(i, 1, false);
if (destStack == null) if (destStack.func_190926_b())
dest.setInventorySlotContents(j, extractItem); dest.setInventorySlotContents(j, extractItem);
else else
{ {
@ -120,7 +120,7 @@ public class VanillaInventoryCodeHooks
for (int i = 0; i < hopper.getSizeInventory(); i++) for (int i = 0; i < hopper.getSizeInventory(); i++)
{ {
ItemStack stackInSlot = hopper.getStackInSlot(i); ItemStack stackInSlot = hopper.getStackInSlot(i);
if (stackInSlot != null) if (stackInSlot.func_190926_b())
{ {
ItemStack insert = stackInSlot.copy(); ItemStack insert = stackInSlot.copy();
insert.func_190920_e(1); insert.func_190920_e(1);

View file

@ -72,8 +72,8 @@ public class InvWrapper implements IItemHandlerModifiable
@Nonnull @Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
{ {
if (stack == null) if (stack.func_190926_b())
return null; return ItemStack.field_190927_a;
if (!getInv().isItemValidForSlot(slot, stack)) if (!getInv().isItemValidForSlot(slot, stack))
return stack; return stack;
@ -98,7 +98,7 @@ public class InvWrapper implements IItemHandlerModifiable
getInv().markDirty(); getInv().markDirty();
} }
return null; return ItemStack.field_190927_a;
} }
else else
{ {
@ -145,7 +145,7 @@ public class InvWrapper implements IItemHandlerModifiable
getInv().setInventorySlotContents(slot, stack); getInv().setInventorySlotContents(slot, stack);
getInv().markDirty(); getInv().markDirty();
} }
return null; return ItemStack.field_190927_a;
} }
} }
@ -156,12 +156,12 @@ public class InvWrapper implements IItemHandlerModifiable
public ItemStack extractItem(int slot, int amount, boolean simulate) public ItemStack extractItem(int slot, int amount, boolean simulate)
{ {
if (amount == 0) if (amount == 0)
return null; return ItemStack.field_190927_a;
ItemStack stackInSlot = getInv().getStackInSlot(slot); ItemStack stackInSlot = getInv().getStackInSlot(slot);
if (stackInSlot == null) if (stackInSlot.func_190926_b())
return null; return ItemStack.field_190927_a;
if (simulate) if (simulate)
{ {
@ -187,7 +187,7 @@ public class InvWrapper implements IItemHandlerModifiable
} }
@Override @Override
public void setStackInSlot(int slot, ItemStack stack) public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{ {
getInv().setInventorySlotContents(slot, stack); getInv().setInventorySlotContents(slot, stack);
} }

View file

@ -58,7 +58,7 @@ public class RangedWrapper implements IItemHandlerModifiable {
return compose.getStackInSlot(slot + minSlot); return compose.getStackInSlot(slot + minSlot);
} }
return null; return ItemStack.field_190927_a;
} }
@Override @Override
@ -86,7 +86,7 @@ public class RangedWrapper implements IItemHandlerModifiable {
} }
@Override @Override
public void setStackInSlot(int slot, ItemStack stack) public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{ {
if (checkSlot(slot)) if (checkSlot(slot))
{ {

View file

@ -653,6 +653,7 @@ public class OreDictionary
return Name; return Name;
} }
@Nonnull
public ItemStack getOre() public ItemStack getOre()
{ {
return Ore; return Ore;