From 4c7868cc074d5643fa28ae7a1a47e2b16ff89f7e Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 24 Nov 2026 01:44:35 +0100 Subject: [PATCH] Enable Ordos caves in the installed generator without replacing unrelated terrain --- tools/PatchOrdosCaves.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tools/PatchOrdosCaves.java diff --git a/tools/PatchOrdosCaves.java b/tools/PatchOrdosCaves.java new file mode 100644 index 00000000..f4ca3b23 --- /dev/null +++ b/tools/PatchOrdosCaves.java @@ -0,0 +1,34 @@ +import java.nio.file.*; +import java.security.MessageDigest; +import java.util.HexFormat; +import jdk.internal.org.objectweb.asm.*; + +/** Build tool: retain the installed planet generator and enable only Ordos cave carving. */ +public final class PatchOrdosCaves { + public static void main(String[] args)throws Exception{ + if(args.length!=3)throw new IllegalArgumentException("input.class output.class expectedSha256"); + Path input=Path.of(args[0]),output=Path.of(args[1]);byte[] original=Files.readAllBytes(input); + if(Files.exists(output)||!HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(original)).equals(args[2]))throw new IllegalStateException("Input changed or output exists"); + ClassReader reader=new ClassReader(original);String owner="com/example/duneterrain/DuneTerrain$PlanetChunkGenerator"; + if(!reader.getClassName().equals(owner))throw new IllegalStateException("Unexpected generator class"); + ClassWriter writer=new ClassWriter(reader,ClassWriter.COMPUTE_MAXS);int[] changed={0}; + reader.accept(new ClassVisitor(Opcodes.ASM9,writer){ + @Override public MethodVisitor visitMethod(int access,String name,String descriptor,String signature,String[] exceptions){ + MethodVisitor method=super.visitMethod(access,name,descriptor,signature,exceptions); + if(!name.equals("shouldGenerateCaves")||!descriptor.equals("(Lorg/bukkit/generator/WorldInfo;Ljava/util/Random;II)Z"))return method; + changed[0]++; + return new MethodVisitor(Opcodes.ASM9,method){ + @Override public void visitCode(){ + super.visitCode();Label originalPath=new Label(); + super.visitVarInsn(Opcodes.ALOAD,0);super.visitFieldInsn(Opcodes.GETFIELD,owner,"planet","Ljava/lang/String;"); + super.visitLdcInsn("sigma_draconis_iv");super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,"java/lang/String","equals","(Ljava/lang/Object;)Z",false); + super.visitJumpInsn(Opcodes.IFEQ,originalPath);super.visitInsn(Opcodes.ICONST_1);super.visitInsn(Opcodes.IRETURN); + super.visitLabel(originalPath);super.visitFrame(Opcodes.F_SAME,0,null,0,null); + } + }; + } + },0); + if(changed[0]!=1)throw new IllegalStateException("Expected exactly one cave policy method"); + Files.write(output,writer.toByteArray());System.out.println("Patched Ordos cave policy; original paths for other planets retained"); + } +}