Skip to content

Commit

Permalink
Add explicit support for CoFH wrench (Thermal Expansion)
Browse files Browse the repository at this point in the history
  • Loading branch information
firenoo committed Oct 10, 2023
1 parent f3594c1 commit d862d50
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
23 changes: 21 additions & 2 deletions src/main/java/appeng/items/tools/ToolNetworkTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
22 changes: 19 additions & 3 deletions src/main/java/appeng/items/tools/quartz/ToolQuartzWrench.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}
}
8 changes: 4 additions & 4 deletions src/main/java/appeng/parts/p2p/PartP2PTunnelStatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
26 changes: 15 additions & 11 deletions src/main/java/appeng/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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...
*/
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d862d50

Please sign in to comment.