Native mods: native_state_block names the block a state belongs to

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Federico TaglianiandClaude Sonnet 5.5 committed 2026-11-02 00:22:17 +01:00
1 parent c9d49d4328
commit 989eb8a0be
3 files changed
+21 -1

No files matched your search

@@ -559,6 +559,11 @@ impl Game<'_> {
.get(key)
.map(String::as_str)
}
/// The block `state` is a state of: its name, as `GameLevel`'s helper of
/// the same name gives it for the hooks that get a state in the world.
pub(super) fn native_state_block(&self, state: BlockStateId) -> Option<&str> {
self.pack.assets.registry.state(state).map(|s| &*s.name)
}
}
#[cfg(test)]
+10 -1
View File
@@ -773,7 +773,8 @@ impl GameLevel<'_> {
/// the clicked position, whether the clicked block is being replaced, the
/// item in hand) and `fluid` the fluid in the position the block would go
/// in, which a waterlogged block reads. Build the state from `state` with
/// `native_state_with_property`. It is asked for every placer that goes
/// `native_state_with_property`, and know whether `state` is yours with
/// `native_state_block`. It is asked for every placer that goes
/// through vanilla's placement (a player's `BlockItem.place`, a
/// dispenser's `DirectionalPlaceContext`), and the answer still takes its
/// survival and entity obstruction checks. Authoritative servers only.
@@ -4140,6 +4141,14 @@ impl GameLevel<'_> {
) -> Option<BlockStateId> {
with_property(self.registry, state, key, value)
}
/// The block `state` is a state of (`BlockState.getBlock()`): its name,
/// `mymod:cable`. `native_state_for_placement` is asked for every block
/// placed and given the block's default state: compare this with your
/// block to answer only for it. None for an unknown state. API
/// @API:state_block@.
pub(super) fn native_state_block(&self, state: BlockStateId) -> Option<&str> {
self.registry.state(state).map(|s| &*s.name)
}
/// This level's own random (vanilla's `Level.random`): the stream
/// `native_level_random(dimension)` hands a server hook, for a world hook
/// that draws as a vanilla block does (`isBonemealSuccess`), so the mod's
@@ -0,0 +1,6 @@
{
"hooks": [],
"rust_summary": "a helper that names the block a state belongs to (`native_state_block`).",
"doc_summary": "`native_state_block(state)` names the block a state belongs to (`BlockState.getBlock()`), on a server hook's level and on the game: `native_state_for_placement` is asked for every block placed, so a mod compares it with its own block to answer only for it. Bundles that use it need \"hooks\": @API:state_block@.",
"comments": ["crates/horizon-client/src/game/native_hooks.rs"]
}