[1.11] Fix nullability issues around ForgeHooks and Capabilities (#3395)

This commit is contained in:
mezz 2016-11-17 10:44:31 -08:00 committed by LexManos
parent bf090cb4c2
commit 150566d9a3
26 changed files with 165 additions and 108 deletions

View file

@ -1222,7 +1222,7 @@
+ * Queries the class of tool required to harvest this block, if null is returned + * Queries the class of tool required to harvest this block, if null is returned
+ * we assume that anything can harvest this block. + * we assume that anything can harvest this block.
+ */ + */
+ public String getHarvestTool(IBlockState state) + @Nullable public String getHarvestTool(IBlockState state)
+ { + {
+ return harvestTool[func_176201_c(state)]; + return harvestTool[func_176201_c(state)];
+ } + }

View file

@ -126,7 +126,7 @@
} }
public boolean func_174816_a(Explosion p_174816_1_, World p_174816_2_, BlockPos p_174816_3_, IBlockState p_174816_4_, float p_174816_5_) public boolean func_174816_a(Explosion p_174816_1_, World p_174816_2_, BlockPos p_174816_3_, IBlockState p_174816_4_, float p_174816_5_)
@@ -2802,6 +2822,164 @@ @@ -2802,6 +2822,167 @@
EnchantmentHelper.func_151385_b(p_174815_1_, p_174815_2_); EnchantmentHelper.func_151385_b(p_174815_1_, p_174815_2_);
} }
@ -158,7 +158,7 @@
+ * Called when a user uses the creative pick block button on this entity. + * Called when a user uses the creative pick block button on this entity.
+ * + *
+ * @param target The full target the player is looking at + * @param target The full target the player is looking at
+ * @return A ItemStack to add to the player's inventory, Null if nothing should be added. + * @return A ItemStack to add to the player's inventory, empty ItemStack if nothing should be added.
+ */ + */
+ public ItemStack getPickedResult(RayTraceResult target) + public ItemStack getPickedResult(RayTraceResult target)
+ { + {
@ -173,7 +173,7 @@
+ else if (this instanceof net.minecraft.entity.item.EntityItemFrame) + else if (this instanceof net.minecraft.entity.item.EntityItemFrame)
+ { + {
+ ItemStack held = ((net.minecraft.entity.item.EntityItemFrame)this).func_82335_i(); + ItemStack held = ((net.minecraft.entity.item.EntityItemFrame)this).func_82335_i();
+ if (held == null) + if (held.func_190926_b())
+ { + {
+ return new ItemStack(net.minecraft.init.Items.field_151160_bD); + return new ItemStack(net.minecraft.init.Items.field_151160_bD);
+ } + }
@ -201,14 +201,14 @@
+ else + else
+ { + {
+ ResourceLocation name = EntityList.func_191301_a(this); + ResourceLocation name = EntityList.func_191301_a(this);
+ if (EntityList.field_75627_a.containsKey(name)) + if (name != null && EntityList.field_75627_a.containsKey(name))
+ { + {
+ ItemStack stack = new ItemStack(net.minecraft.init.Items.field_151063_bx); + ItemStack stack = new ItemStack(net.minecraft.init.Items.field_151063_bx);
+ net.minecraft.item.ItemMonsterPlacer.func_185078_a(stack, name); + net.minecraft.item.ItemMonsterPlacer.func_185078_a(stack, name);
+ return stack; + return stack;
+ } + }
+ } + }
+ return null; + return ItemStack.field_190927_a;
+ } + }
+ +
+ public UUID getPersistentID() + public UUID getPersistentID()
@ -263,14 +263,17 @@
+ return this instanceof EntityLivingBase; + return this instanceof EntityLivingBase;
+ } + }
+ +
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (getCapability(capability, facing) != null) + if (getCapability(capability, facing) != null)
+ return true; + return true;
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing); + return capabilities == null ? false : capabilities.hasCapability(capability, facing);
+ } + }
+ +
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capabilities == null ? null : capabilities.getCapability(capability, facing); + return capabilities == null ? null : capabilities.getCapability(capability, facing);
+ } + }

View file

