Skip to content

Commit

Permalink
Patch compatibility with client commands
Browse files Browse the repository at this point in the history
Fixes #441
  • Loading branch information
Su5eD committed May 1, 2024
1 parent f8ec141 commit 2f36163
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.daemon=true
# Versions
versionConnector=1.0.0-beta.44
versionAdapter=1.11.55-1.20.1-20240428.153904
versionAdapterDefinition=1.11.55
versionAdapterDefinition=1.11.56

versionMc=1.20.1
versionForge=47.1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
public class MixinPatchTransformer implements Transformer {
private static final List<Patch> PRIORITY_PATCHES = MixinPatches.getPriorityPatches();
private static final List<Patch> PATCHES = MixinPatches.getPatches();
private static final List<Patch> EXTRA_CLASS_PATCHES = MixinPatches.getGeneratedClassPatches();
// Applied to non-mixins
private static final List<ClassTransform> CLASS_TRANSFORMS = List.of(
new EnvironmentStripperTransformer(),
Expand Down Expand Up @@ -235,11 +236,17 @@ public ClassEntry process(ClassEntry entry) {
@Override
public Collection<? extends Entry> getExtras() {
List<Entry> entries = new ArrayList<>();
Patch patch = Patch.builder()
.transform(new DynamicInheritedInjectionPointPatch())
.build();
List<Patch> patches = ImmutableList.<Patch>builder()
.addAll(EXTRA_CLASS_PATCHES)
.add(
Patch.builder()
.transform(new DynamicInheritedInjectionPointPatch())
.build()
).build();
this.environment.classGenerator().getGeneratedMixinClasses().forEach((name, cls) -> {
patch.apply(cls.node(), this.environment);
for (Patch patch : patches) {
patch.apply(cls.node(), this.environment);
}

ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cls.node().accept(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public static List<Patch> getPatches() {
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/item/HoeItem;f_41332_:Ljava/util/Map;")
.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)
.build(),
Patch.builder()
.targetClass("net/minecraft/world/entity/animal/SnowGolem")
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
.splitMixin("net/minecraft/world/entity/animal/SnowGolem")
.build(),
Patch.builder()
.targetClass("net/minecraft/world/entity/animal/Sheep")
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
.splitMixin("net/minecraft/world/entity/animal/Sheep")
.build(),
Patch.builder()
.targetClass("net/minecraft/world/entity/animal/MushroomCow")
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
.splitMixin("net/minecraft/world/entity/animal/MushroomCow")
.build(),
Patch.builder()
.targetClass("net/minecraft/client/KeyMapping")
.targetMethod("m_90837_")
Expand Down Expand Up @@ -640,6 +658,31 @@ public static List<Patch> getPatches() {
.collect(Collectors.toList()); // Mutable list
}

public static List<Patch> getGeneratedClassPatches() {
return List.of(
Patch.builder()
.targetClass("net/minecraft/world/entity/animal/SnowGolem")
.targetClass("net/minecraft/world/entity/animal/Sheep")
.targetClass("net/minecraft/world/entity/animal/MushroomCow")
.targetMethod("m_6071_(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;")
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/level/Level;f_46443_:Z")
.modifyTarget("onSheared")
.modifyInjectionPoint("HEAD", "")
.transformParams(b -> b
.inject(1, Type.getObjectType("net/minecraft/world/item/ItemStack"))
.inject(2, Type.getObjectType("net/minecraft/world/level/Level"))
.inject(3, Type.getObjectType("net/minecraft/core/BlockPos"))
.inject(4, Type.INT_TYPE)
.inline(5, i -> {
i.visitVarInsn(Opcodes.ALOAD, 1);
i.visitVarInsn(Opcodes.ALOAD, 2);
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);
})
.withOffset())
.build()
);
}

private static Patch buildGuiPatch(int minOrdinal, int maxOrdinal, String targetMethodName, String injectionPoint, boolean offsetOrdinal) {
return Patch.builder()
.targetClass("net/minecraft/client/gui/Gui")
Expand Down
10 changes: 9 additions & 1 deletion src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
Expand Down Expand Up @@ -82,7 +85,12 @@ public static <T> Optional<T> deserializeLootTable(LootDataType<T> type, Resourc
public static GenericBuilder<?, ?> useModConfigResource(FileConfigBuilder builder, String resource) {
URL url = ConnectorMod.class.getClassLoader().getResource(resource);
return builder.onFileNotFound(FileNotFoundAction.copyData(url));
}
}

@SuppressWarnings("unused")
public static InteractionHand itemToHand(Player player, ItemStack stack) {
return ItemStack.isSameItemSameTags(stack, player.getItemInHand(InteractionHand.MAIN_HAND)) ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
}

@SuppressWarnings("deprecation")
public static void unfreezeRegistries() {
Expand Down

0 comments on commit 2f36163

Please sign in to comment.