Match weighted model choice and multipart random consumption
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"minecraft": "26.3",
|
||||
"manifest_sha1": "4fe1aa1ef8da1cb95c5bad1fb98890ca56dd8ca3",
|
||||
"platform": "Linux-7.0.0-31-generic-x86_64-with-glibc2.43",
|
||||
"java": "openjdk 25.0.4.1 2026-08-18",
|
||||
"rustc": "rustc 1.99.0 (b940084d7 2026-09-28)",
|
||||
"bundled_weight_vectors": 7,
|
||||
"fixtures": 6960,
|
||||
"collections": 111360,
|
||||
"sources_sha256": {
|
||||
"mods/horizon/src/test/java/dev/horizonlab/parity/VanillaModelChoiceOracle.java": "2fa964aab1b822e1d61a856cdbe89075c390c68e0ededdd5f1dd65cf9759f27b",
|
||||
"mods/horizon/src/test/java/dev/horizonlab/parity/VanillaCuboidModelOracle.java": "7526f20513c549483122ab0d5ad24b9e87f38dc2f6aae55addd701a91ac85e43",
|
||||
"tools/test_model_choice_parity.py": "ea7d35684dc62fad4a6a3990e116d224059172021f62723b1e73b18e0232d966",
|
||||
"tools/test_model_baking_parity.py": "392ffec44918fb91740ca4a1316d684480d39f14bd34d46175f7f44946d15bd7",
|
||||
"tools/test_cuboid_model_parity.py": "4a8b1cdcac335751c23413341ae939eea1c49c38d33d70d0708b8904ab8d0461",
|
||||
"tools/lab.py": "d00bf107fa01b6c579734a082c3ca4ade3018f0d6851d46844acf17574f66e64",
|
||||
"tools/test_rust_parity.py": "29d3db08005873528894b45ca10dcd6278753650473b3eb574e53e06ede40ec6",
|
||||
"Cargo.toml": "3f93319c1eb70dbd7ba25cd74ef343fbf35c52c7c4752f955605c58699cbff9d",
|
||||
"Cargo.lock": "cb1e87d449114a63edd904c0559d631e8fa9feeb27efd6539aacdcfeae178876",
|
||||
"crates/horizon-assets/Cargo.toml": "2f2cffacec0b4e22dd7cb032d594289bc51c94ae6cc4e985fee3e310f441d751",
|
||||
"crates/horizon-core/Cargo.toml": "e21b502c949da93cf67826592459b687a8cbf737ef92fee514e3ed2cc7cd27ad",
|
||||
"crates/horizon-assets/examples/blockstate_binding_fixture.rs": "e58fdb432f6bfc1e400729baa9b48d4f00955b3143b98b52506b47dd8b065cf8",
|
||||
"crates/horizon-assets/examples/blockstate_model_fixture.rs": "8f063322e57abdf9361a5a3a3badce2a7e727ee6d5e3947071cb448dfb38e8fd",
|
||||
"crates/horizon-assets/examples/cuboid_model_fixture.rs": "97609d90e3f6ce340f3590296db2dc778113bb2b33c7d1b54080a1d6f3023f40",
|
||||
"crates/horizon-assets/examples/model_baking_fixture.rs": "59caca09dd5afd0b70a2e8fdb8e949deb9322f00adc617918b33d1e7e5b0b522",
|
||||
"crates/horizon-assets/examples/model_choice_fixture.rs": "a4c8a46501d2b5ae7051f10f2307ade048e96c2d330af51cd2431bb44977a99a",
|
||||
"crates/horizon-assets/examples/model_resolution_fixture.rs": "c071067140299e49345a6ebd94e15b3b6d853cb9ae11d8de46e3cbdfb8b01f0e",
|
||||
"crates/horizon-assets/examples/sprite_animation_fixture.rs": "254314d52deda129ab461221d3d8b95323a60730d374e566c1cd599fba85f072",
|
||||
"crates/horizon-assets/examples/support/mod.rs": "bcf5a6d8a54845982191e037911c24139237771d6afa4b01b1e83c011489c3f5",
|
||||
"crates/horizon-assets/src/animation.rs": "ebbf7952146a0e66b41396174492f5702627170b03a57e6cd5a45c97a08c975e",
|
||||
"crates/horizon-assets/src/bake.rs": "0bc519e93ad8200d89543ceb5c811dd82bbeb0e9003b143385c8a03e758dfe65",
|
||||
"crates/horizon-assets/src/blockstate/bind.rs": "6278962e55c9786bba8184bdf2939af9c6e3b9002b08c3022129964b49a60009",
|
||||
"crates/horizon-assets/src/blockstate/choice.rs": "5a66c8b9833e2f19dd8b0773f3593d97ff5941d3c5b773896b98049efa1395ba",
|
||||
"crates/horizon-assets/src/blockstate.rs": "a4299dfd7adaeb4173982ffaa8e9c9eda2925739ae579a714193c99da2e7ce56",
|
||||
"crates/horizon-assets/src/json.rs": "99fe8af4fbf5d4eed408a92e829ac1a39597a0d92471a6bff73771fad9c830a8",
|
||||
"crates/horizon-assets/src/lib.rs": "e39f21c59a2c3e1c53d977b29bd5e0638e5fc41d86ff0fcc1882a6d90fd961e4",
|
||||
"crates/horizon-assets/src/model.rs": "57ddb3d65e88e7a8aa22c62bc298a2dae7f4e994326a873a31f06c0f36ed051b",
|
||||
"crates/horizon-assets/src/resolve.rs": "3927ac926cdcbd7d334901cc32d0ecc1e498b1bec98f76a46bca6d4964c13541",
|
||||
"crates/horizon-core/src/bin/density_parity.rs": "e5b1dd33b7d01306c73cf072629b4fb186e9ab87b672a00108999d1a72263fd0",
|
||||
"crates/horizon-core/src/bin/float_log_parity.rs": "4a655fcf8822ee7668c4bd126bc84d0b118864a6fc7f5a6aeee667d8bf2590b1",
|
||||
"crates/horizon-core/src/bin/geometry_parity.rs": "27f6c09fe5018ac3de8e70e0f0bbf78f9abb14f5e4783bcaf46e8ca87b9c6f8a",
|
||||
"crates/horizon-core/src/bin/noise_parity.rs": "c135bfc708d853e7061e81487d2cfe10de64b2f65677d3b4837cbfe0b8341010",
|
||||
"crates/horizon-core/src/bin/parity.rs": "f35d928c66f958de39fac5e7e836a657eed95f83599e84899f7ea7a5802ba481",
|
||||
"crates/horizon-core/src/bin/tick_parity.rs": "a54c164fe4814034d369947a887f5273966f5a878ba849204b80d1c729526a8f",
|
||||
"crates/horizon-core/src/biome/seed_hash.rs": "5afbb4921c750826b395a08bf06f382fc7f01b5759a93de02a2749c523e2a317",
|
||||
"crates/horizon-core/src/biome.rs": "908efa8cd4aa0a7adf1cb5e1a222e3dfb640eed5e9172e0fe7f0d1287afae7e8",
|
||||
"crates/horizon-core/src/carving/ellipsoid.rs": "09232a7588610e8a9176fd9c62d40afb1fb89f2ecab6d555536a1d847b142d86",
|
||||
"crates/horizon-core/src/carving.rs": "0aa3093caa0437868a8c0ed52a6c6e1993bd51c03583c670a2837e749eae5426",
|
||||
"crates/horizon-core/src/density/arithmetic.rs": "372faec96c923e2cf4aa6c66c1ac398e676853274557823850dbc8933dd15ab1",
|
||||
"crates/horizon-core/src/density/beardifier.rs": "bb1052e27dae4a01954ca78d7d5babafef85f3b2c704ccaf1920cb85a098cb50",
|
||||
"crates/horizon-core/src/density/cache.rs": "38d0b6c9dd04ffef979fdad3f29cfebf98d331c8c9d430be5f39aa34f6c30975",
|
||||
"crates/horizon-core/src/density/end_islands.rs": "168b9384237bd2e41d0ae5a74e944da4dc74e493bdec31fb73184c9a49e3de55",
|
||||
"crates/horizon-core/src/density/graph/compiler.rs": "ac67deeb16f16d0859aa20e5a165811a29aca0b910037ee6bf5098211f3a6ede",
|
||||
"crates/horizon-core/src/density/graph/mod.rs": "b776e7da934cb03051a3053d56d461c71e9978e084922fe4194147aa580c07bf",
|
||||
"crates/horizon-core/src/density/graph/seeded.rs": "6bcdcaa3dffcfa9df673bbbea35120057a16ba3d2b506c52709c36cf8976b74a",
|
||||
"crates/horizon-core/src/density/graph/tests.rs": "6bfb8cbff462587dd147b0775ea01d370abbd97544b9bd596c792df1b5f7e634",
|
||||
"crates/horizon-core/src/density/interpolation.rs": "8c890f52b6467f38a94c654986a6a484b8e0b296ab98c398e60a6ce465b5b010",
|
||||
"crates/horizon-core/src/density/interval.rs": "b42629163baa6b599a233afe8596d1c370cd81d015cc6fc36a9663aa47b98424",
|
||||
"crates/horizon-core/src/density/mod.rs": "ca0d77d3282e3746ddcbc92bee97dbf640b9a56214e6ac1537f51f9a5b63d6e7",
|
||||
"crates/horizon-core/src/density/power.rs": "d5b7270a128d4264268cd772109ad16d71a8ec3ff2d3b63b84cb985296d54a91",
|
||||
"crates/horizon-core/src/density/rounding.rs": "71840c5206ff8d218ac29bf6f66915d5212764ba270c675711a866ba5b55a7a6",
|
||||
"crates/horizon-core/src/density/selection.rs": "0dd26af2e85004ec5e053039ad11c384c17c56ace9ab45eb3f5cb3503c0b0330",
|
||||
"crates/horizon-core/src/density/slice.rs": "5d77605573c0deda47778f1f78f7fa3fbf1944d8f5efbcc65cf589181cadf80b",
|
||||
"crates/horizon-core/src/density/spline.rs": "6bb2e40f940fc6544d6fb09cb0b8cac722be03bc663dbdfb0f61faae207400bc",
|
||||
"crates/horizon-core/src/density/surface.rs": "159e0e69cda74f870e80ea64fe523c4397e64af4ccb861bb9fd07b2c3cb91b00",
|
||||
"crates/horizon-core/src/density/terrain_noise.rs": "8d0059d25eb5d248cb97a4c5a2e670d61528928ea151495c004f25adb723fe3e",
|
||||
"crates/horizon-core/src/density/tests.rs": "7817796ee40d0ae241bfbebec6bca190e0a8e7d5a1caa8ddf858c3eaa58b8858",
|
||||
"crates/horizon-core/src/density/world_fields.rs": "c1ce305cb8046b384d90c564cafb24af7365d580389637910f3d8b0cc18eb583",
|
||||
"crates/horizon-core/src/geometry/mod.rs": "dc92f73885dd0a7760743bf74f1ab8afa839d61cef2dfef890f8a23b67b4742e",
|
||||
"crates/horizon-core/src/geometry/movement.rs": "930e34abef6f6eeec1ee7a6c920b5ba01bfe37b90678884490f4be53241f6b96",
|
||||
"crates/horizon-core/src/geometry/shape/create.rs": "189812b91d5e0e3ad963afcd1a6e2831b31b8188df91a904ef27061e644806ad",
|
||||
"crates/horizon-core/src/geometry/shape/face.rs": "f243bce81384040a95ce7984b02b5699206c596c537b2713097e86005b4d3a5c",
|
||||
"crates/horizon-core/src/geometry/shape/join.rs": "f1b51887b7bf9482557e3ffa99e136f2e5db07ceeb05fdb116adf45e87129075",
|
||||
"crates/horizon-core/src/geometry/shape.rs": "e8d88a763de1525f77a30b99591641e8a8b80946263acbde035a9bcc356df960",
|
||||
"crates/horizon-core/src/geometry/sweep.rs": "abd6009c61555161ef2f18b431b2aa384b126c0871cae8b96a62358498a56a1d",
|
||||
"crates/horizon-core/src/geometry/traversal.rs": "77a3da570a0b85582b669cf4d841cba4b06327006dda26d4a26df4e8ce05bae4",
|
||||
"crates/horizon-core/src/geometry/trig.rs": "05cef9341a298a474221a0556a11ddf47650393ea7a97b4b2022a4da6628fe37",
|
||||
"crates/horizon-core/src/lib.rs": "4255e16837fde42a52ba118f60581d197c571bb530b60d635e506184ebf4db0b",
|
||||
"crates/horizon-core/src/noise/mod.rs": "1dab5a713abf702402e69ace1bf9e476bba544b0ede5a61c3c3afc60af0a03f3",
|
||||
"crates/horizon-core/src/noise/normal.rs": "e9e7a46472a54a02c98c46da819842090567153b32fe0c84249009ef19af7aad",
|
||||
"crates/horizon-core/src/noise/perlin.rs": "e73815447432eab7542f67366cb3f1b368d164e33f6c9cdbd045ac8e4db0932a",
|
||||
"crates/horizon-core/src/noise/simplex.rs": "6c0dbc15b2b7510195dd28fceca01dcaac1847ccc4a84d299c351589c642fe7a",
|
||||
"crates/horizon-core/src/noise/stack.rs": "7f6ef0e7d920139ef1a6ad3ec5640f92765715f86dcc5ec29f1a149984f45fa3",
|
||||
"crates/horizon-core/src/noise/volume.rs": "3f05d2b1780acfdfee60037677d309937a5033b45ef428fc2d540942d4b56b43",
|
||||
"crates/horizon-core/src/position/iter.rs": "32d2d8e74821cc4e49e3354202d35d3120e4415bfdda9375a73f2137ef651129",
|
||||
"crates/horizon-core/src/position.rs": "e10101088e6902386b9b6d27773d44312f1ff72bebb19e57967a54945dde9dcd",
|
||||
"crates/horizon-core/src/random/hash.rs": "0f88a127a1ba2705d3d6c0ebd009324d6ba86ffa2d27edf2d2a84765e690e4a3",
|
||||
"crates/horizon-core/src/random/positional.rs": "35494745e5d4cf89e282c3ae0ee245e9f2640ddbbc03bc0055df742006a9c862",
|
||||
"crates/horizon-core/src/random/worldgen.rs": "9f07ff33bcc038d34e27aa5465753bb21df18f2975e43cae201f709bc186945a",
|
||||
"crates/horizon-core/src/random.rs": "ddb95d3a83e28ad605ff1f49f5df270cc543ca5ef1130e37d989dc74c8d861e6",
|
||||
"crates/horizon-core/src/storage.rs": "f6c32201c64aefde06e57a2c767be46918df613548a322801546b133799cc33d",
|
||||
"crates/horizon-core/src/text.rs": "e6553ddb5db5039e8dc4614b6a6dc9f35a26dc3d1673b68a04e72e7983b67abb",
|
||||
"crates/horizon-core/src/ticks/generation.rs": "be1237e790693f633a61714ddae68c6506a777588a8a3ab5efbe53a35774dbd2",
|
||||
"crates/horizon-core/src/ticks/heap.rs": "bf28afab8af77c3d243aa96cd8a1fb8d934140a4dbd07dbfdbf4e7908bb4b845",
|
||||
"crates/horizon-core/src/ticks/index.rs": "1f1a6a568c2a30eafecb020ca4d5f5fc414860de85b8b381fc419a2e3e65c24a",
|
||||
"crates/horizon-core/src/ticks/mod.rs": "01634630668172516b8b79d0907bad47f6e2c543a6d499c2fa4b201823b375cb"
|
||||
},
|
||||
"fixtures_sha256": {
|
||||
".local/rust-model-choice-parity/inputs.jsonl": "493a8bbd1f9b837401d4ed89df530af253163ed4fc90270fefa3b7d1c9f25c10"
|
||||
},
|
||||
"rust_output_sha256": "d5bb4226fa3f927e4d3dfda4b6cb6746018d7443d2965e3c921693dbdfd31262",
|
||||
"references": [
|
||||
{
|
||||
"side": "client",
|
||||
"jar_sha256": "4508d006323f24fa02876310c192d739af56516eb259000ac50f0909a68c9a2d",
|
||||
"output_sha256": "d5bb4226fa3f927e4d3dfda4b6cb6746018d7443d2965e3c921693dbdfd31262",
|
||||
"matched_output_lines": 6960
|
||||
}
|
||||
],
|
||||
"scope": "Actual WeightedVariants.collectParts and MultiPartModel.collectParts with inert observable leaf models and preselected boolean conditions. Every distinct bundled blockstate weight vector plus synthetic singletons, large totals, empty/partial multipart subsets and random graphs. Legacy and xoroshiro streams, six seeds per graph, repeated collection and subsequent nextLong/nextInt verify model choice and draw consumption. No actual model baking, material evaluation, transformed quads, renderer integration or gameplay parity claim."
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
use horizon_assets::blockstate::{
|
||||
BlockStateDefinition, Selector, Variant, VariantSet, bind::SelectedModels,
|
||||
choice::CompiledChoices,
|
||||
};
|
||||
use horizon_core::random::{LegacyRandom, RandomSource, XoroshiroRandom};
|
||||
use serde_json::{Value, json};
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader, BufWriter, Write},
|
||||
};
|
||||
fn choice(value: &Value, index: usize) -> VariantSet {
|
||||
let variant = |suffix| Variant {
|
||||
model: format!("horizon:part{index}_{suffix}"),
|
||||
rotations: [0; 3],
|
||||
uv_lock: false,
|
||||
};
|
||||
if value.is_null() {
|
||||
VariantSet::Single(variant("single".to_owned()))
|
||||
} else {
|
||||
VariantSet::Weighted(
|
||||
value
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, w)| (variant(format!("variant{i}")), w.as_i64().unwrap() as i32))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
fn trace(
|
||||
mut random: impl RandomSource,
|
||||
compiled: &CompiledChoices,
|
||||
selected: &SelectedModels,
|
||||
repeats: u64,
|
||||
) -> Result<Value, Box<dyn std::error::Error>> {
|
||||
let mut result = Vec::new();
|
||||
let mut output = Vec::new();
|
||||
for _ in 0..repeats {
|
||||
output.clear();
|
||||
compiled.collect(selected, &mut random, &mut output)?;
|
||||
result.push(json!({"models":output.iter().map(|v|&v.model).collect::<Vec<_>>(),"next_long":random.next_long(),"next_int":random.next_int()}));
|
||||
}
|
||||
Ok(json!(result))
|
||||
}
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let input = BufReader::new(File::open(&args[1])?);
|
||||
let mut output = BufWriter::new(File::create(&args[2])?);
|
||||
for line in input.lines() {
|
||||
let row: Value = serde_json::from_str(&line?)?;
|
||||
let parts = row["parts"].as_array().unwrap();
|
||||
let (definition, selected) = if row["multipart"].as_bool().unwrap() {
|
||||
(
|
||||
BlockStateDefinition {
|
||||
variants: None,
|
||||
multipart: Some(
|
||||
parts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, v)| Selector {
|
||||
condition: None,
|
||||
variant: choice(v, i),
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
},
|
||||
SelectedModels::Multipart(
|
||||
row["selected"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|v| v.as_u64().unwrap() as usize)
|
||||
.collect(),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
BlockStateDefinition {
|
||||
variants: Some(vec![(String::new(), choice(&parts[0], 0))]),
|
||||
multipart: None,
|
||||
},
|
||||
SelectedModels::Variant(0),
|
||||
)
|
||||
};
|
||||
let compiled = CompiledChoices::new(&definition)?;
|
||||
let seed = row["seed"].as_i64().unwrap();
|
||||
let repeats = row["repeats"].as_u64().unwrap();
|
||||
let result = if row["random"] == "legacy" {
|
||||
trace(LegacyRandom::new(seed), &compiled, &selected, repeats)?
|
||||
} else {
|
||||
trace(XoroshiroRandom::new(seed), &compiled, &selected, repeats)?
|
||||
};
|
||||
writeln!(output, "{}", json!({"name":row["name"],"trace":result}))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Pinned blockstate resource definitions, before registry binding and baking.
|
||||
pub mod bind;
|
||||
pub mod choice;
|
||||
use crate::json::*;
|
||||
use serde::{
|
||||
Deserializer,
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
//! Prepared model choices with vanilla random draw consumption.
|
||||
use super::{BlockStateDefinition, Variant, VariantSet, bind::SelectedModels};
|
||||
use crate::json::{Result, error};
|
||||
use horizon_core::random::RandomSource;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum Choice {
|
||||
Single(Variant),
|
||||
Weighted {
|
||||
variants: Vec<Variant>,
|
||||
ends: Vec<i32>,
|
||||
total: i32,
|
||||
},
|
||||
}
|
||||
impl Choice {
|
||||
fn new(value: &VariantSet) -> Result<Self> {
|
||||
match value {
|
||||
VariantSet::Single(value) => Ok(Self::Single(value.clone())),
|
||||
VariantSet::Weighted(entries) => {
|
||||
let mut total = 0i32;
|
||||
let mut ends = Vec::with_capacity(entries.len());
|
||||
let mut variants = Vec::with_capacity(entries.len());
|
||||
for (variant, weight) in entries {
|
||||
if *weight <= 0 {
|
||||
return Err(error("nonpositive model weight"));
|
||||
}
|
||||
total = total
|
||||
.checked_add(*weight)
|
||||
.ok_or_else(|| error("model weight overflow"))?;
|
||||
ends.push(total);
|
||||
variants.push(variant.clone());
|
||||
}
|
||||
if total == 0 {
|
||||
return Err(error("empty weighted model"));
|
||||
}
|
||||
Ok(Self::Weighted {
|
||||
variants,
|
||||
ends,
|
||||
total,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
fn select(&self, random: &mut impl RandomSource) -> &Variant {
|
||||
match self {
|
||||
Self::Single(value) => value,
|
||||
Self::Weighted {
|
||||
variants,
|
||||
ends,
|
||||
total,
|
||||
} => {
|
||||
// A singleton weighted list still consumes the bounded draw.
|
||||
let index = random
|
||||
.next_int_bound(*total)
|
||||
.expect("validated positive model weight");
|
||||
&variants[ends.partition_point(|end| *end <= index)]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Compile once per definition and share across its bound block states. Prefix
|
||||
/// sums avoid rebuilding weight totals or scanning all entries during selection.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompiledChoices {
|
||||
variants: Vec<Choice>,
|
||||
multipart: Vec<Choice>,
|
||||
}
|
||||
impl CompiledChoices {
|
||||
pub fn new(definition: &BlockStateDefinition) -> Result<Self> {
|
||||
Ok(Self {
|
||||
variants: definition
|
||||
.variants
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(|(_, v)| Choice::new(v))
|
||||
.collect::<Result<_>>()?,
|
||||
multipart: definition
|
||||
.multipart
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(|s| Choice::new(&s.variant))
|
||||
.collect::<Result<_>>()?,
|
||||
})
|
||||
}
|
||||
/// Append selected variants without allocating intermediate part lists. A
|
||||
/// multipart root consumes nextLong even for an empty selected subset, then
|
||||
/// resets the same random source to that seed before each selected part.
|
||||
pub fn collect<'a>(
|
||||
&'a self,
|
||||
selected: &SelectedModels,
|
||||
random: &mut impl RandomSource,
|
||||
output: &mut Vec<&'a Variant>,
|
||||
) -> Result<()> {
|
||||
match selected {
|
||||
SelectedModels::Variant(index) => {
|
||||
let choice = self
|
||||
.variants
|
||||
.get(*index)
|
||||
.ok_or_else(|| error("invalid variant selection"))?;
|
||||
output.push(choice.select(random));
|
||||
}
|
||||
SelectedModels::Multipart(indices) => {
|
||||
if indices.iter().any(|index| *index >= self.multipart.len()) {
|
||||
return Err(error("invalid multipart selection"));
|
||||
}
|
||||
let seed = random.next_long();
|
||||
for index in indices {
|
||||
random.set_seed(seed);
|
||||
output.push(self.multipart[*index].select(random));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -136,8 +136,7 @@ covers all 1,288 bundled definitions and 1,351 synthetic cases (2,639 total,
|
||||
`BlockStateModelDispatcher.CODEC` as the pinned loader. The Rust representation
|
||||
preserves single versus weighted variants, all three quarter-turn axes, UV-lock
|
||||
flags, positive weights and total-weight limits, ordered selectors, nested
|
||||
AND/OR conditions and per-term negation. Random draw consumption and transformed
|
||||
baking remain separate work.
|
||||
AND/OR conditions and per-term negation. Transformed baking remains separate work.
|
||||
|
||||
```sh
|
||||
python3 tools/test_blockstate_model_parity.py
|
||||
@@ -161,6 +160,21 @@ matches 221,261 output lines against each authenticated client/server JAR.
|
||||
python3 tools/test_blockstate_binding_parity.py
|
||||
```
|
||||
|
||||
`CompiledChoices` prepares cumulative weights once per definition and shares
|
||||
those choices across bound states. Selecting an ordinary single variant consumes
|
||||
no random draw; a weighted singleton still does. Multipart collection draws a
|
||||
seed even for an empty subset and resets the same stream before each chosen
|
||||
part. The [native choice comparison](../benchmarks/rust-blockstate-model-choice-2026-10-06/scoped-parity.json)
|
||||
uses actual `WeightedVariants.collectParts` and `MultiPartModel.collectParts`
|
||||
with inert observable leaves. All seven distinct bundled weight patterns,
|
||||
synthetic large weights and random multipart graphs produce matching selections
|
||||
and subsequent random values: 6,960 fixtures, 111,360 collections, both legacy
|
||||
and xoroshiro streams. This does not yet bake or render the selected models.
|
||||
|
||||
```sh
|
||||
python3 tools/test_model_choice_parity.py
|
||||
```
|
||||
|
||||
The sprite animation module reproduces the pinned metadata codec's integer
|
||||
conversion, strict primitive types, optional null fields and frame dimensions.
|
||||
It preserves repeated frames, filters out-of-image frame indices, and treats
|
||||
|
||||
+3
-2
@@ -22,8 +22,9 @@ also include parent/texture resolution over 5,648 roots and cuboid baking over
|
||||
models and UV locking remain unfinished. Blockstate resource decoding now
|
||||
matches all 1,288 bundled definitions and 1,351 synthetic cases; registry
|
||||
binding now also matches native selection across registered and special
|
||||
item-frame states. Weighted random selection, transformed baking and renderer
|
||||
integration remain unfinished. The native renderer now draws an
|
||||
item-frame states. Weighted selection and multipart random draw consumption
|
||||
also match native traces. Transformed baking and renderer integration remain
|
||||
unfinished. The native renderer now draws an
|
||||
inspection gallery from the decoded/resolved/baked models, including binary
|
||||
cutouts and stepped lantern animation; these are not yet gameplay blocks.
|
||||
Animation metadata, frame sequences and tick-state selection now have native
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package dev.horizonlab.parity;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import net.minecraft.client.renderer.block.dispatch.*;
|
||||
import net.minecraft.client.resources.model.sprite.Material;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.random.*;
|
||||
import net.minecraft.world.level.levelgen.*;
|
||||
import static dev.horizonlab.parity.VanillaCuboidModelOracle.map;
|
||||
|
||||
/** Real weighted and multipart collectParts, with observable inert leaf models. */
|
||||
public final class VanillaModelChoiceOracle {
|
||||
private static final Gson JSON=new GsonBuilder().serializeNulls().create();
|
||||
private record Leaf(String tag,List<String> output) implements BlockStateModel {
|
||||
public Material.Baked particleMaterial(){return null;}
|
||||
public int materialFlags(){return 0;}
|
||||
public void collectParts(RandomSource random,List<BlockStateModelPart> parts){output.add(tag);}
|
||||
}
|
||||
private static BlockStateModel choice(JsonElement value,int index,List<String> output) {
|
||||
if(value.isJsonNull())return new Leaf("horizon:part"+index+"_single",output);
|
||||
var list=new ArrayList<Weighted<BlockStateModel>>();int variant=0;
|
||||
for(var weight:value.getAsJsonArray())list.add(new Weighted<>(new Leaf("horizon:part"+index+"_variant"+variant++,output),weight.getAsInt()));
|
||||
return new WeightedVariants(WeightedList.of(list));
|
||||
}
|
||||
private static Object probe(JsonObject row) throws Exception {
|
||||
var emitted=new ArrayList<String>();var values=row.getAsJsonArray("parts");
|
||||
BlockStateModel model;
|
||||
if(!row.get("multipart").getAsBoolean())model=choice(values.get(0),0,emitted);
|
||||
else {
|
||||
var selectors=new ArrayList<Object>();var selected=new HashSet<Integer>();
|
||||
for(var i:row.getAsJsonArray("selected"))selected.add(i.getAsInt());
|
||||
var selectorType=Class.forName("net.minecraft.client.renderer.block.dispatch.multipart.MultiPartModel$Selector");
|
||||
var selectorConstructor=selectorType.getDeclaredConstructors()[0];selectorConstructor.setAccessible(true);
|
||||
for(int i=0;i<values.size();i++) {
|
||||
boolean enabled=selected.contains(i);
|
||||
java.util.function.Predicate<net.minecraft.world.level.block.state.BlockState> predicate=state->enabled;
|
||||
selectors.add(selectorConstructor.newInstance(predicate,choice(values.get(i),i,emitted)));
|
||||
}
|
||||
var sharedType=Class.forName("net.minecraft.client.renderer.block.dispatch.multipart.MultiPartModel$SharedBakedState");
|
||||
var sharedConstructor=sharedType.getDeclaredConstructors()[0];sharedConstructor.setAccessible(true);
|
||||
var shared=sharedConstructor.newInstance(selectors);
|
||||
var constructor=Class.forName("net.minecraft.client.renderer.block.dispatch.multipart.MultiPartModel").getDeclaredConstructors()[0];constructor.setAccessible(true);
|
||||
model=(BlockStateModel)constructor.newInstance(shared,null);
|
||||
}
|
||||
long seed=row.get("seed").getAsLong();
|
||||
RandomSource random=row.get("random").getAsString().equals("legacy")?new LegacyRandomSource(seed):new XoroshiroRandomSource(seed);
|
||||
var traces=new ArrayList<Object>();var parts=new ArrayList<BlockStateModelPart>();
|
||||
for(int i=0;i<row.get("repeats").getAsInt();i++) {
|
||||
emitted.clear();model.collectParts(random,parts);
|
||||
traces.add(map("models",new ArrayList<>(emitted),"next_long",random.nextLong(),"next_int",random.nextInt()));
|
||||
}
|
||||
return traces;
|
||||
}
|
||||
public static void main(String[] args) throws Exception {
|
||||
net.minecraft.SharedConstants.tryDetectVersion();
|
||||
try(var input=Files.newBufferedReader(Path.of(args[0]));var output=Files.newBufferedWriter(Path.of(args[1]))) {
|
||||
for(String line;(line=input.readLine())!=null;) {
|
||||
var row=JsonParser.parseString(line).getAsJsonObject();
|
||||
output.write(JSON.toJson(map("name",row.get("name").getAsString(),"trace",probe(row))));output.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare weighted model choice and multipart RNG consumption with the client."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import random
|
||||
import subprocess
|
||||
import zipfile
|
||||
try:
|
||||
from . import lab, test_rust_parity as base, test_model_baking_parity as baking, test_cuboid_model_parity as decoding
|
||||
except ImportError:
|
||||
import lab, test_rust_parity as base, test_model_baking_parity as baking, test_cuboid_model_parity as decoding
|
||||
|
||||
|
||||
def corpus(weights):
|
||||
cases=[]
|
||||
for vector in [None,*weights,(1,),(3,),(1,1),(1,2,7),(1073741824,1),(2147483646,1),(1,2147483646),tuple(range(1,100))]:
|
||||
cases.append((False,[vector],[0]));cases.append((True,[vector],[]));cases.append((True,[vector],[0]))
|
||||
cases.append((True,[vector,vector],[0,1]));cases.append((True,[None,vector,None],[0,1,2]))
|
||||
rng=random.Random(0x43484f494345)
|
||||
for _ in range(500):
|
||||
parts=[None if rng.randrange(3)==0 else [rng.randrange(1,1000) for _ in range(rng.randrange(1,20))] for _ in range(rng.randrange(1,20))]
|
||||
selected=[i for i in range(len(parts)) if rng.randrange(2)]
|
||||
cases.append((True,parts,selected))
|
||||
for i,(multipart,parts,selected) in enumerate(cases):
|
||||
for random_kind in ['legacy','xoroshiro']:
|
||||
for seed in [0,1,-1,-(1<<63),(1<<63)-1,rng.randrange(-(1<<63),1<<63)]:
|
||||
yield {'name':f'{i}/{random_kind}/{seed}','multipart':multipart,'parts':parts,'selected':selected,'random':random_kind,'seed':seed,'repeats':16}
|
||||
|
||||
|
||||
def main():
|
||||
lock,jars,_=base.verify_artifacts();build=lab.LOCAL/'rust-model-choice-parity';build.mkdir(parents=True,exist_ok=True);report_path=build/'report.json';report_path.unlink(missing_ok=True)
|
||||
oracle=lab.ROOT/'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaModelChoiceOracle.java';helper=oracle.with_name('VanillaCuboidModelOracle.java');crate=lab.ROOT/'crates/horizon-assets'
|
||||
sources=[oracle,helper,Path(__file__),lab.ROOT/'tools/test_model_baking_parity.py',lab.ROOT/'tools/test_cuboid_model_parity.py',lab.ROOT/'tools/lab.py',lab.ROOT/'tools/test_rust_parity.py',lab.ROOT/'Cargo.toml',lab.ROOT/'Cargo.lock',crate/'Cargo.toml',lab.ROOT/'crates/horizon-core/Cargo.toml',*sorted(crate.rglob('*.rs')),*sorted((lab.ROOT/'crates/horizon-core/src').rglob('*.rs'))]
|
||||
tested=base.source_hashes(sources);weights=set()
|
||||
with zipfile.ZipFile(jars['client']) as archive:
|
||||
for name in archive.namelist():
|
||||
if not name.startswith('assets/minecraft/blockstates/') or not name.endswith('.json'):continue
|
||||
root=json.loads(archive.read(name));models=[*root.get('variants',{}).values(),*(s['apply'] for s in root.get('multipart',[]))]
|
||||
for model in models:
|
||||
if isinstance(model,list):weights.add(tuple(v.get('weight',1) for v in model))
|
||||
rows=list(corpus(sorted(weights)));inputs=build/'inputs.jsonl';inputs.write_text(''.join(json.dumps(row)+'\n' for row in rows));fixtures=base.source_hashes([inputs]);classes=build/'classes';classes.mkdir(exist_ok=True)
|
||||
def run(command,name):
|
||||
with (build/(name+'.log')).open('w') as log:subprocess.run(list(map(str,command)),cwd=lab.ROOT,check=True,timeout=3600,stdout=log,stderr=subprocess.STDOUT)
|
||||
dependencies=os.pathsep.join(map(str,[jars['client'],*baking.client_libraries()]));classpath=str(classes)+os.pathsep+dependencies
|
||||
run(['javac','--release',lock['minecraft']['java_major'],'-proc:none','-cp',dependencies,'-d',classes,oracle,helper],'compile-java')
|
||||
run(['cargo','build','--locked','-p','horizon-assets','--example','model_choice_fixture'],'compile-rust')
|
||||
metadata=json.loads(subprocess.check_output(['cargo','metadata','--locked','--no-deps','--format-version','1'],cwd=lab.ROOT));binary=Path(metadata['target_directory'])/'debug/examples'/('model_choice_fixture.exe' if os.name=='nt' else 'model_choice_fixture')
|
||||
run([binary,inputs,build/'rust.jsonl'],'rust');run(['java','-Xmx512M','-cp',classpath,'dev.horizonlab.parity.VanillaModelChoiceOracle',inputs,build/'client.jsonl'],'client')
|
||||
decoding.canonicalize(build/'client.jsonl');decoding.canonicalize(build/'rust.jsonl');native=[json.loads(line) for line in (build/'client.jsonl').read_text().splitlines()];rust=[json.loads(line) for line in (build/'rust.jsonl').read_text().splitlines()]
|
||||
for left,right in zip(native,rust,strict=True):
|
||||
if left!=right:raise AssertionError('Model choice mismatch: '+left['name'])
|
||||
matched=base.compare(build/'client.jsonl',build/'rust.jsonl');base.ensure_sources_unchanged(sources,tested);base.ensure_sources_unchanged([inputs],fixtures)
|
||||
report={'schema':1,'minecraft':lock['minecraft']['version'],'manifest_sha1':lock['minecraft']['manifest_sha1'],'platform':platform.platform(),'java':subprocess.check_output(['java','--version'],text=True).splitlines()[0],'rustc':subprocess.check_output(['rustc','--version'],text=True).strip(),'bundled_weight_vectors':len(weights),'fixtures':len(rows),'collections':sum(r['repeats'] for r in rows),'sources_sha256':tested,'fixtures_sha256':fixtures,'rust_output_sha256':lab.digest(build/'rust.jsonl','sha256'),'references':[{'side':'client','jar_sha256':lab.digest(jars['client'],'sha256'),'output_sha256':lab.digest(build/'client.jsonl','sha256'),'matched_output_lines':matched}],'scope':'Actual WeightedVariants.collectParts and MultiPartModel.collectParts with inert observable leaf models and preselected boolean conditions. Every distinct bundled blockstate weight vector plus synthetic singletons, large totals, empty/partial multipart subsets and random graphs. Legacy and xoroshiro streams, six seeds per graph, repeated collection and subsequent nextLong/nextInt verify model choice and draw consumption. No actual model baking, material evaluation, transformed quads, renderer integration or gameplay parity claim.'}
|
||||
lab.write_json(report_path,report);print(f'Native model choice: {matched:,} fixtures / {report["collections"]:,} collections match; {report_path}',flush=True)
|
||||
|
||||
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user