diff --git a/src/api/java/cofh/api/item/IToolHammer.java b/src/api/java/cofh/api/item/IToolHammer.java new file mode 100644 index 000000000..1ffefe729 --- /dev/null +++ b/src/api/java/cofh/api/item/IToolHammer.java @@ -0,0 +1,44 @@ +package cofh.api.item; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on subclasses of Item to have that item work as a tool for CoFH mods. + */ +public interface IToolHammer { + + /** + * Called to ensure that the wrench can be used. + * + * @param item + * The itemstack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools) + * @param user + * The entity using the tool + * @param x + * X location of the block/tile + * @param y + * Y location of the block/tile + * @param z + * Z location of the block/tile + * @return True if this tool can be used + */ + boolean isUsable(ItemStack item, EntityLivingBase user, int x, int y, int z); + + /** + * Callback for when the tool has been used reactively. + * + * @param item + * The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools) + * @param user + * The entity using the tool + * @param x + * X location of the block/tile + * @param y + * Y location of the block/tile + * @param z + * Z location of the block/tile + */ + void toolUsed(ItemStack item, EntityLivingBase user, int x, int y, int z); + +} diff --git a/src/main/java/mekanism/common/item/ItemConfigurator.java b/src/main/java/mekanism/common/item/ItemConfigurator.java index ab80ca976..326d91020 100644 --- a/src/main/java/mekanism/common/item/ItemConfigurator.java +++ b/src/main/java/mekanism/common/item/ItemConfigurator.java @@ -16,8 +16,8 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.tile.TileEntityBasicBlock; import mekanism.common.tile.TileEntityElectricChest; import mekanism.common.util.MekanismUtils; - import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -27,13 +27,13 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.tools.IToolWrench; +import cofh.api.item.IToolHammer; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Method; -import buildcraft.api.tools.IToolWrench; - @Interface(iface = "buildcraft.api.tools.IToolWrench", modid = "BuildCraftAPI|tools") -public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench +public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench, IToolHammer { public final int ENERGY_PER_CONFIGURE = 400; public final int ENERGY_PER_ITEM_DUMP = 8; @@ -275,4 +275,13 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool { return getState(player.getCurrentEquippedItem()) == 3; } + + @Override + public boolean isUsable(ItemStack item, EntityLivingBase user, int x, int y, int z) + { + return user instanceof EntityPlayer && canUseWrench((EntityPlayer)user, x, y, z); + } + + @Override + public void toolUsed(ItemStack item, EntityLivingBase user, int x, int y, int z) {} }