Skip to content

Commit

Permalink
fix mixin NPE conflict with gtnh
Browse files Browse the repository at this point in the history
我是铸币
  • Loading branch information
Keriils committed Aug 7, 2024
1 parent 86c0d0f commit d4bf7e4
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 42 deletions.
7 changes: 4 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xir.NHUtilities.Mixins;
package com.xir.NHUtilities.Mixins.late;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -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;
Expand All @@ -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<Teleporter.TeleportLocation> locations = new ArrayList<Teleporter.TeleportLocation>(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 = "<init>", at = @At("TAIL"), cancellable = false)
@Inject(method = "<init>", at = @At("TAIL"))
private void setBaubles(EntityPlayer player, CallbackInfo ci) {
Optional<ItemStack> playerBaublesInventory = InventoryUtils
.getItemInPlayerBaublesInventory(player, TeleporterMKII.class);
Expand All @@ -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<ItemStack> playerBaublesInventory = InventoryUtils
.getItemInPlayerBaublesInventory(player, TeleporterMKII.class);
playerBaublesInventory.ifPresent(this::readDataFromItem);
} else {
readDataFromItem(player.getHeldItem());
}
Expand All @@ -104,6 +108,7 @@ && banHand()) {
}
}

@Unique
private boolean handOrBaubles() {
if (player.isDead) return true;
if (!isBaubles) {
Expand All @@ -113,6 +118,7 @@ private boolean handOrBaubles() {
return false;
}

@Unique
private boolean banHand() {
if (isBaubles) return true;
return player.getHeldItem() != null && player.getHeldItem()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xir.NHUtilities.Mixins;
package com.xir.NHUtilities.Mixins.late;

import java.util.List;

Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<ItemStack> playerBaublesInventory = InventoryUtils
.getItemInPlayerBaublesInventory(instance, TeleporterMKII.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xir.NHUtilities;
package com.xir.NHUtilities.config;

import java.io.File;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/xir/NHUtilities/mixin/LateMixins.java
Original file line number Diff line number Diff line change
@@ -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<String> getMixins(Set<String> loadedMods) {
ArrayList<String> Mixins = new ArrayList<>();
if (loadedMods.contains("DraconicEvolution")) {
Mixins.add("DE_TeleporterMKII_Mixin");
Mixins.add("DE_GUITeleporter_Mixin");
Mixins.add("DE_TeleporterPacket_Mixin");
}
return Mixins;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xir.NHUtilities.Mixins;
package com.xir.NHUtilities.mixin;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -33,9 +33,6 @@ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
@Override
public List<String> getMixins() {
ArrayList<String> Mixins = new ArrayList<>();
Mixins.add("DE_TeleporterMKII_Mixin");
Mixins.add("DE_TeleporterPacket_Mixin");
Mixins.add("DE_GUITeleporter_Mixin");
return Mixins;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixins.NHUtilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/mixins.NHUtilities.late.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit d4bf7e4

Please sign in to comment.