Fix existing transformers
This commit is contained in:
		
							parent
							
								
									6ddfa10903
								
							
						
					
					
						commit
						cad7263d9e
					
				
					 5 changed files with 85 additions and 124 deletions
				
			
		| 
						 | 
				
			
			@ -48,7 +48,8 @@ dependencies {
 | 
			
		|||
 | 
			
		||||
	modImplementation libs.quilted.fabric.api
 | 
			
		||||
 | 
			
		||||
	modApi include("dev.emi:trinkets:${libs.versions.trinkets.get()}")
 | 
			
		||||
	// not JiJ because it causes its mixins to fail to load
 | 
			
		||||
	modApi "dev.emi:trinkets:${libs.versions.trinkets.get()}"
 | 
			
		||||
	modApi include("com.unascribed:lib39-core:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
 | 
			
		||||
	modApi include("com.unascribed:lib39-dessicant:${libs.versions.lib39.get()}+${libs.versions.minecraft.get()}")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,9 +14,8 @@ public class ItemStackMixin {
 | 
			
		|||
    // Excluding ourselves from this check to force unequip/equip when switching bag items fixes a duplication bug
 | 
			
		||||
    // Gross and hacky but oh well, can't mixin mixins.
 | 
			
		||||
    @Inject(method = "areEqual", at = @At("HEAD"), cancellable = true)
 | 
			
		||||
    private void scout$grossTrinketsEquipFix(ItemStack newStack, CallbackInfoReturnable<Boolean> callbackInfo) {
 | 
			
		||||
        ItemStack self = (ItemStack) (Object) this;
 | 
			
		||||
        if (self.getItem() instanceof BaseBagItem && newStack.getItem() instanceof BaseBagItem) {
 | 
			
		||||
    private static void scout$grossTrinketsEquipFix(ItemStack stack, ItemStack otherStack, CallbackInfoReturnable<Boolean> callbackInfo) {
 | 
			
		||||
        if (stack.getItem() instanceof BaseBagItem && otherStack.getItem() instanceof BaseBagItem) {
 | 
			
		||||
            callbackInfo.setReturnValue(false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@ package pm.c7.scout.mixin;
 | 
			
		|||
 | 
			
		||||
import org.objectweb.asm.tree.*;
 | 
			
		||||
import org.quiltmc.loader.api.QuiltLoader;
 | 
			
		||||
 | 
			
		||||
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
 | 
			
		||||
 | 
			
		||||
import static org.objectweb.asm.Opcodes.*;
 | 
			
		||||
| 
						 | 
				
			
			@ -9,31 +10,22 @@ import static org.objectweb.asm.Opcodes.*;
 | 
			
		|||
public class ScreenHandlerTransformer implements ClassNodeTransformer {
 | 
			
		||||
	@Override
 | 
			
		||||
	public void transform(String name, ClassNode node) {
 | 
			
		||||
		var internalOnSlotClick = "m_nqfgpzfl";
 | 
			
		||||
		var insertItem = "m_jpjdgbxy";
 | 
			
		||||
		var resolver = QuiltLoader.getMappingResolver();
 | 
			
		||||
		var namespace = "intermediary";
 | 
			
		||||
 | 
			
		||||
		var PlayerEntity = "net/minecraft/unmapped/C_jzrpycqo";
 | 
			
		||||
		var playerScreenHandler = "f_xvlfpipb";
 | 
			
		||||
 | 
			
		||||
		var PlayerScreenHandler = "net/minecraft/unmapped/C_wgehrbdx";
 | 
			
		||||
		var Slot = "net/minecraft/unmapped/C_nhvqfffd";
 | 
			
		||||
		var DefaultedList = "net/minecraft/unmapped/C_rnrfftze";
 | 
			
		||||
 | 
			
		||||
		if (QuiltLoader.isDevelopmentEnvironment()) {
 | 
			
		||||
			internalOnSlotClick = "internalOnSlotClick";
 | 
			
		||||
			insertItem = "insertItem";
 | 
			
		||||
 | 
			
		||||
			PlayerEntity = "net/minecraft/entity/player/PlayerEntity";
 | 
			
		||||
			playerScreenHandler = "playerScreenHandler";
 | 
			
		||||
 | 
			
		||||
			PlayerScreenHandler = "net/minecraft/screen/PlayerScreenHandler";
 | 
			
		||||
			Slot = "net/minecraft/screen/slot/Slot";
 | 
			
		||||
			DefaultedList = "net/minecraft/util/collection/DefaultedList";
 | 
			
		||||
		}
 | 
			
		||||
		var internalOnSlotClick = resolver.mapMethodName(namespace, name, "method_30010", "(IILnet/minecraft/class_1713;Lnet/minecraft/class_1657;)V");
 | 
			
		||||
 | 
			
		||||
		var PlayerEntity = resolver.mapClassName(namespace, "net.minecraft.class_1657");
 | 
			
		||||
		var PlayerScreenHandler = slash(resolver.mapClassName(namespace, "net.minecraft.class_1723"));
 | 
			
		||||
		var LPlayerScreenHandler = L(PlayerScreenHandler);
 | 
			
		||||
		String playerScreenHandler = resolver.mapFieldName(namespace, PlayerEntity, "field_7498", LPlayerScreenHandler);
 | 
			
		||||
		PlayerEntity = slash(PlayerEntity);
 | 
			
		||||
 | 
			
		||||
		var Slot = slash(resolver.mapClassName(namespace, "net.minecraft.class_1735"));
 | 
			
		||||
		var LSlot = L(Slot);
 | 
			
		||||
 | 
			
		||||
		var DefaultedList = slash(resolver.mapClassName(namespace, "net.minecraft.class_2371"));
 | 
			
		||||
 | 
			
		||||
		for (var mn : node.methods) {
 | 
			
		||||
			if (mn.name.equals(internalOnSlotClick)) {
 | 
			
		||||
				for (var insn : mn.instructions) {
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +39,7 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
 | 
			
		|||
									IFNE(jumpTo)
 | 
			
		||||
								));
 | 
			
		||||
							}
 | 
			
		||||
						} else if (vin.getOpcode() == ASTORE && (vin.var == 6 || vin.var == 7)) {
 | 
			
		||||
						} else if (vin.getOpcode() == ASTORE && vin.var == 7) {
 | 
			
		||||
							if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
 | 
			
		||||
								if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
 | 
			
		||||
									if(prevPrevInsn.owner.equals(DefaultedList)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -75,42 +67,12 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
 | 
			
		|||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}/* else if (mn.name.equals(insertItem)) {
 | 
			
		||||
				for (var insn : mn.instructions) {
 | 
			
		||||
					if (insn instanceof VarInsnNode vin && vin.getOpcode() == ASTORE && vin.var == 7) {
 | 
			
		||||
						if (vin.getPrevious() instanceof TypeInsnNode prevInsn && prevInsn.getOpcode() == CHECKCAST && prevInsn.desc.equals(Slot)) {
 | 
			
		||||
							if (prevInsn.getPrevious() instanceof MethodInsnNode prevPrevInsn && prevPrevInsn.getOpcode() == INVOKEVIRTUAL) {
 | 
			
		||||
								if(prevPrevInsn.owner.equals(DefaultedList)) {
 | 
			
		||||
									LabelNode LnotBag = new LabelNode();
 | 
			
		||||
									LabelNode LpastSlot = new LabelNode();
 | 
			
		||||
									mn.instructions.insertBefore(prevPrevInsn.getPrevious().getPrevious().getPrevious(), insns(
 | 
			
		||||
											INVOKESTATIC("pm/c7/scout/ScoutUtil", "getPlayerScreenHandler", "()" + LPlayerScreenHandler),
 | 
			
		||||
											ASTORE(20),
 | 
			
		||||
											ALOAD(20),
 | 
			
		||||
											IFNULL(LpastSlot),
 | 
			
		||||
											ILOAD(6),
 | 
			
		||||
											INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
 | 
			
		||||
											IFEQ(LnotBag),
 | 
			
		||||
											ILOAD(6),
 | 
			
		||||
											ALOAD(20),
 | 
			
		||||
											INVOKESTATIC("pm/c7/scout/ScoutUtil", "getBagSlot", "(I" + LPlayerScreenHandler + ")" + LSlot),
 | 
			
		||||
											CHECKCAST(Slot),
 | 
			
		||||
											ASTORE(vin.var),
 | 
			
		||||
											LnotBag,
 | 
			
		||||
											ILOAD(6),
 | 
			
		||||
											INVOKESTATIC("pm/c7/scout/ScoutUtil", "isBagSlot", "(I)Z"),
 | 
			
		||||
											IFNE(LpastSlot)
 | 
			
		||||
									));
 | 
			
		||||
									mn.instructions.insert(vin, insns(
 | 
			
		||||
											LpastSlot
 | 
			
		||||
									));
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}*/
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	private String slash(String clazz) {
 | 
			
		||||
		return clazz.replaceAll("\\.", "/");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private String L(String clazz) {
 | 
			
		||||
| 
						 | 
				
			
			@ -122,34 +84,34 @@ public class ScreenHandlerTransformer implements ClassNodeTransformer {
 | 
			
		|||
		for (var i : insns) li.add(i);
 | 
			
		||||
		return li;
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ILOAD(int var) {
 | 
			
		||||
		return new VarInsnNode(ILOAD, var);
 | 
			
		||||
	private static VarInsnNode ILOAD(int v) {
 | 
			
		||||
		return new VarInsnNode(ILOAD, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static MethodInsnNode INVOKESTATIC(String owner, String name, String desc) {
 | 
			
		||||
		return new MethodInsnNode(INVOKESTATIC, owner, name, desc);
 | 
			
		||||
	}
 | 
			
		||||
	private static JumpInsnNode IFNE(LabelNode var) {
 | 
			
		||||
		return new JumpInsnNode(IFNE, var);
 | 
			
		||||
	private static JumpInsnNode IFNE(LabelNode v) {
 | 
			
		||||
		return new JumpInsnNode(IFNE, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static JumpInsnNode IFEQ(LabelNode var) {
 | 
			
		||||
		return new JumpInsnNode(IFEQ, var);
 | 
			
		||||
	private static JumpInsnNode IFEQ(LabelNode v) {
 | 
			
		||||
		return new JumpInsnNode(IFEQ, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ALOAD(int var) {
 | 
			
		||||
		return new VarInsnNode(ALOAD, var);
 | 
			
		||||
	private static VarInsnNode ALOAD(int v) {
 | 
			
		||||
		return new VarInsnNode(ALOAD, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ASTORE(int var) {
 | 
			
		||||
		return new VarInsnNode(ASTORE, var);
 | 
			
		||||
	private static VarInsnNode ASTORE(int v) {
 | 
			
		||||
		return new VarInsnNode(ASTORE, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static FieldInsnNode GETFIELD(String owner, String name, String desc) {
 | 
			
		||||
		return new FieldInsnNode(GETFIELD, owner, name, desc);
 | 
			
		||||
	}
 | 
			
		||||
	private static JumpInsnNode IFNULL(LabelNode var) {
 | 
			
		||||
		return new JumpInsnNode(IFNULL, var);
 | 
			
		||||
	private static JumpInsnNode IFNULL(LabelNode v) {
 | 
			
		||||
		return new JumpInsnNode(IFNULL, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static TypeInsnNode CHECKCAST(String desc) {
 | 
			
		||||
		return new TypeInsnNode(CHECKCAST, desc);
 | 
			
		||||
	}
 | 
			
		||||
	private static JumpInsnNode GOTO(LabelNode var) {
 | 
			
		||||
		return new JumpInsnNode(GOTO, var);
 | 
			
		||||
	private static JumpInsnNode GOTO(LabelNode v) {
 | 
			
		||||
		return new JumpInsnNode(GOTO, v);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,6 @@ package pm.c7.scout.mixin.client;
 | 
			
		|||
import com.mojang.blaze3d.systems.RenderSystem;
 | 
			
		||||
import net.fabricmc.api.EnvType;
 | 
			
		||||
import net.fabricmc.api.Environment;
 | 
			
		||||
import net.minecraft.client.MinecraftClient;
 | 
			
		||||
import net.minecraft.client.gui.GuiGraphics;
 | 
			
		||||
import net.minecraft.client.gui.screen.Screen;
 | 
			
		||||
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,7 +45,7 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
 | 
			
		|||
	@Shadow
 | 
			
		||||
	protected int backgroundHeight;
 | 
			
		||||
 | 
			
		||||
	@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/util/math/MatrixStack;FII)V"))
 | 
			
		||||
	@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawBackground(Lnet/minecraft/client/gui/GuiGraphics;FII)V"))
 | 
			
		||||
	private void scout$drawSatchelRow(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
 | 
			
		||||
		if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
 | 
			
		||||
			ItemStack backStack = ScoutUtil.findBagItem(this.client.player, BaseBagItem.BagType.SATCHEL, false);
 | 
			
		||||
| 
						 | 
				
			
			@ -272,7 +271,7 @@ public abstract class HandledScreenMixin<T extends ScreenHandler> extends Screen
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/util/math/MatrixStack;II)V"))
 | 
			
		||||
	@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;drawForeground(Lnet/minecraft/client/gui/GuiGraphics;II)V"))
 | 
			
		||||
	public void scout$drawOurSlots(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo ci) {
 | 
			
		||||
		if (this.client != null && this.client.player != null && !ScoutUtil.isScreenBlacklisted(this)) {
 | 
			
		||||
			for (int i = ScoutUtil.SATCHEL_SLOT_START; i > ScoutUtil.BAG_SLOTS_END; i--) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,25 +2,21 @@ package pm.c7.scout.mixin.client;
 | 
			
		|||
 | 
			
		||||
import org.objectweb.asm.tree.*;
 | 
			
		||||
import org.quiltmc.loader.api.QuiltLoader;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
 | 
			
		||||
import pm.c7.scout.mixinsupport.ClassNodeTransformer;
 | 
			
		||||
 | 
			
		||||
import static org.objectweb.asm.Opcodes.*;
 | 
			
		||||
 | 
			
		||||
public class HandledScreenTransformer implements ClassNodeTransformer {
 | 
			
		||||
	private static Logger LOGGER = LoggerFactory.getLogger("Scout:HandledScreenTransformer");
 | 
			
		||||
	@Override
 | 
			
		||||
	public void transform(String name, ClassNode node) {
 | 
			
		||||
		var drawSlot = "m_zioswvnu";
 | 
			
		||||
		var Slot = "net/minecraft/unmapped/C_nhvqfffd";
 | 
			
		||||
		var y = "f_tttqoodj";
 | 
			
		||||
		var resolver = QuiltLoader.getMappingResolver();
 | 
			
		||||
		var namespace = "intermediary";
 | 
			
		||||
 | 
			
		||||
		if (QuiltLoader.isDevelopmentEnvironment()) {
 | 
			
		||||
			drawSlot = "drawSlot";
 | 
			
		||||
			Slot = "net/minecraft/screen/slot/Slot";
 | 
			
		||||
			y = "y";
 | 
			
		||||
		}
 | 
			
		||||
		var drawSlot = resolver.mapMethodName(namespace, name, "method_2385", "(Lnet/minecraft/class_332;Lnet/minecraft/class_1735;)V");
 | 
			
		||||
		var Slot = resolver.mapClassName(namespace, "net.minecraft.class_1735");
 | 
			
		||||
		var y = resolver.mapFieldName(namespace, Slot, "field_7872", "I");
 | 
			
		||||
		Slot = slash(Slot);
 | 
			
		||||
 | 
			
		||||
		for (var mn : node.methods) {
 | 
			
		||||
			if (mn.name.equals(drawSlot)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -55,19 +51,23 @@ public class HandledScreenTransformer implements ClassNodeTransformer {
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private String slash(String clazz) {
 | 
			
		||||
		return clazz.replaceAll("\\.", "/");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private InsnList insns(AbstractInsnNode... insns) {
 | 
			
		||||
		var li = new InsnList();
 | 
			
		||||
		for (var i : insns) li.add(i);
 | 
			
		||||
		return li;
 | 
			
		||||
	}
 | 
			
		||||
	private static JumpInsnNode IFEQ(LabelNode var) {
 | 
			
		||||
		return new JumpInsnNode(IFEQ, var);
 | 
			
		||||
	private static JumpInsnNode IFEQ(LabelNode v) {
 | 
			
		||||
		return new JumpInsnNode(IFEQ, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ALOAD(int var) {
 | 
			
		||||
		return new VarInsnNode(ALOAD, var);
 | 
			
		||||
	private static VarInsnNode ALOAD(int v) {
 | 
			
		||||
		return new VarInsnNode(ALOAD, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ASTORE(int var) {
 | 
			
		||||
		return new VarInsnNode(ASTORE, var);
 | 
			
		||||
	private static VarInsnNode ASTORE(int v) {
 | 
			
		||||
		return new VarInsnNode(ASTORE, v);
 | 
			
		||||
	}
 | 
			
		||||
	private static TypeInsnNode INSTANCEOF(String desc) {
 | 
			
		||||
		return new TypeInsnNode(INSTANCEOF, desc);
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ public class HandledScreenTransformer implements ClassNodeTransformer {
 | 
			
		|||
	private static MethodInsnNode INVOKEVIRTUAL(String owner, String name, String desc) {
 | 
			
		||||
		return new MethodInsnNode(INVOKEVIRTUAL, owner, name, desc);
 | 
			
		||||
	}
 | 
			
		||||
	private static VarInsnNode ISTORE(int var) {
 | 
			
		||||
		return new VarInsnNode(ISTORE, var);
 | 
			
		||||
	private static VarInsnNode ISTORE(int v) {
 | 
			
		||||
		return new VarInsnNode(ISTORE, v);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue