Remove mixin example

This commit is contained in:
Johann Bernhardt committed 2021-11-07 01:14:57 +01:00
1 parent 2031cb38dc
commit 6f78d5a347
8 files changed
+5 -221

No files matched your search

@@ -1,28 +0,0 @@
package com.myname.mymodid.mixinplugin;
import java.util.Arrays;
import java.util.List;
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),
// You may also require multiple mods to be loaded if your mixin requires both
GT_Block_Ores_AbstractMixin("gregtech.GT_Block_Ores_AbstractMixin", GREGTECH, VANILLA);
public final String mixinClass;
public final List<TargetedMod> targetedMods;
Mixin(String mixinClass, TargetedMod... targetedMods) {
this.mixinClass = mixinClass;
this.targetedMods = Arrays.asList(targetedMods);
}
}
@@ -1,105 +0,0 @@
package com.myname.mymodid.mixinplugin;
import com.myname.mymodid.Tags;
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 ru.timeconqueror.spongemixins.MinecraftURLClassPath;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.myname.mymodid.mixinplugin.TargetedMod.VANILLA;
public class MixinPlugin implements IMixinConfigPlugin {
private static final Logger LOG = LogManager.getLogger(Tags.MODID + " mixins");
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
// This method return a List<String> of mixins. Every mixins in this list will be loaded.
@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)
|| loadJar(mod.jarNameBeginsWith))
.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 (loadedMods.containsAll(mixin.targetedMods)) {
mixins.add(mixin.mixinClass);
LOG.debug("Loading mixin: " + mixin.mixinClass);
}
}
return mixins;
}
private boolean loadJar(final String jarNameBeginsWith) {
try {
File jar = MinecraftURLClassPath.getJarInModPath(jarNameBeginsWith);
if(jar == null) {
LOG.info("Jar not found: " + jarNameBeginsWith);
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;
}
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
@@ -1,25 +0,0 @@
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;
}
}
@@ -1,28 +0,0 @@
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);
}
}
@@ -1,24 +0,0 @@
package com.myname.mymodid.mixins.minecraft;
import com.myname.mymodid.MyMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemEditableBook;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(value = ItemEditableBook.class)
public class ItemEditableBookMixin {
@Inject(method = "onItemRightClick",
at = @At("HEAD"),
require = 1,
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer, CallbackInfoReturnable<ItemStack> callbackInfoReturnable) {
MyMod.info("You are reading a book");
}
}