Merge pull request #1027 from ludovic111/fix/carry-vine-template

🤖 Agent: merged after verify and CI parity passed (modpacks-11: Chipped's 11 vines carried as vines; the 11 blockstate errors are gone from the game log).
This commit is contained in:
Ludovic Marie
2026-10-21 11:02:04 +02:00
committed by GitHub
2 changed files with 62 additions and 2 deletions
+59 -1
View File
@@ -116,6 +116,52 @@ pub fn template(name: &str, properties: &BTreeSet<String>) -> Option<&'static st
.map(|(_, t)| t)
}
/// [`template`] for a blockstate file. A wall's sides are `none`, `low` or
/// `tall`; sides and `up` that are `true` or `false` are a vine's (Chipped's
/// vines), which the names alone take for a wall.
pub fn block_template(name: &str, blockstate: &Value) -> Option<&'static str> {
let t = template(name, &properties(blockstate))?;
let boolean = ["north", "east", "south", "west"]
.iter()
.flat_map(|side| values(blockstate, side))
.any(|v| v == "true" || v == "false");
Some(if t == "minecraft:cobblestone_wall" && boolean {
"minecraft:vine"
} else {
t
})
}
/// The values a blockstate file tests a property for.
fn values(blockstate: &Value, property: &str) -> BTreeSet<String> {
let mut out = BTreeSet::new();
for key in blockstate["variants"]
.as_object()
.into_iter()
.flatten()
.map(|(k, _)| k)
{
for pair in key.split(',') {
if let Some((k, v)) = pair.split_once('=')
&& k == property
{
out.insert(v.to_owned());
}
}
}
for part in blockstate["multipart"].as_array().into_iter().flatten() {
let when = &part["when"];
let mut conditions: Vec<&Value> = vec![when];
for or in ["OR", "AND"] {
conditions.extend(when[or].as_array().into_iter().flatten());
}
for v in conditions.iter().filter_map(|c| c[property].as_str()) {
out.extend(v.trim_start_matches('!').split('|').map(str::to_owned));
}
}
out
}
/// The property names a blockstate file uses.
pub fn properties(blockstate: &Value) -> BTreeSet<String> {
let mut out = BTreeSet::new();
@@ -1020,7 +1066,7 @@ pub fn carry(
}
} else {
for (b, state) in &blockstates {
match template(b, &properties(state)) {
match block_template(b, state) {
Some(t) => {
write_decl("block", b, &json!({"template": t}))?;
report.blocks.insert(b.clone(), t.to_owned());
@@ -1310,6 +1356,18 @@ mod tests {
template("gem_block", &properties(&json!({"variants": {"": {}}}))),
Some("minecraft:stone")
);
// Walls and vines have the same sides and up; their values tell them apart.
let wall = json!({"multipart": [{"when": {"up": "true"}},
{"when": {"north": "low"}}, {"when": {"east": "tall"}},
{"when": {"south": "low"}}, {"when": {"west": "low"}}]});
assert_eq!(
block_template("gem_wall", &wall),
Some("minecraft:cobblestone_wall")
);
let vine = json!({"multipart": [{"when": {"up": "true"}},
{"when": {"up": "false", "north": "false", "east": "false", "south": "false",
"west": "false"}}, {"when": {"north": "true"}}]});
assert_eq!(block_template("gem_vine", &vine), Some("minecraft:vine"));
let odd = json!({"variants": {"charge=1,mode=fast": {}}});
assert_eq!(template("gem_core", &properties(&odd)), None);
}
+3 -1
View File
@@ -346,7 +346,9 @@ same states (Macaw's garage doors, multi-part gates). Recipes get the convention
(`c:dyes/red`), filled from the oracle with vanilla's and the mod's own members. Without the
oracle, templates are guessed from the blockstate's properties: the template whose properties
include them with the fewest left over (models often ignore `powered` or `waterlogged`), the
block's name breaking ties (`_pane`, `_gate`, `_trapdoor`).
block's name breaking ties (`_pane`, `_gate`, `_trapdoor`). Walls and vines have the same
property names; sides tested as `true` / `false` make a vine (Chipped's 11 vines, which the game
refused as walls: their blockstates did not load).
### 1. Import