@ -294,7 +294,7 @@
} }
this.func_184602_cy(); this.func_184602_cy();
@@ -2761,4 +2833,28 @@ @@ -2761,4 +2833,29 @@
{ {
return true; return true;
} }
@ -306,7 +306,8 @@
+ +
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ { + {
@ -318,7 +319,7 @@
+ } + }
+ +
+ @Override + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); + return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ } + }

View file

@ -8,7 +8,7 @@
if (!this.field_70170_p.field_72995_K) if (!this.field_70170_p.field_72995_K)
{ {
p_184230_1_.func_71007_a(this); p_184230_1_.func_71007_a(this);
@@ -274,6 +275,25 @@ @@ -274,6 +275,26 @@
} }
} }
@ -16,7 +16,8 @@
+ +
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ { + {
@ -26,7 +27,7 @@
+ } + }
+ +
+ @Override + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); + return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ } + }

View file

@ -8,7 +8,7 @@
} }
public void func_110235_q(int p_110235_1_) public void func_110235_q(int p_110235_1_)
@@ -401,4 +402,21 @@ @@ -401,4 +402,22 @@
this.field_190885_a = p_i47337_1_; this.field_190885_a = p_i47337_1_;
} }
} }
@ -18,14 +18,15 @@
+ +
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) itemHandler; + if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) itemHandler;
+ return super.getCapability(capability, facing); + return super.getCapability(capability, facing);
+ } + }
+ +
+ @Override + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); + return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ } + }

View file

@ -423,7 +423,7 @@
if (this.func_70608_bn()) if (this.func_70608_bn())
{ {
@@ -2362,6 +2473,161 @@ @@ -2362,6 +2473,162 @@
return this.field_71075_bZ.field_75098_d && this.func_70003_b(2, ""); return this.field_71075_bZ.field_75098_d && this.func_70003_b(2, "");
} }
@ -563,7 +563,8 @@
+ +
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ { + {
@ -575,7 +576,7 @@
+ } + }
+ +
+ @Override + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); + return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ } + }

View file

@ -203,16 +203,19 @@
} }
return multimap; return multimap;
@@ -982,6 +1007,50 @@ @@ -982,6 +1007,53 @@
} }
} }
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return this.field_190928_g || this.capabilities == null ? false : this.capabilities.hasCapability(capability, facing); + return this.field_190928_g || this.capabilities == null ? false : this.capabilities.hasCapability(capability, facing);
+ } + }
+ +
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return this.field_190928_g || this.capabilities == null ? null : this.capabilities.getCapability(capability, facing); + return this.field_190928_g || this.capabilities == null ? null : this.capabilities.getCapability(capability, facing);
+ } + }
@ -254,7 +257,7 @@
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int func_190921_D() public int func_190921_D()
{ {
@@ -1013,4 +1082,18 @@ @@ -1013,4 +1085,18 @@
{ {
this.func_190917_f(-p_190918_1_); this.func_190917_f(-p_190918_1_);
} }

View file

@ -72,7 +72,7 @@
public double func_145835_a(double p_145835_1_, double p_145835_3_, double p_145835_5_) public double func_145835_a(double p_145835_1_, double p_145835_3_, double p_145835_5_)
{ {
double d0 = (double)this.field_174879_c.func_177958_n() + 0.5D - p_145835_1_; double d0 = (double)this.field_174879_c.func_177958_n() + 0.5D - p_145835_1_;
@@ -303,6 +313,202 @@ @@ -303,6 +313,205 @@
{ {
} }
@ -250,12 +250,15 @@
+ capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this); + capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
+ } + }
+ +
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing); + return capabilities == null ? false : capabilities.hasCapability(capability, facing);
+ } + }
+ +
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capabilities == null ? null : capabilities.getCapability(capability, facing); + return capabilities == null ? null : capabilities.getCapability(capability, facing);
+ } + }

View file

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/tileentity/TileEntityLockable.java --- ../src-base/minecraft/net/minecraft/tileentity/TileEntityLockable.java
+++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityLockable.java +++ ../src-work/minecraft/net/minecraft/tileentity/TileEntityLockable.java
@@ -48,4 +48,26 @@ @@ -48,4 +48,27 @@
{ {
return (ITextComponent)(this.func_145818_k_() ? new TextComponentString(this.func_70005_c_()) : new TextComponentTranslation(this.func_70005_c_(), new Object[0])); return (ITextComponent)(this.func_145818_k_() ? new TextComponentString(this.func_70005_c_()) : new TextComponentTranslation(this.func_70005_c_(), new Object[0]));
} }
@ -14,7 +14,8 @@
+ +
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing) + @javax.annotation.Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) + if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler); + return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler);
@ -22,7 +23,7 @@
+ } + }
+ +
+ @Override + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing) + public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing)
+ { + {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); + return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ } + }

