Restructure and simplify some stuff #1

Merged
kode merged 2 commits from TheKodeToad/restructure into main 2024-05-12 07:57:11 -04:00
5 changed files with 22 additions and 35 deletions
Showing only changes of commit 20ce0ff62a - Show all commits

View file

@ -1,7 +1,7 @@
package io.github.moehreag.mojmap_patcher;
import io.github.moehreag.mojmap_patcher.provider.MojmapProvider;
import io.github.moehreag.mojmap_patcher.format.proguard.ProguardParser;
import io.github.moehreag.mojmap_patcher.parser.ProguardParser;
public class MojMapPatcher {
@ -14,7 +14,7 @@ public class MojMapPatcher {
}
MojmapProvider.get(version).map(ProguardParser::read).ifPresent(s -> {
//s.getClassFields().keySet().forEach(System.out::println);
s.getClassFields().get("net.minecraft.client.Minecraft").forEach((s1, s2) -> System.out.println(s1 + " -> " + s2));
s.classFields().get("net.minecraft.client.Minecraft").forEach((s1, s2) -> System.out.println(s1 + " -> " + s2));
});
}
}

View file

@ -18,11 +18,11 @@ public class Mapper extends Remapper {
}
public String mapClass(String name) {
return data.getClasses().getOrDefault(name, name);
return data.classes().getOrDefault(name, name);
}
private Optional<Method> mapMethodInternal(String owner, String name, String descriptor) {
for (Map.Entry<Method, Method> entry : data.getClassMethods().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
for (Map.Entry<Method, Method> entry : data.classMethods().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
Method from = entry.getKey();
Method to = entry.getValue();
@ -38,7 +38,7 @@ public class Mapper extends Remapper {
}
private Optional<Field> mapFieldInternal(String owner, String name, String descriptor) {
for (Map.Entry<Field, Field> entry : data.getClassFields().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
for (Map.Entry<Field, Field> entry : data.classFields().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
Field from = entry.getKey();
Field to = entry.getValue();

View file

@ -1,12 +1,17 @@
package io.github.moehreag.mojmap_patcher.api.data;
import java.util.HashMap;
import java.util.Map;
public interface MappingData {
public record MappingData(
// IntelliJank, stop putting 8 spaces >:(
Map<String, String> classes,
Map<String, Map<Method, Method>> classMethods,
Map<String, Map<Field, Field>> classFields
) {
Map<String, String> getClasses();
public MappingData() {
this(new HashMap<>(), new HashMap<>(), new HashMap<>());
}
Map<String, Map<Method, Method>> getClassMethods();
Map<String, Map<Field, Field>> getClassFields();
}

View file

@ -1,18 +0,0 @@
package io.github.moehreag.mojmap_patcher.format.proguard;
import io.github.moehreag.mojmap_patcher.api.data.Field;
import io.github.moehreag.mojmap_patcher.api.data.MappingData;
import io.github.moehreag.mojmap_patcher.api.data.Method;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data
public class ProguardData implements MappingData {
private final Map<String, String> classes = new HashMap<>();
private final Map<String, Map<Method, Method>> classMethods = new HashMap<>();
private final Map<String, Map<Field, Field>> classFields = new HashMap<>();
}

View file

@ -1,18 +1,18 @@
package io.github.moehreag.mojmap_patcher.format.proguard;
package io.github.moehreag.mojmap_patcher.parser;
import io.github.moehreag.mojmap_patcher.Constants;
import io.github.moehreag.mojmap_patcher.api.data.Field;
import io.github.moehreag.mojmap_patcher.api.data.MappingData;
import io.github.moehreag.mojmap_patcher.api.data.Method;
import io.github.moehreag.mojmap_patcher.format.proguard.ProguardData;
import java.util.HashMap;
public class ProguardParser {
public static ProguardData read(String mappings) {
public static MappingData read(String mappings) {
String[] lines = mappings.split("\n");
ProguardData data = new ProguardData();
MappingData data = new MappingData();
String currentClass = null;
for (String line : lines) {
if (line.startsWith("#")) { // Filter out comments
@ -30,15 +30,15 @@ public class ProguardParser {
String[] method = deobf.split(":");
String[] descriptor = method[2].split(" ");
int bracket = descriptor[1].indexOf("(");
data.getClassMethods().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), obf, descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)),
data.classMethods().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), obf, descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)),
new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), descriptor[0], descriptor[1].substring(0, bracket), descriptor[1].substring(bracket + 1)));
} else {
String[] field = deobf.split(" ");
data.getClassFields().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Field(field[1], obf), new Field(field[1], field[0]));
data.classFields().computeIfAbsent(currentClass, s -> new HashMap<>()).put(new Field(field[1], obf), new Field(field[1], field[0]));
}
} else { // It's a class mapping
currentClass = deobf;
data.getClasses().put(obf, deobf);
data.classes().put(obf, deobf);
}
}
return data;