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); } }