Skip to content

Commit

Permalink
Allow mergeTools to produce a merged jar with fabric-loader `@Environ…
Browse files Browse the repository at this point in the history
…ment` annotation type (#4)

Use of fabric annotations can be enabled by passing `-ann FABRIC`
  • Loading branch information
lukebemish authored Sep 24, 2024
1 parent fca29f7 commit 17e4ead
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/main/java/net/neoforged/mergetool/AnnotationVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public enum AnnotationVersion
{
CPW(cpw.mods.fml.relauncher.SideOnly.class, cpw.mods.fml.relauncher.Side.class, "CLIENT", "SERVER"),
NMF(net.neoforged.fml.relauncher.SideOnly.class, net.neoforged.fml.relauncher.Side.class, "CLIENT", "SERVER"),
API(OnlyIn.class, Dist.class, OnlyIns.class, "_interface", "CLIENT", "DEDICATED_SERVER");
API(OnlyIn.class, Dist.class, OnlyIns.class, "_interface", "CLIENT", "DEDICATED_SERVER"),
FABRIC("Lnet/fabricmc/api/Environment;", "Lnet/fabricmc/api/EnvType;", "CLIENT", "SERVER", false);

private final String holder;
private final String value;
private final String repeatable;
private final String interface_key;
private final String client;
private final String server;
private final boolean runtimeRetention;

private static final MinecraftVersion MC_8 = MinecraftVersion.from("14w02a");
private static final MinecraftVersion MC_13 = MinecraftVersion.from("17w43a");
Expand All @@ -50,6 +52,17 @@ private AnnotationVersion(Class<?> holder, Class<?> value, String client, String
{
this(holder, value, null, null, client, server);
}

private AnnotationVersion(String holder, String value, String client, String server, boolean runtimeRetention)
{
this.holder = holder;
this.value = value;
this.repeatable = null;
this.interface_key = null;
this.client = client;
this.server = server;
this.runtimeRetention = runtimeRetention;
}

private AnnotationVersion(Class<?> holder, Class<?> value, Class<?> repeatable, String interface_key, String client, String server)
{
Expand All @@ -59,6 +72,7 @@ private AnnotationVersion(Class<?> holder, Class<?> value, Class<?> repeatable,
this.interface_key = interface_key;
this.client = client;
this.server = server;
this.runtimeRetention = true;
}

public static AnnotationVersion fromVersion(String v)
Expand Down Expand Up @@ -98,28 +112,28 @@ public void add(ClassVisitor cls, List<String> clientOnly, List<String> serverOn
if (clientOnly.size() + serverOnly.size() == 1)
{
if (clientOnly.size() == 1)
add(cls.visitAnnotation(this.holder, true), true).visit(interface_key, Type.getObjectType(clientOnly.get(0)));
add(cls.visitAnnotation(this.holder, this.runtimeRetention), true).visit(interface_key, Type.getObjectType(clientOnly.get(0)));
else
add(cls.visitAnnotation(this.holder, true), false).visit(interface_key, Type.getObjectType(serverOnly.get(0)));
add(cls.visitAnnotation(this.holder, this.runtimeRetention), false).visit(interface_key, Type.getObjectType(serverOnly.get(0)));
}
else
{
AnnotationVisitor rep = cls.visitAnnotation(this.holder, true).visitArray("value");
AnnotationVisitor rep = cls.visitAnnotation(this.holder, this.runtimeRetention).visitArray("value");
clientOnly.forEach(intf -> add(rep.visitAnnotation(null, this.repeatable), true).visit(interface_key, Type.getObjectType(intf)));
serverOnly.forEach(intf -> add(rep.visitAnnotation(null, this.repeatable), false).visit(interface_key, Type.getObjectType(intf)));
}
}
public void add(ClassVisitor cls, boolean isClientOnly)
{
add(cls.visitAnnotation(this.holder, true), isClientOnly);
add(cls.visitAnnotation(this.holder, this.runtimeRetention), isClientOnly);
}
public void add(FieldVisitor fld, boolean isClientOnly)
{
add(fld.visitAnnotation(this.holder, true), isClientOnly);
add(fld.visitAnnotation(this.holder, this.runtimeRetention), isClientOnly);
}
public void add(MethodVisitor mtd, boolean isClientOnly)
{
add(mtd.visitAnnotation(this.holder, true), isClientOnly);
add(mtd.visitAnnotation(this.holder, this.runtimeRetention), isClientOnly);
}
private AnnotationVisitor add(AnnotationVisitor ann, boolean isClientOnly)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/neoforged/mergetool/ConsoleMerger.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static void merge(String[] args)
}
catch (OptionException e)
{
System.out.println("Usage: ConsoleMerger --merge --client <ClientJar> --server <ServerJar> --output <MergedJar> [--ann CPW|NMF|API] [--keep-data] [--keep-meta]");
System.out.println("Usage: ConsoleMerger --merge --client <ClientJar> --server <ServerJar> --output <MergedJar> [--ann CPW|NMF|API|FABRIC] [--keep-data] [--keep-meta]");
e.printStackTrace();
}
}
Expand Down

0 comments on commit 17e4ead

Please sign in to comment.