From 43efa3cfc444debe0457f7a93961c6d76e45a7d9 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Wed, 11 Jan 2017 23:17:08 +0000 Subject: [PATCH] Small cleanup for PlayerInteractEvent (#3563) --- .../net/minecraft/client/Minecraft.java.patch | 2 +- .../net/minecraftforge/common/ForgeHooks.java | 10 +++++++++- .../entity/player/PlayerInteractEvent.java | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/patches/minecraft/net/minecraft/client/Minecraft.java.patch b/patches/minecraft/net/minecraft/client/Minecraft.java.patch index 629e150e6..28ffa7ee0 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.java.patch +++ b/patches/minecraft/net/minecraft/client/Minecraft.java.patch @@ -190,7 +190,7 @@ } this.field_71439_g.func_184821_cY(); -+ net.minecraftforge.common.ForgeHooks.onEmptyLeftClick(this.field_71439_g, this.field_71439_g.func_184614_ca()); ++ net.minecraftforge.common.ForgeHooks.onEmptyLeftClick(this.field_71439_g); } this.field_71439_g.func_184609_a(EnumHand.MAIN_HAND); diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 5f16756fd..8526879f9 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -1062,9 +1062,17 @@ public class ForgeHooks MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickEmpty(player, hand)); } + public static void onEmptyLeftClick(EntityPlayer player) + { + MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player)); + } + + // TODO: remove + /** @deprecated use {@link ForgeHooks#onEmptyLeftClick(EntityPlayer)} */ + @Deprecated public static void onEmptyLeftClick(EntityPlayer player, @Nonnull ItemStack stack) { - MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player, stack)); + onEmptyLeftClick(player); } private static ThreadLocal> lootContext = new ThreadLocal>(); diff --git a/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java b/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java index 00b4280d4..6d280896a 100644 --- a/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/player/PlayerInteractEvent.java @@ -20,16 +20,13 @@ package net.minecraftforge.event.entity.player; import com.google.common.base.Preconditions; -import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.Cancelable; @@ -313,22 +310,31 @@ public class PlayerInteractEvent extends PlayerEvent */ public static class LeftClickEmpty extends PlayerInteractEvent { - public LeftClickEmpty(EntityPlayer player, @Nonnull ItemStack stack) + public LeftClickEmpty(EntityPlayer player) { super(player, EnumHand.MAIN_HAND, new BlockPos(player), null); } + + // TODO: remove + /** @deprecated use {@link LeftClickEmpty(EntityPlayer)} */ + @Deprecated + public LeftClickEmpty(EntityPlayer player, @Nonnull ItemStack stack) + { + this(player); + } } /** * @return The hand involved in this interaction. Will never be null. */ + @Nonnull public EnumHand getHand() { return hand; } /** - * @return The itemstack involved in this interaction, or null if the hand was empty. + * @return The itemstack involved in this interaction, {@code ItemStack.EMPTY} if the hand was empty. */ @Nonnull public ItemStack getItemStack() @@ -343,6 +349,7 @@ public class PlayerInteractEvent extends PlayerEvent * Will never be null. * @return The position involved in this interaction. */ + @Nonnull public BlockPos getPos() { return pos;