Restrict Ordos sulfur caves to mushroom island footprints #53

Merged
unimatrix merged 1 commit from fix/ordos-sulfur-near-mushrooms-20261202 into main 2026-12-02 08:51:00 +01:00
6 changed files with 245 additions and 2 deletions

View file

@ -0,0 +1,49 @@
name: Ordos Sulfur Near Mushrooms Build
on:
workflow_dispatch:
push:
branches: ['fix/ordos-sulfur-near-mushrooms-*']
jobs:
ordos-sulfur:
runs-on: dune-ci
steps:
- name: Check out exact revision
shell: bash
env:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git init .
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
git checkout --detach FETCH_HEAD
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '9.2.1'
- name: Build and verify the sulfur range guard
shell: bash
run: |
set -euo pipefail
gradle --no-daemon -p DuneTerrain test jar
python3 tools/test_planet_ore_release.py
mkdir ordos-sulfur-artifacts
cp DuneTerrain/build/classes/java/main/com/example/duneterrain/OrdosSulfurRange.class ordos-sulfur-artifacts/
cp tools/{OrdosSulfurTransition.java,planet_ore_release.py,reset-planet-ores.py,reset-ordos-sulfur.py} ordos-sulfur-artifacts/
printf '%s\n' "$(git rev-parse HEAD)" > ordos-sulfur-artifacts/SOURCE_COMMIT
(cd ordos-sulfur-artifacts && sha256sum -- *.class *.java *.py SOURCE_COMMIT > SHA256SUMS)
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '25'
- name: Verify the retained-class transition builder
shell: bash
run: javac -d "$(mktemp -d)" tools/OrdosSulfurTransition.java
- uses: actions/upload-artifact@v3
with:
name: DuneRealms-Ordos-Sulfur-Near-Mushrooms
path: ordos-sulfur-artifacts/
if-no-files-found: error

View file

@ -0,0 +1,11 @@
package com.example.duneterrain;
final class OrdosSulfurRange {
static final int MUSHROOM_FIELDS_RADIUS = 145;
private OrdosSulfurRange() {}
static boolean near(double islandDistance) {
return islandDistance < MUSHROOM_FIELDS_RADIUS;
}
}

View file

