bytecode moment (fix #249)
This commit is contained in:
parent
0098302f39
commit
be43c59a2d
@ -0,0 +1,29 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
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.Redirect;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability;
|
||||||
|
|
||||||
|
@Mixin(Minecraft.class)
|
||||||
|
public class MixinMinecraft {
|
||||||
|
@Redirect(
|
||||||
|
method = "pickBlock()V",
|
||||||
|
at = @At(
|
||||||
|
value = "INVOKE",
|
||||||
|
target = "Lnet/minecraft/world/entity/player/Inventory;findSlotMatchingItem(Lnet/minecraft/world/item/ItemStack;)I"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
private int pickBlock(Inventory inventory, ItemStack itemStack) {
|
||||||
|
int i = inventory.findSlotMatchingItem(itemStack);
|
||||||
|
|
||||||
|
MatteryPlayerCapability.pickBlockHook(i, itemStack);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
@ -681,74 +681,6 @@ function initializeCoreMod() {
|
|||||||
'transformer': patchBlendFunc
|
'transformer': patchBlendFunc
|
||||||
},
|
},
|
||||||
|
|
||||||
'Minecraft#pickBlock patch for exosuit':
|
|
||||||
method('net.minecraft.client.Minecraft.m_91280_()V', function(node) {
|
|
||||||
// 275: invokevirtual #7672 // Method net/minecraft/world/entity/Entity.getType:()Lnet/minecraft/world/entity/EntityType;
|
|
||||||
// 278: invokevirtual #7667 // Method net/minecraft/core/DefaultedRegistry.getKey:(Ljava/lang/Object;)Lnet/minecraft/resources/ResourceLocation;
|
|
||||||
// 281: invokevirtual #4475 // Method net/minecraft/resources/ResourceLocation.toString:()Ljava/lang/String;
|
|
||||||
// 284: astore 5
|
|
||||||
// 286: getstatic #5986 // Field LOGGER:Lorg/slf4j/Logger;
|
|
||||||
// 289: ldc_w #4484 // String Picking on: [{}] {} gave null item
|
|
||||||
// 292: aload_3
|
|
||||||
// 293: aload 5
|
|
||||||
// 295: invokeinterface #3145, 4 // InterfaceMethod org/slf4j/Logger.warn:(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
|
|
||||||
// 300: goto 405
|
|
||||||
// 303: aload_0
|
|
||||||
// 304: getfield #6654 // Field player:Lnet/minecraft/client/player/LocalPlayer;
|
|
||||||
// 307: invokevirtual #7409 // Method net/minecraft/client/player/LocalPlayer.getInventory:()Lnet/minecraft/world/entity/player/Inventory;
|
|
||||||
// 310: astore 5
|
|
||||||
// 312: aload_2
|
|
||||||
// 313: ifnull 324
|
|
||||||
// 316: aload_0
|
|
||||||
// 317: aload 4
|
|
||||||
// 319: aload_2
|
|
||||||
// 320: invokevirtual #7675 // Method addCustomNbtData:(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/level/block/entity/BlockEntity;)Lnet/minecraft/world/item/ItemStack;
|
|
||||||
// 323: pop
|
|
||||||
// 324: aload 5
|
|
||||||
// 326: aload 4
|
|
||||||
// 328: invokevirtual #7678 // Method net/minecraft/world/entity/player/Inventory.findSlotMatchingItem:(Lnet/minecraft/world/item/ItemStack;)I
|
|
||||||
// 331: istore 6
|
|
||||||
// <-- Our target
|
|
||||||
// 333: iload_1
|
|
||||||
// 334: ifeq 372
|
|
||||||
// 337: aload 5
|
|
||||||
// 339: aload 4
|
|
||||||
// 341: invokevirtual #7681 // Method net/minecraft/world/entity/player/Inventory.setPickedItem:(Lnet/minecraft/world/item/ItemStack;)V
|
|
||||||
// 344: aload_0
|
|
||||||
|
|
||||||
for (var i = 0; i < node.instructions.size(); i++) {
|
|
||||||
var determinedOffset = test([
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.getfield,
|
|
||||||
opcodesRemapped.invokevirtual,
|
|
||||||
opcodesRemapped.astore,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.ifnull,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.invokevirtual,
|
|
||||||
opcodesRemapped.pop,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.aload,
|
|
||||||
opcodesRemapped.invokevirtual,
|
|
||||||
opcodesRemapped.istore,
|
|
||||||
], node.instructions, i)
|
|
||||||
|
|
||||||
if (determinedOffset != -1) {
|
|
||||||
putInstructions(node, node.instructions.get(determinedOffset), [
|
|
||||||
new VarInsnNode(opcodesRemapped.iload, backtrack(node.instructions, determinedOffset, opcodesRemapped.istore, 0)['var']),
|
|
||||||
new VarInsnNode(opcodesRemapped.aload, backtrack(node.instructions, determinedOffset, opcodesRemapped.aload, 0)['var']),
|
|
||||||
new MethodInsnNode(opcodesRemapped.invokestatic, 'ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability', 'pickBlockHook', '(ILnet/minecraft/world/item/ItemStack;)V', false)
|
|
||||||
])
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return node
|
|
||||||
}),
|
|
||||||
|
|
||||||
'LevelRenderer DynamicBufferSource callback': {
|
'LevelRenderer DynamicBufferSource callback': {
|
||||||
'target': {
|
'target': {
|
||||||
'type': 'METHOD',
|
'type': 'METHOD',
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
"MixinPlayer"
|
"MixinPlayer"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"MixinGameRenderer"
|
"MixinGameRenderer",
|
||||||
|
"MixinMinecraft"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user