Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit support for BuildCraft, CoFH wrenches #396

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ dependencies {
compileOnly('com.github.GTNewHorizons:OpenComputers:1.9.17-GTNH:api') {transitive = false}
compileOnly('com.github.GTNewHorizons:waila:1.6.0:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Railcraft:9.15.0:api') {transitive = false}

compileOnly('net.industrial-craft:industrialcraft-2:2.2.828-experimental:api')
compileOnly('curse.maven:minefactory-reloaded-66672:2366150')
compileOnly('pneumaticCraft:PneumaticCraft-1.7.10:1.12.7-152:api') {transitive = false}
compileOnly('curse.maven:better-storage-232919:2731636')
compileOnly('api:immibis:1')

// Uncomment to add thermal expansion + foundation for testing
// runtimeOnlyNonPublishable('curse.maven:thermal-foundation-222880:2388753')
// runtimeOnlyNonPublishable('curse.maven:thermal-expansion-69163:2388759')

testImplementation('junit:junit:4.12')
functionalTestImplementation(platform('org.junit:junit-bom:5.9.2'))
functionalTestImplementation('org.junit.jupiter:junit-jupiter')
Expand Down
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
1 change: 1 addition & 0 deletions src/main/java/appeng/integration/IntegrationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum IntegrationType {
RF(IntegrationSide.BOTH, "RedstoneFlux Power - Tiles", "CoFHAPI"),

RFItem(IntegrationSide.BOTH, "RedstoneFlux Power - Items", "CoFHAPI"),
CoFHWrench(IntegrationSide.BOTH, "CoFHWrench", "CoFHAPI"),

MFR(IntegrationSide.BOTH, "Mine Factory Reloaded", "MineFactoryReloaded"),

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/appeng/integration/modules/CoFHWrench.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package appeng.integration.modules;

import appeng.helpers.Reflected;
import appeng.integration.IIntegrationModule;
import appeng.integration.IntegrationHelper;

public class CoFHWrench implements IIntegrationModule {

@Reflected
public static CoFHWrench instance;

public CoFHWrench() {
IntegrationHelper.testClassExistence(this, cofh.api.item.IToolHammer.class);
}

@Override
public void init() {}

@Override
public void postInit() {}
}
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
9 changes: 4 additions & 5 deletions src/main/java/appeng/transformer/asm/ASMIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ public final class ASMIntegration implements IClassTransformer {

@Reflected
public ASMIntegration() {

/**
* Side, Display Name, ModID ClassPostFix
*/
for (final IntegrationType type : IntegrationType.values()) {
IntegrationRegistry.INSTANCE.add(type);
}

// These are kept so we don't have to search through git for stuff like this
/*
* Side, Display Name, ModID ClassPostFix
*/
// integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE );
// integrationModules.add( IntegrationSide.BOTH, "Mystcraft", "Mystcraft", IntegrationType.Mystcraft );
// integrationModules.add( IntegrationSide.BOTH, "Greg Tech", "gregtech_addon", IntegrationType.GT );
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