View file

@ -103,7 +103,7 @@
+ } + }
+ +
+ // Split off from original setBlockState(BlockPos, IBlockState, int) method in order to directly send client and physic updates + // Split off from original setBlockState(BlockPos, IBlockState, int) method in order to directly send client and physic updates
+ public void markAndNotifyBlock(BlockPos p_180501_1_, Chunk chunk, IBlockState iblockstate, IBlockState p_180501_2_, int p_180501_3_) + public void markAndNotifyBlock(BlockPos p_180501_1_, @Nullable Chunk chunk, IBlockState iblockstate, IBlockState p_180501_2_, int p_180501_3_)
+ { + {
+ Block block = p_180501_2_.func_177230_c(); + Block block = p_180501_2_.func_177230_c();
+ { + {
@ -802,7 +802,7 @@
{ {
BlockPos blockpos = p_175666_1_.func_177972_a(enumfacing); BlockPos blockpos = p_175666_1_.func_177972_a(enumfacing);
@@ -3621,6 +3815,112 @@ @@ -3621,6 +3815,115 @@
return i >= -128 && i <= 128 && j >= -128 && j <= 128; return i >= -128 && i <= 128 && j >= -128 && j <= 128;
} }
@ -897,11 +897,14 @@
+ capabilityData.setCapabilities(field_73011_w, capabilities); + capabilityData.setCapabilities(field_73011_w, capabilities);
+ } + }
+ } + }
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, EnumFacing facing) + @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable EnumFacing facing)
+ { + {
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing); + return capabilities == null ? false : capabilities.hasCapability(capability, facing);
+ } + }
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, EnumFacing facing) + @Override
+ @Nullable
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable EnumFacing facing)
+ { + {
+ return capabilities == null ? null : capabilities.getCapability(capability, facing); + return capabilities == null ? null : capabilities.getCapability(capability, facing);
+ } + }

View file

