Reformat and exclude .idea

This commit is contained in:
TheKodeToad 2024-05-12 12:26:25 +01:00
parent 2198a126cd
commit 129ed53127
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
12 changed files with 24 additions and 186 deletions

5
.gitignore vendored
View file

@ -5,10 +5,7 @@ build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/
*.iws
*.iml
*.ipr

3
.idea/.gitignore vendored
View file

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="temurin-21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View file

@ -1,124 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -25,7 +25,7 @@ public class HttpHelper {
return getString(url).map(s -> GSON.fromJson(s, JsonObject.class));
}
public static Optional<String> getString(String url){
public static Optional<String> getString(String url) {
return Optional.ofNullable(requestCache.computeIfAbsent(url, s -> {
try (InputStream in = URI.create(url).parseServerAuthority().toURL().openStream()) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);

View file

@ -5,16 +5,16 @@ import io.github.moehreag.mojmap_patcher.parser.MojmapParser;
public class MojMapPatcher {
public static void main(String[] args){
public static void main(String[] args) {
String version;
if (args.length == 0){
if (args.length == 0) {
version = "latest-release";
} else {
version = args[0];
}
MojmapLoader.get(version).map(MojmapParser::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.getClassFields().get("net.minecraft.client.Minecraft").forEach((s1, s2) -> System.out.println(s1 + " -> " + s2));
});
}
}

View file

@ -13,43 +13,43 @@ public class Mapper extends Remapper {
private Data data;
public static Mapper load(){
public static Mapper load() {
}
public String mapClass(String name){
public String mapClass(String name) {
return data.getClasses().getOrDefault(name, name);
}
private Optional<Method> mapMethodInternal(String owner, String name, String descriptor){
private Optional<Method> mapMethodInternal(String owner, String name, String descriptor) {
for (Map.Entry<Method, Method> entry : data.getClassMethods().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
Method from = entry.getKey();
Method to = entry.getValue();
if (from.name().equals(name) && from.descriptor().equals(descriptor)){
if (from.name().equals(name) && from.descriptor().equals(descriptor)) {
return Optional.of(to);
}
}
return Optional.empty();
}
public Method mapMethod(String owner, String name, String descriptor){
public Method mapMethod(String owner, String name, String descriptor) {
return mapMethodInternal(owner, name, descriptor).orElse(null);
}
private Optional<Field> mapFieldInternal(String owner, String name, String descriptor){
private Optional<Field> mapFieldInternal(String owner, String name, String descriptor) {
for (Map.Entry<Field, Field> entry : data.getClassFields().getOrDefault(owner, Collections.emptyMap()).entrySet()) {
Field from = entry.getKey();
Field to = entry.getValue();
if (from.name().equals(name) && from.descriptor().equals(descriptor)){
if (from.name().equals(name) && from.descriptor().equals(descriptor)) {
return Optional.of(to);
}
}
return Optional.empty();
}
public Field mapField(String owner, String name, String descriptor){
public Field mapField(String owner, String name, String descriptor) {
return mapFieldInternal(owner, name, descriptor).orElse(null);
}

View file

@ -8,11 +8,11 @@ public class Remapper {
this.mapper = mapper;
}
public static Remapper of(Mapper mapper){
public static Remapper of(Mapper mapper) {
return new Remapper(mapper);
}
public void apply(){
public void apply() {
}
}

View file

@ -9,17 +9,15 @@ import java.util.Optional;
public class MojmapLoader {
public static Optional<String> get(String gameVersion) {
return HttpHelper.getJson(Constants.VERSION_MANIFEST).map(manifest -> {
String versionName;
if (gameVersion.startsWith("latest-")){
if (gameVersion.startsWith("latest-")) {
versionName = manifest.get("latest").getAsJsonObject().get(gameVersion.split("-")[1]).getAsString();
} else {
versionName = gameVersion;
}
System.out.println("Loading version: "+versionName);
System.out.println("Loading version: " + versionName);
for (JsonElement element : manifest.get("versions").getAsJsonArray()) {
JsonObject version = element.getAsJsonObject();

View file

@ -9,29 +9,29 @@ import java.util.HashMap;
public class MojmapParser {
public static MojmapData read(String mappings){
public static MojmapData read(String mappings) {
String[] lines = mappings.split("\n");
MojmapData data = new MojmapData();
String currentClass = null;
for (String line : lines) {
if (line.startsWith("#")){ // Filter out comments
if (line.startsWith("#")) { // Filter out comments
continue;
}
String[] mapping = line.split("->");
String deobf = mapping[0].trim();
String obf = mapping[1].trim();
if (line.startsWith(" ")){ // It's a field/method mapping
if (currentClass == null){
if (line.startsWith(" ")) { // It's a field/method mapping
if (currentClass == null) {
throw new IllegalStateException("Field/Method mapping outside a class");
}
if (Constants.METHOD_PATTERN.matcher(deobf).matches()){
if (Constants.METHOD_PATTERN.matcher(deobf).matches()) {
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)),
new Method(Integer.parseInt(method[0]), Integer.parseInt(method[1]), descriptor[0], descriptor[1].substring(0, bracket), descriptor[1].substring(bracket+1)));
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)),
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]));