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

@@ -143,10 +143,10 @@ public class ForgeEventFactory
@Deprecated
public static PlaceEvent onPlayerBlockPlace(EntityPlayer player, BlockSnapshot blockSnapshot, EnumFacing direction)
{
return onPlayerBlockPlace(player, blockSnapshot, direction, null);
return onPlayerBlockPlace(player, blockSnapshot, direction, EnumHand.MAIN_HAND);
}
public static PlaceEvent onPlayerBlockPlace(EntityPlayer player, BlockSnapshot blockSnapshot, EnumFacing direction, @Nullable EnumHand hand)
public static PlaceEvent onPlayerBlockPlace(@Nonnull EntityPlayer player, @Nonnull BlockSnapshot blockSnapshot, @Nonnull EnumFacing direction, @Nonnull EnumHand hand)
{
IBlockState placedAgainst = blockSnapshot.getWorld().getBlockState(blockSnapshot.getPos().offset(direction.getOpposite()));
PlaceEvent event = new PlaceEvent(blockSnapshot, placedAgainst, player, hand);
@@ -223,6 +223,7 @@ public class ForgeEventFactory
return event.getDroppedExperience();
}
@Nullable
public static List<Biome.SpawnListEntry> getPotentialSpawns(WorldServer world, EnumCreatureType type, BlockPos pos, List<Biome.SpawnListEntry> oldList)
{
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, pos, oldList);
@@ -331,6 +332,7 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, dir, uuidString));
}
@Nullable
public static ITextComponent onClientChat(byte type, ITextComponent message)
{
ClientChatReceivedEvent event = new ClientChatReceivedEvent(type, message);
@@ -362,7 +364,8 @@ public class ForgeEventFactory
return 0;
}
public static ActionResult<ItemStack> onBucketUse(EntityPlayer player, World world, ItemStack stack, RayTraceResult target)
@Nullable
public static ActionResult<ItemStack> onBucketUse(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull ItemStack stack, @Nullable RayTraceResult target)
{
FillBucketEvent event = new FillBucketEvent(player, stack, world, target);
if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
@@ -543,27 +546,32 @@ public class ForgeEventFactory
return MinecraftForge.EVENT_BUS.post(new RenderBlockOverlayEvent(player, renderPartialTicks, type, block, pos));
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(TileEntity tileEntity)
{
return gatherCapabilities(new AttachCapabilitiesEvent.TileEntity(tileEntity), null);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(Entity entity)
{
return gatherCapabilities(new AttachCapabilitiesEvent.Entity(entity), null);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(Item item, ItemStack stack, ICapabilityProvider parent)
{
return gatherCapabilities(new AttachCapabilitiesEvent.Item(item, stack), parent);
}
@Nullable
public static CapabilityDispatcher gatherCapabilities(World world, ICapabilityProvider parent)
{
return gatherCapabilities(new AttachCapabilitiesEvent.World(world), parent);
}
private static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent event, ICapabilityProvider parent)
@Nullable
private static CapabilityDispatcher gatherCapabilities(AttachCapabilitiesEvent<?> event, @Nullable ICapabilityProvider parent)
{
MinecraftForge.EVENT_BUS.post(event);
return event.getCapabilities().size() > 0 || parent != null ? new CapabilityDispatcher(event.getCapabilities(), parent) : null;
@@ -42,7 +42,7 @@ public class PotionBrewEvent extends Event
@Nonnull
public ItemStack getItem(int index)
{
if (index >= stacks.size()) return ItemStack.EMPTY;
if (index < 0 || index >= stacks.size()) return ItemStack.EMPTY;
return stacks.get(index);
}
@@ -24,6 +24,8 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nonnull;
/**
* Fired when the enchantment level is set for each of the three potential enchantments in the enchanting table.
* The {@link #level} is set to the vanilla value and can be modified by this event handler.
@@ -38,11 +40,12 @@ public class EnchantmentLevelSetEvent extends Event
private final BlockPos pos;
private final int enchantRow;
private final int power;
@Nonnull
private final ItemStack itemStack;
private final int originalLevel;
private int level;
public EnchantmentLevelSetEvent(World world, BlockPos pos, int enchantRow, int power, ItemStack itemStack, int level)
public EnchantmentLevelSetEvent(World world, BlockPos pos, int enchantRow, int power, @Nonnull ItemStack itemStack, int level)
{
this.world = world;
this.pos = pos;
@@ -98,6 +101,7 @@ public class EnchantmentLevelSetEvent extends Event
*
* @return the item being enchanted
*/
@Nonnull
public ItemStack getItem()
{
return itemStack;
@@ -25,6 +25,8 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import javax.annotation.Nonnull;
/**
* {@link LivingEquipmentChangeEvent} is fired when the Equipment of a Entity changes. <br>
* This event is fired whenever changes in Equipment are detected in {@link EntityLivingBase#onUpdate()}. <br>
@@ -47,7 +49,7 @@ public class LivingEquipmentChangeEvent extends LivingEvent
private final ItemStack from;
private final ItemStack to;
public LivingEquipmentChangeEvent(EntityLivingBase entity, EntityEquipmentSlot slot, ItemStack from, ItemStack to)
public LivingEquipmentChangeEvent(EntityLivingBase entity, EntityEquipmentSlot slot, @Nonnull ItemStack from, @Nonnull ItemStack to)
{
super(entity);
this.slot = slot;
@@ -56,6 +58,8 @@ public class LivingEquipmentChangeEvent extends LivingEvent
}
public EntityEquipmentSlot getSlot() { return this.slot; }
@Nonnull
public ItemStack getFrom() { return this.from; }
@Nonnull
public ItemStack getTo() { return this.to; }
}
@@ -33,13 +33,15 @@ import javax.annotation.Nonnull;
*/
public class AnvilRepairEvent extends PlayerEvent
{
@Nonnull
private final ItemStack left; // The left side of the input
@Nonnull
private final ItemStack right; // The right side of the input
@Nonnull
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)
public AnvilRepairEvent(EntityPlayer player, @Nonnull ItemStack left, @Nonnull ItemStack right, ItemStack output)
public AnvilRepairEvent(EntityPlayer player, @Nonnull ItemStack left, @Nonnull ItemStack right, @Nonnull ItemStack output)
{
super(player);
this.output = output;
@@ -53,18 +55,21 @@ public class AnvilRepairEvent extends PlayerEvent
* @return the output slot
*/
@Deprecated
@Nonnull
public ItemStack getLeft() { return output; }
/**
* Deprecated in favour of {@link #getIngredientInput()}} - this is actually the first input slot of the anvil
* @return the first input slot
*/
@Deprecated
@Nonnull
public ItemStack getRight() { return left; }
/**
* Deprecated in favour of {@link #getItemResult()} - this is actually the second input slot of the anvil
* @return the second input slot
*/
@Deprecated
@Nonnull
public ItemStack getOutput() { return right; }
/**
@@ -27,6 +27,7 @@ import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* This event is fired when a player attempts to use a Empty bucket, it
@@ -44,11 +45,12 @@ public class FillBucketEvent extends PlayerEvent
private final ItemStack current;
private final World world;
@Nullable
private final RayTraceResult target;
private ItemStack result;
public FillBucketEvent(EntityPlayer player, @Nonnull ItemStack current, World world, RayTraceResult target)
public FillBucketEvent(EntityPlayer player, @Nonnull ItemStack current, World world, @Nullable RayTraceResult target)
{
super(player);
this.current = current;
@@ -59,6 +61,7 @@ public class FillBucketEvent extends PlayerEvent
@Nonnull
public ItemStack getEmptyBucket() { return this.current; }
public World getWorld(){ return this.world; }
@Nullable
public RayTraceResult getTarget() { return this.target; }
@Nonnull
public ItemStack getFilledBucket() { return this.result; }
@@ -47,9 +47,10 @@ public class PlayerInteractEvent extends PlayerEvent
{
private final EnumHand hand;
private final BlockPos pos;
@Nullable
private final EnumFacing face;
private PlayerInteractEvent(EntityPlayer player, EnumHand hand, BlockPos pos, EnumFacing face)
private PlayerInteractEvent(EntityPlayer player, EnumHand hand, BlockPos pos, @Nullable EnumFacing face)
{
super(Preconditions.checkNotNull(player, "Null player in PlayerInteractEvent!"));
this.hand = Preconditions.checkNotNull(hand, "Null hand in PlayerInteractEvent!");
@@ -40,6 +40,7 @@ import net.minecraftforge.fml.common.eventhandler.Event.Result;
import com.google.common.collect.ImmutableList;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class BlockEvent extends Event
@@ -171,7 +172,6 @@ public class BlockEvent extends Event
public static class PlaceEvent extends BlockEvent
{
private final EntityPlayer player;
private final ItemStack itemInHand;
private final BlockSnapshot blockSnapshot;
private final IBlockState placedBlock;
private final IBlockState placedAgainst;
@@ -180,30 +180,29 @@ public class BlockEvent extends Event
@Deprecated
public PlaceEvent(BlockSnapshot blockSnapshot, IBlockState placedAgainst, EntityPlayer player)
{
this(blockSnapshot, placedAgainst, player, null);
this(blockSnapshot, placedAgainst, player, EnumHand.MAIN_HAND);
}
public PlaceEvent(BlockSnapshot blockSnapshot, IBlockState placedAgainst, EntityPlayer player, @Nullable EnumHand hand) {
public PlaceEvent(@Nonnull BlockSnapshot blockSnapshot, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshot.getWorld(), blockSnapshot.getPos(), blockSnapshot.getCurrentBlock());
this.player = player;
this.itemInHand = player.getHeldItem(hand != null ? hand : EnumHand.MAIN_HAND);
this.blockSnapshot = blockSnapshot;
this.placedBlock = blockSnapshot.getCurrentBlock();
this.placedAgainst = placedAgainst;
this.hand = hand;
if (DEBUG)
{
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, getItemInHand(), player, hand);
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, player.getHeldItem(hand), player, hand);
}
}
public EntityPlayer getPlayer() { return player; }
@Nullable
public ItemStack getItemInHand() { return itemInHand; }
@Nonnull
@Deprecated
public ItemStack getItemInHand() { return player.getHeldItem(hand); }
public BlockSnapshot getBlockSnapshot() { return blockSnapshot; }
public IBlockState getPlacedBlock() { return placedBlock; }
public IBlockState getPlacedAgainst() { return placedAgainst; }
@Nullable
public EnumHand getHand() { return hand; }
}
@@ -222,15 +221,15 @@ public class BlockEvent extends Event
@Deprecated
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, IBlockState placedAgainst, EntityPlayer player)
{
this(blockSnapshots, placedAgainst, player, null);
this(blockSnapshots, placedAgainst, player, EnumHand.MAIN_HAND);
}
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, IBlockState placedAgainst, EntityPlayer player, @Nullable EnumHand hand) {
public MultiPlaceEvent(@Nonnull List<BlockSnapshot> blockSnapshots, @Nonnull IBlockState placedAgainst, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
super(blockSnapshots.get(0), placedAgainst, player, hand);
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
if (DEBUG)
{
System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, this.getItemInHand(), player);
System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, player.getHeldItem(hand), player);
}
}