@ -30,7 +30,6 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.google.common.base.Throwables;
import com.google.common.collect.Queues; import com.google.common.collect.Queues;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -45,7 +44,6 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityMinecartContainer; import net.minecraft.entity.item.EntityMinecartContainer;
@ -55,7 +53,6 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.entity.projectile.EntityThrowable; import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ContainerRepair; import net.minecraft.inventory.ContainerRepair;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
@ -92,11 +89,9 @@ import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.GameType; import net.minecraft.world.GameType;
import net.minecraft.world.storage.loot.LootEntry; import net.minecraft.world.storage.loot.LootEntry;
import net.minecraft.world.storage.loot.LootTable; import net.minecraft.world.storage.loot.LootTable;
import net.minecraft.world.storage.loot.LootTableManager;
import net.minecraft.world.storage.loot.conditions.LootCondition; import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraftforge.common.util.BlockSnapshot; import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.event.AnvilUpdateEvent; import net.minecraftforge.event.AnvilUpdateEvent;
@ -121,23 +116,25 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent; import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.relauncher.ReflectionHelper; import net.minecraftforge.fml.relauncher.ReflectionHelper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ForgeHooks public class ForgeHooks
{ {
//TODO: Loot tables? //TODO: Loot tables?
static class SeedEntry extends WeightedRandom.Item static class SeedEntry extends WeightedRandom.Item
{ {
@Nonnull
public final ItemStack seed; public final ItemStack seed;
public SeedEntry(ItemStack seed, int weight) public SeedEntry(@Nonnull ItemStack seed, int weight)
{ {
super(weight); super(weight);
this.seed = seed; this.seed = seed;
} }
@Nonnull
public ItemStack getStack(Random rand, int fortune) public ItemStack getStack(Random rand, int fortune)
{ {
return seed.copy(); return seed.copy();
@ -148,7 +145,7 @@ public class ForgeHooks
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);
if (entry == null || entry.seed == null) if (entry == null || entry.seed.func_190926_b())
{ {
return ItemStack.field_190927_a; return ItemStack.field_190927_a;
} }
@ -169,7 +166,7 @@ public class ForgeHooks
ItemStack stack = player.inventory.getCurrentItem(); ItemStack stack = player.inventory.getCurrentItem();
String tool = block.getHarvestTool(state); String tool = block.getHarvestTool(state);
if (stack == null || tool == null) if (stack.func_190926_b() || tool == null)
{ {
return player.canHarvestBlock(state); return player.canHarvestBlock(state);
} }
@ -183,12 +180,12 @@ public class ForgeHooks
return toolLevel >= block.getHarvestLevel(state); return toolLevel >= block.getHarvestLevel(state);
} }
public static boolean canToolHarvestBlock(IBlockAccess world, BlockPos pos, ItemStack stack) public static boolean canToolHarvestBlock(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);
String tool = state.getBlock().getHarvestTool(state); String tool = state.getBlock().getHarvestTool(state);
if (stack == null || tool == null) return false; if (stack.func_190926_b() || tool == null) return false;
return stack.getItem().getHarvestLevel(stack, tool, null, null) >= state.getBlock().getHarvestLevel(state); return stack.getItem().getHarvestLevel(stack, tool, null, null) >= state.getBlock().getHarvestLevel(state);
} }
@ -287,6 +284,8 @@ public class ForgeHooks
{ {
seedList.add(new SeedEntry(new ItemStack(Items.WHEAT_SEEDS), 10) seedList.add(new SeedEntry(new ItemStack(Items.WHEAT_SEEDS), 10)
{ {
@Override
@Nonnull
public ItemStack getStack(Random rand, int fortune) public ItemStack getStack(Random rand, int fortune)
{ {
return new ItemStack(Items.WHEAT_SEEDS, 1 + rand.nextInt(fortune * 2 + 1)); return new ItemStack(Items.WHEAT_SEEDS, 1 + rand.nextInt(fortune * 2 + 1));
@ -455,7 +454,7 @@ public class ForgeHooks
} }
} }
*/ */
ItemStack result = null; ItemStack result;
boolean isCreative = player.capabilities.isCreativeMode; boolean isCreative = player.capabilities.isCreativeMode;
TileEntity te = null; TileEntity te = null;
@ -483,28 +482,11 @@ public class ForgeHooks
result = target.entityHit.getPickedResult(target); result = target.entityHit.getPickedResult(target);
} }
if (result == null) if (result.func_190926_b())
{ {
return false; return false;
} }
if (result.getItem() == null)
{
String s1 = "";
if (target.typeOfHit == RayTraceResult.Type.BLOCK)
{
s1 = Block.REGISTRY.getNameForObject(world.getBlockState(target.getBlockPos()).getBlock()).toString();
}
else if (target.typeOfHit == RayTraceResult.Type.ENTITY)
{
s1 = EntityList.getEntityString(target.entityHit);
}
FMLLog.warning("Picking on: [%s] %s gave null item", target.typeOfHit, s1);
return true;
}
if (te != null) if (te != null)
{ {
Minecraft.getMinecraft().storeTEInStack(result, te); Minecraft.getMinecraft().storeTEInStack(result, te);
@ -562,6 +544,7 @@ public class ForgeHooks
return MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit)); return MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, source, drops, lootingLevel, recentlyHit));
} }
@Nullable
public static float[] onLivingFall(EntityLivingBase entity, float distance, float damageMultiplier) public static float[] onLivingFall(EntityLivingBase entity, float distance, float damageMultiplier)
{ {
LivingFallEvent event = new LivingFallEvent(entity, distance, damageMultiplier); LivingFallEvent event = new LivingFallEvent(entity, distance, damageMultiplier);
@ -597,13 +580,13 @@ public class ForgeHooks
return value >= maxXZDistance ? maxXZDistance : value; return value >= maxXZDistance ? maxXZDistance : value;
} }
public static boolean isLivingOnLadder(IBlockState state, World world, BlockPos pos, EntityLivingBase entity) public static boolean isLivingOnLadder(@Nonnull IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EntityLivingBase entity)
{ {
boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator()); boolean isSpectator = (entity instanceof EntityPlayer && ((EntityPlayer)entity).isSpectator());
if (isSpectator) return false; if (isSpectator) return false;
if (!ForgeModContainer.fullBoundingBoxLadders) if (!ForgeModContainer.fullBoundingBoxLadders)
{ {
return state != null && state.getBlock().isLadder(state, world, pos, entity); return state.getBlock().isLadder(state, world, pos, entity);
} }
else else
{ {
@ -635,7 +618,7 @@ public class ForgeHooks
MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity)); MinecraftForge.EVENT_BUS.post(new LivingJumpEvent(entity));
} }
public static EntityItem onPlayerTossEvent(EntityPlayer player, ItemStack item, boolean includeName) public static EntityItem onPlayerTossEvent(@Nonnull EntityPlayer player, @Nonnull ItemStack item, boolean includeName)
{ {
player.captureDrops = true; player.captureDrops = true;
EntityItem ret = player.dropItem(item, false, includeName); EntityItem ret = player.dropItem(item, false, includeName);
@ -660,7 +643,7 @@ public class ForgeHooks
return event.getEntityItem(); return event.getEntityItem();
} }
public static float getEnchantPower(World world, BlockPos pos) public static float getEnchantPower(@Nonnull World world, @Nonnull BlockPos pos)
{ {
return world.getBlockState(pos).getBlock().getEnchantPowerBonus(world, pos); return world.getBlockState(pos).getBlock().getEnchantPowerBonus(world, pos);
} }
@ -759,7 +742,7 @@ public class ForgeHooks
{ {
// Logic from tryHarvestBlock for pre-canceling the event // Logic from tryHarvestBlock for pre-canceling the event
boolean preCancelEvent = false; boolean preCancelEvent = false;
if (gameType.isCreative() && entityPlayer.getHeldItemMainhand() != null && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword) if (gameType.isCreative() && !entityPlayer.getHeldItemMainhand().func_190926_b() && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
preCancelEvent = true; preCancelEvent = true;
if (gameType.isAdventure()) if (gameType.isAdventure())
@ -770,7 +753,7 @@ public class ForgeHooks
if (!entityPlayer.isAllowEdit()) if (!entityPlayer.isAllowEdit())
{ {
ItemStack itemstack = entityPlayer.getHeldItemMainhand(); ItemStack itemstack = entityPlayer.getHeldItemMainhand();
if (itemstack == null || !itemstack.canDestroy(world.getBlockState(pos).getBlock())) if (itemstack.func_190926_b() || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
preCancelEvent = true; preCancelEvent = true;
} }
} }
@ -885,7 +868,7 @@ public class ForgeHooks
int updateFlag = snap.getFlag(); int updateFlag = snap.getFlag();
IBlockState oldBlock = snap.getReplacedBlock(); IBlockState oldBlock = snap.getReplacedBlock();
IBlockState newBlock = world.getBlockState(snap.getPos()); IBlockState newBlock = world.getBlockState(snap.getPos());
if (newBlock != null && !(newBlock.getBlock().hasTileEntity(newBlock))) // Containers get placed automatically if (!newBlock.getBlock().hasTileEntity(newBlock)) // Containers get placed automatically
{ {
newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock); newBlock.getBlock().onBlockAdded(world, snap.getPos(), newBlock);
} }
@ -904,7 +887,7 @@ public class ForgeHooks
{ {
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;
if (e.getOutput() == null) return true; if (e.getOutput().func_190926_b()) return true;
outputSlot.setInventorySlotContents(0, e.getOutput()); outputSlot.setInventorySlotContents(0, e.getOutput());
container.maximumCost = e.getCost(); container.maximumCost = e.getCost();
@ -1007,8 +990,7 @@ public class ForgeHooks
{ {
if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false; if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false;
ItemStack stack = player.getHeldItemMainhand(); ItemStack stack = player.getHeldItemMainhand();
if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return false; return stack.func_190926_b() || !stack.getItem().onLeftClickEntity(stack, player, target);
return true;
} }
public static boolean onTravelToDimension(Entity entity, int dimension) public static boolean onTravelToDimension(Entity entity, int dimension)
@ -1147,7 +1129,7 @@ public class ForgeHooks
this.entryNames.clear(); this.entryNames.clear();
} }
public String validateEntryName(String name) public String validateEntryName(@Nullable String name)
{ {
if (!this.entryNames.contains(name)) if (!this.entryNames.contains(name))
{ {

View file

@ -19,6 +19,7 @@
package net.minecraftforge.common.capabilities; package net.minecraftforge.common.capabilities;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -86,7 +87,7 @@ public final class CapabilityDispatcher implements INBTSerializable<NBTTagCompou
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
for (ICapabilityProvider cap : caps) for (ICapabilityProvider cap : caps)
{ {
@ -99,7 +100,8 @@ public final class CapabilityDispatcher implements INBTSerializable<NBTTagCompou
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
for (ICapabilityProvider cap : caps) for (ICapabilityProvider cap : caps)
{ {

View file

@ -19,6 +19,7 @@
package net.minecraftforge.common.capabilities; package net.minecraftforge.common.capabilities;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -40,7 +41,7 @@ public interface ICapabilityProvider
* CAN BE NULL. Null is defined to represent 'internal' or 'self' * CAN BE NULL. Null is defined to represent 'internal' or 'self'
* @return True if this object supports the capability. * @return True if this object supports the capability.
*/ */
boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing); boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing);
/** /**
* Retrieves the handler for the capability requested on the specific side. * Retrieves the handler for the capability requested on the specific side.
@ -50,7 +51,8 @@ public interface ICapabilityProvider
* @param capability The capability to check * @param capability The capability to check
* @param facing The Side to check from: * @param facing The Side to check from:
* CAN BE NULL. Null is defined to represent 'internal' or 'self' * CAN BE NULL. Null is defined to represent 'internal' or 'self'
* @return True if this object supports the capability. * @return The requested capability. Returns null when {@link #hasCapability(Capability, EnumFacing)} would return false.
*/ */
<T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing); @Nullable
<T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing);
} }

View file

@ -28,6 +28,9 @@ import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.capabilities.ICapabilityProvider;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class CapabilityAnimation public class CapabilityAnimation
{ {
@CapabilityInject(IAnimationStateMachine.class) @CapabilityInject(IAnimationStateMachine.class)
@ -61,12 +64,15 @@ public class CapabilityAnimation
this.asm = asm; this.asm = asm;
} }
public boolean hasCapability(Capability<?> capability, EnumFacing facing) @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == ANIMATION_CAPABILITY; return capability == ANIMATION_CAPABILITY;
} }
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Override
@Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if(capability == ANIMATION_CAPABILITY) if(capability == ANIMATION_CAPABILITY)
{ {

View file

@ -23,6 +23,8 @@ import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
/** /**
* *
* AnvilUpdateEvent is fired when a player places items in both the left and right slots of a anvil. * AnvilUpdateEvent is fired when a player places items in both the left and right slots of a anvil.
@ -33,27 +35,34 @@ import net.minecraft.item.ItemStack;
@Cancelable @Cancelable
public class AnvilUpdateEvent extends Event public class AnvilUpdateEvent extends Event
{ {
@Nonnull
private final ItemStack left; // The left side of the input private final ItemStack left; // The left side of the input
@Nonnull
private final ItemStack right; // The right side of the input private final ItemStack right; // The right side of the input
private final String name; // The name to set the item, if the user specified one. private final String name; // The name to set the item, if the user specified one.
@Nonnull
private ItemStack output; // Set this to set the output stack private ItemStack output; // Set this to set the output stack
private int cost; // The base cost, set this to change it if output != null private int cost; // The base cost, set this to change it if output != null
private int materialCost; // The number of items from the right slot to be consumed during the repair. Leave as 0 to consume the entire stack. private int materialCost; // The number of items from the right slot to be consumed during the repair. Leave as 0 to consume the entire stack.
public AnvilUpdateEvent(ItemStack left, ItemStack right, String name, int cost) public AnvilUpdateEvent(@Nonnull ItemStack left, @Nonnull ItemStack right, String name, int cost)
{ {
this.left = left; this.left = left;
this.right = right; this.right = right;
this.output = ItemStack.field_190927_a;
this.name = name; this.name = name;
this.setCost(cost); this.setCost(cost);
this.setMaterialCost(0); this.setMaterialCost(0);
} }
@Nonnull
public ItemStack getLeft() { return left; } public ItemStack getLeft() { return left; }
@Nonnull
public ItemStack getRight() { return right; } public ItemStack getRight() { return right; }
public String getName() { return name; } public String getName() { return name; }
@Nonnull
public ItemStack getOutput() { return output; } public ItemStack getOutput() { return output; }
public void setOutput(ItemStack output) { this.output = output; } public void setOutput(@Nonnull ItemStack output) { this.output = output; }
public int getCost() { return cost; } public int getCost() { return cost; }
public void setCost(int cost) { this.cost = cost; } public void setCost(int cost) { this.cost = cost; }
public int getMaterialCost() { return materialCost; } public int getMaterialCost() { return materialCost; }

View file

@ -113,6 +113,7 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.Result; import net.minecraftforge.fml.common.eventhandler.Event.Result;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class ForgeEventFactory public class ForgeEventFactory
@ -173,7 +174,7 @@ public class ForgeEventFactory
return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getNewSpeed()); return (MinecraftForge.EVENT_BUS.post(event) ? -1 : event.getNewSpeed());
} }
public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack, EnumHand hand) public static void onPlayerDestroyItem(EntityPlayer player, @Nonnull ItemStack stack, @Nullable EnumHand hand)
{ {
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand)); MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack, hand));
} }

View file

@ -38,6 +38,9 @@ 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;
import javax.annotation.Nullable;
/** /**
* PlayerDestroyItemEvent is fired when a player destroys an item.<br> * PlayerDestroyItemEvent is fired when a player destroys an item.<br>
* This event is fired whenever a player destroys an item in * This event is fired whenever a player destroys an item in
@ -61,16 +64,20 @@ import net.minecraft.util.EnumHand;
**/ **/
public class PlayerDestroyItemEvent extends PlayerEvent public class PlayerDestroyItemEvent extends PlayerEvent
{ {
@Nonnull
private final ItemStack original; private final ItemStack original;
@Nullable
private final EnumHand hand; // May be null if this player destroys the item by any use besides holding it. private final EnumHand hand; // May be null if this player destroys the item by any use besides holding it.
public PlayerDestroyItemEvent(EntityPlayer player, ItemStack original, EnumHand hand) public PlayerDestroyItemEvent(EntityPlayer player, @Nonnull ItemStack original, @Nullable EnumHand hand)
{ {
super(player); super(player);
this.original = original; this.original = original;
this.hand = hand; this.hand = hand;
} }
@Nonnull
public ItemStack getOriginal() { return this.original; } public ItemStack getOriginal() { return this.original; }
@Nullable
public EnumHand getHand() { return this.hand; } public EnumHand getHand() { return this.hand; }
} }

View file

@ -26,6 +26,9 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TileFluidHandler extends TileEntity public class TileFluidHandler extends TileEntity
{ {
protected FluidTank tank = new FluidTank(Fluid.BUCKET_VOLUME); protected FluidTank tank = new FluidTank(Fluid.BUCKET_VOLUME);
@ -46,14 +49,15 @@ public class TileFluidHandler extends TileEntity
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing); return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
return (T) tank; return (T) tank;

View file

@ -201,14 +201,15 @@ public class FluidHandlerItemStack implements IFluidHandlerItem, ICapabilityProv
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY; return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY ? (T) this : null; return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY ? (T) this : null;
} }

View file

@ -178,14 +178,15 @@ public class FluidHandlerItemStackSimple implements IFluidHandlerItem, ICapabili
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY; return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY ? (T) this : null; return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY ? (T) this : null;
} }

