From 753bc402777f120e63cd90392f20d9797d60ae17 Mon Sep 17 00:00:00 2001 From: NotMyWing Date: Mon, 10 Jun 2024 18:21:45 +1100 Subject: [PATCH] Switch over to TunnelType API --- src/main/java/co/neeve/nae2/NAE2API.java | 6 --- .../nae2/common/api/TunnelConversionAPI.java | 19 -------- .../nae2/common/integration/ae2fc/AE2FC.java | 11 +++-- .../registration/definitions/Parts.java | 13 +++--- .../mixin/core/MixinTunnelConversion.java | 43 ------------------- src/main/resources/mixins.nae2.json | 1 - 6 files changed, 16 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/co/neeve/nae2/common/api/TunnelConversionAPI.java delete mode 100644 src/main/java/co/neeve/nae2/mixin/core/MixinTunnelConversion.java diff --git a/src/main/java/co/neeve/nae2/NAE2API.java b/src/main/java/co/neeve/nae2/NAE2API.java index f6155af..ad8c1ce 100644 --- a/src/main/java/co/neeve/nae2/NAE2API.java +++ b/src/main/java/co/neeve/nae2/NAE2API.java @@ -1,11 +1,9 @@ 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() {} @@ -17,8 +15,4 @@ public class NAE2API { public ExposerAPI exposer() { return this.exposerAPI; } - - public TunnelConversionAPI tunnelConversion() { - return this.tunnelConversionAPI; - } } diff --git a/src/main/java/co/neeve/nae2/common/api/TunnelConversionAPI.java b/src/main/java/co/neeve/nae2/common/api/TunnelConversionAPI.java deleted file mode 100644 index c7bbccb..0000000 --- a/src/main/java/co/neeve/nae2/common/api/TunnelConversionAPI.java +++ /dev/null @@ -1,19 +0,0 @@ -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 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); - } -} diff --git a/src/main/java/co/neeve/nae2/common/integration/ae2fc/AE2FC.java b/src/main/java/co/neeve/nae2/common/integration/ae2fc/AE2FC.java index 4babdaf..0a5d2ce 100644 --- a/src/main/java/co/neeve/nae2/common/integration/ae2fc/AE2FC.java +++ b/src/main/java/co/neeve/nae2/common/integration/ae2fc/AE2FC.java @@ -1,5 +1,7 @@ package co.neeve.nae2.common.integration.ae2fc; +import appeng.api.AEApi; +import appeng.api.config.TunnelType; import co.neeve.nae2.NAE2; import co.neeve.nae2.common.registration.definitions.Upgrades; import com.glodblock.github.loader.FCBlocks; @@ -16,9 +18,12 @@ public static void initInterfaceUpgrade(Upgrades.UpgradeType upgrade) { 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); + try { + var tunnelType = Enum.valueOf(TunnelType.class, "NAE2_IFACE_P2P"); + var reg = AEApi.instance().registries().p2pTunnel(); + reg.addNewAttunement(new ItemStack(FCBlocks.DUAL_INTERFACE), tunnelType); + reg.addNewAttunement(new ItemStack(FCItems.PART_DUAL_INTERFACE), tunnelType); + } catch (IllegalArgumentException ignored) {} }); } } diff --git a/src/main/java/co/neeve/nae2/common/registration/definitions/Parts.java b/src/main/java/co/neeve/nae2/common/registration/definitions/Parts.java index a204dc2..14354f8 100644 --- a/src/main/java/co/neeve/nae2/common/registration/definitions/Parts.java +++ b/src/main/java/co/neeve/nae2/common/registration/definitions/Parts.java @@ -1,13 +1,13 @@ package co.neeve.nae2.common.registration.definitions; import appeng.api.AEApi; +import appeng.api.config.TunnelType; 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; @@ -59,19 +59,22 @@ public Parts(Registry registry) { this.p2pTunnelInterface = this.createPart(this.itemPart, PartType.P2P_TUNNEL_INTERFACE); this.p2pTunnelInterface.maybeStack(1) .ifPresent((tunnelStack) -> registry.addBootstrapComponent((IPostInitComponent) (r) -> { + var tunnelType = AEApi.instance().registries().p2pTunnel() + .registerTunnelType("NAE2_IFACE_P2P", tunnelStack); + var definitions = Api.INSTANCE.definitions(); definitions.blocks().iface().maybeStack(1) - .ifPresent((stack) -> registerTunnelConversion(tunnelStack, stack)); + .ifPresent((stack) -> registerTunnelConversion(tunnelType, stack)); definitions.parts().iface().maybeStack(1) - .ifPresent((stack) -> registerTunnelConversion(tunnelStack, stack)); + .ifPresent((stack) -> registerTunnelConversion(tunnelType, stack)); })); this.exposer = this.createPart(this.itemPart, PartType.EXPOSER); } - private static void registerTunnelConversion(ItemStack tunnelStack, ItemStack stack) { - NAE2.api().tunnelConversion().register(stack, tunnelStack); + private static void registerTunnelConversion(TunnelType tunnelType, ItemStack stack) { + AEApi.instance().registries().p2pTunnel().addNewAttunement(stack, tunnelType); } public static Optional getById(int itemDamage) { diff --git a/src/main/java/co/neeve/nae2/mixin/core/MixinTunnelConversion.java b/src/main/java/co/neeve/nae2/mixin/core/MixinTunnelConversion.java deleted file mode 100644 index cc9ba42..0000000 --- a/src/main/java/co/neeve/nae2/mixin/core/MixinTunnelConversion.java +++ /dev/null @@ -1,43 +0,0 @@ -package co.neeve.nae2.mixin.core; - -import appeng.api.config.TunnelType; -import appeng.api.implementations.items.IMemoryCard; -import appeng.parts.p2p.PartP2PTunnel; -import co.neeve.nae2.NAE2; -import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyVariable; - -@Mixin(PartP2PTunnel.class) -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 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(); - - if (!(item instanceof IMemoryCard)) { - var conversion = NAE2.api().tunnelConversion().getConversion(hand); - if (!conversion.isEmpty()) { - // Return whatever. - return TunnelType.ME; - } - } - - return newType; - } -} diff --git a/src/main/resources/mixins.nae2.json b/src/main/resources/mixins.nae2.json index 51414f0..dc39939 100644 --- a/src/main/resources/mixins.nae2.json +++ b/src/main/resources/mixins.nae2.json @@ -5,7 +5,6 @@ "minVersion": "0.8", "compatibilityLevel": "JAVA_8", "mixins": [ - "core.MixinTunnelConversion", "core.crafting.patterntransform.MixinCraftingCPUCluster", "core.crafting.patterntransform.MixinCraftingGrid" ],