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..5cedeadf7 --- /dev/null +++ b/src/api/java/cofh/api/item/IToolHammer.java @@ -0,0 +1,51 @@ +package cofh.api.item; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; + +/** + * 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 tool can be used on a block. + * + * @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 pos Coordinates of the block. + * @return True if this tool can be used. + */ + boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos); + + /** + * Called to ensure that the tool can be used on an entity. + * + * @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 entity The entity the tool is being used on. + * @return True if this tool can be used. + */ + boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity); + + /** + * 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 pos Coordinates of the block. + */ + void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos); + + /** + * 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 entity The entity the tool is being used on. + */ + void toolUsed(ItemStack item, EntityLivingBase user, Entity entity); + +} \ No newline at end of file diff --git a/src/main/java/mekanism/common/item/ItemConfigurator.java b/src/main/java/mekanism/common/item/ItemConfigurator.java index 1cecfe3b3..e3b70de89 100644 --- a/src/main/java/mekanism/common/item/ItemConfigurator.java +++ b/src/main/java/mekanism/common/item/ItemConfigurator.java @@ -1,5 +1,6 @@ package mekanism.common.item; +import cofh.api.item.IToolHammer; import io.netty.buffer.ByteBuf; import java.util.ArrayList; @@ -30,6 +31,8 @@ import mekanism.common.util.MekanismUtils; import mekanism.common.util.SecurityUtils; import net.minecraft.block.Block; import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -53,9 +56,10 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @InterfaceList({ - @Interface(iface = "buildcraft.api.tools.IToolWrench", modid = MekanismHooks.BUILDCRAFT_MOD_ID) + @Interface(iface = "buildcraft.api.tools.IToolWrench", modid = MekanismHooks.BUILDCRAFT_MOD_ID), + @Interface(iface = "cofh.api.item.IToolHammer", modid = MekanismHooks.COFH_API_MOD_ID) }) -public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench, IItemNetwork +public class ItemConfigurator extends ItemEnergized implements IMekWrench, IToolWrench, IItemNetwork, IToolHammer { public final int ENERGY_PER_CONFIGURE = 400; public final int ENERGY_PER_ITEM_DUMP = 8; @@ -282,7 +286,25 @@ public class ItemConfigurator extends ItemEnergized implements IMekWrench, ITool { return getState(stack) == ConfiguratorMode.WRENCH; } - + + /*cofh IToolHammer */ + @Override + public boolean isUsable(ItemStack stack, EntityLivingBase user, BlockPos pos) { + return getState(stack) == ConfiguratorMode.WRENCH; + } + + @Override + public boolean isUsable(ItemStack stack, EntityLivingBase user, Entity entity) { + return getState(stack) == ConfiguratorMode.WRENCH; + } + + @Override + public void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos) {} + + @Override + public void toolUsed(ItemStack item, EntityLivingBase user, Entity entity) {} + /*end cofh IToolHammer */ + public enum ConfiguratorMode { CONFIGURATE_ITEMS("configurate", "(" + TransmissionType.ITEM.localize() + ")", EnumColor.BRIGHT_GREEN, true),