diff options
author | Raven Szewczyk <git@eigenraven.me> | 2024-05-26 22:40:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-26 23:40:25 +0200 |
commit | f3df59d9f730d7d777346c454c43e28157d1f60f (patch) | |
tree | fff0ca6f093f071ec6a926ea5e80476a5c6919fd /src/main/java | |
parent | d96dbdb8d58b646c3f3dda174b8dd87724327d7f (diff) | |
download | GT5-Unofficial-f3df59d9f730d7d777346c454c43e28157d1f60f.tar.gz GT5-Unofficial-f3df59d9f730d7d777346c454c43e28157d1f60f.tar.bz2 GT5-Unofficial-f3df59d9f730d7d777346c454c43e28157d1f60f.zip |
Asm->Mixin conversion (#2620)
* Set up early and late mixins hodgepodge-style
* Port bartworks asm to mixins
* Wire up bartworks asm configs
* Fix wrong mixin targets
* Remove the coremod dependency
* update deps
---------
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java')
18 files changed, 474 insertions, 581 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java deleted file mode 100644 index 725a0135a4..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.ASM; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.objectweb.asm.tree.MethodNode; - -public class ASMUtils { - - public static String matchAny(String toCompare, String... args) { - for (String arg : args) { - if (toCompare.equalsIgnoreCase(arg)) return arg; - } - return ""; - } - - /** - * Call this Method twice, one time for the Descriptor and one time for the Name. - */ - public static boolean isCorrectMethod(MethodNode methodNode, String... args) { - for (String arg : args) { - if (methodNode.name.equalsIgnoreCase(arg) || methodNode.desc.equalsIgnoreCase(arg)) return true; - } - return false; - } - - public static boolean writeClassToDisk(byte[] towrite, String Classname, String Path) { - try { - if (Path.charAt(Path.length() - 1) == '/' || Path.charAt(Path.length() - 1) == '\\') - Path = Path.substring(0, Path.length() - 1); - OutputStream os = new FileOutputStream(new File(Path + '/' + Classname + ".class")); - os.write(towrite); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - return true; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java deleted file mode 100644 index 9841ef78da..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.ASM; - -import static com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer.shouldTransform; -import static gregtech.api.enums.Mods.ExtraUtilities; -import static gregtech.api.enums.Mods.RWG; -import static gregtech.api.enums.Mods.Thaumcraft; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.github.bartimaeusnek.bartworks.MainMod; -import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; -import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -import cpw.mods.fml.common.DummyModContainer; -import cpw.mods.fml.common.LoadController; -import cpw.mods.fml.common.ModMetadata; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.versioning.ArtifactVersion; -import cpw.mods.fml.common.versioning.DefaultArtifactVersion; - -public class BWCore extends DummyModContainer { - - public static final String BWCORE_NAME = "BartWorks ASM Core"; - public static final Logger BWCORE_LOG = LogManager.getLogger(BWCore.BWCORE_NAME); - - public BWCore() { - super(new ModMetadata()); - ModMetadata metadata = this.getMetadata(); - metadata.modId = "BWCore"; - metadata.name = BWCore.BWCORE_NAME; - metadata.version = "0.0.1"; - metadata.authorList.add("bartimaeusnek"); - metadata.dependants = this.getDependants(); - metadata.parent = MainMod.MOD_ID; - } - - @Subscribe - public void preInit(FMLPreInitializationEvent event) { - shouldTransform[0] = ConfigHandler.enabledPatches[0]; - shouldTransform[1] = ConfigHandler.enabledPatches[1]; - shouldTransform[2] = ConfigHandler.enabledPatches[2]; - shouldTransform[3] = ConfigHandler.enabledPatches[3]; - BWCore.BWCORE_LOG.info("Extra Utilities found and ASM Patch enabled? " + shouldTransform[0]); - BWCore.BWCORE_LOG.info("Thaumcraft found and ASM Patch enabled? " + shouldTransform[2]); - } - - @Override - public List<ArtifactVersion> getDependants() { - List<ArtifactVersion> ret = new ArrayList<>(); - ret.add(new DefaultArtifactVersion(ExtraUtilities.ID, true)); - ret.add(new DefaultArtifactVersion(Thaumcraft.ID, true)); - ret.add(new DefaultArtifactVersion(RWG.ID, true)); - ret.add(new DefaultArtifactVersion(MainMod.MOD_ID, true)); - ret.add(new DefaultArtifactVersion(BartWorksCrossmod.MOD_ID, true)); - return ret; - } - - @Override - public boolean registerBus(EventBus bus, LoadController controller) { - bus.register(this); - return true; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java deleted file mode 100644 index 2659f07af1..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: The above copyright notice and this permission notice shall be included in all copies or substantial - * portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.github.bartimaeusnek.bartworks.ASM; - -import static org.objectweb.asm.Opcodes.ACC_PUBLIC; -import static org.objectweb.asm.Opcodes.ACONST_NULL; -import static org.objectweb.asm.Opcodes.ALOAD; -import static org.objectweb.asm.Opcodes.ARETURN; -import static org.objectweb.asm.Opcodes.GETFIELD; -import static org.objectweb.asm.Opcodes.ICONST_0; -import static org.objectweb.asm.Opcodes.IFNE; -import static org.objectweb.asm.Opcodes.INVOKESTATIC; -import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; -import static org.objectweb.asm.Opcodes.IRETURN; -import static org.objectweb.asm.Opcodes.POP; - -import java.util.Arrays; -import java.util.List; - -import net.minecraft.launchwrapper.IClassTransformer; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.JumpInsnNode; -import org.objectweb.asm.tree.LabelNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.VarInsnNode; - -public class BWCoreTransformer implements IClassTransformer { - - public static final String[] DESCRIPTIONFORCONFIG = { "REMOVING RAIN FROM LAST MILLENNIUM (EXU)", - "REMOVING CREATURES FROM LAST MILLENNIUM (EXU)", "PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION", - "PATCHING CRAFTING MANAGER FOR CACHING RECIPES" }; - public static final String[] CLASSESBEINGTRANSFORMED = { - "com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime", - "com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime", "thaumcraft.common.tiles.TileWandPedestal", - "net.minecraft.item.crafting.CraftingManager" }; - public static boolean obfs; - - public static boolean[] shouldTransform = new boolean[BWCoreTransformer.CLASSESBEINGTRANSFORMED.length]; - - /** - * Made by DarkShaddow44 - */ - private static MethodNode transformThaumcraftWandPedestal(MethodNode method) { - InsnList nu = new InsnList(); - for (int j = 0; j < method.instructions.size(); j++) { - AbstractInsnNode instruction = method.instructions.get(j); - nu.add(instruction); - if (instruction.getOpcode() == INVOKEVIRTUAL) { - MethodInsnNode invokevirtual = (MethodInsnNode) instruction; - if ("addVis".equals(invokevirtual.name)) { - AbstractInsnNode beginning = method.instructions.get(j - 7); - LabelNode label = new LabelNode(); - nu.insertBefore(beginning, new VarInsnNode(ALOAD, 0)); - nu.insertBefore( - beginning, - new FieldInsnNode( - GETFIELD, - "thaumcraft/common/tiles/TileWandPedestal", - obfs ? "field_145850_b" : "worldObj", - "Lnet/minecraft/world/World;")); - nu.insertBefore( - beginning, - new FieldInsnNode( - GETFIELD, - "net/minecraft/world/World", - obfs ? "field_72995_K" : "isRemote", - "Z")); - nu.insertBefore(beginning, new JumpInsnNode(IFNE, label)); - nu.add(new InsnNode(POP)); - nu.add(label); - j++; // Skip actual Pop - } - } - } - method.instructions = nu; - return method; - } - - public static byte[] transform(int id, byte[] basicClass) { - if (!BWCoreTransformer.shouldTransform[id]) { - BWCore.BWCORE_LOG - .info("Patch: " + BWCoreTransformer.DESCRIPTIONFORCONFIG[id] + " is disabled, will not patch!"); - return basicClass; - } - - if (id < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length) { - BWCore.BWCORE_LOG.info(BWCoreTransformer.DESCRIPTIONFORCONFIG[id]); - ClassReader classReader = new ClassReader(basicClass); - ClassNode classNode = new ClassNode(); - classReader.accept(classNode, ClassReader.SKIP_FRAMES); - List<MethodNode> methods = classNode.methods; - scase: switch (id) { - case 0: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "canDoRainSnowIce"; - - String dsc_deObfs = "(Lnet/minecraft/world/chunk/Chunk;)Z"; - for (int i = 0; i < methods.size(); i++) { - if (methods.get(i).name.equalsIgnoreCase(name_deObfs)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Removing!"); - methods.remove(i); - break; - } - } - BWCore.BWCORE_LOG.info("Creating new " + name_deObfs + "!"); - MethodNode nu = new MethodNode(ACC_PUBLIC, name_deObfs, dsc_deObfs, null, new String[0]); - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(ICONST_0)); - insnList.add(new InsnNode(IRETURN)); - nu.instructions = insnList; - nu.maxLocals = 1; - nu.maxStack = 1; - methods.add(nu); - break; - } - case 1: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "getPossibleCreatures"; - String name_src = "func_73155_a"; - String name_Obfs = "a"; - String dsc_deObfs = "(Lnet/minecraft/entity/EnumCreatureType;III)Ljava/util/List;"; - String dsc_Obfs = "(Lsx;III)Ljava/util/List;"; - - for (int i = 0; i < methods.size(); i++) { - if (ASMUtils.isCorrectMethod(methods.get(i), name_deObfs, name_Obfs, name_src) - && ASMUtils.isCorrectMethod(methods.get(i), dsc_deObfs, dsc_Obfs)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!"); - MethodNode toPatch = methods.get(i); - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(ACONST_NULL)); - insnList.add(new InsnNode(ARETURN)); - toPatch.instructions = insnList; - toPatch.maxStack = 1; - toPatch.maxLocals = 5; - methods.set(i, toPatch); - break scase; - } - } - } - case 2: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "updateEntity"; - String name_src = "func_145845_h"; - String name_Obfs = "h"; - String dsc_universal = "()V"; - - for (int i = 0; i < methods.size(); i++) { - if (ASMUtils.isCorrectMethod(methods.get(i), name_deObfs, name_Obfs, name_src) - && ASMUtils.isCorrectMethod(methods.get(i), dsc_universal, dsc_universal)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!"); - methods.set(i, BWCoreTransformer.transformThaumcraftWandPedestal(methods.get(i))); - break scase; - } - } - } - case 3: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "findMatchingRecipe"; - String name_Obfs = "a"; - String name_src = "func_82787_a"; - for (MethodNode toPatch : methods) { - if (ASMUtils.isCorrectMethod(toPatch, name_deObfs, name_Obfs, name_src)) { - toPatch.instructions = new InsnList(); - toPatch.instructions.add(new VarInsnNode(ALOAD, 1)); - toPatch.instructions.add(new VarInsnNode(ALOAD, 2)); - toPatch.instructions.add( - new MethodInsnNode( - INVOKESTATIC, - "com/github/bartimaeusnek/bartworks/ASM/BWCoreStaticReplacementMethodes", - "findCachedMatchingRecipe", - "(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Lnet/minecraft/item/ItemStack;", - false)); - toPatch.instructions.add(new InsnNode(ARETURN)); - toPatch.localVariables.clear(); - toPatch.maxStack = 2; - toPatch.maxLocals = 3; - break scase; - } - } - } - - default: { - BWCore.BWCORE_LOG.info("Could not find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - return basicClass; - } - } - - classNode.methods = methods; - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - classNode.accept(classWriter); - byte[] ret = classWriter.toByteArray(); - if (Arrays.hashCode(basicClass) == Arrays.hashCode(ret)) - BWCore.BWCORE_LOG.warn("Could not patch: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - return ret; - } - return basicClass; - } - - @Override - public byte[] transform(String name, String transformedName, byte[] basicClass) { - for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++) { - if (name.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i]) - || transformedName.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i])) - return BWCoreTransformer.transform(i, basicClass); - } - return basicClass; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java index 7c5a515b86..ee53c6ec64 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java @@ -21,7 +21,6 @@ import java.util.Set; import net.minecraftforge.common.config.Configuration; import com.github.bartimaeusnek.bartworks.API.API_ConfigValues; -import com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer; public class ConfigHandler { @@ -104,6 +103,14 @@ public class ConfigHandler { "Ultimate Extended Mega Voltage", "Overpowered Voltage", "Maximum Voltage" }; private static final String[] names = { "Generators", "Buffers", "Cables", "Machines" }; + public static final String[] ASM_TRANSFORMER_DESCRIPTIONS = { "REMOVING RAIN FROM LAST MILLENNIUM (EXU)", + "REMOVING CREATURES FROM LAST MILLENNIUM (EXU)", "PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION", + "PATCHING CRAFTING MANAGER FOR CACHING RECIPES" }; + public static final String[] ASM_TRANSFORMER_CLASSES = { + "com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime", + "com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime", "thaumcraft.common.tiles.TileWandPedestal", + "net.minecraft.item.crafting.CraftingManager" }; + public ConfigHandler(Configuration C) { ConfigHandler.c = C; ConfigHandler.classicMode = ConfigHandler.c @@ -255,18 +262,11 @@ public class ConfigHandler { .get("System", "Enable Debug Log", false, "Enables or Disables the debug log.") .getBoolean(false); - for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++) - BWCoreTransformer.shouldTransform[i] = ConfigHandler.c - .get( - "ASM fixes", - BWCoreTransformer.DESCRIPTIONFORCONFIG[i] + " in class: " - + BWCoreTransformer.CLASSESBEINGTRANSFORMED[i], - true) - .getBoolean(true); - - ConfigHandler.enabledPatches = new boolean[BWCoreTransformer.shouldTransform.length]; - ConfigHandler.enabledPatches = Arrays - .copyOf(BWCoreTransformer.shouldTransform, BWCoreTransformer.shouldTransform.length); + ConfigHandler.enabledPatches = new boolean[ASM_TRANSFORMER_CLASSES.length]; + for (int i = 0; i < ASM_TRANSFORMER_CLASSES.length; i++) ConfigHandler.enabledPatches[i] = ConfigHandler.c + .get("ASM fixes", ASM_TRANSFORMER_DESCRIPTIONS[i] + " in class: " + ASM_TRANSFORMER_CLASSES[i], true) + .getBoolean(true); + ConfigHandler.ross128BID = ConfigHandler.c .get("CrossMod Interactions", "DimID - Ross128b", -64, "The Dim ID for Ross128b") .getInt(-64); diff --git a/src/main/java/gregtech/asm/GTCorePlugin.java b/src/main/java/gregtech/asm/GTCorePlugin.java index a31d106bbe..0f50b78f1d 100644 --- a/src/main/java/gregtech/asm/GTCorePlugin.java +++ b/src/main/java/gregtech/asm/GTCorePlugin.java @@ -1,17 +1,18 @@ package gregtech.asm; import java.io.File; -import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.Set; import net.minecraftforge.common.config.Configuration; -import com.github.bartimaeusnek.bartworks.ASM.BWCore; -import com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; +import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader; import cpw.mods.fml.relauncher.FMLInjectionData; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import gregtech.mixin.Mixin; import gtPlusPlus.preloader.CORE_Preloader; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.preloader.asm.Preloader_DummyContainer; @@ -23,7 +24,7 @@ import gtPlusPlus.preloader.asm.transformers.Preloader_Transformer_Handler; "gregtech.asm" }) @IFMLLoadingPlugin.Name("GregTech 5 Unofficial core plugin") @SuppressWarnings("unused") // loaded by FML -public class GTCorePlugin implements IFMLLoadingPlugin { +public class GTCorePlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { public static final String BWCORE_PLUGIN_NAME = "BartWorks ASM Core Plugin"; public static File minecraftDir; @@ -34,17 +35,15 @@ public class GTCorePlugin implements IFMLLoadingPlugin { minecraftDir = (File) FMLInjectionData.data()[6]; // do all the configuration already now... new ConfigHandler(new Configuration(new File(new File(minecraftDir, "config"), "bartworks.cfg"))); - BWCoreTransformer.shouldTransform[2] = false; } @Override public String[] getASMTransformerClass() { - return new String[] { BWCoreTransformer.class.getName(), Preloader_Transformer_Handler.class.getName() }; + return new String[] { Preloader_Transformer_Handler.class.getName() }; } @Override public String getModContainerClass() { - FMLInjectionData.containers.add(BWCore.class.getName()); return Preloader_DummyContainer.class.getName(); } @@ -62,24 +61,20 @@ public class GTCorePlugin implements IFMLLoadingPlugin { CORE_Preloader.setMinecraftDirectory(mcDir); } CORE_Preloader.DEBUG_MODE = AsmConfig.debugMode; - - // Bartworks - if (data.get("runtimeDeobfuscationEnabled") != null) { - BWCoreTransformer.obfs = (boolean) data.get("runtimeDeobfuscationEnabled"); - } - if (data.get("coremodList") != null) { - for (Object o : (ArrayList) data.get("coremodList")) { - if (o.toString() - .contains("MicdoodlePlugin")) { - BWCoreTransformer.shouldTransform[2] = ConfigHandler.enabledPatches[2]; - break; - } - } - } } @Override public String getAccessTransformerClass() { return null; } + + @Override + public String getMixinConfig() { + return "mixins.gregtech.early.json"; + } + + @Override + public List<String> getMixins(Set<String> loadedCoreMods) { + return Mixin.getEarlyMixins(loadedCoreMods); + } } diff --git a/src/main/java/gregtech/mixin/LateMixinPlugin.java b/src/main/java/gregtech/mixin/LateMixinPlugin.java new file mode 100644 index 0000000000..dab8cc5f03 --- /dev/null +++ b/src/main/java/gregtech/mixin/LateMixinPlugin.java @@ -0,0 +1,21 @@ +package gregtech.mixin; + +import java.util.List; +import java.util.Set; + +import com.gtnewhorizon.gtnhmixins.ILateMixinLoader; +import com.gtnewhorizon.gtnhmixins.LateMixin; + +@LateMixin +public class LateMixinPlugin implements ILateMixinLoader { + + @Override + public String getMixinConfig() { + return "mixins.gregtech.late.json"; + } + + @Override + public List<String> getMixins(Set<String> loadedMods) { + return Mixin.getLateMixins(loadedMods); + } +} diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 347dec2c5e..6e2b927afe 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -1,50 +1,237 @@ package gregtech.mixin; +import static gregtech.mixin.TargetedMod.EXTRA_UTILITIES; +import static gregtech.mixin.TargetedMod.THAUMCRAFT; import static gregtech.mixin.TargetedMod.VANILLA; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import cpw.mods.fml.relauncher.FMLLaunchHandler; public enum Mixin { // Minecraft - WorldMixin("minecraft.WorldMixin", VANILLA), - StringTranslateMixin("minecraft.StringTranslateMixin", VANILLA), - LanguageRegistryMixin("minecraft.LanguageRegistryMixin", VANILLA), - LocaleMixin("minecraft.LocaleMixin", Side.CLIENT, VANILLA), + WorldMixin(new Builder("Block update detection").addMixinClasses("minecraft.WorldMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + StringTranslateMixin(new Builder("Keep track of currently translating mods") + .addMixinClasses("minecraft.StringTranslateMixin", "minecraft.LanguageRegistryMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + LocaleMixin(new Builder("Keep track of currently translating client mods").addMixinClasses("minecraft.LocaleMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.CLIENT)), + CacheCraftingManagerRecipes( + new Builder("Cache CraftingManager recipes").addMixinClasses("minecraft.CraftingManagerMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> ConfigHandler.enabledPatches[3]) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + // Extra utilities + RemoveLastMilleniumRain(new Builder("Remove rain from the Last Millenium (Extra Utilities)") + .addMixinClasses("xu.WorldProviderEndOfTimeMixin") + .addTargetedMod(EXTRA_UTILITIES) + .setApplyIf(() -> ConfigHandler.enabledPatches[0]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)), + RemoveLastMilleniumCreatures(new Builder("Remove creatures from the Last Millenium (Extra Utilities)") + .addMixinClasses("xu.ChunkProviderEndOfTimeMixin") + .addTargetedMod(EXTRA_UTILITIES) + .setApplyIf(() -> ConfigHandler.enabledPatches[1]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)), + // Thaumcraft + PatchWandPedestalVisDuplication(new Builder("Fix wand pedestal vis duplication (Thaumcraft)") + .addMixinClasses("thaumcraft.TileWandPedestalMixin") + .addTargetedMod(THAUMCRAFT) + .setApplyIf(() -> ConfigHandler.enabledPatches[2]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)),; - ; + public static final Logger LOGGER = LogManager.getLogger("GregTech-Mixin"); - public final String mixinClass; - public final List<TargetedMod> targetedMods; + private final List<String> mixinClasses; + private final List<TargetedMod> targetedMods; + private final List<TargetedMod> excludedMods; + private final Supplier<Boolean> applyIf; + private final Phase phase; private final Side side; - Mixin(String mixinClass, Side side, TargetedMod... targetedMods) { - this.mixinClass = mixinClass; - this.targetedMods = Arrays.asList(targetedMods); - this.side = side; + Mixin(Builder builder) { + this.mixinClasses = builder.mixinClasses; + this.targetedMods = builder.targetedMods; + this.excludedMods = builder.excludedMods; + this.applyIf = builder.applyIf; + this.phase = builder.phase; + this.side = builder.side; + if (this.mixinClasses.isEmpty()) { + throw new RuntimeException("No mixin class specified for Mixin : " + this.name()); + } + if (this.targetedMods.isEmpty()) { + throw new RuntimeException("No targeted mods specified for Mixin : " + this.name()); + } + if (this.applyIf == null) { + throw new RuntimeException("No ApplyIf function specified for Mixin : " + this.name()); + } + if (this.phase == null) { + throw new RuntimeException("No Phase specified for Mixin : " + this.name()); + } + if (this.side == null) { + throw new RuntimeException("No Side function specified for Mixin : " + this.name()); + } + } + + public static List<String> getEarlyMixins(Set<String> loadedCoreMods) { + final List<String> mixins = new ArrayList<>(); + final List<String> notLoading = new ArrayList<>(); + for (Mixin mixin : Mixin.values()) { + if (mixin.phase == Phase.EARLY) { + if (mixin.shouldLoad(loadedCoreMods, Collections.emptySet())) { + mixins.addAll(mixin.mixinClasses); + } else { + notLoading.addAll(mixin.mixinClasses); + } + } + } + LOGGER.info("Not loading the following EARLY mixins: {}", notLoading.toString()); + return mixins; + } + + public static List<String> getLateMixins(Set<String> loadedMods) { + // NOTE: Any targetmod here needs a modid, not a coremod id + final List<String> mixins = new ArrayList<>(); + final List<String> notLoading = new ArrayList<>(); + for (Mixin mixin : Mixin.values()) { + if (mixin.phase == Phase.LATE) { + if (mixin.shouldLoad(Collections.emptySet(), loadedMods)) { + mixins.addAll(mixin.mixinClasses); + } else { + notLoading.addAll(mixin.mixinClasses); + } + } + } + LOGGER.info("Not loading the following LATE mixins: {}", notLoading.toString()); + return mixins; + } + + private boolean shouldLoadSide() { + return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side() + .isServer()) + || (side == Side.CLIENT && FMLLaunchHandler.side() + .isClient()); + } + + private boolean allModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) { + if (targetedMods.isEmpty()) return false; + + for (TargetedMod target : targetedMods) { + if (target == TargetedMod.VANILLA) continue; + + // Check coremod first + if (!loadedCoreMods.isEmpty() && target.coreModClass != null + && !loadedCoreMods.contains(target.coreModClass)) return false; + else if (!loadedMods.isEmpty() && target.modId != null && !loadedMods.contains(target.modId)) return false; + } + + return true; + } + + private boolean noModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) { + if (targetedMods.isEmpty()) return true; + + for (TargetedMod target : targetedMods) { + if (target == TargetedMod.VANILLA) continue; + + // Check coremod first + if (!loadedCoreMods.isEmpty() && target.coreModClass != null + && loadedCoreMods.contains(target.coreModClass)) return false; + else if (!loadedMods.isEmpty() && target.modId != null && loadedMods.contains(target.modId)) return false; + } + + return true; } - Mixin(String mixinClass, TargetedMod... targetedMods) { - this.mixinClass = mixinClass; - this.targetedMods = Arrays.asList(targetedMods); - this.side = Side.BOTH; + private boolean shouldLoad(Set<String> loadedCoreMods, Set<String> loadedMods) { + return (shouldLoadSide() && applyIf.get() + && allModsLoaded(targetedMods, loadedCoreMods, loadedMods) + && noModsLoaded(excludedMods, loadedCoreMods, loadedMods)); } - public boolean shouldLoad(List<TargetedMod> loadedMods) { - return (side == Side.BOTH || side == Side.SERVER && FMLLaunchHandler.side() - .isServer() - || side == Side.CLIENT && FMLLaunchHandler.side() - .isClient()) - && new HashSet<>(loadedMods).containsAll(targetedMods); + private static class Builder { + + private final String name; + private final List<String> mixinClasses = new ArrayList<>(); + private final List<TargetedMod> targetedMods = new ArrayList<>(); + private final List<TargetedMod> excludedMods = new ArrayList<>(); + private Supplier<Boolean> applyIf = null; + private Phase phase = null; + private Side side = null; + + public Builder(String name) { + this.name = name; + } + + public Builder addMixinClasses(String... mixinClasses) { + this.mixinClasses.addAll(Arrays.asList(mixinClasses)); + return this; + } + + public Builder setPhase(Phase phase) { + if (this.phase != null) { + throw new RuntimeException("Trying to define Phase twice for " + this.name); + } + this.phase = phase; + return this; + } + + public Builder setSide(Side side) { + if (this.side != null) { + throw new RuntimeException("Trying to define Side twice for " + this.name); + } + this.side = side; + return this; + } + + public Builder setApplyIf(Supplier<Boolean> applyIf) { + this.applyIf = applyIf; + return this; + } + + public Builder addTargetedMod(TargetedMod mod) { + this.targetedMods.add(mod); + return this; + } + + public Builder addExcludedMod(TargetedMod mod) { + this.excludedMods.add(mod); + return this; + } } - enum Side { + private enum Side { BOTH, CLIENT, SERVER } + + private enum Phase { + EARLY, + LATE, + } } diff --git a/src/main/java/gregtech/mixin/MixinPlugin.java b/src/main/java/gregtech/mixin/MixinPlugin.java deleted file mode 100644 index 074eeb81aa..0000000000 --- a/src/main/java/gregtech/mixin/MixinPlugin.java +++ /dev/null @@ -1,113 +0,0 @@ -package gregtech.mixin; - -import static gregtech.mixin.TargetedMod.VANILLA; -import static java.nio.file.Files.walk; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import net.minecraft.launchwrapper.Launch; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.lib.tree.ClassNode; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; -import org.spongepowered.asm.mixin.extensibility.IMixinInfo; - -import com.gtnewhorizon.gtnhmixins.MinecraftURLClassPath; - -import kubatech.Tags; - -public class MixinPlugin implements IMixinConfigPlugin { - - private static final Logger LOG = LogManager.getLogger(Tags.MODID + " mixins"); - private static final Path MODS_DIRECTORY_PATH = new File(Launch.minecraftHome, "mods/").toPath(); - - @Override - public void onLoad(String mixinPackage) {} - - @Override - public String getRefMapperConfig() { - return null; - } - - @Override - public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - return false; - } - - @Override - public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {} - - @Override - public List<String> getMixins() { - final boolean isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); - - List<TargetedMod> loadedMods = Arrays.stream(TargetedMod.values()) - .filter(mod -> mod == VANILLA || (mod.loadInDevelopment && isDevelopmentEnvironment) || loadJarOf(mod)) - .collect(Collectors.toList()); - - for (TargetedMod mod : TargetedMod.values()) { - if (loadedMods.contains(mod)) { - LOG.info("Found " + mod.modName + "! Integrating now..."); - } else { - LOG.info("Could not find " + mod.modName + "! Skipping integration...."); - } - } - - List<String> mixins = new ArrayList<>(); - for (Mixin mixin : Mixin.values()) { - if (mixin.shouldLoad(loadedMods)) { - mixins.add(mixin.mixinClass); - LOG.debug("Loading mixin: " + mixin.mixinClass); - } - } - return mixins; - } - - private boolean loadJarOf(final TargetedMod mod) { - try { - File jar = findJarOf(mod); - if (jar == null) { - LOG.info("Jar not found for " + mod); - return false; - } - - LOG.info("Attempting to add " + jar + " to the URL Class Path"); - if (!jar.exists()) { - throw new FileNotFoundException(jar.toString()); - } - MinecraftURLClassPath.addJar(jar); - return true; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - public static File findJarOf(final TargetedMod mod) { - try (Stream<Path> stream = walk(MODS_DIRECTORY_PATH)) { - return stream.filter(mod::isMatchingJar) - .map(Path::toFile) - .findFirst() - .orElse(null); - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - @Override - public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} - - @Override - public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} -} diff --git a/src/main/java/gregtech/mixin/TargetedMod.java b/src/main/java/gregtech/mixin/TargetedMod.java index 0f402d1947..d8e1018f17 100644 --- a/src/main/java/gregtech/mixin/TargetedMod.java +++ b/src/main/java/gregtech/mixin/TargetedMod.java @@ -1,43 +1,75 @@ package gregtech.mixin; -import java.nio.file.Path; - -import com.google.common.io.Files; +import cpw.mods.fml.common.Mod; public enum TargetedMod { - VANILLA("Minecraft", "unused", true), - - ; + // NOTE: This doesn't work - late mods need a modid, not a coremod class + ADVANCED_SOLAR_PANELS("Advanced Solar Panels", null, "AdvancedSolarPanel"), + ANGELICA("Angelica", "com.gtnewhorizons.angelica.loading.AngelicaTweaker", "angelica"), + ARCHAICFIX("ArchaicFix", "org.embeddedt.archaicfix.ArchaicCore", "archaicfix"), + AUTOMAGY("Automagy", null, "Automagy"), + BAUBLES("Baubles", null, "Baubles"), + BETTERHUD("Better HUD", null, "hud"), + BIBLIOCRAFT("Bibliocraft", null, "BiblioCraft"), + BOP("BiomesOPlenty", null, "BiomesOPlenty"), + BUGTORCH("BugTorch", "jss.bugtorch.mixinplugin.BugTorchEarlyMixins", "bugtorch"), + BUKKIT("Bukkit/Thermos", "Bukkit", null), + COFH_CORE("CoFHCore", "cofh.asm.LoadingPlugin", "CoFHCore"), + DAMAGE_INDICATORS("Damage Indicators", null, "DamageIndicatorsMod"), + EXTRATIC("ExtraTiC", null, "ExtraTiC"), + EXTRA_UTILITIES("ExtraUtilities", null, "ExtraUtilities"), + FASTCRAFT("FastCraft", "fastcraft.Tweaker"), + GALACTICRAFT_CORE("GalacticraftCore", "micdoodle8.mods.galacticraft.core.asm.GCLoadingPlugin", "GalacticraftCore"), + GT5U("GregTech5u", null, "gregtech"), // Also matches GT6. + GT6("GregTech6", "gregtech.asm.GT_ASM", "gregapi"), // Can be used to exclude GT6 from the GT5U target. + GTNHLIB("GTNHLib", "com.gtnewhorizon.gtnhlib.core.GTNHLibCore", "gtnhlib"), + HARVESTCRAFT("harvestcraft", null, "harvestcraft"), + HARVESTTHENETHER("harvestthenether", null, "harvestthenether"), + HUNGER_OVERHAUL("HungerOverhaul", null, "HungerOverhaul"), + IC2("IC2", "ic2.core.coremod.IC2core", "IC2"), + IMMERSIVE_ENGINENEERING("Immersive Engineering", null, "ImmersiveEngineering"), + JOURNEYMAP("JourneyMap", null, "journeymap"), + LOTR("The Lord of the rings mod", "lotr.common.coremod.LOTRLoadingPlugin", "lotr"), + LWJGL3IFY("lwjgl3ify", "me.eigenraven.lwjgl3ify.core.Lwjgl3ifyCoremod", "lwjgl3ify"), + MINECHEM("Minechem", null, "minechem"), + MINEFACTORY_RELOADED("MineFactory Reloaded", null, "MineFactoryReloaded"), + MRTJPCORE("MrTJPCore", null, "MrTJPCoreMod"), + NOTENOUGHITEMS("NotEnoughItems", "codechicken.nei.asm.NEICorePlugin", "NotEnoughItems"), + OPTIFINE("Optifine", "optifine.OptiFineForgeTweaker", "Optifine"), + PORTAL_GUN("PortalGun", null, "PortalGun"), + PROJECTE("ProjectE", null, "ProjectE"), + RAILCRAFT("Railcraft", null, "Railcraft"), + THAUMCRAFT("Thaumcraft", null, "Thaumcraft"), // "thaumcraft.codechicken.core.launch.DepLoader" + THERMALDYNAMICS("Thermal Dynamics", null, "ThermalDynamics"), + THERMALEXPANSION("Thermal Expansion", null, "ThermalExpansion"), + TINKERSCONSTRUCT("TConstruct", null, "TConstruct"), + TRAVELLERSGEAR("TravellersGear", null, "TravellersGear"), + VANILLA("Minecraft", null), + VOXELMAP("VoxelMap", "com.thevoxelbox.voxelmap.litemod.VoxelMapTransformer", "voxelmap"), + WITCHERY("Witchery", null, "witchery"), + XAEROWORLDMAP("Xaero's World Map", null, "XaeroWorldMap"), + ZTONES("ZTones", null, "Ztones"); + /** The "name" in the {@link Mod @Mod} annotation */ public final String modName; - public final String jarNamePrefixLowercase; - public final boolean loadInDevelopment; + /** Class that implements the IFMLLoadingPlugin interface */ + public final String coreModClass; + /** The "modid" in the {@link Mod @Mod} annotation */ + public final String modId; - TargetedMod(String modName, String jarNamePrefix, boolean loadInDevelopment) { - this.modName = modName; - this.jarNamePrefixLowercase = jarNamePrefix.toLowerCase(); - this.loadInDevelopment = loadInDevelopment; + TargetedMod(String modName, String coreModClass) { + this(modName, coreModClass, null); } - @SuppressWarnings("UnstableApiUsage") - public boolean isMatchingJar(Path path) { - final String pathString = path.toString(); - final String nameLowerCase = Files.getNameWithoutExtension(pathString) - .toLowerCase(); - final String fileExtension = Files.getFileExtension(pathString); - - return nameLowerCase.startsWith(jarNamePrefixLowercase) && "jar".equals(fileExtension); + TargetedMod(String modName, String coreModClass, String modId) { + this.modName = modName; + this.coreModClass = coreModClass; + this.modId = modId; } @Override public String toString() { - return "TargetedMod{" + "modName='" - + modName - + '\'' - + ", jarNamePrefixLowercase='" - + jarNamePrefixLowercase - + '\'' - + '}'; + return "TargetedMod{modName='" + modName + "', coreModClass='" + coreModClass + "', modId='" + modId + "'}"; } } diff --git a/src/main/java/gregtech/mixin/mixins/early/minecraft/CraftingManagerMixin.java b/src/main/java/gregtech/mixin/mixins/early/minecraft/CraftingManagerMixin.java new file mode 100644 index 0000000000..1a88150128 --- /dev/null +++ b/src/main/java/gregtech/mixin/mixins/early/minecraft/CraftingManagerMixin.java @@ -0,0 +1,24 @@ +package gregtech.mixin.mixins.early.minecraft; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.world.World; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +import com.github.bartimaeusnek.bartworks.ASM.BWCoreStaticReplacementMethodes; + +@Mixin(CraftingManager.class) +public abstract class CraftingManagerMixin { + + /** + * @author bart + * @reason Cache the result of findMatchingRecipe + */ + @Overwrite + public ItemStack findMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { + return BWCoreStaticReplacementMethodes.findCachedMatchingRecipe(inventoryCrafting, world); + } +} diff --git a/src/main/java/gregtech/mixin/mixins/minecraft/LanguageRegistryMixin.java b/src/main/java/gregtech/mixin/mixins/early/minecraft/LanguageRegistryMixin.java index ee98a11f88..f6a0ebeaad 100644 --- a/src/main/java/gregtech/mixin/mixins/minecraft/LanguageRegistryMixin.java +++ b/src/main/java/gregtech/mixin/mixins/early/minecraft/LanguageRegistryMixin.java @@ -1,4 +1,4 @@ -package gregtech.mixin.mixins.minecraft; +package gregtech.mixin.mixins.early.minecraft; import static gregtech.mixin.MixinsVariablesHelper.currentlyTranslating; diff --git a/src/main/java/gregtech/mixin/mixins/minecraft/LocaleMixin.java b/src/main/java/gregtech/mixin/mixins/early/minecraft/LocaleMixin.java index 3a1864534a..e45548765c 100644 --- a/src/main/java/gregtech/mixin/mixins/minecraft/LocaleMixin.java +++ b/src/main/java/gregtech/mixin/mixins/early/minecraft/LocaleMixin.java @@ -1,4 +1,4 @@ -package gregtech.mixin.mixins.minecraft; +package gregtech.mixin.mixins.early.minecraft; import static gregtech.mixin.MixinsVariablesHelper.currentlyTranslating; diff --git a/src/main/java/gregtech/mixin/mixins/minecraft/StringTranslateMixin.java b/src/main/java/gregtech/mixin/mixins/early/minecraft/StringTranslateMixin.java index d9b80a0f52..5fb393def9 100644 --- a/src/main/java/gregtech/mixin/mixins/minecraft/StringTranslateMixin.java +++ b/src/main/java/gregtech/mixin/mixins/early/minecraft/StringTranslateMixin.java @@ -1,4 +1,4 @@ -package gregtech.mixin.mixins.minecraft; +package gregtech.mixin.mixins.early.minecraft; import static gregtech.mixin.MixinsVariablesHelper.currentlyTranslating; diff --git a/src/main/java/gregtech/mixin/mixins/minecraft/WorldMixin.java b/src/main/java/gregtech/mixin/mixins/early/minecraft/WorldMixin.java index 1d99287659..abdb61f55b 100644 --- a/src/main/java/gregtech/mixin/mixins/minecraft/WorldMixin.java +++ b/src/main/java/gregtech/mixin/mixins/early/minecraft/WorldMixin.java @@ -1,4 +1,4 @@ -package gregtech.mixin.mixins.minecraft; +package gregtech.mixin.mixins.early.minecraft; import net.minecraft.block.Block; import net.minecraft.world.World; diff --git a/src/main/java/gregtech/mixin/mixins/late/thaumcraft/TileWandPedestalMixin.java b/src/main/java/gregtech/mixin/mixins/late/thaumcraft/TileWandPedestalMixin.java new file mode 100644 index 0000000000..bfc79731e4 --- /dev/null +++ b/src/main/java/gregtech/mixin/mixins/late/thaumcraft/TileWandPedestalMixin.java @@ -0,0 +1,43 @@ +package gregtech.mixin.mixins.late.thaumcraft; + +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; + +import thaumcraft.api.TileThaumcraft; +import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.IAspectContainer; +import thaumcraft.common.items.baubles.ItemAmuletVis; +import thaumcraft.common.items.wands.ItemWandCasting; +import thaumcraft.common.tiles.TileWandPedestal; + +@Mixin(TileWandPedestal.class) +public abstract class TileWandPedestalMixin extends TileThaumcraft implements ISidedInventory, IAspectContainer { + + @WrapWithCondition( + method = "updateEntity", + at = @At( + value = "INVOKE", + target = "Lthaumcraft/common/items/wands/ItemWandCasting;addVis(Lnet/minecraft/item/ItemStack;Lthaumcraft/api/aspects/Aspect;IZ)I", + remap = false)) + boolean gregtech$checkWandServerWorld(ItemWandCasting instance, ItemStack is, Aspect aspect, int amount, + boolean doit) { + return !this.worldObj.isRemote; + } + + @WrapWithCondition( + method = "updateEntity", + at = @At( + value = "INVOKE", + target = "Lthaumcraft/common/items/baubles/ItemAmuletVis;addVis(Lnet/minecraft/item/ItemStack;Lthaumcraft/api/aspects/Aspect;IZ)I", + remap = false)) + boolean gregtech$checkAmuletServerWorld(ItemAmuletVis instance, ItemStack is, Aspect aspect, int amount, + boolean doit) { + return !this.worldObj.isRemote; + } + +} diff --git a/src/main/java/gregtech/mixin/mixins/late/xu/ChunkProviderEndOfTimeMixin.java b/src/main/java/gregtech/mixin/mixins/late/xu/ChunkProviderEndOfTimeMixin.java new file mode 100644 index 0000000000..2565e309f2 --- /dev/null +++ b/src/main/java/gregtech/mixin/mixins/late/xu/ChunkProviderEndOfTimeMixin.java @@ -0,0 +1,28 @@ +package gregtech.mixin.mixins.late.xu; + +import java.util.Collections; +import java.util.List; + +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.IChunkProvider; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +import com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime; + +@Mixin(ChunkProviderEndOfTime.class) +@SuppressWarnings("unused") +public abstract class ChunkProviderEndOfTimeMixin implements IChunkProvider { + + /** + * @author bart + * @reason Disable creature spawning in the Last Millenium entirely + */ + @Overwrite + public List<BiomeGenBase.SpawnListEntry> getPossibleCreatures(EnumCreatureType p_73155_1_, int p_73155_2_, + int p_73155_3_, int p_73155_4_) { + return Collections.emptyList(); + } +} diff --git a/src/main/java/gregtech/mixin/mixins/late/xu/WorldProviderEndOfTimeMixin.java b/src/main/java/gregtech/mixin/mixins/late/xu/WorldProviderEndOfTimeMixin.java new file mode 100644 index 0000000000..3a063dc283 --- /dev/null +++ b/src/main/java/gregtech/mixin/mixins/late/xu/WorldProviderEndOfTimeMixin.java @@ -0,0 +1,18 @@ +package gregtech.mixin.mixins.late.xu; + +import net.minecraft.world.WorldProvider; +import net.minecraft.world.chunk.Chunk; + +import org.spongepowered.asm.mixin.Mixin; + +import com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime; + +@Mixin(WorldProviderEndOfTime.class) +@SuppressWarnings("unused") +public abstract class WorldProviderEndOfTimeMixin extends WorldProvider { + + @Override + public boolean canDoRainSnowIce(Chunk chunk) { + return false; + } +} diff --git a/src/main/java/kubatech/loaders/MobHandlerLoader.java b/src/main/java/kubatech/loaders/MobHandlerLoader.java index 261cad087c..e9e0851f30 100644 --- a/src/main/java/kubatech/loaders/MobHandlerLoader.java +++ b/src/main/java/kubatech/loaders/MobHandlerLoader.java @@ -26,6 +26,7 @@ import static kubatech.tileentity.gregtech.multiblock.GT_MetaTileEntity_ExtremeE import static kubatech.tileentity.gregtech.multiblock.GT_MetaTileEntity_ExtremeEntityCrusher.MOB_SPAWN_INTERVAL; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -45,8 +46,6 @@ import net.minecraftforge.common.MinecraftForge; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.dreammaster.main.MainRegistry; -import com.dreammaster.modcustomdrops.CustomDrops; import com.kuba6000.mobsinfo.api.IChanceModifier; import com.kuba6000.mobsinfo.api.MobDrop; import com.kuba6000.mobsinfo.api.MobOverride; @@ -213,11 +212,13 @@ public class MobHandlerLoader { } @SubscribeEvent + @SuppressWarnings("unused") public void onPreMobsRegistration(PreMobsRegistrationEvent event) { recipeMap.clear(); } @SubscribeEvent + @SuppressWarnings("unused") public void onPostMobRegistration(PostMobRegistrationEvent event) { if (!event.drops.isEmpty() && event.recipe.isUsableInVial) { @SuppressWarnings("unchecked") @@ -229,24 +230,43 @@ public class MobHandlerLoader { } @SubscribeEvent - public void onPostOverridesConfigLoad(PostMobsOverridesLoadEvent event) { + @SuppressWarnings("unused") + public void onPostOverridesConfigLoad(PostMobsOverridesLoadEvent event) throws ReflectiveOperationException { if (NewHorizonsCoreMod.isModLoaded()) { LOG.info("Detected GTNH Core Mod, parsing custom drops from there."); - CustomDrops coredrops = ReflectionHelper.getField(MainRegistry.Module_CustomDrops, "_mCustomDrops", null); + final Class<?> cMainRegistry = Class.forName("com.dreammaster.main.MainRegistry"); + final Object dropsHandler = cMainRegistry.getField("Module_CustomDrops") + .get(null); + final Class<?> cDrops = Class.forName("com.dreammaster.modcustomdrops.CustomDrops"); + final Object coredrops = ReflectionHelper.getField(dropsHandler, "_mCustomDrops", null); + final Method mGetCustomDrops = cDrops.getMethod("getCustomDrops"); + + final Class<?> cCustomDrop = Class.forName("com.dreammaster.modcustomdrops.CustomDrops$CustomDrop"); + final Method mGetCustomDropEntityName = cCustomDrop.getMethod("getEntityName"); + final Method mGetCustomDropDrops = cCustomDrop.getMethod("getDrops"); + + final Class<?> cDrop = Class.forName("com.dreammaster.modcustomdrops.CustomDrops$CustomDrop$Drop"); + final Method mDropGetItemName = cDrop.getMethod("getItemName"); + final Method mDropGetChance = cDrop.getMethod("getChance"); + final Method mDropGetAmount = cDrop.getMethod("getAmount"); + final Method mDropGetIsRandomAmount = cDrop.getMethod("getIsRandomAmount"); + if (coredrops != null) { - @SuppressWarnings("unchecked") - ArrayList<CustomDrops.CustomDrop> customdrops = (ArrayList<CustomDrops.CustomDrop>) ((ArrayList<CustomDrops.CustomDrop>) coredrops - .getCustomDrops()).clone(); - for (CustomDrops.CustomDrop customdrop : customdrops) { + final ArrayList<?> customDrops = new ArrayList<>((ArrayList<?>) mGetCustomDrops.invoke(coredrops)); + for (final Object customDrop : customDrops) { try { - Class<?> eclass = Class.forName(customdrop.getEntityName()); + final String entityName = (String) mGetCustomDropEntityName.invoke(customDrop); + + final Class<?> eclass = Class.forName(entityName); if (!EntityLiving.class.isAssignableFrom(eclass)) continue; - String ename = (String) EntityList.classToStringMapping.get(eclass); + final String ename = EntityList.classToStringMapping.get(eclass); if (ename == null) continue; - MobOverride override = event.overrides.computeIfAbsent(ename, k -> new MobOverride()); - for (CustomDrops.CustomDrop.Drop drop : customdrop.getDrops()) { - String[] parts = drop.getItemName() - .split(":"); + final MobOverride override = event.overrides.computeIfAbsent(ename, k -> new MobOverride()); + final List<?> entityDrops = (List<?>) mGetCustomDropDrops.invoke(customDrop); + + for (final Object drop : entityDrops) { + final String itemName = (String) mDropGetItemName.invoke(drop); + String[] parts = itemName.split(":"); ItemStack stack = GameRegistry.findItemStack(parts[0], parts[1], 1); if (stack == null) continue; if (parts.length > 2) stack.setItemDamage(Integer.parseInt(parts[2])); @@ -256,9 +276,9 @@ public class MobHandlerLoader { stack.stackTagCompound = (NBTTagCompound) JsonToNBT.func_150315_a(pNBT); } catch (Exception ignored) {} } - int chance = drop.getChance() * 100; - int amount = drop.getAmount(); - if (drop.getIsRandomAmount()) { + int chance = ((int) mDropGetChance.invoke(drop)) * 100; + int amount = (int) mDropGetAmount.invoke(drop); + if ((boolean) mDropGetIsRandomAmount.invoke(drop)) { // average chance formula // chance *= ((((amount * (amount + 1d)) / 2d)) + 1d) / (amount + 1d); chance *= (2d + (amount * amount) + amount) / (2d * (amount + 1d)); @@ -295,6 +315,7 @@ public class MobHandlerLoader { } @SubscribeEvent + @SuppressWarnings("unused") public void onMobNEIRegistration(MobNEIRegistrationEvent event) { MobEECRecipe recipe = recipeMap.get(event.mobName); if (recipe != null) { |