plugins/tools/OrdosSulfurTransition.java
unimatrixgit 98376da8b5
Some checks failed
Ordos Sulfur Near Mushrooms Build / ordos-sulfur (push) Successful in 56s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 10s
DuneRealms Plugin CI / plugins (push) Successful in 2m17s
Restrict Ordos sulfur caves to mushroom island footprints
2026-12-02 08:47:24 +01:00

37 lines
1.9 KiB
Java

import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassTransform;
import java.lang.constant.ClassDesc;
import java.lang.constant.MethodTypeDesc;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
/** Add the mushroom proximity guard to the retained Sigma terrain variant. */
class OrdosSulfurTransition {
private static final String PACKAGE = "com.example.duneterrain.";
public static void main(String[] args) throws Exception {
if (args.length != 2) throw new IllegalArgumentException("Expected input and output class paths");
var format = ClassFile.of();
var original = format.parse(Files.readAllBytes(Path.of(args[0])));
var landscape = ClassDesc.of(PACKAGE + "TemperateLandscape");
if (!original.thisClass().asSymbol().equals(landscape))
throw new IllegalArgumentException("Expected retained Sigma landscape class");
boolean[] inserted = {false};
byte[] candidate = format.transformClass(original, ClassTransform.transformingMethodBodies(
method -> method.methodName().equalsString("sulfurPocket") && method.methodType().equalsString("(JIII)Z"),
(out, element) -> {
if (!inserted[0]) {
var nearby = out.newLabel();
out.lload(0).iload(2).iload(4)
.invokestatic(landscape, "islandDistance", MethodTypeDesc.ofDescriptor("(JII)D"))
.invokestatic(ClassDesc.of(PACKAGE + "OrdosSulfurRange"), "near", MethodTypeDesc.ofDescriptor("(D)Z"))
.ifne(nearby).iconst_0().ireturn().labelBinding(nearby);
inserted[0] = true;
}
out.with(element);
}));
if (!inserted[0]) throw new IllegalArgumentException("Expected the retained sulfur selector");
Files.write(Path.of(args[1]), candidate, StandardOpenOption.CREATE_NEW);
}
}