From d8fa9a849740758f36fd007e8fa66fbc9e2899af Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 13 Feb 2012 04:04:55 -0800 Subject: [PATCH] Added Item.onLeftClickEntity hook. Used to intercept and cancel the 'attack' action within items. --- .../net/minecraft/src/EntityPlayer.java.patch | 14 +++++++++++++- .../minecraft/net/minecraft/src/Item.java.patch | 17 ++++++++++++++++- .../net/minecraft/src/EntityPlayer.java.patch | 14 +++++++++++++- .../net/minecraft/src/Item.java.patch | 17 ++++++++++++++++- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch index e2ba65801c..0b6b7757cb 100644 --- a/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/EntityPlayer.java.patch @@ -160,7 +160,19 @@ } public double getYOffset() -@@ -947,6 +1051,11 @@ +@@ -834,6 +938,11 @@ + + public void attackTargetEntityWithCurrentItem(Entity entity) + { ++ ItemStack stack = getCurrentEquippedItem(); ++ if (stack != null && stack.getItem().onLeftClickEntity(stack, this, entity)) ++ { ++ return; ++ } + int i = inventory.getDamageVsEntity(entity); + if (isPotionActive(Potion.damageBoost)) + { +@@ -947,6 +1056,11 @@ public EnumStatus sleepInBedAt(int i, int j, int k) { diff --git a/forge/patches/minecraft/net/minecraft/src/Item.java.patch b/forge/patches/minecraft/net/minecraft/src/Item.java.patch index f8f3dc90fc..df0f167382 100644 --- a/forge/patches/minecraft/net/minecraft/src/Item.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/Item.java.patch @@ -27,7 +27,7 @@ Vec3D vec3d1 = vec3d.addVector((double)f7 * d3, (double)f8 * d3, (double)f9 * d3); MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do_do(vec3d, vec3d1, flag, !flag); return movingobjectposition; -@@ -469,6 +473,109 @@ +@@ -469,6 +473,124 @@ { return getIconFromDamage(i); } @@ -133,6 +133,21 @@ + */ + public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count) + { ++ } ++ ++ /** ++ * Called when the player Left Clicks (attacks) an entity. ++ * Processed before damage is done, if return value is true further processing is canceled ++ * and the entity is not attacked. ++ * ++ * @param stack The Item being used ++ * @param player The player that is attacking ++ * @param entity The entity being attacked ++ * @return True to cancel the rest of the interaction. ++ */ ++ public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) ++ { ++ return false; + } static diff --git a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch index 72ab7e25b6..3a35420dd5 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/EntityPlayer.java.patch @@ -170,7 +170,19 @@ } public double getYOffset() -@@ -884,6 +991,11 @@ +@@ -777,6 +884,11 @@ + + public void attackTargetEntityWithCurrentItem(Entity entity) + { ++ ItemStack stack = getCurrentEquippedItem(); ++ if (stack != null && stack.getItem().onLeftClickEntity(stack, this, entity)) ++ { ++ return; ++ } + int i = inventory.getDamageVsEntity(entity); + if (isPotionActive(Potion.damageBoost)) + { +@@ -884,6 +996,11 @@ public EnumStatus sleepInBedAt(int i, int j, int k) { diff --git a/forge/patches/minecraft_server/net/minecraft/src/Item.java.patch b/forge/patches/minecraft_server/net/minecraft/src/Item.java.patch index e517f254eb..08c4d062da 100644 --- a/forge/patches/minecraft_server/net/minecraft/src/Item.java.patch +++ b/forge/patches/minecraft_server/net/minecraft/src/Item.java.patch @@ -18,7 +18,7 @@ protected Item(int i) { maxStackSize = 64; -@@ -389,10 +393,117 @@ +@@ -389,10 +393,132 @@ float f8 = f6; float f9 = f3 * f5; double d3 = 5D; @@ -132,6 +132,21 @@ + */ + public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count) + { ++ } ++ ++ /** ++ * Called when the player Left Clicks (attacks) an entity. ++ * Processed before damage is done, if return value is true further processing is canceled ++ * and the entity is not attacked. ++ * ++ * @param stack The Item being used ++ * @param player The player that is attacking ++ * @param entity The entity being attacked ++ * @return True to cancel the rest of the interaction. ++ */ ++ public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) ++ { ++ return false; + } public int getItemEnchantability()