stevenarella/blocks/src/bin/dump_block.rs

22 lines
583 B
Rust
Raw Normal View History

blocks: versioned block states, fixes world on fire #467 (#469) Since the unflattening in 1.13.x, block IDs are no longer stable across versions, and can be shifted by the addition of new block states. To get the right block IDs across multiple protocol versions, add a new `offsets` token to `define_blocks!`, which is similar to `offset` (used post-flattening, compare to `data` used pre-flattening), but accepts a protocol_version argument to enable block states _per-version_: * Add 'offsets' for protocol_version-specific blockstates As part of this change, by_vanilla_id is now a method of a VanillaIDMap instance, instead of a method of Block, so it can know the protocol version. Previously, the ID map was lazily computed statically, once, but this change allows it to be computed based on protocol version: * Move by_vanilla_id to VanillaIDMap instance Tools to help debug blocks: * Add DEBUG_BLOCKS environment variable to dump block states * Add dump_block command-line tool The block `offset`s were previously only correct for 1.13.2, to take advantage of the new version-specific `offsets` capability, blocks were updated for 1.14.x: 1.14+ (protocol_version >= 477): * Add NoteBlock instruments * Add FlowerPot and RedFlowerVariant cornflower, wither rose, lily of the valley * Add StandingSign wood variants * Add WallSign tree variants * Add StoneSlab smooth stone, cut sandstone, cut red sandstone This fixes #467, where grass was misinterpreted as fire on 1.14+ because of the ID shifts caused by NoteBlock, among other block misassignments (though not 100%).
2021-01-13 22:50:05 -05:00
use std::collections::HashMap;
use std::env;
use steven_blocks::VanillaIDMap;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 3 {
println!(
"usage: {} protocol_version id\nrun with DEBUG_BLOCKS=1 to dump all",
args[0]
);
return;
}
let protocol_version = str::parse::<i32>(&args[1]).unwrap();
let id = str::parse::<usize>(&args[2]).unwrap();
let id_map = VanillaIDMap::new(protocol_version);
let block = id_map.by_vanilla_id(id, &HashMap::new());
println!("{:?}", block);
}