From d4bf7e44edcee523535d8075c6d8c5858dcc2511 Mon Sep 17 00:00:00 2001 From: DauphalXir <3013875189@qq.com> Date: Thu, 8 Aug 2024 07:56:11 +0800 Subject: [PATCH] fix mixin NPE conflict with gtnh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 我是铸币 --- dependencies.gradle | 7 +-- gradle.properties | 2 +- .../{ => late}/DE_GUITeleporter_Mixin.java | 44 +++++++++++-------- .../{ => late}/DE_TeleporterMKII_Mixin.java | 4 +- .../{ => late}/DE_TeleporterPacket_Mixin.java | 8 ++-- .../NHUtilities/{ => client}/ClientProxy.java | 5 +-- .../NHUtilities/{ => common}/CommonProxy.java | 6 ++- .../xir/NHUtilities/{ => config}/Config.java | 2 +- .../NHUtilities/{ => main}/NHUtilities.java | 10 +++-- .../com/xir/NHUtilities/mixin/LateMixins.java | 28 ++++++++++++ .../{Mixins => mixin}/MixinPlugin.java | 5 +-- src/main/resources/mixins.NHUtilities.json | 2 +- .../resources/mixins.NHUtilities.late.json | 9 ++++ 13 files changed, 90 insertions(+), 42 deletions(-) rename src/main/java/com/xir/NHUtilities/Mixins/{ => late}/DE_GUITeleporter_Mixin.java (78%) rename src/main/java/com/xir/NHUtilities/Mixins/{ => late}/DE_TeleporterMKII_Mixin.java (96%) rename src/main/java/com/xir/NHUtilities/Mixins/{ => late}/DE_TeleporterPacket_Mixin.java (91%) rename src/main/java/com/xir/NHUtilities/{ => client}/ClientProxy.java (75%) rename src/main/java/com/xir/NHUtilities/{ => common}/CommonProxy.java (81%) rename src/main/java/com/xir/NHUtilities/{ => config}/Config.java (93%) rename src/main/java/com/xir/NHUtilities/{ => main}/NHUtilities.java (83%) create mode 100644 src/main/java/com/xir/NHUtilities/mixin/LateMixins.java rename src/main/java/com/xir/NHUtilities/{Mixins => mixin}/MixinPlugin.java (85%) create mode 100644 src/main/resources/mixins.NHUtilities.late.json diff --git a/dependencies.gradle b/dependencies.gradle index 72203e7..d253429 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -34,7 +34,8 @@ * For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph */ dependencies { - api("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.66:dev") - implementation("com.github.GTNewHorizons:Draconic-Evolution:1.3.5-GTNH:dev") - implementation("com.github.GTNewHorizons:ae2stuff:0.8.2-GTNH:dev") +// api("com.github.GTNewHorizons:GT5-Unofficial:5.09.48.66:dev") + api('com.github.GTNewHorizons:Baubles:1.0.4:dev') + api("com.github.GTNewHorizons:Draconic-Evolution:1.3.5-GTNH:dev") +// implementation("com.github.GTNewHorizons:ae2stuff:0.8.2-GTNH:dev") } diff --git a/gradle.properties b/gradle.properties index c9c2a18..07518d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -85,7 +85,7 @@ separateMixinSourceSet = usesMixinDebug = false # Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise. -mixinPlugin = +mixinPlugin = mixin.MixinPlugin # Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail! mixinsPackage = Mixins diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_GUITeleporter_Mixin.java similarity index 78% rename from src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java rename to src/main/java/com/xir/NHUtilities/Mixins/late/DE_GUITeleporter_Mixin.java index c84c44c..2b4ee27 100644 --- a/src/main/java/com/xir/NHUtilities/Mixins/DE_GUITeleporter_Mixin.java +++ b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_GUITeleporter_Mixin.java @@ -1,4 +1,4 @@ -package com.xir.NHUtilities.Mixins; +package com.xir.NHUtilities.Mixins.late; import java.util.ArrayList; import java.util.List; @@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -23,43 +24,46 @@ // Before modifying this code, please comment out the annotation below. @SuppressWarnings("all") -@Mixin(value = GUITeleporter.class, remap = false) +@Mixin(value = GUITeleporter.class, remap = true) public abstract class DE_GUITeleporter_Mixin { - @Shadow + @Shadow(remap = false) private ItemStack teleporterItem; - @Shadow + @Shadow(remap = false) private EntityPlayer player; - @Shadow + @Shadow(remap = false) protected List locations = new ArrayList(0); - @Shadow + @Shadow(remap = false) private int tick = 0; - @Shadow + @Shadow(remap = false) private int selected = 0; - @Shadow + @Shadow(remap = false) private int selectionOffset = 0; - @Shadow + @Shadow(remap = false) private boolean showFuelLight = true; - private GUITeleporter theGUITeleporter = (GUITeleporter) ((Object) this); + @Unique + private final GUITeleporter theGUITeleporter = (GUITeleporter) ((Object) this); + @Unique private boolean isBaubles = false; - @Shadow + @Shadow(remap = false) protected abstract void readDataFromItem(ItemStack teleporter); + @Unique private Teleporter.TeleportLocation getLocationSafely(int index) { if (index < locations.size() && index >= 0) return locations.get(index); return new Teleporter.TeleportLocation(0, 0, 0, 0, 0, 0, EnumChatFormatting.DARK_RED + "[Index Error]"); } - @Inject(method = "", at = @At("TAIL"), cancellable = false) + @Inject(method = "", at = @At("TAIL")) private void setBaubles(EntityPlayer player, CallbackInfo ci) { Optional playerBaublesInventory = InventoryUtils .getItemInPlayerBaublesInventory(player, TeleporterMKII.class); @@ -74,24 +78,24 @@ private void setBaubles(EntityPlayer player, CallbackInfo ci) { } /** - * @author Keriils + * @author Keriils -> wo shi zhu bi * @reason the simpler method */ - @Overwrite(remap = false) + @Overwrite(remap = true) public void updateScreen() { if (handOrBaubles()) { theGUITeleporter.mc.displayGuiScreen(null); theGUITeleporter.mc.setIngameFocus(); } - if (tick % 5 == 0 && locations.size() > 0 + if (tick % 5 == 0 && !locations.isEmpty() && getLocationSafely(selected + selectionOffset).getDimensionName() - .equals("") + .isEmpty() && banHand()) { if (isBaubles) { - readDataFromItem( - InventoryUtils.getItemInPlayerBaublesInventory(player, TeleporterMKII.class) - .get()); + Optional playerBaublesInventory = InventoryUtils + .getItemInPlayerBaublesInventory(player, TeleporterMKII.class); + playerBaublesInventory.ifPresent(this::readDataFromItem); } else { readDataFromItem(player.getHeldItem()); } @@ -104,6 +108,7 @@ && banHand()) { } } + @Unique private boolean handOrBaubles() { if (player.isDead) return true; if (!isBaubles) { @@ -113,6 +118,7 @@ private boolean handOrBaubles() { return false; } + @Unique private boolean banHand() { if (isBaubles) return true; return player.getHeldItem() != null && player.getHeldItem() diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterMKII_Mixin.java similarity index 96% rename from src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java rename to src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterMKII_Mixin.java index 1368a3e..2512bc2 100644 --- a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterMKII_Mixin.java +++ b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterMKII_Mixin.java @@ -1,4 +1,4 @@ -package com.xir.NHUtilities.Mixins; +package com.xir.NHUtilities.Mixins.late; import java.util.List; @@ -22,7 +22,7 @@ // Before modifying this code, please comment out the annotation below. @SuppressWarnings("all") -@Mixin(value = TeleporterMKII.class, remap = false) +@Mixin(value = TeleporterMKII.class, remap = true) @Optional.Interface(iface = "baubles.api.IBauble", modid = "Baubles") public class DE_TeleporterMKII_Mixin implements IBauble { diff --git a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterPacket_Mixin.java similarity index 91% rename from src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java rename to src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterPacket_Mixin.java index ab53304..a92e65d 100644 --- a/src/main/java/com/xir/NHUtilities/Mixins/DE_TeleporterPacket_Mixin.java +++ b/src/main/java/com/xir/NHUtilities/Mixins/late/DE_TeleporterPacket_Mixin.java @@ -1,12 +1,12 @@ -package com.xir.NHUtilities.Mixins; +package com.xir.NHUtilities.Mixins.late; import java.util.Optional; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; -import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -17,10 +17,10 @@ // Before modifying this code, please comment out the annotation below. @SuppressWarnings("all") -@Mixin(value = TeleporterPacket.Handler.class, remap = false) +@Mixin(value = TeleporterPacket.Handler.class, remap = true) public class DE_TeleporterPacket_Mixin { - @Nullable + @Unique private ItemStack getHandOrBaublesTeleporter(EntityPlayerMP instance) { Optional playerBaublesInventory = InventoryUtils .getItemInPlayerBaublesInventory(instance, TeleporterMKII.class); diff --git a/src/main/java/com/xir/NHUtilities/ClientProxy.java b/src/main/java/com/xir/NHUtilities/client/ClientProxy.java similarity index 75% rename from src/main/java/com/xir/NHUtilities/ClientProxy.java rename to src/main/java/com/xir/NHUtilities/client/ClientProxy.java index c46ff43..54a8bd7 100644 --- a/src/main/java/com/xir/NHUtilities/ClientProxy.java +++ b/src/main/java/com/xir/NHUtilities/client/ClientProxy.java @@ -1,7 +1,6 @@ -package com.xir.NHUtilities; +package com.xir.NHUtilities.client; -import com.xir.NHUtilities.client.KeyBindings; -import com.xir.NHUtilities.client.KeyInputHandler; +import com.xir.NHUtilities.common.CommonProxy; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; diff --git a/src/main/java/com/xir/NHUtilities/CommonProxy.java b/src/main/java/com/xir/NHUtilities/common/CommonProxy.java similarity index 81% rename from src/main/java/com/xir/NHUtilities/CommonProxy.java rename to src/main/java/com/xir/NHUtilities/common/CommonProxy.java index 8852acf..538bcef 100644 --- a/src/main/java/com/xir/NHUtilities/CommonProxy.java +++ b/src/main/java/com/xir/NHUtilities/common/CommonProxy.java @@ -1,4 +1,8 @@ -package com.xir.NHUtilities; +package com.xir.NHUtilities.common; + +import com.xir.NHUtilities.Tags; +import com.xir.NHUtilities.config.Config; +import com.xir.NHUtilities.main.NHUtilities; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; diff --git a/src/main/java/com/xir/NHUtilities/Config.java b/src/main/java/com/xir/NHUtilities/config/Config.java similarity index 93% rename from src/main/java/com/xir/NHUtilities/Config.java rename to src/main/java/com/xir/NHUtilities/config/Config.java index 162518a..39ebec0 100644 --- a/src/main/java/com/xir/NHUtilities/Config.java +++ b/src/main/java/com/xir/NHUtilities/config/Config.java @@ -1,4 +1,4 @@ -package com.xir.NHUtilities; +package com.xir.NHUtilities.config; import java.io.File; diff --git a/src/main/java/com/xir/NHUtilities/NHUtilities.java b/src/main/java/com/xir/NHUtilities/main/NHUtilities.java similarity index 83% rename from src/main/java/com/xir/NHUtilities/NHUtilities.java rename to src/main/java/com/xir/NHUtilities/main/NHUtilities.java index fac6d67..ceab212 100644 --- a/src/main/java/com/xir/NHUtilities/NHUtilities.java +++ b/src/main/java/com/xir/NHUtilities/main/NHUtilities.java @@ -1,8 +1,11 @@ -package com.xir.NHUtilities; +package com.xir.NHUtilities.main; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.xir.NHUtilities.Tags; +import com.xir.NHUtilities.common.CommonProxy; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; @@ -14,7 +17,6 @@ modid = NHUtilities.MODID, version = Tags.VERSION, name = NHUtilities.MOD_NAME, - dependencies = "required-before:IC2; " + "required-before:gregtech; ", acceptedMinecraftVersions = "[1.7.10]") public class NHUtilities { @@ -25,7 +27,9 @@ public class NHUtilities { @Mod.Instance public static NHUtilities instance; - @SidedProxy(clientSide = "com.xir.NHUtilities.ClientProxy", serverSide = "com.xir.NHUtilities.CommonProxy") + @SidedProxy( + clientSide = "com.xir.NHUtilities.client.ClientProxy", + serverSide = "com.xir.NHUtilities.common.CommonProxy") public static CommonProxy proxy; @Mod.EventHandler diff --git a/src/main/java/com/xir/NHUtilities/mixin/LateMixins.java b/src/main/java/com/xir/NHUtilities/mixin/LateMixins.java new file mode 100644 index 0000000..d8861b9 --- /dev/null +++ b/src/main/java/com/xir/NHUtilities/mixin/LateMixins.java @@ -0,0 +1,28 @@ +package com.xir.NHUtilities.mixin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import com.gtnewhorizon.gtnhmixins.ILateMixinLoader; +import com.gtnewhorizon.gtnhmixins.LateMixin; + +@LateMixin +public class LateMixins implements ILateMixinLoader { + + @Override + public String getMixinConfig() { + return "mixins.NHUtilities.late.json"; + } + + @Override + public List getMixins(Set loadedMods) { + ArrayList Mixins = new ArrayList<>(); + if (loadedMods.contains("DraconicEvolution")) { + Mixins.add("DE_TeleporterMKII_Mixin"); + Mixins.add("DE_GUITeleporter_Mixin"); + Mixins.add("DE_TeleporterPacket_Mixin"); + } + return Mixins; + } +} diff --git a/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java b/src/main/java/com/xir/NHUtilities/mixin/MixinPlugin.java similarity index 85% rename from src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java rename to src/main/java/com/xir/NHUtilities/mixin/MixinPlugin.java index 77ddd0a..265b82a 100644 --- a/src/main/java/com/xir/NHUtilities/Mixins/MixinPlugin.java +++ b/src/main/java/com/xir/NHUtilities/mixin/MixinPlugin.java @@ -1,4 +1,4 @@ -package com.xir.NHUtilities.Mixins; +package com.xir.NHUtilities.mixin; import java.util.ArrayList; import java.util.List; @@ -33,9 +33,6 @@ public void acceptTargets(Set myTargets, Set otherTargets) { @Override public List getMixins() { ArrayList Mixins = new ArrayList<>(); - Mixins.add("DE_TeleporterMKII_Mixin"); - Mixins.add("DE_TeleporterPacket_Mixin"); - Mixins.add("DE_GUITeleporter_Mixin"); return Mixins; } diff --git a/src/main/resources/mixins.NHUtilities.json b/src/main/resources/mixins.NHUtilities.json index e4c5bdf..98f615e 100644 --- a/src/main/resources/mixins.NHUtilities.json +++ b/src/main/resources/mixins.NHUtilities.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8.5-GTNH", "package": "com.xir.NHUtilities.Mixins", - "plugin": "com.xir.NHUtilities.Mixins.MixinPlugin", + "plugin": "com.xir.NHUtilities.mixin.MixinPlugin", "refmap": "mixins.NHUtilities.refmap.json", "target": "@env(DEFAULT)", "compatibilityLevel": "JAVA_8" diff --git a/src/main/resources/mixins.NHUtilities.late.json b/src/main/resources/mixins.NHUtilities.late.json new file mode 100644 index 0000000..987a6ef --- /dev/null +++ b/src/main/resources/mixins.NHUtilities.late.json @@ -0,0 +1,9 @@ +{ + "required": true, + "minVersion": "0.8.5-GTNH", + "package": "com.xir.NHUtilities.Mixins.late", + "refmap": "mixins.NHUtilities.refmap.json", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8" +} +