From 8a4636cba3a66ad3ef812a6109c17ee9dd9e165f Mon Sep 17 00:00:00 2001 From: Eloraam Date: Fri, 2 Dec 2011 04:32:10 +0000 Subject: [PATCH] Added a hoe handler for advanced farming. --- .../net/minecraft/src/forge/ForgeHooks.java | 11 ++++++++++ .../net/minecraft/src/forge/IHoeHandler.java | 21 +++++++++++++++++++ .../minecraft/src/forge/MinecraftForge.java | 7 +++++++ .../net/minecraft/src/Item.java.patch | 2 +- .../net/minecraft/src/ItemHoe.java.patch | 21 +++++++++++++++++++ .../net/minecraft/src/ItemHoe.java.patch | 21 +++++++++++++++++++ 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 forge/forge_common/net/minecraft/src/forge/IHoeHandler.java create mode 100644 forge/patches/minecraft/net/minecraft/src/ItemHoe.java.patch create mode 100644 forge/patches/minecraft_server/net/minecraft/src/ItemHoe.java.patch diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index 746da75e9..2099b599c 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -49,6 +49,17 @@ public class ForgeHooks { static LinkedList bonemealHandlers = new LinkedList(); + public static boolean onUseHoe(ItemStack hoe, EntityPlayer player, + World world, int i, int j, int k) { + for(IHoeHandler handler : hoeHandlers) { + if(handler.onUseHoe(hoe,player,world,i,j,k)) + return true; + } + return false; + } + + static LinkedList hoeHandlers = new LinkedList(); + public static EnumStatus sleepInBedAt(EntityPlayer player, int i, int j, int k) { for (ISleepHandler handler : sleepHandlers) { EnumStatus status = handler.sleepInBedAt(player, i, j, k); diff --git a/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java b/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java new file mode 100644 index 000000000..78886bdba --- /dev/null +++ b/forge/forge_common/net/minecraft/src/forge/IHoeHandler.java @@ -0,0 +1,21 @@ +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ + +package net.minecraft.src.forge; + +import net.minecraft.src.World; +import net.minecraft.src.ItemStack; +import net.minecraft.src.EntityPlayer; + +public interface IHoeHandler { + /** Called when a hoe is used on a block. This is called on both sides + * in SMP. + * @return true to consume a use of the hoe and return. + */ + public boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, + int i, int j, int k); + +} + diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index 8a5449338..89c049dde 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -36,6 +36,13 @@ public class MinecraftForge { ForgeHooks.bonemealHandlers.add(handler); } + /** + * Registers a new hoe handler. + */ + public static void registerHoeHandler(IHoeHandler handler) { + ForgeHooks.hoeHandlers.add(handler); + } + /** * Registers a new destroy tool handler. */ diff --git a/forge/patches/minecraft/net/minecraft/src/Item.java.patch b/forge/patches/minecraft/net/minecraft/src/Item.java.patch index 319bb71f6..440b06e87 100644 --- a/forge/patches/minecraft/net/minecraft/src/Item.java.patch +++ b/forge/patches/minecraft/net/minecraft/src/Item.java.patch @@ -62,7 +62,7 @@ public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) { return false; -@@ -473,6 +497,18 @@ +@@ -473,6 +507,18 @@ { return 0; } diff --git a/forge/patches/minecraft/net/minecraft/src/ItemHoe.java.patch b/forge/patches/minecraft/net/minecraft/src/ItemHoe.java.patch new file mode 100644 index 000000000..a6b7b417b --- /dev/null +++ b/forge/patches/minecraft/net/minecraft/src/ItemHoe.java.patch @@ -0,0 +1,21 @@ +--- ../src_base/minecraft/net/minecraft/src/ItemHoe.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft/net/minecraft/src/ItemHoe.java 0000-00-00 00:00:00.000000000 -0000 +@@ -4,6 +4,7 @@ + + package net.minecraft.src; + ++import net.minecraft.src.forge.ForgeHooks; + + // Referenced classes of package net.minecraft.src: + // Item, EnumToolMaterial, EntityPlayer, World, +@@ -25,6 +26,10 @@ + { + return false; + } ++ if(ForgeHooks.onUseHoe(itemstack,entityplayer,world,i,j,k)) { ++ itemstack.damageItem(1, entityplayer); ++ return true; ++ } + int i1 = world.getBlockId(i, j, k); + int j1 = world.getBlockId(i, j + 1, k); + if(l != 0 && j1 == 0 && i1 == Block.grass.blockID || i1 == Block.dirt.blockID) diff --git a/forge/patches/minecraft_server/net/minecraft/src/ItemHoe.java.patch b/forge/patches/minecraft_server/net/minecraft/src/ItemHoe.java.patch new file mode 100644 index 000000000..18402927e --- /dev/null +++ b/forge/patches/minecraft_server/net/minecraft/src/ItemHoe.java.patch @@ -0,0 +1,21 @@ +--- ../src_base/minecraft_server/net/minecraft/src/ItemHoe.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src_work/minecraft_server/net/minecraft/src/ItemHoe.java 0000-00-00 00:00:00.000000000 -0000 +@@ -4,6 +4,7 @@ + + package net.minecraft.src; + ++import net.minecraft.src.forge.ForgeHooks; + + // Referenced classes of package net.minecraft.src: + // Item, EnumToolMaterial, EntityPlayer, World, +@@ -25,6 +26,10 @@ + { + return false; + } ++ if(ForgeHooks.onUseHoe(itemstack,entityplayer,world,i,j,k)) { ++ itemstack.damageItem(1, entityplayer); ++ return true; ++ } + int i1 = world.getBlockId(i, j, k); + int j1 = world.getBlockId(i, j + 1, k); + if(l != 0 && j1 == 0 && i1 == Block.grass.blockID || i1 == Block.dirt.blockID)