-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor MCP support - now also parses MCP from FML in 1.3 - 1.7
- Loading branch information
1 parent
d242837
commit 2f260d0
Showing
11 changed files
with
304 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
public abstract class McpFiles { | ||
|
||
private final Path intermediaryFile; | ||
|
||
protected McpFiles(Path intermediaryFile) { | ||
this.intermediaryFile = intermediaryFile; | ||
} | ||
|
||
public InputStream readIntermediary() throws IOException { | ||
try (ZipFile zip = new ZipFile(intermediaryFile.toFile())) { | ||
ZipEntry intermediary = zip.getEntry("mappings/mappings.tiny"); | ||
|
||
if (intermediary == null) { | ||
throw new FileNotFoundException("intermediary mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(intermediary); | ||
} | ||
} | ||
|
||
public abstract InputStream readSrg() throws IOException; | ||
|
||
public abstract InputStream readFields() throws IOException; | ||
|
||
public abstract InputStream readMethods() throws IOException; | ||
|
||
public abstract InputStream readParams() throws IOException; | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/net/ornithemc/ploceus/mcp/McpForgeFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
public class McpForgeFiles extends McpFiles { | ||
|
||
private final Path zipFile; | ||
|
||
public McpForgeFiles(Path intermediaryFile, Path zipFile) { | ||
super(intermediaryFile); | ||
|
||
this.zipFile = zipFile; | ||
} | ||
|
||
@Override | ||
public InputStream readSrg() throws IOException { | ||
try (ZipFile zip = new ZipFile(zipFile.toFile())) { | ||
ZipEntry srg = zip.getEntry("conf/joined.srg"); | ||
|
||
if (srg == null) { | ||
throw new FileNotFoundException("srg mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(srg); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readFields() throws IOException { | ||
try (ZipFile zip = new ZipFile(zipFile.toFile())) { | ||
ZipEntry fields = zip.getEntry("conf/fields.csv"); | ||
|
||
if (fields == null) { | ||
throw new FileNotFoundException("field mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(fields); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readMethods() throws IOException { | ||
try (ZipFile zip = new ZipFile(zipFile.toFile())) { | ||
ZipEntry fields = zip.getEntry("conf/methods.csv"); | ||
|
||
if (fields == null) { | ||
throw new FileNotFoundException("method mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(fields); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readParams() throws IOException { | ||
try (ZipFile zip = new ZipFile(zipFile.toFile())) { | ||
ZipEntry params = zip.getEntry("conf/params.csv"); | ||
|
||
if (params == null) { | ||
throw new FileNotFoundException("parameter mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(params); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/net/ornithemc/ploceus/mcp/McpForgeMappingsSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import net.fabricmc.loom.api.mappings.layered.MappingContext; | ||
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; | ||
|
||
public class McpForgeMappingsSpec extends McpMappingsSpec<McpForgeMappingsLayer> { | ||
|
||
private final FileSpec zipFile; | ||
|
||
public McpForgeMappingsSpec(FileSpec intermediaryFile, FileSpec zipFile) { | ||
super(intermediaryFile); | ||
|
||
this.zipFile = zipFile; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * super.hashCode() + zipFile.hashCode(); | ||
} | ||
|
||
@Override | ||
public McpForgeMappingsLayer createLayer(MappingContext ctx) { | ||
return new McpForgeMappingsLayer(intermediaryFile.get(ctx), zipFile.get(ctx)); | ||
} | ||
} |
19 changes: 5 additions & 14 deletions
19
src/main/java/net/ornithemc/ploceus/mcp/McpMappingsSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,19 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import net.fabricmc.loom.api.mappings.layered.MappingContext; | ||
import net.fabricmc.loom.api.mappings.layered.MappingLayer; | ||
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; | ||
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; | ||
|
||
public class McpMappingsSpec implements MappingsSpec<McpMappingsLayer> { | ||
public abstract class McpMappingsSpec<T extends MappingLayer> implements MappingsSpec<T> { | ||
|
||
private final FileSpec intermediaryFile; | ||
private final FileSpec srgFile; | ||
private final FileSpec mcpFile; | ||
protected final FileSpec intermediaryFile; | ||
|
||
public McpMappingsSpec(FileSpec intermediaryFile, FileSpec srgFile, FileSpec mcpFile) { | ||
public McpMappingsSpec(FileSpec intermediaryFile) { | ||
this.intermediaryFile = intermediaryFile; | ||
this.srgFile = srgFile; | ||
this.mcpFile = mcpFile; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * srgFile.hashCode() + mcpFile.hashCode(); | ||
} | ||
|
||
@Override | ||
public McpMappingsLayer createLayer(MappingContext ctx) { | ||
return new McpMappingsLayer(intermediaryFile.get(ctx), srgFile.get(ctx), mcpFile.get(ctx)); | ||
return intermediaryFile.hashCode(); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/net/ornithemc/ploceus/mcp/McpModernFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
public class McpModernFiles extends McpFiles { | ||
|
||
private final Path srgFile; | ||
private final Path mcpFile; | ||
|
||
public McpModernFiles(Path intermediaryFile, Path srgFile, Path mcpFile) { | ||
super(intermediaryFile); | ||
|
||
this.srgFile = srgFile; | ||
this.mcpFile = mcpFile; | ||
} | ||
|
||
@Override | ||
public InputStream readSrg() throws IOException { | ||
try (ZipFile zip = new ZipFile(srgFile.toFile())) { | ||
ZipEntry srg = zip.getEntry("joined.srg"); | ||
|
||
if (srg == null) { | ||
throw new FileNotFoundException("srg mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(srg); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readFields() throws IOException { | ||
try (ZipFile zip = new ZipFile(mcpFile.toFile())) { | ||
ZipEntry fields = zip.getEntry("fields.csv"); | ||
|
||
if (fields == null) { | ||
throw new FileNotFoundException("field mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(fields); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readMethods() throws IOException { | ||
try (ZipFile zip = new ZipFile(mcpFile.toFile())) { | ||
ZipEntry fields = zip.getEntry("methods.csv"); | ||
|
||
if (fields == null) { | ||
throw new FileNotFoundException("method mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(fields); | ||
} | ||
} | ||
|
||
@Override | ||
public InputStream readParams() throws IOException { | ||
try (ZipFile zip = new ZipFile(mcpFile.toFile())) { | ||
ZipEntry params = zip.getEntry("params.csv"); | ||
|
||
if (params == null) { | ||
throw new FileNotFoundException("parameter mappings are missing!"); | ||
} | ||
|
||
return zip.getInputStream(params); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/net/ornithemc/ploceus/mcp/McpModernMappingsLayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import net.fabricmc.loom.api.mappings.layered.MappingLayer; | ||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; | ||
import net.fabricmc.mappingio.MappingVisitor; | ||
|
||
import net.ornithemc.ploceus.mcp.io.McpReader; | ||
|
||
public record McpModernMappingsLayer(Path intermediaryFile, Path srgFile, Path mcpFile) implements MappingLayer { | ||
|
||
@Override | ||
public MappingsNamespace getSourceNamespace() { | ||
return MappingsNamespace.INTERMEDIARY; | ||
} | ||
|
||
@Override | ||
public void visit(MappingVisitor visitor) throws IOException { | ||
McpReader.read(new McpModernFiles(intermediaryFile, srgFile, mcpFile), visitor); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/net/ornithemc/ploceus/mcp/McpModernMappingsSpec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.ornithemc.ploceus.mcp; | ||
|
||
import net.fabricmc.loom.api.mappings.layered.MappingContext; | ||
import net.fabricmc.loom.api.mappings.layered.spec.FileSpec; | ||
|
||
public class McpModernMappingsSpec extends McpMappingsSpec<McpModernMappingsLayer> { | ||
|
||
private final FileSpec srgFile; | ||
private final FileSpec mcpFile; | ||
|
||
public McpModernMappingsSpec(FileSpec intermediaryFile, FileSpec srgFile, FileSpec mcpFile) { | ||
super(intermediaryFile); | ||
|
||
this.srgFile = srgFile; | ||
this.mcpFile = mcpFile; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * super.hashCode() + 31 * srgFile.hashCode() + mcpFile.hashCode(); | ||
} | ||
|
||
@Override | ||
public McpModernMappingsLayer createLayer(MappingContext ctx) { | ||
return new McpModernMappingsLayer(intermediaryFile.get(ctx), srgFile.get(ctx), mcpFile.get(ctx)); | ||
} | ||
} |
Oops, something went wrong.