View file

@ -186,13 +186,14 @@ public class FluidBucketWrapper implements IFluidHandlerItem, ICapabilityProvide
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY; return capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY) if (capability == CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY)
{ {

View file

@ -60,6 +60,9 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Mod(modid = DynBucketTest.MODID, name = "DynBucketTest", version = "0.1", dependencies = "after:" + ModelFluidDebug.MODID) @Mod(modid = DynBucketTest.MODID, name = "DynBucketTest", version = "0.1", dependencies = "after:" + ModelFluidDebug.MODID)
public class DynBucketTest public class DynBucketTest
{ {
@ -335,13 +338,14 @@ public class DynBucketTest
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing); return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{ {

View file

@ -57,6 +57,9 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Mod(modid = ModelAnimationDebug.MODID, name = "ForgeDebugModelAnimation", version = ModelAnimationDebug.VERSION) @Mod(modid = ModelAnimationDebug.MODID, name = "ForgeDebugModelAnimation", version = ModelAnimationDebug.VERSION)
public class ModelAnimationDebug public class ModelAnimationDebug
{ {
@ -241,12 +244,15 @@ public class ModelAnimationDebug
"cycle_length", cycleLength "cycle_length", cycleLength
)); ));
public boolean hasCapability(Capability<?> capability, EnumFacing facing) @Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == CapabilityAnimation.ANIMATION_CAPABILITY; return capability == CapabilityAnimation.ANIMATION_CAPABILITY;
} }
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Override
@Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY) if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{ {
@ -330,7 +336,7 @@ public class ModelAnimationDebug
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing side) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
{ {
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY) if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{ {
@ -340,7 +346,8 @@ public class ModelAnimationDebug
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing side) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
{ {
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY) if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{ {
@ -387,7 +394,7 @@ public class ModelAnimationDebug
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing side) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing side)
{ {
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY) if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{ {
@ -397,7 +404,8 @@ public class ModelAnimationDebug
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing side) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing side)
{ {
if(capability == CapabilityAnimation.ANIMATION_CAPABILITY) if(capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{ {

View file

@ -32,6 +32,9 @@ import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Mod(modid = NoBedSleepingTest.MODID, name = "ForgeDebugNoBedSleeping", version = NoBedSleepingTest.VERSION) @Mod(modid = NoBedSleepingTest.MODID, name = "ForgeDebugNoBedSleeping", version = NoBedSleepingTest.VERSION)
public class NoBedSleepingTest public class NoBedSleepingTest
{ {
@ -83,12 +86,13 @@ public class NoBedSleepingTest
{ {
IExtraSleeping inst = SLEEP_CAP.getDefaultInstance(); IExtraSleeping inst = SLEEP_CAP.getDefaultInstance();
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) { public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
return capability == SLEEP_CAP; return capability == SLEEP_CAP;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) { @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
return capability == SLEEP_CAP ? SLEEP_CAP.<T>cast(inst) : null; return capability == SLEEP_CAP ? SLEEP_CAP.<T>cast(inst) : null;
} }

View file

@ -20,6 +20,9 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Mod(modid = "forge.testcapmod", name = "Forge TestCapMod", version = "1.0") @Mod(modid = "forge.testcapmod", name = "Forge TestCapMod", version = "1.0")
public class TestCapabilityMod public class TestCapabilityMod
{ {
@ -92,12 +95,13 @@ public class TestCapabilityMod
this.te = te; this.te = te;
} }
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return TEST_CAP != null && capability == TEST_CAP; return TEST_CAP != null && capability == TEST_CAP;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
if (TEST_CAP != null && capability == TEST_CAP) return TEST_CAP.cast(this); if (TEST_CAP != null && capability == TEST_CAP) return TEST_CAP.cast(this);
return null; return null;

View file

@ -17,6 +17,9 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/** Simple mod to test world capability, by adding timer logic and check for raining time. */ /** Simple mod to test world capability, by adding timer logic and check for raining time. */
@Mod(modid=WorldCapabilityRainTimerTest.MODID, name="World Periodic Rain Check Test", version="0.0.0") @Mod(modid=WorldCapabilityRainTimerTest.MODID, name="World Periodic Rain Check Test", version="0.0.0")
public class WorldCapabilityRainTimerTest { public class WorldCapabilityRainTimerTest {
@ -139,13 +142,14 @@ public class WorldCapabilityRainTimerTest {
private IRainTimer timer = TIMER_CAP.getDefaultInstance(); private IRainTimer timer = TIMER_CAP.getDefaultInstance();
@Override @Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{ {
return capability == TIMER_CAP; return capability == TIMER_CAP;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) @Nullable
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{ {
return capability == TIMER_CAP? TIMER_CAP.<T>cast(this.timer) : null; return capability == TIMER_CAP? TIMER_CAP.<T>cast(this.timer) : null;
} }