From dd461d8b6b5a48cfcde45d021c4dfb49d9357958 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Sat, 13 Jan 2024 18:39:04 +0100 Subject: [PATCH] Fix BTW patch crashing with StAPI --- .../apron/compat/MixinCompatPlugin.java | 40 ++----------------- .../betterthanwolves/FireBlockMixin.java | 19 ++------- .../nostation/FireBlockMixin.java | 19 +++++++++ .../main/resources/apron-compat.mixins.json | 1 + 4 files changed, 28 insertions(+), 51 deletions(-) create mode 100644 apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/nostation/FireBlockMixin.java diff --git a/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/MixinCompatPlugin.java b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/MixinCompatPlugin.java index a992a527..351aad86 100644 --- a/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/MixinCompatPlugin.java +++ b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/MixinCompatPlugin.java @@ -1,7 +1,7 @@ package io.github.betterthanupdates.apron.compat; -import com.llamalad7.mixinextras.MixinExtrasBootstrap; import fr.catcore.modremapperapi.utils.MixinUtils; +import io.github.betterthanupdates.apron.ApronMixinPlugin; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; @@ -11,7 +11,7 @@ import java.util.Map; import java.util.Set; -public class MixinCompatPlugin implements IMixinConfigPlugin { +public class MixinCompatPlugin extends ApronMixinPlugin { private static final Map COMPAT = new HashMap<>(); public MixinCompatPlugin() { @@ -30,24 +30,12 @@ public MixinCompatPlugin() { COMPAT.put(".somnia.", "net.minecraft.mod_Somnia"); COMPAT.put(".betterblocks.", "net.minecraft.mod_BetterBlocks"); COMPAT.put(".incrediblefungus.", "net.minecraft.mod_Fungus"); -// COMPAT.put(".aei.", "net.minecraft.mod_AEI"); -// COMPAT.put(".concrete.", "net.minecraft.mod_Concrete"); -// COMPAT.put(".spawneggs.", "net.minecraft.mod_spawnEggs"); - } - - @Override - public void onLoad(String mixinPackage) { - } - - @Override - public String getRefMapperConfig() { - return null; } @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { for (Map.Entry entry : COMPAT.entrySet()) { - if (mixinClassName.contains(entry.getKey())) { + if (mixinClassName.contains(entry.getKey()) && super.shouldApplyMixin(targetClassName, mixinClassName)) { try { Class.forName(entry.getValue(), false, getClass().getClassLoader()); return true; @@ -57,26 +45,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { } } - return true; - } - - @Override - public void acceptTargets(Set myTargets, Set otherTargets) { - - } - - @Override - public List getMixins() { - 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) { - MixinUtils.applyASMMagic(targetClassName, targetClass, mixinClassName, mixinInfo); + return super.shouldApplyMixin(targetClassName, mixinClassName); } } diff --git a/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/FireBlockMixin.java b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/FireBlockMixin.java index 0259c03f..9f2c75bc 100644 --- a/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/FireBlockMixin.java +++ b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/FireBlockMixin.java @@ -3,6 +3,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; import net.minecraft.FCBlockBBQ; import net.minecraft.block.Block; import net.minecraft.block.FireBlock; @@ -13,9 +14,7 @@ import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; @@ -24,31 +23,21 @@ @Mixin(FireBlock.class) public class FireBlockMixin implements BTWFireBlock { - @ModifyConstant(method = "", constant = @Constant(intValue = 256, ordinal = 0)) - private int btw$changeTo1024_1(int constant) { - return 1024; - } - - @ModifyConstant(method = "", constant = @Constant(intValue = 256, ordinal = 1)) - private int btw$changeTo1024_2(int constant) { - return 1024; - } - @ModifyReturnValue(method = "getRenderType", at = @At("RETURN")) private int btw$getRenderType(int original) { return mod_FCBetterThanWolves.iCustomFireRenderID; } @Inject(method = "onScheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;canPlaceAt(Lnet/minecraft/world/World;III)Z", shift = At.Shift.BY, by = 3), cancellable = true) - private void addBTWFireCheck(World arg, int i, int j, int k, Random random, CallbackInfo callbackInfo, @Local(ordinal = 3) int var6) { + private void addBTWFireCheck(World arg, int i, int j, int k, Random random, CallbackInfo callbackInfo, @Local(ordinal = 3) LocalIntRef var6) { if(arg.getBlockId(i, j - 1, k) == mod_FCBetterThanWolves.fcBBQ.id) { if(!((FCBlockBBQ)mod_FCBetterThanWolves.fcBBQ).IsBBQLit(arg, i, j - 1, k)) { arg.setBlock(i, j, k, 0); callbackInfo.cancel(); } - var6 = 1; + var6.set(1); } else if(arg.getBlockId(i, j - 1, k) == mod_FCBetterThanWolves.fcStokedFire.id) { - var6 = 1; + var6.set(1); } } diff --git a/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/nostation/FireBlockMixin.java b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/nostation/FireBlockMixin.java new file mode 100644 index 00000000..eb2cbd5f --- /dev/null +++ b/apron-compat/src/main/java/io/github/betterthanupdates/apron/compat/mixin/client/betterthanwolves/nostation/FireBlockMixin.java @@ -0,0 +1,19 @@ +package io.github.betterthanupdates.apron.compat.mixin.client.betterthanwolves.nostation; + +import net.minecraft.block.FireBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Mixin(FireBlock.class) +public class FireBlockMixin { + @ModifyConstant(method = "", constant = @Constant(intValue = 256, ordinal = 0)) + private int btw$changeTo1024_1(int constant) { + return 1024; + } + + @ModifyConstant(method = "", constant = @Constant(intValue = 256, ordinal = 1)) + private int btw$changeTo1024_2(int constant) { + return 1024; + } +} diff --git a/apron-compat/src/main/resources/apron-compat.mixins.json b/apron-compat/src/main/resources/apron-compat.mixins.json index 53ad9c97..2c9d27e4 100644 --- a/apron-compat/src/main/resources/apron-compat.mixins.json +++ b/apron-compat/src/main/resources/apron-compat.mixins.json @@ -39,6 +39,7 @@ "client.betterthanwolves.SugarCaneBlockMixin", "client.betterthanwolves.TallGrassBlockMixin", "client.betterthanwolves.WolfEntityMixin", + "client.betterthanwolves.nostation.FireBlockMixin", "client.concrete.ConcreteMixin", "client.eqex.BlockAggregatorMixin", "client.eqex.BlockAlchestMixin",