Skip to content

Commit

Permalink
Fix BTW patch crashing with StAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Jan 13, 2024
1 parent ca8043b commit dd461d8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String, String> COMPAT = new HashMap<>();

public MixinCompatPlugin() {
Expand All @@ -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<String, String> 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;
Expand All @@ -57,26 +45,6 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
}
}

return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -24,31 +23,21 @@

@Mixin(FireBlock.class)
public class FireBlockMixin implements BTWFireBlock {
@ModifyConstant(method = "<init>", constant = @Constant(intValue = 256, ordinal = 0))
private int btw$changeTo1024_1(int constant) {
return 1024;
}

@ModifyConstant(method = "<init>", 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "<init>", constant = @Constant(intValue = 256, ordinal = 0))
private int btw$changeTo1024_1(int constant) {
return 1024;
}

@ModifyConstant(method = "<init>", constant = @Constant(intValue = 256, ordinal = 1))
private int btw$changeTo1024_2(int constant) {
return 1024;
}
}
1 change: 1 addition & 0 deletions apron-compat/src/main/resources/apron-compat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dd461d8

Please sign in to comment.