Skip to content

Commit

Permalink
Change attribute names
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 14, 2024
1 parent 74f5d10 commit f046945
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

import com.google.common.collect.Streams;
import com.mojang.logging.LogUtils;
import cpw.mods.jarhandling.SecureJar;
import cpw.mods.modlauncher.serviceapi.ILaunchPluginService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.jar.Attributes;
import java.util.stream.Collectors;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
Expand All @@ -42,19 +38,10 @@ public class RuntimeDistCleaner implements ILaunchPluginService {
private static final Marker DISTXFORM = MarkerFactory.getMarker("DISTXFORM");
private static final String ONLYIN = Type.getDescriptor(OnlyIn.class);
private static final String ONLYINS = Type.getDescriptor(OnlyIns.class);
private static final Attributes.Name NAME_DISTS = new Attributes.Name("NeoForm-Minecraft-Dists");
private static final Attributes.Name NAME_DIST = new Attributes.Name("NeoForm-Minecraft-Dist");

@Nullable
private String dist;

/**
* Records which files were masked in a joined distribution because the user requested to run
* in client or server explicitly. The key is the class name while the value is the dist it originally
* comes from.
*/
private final Map<String, String> maskedClasses = new HashMap<>();

@Override
public String name() {
return "runtimedistcleaner";
Expand All @@ -67,12 +54,6 @@ public int processClassWithFlags(final Phase phase, final ClassNode classNode, f
return ComputeFlags.NO_REWRITE;
}

// See if the class we're trying to load was masked
var sourceDist = maskedClasses.get(classNode.name);
if (sourceDist != null && !dist.equals(sourceDist)) {
throw new RuntimeException("Attempted to load class " + classNode.name + " for invalid dist " + dist);
}

AtomicBoolean changes = new AtomicBoolean();
if (remove(classNode.visibleAnnotations, dist)) {
LOGGER.error(DISTXFORM, "Attempted to load class {} for invalid dist {}", classNode.name, dist);
Expand Down Expand Up @@ -163,32 +144,6 @@ private boolean remove(final List<AnnotationNode> anns, final String side) {
return unpack(anns).stream().filter(ann -> Objects.equals(ann.desc, ONLYIN)).filter(ann -> !ann.values.contains("_interface")).anyMatch(ann -> !Objects.equals(((String[]) ann.values.get(ann.values.indexOf("value") + 1))[1], side));
}

@Override
public void addResources(List<SecureJar> resources) {
for (var resource : resources) {
var manifest = resource.moduleDataProvider().getManifest();
// Only process manifests of jars that indicate they have multiple source distributions
if (manifest.getMainAttributes().getValue(NAME_DISTS) != null) {
for (var entry : manifest.getEntries().entrySet()) {
String sourceDist = switch (entry.getValue().getValue(NAME_DIST)) {
case "client" -> Dist.CLIENT.name();
case "server" -> Dist.DEDICATED_SERVER.name();
case null, default -> null;
};
if (sourceDist == null) {
continue;
}

var path = entry.getKey();
if (path.endsWith(".class")) {
var key = path.substring(0, path.length() - ".class".length());
maskedClasses.put(key, sourceDist);
}
}
}
}
}

public void setDistribution(@Nullable Dist dist) {
if (dist != null) {
this.dist = dist.name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/
public class NeoForgeDevProvider implements IModFileCandidateLocator {
private static final Logger LOG = LoggerFactory.getLogger(NeoForgeDevProvider.class);
private static final Attributes.Name NAME_DISTS = new Attributes.Name("NeoForm-Minecraft-Dists");
private static final Attributes.Name NAME_DIST = new Attributes.Name("NeoForm-Minecraft-Dist");
private static final Attributes.Name NAME_DISTS = new Attributes.Name("Minecraft-Dists");
private static final Attributes.Name NAME_DIST = new Attributes.Name("Minecraft-Dist");

private final List<Path> paths;

Expand Down

0 comments on commit f046945

Please sign in to comment.