Skip to content

Commit

Permalink
Add Tunnel Conversion API
Browse files Browse the repository at this point in the history
Allows AE2FC Interfaces to convert P2P Tunnels, closes #73
  • Loading branch information
NotMyWing committed Jun 9, 2024
1 parent 3b7dc10 commit 30ec2b4
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 50 deletions.
6 changes: 6 additions & 0 deletions src/main/java/co/neeve/nae2/NAE2API.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package co.neeve.nae2;

import co.neeve.nae2.common.api.ExposerAPI;
import co.neeve.nae2.common.api.TunnelConversionAPI;

public class NAE2API {
private final ExposerAPI exposerAPI = new ExposerAPI();
private final TunnelConversionAPI tunnelConversionAPI = new TunnelConversionAPI();

NAE2API() {}

Expand All @@ -15,4 +17,8 @@ public class NAE2API {
public ExposerAPI exposer() {
return this.exposerAPI;
}

public TunnelConversionAPI tunnelConversion() {
return this.tunnelConversionAPI;
}
}
19 changes: 19 additions & 0 deletions src/main/java/co/neeve/nae2/common/api/TunnelConversionAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package co.neeve.nae2.common.api;

import appeng.util.item.ItemStackHashStrategy;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import net.minecraft.item.ItemStack;

public class TunnelConversionAPI {
private final Object2ObjectMap<ItemStack, ItemStack> tunnelMap =
new Object2ObjectOpenCustomHashMap<>(ItemStackHashStrategy.comparingAllButCount());

public void register(ItemStack catalyst, ItemStack tunnelStack) {
this.tunnelMap.put(catalyst, tunnelStack);
}

public ItemStack getConversion(ItemStack catalyst) {
return this.tunnelMap.getOrDefault(catalyst, ItemStack.EMPTY);
}
}
24 changes: 24 additions & 0 deletions src/main/java/co/neeve/nae2/common/integration/ae2fc/AE2FC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package co.neeve.nae2.common.integration.ae2fc;

import co.neeve.nae2.NAE2;
import co.neeve.nae2.common.registration.definitions.Upgrades;
import com.glodblock.github.loader.FCBlocks;
import com.glodblock.github.loader.FCItems;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;

public class AE2FC {

public static void initInterfaceUpgrade(Upgrades.UpgradeType upgrade) {
upgrade.registerItem(new ItemStack(FCBlocks.DUAL_INTERFACE), 1);
upgrade.registerItem(new ItemStack(FCItems.PART_DUAL_INTERFACE), 1);
}

public static void postInit(Side side) {
NAE2.definitions().parts().p2pTunnelInterface().maybeStack(1).ifPresent((p2pTunnel) -> {
var tc = NAE2.api().tunnelConversion();
tc.register(new ItemStack(FCBlocks.DUAL_INTERFACE), p2pTunnel);
tc.register(new ItemStack(FCItems.PART_DUAL_INTERFACE), p2pTunnel);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;

public class AE2FCIntegrationHelper {
public class AE2FCInterfaceHelper {
private static TileEntity interfaceOverride = null;
private static EnumFacing enumFacingOverride = null;

Expand All @@ -12,14 +12,14 @@ public static TileEntity getInterfaceOverride() {
}

public static void setInterfaceOverride(TileEntity interfaceOverride) {
AE2FCIntegrationHelper.interfaceOverride = interfaceOverride;
AE2FCInterfaceHelper.interfaceOverride = interfaceOverride;
}

public static EnumFacing getEnumFacingOverride() {
return enumFacingOverride;
}

public static void setEnumFacingOverride(EnumFacing enumFacingOverride) {
AE2FCIntegrationHelper.enumFacingOverride = enumFacingOverride;
AE2FCInterfaceHelper.enumFacingOverride = enumFacingOverride;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import appeng.bootstrap.components.*;
import appeng.core.AEConfig;
import appeng.core.features.AEFeature;
import appeng.util.Platform;
import co.neeve.nae2.common.integration.ae2fc.AE2FC;
import co.neeve.nae2.common.recipes.handlers.DisassembleRecipe;
import co.neeve.nae2.common.registration.definitions.*;
import co.neeve.nae2.common.registration.registry.Registry;
Expand Down Expand Up @@ -43,6 +45,10 @@ public Registration() {
this.parts = new Parts(this.registry);
this.upgrades = new Upgrades(this.registry);
this.blocks = new Blocks(this.registry);

if (Platform.isModLoaded("ae2fc")) {
this.registry.addBootstrapComponent((IPostInitComponent) AE2FC::postInit);
}
}

public void preInit(FMLPreInitializationEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import appeng.api.AEApi;
import appeng.api.parts.IPart;
import appeng.bootstrap.components.IPostInitComponent;
import appeng.core.Api;
import appeng.core.features.DamagedItemDefinition;
import appeng.core.localization.GuiText;
import appeng.util.Platform;
import co.neeve.nae2.NAE2;
import co.neeve.nae2.Tags;
import co.neeve.nae2.common.features.Features;
import co.neeve.nae2.common.features.IFeature;
Expand Down Expand Up @@ -54,9 +57,23 @@ public Parts(Registry registry) {

this.beamFormer = this.createPart(this.itemPart, PartType.BEAM_FORMER);
this.p2pTunnelInterface = this.createPart(this.itemPart, PartType.P2P_TUNNEL_INTERFACE);
this.p2pTunnelInterface.maybeStack(1)
.ifPresent((tunnelStack) -> registry.addBootstrapComponent((IPostInitComponent) (r) -> {
var definitions = Api.INSTANCE.definitions();

definitions.blocks().iface().maybeStack(1)
.ifPresent((stack) -> registerTunnelConversion(tunnelStack, stack));

definitions.parts().iface().maybeStack(1)
.ifPresent((stack) -> registerTunnelConversion(tunnelStack, stack));
}));
this.exposer = this.createPart(this.itemPart, PartType.EXPOSER);
}

private static void registerTunnelConversion(ItemStack tunnelStack, ItemStack stack) {
NAE2.api().tunnelConversion().register(stack, tunnelStack);
}

public static Optional<PartType> getById(int itemDamage) {
return Optional.ofNullable(PartType.getCachedValues().getOrDefault(itemDamage, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import co.neeve.nae2.common.crafting.patterntransform.transformers.GregTechCircuitPatternTransformer;
import co.neeve.nae2.common.features.IFeature;
import co.neeve.nae2.common.features.subfeatures.UpgradeFeatures;
import co.neeve.nae2.common.integration.ae2fc.UpgradeInit;
import co.neeve.nae2.common.integration.ae2fc.AE2FC;
import co.neeve.nae2.common.items.NAEBaseItemUpgrade;
import co.neeve.nae2.common.registration.registry.Registry;
import co.neeve.nae2.common.registration.registry.interfaces.DamagedDefinitions;
Expand Down Expand Up @@ -68,7 +68,7 @@ public Upgrades(Registry registry) {
UpgradeType.AUTO_COMPLETE.registerItem(blocks.iface(), 1);
UpgradeType.AUTO_COMPLETE.registerItem(parts.iface(), 1);
if (Platform.isModLoaded("ae2fc")) {
UpgradeInit.init(UpgradeType.AUTO_COMPLETE);
AE2FC.initInterfaceUpgrade(UpgradeType.AUTO_COMPLETE);
}
});
}
Expand All @@ -85,7 +85,7 @@ public Upgrades(Registry registry) {
UpgradeType.GREGTECH_CIRCUIT.registerItem(blocks.iface(), 1);
UpgradeType.GREGTECH_CIRCUIT.registerItem(parts.iface(), 1);
if (Platform.isModLoaded("ae2fc")) {
UpgradeInit.init(UpgradeType.GREGTECH_CIRCUIT);
AE2FC.initInterfaceUpgrade(UpgradeType.GREGTECH_CIRCUIT);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.neeve.nae2.mixin.ifacep2p.shared;
package co.neeve.nae2.mixin.core;

import appeng.api.config.TunnelType;
import appeng.api.implementations.items.IMemoryCard;
import appeng.core.Api;
import appeng.parts.p2p.PartP2PTunnel;
import co.neeve.nae2.NAE2;
import com.llamalad7.mixinextras.sugar.Local;
Expand All @@ -11,19 +11,30 @@
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(PartP2PTunnel.class)
public class MixinPartP2PTunnel {
public class MixinTunnelConversion {
@ModifyVariable(method = "onPartActivate", at = @At(value = "LOAD"), name = "newType", remap = false)
public ItemStack injectP2PTypes(ItemStack newType, @Local(ordinal = 0) ItemStack hand) {
var item = hand.getItem();

if (!(item instanceof IMemoryCard)) {
var definitions = Api.INSTANCE.definitions();
var conversion = NAE2.api().tunnelConversion().getConversion(hand);
if (!conversion.isEmpty()) {
return conversion;
}
}

return newType;
}

@ModifyVariable(method = "onPartActivate", at = @At(value = "LOAD"), name = "tt", remap = false)
public TunnelType maskTunnelType(TunnelType newType, @Local(ordinal = 0) ItemStack hand) {
var item = hand.getItem();

var iface = definitions.blocks().iface().maybeStack(1);
var ifacePart = definitions.parts().iface().maybeStack(1);
if ((iface.isPresent() && hand.isItemEqual(iface.get()))
|| (ifacePart.isPresent() && hand.isItemEqual(ifacePart.get()))) {
return NAE2.definitions().parts().p2pTunnelInterface().maybeStack(1).orElse(ItemStack.EMPTY);
if (!(item instanceof IMemoryCard)) {
var conversion = NAE2.api().tunnelConversion().getConversion(hand);
if (!conversion.isEmpty()) {
// Return whatever.
return TunnelType.ME;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.neeve.nae2.mixin.crafting.patterntransform;
package co.neeve.nae2.mixin.core.crafting.patterntransform;

import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.neeve.nae2.mixin.crafting.patterntransform;
package co.neeve.nae2.mixin.core.crafting.patterntransform;

import appeng.api.networking.crafting.ICraftingMedium;
import appeng.api.networking.crafting.ICraftingPatternDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package co.neeve.nae2.mixin.ifacep2p.shared;

import appeng.helpers.IInterfaceHost;
import co.neeve.nae2.common.integration.ae2fc.AE2FCIntegrationHelper;
import co.neeve.nae2.common.integration.ae2fc.AE2FCInterfaceHelper;
import com.glodblock.github.inventory.FluidConvertingInventoryAdaptor;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
Expand All @@ -21,7 +21,7 @@ public class MixinAE2FCInventoryAdaptor {
remap = true
))
private static TileEntity wrapTileEntity(World instance, BlockPos blockPos, Operation<TileEntity> original) {
var override = AE2FCIntegrationHelper.getInterfaceOverride();
var override = AE2FCInterfaceHelper.getInterfaceOverride();
if (override != null) {
return override;
}
Expand All @@ -36,9 +36,9 @@ private static TileEntity wrapTileEntity(World instance, BlockPos blockPos, Oper
))
private static IInterfaceHost wrapGetInterfaceTE(TileEntity te, EnumFacing facing,
Operation<IInterfaceHost> operation) {
var override = AE2FCIntegrationHelper.getInterfaceOverride();
var override = AE2FCInterfaceHelper.getInterfaceOverride();
if (override != null) {
return operation.call(override, AE2FCIntegrationHelper.getEnumFacingOverride());
return operation.call(override, AE2FCInterfaceHelper.getEnumFacingOverride());
}

return operation.call(te, facing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.util.Platform;
import co.neeve.nae2.common.integration.ae2fc.AE2FCIntegrationHelper;
import co.neeve.nae2.common.integration.ae2fc.AE2FCInterfaceHelper;
import co.neeve.nae2.common.parts.p2p.PartP2PInterface;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
Expand Down Expand Up @@ -80,8 +80,8 @@ private TileEntity wrapEntityGetter(World instance, BlockPos bp, Operation<TileE
interfaceHost = null;
}

AE2FCIntegrationHelper.setEnumFacingOverride(this.nae2$originalFacing.getOpposite());
AE2FCIntegrationHelper.setInterfaceOverride(
AE2FCInterfaceHelper.setEnumFacingOverride(this.nae2$originalFacing.getOpposite());
AE2FCInterfaceHelper.setInterfaceOverride(
interfaceHost != null ? interfaceHost.getTileEntity() : null);
}
return pair.getRight();
Expand Down Expand Up @@ -115,8 +115,8 @@ private TileEntity wrapEntityGetter(World instance, BlockPos bp, Operation<TileE
}

if (Platform.isModLoaded("ae2fc")) {
AE2FCIntegrationHelper.setEnumFacingOverride(null);
AE2FCIntegrationHelper.setInterfaceOverride(null);
AE2FCInterfaceHelper.setEnumFacingOverride(null);
AE2FCInterfaceHelper.setInterfaceOverride(null);
}
return te;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.util.Platform;
import co.neeve.nae2.common.integration.ae2fc.AE2FCIntegrationHelper;
import co.neeve.nae2.common.integration.ae2fc.AE2FCInterfaceHelper;
import co.neeve.nae2.common.parts.p2p.PartP2PInterface;
import com.google.common.collect.Lists;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
Expand Down Expand Up @@ -85,7 +85,7 @@ private void wrapPushOut(DualityInterface instance, EnumFacing facing,
operation.call(instance, facing);
}
}

@WrapOperation(
method = "pushPattern",
at = @At(
Expand Down Expand Up @@ -144,8 +144,8 @@ private TileEntity wrapPushGetTE(World instance, BlockPos bp, Operation<TileEnti
interfaceHost = null;
}

AE2FCIntegrationHelper.setEnumFacingOverride(originalFacing.getOpposite());
AE2FCIntegrationHelper.setInterfaceOverride(
AE2FCInterfaceHelper.setEnumFacingOverride(originalFacing.getOpposite());
AE2FCInterfaceHelper.setInterfaceOverride(
interfaceHost != null ? interfaceHost.getTileEntity() : null);
}

Expand Down Expand Up @@ -174,8 +174,8 @@ private TileEntity wrapPushGetTE(World instance, BlockPos bp, Operation<TileEnti
}

if (Platform.isModLoaded("ae2fc")) {
AE2FCIntegrationHelper.setEnumFacingOverride(null);
AE2FCIntegrationHelper.setInterfaceOverride(null);
AE2FCInterfaceHelper.setEnumFacingOverride(null);
AE2FCInterfaceHelper.setInterfaceOverride(null);
}

currentOutputTunnel.set(null);
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mixins.nae2.ifacep2p.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"mixins": [
"ifacep2p.shared.DualityAccessor",
"ifacep2p.shared.MixinBlockingTermName",
"ifacep2p.shared.MixinPartP2PTunnel",
"ifacep2p.shared.MixinPushPattern"
],
"client": [],
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/mixins.nae2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"crafting.patterntransform.MixinCraftingCPUCluster",
"crafting.patterntransform.MixinCraftingGrid"
"core.MixinTunnelConversion",
"core.crafting.patterntransform.MixinCraftingCPUCluster",
"core.crafting.patterntransform.MixinCraftingGrid"
],
"client": [],
"server": []
Expand Down

0 comments on commit 30ec2b4

Please sign in to comment.