Skip to content

Registry overhaul (WIP)#51

Draft
Pookachu wants to merge 2 commits into
temper-mc:devfrom
Pookachu:registry-overhaul
Draft

Registry overhaul (WIP)#51
Pookachu wants to merge 2 commits into
temper-mc:devfrom
Pookachu:registry-overhaul

Conversation

@Pookachu

Copy link
Copy Markdown
Contributor

No description provided.

@Pookachu Pookachu changed the base branch from master to dev May 15, 2026 04:04
impl BlockStateId {
/// Do NOT use this by yourself. Instead use the block macro `block!("stone")` the item to block
/// map
#[inline(always)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't force inline, the compiler is pretty good at figuring out when it will help and can blow up compile time if used wrong

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely correct. my bad

// --- Getters (Using State IDs) ---

#[inline(always)]
fn base_id(state_id: u32) -> u32 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these can we use impl Into<u32> so we can pass in blockstateids without having to convert?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would actually be much more ergonomic than what i was thinking. thank you

reg.state_to_block
.get(state_id as usize)
.copied()
.unwrap_or(0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the fallbacks can we warn please


// --- Getters (Using State IDs) ---

#[inline(always)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forcing inline on these is a really bad idea as they will expand to a lot of code and cause compile time problems later down the line

|| name.ends_with("_roots")
}

pub fn init(json_string: &str) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this entire thing, could we move it to something like PHF and do this at compile time? Might not be feasible but could result in better startup and runtime performance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading up on it again, PHF is strictly for mapping strings to values and is kinda useless for mapping state IDs to other IDs. We can definitely do compile time generation instead of what i'm doing here though.

Comment thread src/registry/src/items.rs
max_durability: Option<u16>,
}

struct ItemRegistry {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have all the fields in 1 vec?

@Pookachu Pookachu May 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a trap for ECS. you're suggesting an AoS (array of structs) but we want an SoA (struct of arrays) because it maximizes cache locality

for integer-to-value lookups, i'll just generate a flat &[T] array at compile time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants