Skip to main content

ghast_data/v26_2/
mod.rs

1//! Minecraft 26.2 (protocol 776) data: the global block-state palette with properties, collision
2//! voxel shapes and the per-state facts the movement code reads, items and entities.
3//!
4//! The same API as [`crate::v26_1`] (the shared items are the same Rust types: [`StatePhys`],
5//! [`BlockKind`], [`VoxelShapeRef`], ...; the shape tables are one pool shared by both). Every
6//! value comes from the real 26.2 jar (oracle dumps in `tests/golden/26.2/`): ids, names,
7//! state layout and every movement fact. minecraft-data has no 26.2 yet: display fields
8//! (display names, resistance, light) are minecraft-data's 26.1 values by name, and the
9//! blocks, items and entity new in 26.2 take them from a reviewed table
10//! (`codegen/data/src/v26_2.rs`).
11//!
12//! Unlike 26.1 the per-block and per-item rows hold no pointers ([`BlockData`] and
13//! [`ItemData`] have no `name` / `display_name` fields): use [`Block::name`],
14//! [`Block::display_name`], [`Item::name`], [`Item::display_name`], which exist in `v26_1`
15//! too, so code written against those works with both versions.
16//!
17//! The hot path is one table read per state: [`BlockState::phys`] returns a packed
18//! [`StatePhys`] (shape index, flags, fluid, per-kind extra bits, [`BlockKind`]).
19
20use crate::common::{SelectionShape, lookup_name};
21use crate::generated::v26_2 as g;
22
23pub use crate::modern::{
24    BlockKind, StatePhys, VoxelClass, VoxelShapeRef, block_flags, state_flags,
25};
26use core::fmt;
27
28pub use g::blocks::Property;
29
30// The 26.1 source, compiled over the 26.2 tables.
31#[allow(clippy::duplicate_mod)]
32#[path = "../v26_1/dig.rs"]
33pub mod dig;
34// The 26.1 source, compiled over the 26.2 tables.
35#[allow(clippy::duplicate_mod)]
36#[path = "../v26_1/entities.rs"]
37pub mod entities;
38// The 26.1 source, compiled over the 26.2 tables.
39#[allow(clippy::duplicate_mod)]
40#[path = "../v26_1/items.rs"]
41pub mod items;
42
43pub use entities::{
44    EntityTypeData, entities, entity, entity_by_name, entity_type, entity_types,
45    vanilla_entity_size, vanilla_entity_sizes,
46};
47pub use items::{BlockSet, Food, Item, Tool, ToolRule, food};
48
49/// Static per-block data (jar values for everything movement reads).
50#[derive(Clone, Copy, Debug, PartialEq)]
51pub struct BlockData {
52    /// Destroy time (minecraft-data; `None` = unbreakable).
53    pub hardness: Option<f32>,
54    /// Explosion resistance (minecraft-data).
55    pub resistance: f32,
56    /// Can be mined (minecraft-data).
57    pub diggable: bool,
58    /// Lets light through (minecraft-data).
59    pub transparent: bool,
60    /// Light emitted (minecraft-data).
61    pub emit_light: u8,
62    /// Light filtered (minecraft-data).
63    pub filter_light: u8,
64    /// `Block.getFriction()` (jar).
65    pub friction: f32,
66    /// `Block.getSpeedFactor()` (jar).
67    pub speed_factor: f32,
68    /// `Block.getJumpFactor()` (jar).
69    pub jump_factor: f32,
70    /// [`block_flags`] bits.
71    pub flags: u32,
72    /// Special movement behaviour.
73    pub kind: BlockKind,
74    /// Model offset function: `(max horizontal, max vertical, xyz)`; bamboo and pointed dripstone
75    /// shift their collision shape by it.
76    pub offset: Option<(f32, f32, bool)>,
77}
78
79/// String `i` of a text table (`ends` = end offsets).
80fn nth(text: &'static str, ends: &[u32], i: u16) -> &'static str {
81    let i = usize::from(i);
82    let end = ends[i] as usize;
83    let start = if i == 0 { 0 } else { ends[i - 1] as usize };
84    &text[start..end]
85}
86
87/// Registry name of block `id` (no namespace).
88fn block_name(id: u16) -> &'static str {
89    nth(
90        g::blocks::BLOCK_ID_NAMES_TEXT,
91        &g::blocks::BLOCK_ID_NAMES_ENDS,
92        id,
93    )
94}
95
96/// English display name of block `id`.
97#[cfg(feature = "display-names")]
98fn block_display_name(id: u16) -> &'static str {
99    nth(
100        g::blocks::BLOCK_DISPLAY_NAMES_TEXT,
101        &g::blocks::BLOCK_DISPLAY_NAMES_ENDS,
102        id,
103    )
104}
105
106/// Static item data (default components).
107#[derive(Clone, Copy, Debug, PartialEq)]
108pub struct ItemData {
109    /// Default `minecraft:max_stack_size`.
110    pub max_stack_size: u8,
111    /// Default `minecraft:max_damage` (damageable items).
112    pub max_damage: Option<u16>,
113    /// The block a `BlockItem` places (block id).
114    pub block: Option<u16>,
115    /// Default `minecraft:food`.
116    pub food: Option<Food>,
117    /// Default `minecraft:tool` (index into the tool table).
118    pub tool: Option<u16>,
119}
120
121/// Registry name of item `id` (no namespace).
122fn item_name(id: u16) -> &'static str {
123    nth(
124        g::items::ITEM_ID_NAMES_TEXT,
125        &g::items::ITEM_ID_NAMES_ENDS,
126        id,
127    )
128}
129
130/// English display name of item `id`.
131#[cfg(feature = "display-names")]
132fn item_display_name(id: u16) -> &'static str {
133    nth(
134        g::items::ITEM_DISPLAY_NAMES_TEXT,
135        &g::items::ITEM_DISPLAY_NAMES_ENDS,
136        id,
137    )
138}
139
140// The API shared with the other modern versions (`v26_2` compiles the same source).
141include!("../modern_api.rs");
142
143#[cfg(test)]
144mod tests;