Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mergeTools to produce a merged jar with fabric-loader @Environment annotation type #4

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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