Added a hoe handler for advanced farming.

This commit is contained in:
Eloraam 2011-12-02 04:32:10 +00:00
parent 9c6f5bd8ee
commit 8a4636cba3
6 changed files with 82 additions and 1 deletions

View file

@ -49,6 +49,17 @@ public class ForgeHooks {
static LinkedList<IBonemealHandler> bonemealHandlers = new LinkedList<IBonemealHandler>(); static LinkedList<IBonemealHandler> bonemealHandlers = new LinkedList<IBonemealHandler>();
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<IHoeHandler> hoeHandlers = new LinkedList<IHoeHandler>();
public static EnumStatus sleepInBedAt(EntityPlayer player, int i, int j, int k) { public static EnumStatus sleepInBedAt(EntityPlayer player, int i, int j, int k) {
for (ISleepHandler handler : sleepHandlers) { for (ISleepHandler handler : sleepHandlers) {
EnumStatus status = handler.sleepInBedAt(player, i, j, k); EnumStatus status = handler.sleepInBedAt(player, i, j, k);

View file

@ -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);
}

View file

@ -36,6 +36,13 @@ public class MinecraftForge {
ForgeHooks.bonemealHandlers.add(handler); 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. * Registers a new destroy tool handler.
*/ */

View file

@ -62,7 +62,7 @@
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{ {
return false; return false;
@@ -473,6 +497,18 @@ @@ -473,6 +507,18 @@
{ {
return 0; return 0;
} }

View file

@ -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)

View file

@ -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)