diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index f5b0d3b456..13c73eaf74 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -370,6 +370,34 @@ public class ForgeHooks { public static Hashtable networkMods = new Hashtable(); public static Hashtable guiHandlers = new Hashtable(); + public static boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime) + { + for (IArrowLooseHandler handler : arrowLooseHandlers) + { + if (handler.onArrowLoose(itemstack, world, player, heldTime)) + { + return true; + } + } + return false; + } + + public static ArrayList arrowLooseHandlers = new ArrayList(); + + public static ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player) + { + for (IArrowNockHandler handler : arrowNockHandlers) + { + ItemStack ret = handler.onArrowNock(itemstack, world, player); + if (ret != null) + { + return ret; + } + } + return null; + } + public static ArrayList arrowNockHandlers = new ArrayList(); + public static final int majorVersion=0; public static final int minorVersion=0; public static final int revisionVersion=0; diff --git a/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java b/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java new file mode 100644 index 0000000000..1f77f46287 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/IArrowLooseHandler.java @@ -0,0 +1,24 @@ +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ +package net.minecraft.src.forge; + +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; + +public interface IArrowLooseHandler +{ + /** + * This is called before a bow tries to shoot an arrow. If it + * returns a true result, then the normal arrow will not be shot. + * + * @param itemstack The ItemStack for the bow doing the firing + * @param world The current world + * @param player The player that is firing the bow + * @param heldTime The amount of ticks the bow was held ready. + * @return True if the event should be canceled. + */ + public boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime); +} diff --git a/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java b/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java new file mode 100644 index 0000000000..d1858aecc3 --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/IArrowNockHandler.java @@ -0,0 +1,26 @@ +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ +package net.minecraft.src.forge; + +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; +import net.minecraft.src.EntityPlayer; + +public interface IArrowNockHandler +{ + + /** + * This is called before a player tries to load an arrow. If it returns + * a non-null result, then the normal arrow will not be loaded and the + * bow will be changed to the returned value. + * + * @param itemstack The ItemStack for the bow doing the firing + * @param world The current world + * @param player The player that is using the bow + * @return The new bow item, or null to continue normally. + */ + public ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player); + +} \ No newline at end of file diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index e669f3c71d..1ac86308ec 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -928,6 +928,24 @@ public class MinecraftForge { { return ForgeHooks.guiHandlers.get(mod); } + + /** + * Registers a new Arrow Nock event handler + * @param handler The Handler to be registered + */ + public static void registerArrowNockHandler(IArrowNockHandler handler) + { + ForgeHooks.arrowNockHandlers.add(handler); + } + + /** + * Registers a new Arrow Loose event handler + * @param handler The Handler to be registered + */ + public static void registerArrowLooseHandler(IArrowLooseHandler handler) + { + ForgeHooks.arrowLooseHandlers.add(handler); + } static diff --git a/forge/patches/minecraft/net/minecraft/src/ItemBow.java.patch b/forge/patches/minecraft/net/minecraft/src/ItemBow.java.patch new file mode 100644 index 0000000000..47712eb79b --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/ItemBow.java.patch @@ -0,0 +1,35 @@ +--- ../src_base/minecraft/net/minecraft/src/ItemBow.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft/net/minecraft/src/ItemBow.java 0000-00-00 00:00:00.000000000 -0000 +@@ -2,6 +2,8 @@ + + import java.util.Random; + ++import net.minecraft.src.forge.ForgeHooks; ++ + public class ItemBow extends Item + { + public ItemBow(int i) +@@ -13,6 +15,11 @@ + + public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityplayer, int i) + { ++ boolean handled = ForgeHooks.onArrowLoose(itemstack, world, entityplayer, getMaxItemUseDuration(itemstack) - i); ++ if (handled) ++ { ++ return; ++ } + boolean flag = entityplayer.capabilities.depleteBuckets || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, itemstack) > 0; + if (flag || entityplayer.inventory.hasItem(Item.arrow.shiftedIndex)) + { +@@ -80,6 +87,11 @@ + + public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) + { ++ ItemStack stack = ForgeHooks.onArrowNock(itemstack, world, entityplayer); ++ if (stack != null) ++ { ++ return stack; ++ } + if (entityplayer.capabilities.depleteBuckets || entityplayer.inventory.hasItem(Item.arrow.shiftedIndex)) + { + entityplayer.setItemInUse(itemstack, getMaxItemUseDuration(itemstack)); diff --git a/forge/patches/minecraft_server/net/minecraft/src/ItemBow.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ItemBow.java.patch new file mode 100644 index 0000000000..b191bdf427 --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ItemBow.java.patch @@ -0,0 +1,35 @@ +--- ../src_base/minecraft_server/net/minecraft/src/ItemBow.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/ItemBow.java 0000-00-00 00:00:00.000000000 -0000 +@@ -2,6 +2,8 @@ + + import java.util.Random; + ++import net.minecraft.src.forge.ForgeHooks; ++ + public class ItemBow extends Item + { + public ItemBow(int i) +@@ -13,6 +15,11 @@ + + public void onPlayerStoppedUsing(ItemStack itemstack, World world, EntityPlayer entityplayer, int i) + { ++ boolean handled = ForgeHooks.onArrowLoose(itemstack, world, entityplayer, getMaxItemUseDuration(itemstack) - i); ++ if (handled) ++ { ++ return; ++ } + boolean flag = entityplayer.capabilities.depleteBuckets || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, itemstack) > 0; + if (flag || entityplayer.inventory.hasItem(Item.arrow.shiftedIndex)) + { +@@ -80,6 +87,11 @@ + + public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) + { ++ ItemStack stack = ForgeHooks.onArrowNock(itemstack, world, entityplayer); ++ if (stack != null) ++ { ++ return stack; ++ } + if (entityplayer.capabilities.depleteBuckets || entityplayer.inventory.hasItem(Item.arrow.shiftedIndex)) + { + entityplayer.setItemInUse(itemstack, getMaxItemUseDuration(itemstack));