From 9054d2912fefe861b02467032756b9d07e175f57 Mon Sep 17 00:00:00 2001 From: Jab125 <67534807+Jab125@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:51:45 +1000 Subject: [PATCH] fix checkstyle --- .../loom/util/ForgeSrgToMojangUtil.java | 21 +++++++++++++++---- .../loom/configuration/mods/ModProcessor.java | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/architectury/loom/util/ForgeSrgToMojangUtil.java b/src/main/java/dev/architectury/loom/util/ForgeSrgToMojangUtil.java index b85dc68e9..c31c38710 100644 --- a/src/main/java/dev/architectury/loom/util/ForgeSrgToMojangUtil.java +++ b/src/main/java/dev/architectury/loom/util/ForgeSrgToMojangUtil.java @@ -4,6 +4,7 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; + import net.fabricmc.mappingio.tree.MappingTree; import net.fabricmc.mappingio.tree.MemoryMappingTree; import net.fabricmc.tinyremapper.ClassInstance; @@ -13,18 +14,19 @@ // FIXME: There has to be a better way to fix the mappings public final class ForgeSrgToMojangUtil { - private ForgeSrgToMojangUtil() { - - } + private ForgeSrgToMojangUtil() { } @SuppressWarnings("unchecked") public static void replaceSrgWithMojangMappings(TinyRemapper remapper, MemoryMappingTree mappings) { Map readClasses; + try { Field readClassesField = TinyRemapper.class.getDeclaredField("readClasses"); readClassesField.setAccessible(true); readClasses = (Map) readClassesField.get(remapper); - } catch (Throwable t) {throw new RuntimeException(t);} + } catch (Throwable t) { + throw new RuntimeException(t); + } for (ClassInstance value : readClasses.values()) { replaceSrgWithMojangMappings(value, mappings); @@ -36,6 +38,7 @@ public static void replaceSrgWithMojangMappings(ClassInstance value, MemoryMappi int srg = tree.getNamespaceId("srg"); int mojang = tree.getNamespaceId("mojang"); HashMap members; + try { Field membersField = ClassInstance.class.getDeclaredField("members"); membersField.setAccessible(true); @@ -43,35 +46,45 @@ public static void replaceSrgWithMojangMappings(ClassInstance value, MemoryMappi } catch (Throwable t) { throw new RuntimeException(t); } + Map copy = (Map) members.clone(); members.clear(); + for (Map.Entry entry : copy.entrySet()) { TrMember.MemberType type = entry.getValue().getType(); MemberInstance memberInstance = entry.getValue(); String name; + if (type == TrMember.MemberType.FIELD) { MappingTree.FieldMapping field = tree.getField(value.getName(), memberInstance.getName(), memberInstance.getDesc(), srg); + if (field == null) { field = tree.getField(value.getName(), memberInstance.getName(), null, srg); + if (field == null) { members.put(memberInstance.getId(), memberInstance); continue; } } + name = field.getName(mojang); } else if (type == TrMember.MemberType.METHOD) { MappingTree.MethodMapping method = tree.getMethod(value.getName(), memberInstance.getName(), memberInstance.getDesc(), srg); + if (method == null) { method = tree.getMethod(value.getName(), memberInstance.getName(), null, srg); + if (method == null) { members.put(memberInstance.getId(), memberInstance); continue; } } + name = method.getName(mojang); } else { throw new AssertionError(); } + MemberInstance instance = of(type, value, name, memberInstance.getDesc(), memberInstance.getAccess(), memberInstance.getIndex()); members.put(instance.getId(), instance); } diff --git a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java index 0b87597ca..57e8773fa 100644 --- a/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java @@ -208,6 +208,7 @@ private void remapJars(List remapList) throws IOException { final TinyRemapper remapper = builder.build(); remapper.readClassPath(extension.getMinecraftJars(IntermediaryNamespaces.intermediaryNamespace(project)).toArray(Path[]::new)); + if (extension.isForge() && extension.getForgeProvider().usesMojangAtRuntime()) { ForgeSrgToMojangUtil.replaceSrgWithMojangMappings(remapper, mappings); }