Load ATM10's 42 carried mods: room past 8,192 textures and tags

With the wide state ids, ATM10's 42 data-tier mods (193,762 states)
reach the world once these loaders stop refusing them:

- Block sprites: eight texture arrays of 2048 layers instead of four
  (9,790 block textures for the 42).
- Per-state tables read as NBT: the table limits cover 2^20 states, and
  the collision table in level data uses them.
- Worldgen block tags: 2^20 blocks instead of 8,192 (mineable/pickaxe
  holds every stone block of a pack).
- As vanilla's loaders do, a blockstate definition that does not bind,
  a missing or broken block model of a mod, and a recipe that does not
  parse are logged and skipped instead of dropping every mod (or
  stopping the game).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-17 08:53:46 +02:00
parent f48a54da09
commit 4d1596fe3b
12 changed files with 139 additions and 31 deletions
+9 -1
View File
@@ -1209,7 +1209,15 @@ impl Recipes {
for (prefix, path) in files {
let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or("");
let name = format!("{prefix}{stem}");
let v: Value = serde_json::from_slice(&fs::read(&path)?)?;
// Vanilla's RecipeManager logs a file that does not parse and
// goes on ("Couldn't parse data file").
let v: Value = match serde_json::from_slice(&fs::read(&path)?) {
Ok(v) => v,
Err(e) => {
log::warn!("Horizon: recipe {name} not loaded: {e}");
continue;
}
};
let text = |k: &str| v[k].as_str().unwrap_or("").to_owned();
meta.insert(name.clone(), (text("category"), text("group")));
let ing = |k: &str| Ingredient::parse(&v[k], items);
+7
View File
@@ -644,6 +644,13 @@ impl Game<'_> {
if strategy.global_bits != ours.global_bits {
let mut values = [0u32; 4096];
blocks.unpack(&mut values);
// Ids past our registry (a host with mods we lack) read as air.
let limit = 1u64 << ours.global_bits;
for v in &mut values {
if u64::from(*v) >= limit {
*v = 0;
}
}
blocks = PalettedContainer::from_values(ours, &values);
}
let mut section = Section {
+9 -1
View File
@@ -385,7 +385,7 @@ fn sprite_split() -> u32 {
.unwrap_or(SPRITE_SPLIT)
}
/// Sprite arrays terrain.wgsl binds (`sprites`, `sprites_1`...).
const SPRITE_ARRAYS: u32 = 4;
const SPRITE_ARRAYS: u32 = 8;
/// The views of terrain.wgsl's sprite arrays, the unused ones a 1-layer
/// stand-in.
fn sprite_views(
@@ -441,6 +441,10 @@ fn terrain_group(
view(5, &sprites[1]),
view(6, &sprites[2]),
view(7, &sprites[3]),
view(8, &sprites[4]),
view(9, &sprites[5]),
view(10, &sprites[6]),
view(11, &sprites[7]),
],
})
}
@@ -739,6 +743,10 @@ impl Renderer {
entry(5, vf, sprite_array),
entry(6, vf, sprite_array),
entry(7, vf, sprite_array),
entry(8, vf, sprite_array),
entry(9, vf, sprite_array),
entry(10, vf, sprite_array),
entry(11, vf, sprite_array),
],
});
let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
+42 -8
View File
@@ -42,25 +42,52 @@ impl ParsedModels {
/// Blocks require every referenced resource, including parents. Items instead
/// skip broken resources and use the resolver's missing-model fallback.
pub(crate) fn block_library(
pub(crate) fn block_library(&self, root: &Path, pending: Vec<String>) -> Result<ModelLibrary> {
self.block_models(root, pending, false)
}
/// [`Self::block_library`], but a model that does not read takes the
/// built-in missing model, logged, as vanilla's model discovery does
/// ("Missing block model"). Mods' content gets this; vanilla's resources
/// always read.
pub(crate) fn block_library_or_missing(
&self,
root: &Path,
pending: Vec<String>,
) -> Result<ModelLibrary> {
self.block_models(root, pending, true)
}
fn block_models(
&self,
root: &Path,
mut pending: Vec<String>,
or_missing: bool,
) -> Result<ModelLibrary> {
let mut models = BTreeMap::new();
let mut skipped = std::collections::BTreeSet::new();
while let Some(name) = pending.pop() {
if models.contains_key(&name) {
if models.contains_key(&name) || skipped.contains(&name) {
continue;
}
let model = match self.models.get(&name) {
Some(model) => Arc::clone(model),
None => {
let (namespace, path) =
name.split_once(':').ok_or("invalid model identifier")?;
let text = fs::read_to_string(
root.join(format!("assets/{namespace}/models/{path}.json")),
)?;
Arc::new(CuboidModel::from_json(&text)?)
let read = || -> Result<CuboidModel> {
let (namespace, path) =
name.split_once(':').ok_or("invalid model identifier")?;
let text = fs::read_to_string(
root.join(format!("assets/{namespace}/models/{path}.json")),
)?;
Ok(CuboidModel::from_json(&text)?)
};
match read() {
Ok(model) => Arc::new(model),
Err(e) if or_missing => {
log::warn!("Horizon: missing block model {name}: {e}");
skipped.insert(name);
continue;
}
Err(e) => return Err(e),
}
}
};
if let Some(parent) = &model.parent {
@@ -141,6 +168,13 @@ mod tests {
.to_string()
};
assert_eq!(load(&direct), load(&parsed));
// Mods' content: vanilla's missing model instead of an error.
let lenient = parsed.block_library_or_missing(&fixture.0, vec![name.into()])?;
assert_eq!(
format!("{:?}", lenient.resolve(name)?.elements()),
format!("{:?}", lenient.resolve(MISSING_MODEL)?.elements()),
"{name}"
);
}
let items = parsed.into_item_library()?;
let block = shared.resolve("horizon:nested/child")?;
+30 -8
View File
@@ -136,11 +136,29 @@ impl StateModels {
})
.collect::<Result<_>>()?;
let possible: Vec<Properties> = serde_json::from_value(facts["states"].clone())?;
let resource = fs::read_to_string(
// Vanilla's BlockStateModelLoader: a definition that does not
// read or bind is logged and its block gets no model; the other
// blocks still load.
let loaded = fs::read_to_string(
root.join(format!("assets/{namespace}/blockstates/{path}.json")),
)?;
let definition = BlockStateDefinition::from_json(&resource)?;
let bound = definition.bind(&schema, &possible)?;
)
.map_err(|e| e.to_string())
.and_then(|text| BlockStateDefinition::from_json(&text).map_err(|e| e.to_string()))
.and_then(|definition| {
let bound = definition
.bind(&schema, &possible)
.map_err(|e| e.to_string())?;
Ok((definition, bound))
});
let (definition, bound) = match loaded {
Ok(loaded) => loaded,
Err(e) => {
log::warn!(
"Horizon: blockstate definition of {namespace}:{path} not loaded: {e}"
);
continue;
}
};
let native_order: Vec<_> = by_name
.get(name.as_str())
.map(Vec::as_slice)
@@ -185,10 +203,14 @@ impl StateModels {
}
choices.push(CompiledChoices::new(&definition)?);
}
let library = models.block_library(
root,
variants.iter().map(|(name, _, _)| name.clone()).collect(),
)?;
let names: Vec<String> = variants.iter().map(|(name, _, _)| name.clone()).collect();
let library = match models.block_library(root, names.clone()) {
Ok(library) => library,
Err(e) => {
log::warn!("Horizon: block models incomplete ({e}); using the missing model");
models.block_library_or_missing(root, names)?
}
};
let mut baked = BTreeMap::new();
for (name, turns, lock) in variants {
let model = library.resolve(&name)?;
+9 -1
View File
@@ -31,6 +31,10 @@ struct Globals {
@group(0) @binding(5) var sprites_1: texture_2d_array<f32>;
@group(0) @binding(6) var sprites_2: texture_2d_array<f32>;
@group(0) @binding(7) var sprites_3: texture_2d_array<f32>;
@group(0) @binding(8) var sprites_4: texture_2d_array<f32>;
@group(0) @binding(9) var sprites_5: texture_2d_array<f32>;
@group(0) @binding(10) var sprites_6: texture_2d_array<f32>;
@group(0) @binding(11) var sprites_7: texture_2d_array<f32>;
// How many sprite arrays hold layers (a pipeline constant): 1 for vanilla,
// which then samples exactly as before.
override SPRITE_ARRAYS: u32 = 1u;
@@ -47,7 +51,11 @@ fn sprite(uv: vec2<f32>, layer: u32) -> vec4<f32> {
case 0u: { return textureSampleGrad(sprites, sprite_sampler, uv, l, dx, dy); }
case 1u: { return textureSampleGrad(sprites_1, sprite_sampler, uv, l, dx, dy); }
case 2u: { return textureSampleGrad(sprites_2, sprite_sampler, uv, l, dx, dy); }
default: { return textureSampleGrad(sprites_3, sprite_sampler, uv, l, dx, dy); }
case 3u: { return textureSampleGrad(sprites_3, sprite_sampler, uv, l, dx, dy); }
case 4u: { return textureSampleGrad(sprites_4, sprite_sampler, uv, l, dx, dy); }
case 5u: { return textureSampleGrad(sprites_5, sprite_sampler, uv, l, dx, dy); }
case 6u: { return textureSampleGrad(sprites_6, sprite_sampler, uv, l, dx, dy); }
default: { return textureSampleGrad(sprites_7, sprite_sampler, uv, l, dx, dy); }
}
}
+1 -1
View File
@@ -744,7 +744,7 @@ pub(super) fn load_with_gameplay<G: GameplayStateSource>(
// Collision shapes.
let collision_tag = nbt::read_named(
&fs::read(root.join("cached-collision.nbt"))?,
Limits::default(),
Limits::tables(),
)
.map_err(|e| invalid(e.to_string()))?
.0
+5 -3
View File
@@ -100,11 +100,13 @@ impl Default for Limits {
impl Limits {
/// The prepared per-state block tables (`cached-collision.nbt`,
/// `block-properties.nbt`, ...): trusted files with a row per block
/// state, which content mods' states grow past the default caps.
/// state, which content mods' states grow past the default caps
/// (vanilla's 35,723 states fill about a tenth of these; ATM10's ported
/// mods, 193,762 states, about half).
pub fn tables() -> Self {
Self {
max_bytes: 1 << 28,
max_nodes: 16_000_000,
max_bytes: 1 << 30,
max_nodes: 128_000_000,
max_depth: 512,
}
}
@@ -192,7 +192,7 @@ impl FeatureCatalog {
if names.is_empty() {
return Ok(serde_json::to_string(&format!("#{tag}"))?);
}
if names.len() > 8192 {
if names.len() > super::state_provider::MAX_TAG_BLOCKS {
return Err(DecodeError::Field("placed-feature tag size"));
}
names
@@ -93,7 +93,7 @@ impl<'r> StateProviderBindings<'r> {
}
let mut bound_tags = BTreeMap::new();
for (name, entries) in tags {
if entries.len() > 8192 {
if entries.len() > MAX_TAG_BLOCKS {
return Err(DecodeError::Field("provider tag size"));
}
let values = entries
@@ -558,6 +558,11 @@ impl BlockStateProvider {
}
}
/// Blocks a bound block tag may list (8,192 before content mods, vanilla's
/// tags fit well within it): content mods' blocks join the shared tags
/// (`mineable/pickaxe` takes every stone block of a pack).
pub(crate) const MAX_TAG_BLOCKS: usize = 1 << 20;
/// Bind the pinned registry's full-axis/full-facing/horizontal-facing property
/// families. A five-way facing or two-axis property is a different property and
/// is intentionally left unchanged. Unrelated properties retain their values.
@@ -41,7 +41,13 @@ fn bound_recursive_providers_and_registry_lists_before_sampling() {
let branching = serde_json::json!({"if_true":{"type":"all_of","predicates":vec![serde_json::json!({"type":"true"});7]},"then":{"id":"stone"}});
let oversized = serde_json::json!({"type":"rule_based","rules":vec![branching;8192]});
assert!(BlockStateProvider::from_json(&oversized.to_string(), &bindings).is_err());
let tags = BTreeMap::from([("horizon:oversized".into(), vec!["stone".into(); 8193])]);
// Content mods' blocks join shared tags: the cap is 2^20 blocks.
let tags = BTreeMap::from([("horizon:large".into(), vec!["stone".into(); 8193])]);
assert!(StateProviderBindings::new(&registry, BTreeSet::new(), &tags).is_ok());
let tags = BTreeMap::from([(
"horizon:oversized".into(),
vec!["stone".into(); (1 << 20) + 1],
)]);
assert!(StateProviderBindings::new(&registry, BTreeSet::new(), &tags).is_err());
let tags = BTreeMap::from([("tag".into(), vec![]), ("minecraft:tag".into(), vec![])]);
assert!(StateProviderBindings::new(&registry, BTreeSet::new(), &tags).is_err());
+13 -5
View File
@@ -237,11 +237,19 @@ How the game loads them, without touching vanilla's path:
- Loaders that read only `data/minecraft/` (recipes, loot, tags) read every namespace, as
vanilla does. With no mods there is only `minecraft`, so nothing changes.
- The overlay is cached like the resource-pack overlay and rebuilt when a mod file changes.
- **Limits.** Chunk sections store a block state in 16 bits: vanilla 26.3 has 35,723 states,
so mods may add 29,813. Past that the content root is refused with the states per mod
(Macaw's Doors, Fences, Paths and Trapdoors alone add 36,154: not all four fit). Block
sprites fill texture arrays of 2048 layers, four at most (8,192; vanilla takes 1,250,
identical textures share a layer). Wider state ids are the next step for big packs.
- **Limits.** Chunk sections size their global palette to the registry: 16 bits for vanilla's
35,723 states (the same chunks, saves and packets as before), one more bit each time content
mods double it, up to 2^20 states (1,048,576). Past that the content root is refused with the
states per mod. ATM10's 42 carried mods take the registry to 193,762 states (18 bits). On the
network the width is the registry's: unchanged for vanilla clients as long as no content mod
is on, wider only between Horizons that share the same mods; a Horizon with content mods still
reads a vanilla server's 16-bit chunks. Block sprites fill texture arrays of 2048 layers, eight
at most (16,384; vanilla takes 1,250, identical textures share a layer; ATM10's 42 take 9,790).
- **Broken mod files load as vanilla loads them.** A blockstate definition that does not bind
(a multipart value the block does not have), a block model that is missing or does not parse,
and a recipe that does not parse are logged and skipped: the block gets no model or the
missing model, the recipe is absent, everything else loads. Vanilla's own files never hit
these paths.
- Not in 0.2: multiplayer registry sync (single player and the integrated server first), worlds
opened without a mod they used (vanilla turns unknown blocks into air; we will ask first),
vanilla ids redefined by a mod (refused).