@ -28,7 +28,7 @@ public final class TemperateLandscape {
private static Biome frozenDesert(){var biome=Registry.BIOME.get(NamespacedKey.fromString("dunerealms:frozen_desert"));return biome==null?Biome.SNOWY_PLAINS:biome;}
static boolean ordosBadlands(long seed,int x,int z){int h=height(seed,x,z,"sigma_draconis_iv");return h>SEA+4&&h<150&&islandDistance(seed,x,z)>=240&&climate(seed^0x5445525241434f54L,x,z,1500)>.30;}
private static Biome sulfurBiome(){return Registry.BIOME.get(NamespacedKey.minecraft("sulfur_caves"));}
static boolean sulfurPocket(long seed,int x,int y,int z){return y<35&&y> -45&&climate(seed^0x53554c465552L,x,z,900)>.24;}
static boolean sulfurPocket(long seed,int x,int y,int z){return y<35&&y> -45&&OrdosSulfurRange.near(islandDistance(seed,x,z))&&climate(seed^0x53554c465552L,x,z,900)>.24;}
public static int height(long seed,int x,int z,String planet){
if(planet.equals("sigma_draconis_iv")){
double distance=islandDistance(seed,x,z);
@ -48,7 +48,7 @@ public final class TemperateLandscape {
public static boolean lavaSurface(long seed,int x,int z){return false;}
public static double islandDistance(long seed,int x,int z){long cx=Math.floorDiv(x,1024),cz=Math.floorDiv(z,1024),key=mix(seed^cx*0x9e3779b97f4a7c15L^cz*0xc2b2ae3d27d4eb4fL^0x4d555348524f4f4dL);if((key&127)!=0)return Double.POSITIVE_INFINITY;long centerX=cx*1024+384+Math.floorMod(key>>>8,256),centerZ=cz*1024+384+Math.floorMod(key>>>24,256);return Math.hypot(x-(double)centerX,z-(double)centerZ);}
public static Biome biome(WorldInfo world,int x,int y,int z,String planet){long seed=world.getSeed();int h=height(seed,x,z,planet);double region=climate(seed^321,x,z,420);
if(planet.equals("sigma_draconis_iv")){if(y<35&&sulfurPocket(seed,x,y,z)&&sulfurBiome()!=null)return sulfurBiome();if(islandDistance(seed,x,z)<145)return Biome.MUSHROOM_FIELDS;if(ordosBadlands(seed,x,z))return region>.2?Biome.ERODED_BADLANDS:Biome.BADLANDS;double cold=climate(seed^974,x,z,1200);if(h<SEA-14)return cold>.3?Biome.DEEP_COLD_OCEAN:Biome.DEEP_FROZEN_OCEAN;if(h<SEA-2)return h>SEA-8&&region>.2?Biome.FROZEN_RIVER:cold>.3?Biome.COLD_OCEAN:Biome.FROZEN_OCEAN;if(h<=SEA+2)return Biome.SNOWY_BEACH;if(h>155)return region>0?Biome.JAGGED_PEAKS:Biome.FROZEN_PEAKS;if(h>145)return region>.1?Biome.GROVE:Biome.SNOWY_SLOPES;if(cold<-.22)return frozenDesert();double forest=climate(seed^32171,x,z,1800);if(forest>.14)return Biome.OLD_GROWTH_SPRUCE_TAIGA;if(forest>.02)return Biome.OLD_GROWTH_PINE_TAIGA;if(forest>-.18)return Biome.SNOWY_TAIGA;if(region<-.4)return Biome.ICE_SPIKES;if(region>.3)return Biome.SNOWY_TAIGA;return h>105?(region>0?Biome.WINDSWEPT_HILLS:Biome.WINDSWEPT_GRAVELLY_HILLS):Biome.SNOWY_PLAINS;}
if(planet.equals("sigma_draconis_iv")){if(y<35&&sulfurPocket(seed,x,y,z)&&sulfurBiome()!=null)return sulfurBiome();if(islandDistance(seed,x,z)<OrdosSulfurRange.MUSHROOM_FIELDS_RADIUS)return Biome.MUSHROOM_FIELDS;if(ordosBadlands(seed,x,z))return region>.2?Biome.ERODED_BADLANDS:Biome.BADLANDS;double cold=climate(seed^974,x,z,1200);if(h<SEA-14)return cold>.3?Biome.DEEP_COLD_OCEAN:Biome.DEEP_FROZEN_OCEAN;if(h<SEA-2)return h>SEA-8&&region>.2?Biome.FROZEN_RIVER:cold>.3?Biome.COLD_OCEAN:Biome.FROZEN_OCEAN;if(h<=SEA+2)return Biome.SNOWY_BEACH;if(h>155)return region>0?Biome.JAGGED_PEAKS:Biome.FROZEN_PEAKS;if(h>145)return region>.1?Biome.GROVE:Biome.SNOWY_SLOPES;if(cold<-.22)return frozenDesert();double forest=climate(seed^32171,x,z,1800);if(forest>.14)return Biome.OLD_GROWTH_SPRUCE_TAIGA;if(forest>.02)return Biome.OLD_GROWTH_PINE_TAIGA;if(forest>-.18)return Biome.SNOWY_TAIGA;if(region<-.4)return Biome.ICE_SPIKES;if(region>.3)return Biome.SNOWY_TAIGA;return h>105?(region>0?Biome.WINDSWEPT_HILLS:Biome.WINDSWEPT_GRAVELLY_HILLS):Biome.SNOWY_PLAINS;}
if(planet.equals("giedi_prime")){region=climate(seed^321,x,z,1100);double zone=climate(seed^791,x,z,850);if(y< -16&&zone>.1)return Biome.DEEP_DARK;if(y<25&&zone<-.22)return Biome.DRIPSTONE_CAVES;if(h>140)return Biome.STONY_PEAKS;if(Math.abs(region)<.32&&zone<.25)return Biome.WINDSWEPT_GRAVELLY_HILLS;if(zone<-.4||region<-.55||region>.55)return Biome.WINDSWEPT_GRAVELLY_HILLS;if(zone>.25)return region>.1?Biome.ERODED_BADLANDS:region<-.1?Biome.WOODED_BADLANDS:Biome.BADLANDS;return Biome.PALE_GARDEN;}
if(planet.equals("caladan")){if(h>=SEA-4&&h<=SEA+1&&riverDistance(seed,x,z)<.018)return Biome.RIVER;if(y<35+layered(seed^431,x,z,140)*14&&h>SEA+4)return Biome.LUSH_CAVES;double wet=climate(seed^873,x,z,520),forest=climate(seed^681,x,z,640);if(h<40)return wet<-.15?Biome.DEEP_OCEAN:Biome.DEEP_LUKEWARM_OCEAN;if(h<SEA-2)return wet<-.15?Biome.LUKEWARM_OCEAN:Biome.WARM_OCEAN;if(h<=SEA+10&&wet>.18)return wet>.34?Biome.MANGROVE_SWAMP:Biome.SWAMP;if(h<=SEA+2)return Biome.STONY_SHORE;if(h>155)return Biome.STONY_PEAKS;if(h>115&&forest>.1)return Biome.WINDSWEPT_FOREST;if(forest<-.38)return Biome.OLD_GROWTH_BIRCH_FOREST;if(forest<-.12&&region<0)return Biome.FOREST;return region<-.4?Biome.CHERRY_GROVE:region>.35?Biome.BAMBOO_JUNGLE:forest>.3?Biome.SPARSE_JUNGLE:Biome.JUNGLE;}
if(h>=SEA-4&&h<=SEA+1&&riverDistance(seed,x,z)<.018)return Biome.RIVER;if(h<SEA-2)return Biome.OCEAN;if(h<=SEA+beachWidth(seed,x,z))return Biome.BEACH;double meadow=climate(seed^912,x,z,620);if(meadow>.3)return h>88?Biome.WINDSWEPT_SAVANNA:h>78?Biome.SAVANNA_PLATEAU:Biome.SAVANNA;if(region>.3)return Biome.DARK_FOREST;if(region<-.48)return Biome.CHERRY_GROVE;if(region<-.25)return Biome.TAIGA;if(meadow<-.38)return Biome.FLOWER_FOREST;if(meadow<-.15)return Biome.BIRCH_FOREST;if(h>87)return Biome.MEADOW;return meadow>.08?Biome.SUNFLOWER_PLAINS:Biome.PLAINS;

View file

@ -0,0 +1,31 @@
package com.example.duneterrain;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class OrdosSulfurRangeTest {
@Test void sulfurStopsAtTheMushroomFieldsEdge() {
assertTrue(OrdosSulfurRange.near(0));
assertTrue(OrdosSulfurRange.near(144.99));
assertFalse(OrdosSulfurRange.near(145));
assertFalse(OrdosSulfurRange.near(Double.POSITIVE_INFINITY));
}
@Test void realIslandGeometryAndOriginalVerticalLimitsBothConstrainSulfur() {
for (long seed = 0; seed < 2048; seed++) {
for (int x = 384; x <= 640; x += 32) {
for (int z = 384; z <= 640; z += 32) {
double distance = TemperateLandscape.islandDistance(seed, x, z);
boolean pocket = TemperateLandscape.sulfurPocket(seed, x, 0, z);
if (distance >= 145) assertFalse(pocket);
if (!pocket) continue;
assertFalse(TemperateLandscape.sulfurPocket(seed, x, -45, z));
assertFalse(TemperateLandscape.sulfurPocket(seed, x, 35, z));
return;
}
}
}
fail("Expected a sulfur pocket close to a real mushroom island");
}
}

View file

@ -0,0 +1,37 @@
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);
}
}

115
tools/reset-ordos-sulfur.py Normal file
View file

@ -0,0 +1,115 @@
"""Install the mushroom proximity guard and regenerate Ordos only."""
import argparse
import importlib.util
import json
from pathlib import Path
import re
import subprocess
import tempfile
from zipfile import ZIP_DEFLATED, ZipFile
from planet_ore_release import archive_names, sha
spec = importlib.util.spec_from_file_location('reset_planet_ores', Path(__file__).with_name('reset-planet-ores.py'))
reset = importlib.util.module_from_spec(spec)
spec.loader.exec_module(reset)
PLANET = 'sigma_draconis_iv'
UNIT = f'dune-{PLANET}.service'
TERRAIN = 'c1a564402a9cfea8be942d4945cdc55af36b7ffb441707ce683a177ab397494e'
PACK = '0116d155df34e6c9c0482c0f7e21404ea69ea1357819005acfdb110ab748b139'
LANDSCAPE = 'com/example/duneterrain/TemperateLandscape.class'
RANGE = 'com/example/duneterrain/OrdosSulfurRange.class'
ASSETS = {'OrdosSulfurRange.class', 'OrdosSulfurTransition.java', 'planet_ore_release.py',
'reset-planet-ores.py', 'reset-ordos-sulfur.py', 'SOURCE_COMMIT'}
def assemble(baseline, bundle, candidate, java):
if sha(baseline) != TERRAIN:
raise ValueError('Expected the exact retained Ordos Terrain')
with ZipFile(baseline) as original, tempfile.TemporaryDirectory() as temp:
if RANGE in archive_names(original):
raise ValueError('Ordos sulfur guard is already installed')
previous, updated = Path(temp) / 'previous.class', Path(temp) / 'candidate.class'
previous.write_bytes(original.read(LANDSCAPE))
subprocess.run([java, str(bundle / 'OrdosSulfurTransition.java'), str(previous), str(updated)], check=True)
with ZipFile(candidate, 'x', ZIP_DEFLATED) as incoming:
for entry in original.infolist():
incoming.writestr(entry, updated.read_bytes() if entry.filename == LANDSCAPE else original.read(entry))
incoming.writestr(RANGE, (bundle / 'OrdosSulfurRange.class').read_bytes())
verify_candidate(baseline, bundle, candidate)
def verify_candidate(baseline, bundle, candidate):
with ZipFile(baseline) as original, ZipFile(candidate) as incoming:
names = archive_names(original)
if archive_names(incoming) != names | {RANGE}:
raise ValueError('Unexpected assembled Ordos Terrain entries')
if incoming.read(LANDSCAPE) == original.read(LANDSCAPE):
raise ValueError('Ordos sulfur selector was not updated')
if incoming.read(RANGE) != (bundle / 'OrdosSulfurRange.class').read_bytes():
raise ValueError('Sulfur guard differs from the canonical build')
if any(incoming.read(name) != original.read(name) for name in names - {LANDSCAPE}):
raise ValueError('Unrelated Ordos Terrain entry changed')
def run(bundle, source, candidate, candidate_hash, apply, receipt):
root = reset.checked(reset.ROOT / PLANET)
if reset.state(UNIT) != 'active' or reset.service('show', UNIT, '--property=WorkingDirectory', '--value') != str(root):
raise ValueError('Unexpected Ordos service or working directory')
before = reset.snapshot_server(root)
existing = [name for name, details in before['jars'].items() if details[0] == TERRAIN]
if before['settings'].get('level-name') != PLANET or len(existing) != 1:
raise ValueError('Expected Ordos primary world and exact installed Terrain')
if not re.search(rf'^\s+generator:\s*[\'\"]?DuneTerrain:{PLANET}[\'\"]?\s*$', (root / 'bukkit.yml').read_text(), re.M):
raise ValueError('Expected the retained Ordos generator')
world = reset.checked(root / PLANET)
if reset.fingerprint(world / reset.PACK)[0] != PACK:
raise ValueError('Expected the currently deployed Ordos ore palette pack')
dimension = reset.checked(world / reset.DIMENSION)
identity = {name: reset.fingerprint(dimension / name) for name in reset.IDENTITY}
target = root / 'plugins' / existing[0]
previous = {target: reset.fingerprint(target)}
if not re.fullmatch(r'[0-9a-f]{64}', candidate_hash) or reset.fingerprint(candidate)[0] != candidate_hash:
raise ValueError('Assembled Terrain differs from the independently reviewed candidate hash')
verify_candidate(target, bundle, candidate)
report = {'source': source, 'planet': PLANET, 'world': str(world), 'unit': UNIT,
'identity': identity, 'incoming': {str(target): candidate_hash},
'chunkFileCount': len(reset.chunk_files(dimension)), 'status': 'planned'}
if not apply:
return report
return reset.apply_transition(root, world, dimension, UNIT, before, identity, previous,
{target: candidate}, report, receipt)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--bundle', required=True, type=Path)
parser.add_argument('--expected-source', required=True)
parser.add_argument('--candidate', required=True, type=Path)
parser.add_argument('--candidate-sha256')
parser.add_argument('--assemble-from', type=Path)
parser.add_argument('--java', default='java')
parser.add_argument('--apply-reset-no-backup', action='store_true')
parser.add_argument('--receipt', type=Path)
args = parser.parse_args()
reset.verify_bundle(reset.checked(args.bundle), args.expected_source, ASSETS)
if args.assemble_from is not None:
if args.apply_reset_no_backup or args.receipt is not None:
parser.error('Assembly is a separate offline operation')
assemble(args.assemble_from, args.bundle, args.candidate, args.java)
print(sha(args.candidate))
else:
if args.candidate_sha256 is None or args.apply_reset_no_backup != (args.receipt is not None):
parser.error('Planning requires a candidate hash; apply also requires a private receipt path')
params = (args.bundle, args.expected_source, args.candidate, args.candidate_sha256)
if args.apply_reset_no_backup:
import fcntl
with Path('/run/lock/dunerealms-planet-ore-reset.lock').open('a') as lock:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
result = run(*params, True, args.receipt)
else:
result = run(*params, False, None)
print(json.dumps(result, indent=2))