Skip to content

Biome-independent structure tables#2129

Open
BoySanic wants to merge 16 commits intoPixelGuys:masterfrom
BoySanic:fix/1805
Open

Biome-independent structure tables#2129
BoySanic wants to merge 16 commits intoPixelGuys:masterfrom
BoySanic:fix/1805

Conversation

@BoySanic
Copy link
Contributor

@BoySanic BoySanic commented Oct 24, 2025

Fixes #1805
Implements biome-independent structure tables.

The way these work:

Structure tables are loaded into the game along with all other assets.
When loading biomes, each biome checks its biomeTags (new feature, currently unused) against the biomeTags in each structure table that was loaded previously. If any biomeTags match, add the structures from those tables into the biome's internal structure table in memory at world load time.

Additionally, if a structure table has an empty .biomeTags (len == 0), it should spawn those structures in all biomes. So those structures are added to all biomes' internal structure table.

Implementation details:

Moved hashing functions out of src/server/terrain/biomes.zig into src/utils/hash.zig
Moved SimpleStructureModel into src/server/terrain/structures.zig from src/server/terrain/biomes.zig.

Example structure table .zig.zon in assets/cubyz/structure_tables in this branch.

@BoySanic BoySanic changed the title Fix/1805 Biome-independent structure tables Oct 25, 2025
@BoySanic
Copy link
Contributor Author

On the topic of this PR, I was thinking about how addons might target biomes and with the current approach they'd use biome tags.

I think it may make sense to allow the structure table to use the biome's id as a tag, too. Just check if the structure table's biomeTags contains the biome's Id (it would just be an or on the current check that is used) and it'd make that easier. Then we don't have to come up with tags to target specific biomes, we just use their id as a tag logically.

In the future I envision we start categorizing biomes. like cubyz:cold, cubyz:humid, cubyz:dry, cubyz:hot, and so on for the various "tags" that could apply to a biome. Then, similar to the #1805 example, maybe an addon that adds igloos would create a structure table containing that igloo and it would set its biomeTags to cubyz:cold or something, so the igloos are added to biomes that are tagged cubyz:cold.

@BoySanic BoySanic moved this to WIP/not ready for review in PRs to review Nov 3, 2025
This was referenced Nov 3, 2025
@BoySanic BoySanic closed this Nov 7, 2025
@BoySanic BoySanic deleted the fix/1805 branch November 7, 2025 22:09
@BoySanic BoySanic restored the fix/1805 branch November 7, 2025 22:35
@BoySanic
Copy link
Contributor Author

BoySanic commented Nov 7, 2025

I didn't mean to close that

@BoySanic BoySanic reopened this Nov 7, 2025
IntegratedQuantum pushed a commit that referenced this pull request Feb 25, 2026
This PR splits out structures and hashing from biomes.zig into
structures.zig and src/utils.zig respectively.

This change should be done for the following reasons:

1. It cleans up #2129. A lot.
2. Splitting it out from biomes.zig into another file makes it a bit
cleaner once we add the changes from #2129 that introduces the
StructureTable struct for example. It's technically feasible to leave it
all in biomes.zig, splitting it out made the most sense to me at the
time for organization purposes.
@BoySanic BoySanic marked this pull request as ready for review February 25, 2026 17:58
@BoySanic BoySanic moved this from WIP/not ready for review to High Priority in PRs to review Feb 25, 2026
@BoySanic
Copy link
Contributor Author

Memory leak fixed, and I added migrations stuff to it for whenever someone needs to migrate structure_tables in the future. This should be good to go for review.

@BoySanic
Copy link
Contributor Author

Whenever this is merged, #1283 can proceed as meteorites can be made into a structure table that spawns in any biome or biomes with specific tags. (Biomes currently have no tags, but coming up with those tags could be an issue on its own to discuss)

@BoySanic BoySanic mentioned this pull request Feb 26, 2026
@IntegratedQuantum IntegratedQuantum moved this from High Priority to In review in PRs to review Feb 26, 2026
BoySanic added 2 commits March 2, 2026 23:11
- Added back structureTablesById
- Added sorting to the structureTables slice
- Removed unused numerical id (paletteId)
- Removed potentially dangerous check that returned `undefined` instead
  of an empty structureTable
@IntegratedQuantum
Copy link
Member

@ikabod-kee could you add your special structure from https://github.com/IntegratedQuantum/Cubyz-Lore/issues/4#issuecomment-3114276769 to this PR as an entry to an ultra-rare structure table that applies to all biomes

for (structureList.items) |*model| {
model.chance /= totalChance;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this normalization here? I think it could change the chances in unexpected ways (.chance = 1 in structure table has a different meaning from .chance = 1 in the host biome) when combined with the host biome normalization or other structure tables.

itemPalette: *assets.Palette = undefined,
toolPalette: *assets.Palette = undefined,
biomePalette: *assets.Palette = undefined,
structureTablePalette: *assets.Palette = undefined,
Copy link
Member

Choose a reason for hiding this comment

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

with the sorting, a palette isn't needed

@ikabod-kee
Copy link
Collaborator

@ikabod-kee could you add your special structure from IntegratedQuantum/Cubyz-Lore#4 (comment) to this PR as an entry to an ultra-rare structure table that applies to all biomes

Leaking the cubyz lore like that? For shame!!! (just joking XD)

Sure! I'll have to rebuild it, but it should be easy.

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Biome independent structure table

4 participants