Skip to content

Conversation

CuddlyBunion341
Copy link
Owner

@CuddlyBunion341 CuddlyBunion341 commented Mar 2, 2025

Finally decided to add so called "trees".

Two components:

  • tree stump (an elongated box made of wood)
  • bush (perfect, booring sphere of leaves)

Also added debug UI to tweak params, such as the number of attempts and tree size.

image

Implementation details

  • The spawn locations are non deterministic, it is a headache to mutate a seeded generator rng across threads, without precalculating a bunch of numbers and distributing them based on Chunk ID. (Thanks Rust compiler for making me aware of such race condition!)
  • Pythagoras is applied to calculate if position is inside sphere.
  • took forever as every line is hand written (no copilot, no deepseek, no ChatGPT). This is because I want to experience writing code probably for the last time in my life before AI replaces programmers (not software developers) for good 😢

Additional notes

  • Trees can spawn in caves (this a feature not a bug)
  • Tests? Didn't feel like it, sowwy

Unrelated changes

  • Reworked block texture definitions (because the old system sucked as you needed to provide u and v coordinates explicitly)
  • Updated block list (many were unused and were not really relevant for the current setting, which is plains / mountains / forest)

@CuddlyBunion341 CuddlyBunion341 self-assigned this Mar 2, 2025
bevy_renet = { git = "https://github.com/CuddlyBunion341/renet.git" }
bincode = "1.3.3"
rand = "0.8.5"
rand = {version = "0.9.0", features = ["small_rng"]}
Copy link
Owner Author

Choose a reason for hiding this comment

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

Old one didn't support range

Copy link
Owner Author

@CuddlyBunion341 CuddlyBunion341 Mar 2, 2025

Choose a reason for hiding this comment

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

Terracota is no longer planned in terrain generation, had to make room for trees and ores

IronOre,
CoalOre,
Bedrock,
RedSand,
Copy link
Owner Author

Choose a reason for hiding this comment

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

Bye bye

const ATLAS_HEIGHT: usize = 4;

let textures: [[TextureName; ATLAS_WIDTH]; ATLAS_HEIGHT] = [
[Stone, CobbleStone, GrassTop, OakLeaves],
Copy link
Owner Author

Choose a reason for hiding this comment

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

This texture definition makes me happier than I was before, hopefully making adding textures simpler ^^

max: Vec3,
}

let proposal_bounds = proposal.iter().fold(
Copy link
Owner Author

Choose a reason for hiding this comment

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

Maybe overkill, but the goal is to first generate a tree scheme (with relative positions to spawn origin) and then determine a planting position that is in bounds of the chunk, thus not wasting spawn attempts.

let proposal_valid = proposal.iter().all(|(relative_pos, _block)| {
let Vec3 { x, y, z } = relative_pos;
Chunk::valid_padded(
(sapling_x as f32 + *x) as usize,
Copy link
Owner Author

Choose a reason for hiding this comment

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

Duplicate code, I know....

what do I do?

for dx in -bush_radius..bush_radius {
for dz in -bush_radius..bush_radius {
for dy in -bush_radius..bush_radius {
let distance_from_center = dx * dx + dy * dy + dz * dz;
Copy link
Owner Author

Choose a reason for hiding this comment

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

Pythagoras saves the day

}
}

for dy in 1..tree_stump_height {
Copy link
Owner Author

Choose a reason for hiding this comment

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

I want to override the leaves with stump.

@CuddlyBunion341 CuddlyBunion341 merged commit 8273f06 into main Mar 2, 2025
3 checks passed
@CuddlyBunion341 CuddlyBunion341 deleted the feature/trees branch March 2, 2025 18:52
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.

1 participant