Target rarer natural spawns in the parity harness

Desert, snowy, swamp and jungle nights, lush, sulfur and dripstone caves,
warm and frozen oceans, crimson forests and slime chunks. A cube mob grown
by finalizeSpawn takes its constructor's head rotation from the entity's
unseeded random (AbstractCubeMob.onSyncedDataUpdated), so that yaw alone is
not compared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-11 16:14:22 +02:00
parent b2812c55be
commit 6949ca4455
3 changed files with 94 additions and 10 deletions
@@ -342,8 +342,15 @@ fn parse_state(spec: &str) -> BlockState {
fn bits(v: f64) -> String {
format!("{:x}", v.to_bits())
}
fn fbits(v: f32) -> String {
format!("{:x}", v.to_bits())
/// The yaw as the oracle prints it: a cube mob grown by `finalizeSpawn`
/// (sulfur cubes, size 2 under the fixed random) takes its constructor's
/// head rotation from the entity's unseeded random.
fn yaw_text(entity: &str, v: f32) -> String {
if entity == "minecraft:sulfur_cube" {
"head".to_owned()
} else {
format!("{:x}", v.to_bits())
}
}
fn main() -> horizon_client::Result<()> {
@@ -581,7 +588,7 @@ fn main() -> horizon_client::Result<()> {
bits(p[0]),
bits(p[1]),
bits(p[2]),
fbits(yaw)
yaw_text(&t, yaw)
)),
},
);
@@ -638,7 +645,7 @@ fn main() -> horizon_client::Result<()> {
bits(p[0]),
bits(p[1]),
bits(p[2]),
fbits(yaw)
yaw_text(&t, yaw)
),
})
};
@@ -302,6 +302,15 @@ public final class VanillaNaturalSpawnOracle {
}
static String bits(double v) { return Long.toHexString(Double.doubleToRawLongBits(v)); }
/**
* A spawned mob's yaw. A cube mob whose size finalizeSpawn changed took its
* constructor's head rotation (AbstractCubeMob.onSyncedDataUpdated), drawn
* from the entity's own unseeded random: not reproducible, so not compared.
*/
static String yaw(Entity e) {
if (e instanceof net.minecraft.world.entity.monster.cubemob.AbstractCubeMob cube && cube.getSize() != 1) return "head";
return bits(e.getYRot());
}
static String bits(float v) { return Integer.toHexString(Float.floatToRawIntBits(v)); }
public static void main(String[] args) throws Exception {
@@ -476,7 +485,7 @@ public final class VanillaNaturalSpawnOracle {
level.logColumns = false;
for (Entity e : level.entities.subList(n, level.entities.size()))
if (e.getVehicle() == null)
log.add("spawn " + BuiltInRegistries.ENTITY_TYPE.getKey(e.getType()) + " " + bits(e.getX()) + " " + bits(e.getY()) + " " + bits(e.getZ()) + " " + bits(e.getYRot()));
log.add("spawn " + BuiltInRegistries.ENTITY_TYPE.getKey(e.getType()) + " " + bits(e.getX()) + " " + bits(e.getY()) + " " + bits(e.getZ()) + " " + yaw(e));
log.add("next " + random.nextInt(1000));
} else {
Map<Long, Chunk> chunks = new HashMap<>();
@@ -501,7 +510,7 @@ public final class VanillaNaturalSpawnOracle {
} catch (Exception ex) { throw new RuntimeException(ex); }
};
NaturalSpawner.AfterSpawnCallback after = (mob, ch) -> {
log.add("spawn " + BuiltInRegistries.ENTITY_TYPE.getKey(mob.getType()) + " " + bits(mob.getX()) + " " + bits(mob.getY()) + " " + bits(mob.getZ()) + " " + bits(mob.getYRot()));
log.add("spawn " + BuiltInRegistries.ENTITY_TYPE.getKey(mob.getType()) + " " + bits(mob.getX()) + " " + bits(mob.getY()) + " " + bits(mob.getZ()) + " " + yaw(mob));
try { afterSpawn.invoke(state, mob, ch); } catch (Exception ex) { throw new RuntimeException(ex); }
};
if (mode.equals("pos")) {
+72 -4
View File
@@ -75,11 +75,13 @@ OVERWORLD = {
'minecraft:pale_garden': ('minecraft:grass_block', 'minecraft:dirt'),
'minecraft:grove': ('minecraft:snow_block', 'minecraft:dirt'),
'minecraft:snowy_slopes': ('minecraft:snow_block', 'minecraft:stone'),
'minecraft:savanna_plateau': ('minecraft:grass_block', 'minecraft:dirt'),
'minecraft:eroded_badlands': ('minecraft:red_sand', 'minecraft:terracotta'),
}
OCEANS = ['minecraft:ocean', 'minecraft:deep_ocean', 'minecraft:warm_ocean', 'minecraft:lukewarm_ocean',
'minecraft:deep_lukewarm_ocean', 'minecraft:cold_ocean', 'minecraft:deep_cold_ocean',
'minecraft:frozen_ocean', 'minecraft:deep_frozen_ocean', 'minecraft:river', 'minecraft:frozen_river']
CAVES = ['minecraft:lush_caves', 'minecraft:dripstone_caves', 'minecraft:deep_dark']
CAVES = ['minecraft:lush_caves', 'minecraft:dripstone_caves', 'minecraft:deep_dark', 'minecraft:sulfur_caves']
NETHER = {
'minecraft:nether_wastes': 'minecraft:netherrack',
'minecraft:crimson_forest': 'minecraft:crimson_nylium',
@@ -107,6 +109,26 @@ CATEGORIES = ['monster', 'creature', 'ambient', 'axolotls', 'underground_water_c
TORCH_LIGHT = [0, 0, 0, 1, 4, 7, 8, 9, 12, 14]
def java_next_int(seed, bound):
"""java.util.Random(seed).nextInt(bound)."""
mask = (1 << 48) - 1
state = (seed ^ 0x5DEECE66D) & mask
while True:
state = (state * 0x5DEECE66D + 0xB) & mask
bits = state >> 17
value = bits % bound
if bits - value + bound - 1 < 2**31:
return value
def slime_chunk(world_seed, cx, cz):
"""WorldgenRandom.seedSlimeChunk(cx, cz, seed, 987234911).nextInt(10) == 0."""
def i32(v):
return (v + 2**31) % 2**32 - 2**31
seed = (world_seed + i32(cx * cx * 4987142) + i32(cx * 5947611) + i32(cz * cz) * 4392871 + i32(cz * 389711)) ^ 987234911
return java_next_int(seed & (2**64 - 1), 10) == 0
def box(x0, y0, z0, x1, y1, z1):
return f'{x0},{y0},{z0},{x1},{y1},{z1}'
@@ -396,14 +418,14 @@ def common(w, rng, seed):
w.kv['unloaded'] = ';'.join(f'{rng.choice([-1, 0, 1])},{rng.choice([-1, 0, 1])}' for _ in range(rng.randrange(1, 5)))
def make_world(rng, seed, dim=None):
def make_world(rng, seed, dim=None, biome=None, ocean=None):
w = World(rng)
dim = dim or rng.choices(['overworld', 'nether', 'end'], [70, 22, 8])[0]
if dim == 'overworld':
overworld(w, rng)
overworld(w, rng, biome=biome, ocean=ocean)
elif dim == 'nether':
w.min_y = 0
nether(w, rng)
nether(w, rng, biome=biome)
else:
w.min_y = 0
end(w, rng)
@@ -449,6 +471,52 @@ def corpus():
if rng.random() < 0.05:
category = rng.choice(CATEGORIES)
cases.append(f'pos/{k} mode=pos cat={category} start={x},{y},{z} {w.tokens()}')
# Targeted nights and places for the rarer types.
targets = [
('minecraft:desert', False, 'surface', 'monster'), ('minecraft:desert', False, 'surface', 'creature'),
('minecraft:snowy_plains', False, 'surface', 'monster'), ('minecraft:ice_spikes', False, 'surface', 'creature'),
('minecraft:swamp', False, 'surface', 'monster'), ('minecraft:mangrove_swamp', False, 'surface', 'monster'),
('minecraft:jungle', False, 'surface', 'monster'), ('minecraft:bamboo_jungle', False, 'surface', 'monster'),
('minecraft:plains', False, 'surface', 'monster'), ('minecraft:savanna', False, 'surface', 'creature'),
('minecraft:badlands', False, 'surface', 'creature'), ('minecraft:warm_ocean', True, 'water', 'water_ambient'),
('minecraft:lukewarm_ocean', True, 'water', 'water_creature'), ('minecraft:deep_ocean', True, 'water', 'monster'),
('minecraft:frozen_ocean', True, 'water', 'creature'), ('minecraft:lush_caves', None, 'cave', 'axolotls'),
('minecraft:sulfur_caves', None, 'cave', 'monster'), ('minecraft:dripstone_caves', None, 'cave', 'monster'),
('minecraft:crimson_forest', 'nether', 'surface', 'monster'), ('slime', None, 'cave', 'monster'),
('minecraft:river', True, 'water', 'monster'),
]
for k in range(4000):
biome, ocean, kind, category = rng.choice(targets)
if ocean == 'nether':
w = make_world(rng, rng.randrange(-2**47, 2**47), dim='nether', biome=biome)
elif kind == 'cave':
w = make_world(rng, rng.randrange(-2**47, 2**47), dim='overworld', ocean=False)
else:
w = make_world(rng, rng.randrange(-2**47, 2**47), dim='overworld', biome=biome, ocean=ocean)
w.kv['darken'] = 11 if category == 'monster' else rng.choice([0, 0, 4, 11])
w.kv.pop('thunder', None)
sites = [t for t in w.sites if t[3] == kind] or w.sites
x, y, z, _ = rng.choice(sites)
if kind == 'cave':
# A dark room under the start, in the cave biome (or a slime chunk).
w.block(box(x - 6, y, z - 6, x + 6, y + 4, z + 6), 'minecraft:cave_air')
floor = 'minecraft:clay' if category == 'axolotls' else rng.choice(['minecraft:stone', 'minecraft:deepslate'])
w.block(box(x - 6, y - 1, z - 6, x + 6, y - 1, z + 6), floor)
if category == 'axolotls' or biome == 'minecraft:dripstone_caves' and rng.random() < 0.5:
w.block(box(x - 6, y, z - 6, x + 6, y + 2, z + 6), 'minecraft:water')
w.light(box(x - 6, y, z - 6, x + 6, y + 4, z + 6), 0, rng.choice([0, 0, 0, 3]))
if biome == 'slime':
y = min(y, rng.randrange(-50, 38))
w.block(box(x - 6, y, z - 6, x + 6, y + 4, z + 6), 'minecraft:cave_air')
w.block(box(x - 6, y - 1, z - 6, x + 6, y - 1, z + 6), 'minecraft:stone')
w.light(box(x - 6, y, z - 6, x + 6, y + 4, z + 6), 0, 0)
while not slime_chunk(w.kv['wseed'], 0, 0):
w.kv['wseed'] = rng.randrange(-2**63, 2**63)
else:
w.biomes.append(f'{box(x - 8, y - 3, z - 8, x + 8, y + 6, z + 8)}/{biome}')
if biome in ('minecraft:swamp', 'minecraft:mangrove_swamp'):
w.kv['slime'] = rng.choice([0.0, 0.25, 0.5])
cases.append(f'target/{k} mode=pos cat={category} start={x},{y},{z} {w.tokens()}')
# Chunk generation: creature packs placed on the surface.
for k in range(1500):
w = World(rng)