Skip to content

Commit

Permalink
refactor MCP support - now also parses MCP from FML in 1.3 - 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceWalkerRS committed Nov 19, 2023
1 parent d242837 commit 2f260d0
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 85 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/ornithemc/ploceus/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ public class Constants {
public static final String SRG_MAPPINGS = "mcp:%s:srg@zip";
public static final String MCP_MAPPINGS = "mcp_%s:%s-%s@zip";

public static final String FORGE_MAVEN_GROUP = "net.minecraftforge.mcp";
public static final String FORGE_SRC = "forge:%s-%s:src@zip";

}
20 changes: 16 additions & 4 deletions src/main/java/net/ornithemc/ploceus/PloceusGradleExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import net.fabricmc.loom.configuration.DependencyInfo;

import net.ornithemc.ploceus.mappings.SidedIntermediaryMappingsProvider;
import net.ornithemc.ploceus.mcp.McpMappingsSpec;
import net.ornithemc.ploceus.mcp.McpForgeMappingsSpec;
import net.ornithemc.ploceus.mcp.McpModernMappingsSpec;
import net.ornithemc.ploceus.nester.NestedMappingsSpec;
import net.ornithemc.ploceus.nester.NesterProcessor;
import net.ornithemc.ploceus.nester.NestsProvider;
Expand Down Expand Up @@ -48,18 +49,29 @@ public NestedMappingsSpec nestedMappings() {
return new NestedMappingsSpec(this);
}

public McpMappingsSpec mcpMappings(String channel, String build) {
public McpModernMappingsSpec mcpMappings(String channel, String build) {
return mcpMappings(channel, DependencyInfo.create(project, Constants.MINECRAFT_CONFIGURATION).getDependency().getVersion(), build);
}

public McpMappingsSpec mcpMappings(String channel, String mc, String build) {
return new McpMappingsSpec(
public McpModernMappingsSpec mcpMappings(String channel, String mc, String build) {
return new McpModernMappingsSpec(
FileSpec.create(String.format(Constants.CALAMUS_INTERMEDIARY_MAVEN_GROUP + ":" + Constants.CALAMUS_INTERMEDIARY_MAPPINGS, mc)),
FileSpec.create(String.format(Constants.MCP_MAVEN_GROUP + ":" + Constants.SRG_MAPPINGS, mc)),
FileSpec.create(String.format(Constants.MCP_MAVEN_GROUP + ":" + Constants.MCP_MAPPINGS, channel, build, mc))
);
}

public McpForgeMappingsSpec mcpForgeMappings(String version) {
return mcpForgeMappings(DependencyInfo.create(project, Constants.MINECRAFT_CONFIGURATION).getDependency().getVersion(), version);
}

public McpForgeMappingsSpec mcpForgeMappings(String mc, String version) {
return new McpForgeMappingsSpec(
FileSpec.create(String.format(Constants.CALAMUS_INTERMEDIARY_MAVEN_GROUP + ":" + Constants.CALAMUS_INTERMEDIARY_MAPPINGS, mc)),
FileSpec.create(String.format(Constants.FORGE_MAVEN_GROUP+ ":" + Constants.FORGE_SRC, mc, version))
);
}

public void dependOsl(String version) throws Exception {
dependOsl(version, GameSide.MERGED);
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/net/ornithemc/ploceus/mcp/McpFiles.java
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 src/main/java/net/ornithemc/ploceus/mcp/McpForgeFiles.java
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import net.ornithemc.ploceus.mcp.io.McpReader;

public record McpMappingsLayer(Path intermediaryFile, Path srgFile, Path mcpFile) implements MappingLayer {
public record McpForgeMappingsLayer(Path intermediaryFile, Path zipFile) implements MappingLayer {

@Override
public MappingsNamespace getSourceNamespace() {
Expand All @@ -18,6 +18,6 @@ public MappingsNamespace getSourceNamespace() {

@Override
public void visit(MappingVisitor visitor) throws IOException {
McpReader.read(intermediaryFile, srgFile, mcpFile, visitor);
McpReader.read(new McpForgeFiles(intermediaryFile, zipFile), visitor);
}
}
25 changes: 25 additions & 0 deletions src/main/java/net/ornithemc/ploceus/mcp/McpForgeMappingsSpec.java
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 src/main/java/net/ornithemc/ploceus/mcp/McpMappingsSpec.java
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 src/main/java/net/ornithemc/ploceus/mcp/McpModernFiles.java
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);
}
}
}
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 src/main/java/net/ornithemc/ploceus/mcp/McpModernMappingsSpec.java
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));
}
}
Loading

0 comments on commit 2f260d0

Please sign in to comment.