diff --git a/dependencies.gradle b/dependencies.gradle index afbc494..ea1f482 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,5 +1,9 @@ // Add your dependencies here dependencies { - + compileOnly("com.github.GTNewHorizons:GT5-Unofficial:experimental-SNAPSHOT:dev") { + // Only get GT5U and not its dependencies, since it won't be run in dev. It is an optional dependency + transitive = false + setChanging(true) + } } diff --git a/repositories.gradle b/repositories.gradle index f7d641b..7d02b58 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -1,5 +1,7 @@ // Add any additional repositiroes for your dependencies here repositories { - + maven { + url = "https://jitpack.io" + } } diff --git a/src/main/java/com/myname/mymodid/Tags.java b/src/main/java/com/myname/mymodid/Tags.java index 9aede58..568778f 100644 --- a/src/main/java/com/myname/mymodid/Tags.java +++ b/src/main/java/com/myname/mymodid/Tags.java @@ -1,5 +1,7 @@ package com.myname.mymodid; +// Use this class for Strings only. Do not import any classes here. It will lead to issues with Mixins if in use! + public class Tags { // GRADLETOKEN_* will be replaced by your configuration values at build time diff --git a/src/main/java/com/myname/mymodid/mixinplugin/Mixin.java b/src/main/java/com/myname/mymodid/mixinplugin/Mixin.java new file mode 100644 index 0000000..a5fa833 --- /dev/null +++ b/src/main/java/com/myname/mymodid/mixinplugin/Mixin.java @@ -0,0 +1,27 @@ +package com.myname.mymodid.mixinplugin; + +import static com.myname.mymodid.mixinplugin.TargetedMod.*; + +public enum Mixin { + + // + // IMPORTANT: Do not make any references to any mod from this file. This file is loaded quite early on and if + // you refer to other mods you load them as well. The consequence is: You can't inject any previously loaded classes! + // Exception: Tags.java, as long as it is used for Strings only! + // + + // Replace with your own mixins: + ItemEditableBookMixin("minecraft.ItemEditableBookMixin", VANILLA, false), + GT_Block_Ores_AbstractMixin("gregtech.GT_Block_Ores_AbstractMixin", GREGTECH, false); + + public final String mixinClass; + public final TargetedMod targetedMod; + // Injecting into GUI classes will crash the server. Flag them as clientSideOnly! + public final boolean clientSideOnly; + + Mixin(String mixinClass, TargetedMod targetedMod, boolean clientSideOnly) { + this.mixinClass = mixinClass; + this.targetedMod = targetedMod; + this.clientSideOnly = clientSideOnly; + } +} diff --git a/src/main/java/com/myname/mymodid/mixinplugin/MixinPlugin.java b/src/main/java/com/myname/mymodid/mixinplugin/MixinPlugin.java index 3581dc9..115f2d8 100644 --- a/src/main/java/com/myname/mymodid/mixinplugin/MixinPlugin.java +++ b/src/main/java/com/myname/mymodid/mixinplugin/MixinPlugin.java @@ -18,7 +18,7 @@ import java.util.Set; public class MixinPlugin implements IMixinConfigPlugin { - private static Logger LOG = LogManager.getLogger(Tags.MODID); + private static Logger LOG = LogManager.getLogger(Tags.MODID + " mixins"); @Override public void onLoad(String mixinPackage) { @@ -46,27 +46,23 @@ public class MixinPlugin implements IMixinConfigPlugin { final boolean loadClientSideOnlyClasses = FMLLaunchHandler.side().isClient(); final boolean isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"); - // - // IMPORTANT: Do not make any references to any mod from this file. This file is loaded quite early on and if - // you refer to other mods you load them as well. The consequence is: You can't inject any previously loaded classes! - // - List mixins = new ArrayList<>(); - // We may add vanilla mixins at all times. Vanilla Minecraft is guaranteed to be on the class path - mixins.add("minecraft.ItemEditableBookMixin"); - - // If we inject into another mod we need to ensure it is available on the classpath. Some mods are, some are not. - // loadJar() will ensure it is available and return false if a mod is not installed. - - // Additionally, we don't have the other mod in /mods during development runs. If you want a mixin to be applied - // at development you should allow its addition with an additional check to isDevelopmentEnvironment. If your - // dependency is optional, eg added as compileOnly dependency, you must skip the test against isDevelopmentEnvironment! - if(isDevelopmentEnvironment || loadJar("gregtech")) { - LOG.info("Found GregTech! Integrating now..."); - //mixins.add("gregtech.SOMEGTMIXINEXAMPLE"); - } - else { - LOG.info("Could not find GregTech! Skipping integration...."); + for (TargetedMod targetedMod : TargetedMod.values()) { + if (targetedMod == TargetedMod.VANILLA + || (targetedMod.loadInDevelopment && isDevelopmentEnvironment) + || loadJar(targetedMod.jarNameBeginsWith)) { + LOG.info("Found " + targetedMod.modName + "! Integrating now..."); + for (Mixin mixin : Mixin.values()) { + if (mixin.targetedMod == targetedMod + && (mixin.clientSideOnly == false || loadClientSideOnlyClasses)) { + mixins.add(mixin.mixinClass); + LOG.debug("Loading mixin: " + mixin.mixinClass); + } + } + } + else { + LOG.info("Could not find " + targetedMod.modName + "! Skipping integration...."); + } } return mixins; @@ -80,7 +76,7 @@ public class MixinPlugin implements IMixinConfigPlugin { return false; } - LOG.info("Attempting to add " + jar.toString() + " to the URL Class Path"); + LOG.info("Attempting to add " + jar + " to the URL Class Path"); if(!jar.exists()) { throw new FileNotFoundException(jar.toString()); } diff --git a/src/main/java/com/myname/mymodid/mixinplugin/TargetedMod.java b/src/main/java/com/myname/mymodid/mixinplugin/TargetedMod.java new file mode 100644 index 0000000..3a6304a --- /dev/null +++ b/src/main/java/com/myname/mymodid/mixinplugin/TargetedMod.java @@ -0,0 +1,25 @@ +package com.myname.mymodid.mixinplugin; + +public enum TargetedMod { + + // + // IMPORTANT: Do not make any references to any mod from this file. This file is loaded quite early on and if + // you refer to other mods you load them as well. The consequence is: You can't inject any previously loaded classes! + // Exception: Tags.java, as long as it is used for Strings only! + // + + // Replace with your injected mods here, but always keep VANILLA: + VANILLA("Minecraft", "unused", true), + GREGTECH("GregTech", "gregtech", false); + + public final String modName; + public final String jarNameBeginsWith; + // Optional dependencies can be omitted in development. Especially skipping GT5U will drastically speed up your game start! + public final boolean loadInDevelopment; + + TargetedMod(String modName, String jarNameBeginsWith, boolean loadInDevelopment) { + this.modName = modName; + this.jarNameBeginsWith = jarNameBeginsWith; + this.loadInDevelopment = loadInDevelopment; + } +} diff --git a/src/main/java/com/myname/mymodid/mixins/gregtech/GT_Block_Ores_AbstractMixin.java b/src/main/java/com/myname/mymodid/mixins/gregtech/GT_Block_Ores_AbstractMixin.java new file mode 100644 index 0000000..c480f8c --- /dev/null +++ b/src/main/java/com/myname/mymodid/mixins/gregtech/GT_Block_Ores_AbstractMixin.java @@ -0,0 +1,28 @@ +package com.myname.mymodid.mixins.gregtech; + +import com.myname.mymodid.MyMod; +import gregtech.api.items.GT_Generic_Block; +import gregtech.common.blocks.GT_Block_Ores_Abstract; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(value = GT_Block_Ores_Abstract.class, remap = false) +public class GT_Block_Ores_AbstractMixin extends GT_Generic_Block { + + protected GT_Block_Ores_AbstractMixin() { + super(null, null, null); + } + + @Override + public boolean onBlockActivated(World world, int blockX, int blockY, int blockZ, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ) { + MyMod.info("You touched a GT Ore!"); + return super.onBlockActivated(world, blockX, blockY, blockZ, player, side, offsetX, offsetY, offsetZ); + } + + @Override + public void onBlockClicked(World world, int blockX, int blockY, int blockZ, EntityPlayer player) { + MyMod.info("You touched a GT Ore!"); + super.onBlockClicked(world, blockX, blockY, blockZ, player); + } +}