Skip to content

Commit 2f36163

Browse files
committed
Patch compatibility with client commands
Fixes #441
1 parent f8ec141 commit 2f36163

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

Diff for: gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ org.gradle.daemon=true
66
# Versions
77
versionConnector=1.0.0-beta.44
88
versionAdapter=1.11.55-1.20.1-20240428.153904
9-
versionAdapterDefinition=1.11.55
9+
versionAdapterDefinition=1.11.56
1010

1111
versionMc=1.20.1
1212
versionForge=47.1.3

Diff for: src/main/java/dev/su5ed/sinytra/connector/transformer/MixinPatchTransformer.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
public class MixinPatchTransformer implements Transformer {
5353
private static final List<Patch> PRIORITY_PATCHES = MixinPatches.getPriorityPatches();
5454
private static final List<Patch> PATCHES = MixinPatches.getPatches();
55+
private static final List<Patch> EXTRA_CLASS_PATCHES = MixinPatches.getGeneratedClassPatches();
5556
// Applied to non-mixins
5657
private static final List<ClassTransform> CLASS_TRANSFORMS = List.of(
5758
new EnvironmentStripperTransformer(),
@@ -235,11 +236,17 @@ public ClassEntry process(ClassEntry entry) {
235236
@Override
236237
public Collection<? extends Entry> getExtras() {
237238
List<Entry> entries = new ArrayList<>();
238-
Patch patch = Patch.builder()
239-
.transform(new DynamicInheritedInjectionPointPatch())
240-
.build();
239+
List<Patch> patches = ImmutableList.<Patch>builder()
240+
.addAll(EXTRA_CLASS_PATCHES)
241+
.add(
242+
Patch.builder()
243+
.transform(new DynamicInheritedInjectionPointPatch())
244+
.build()
245+
).build();
241246
this.environment.classGenerator().getGeneratedMixinClasses().forEach((name, cls) -> {
242-
patch.apply(cls.node(), this.environment);
247+
for (Patch patch : patches) {
248+
patch.apply(cls.node(), this.environment);
249+
}
243250

244251
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
245252
cls.node().accept(writer);

Diff for: src/main/java/dev/su5ed/sinytra/connector/transformer/MixinPatches.java

+43
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ public static List<Patch> getPatches() {
7070
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/item/HoeItem;f_41332_:Ljava/util/Map;")
7171
.modifyInjectionPoint("INVOKE", "Lnet/minecraft/world/level/block/state/BlockState;getToolModifiedState(Lnet/minecraft/world/item/context/UseOnContext;Lnet/minecraftforge/common/ToolAction;Z)Lnet/minecraft/world/level/block/state/BlockState;", true)
7272
.build(),
73+
Patch.builder()
74+
.targetClass("net/minecraft/world/entity/animal/SnowGolem")
75+
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
76+
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
77+
.splitMixin("net/minecraft/world/entity/animal/SnowGolem")
78+
.build(),
79+
Patch.builder()
80+
.targetClass("net/minecraft/world/entity/animal/Sheep")
81+
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
82+
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
83+
.splitMixin("net/minecraft/world/entity/animal/Sheep")
84+
.build(),
85+
Patch.builder()
86+
.targetClass("net/minecraft/world/entity/animal/MushroomCow")
87+
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
88+
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
89+
.splitMixin("net/minecraft/world/entity/animal/MushroomCow")
90+
.build(),
7391
Patch.builder()
7492
.targetClass("net/minecraft/client/KeyMapping")
7593
.targetMethod("m_90837_")
@@ -640,6 +658,31 @@ public static List<Patch> getPatches() {
640658
.collect(Collectors.toList()); // Mutable list
641659
}
642660

661+
public static List<Patch> getGeneratedClassPatches() {
662+
return List.of(
663+
Patch.builder()
664+
.targetClass("net/minecraft/world/entity/animal/SnowGolem")
665+
.targetClass("net/minecraft/world/entity/animal/Sheep")
666+
.targetClass("net/minecraft/world/entity/animal/MushroomCow")
667+
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
668+
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
669+
.modifyTarget("onSheared")
670+
.modifyInjectionPoint("HEAD", "")
671+
.transformParams(b -> b
672+
.inject(1, Type.getObjectType("net/minecraft/world/item/ItemStack"))
673+
.inject(2, Type.getObjectType("net/minecraft/world/level/Level"))
674+
.inject(3, Type.getObjectType("net/minecraft/core/BlockPos"))
675+
.inject(4, Type.INT_TYPE)
676+
.inline(5, i -> {
677+
i.visitVarInsn(Opcodes.ALOAD, 1);
678+
i.visitVarInsn(Opcodes.ALOAD, 2);
679+
i.invokestatic("dev/su5ed/sinytra/connector/mod/ConnectorMod", "itemToHand", "(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/InteractionHand;", false);
680+
})
681+
.withOffset())
682+
.build()
683+
);
684+
}
685+
643686
private static Patch buildGuiPatch(int minOrdinal, int maxOrdinal, String targetMethodName, String injectionPoint, boolean offsetOrdinal) {
644687
return Patch.builder()
645688
.targetClass("net/minecraft/client/gui/Gui")

Diff for: src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import net.minecraft.core.Registry;
1515
import net.minecraft.core.registries.BuiltInRegistries;
1616
import net.minecraft.resources.ResourceLocation;
17+
import net.minecraft.world.InteractionHand;
18+
import net.minecraft.world.entity.player.Player;
19+
import net.minecraft.world.item.ItemStack;
1720
import net.minecraft.world.level.storage.loot.LootDataType;
1821
import net.minecraftforge.eventbus.api.EventPriority;
1922
import net.minecraftforge.eventbus.api.IEventBus;
@@ -82,7 +85,12 @@ public static <T> Optional<T> deserializeLootTable(LootDataType<T> type, Resourc
8285
public static GenericBuilder<?, ?> useModConfigResource(FileConfigBuilder builder, String resource) {
8386
URL url = ConnectorMod.class.getClassLoader().getResource(resource);
8487
return builder.onFileNotFound(FileNotFoundAction.copyData(url));
85-
}
88+
}
89+
90+
@SuppressWarnings("unused")
91+
public static InteractionHand itemToHand(Player player, ItemStack stack) {
92+
return ItemStack.isSameItemSameTags(stack, player.getItemInHand(InteractionHand.MAIN_HAND)) ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
93+
}
8694

8795
@SuppressWarnings("deprecation")
8896
public static void unfreezeRegistries() {

0 commit comments

Comments
 (0)