mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Implemented a response to Methuselah96's Arrow hook request. See IArrowNockHandler and IArrowLooseHandler
This commit is contained in:
1 parent
a5e209952e
commit
08b908acea
6 files changed
+166
No files matched your search
@@ -370,6 +370,34 @@ public class ForgeHooks {
|
||||
public static Hashtable<Integer, NetworkMod> networkMods = new Hashtable<Integer, NetworkMod>();
|
||||
public static Hashtable<BaseMod, IGuiHandler> guiHandlers = new Hashtable<BaseMod, IGuiHandler>();
|
||||
|
||||
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<IArrowLooseHandler> arrowLooseHandlers = new ArrayList<IArrowLooseHandler>();
|
||||
|
||||
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<IArrowNockHandler> arrowNockHandlers = new ArrayList<IArrowNockHandler>();
|
||||
|
||||
public static final int majorVersion=0;
|
||||
public static final int minorVersion=0;
|
||||
public static final int revisionVersion=0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
@@ -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));
|
||||
Reference in new issue
Block a user