diff --git a/src/main/java/appeng/api/implementations/items/IAEWrench.java b/src/main/java/appeng/api/implementations/items/IAEWrench.java index a360d9e654f..3b8065f27fe 100644 --- a/src/main/java/appeng/api/implementations/items/IAEWrench.java +++ b/src/main/java/appeng/api/implementations/items/IAEWrench.java @@ -17,7 +17,7 @@ import net.minecraft.item.ItemStack; /** - * Implemented on AE's wrench(s) as a substitute for if BC's API is not available. + * Implemented on AE's wrench(s) */ public interface IAEWrench { diff --git a/src/main/java/appeng/items/tools/ToolNetworkTool.java b/src/main/java/appeng/items/tools/ToolNetworkTool.java index b391532a3e8..e1df102cd1c 100644 --- a/src/main/java/appeng/items/tools/ToolNetworkTool.java +++ b/src/main/java/appeng/items/tools/ToolNetworkTool.java @@ -13,6 +13,7 @@ import java.util.EnumSet; import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -43,11 +44,15 @@ import appeng.items.AEBaseItem; import appeng.items.contents.NetworkToolViewer; import appeng.transformer.annotations.Integration.Interface; +import appeng.transformer.annotations.Integration.InterfaceList; import appeng.util.Platform; import buildcraft.api.tools.IToolWrench; +import cofh.api.item.IToolHammer; -@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore) -public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench { +@InterfaceList( + value = { @Interface(iface = "cofh.api.item.IToolHammer", iname = IntegrationType.CoFHWrench), + @Interface(iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore) }) +public class ToolNetworkTool extends AEBaseItem implements IGuiItem, IAEWrench, IToolWrench, IToolHammer { public ToolNetworkTool() { super(Optional.absent()); @@ -192,6 +197,8 @@ public boolean canWrench(final ItemStack is, final EntityPlayer player, final in return true; } + /* IToolWrench (BC) */ + @Override public boolean canWrench(final EntityPlayer player, final int x, final int y, final int z) { return true; @@ -201,4 +208,16 @@ public boolean canWrench(final EntityPlayer player, final int x, final int y, fi public void wrenchUsed(final EntityPlayer player, final int x, final int y, final int z) { player.swingItem(); } + + /* IToolHammer (CoFH) */ + + @Override + public boolean isUsable(ItemStack itemStack, EntityLivingBase entityLivingBase, int x, int y, int z) { + return true; + } + + @Override + public void toolUsed(ItemStack itemStack, EntityLivingBase entity, int x, int y, int z) { + entity.swingItem(); + } } diff --git a/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java b/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java index 7eab7cb4506..af6a2902e2b 100644 --- a/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java +++ b/src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java @@ -13,6 +13,7 @@ import java.util.EnumSet; import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -28,11 +29,15 @@ import appeng.integration.IntegrationType; import appeng.items.AEBaseItem; import appeng.transformer.annotations.Integration.Interface; +import appeng.transformer.annotations.Integration.InterfaceList; import appeng.util.Platform; import buildcraft.api.tools.IToolWrench; +import cofh.api.item.IToolHammer; -@Interface(iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore) -public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench { +@InterfaceList( + value = { @Interface(iface = "cofh.api.item.IToolHammer", iname = IntegrationType.CoFHWrench), + @Interface(iface = "buildcraft.api.tools.IToolWrench", iname = IntegrationType.BuildCraftCore) }) +public class ToolQuartzWrench extends AEBaseItem implements IAEWrench, IToolWrench, IToolHammer { public ToolQuartzWrench(final AEFeature type) { super(Optional.of(type.name())); @@ -77,7 +82,6 @@ public boolean onItemUseFirst(final ItemStack is, final EntityPlayer player, fin } @Override - // public boolean shouldPassSneakingClickToBlock(World w, int x, int y, int z) public boolean doesSneakBypassUse(final World world, final int x, final int y, final int z, final EntityPlayer player) { return true; @@ -88,6 +92,7 @@ public boolean canWrench(final ItemStack is, final EntityPlayer player, final in return true; } + /* IToolWrench - BC */ @Override public boolean canWrench(final EntityPlayer player, final int x, final int y, final int z) { return true; @@ -97,4 +102,15 @@ public boolean canWrench(final EntityPlayer player, final int x, final int y, fi public void wrenchUsed(final EntityPlayer player, final int x, final int y, final int z) { player.swingItem(); } + + /* IToolHammer - CoFH */ + @Override + public boolean isUsable(ItemStack itemStack, EntityLivingBase entity, int x, int y, int z) { + return true; + } + + @Override + public void toolUsed(ItemStack itemStack, EntityLivingBase entity, int x, int y, int z) { + entity.swingItem(); + } } diff --git a/src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java b/src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java index d6eb5867328..9972ed748b2 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java +++ b/src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java @@ -15,7 +15,6 @@ import appeng.me.GridAccessException; import appeng.me.cache.P2PCache; import appeng.util.Platform; -import buildcraft.api.tools.IToolWrench; /** * Static P2P tunnels cannot be attuned to. They can only be bound to each other. @@ -67,9 +66,10 @@ public boolean onPartActivate(EntityPlayer player, Vec3 pos) { } } mc.notifyUser(player, MemoryCardMessages.INVALID_MACHINE); - } else if (!player.isSneaking() && is != null && is.getItem() instanceof IToolWrench && !Platform.isClient()) { - printConnectionInfo(player); - } + } else if (!player.isSneaking() && Platform.isServer() + && Platform.isWrench(player, is, (int) pos.xCoord, (int) pos.yCoord, (int) pos.zCoord)) { + printConnectionInfo(player); + } return false; } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 43c30ae1770..a159de830a1 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -126,6 +126,7 @@ import appeng.util.item.OreReference; import appeng.util.prioitylist.IPartitionList; import buildcraft.api.tools.IToolWrench; +import cofh.api.item.IToolHammer; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; @@ -145,8 +146,6 @@ public class Platform { public static final int DEF_OFFSET = 16; - private static final boolean isBuildCraftLoaded = Loader.isModLoaded("BuildCraft|Core"); - /* * random source, use it for item drop locations... */ @@ -844,18 +843,23 @@ public static boolean hasSpecialComparison(final ItemStack willAdd) { return false; } - public static boolean isWrench(final EntityPlayer player, final ItemStack eq, final int x, final int y, + public static boolean isWrench(final EntityPlayer player, final ItemStack stack, final int x, final int y, final int z) { - if (eq == null) { - return false; - } + if (stack != null) { + Item itemWrench = stack.getItem(); + if (itemWrench instanceof IAEWrench wrench) { + return wrench.canWrench(stack, player, x, y, z); + } - if (isBuildCraftLoaded && eq.getItem() instanceof IToolWrench wrench) { - return wrench.canWrench(player, x, y, z); - } + if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.CoFHWrench) + && itemWrench instanceof IToolHammer wrench) { + return wrench.isUsable(stack, player, x, y, z); + } - if (eq.getItem() instanceof IAEWrench wrench) { - return wrench.canWrench(eq, player, x, y, z); + if (IntegrationRegistry.INSTANCE.isEnabled(IntegrationType.BuildCraftCore) + && itemWrench instanceof IToolWrench wrench) { + return wrench.canWrench(player, x, y, z); + } } return false; }