chore: move to crates folder
This commit is contained in:
1 parent
5d10c0d8a8
commit
cb3660bcd2
3393 files changed
+1270
-741
No files matched your search
@@ -0,0 +1,387 @@
|
||||
use pumpkin_data::{
|
||||
chunk::Biome,
|
||||
chunk_gen_settings::{
|
||||
AboveYMaterialCondition, MaterialCondition, NoiseThresholdMaterialCondition,
|
||||
NotMaterialCondition, StoneDepthMaterialCondition, VerticalGradientMaterialCondition,
|
||||
WaterMaterialCondition,
|
||||
},
|
||||
};
|
||||
use pumpkin_util::{
|
||||
math::{lerp2, vertical_surface_type::VerticalSurfaceType},
|
||||
random::{RandomImpl, xoroshiro128::XoroshiroSplitter},
|
||||
};
|
||||
|
||||
use terrain::SurfaceTerrainBuilder;
|
||||
|
||||
use crate::{
|
||||
ProtoChunk,
|
||||
generation::{positions::chunk_pos, section_coords},
|
||||
};
|
||||
|
||||
use super::{
|
||||
noise::perlin::DoublePerlinNoiseSampler,
|
||||
noise::router::{
|
||||
proto_noise_router::DoublePerlinNoiseBuilder,
|
||||
surface_height_sampler::SurfaceHeightEstimateSampler,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod rule;
|
||||
pub mod terrain;
|
||||
|
||||
pub struct MaterialRuleContext<'a> {
|
||||
pub min_y: i8,
|
||||
pub height: u16,
|
||||
pub random_deriver: &'a XoroshiroSplitter,
|
||||
fluid_height: i32,
|
||||
pub block_pos_x: i32,
|
||||
pub block_pos_y: i32,
|
||||
pub block_pos_z: i32,
|
||||
pub biome: &'a Biome,
|
||||
pub run_depth: i32,
|
||||
pub secondary_depth: f64,
|
||||
packed_chunk_pos: i64,
|
||||
estimated_surface_heights: [i32; 4],
|
||||
last_unique_horizontal_pos_value: i64,
|
||||
last_est_heiht_unique_horizontal_pos_value: i64,
|
||||
unique_horizontal_pos_value: i64,
|
||||
surface_min_y: i32,
|
||||
pub surface_noise: &'a DoublePerlinNoiseSampler,
|
||||
pub secondary_noise: &'a DoublePerlinNoiseSampler,
|
||||
pub stone_depth_below: i32,
|
||||
pub stone_depth_above: i32,
|
||||
pub terrain_builder: &'a SurfaceTerrainBuilder,
|
||||
pub sea_level: i32,
|
||||
steep_material_condition: Option<bool>,
|
||||
}
|
||||
|
||||
impl<'a> MaterialRuleContext<'a> {
|
||||
pub const fn new(
|
||||
min_y: i8,
|
||||
height: u16,
|
||||
random_deriver: &'a XoroshiroSplitter,
|
||||
terrain_builder: &'a SurfaceTerrainBuilder,
|
||||
surface_noise: &'a DoublePerlinNoiseSampler,
|
||||
secondary_noise: &'a DoublePerlinNoiseSampler,
|
||||
sea_level: i32,
|
||||
) -> Self {
|
||||
const HORIZONTAL_POS: i64 = -i64::MAX; // Vanilla
|
||||
Self {
|
||||
min_y,
|
||||
height,
|
||||
estimated_surface_heights: [0, 0, 0, 0],
|
||||
surface_min_y: 0,
|
||||
packed_chunk_pos: i64::MAX,
|
||||
unique_horizontal_pos_value: HORIZONTAL_POS - 1, // Because pre increment
|
||||
last_unique_horizontal_pos_value: HORIZONTAL_POS - 1,
|
||||
last_est_heiht_unique_horizontal_pos_value: HORIZONTAL_POS - 1,
|
||||
random_deriver,
|
||||
terrain_builder,
|
||||
fluid_height: 0,
|
||||
block_pos_x: 0,
|
||||
block_pos_y: 0,
|
||||
block_pos_z: 0,
|
||||
biome: &Biome::PLAINS,
|
||||
run_depth: 0,
|
||||
secondary_depth: 0.0,
|
||||
surface_noise,
|
||||
secondary_noise,
|
||||
stone_depth_below: 0,
|
||||
stone_depth_above: 0,
|
||||
sea_level,
|
||||
steep_material_condition: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn sample_run_depth(&self) -> i32 {
|
||||
let noise =
|
||||
self.surface_noise
|
||||
.sample(self.block_pos_x as f64, 0.0, self.block_pos_z as f64);
|
||||
(noise * 2.75
|
||||
+ 3.0
|
||||
+ self
|
||||
.random_deriver
|
||||
.split_pos(self.block_pos_x, 0, self.block_pos_z)
|
||||
.next_f64()
|
||||
* 0.25) as i32
|
||||
}
|
||||
|
||||
pub fn init_horizontal(&mut self, x: i32, z: i32) {
|
||||
self.unique_horizontal_pos_value += 1;
|
||||
self.block_pos_x = x;
|
||||
self.block_pos_z = z;
|
||||
self.run_depth = self.sample_run_depth();
|
||||
}
|
||||
|
||||
pub const fn init_vertical(
|
||||
&mut self,
|
||||
stone_depth_above: i32,
|
||||
stone_depth_below: i32,
|
||||
y: i32,
|
||||
fluid_height: i32,
|
||||
) {
|
||||
self.block_pos_y = y;
|
||||
self.fluid_height = fluid_height;
|
||||
self.stone_depth_below = stone_depth_below;
|
||||
self.stone_depth_above = stone_depth_above;
|
||||
}
|
||||
|
||||
pub fn get_secondary_depth(&mut self) -> f64 {
|
||||
if self.last_unique_horizontal_pos_value != self.unique_horizontal_pos_value {
|
||||
self.last_unique_horizontal_pos_value = self.unique_horizontal_pos_value;
|
||||
self.secondary_depth =
|
||||
self.secondary_noise
|
||||
.sample(self.block_pos_x as f64, 0.0, self.block_pos_z as f64);
|
||||
}
|
||||
self.secondary_depth
|
||||
}
|
||||
|
||||
pub const fn set_steep_material_condition(&mut self, steep: bool) {
|
||||
self.steep_material_condition = Some(steep);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_condition(
|
||||
condition: &MaterialCondition,
|
||||
chunk: &mut ProtoChunk,
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> bool {
|
||||
match condition {
|
||||
MaterialCondition::Biome(biome) => BiomeMaterialCondition::test(biome.biome_is, context),
|
||||
MaterialCondition::NoiseThreshold(noise_threshold) => {
|
||||
test_noise_threshold(noise_threshold, context)
|
||||
}
|
||||
MaterialCondition::VerticalGradient(vertical_gradient) => {
|
||||
test_vertical_gradient(vertical_gradient, context)
|
||||
}
|
||||
MaterialCondition::YAbove(above_y) => test_above_y_material(above_y, context),
|
||||
MaterialCondition::Water(water) => test_water_material(water, context),
|
||||
MaterialCondition::Temperature => {
|
||||
let temperature = context.biome.weather.compute_temperature(
|
||||
context.block_pos_x as f64,
|
||||
context.block_pos_y,
|
||||
context.block_pos_z as f64,
|
||||
context.sea_level,
|
||||
);
|
||||
temperature < 0.15f32
|
||||
}
|
||||
MaterialCondition::Steep => context.steep_material_condition.unwrap_or_else(|| {
|
||||
steep_material_condition(chunk, context.block_pos_x, context.block_pos_z)
|
||||
}),
|
||||
MaterialCondition::Not(not) => {
|
||||
test_not_material(not, chunk, context, surface_height_estimate_sampler)
|
||||
}
|
||||
MaterialCondition::Hole(_hole) => HoleMaterialCondition::test(context),
|
||||
MaterialCondition::AbovePreliminarySurface(_above) => {
|
||||
SurfaceMaterialCondition::test(context, surface_height_estimate_sampler)
|
||||
}
|
||||
MaterialCondition::StoneDepth(stone_depth) => test_stone_depth(stone_depth, context),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn steep_material_condition(chunk: &ProtoChunk, block_x: i32, block_z: i32) -> bool {
|
||||
let local_x = block_x & 15;
|
||||
let local_z = block_z & 15;
|
||||
|
||||
let local_z_sub = 0.max(local_z - 1);
|
||||
let local_z_add = 15.min(local_z + 1);
|
||||
|
||||
let sub_height = chunk.top_block_height_exclusive(local_x, local_z_sub);
|
||||
let add_height = chunk.top_block_height_exclusive(local_x, local_z_add);
|
||||
|
||||
if add_height >= sub_height + 4 {
|
||||
return true;
|
||||
}
|
||||
|
||||
let local_x_sub = 0.max(local_x - 1);
|
||||
let local_x_add = 15.min(local_x + 1);
|
||||
|
||||
let sub_height = chunk.top_block_height_exclusive(local_x_sub, local_z);
|
||||
let add_height = chunk.top_block_height_exclusive(local_x_add, local_z);
|
||||
|
||||
sub_height >= add_height + 4
|
||||
}
|
||||
|
||||
pub struct HoleMaterialCondition;
|
||||
|
||||
impl HoleMaterialCondition {
|
||||
pub const fn test(context: &MaterialRuleContext) -> bool {
|
||||
context.run_depth <= 0
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn test_above_y_material(
|
||||
condition: &AboveYMaterialCondition,
|
||||
context: &MaterialRuleContext,
|
||||
) -> bool {
|
||||
context.block_pos_y
|
||||
+ if condition.add_stone_depth {
|
||||
context.stone_depth_above
|
||||
} else {
|
||||
0
|
||||
}
|
||||
>= condition.anchor.get_y(context.min_y as i16, context.height)
|
||||
+ context.run_depth * condition.surface_depth_multiplier
|
||||
}
|
||||
|
||||
pub fn test_not_material(
|
||||
condition: &NotMaterialCondition,
|
||||
chunk: &mut ProtoChunk,
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> bool {
|
||||
!test_condition(
|
||||
condition.invert,
|
||||
chunk,
|
||||
context,
|
||||
surface_height_estimate_sampler,
|
||||
)
|
||||
}
|
||||
|
||||
pub struct SurfaceMaterialCondition;
|
||||
|
||||
impl SurfaceMaterialCondition {
|
||||
pub fn test(
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> bool {
|
||||
context.block_pos_y >= estimate_surface_height(context, surface_height_estimate_sampler)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn estimate_surface_height(
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> i32 {
|
||||
if context.last_est_heiht_unique_horizontal_pos_value != context.unique_horizontal_pos_value {
|
||||
context.last_est_heiht_unique_horizontal_pos_value = context.unique_horizontal_pos_value;
|
||||
let x = section_coords::block_to_section(context.block_pos_x);
|
||||
let z = section_coords::block_to_section(context.block_pos_z);
|
||||
let packed = chunk_pos::packed(x as u64, z as u64) as i64;
|
||||
if context.packed_chunk_pos != packed {
|
||||
context.packed_chunk_pos = packed;
|
||||
context.estimated_surface_heights[0] = surface_height_estimate_sampler.estimate_height(
|
||||
section_coords::section_to_block(x),
|
||||
section_coords::section_to_block(z),
|
||||
);
|
||||
context.estimated_surface_heights[1] = surface_height_estimate_sampler.estimate_height(
|
||||
section_coords::section_to_block(x + 1),
|
||||
section_coords::section_to_block(z),
|
||||
);
|
||||
context.estimated_surface_heights[2] = surface_height_estimate_sampler.estimate_height(
|
||||
section_coords::section_to_block(x),
|
||||
section_coords::section_to_block(z + 1),
|
||||
);
|
||||
context.estimated_surface_heights[3] = surface_height_estimate_sampler.estimate_height(
|
||||
section_coords::section_to_block(x + 1),
|
||||
section_coords::section_to_block(z + 1),
|
||||
);
|
||||
}
|
||||
let surface = lerp2(
|
||||
((context.block_pos_x & 15) as f32 / 16.0) as f64,
|
||||
((context.block_pos_z & 15) as f32 / 16.0) as f64,
|
||||
context.estimated_surface_heights[0] as f64,
|
||||
context.estimated_surface_heights[1] as f64,
|
||||
context.estimated_surface_heights[2] as f64,
|
||||
context.estimated_surface_heights[3] as f64,
|
||||
)
|
||||
.floor() as i32;
|
||||
context.surface_min_y = surface.saturating_add(context.run_depth) - 8;
|
||||
}
|
||||
context.surface_min_y
|
||||
}
|
||||
|
||||
pub struct BiomeMaterialCondition;
|
||||
|
||||
impl BiomeMaterialCondition {
|
||||
pub fn test(biome_is: &[&'static Biome], context: &MaterialRuleContext) -> bool {
|
||||
biome_is.contains(&context.biome)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_noise_threshold(
|
||||
condition: &NoiseThresholdMaterialCondition,
|
||||
context: &mut MaterialRuleContext,
|
||||
) -> bool {
|
||||
// TODO: we want to cache these
|
||||
let sampler = DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
context.random_deriver,
|
||||
&condition.noise,
|
||||
);
|
||||
let value = sampler.sample(context.block_pos_x as f64, 0.0, context.block_pos_z as f64);
|
||||
value >= condition.min_threshold && value <= condition.max_threshold
|
||||
}
|
||||
|
||||
pub fn test_stone_depth(
|
||||
condition: &StoneDepthMaterialCondition,
|
||||
context: &mut MaterialRuleContext,
|
||||
) -> bool {
|
||||
let stone_depth = match &condition.surface_type {
|
||||
VerticalSurfaceType::Ceiling => context.stone_depth_below,
|
||||
VerticalSurfaceType::Floor => context.stone_depth_above,
|
||||
};
|
||||
let depth = if condition.add_surface_depth {
|
||||
context.run_depth
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let depth_range = if condition.secondary_depth_range == 0 {
|
||||
0
|
||||
} else {
|
||||
pumpkin_util::math::map(
|
||||
context.get_secondary_depth(),
|
||||
-1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
condition.secondary_depth_range as f64,
|
||||
) as i32
|
||||
};
|
||||
stone_depth <= 1 + condition.offset + depth + depth_range
|
||||
}
|
||||
|
||||
pub const fn test_water_material(
|
||||
condition: &WaterMaterialCondition,
|
||||
context: &MaterialRuleContext,
|
||||
) -> bool {
|
||||
context.fluid_height == i32::MIN
|
||||
|| context.block_pos_y
|
||||
+ (if condition.add_stone_depth {
|
||||
context.stone_depth_above
|
||||
} else {
|
||||
0
|
||||
})
|
||||
>= context.fluid_height
|
||||
+ condition.offset
|
||||
+ context.run_depth * condition.surface_depth_multiplier
|
||||
}
|
||||
|
||||
// random_deriver: ThreadLocal<RefCell<LruCache<usize, RandomDeriver>>>,
|
||||
|
||||
pub fn test_vertical_gradient(
|
||||
condition: &VerticalGradientMaterialCondition,
|
||||
context: &MaterialRuleContext,
|
||||
) -> bool {
|
||||
let true_at = condition
|
||||
.true_at_and_below
|
||||
.get_y(context.min_y as i16, context.height);
|
||||
let false_at = condition
|
||||
.false_at_and_above
|
||||
.get_y(context.min_y as i16, context.height);
|
||||
|
||||
let block_y = context.block_pos_y;
|
||||
if block_y <= true_at {
|
||||
return true;
|
||||
}
|
||||
if block_y >= false_at {
|
||||
return false;
|
||||
}
|
||||
let splitter = context
|
||||
.random_deriver
|
||||
.from_lo_and_hi(condition.random_lo, condition.random_hi)
|
||||
.next_splitter();
|
||||
let mapped = pumpkin_util::math::map(block_y as f32, true_at as f32, false_at as f32, 1.0, 0.0);
|
||||
let mut random = splitter.split_pos(context.block_pos_x, block_y, context.block_pos_z);
|
||||
random.next_f32() < mapped
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
use pumpkin_data::{
|
||||
BlockState,
|
||||
chunk_gen_settings::{ConditionMaterialRule, MaterialRule, SequenceMaterialRule},
|
||||
};
|
||||
|
||||
use super::MaterialRuleContext;
|
||||
use crate::{
|
||||
ProtoChunk,
|
||||
generation::{
|
||||
noise::router::surface_height_sampler::SurfaceHeightEstimateSampler,
|
||||
surface::test_condition,
|
||||
},
|
||||
};
|
||||
|
||||
pub fn try_apply_material_rule(
|
||||
rule: &MaterialRule,
|
||||
chunk: &mut ProtoChunk,
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> Option<&'static BlockState> {
|
||||
match rule {
|
||||
MaterialRule::Badlands(_badlands) => Some(BadLandsMaterialRule::try_apply(context)),
|
||||
MaterialRule::Block(block) => Some(BlockMaterialRule::try_apply(block.result_state)),
|
||||
MaterialRule::Sequence(sequence) => {
|
||||
try_apply_sequence(sequence, chunk, context, surface_height_estimate_sampler)
|
||||
}
|
||||
MaterialRule::Condition(condition) => {
|
||||
try_apply_condition(condition, chunk, context, surface_height_estimate_sampler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BadLandsMaterialRule;
|
||||
|
||||
impl BadLandsMaterialRule {
|
||||
pub fn try_apply(context: &mut MaterialRuleContext) -> &'static BlockState {
|
||||
context.terrain_builder.get_terracotta_block(
|
||||
context.block_pos_x,
|
||||
context.block_pos_y,
|
||||
context.block_pos_z,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BlockMaterialRule;
|
||||
|
||||
impl BlockMaterialRule {
|
||||
pub const fn try_apply(state: &'static BlockState) -> &'static BlockState {
|
||||
state
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_apply_sequence(
|
||||
rule: &SequenceMaterialRule,
|
||||
chunk: &mut ProtoChunk,
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> Option<&'static BlockState> {
|
||||
for seq in rule.sequence {
|
||||
if let Some(state) =
|
||||
try_apply_material_rule(seq, chunk, context, surface_height_estimate_sampler)
|
||||
{
|
||||
return Some(state);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn try_apply_condition(
|
||||
rule: &ConditionMaterialRule,
|
||||
chunk: &mut ProtoChunk,
|
||||
context: &mut MaterialRuleContext,
|
||||
surface_height_estimate_sampler: &mut SurfaceHeightEstimateSampler,
|
||||
) -> Option<&'static BlockState> {
|
||||
if test_condition(
|
||||
&rule.if_true,
|
||||
chunk,
|
||||
context,
|
||||
surface_height_estimate_sampler,
|
||||
) {
|
||||
return try_apply_material_rule(
|
||||
rule.then_run,
|
||||
chunk,
|
||||
context,
|
||||
surface_height_estimate_sampler,
|
||||
);
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
use pumpkin_data::{
|
||||
Block, BlockState, BlockStateId,
|
||||
chunk::{Biome, DoublePerlinNoiseParameters},
|
||||
};
|
||||
use pumpkin_util::{
|
||||
math::vector3::Vector3,
|
||||
random::{
|
||||
RandomImpl,
|
||||
xoroshiro128::{Xoroshiro, XoroshiroSplitter},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ProtoChunk,
|
||||
generation::noise::{
|
||||
WATER_BLOCK, perlin::DoublePerlinNoiseSampler,
|
||||
router::proto_noise_router::DoublePerlinNoiseBuilder,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct SurfaceTerrainBuilder {
|
||||
// Badlands stuff
|
||||
terracotta_bands: Box<[BlockStateId]>,
|
||||
terracotta_bands_offset_noise: DoublePerlinNoiseSampler,
|
||||
badlands_pillar_noise: DoublePerlinNoiseSampler,
|
||||
badlands_surface_noise: DoublePerlinNoiseSampler,
|
||||
badlands_pillar_roof_noise: DoublePerlinNoiseSampler,
|
||||
// Iceberg stuff
|
||||
iceberg_pillar_noise: DoublePerlinNoiseSampler,
|
||||
iceberg_pillar_roof_noise: DoublePerlinNoiseSampler,
|
||||
iceberg_surface_noise: DoublePerlinNoiseSampler,
|
||||
}
|
||||
|
||||
impl SurfaceTerrainBuilder {
|
||||
pub fn new(random_deriver: &XoroshiroSplitter) -> Self {
|
||||
Self {
|
||||
terracotta_bands: Self::create_terracotta_bands(
|
||||
random_deriver.split_string("minecraft:clay_bands"),
|
||||
),
|
||||
terracotta_bands_offset_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::CLAY_BANDS_OFFSET,
|
||||
),
|
||||
badlands_pillar_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::BADLANDS_PILLAR,
|
||||
),
|
||||
badlands_surface_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::BADLANDS_SURFACE,
|
||||
),
|
||||
badlands_pillar_roof_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::BADLANDS_PILLAR_ROOF,
|
||||
),
|
||||
iceberg_pillar_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::ICEBERG_PILLAR,
|
||||
),
|
||||
iceberg_pillar_roof_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::ICEBERG_PILLAR_ROOF,
|
||||
),
|
||||
iceberg_surface_noise: DoublePerlinNoiseBuilder::get_noise_sampler_for_id(
|
||||
random_deriver,
|
||||
&DoublePerlinNoiseParameters::ICEBERG_SURFACE,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
const ORANGE_TERRACOTTA: BlockStateId = Block::ORANGE_TERRACOTTA.default_state.id;
|
||||
const YELLOW_TERRACOTTA: BlockStateId = Block::YELLOW_TERRACOTTA.default_state.id;
|
||||
const BROWN_TERRACOTTA: BlockStateId = Block::BROWN_TERRACOTTA.default_state.id;
|
||||
const RED_TERRACOTTA: BlockStateId = Block::RED_TERRACOTTA.default_state.id;
|
||||
const WHITE_TERRACOTTA: BlockStateId = Block::WHITE_TERRACOTTA.default_state.id;
|
||||
const LIGHT_GRAY_TERRACOTTA: BlockStateId = Block::LIGHT_GRAY_TERRACOTTA.default_state.id;
|
||||
const TERRACOTTA: BlockStateId = Block::TERRACOTTA.default_state.id;
|
||||
|
||||
fn create_terracotta_bands(mut random: Xoroshiro) -> Box<[BlockStateId]> {
|
||||
let mut block_states = [Self::TERRACOTTA; 192];
|
||||
|
||||
let mut i = 0;
|
||||
while i < block_states.len() {
|
||||
i += random.next_bounded_i32(5) as usize + 1;
|
||||
if i >= block_states.len() {
|
||||
break;
|
||||
}
|
||||
block_states[i] = Self::ORANGE_TERRACOTTA;
|
||||
i += 1;
|
||||
}
|
||||
|
||||
Self::add_terracotta_bands(&mut random, &mut block_states, 1, Self::YELLOW_TERRACOTTA);
|
||||
Self::add_terracotta_bands(&mut random, &mut block_states, 2, Self::BROWN_TERRACOTTA);
|
||||
Self::add_terracotta_bands(&mut random, &mut block_states, 1, Self::RED_TERRACOTTA);
|
||||
|
||||
let band_count = random.next_inbetween_i32(9, 15);
|
||||
let mut current_band = 0;
|
||||
let mut index = 0;
|
||||
|
||||
while current_band < band_count && index < block_states.len() {
|
||||
block_states[index] = Self::WHITE_TERRACOTTA;
|
||||
|
||||
if index > 1 && random.next_bool() {
|
||||
block_states[index - 1] = Self::LIGHT_GRAY_TERRACOTTA;
|
||||
}
|
||||
|
||||
if index + 1 < block_states.len() && random.next_bool() {
|
||||
block_states[index + 1] = Self::LIGHT_GRAY_TERRACOTTA;
|
||||
}
|
||||
|
||||
index += random.next_bounded_i32(16) as usize + 4;
|
||||
current_band += 1;
|
||||
}
|
||||
|
||||
Box::new(block_states)
|
||||
}
|
||||
|
||||
fn add_terracotta_bands(
|
||||
random: &mut Xoroshiro,
|
||||
terracotta_bands: &mut [BlockStateId],
|
||||
min_band_size: i32,
|
||||
state: BlockStateId,
|
||||
) {
|
||||
let band_count = random.next_inbetween_i32(6, 15);
|
||||
|
||||
for _ in 0..band_count {
|
||||
let band_width = min_band_size + random.next_bounded_i32(3);
|
||||
let start_index = random.next_bounded_i32(terracotta_bands.len() as i32);
|
||||
|
||||
for m in 0..band_width {
|
||||
if (start_index + m < terracotta_bands.len() as i32) && (m < band_width) {
|
||||
terracotta_bands[(start_index + m) as usize] = state;
|
||||
} else {
|
||||
break; // Stop if we reach the end of the array
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn place_badlands_pillar(
|
||||
&self,
|
||||
chunk: &mut ProtoChunk,
|
||||
global_x: i32,
|
||||
global_z: i32,
|
||||
surface_y: i32,
|
||||
) {
|
||||
let surface_noise =
|
||||
(self
|
||||
.badlands_surface_noise
|
||||
.sample(global_x as f64, 0.0, global_z as f64)
|
||||
* 8.25)
|
||||
.abs();
|
||||
let pillar_noise =
|
||||
self.badlands_pillar_noise
|
||||
.sample(global_x as f64 * 0.2, 0.0, global_z as f64 * 0.2)
|
||||
* 15.0;
|
||||
|
||||
let threshold = surface_noise.min(pillar_noise);
|
||||
|
||||
if threshold > 0.0 {
|
||||
let pillar_roof_noise = (self.badlands_pillar_roof_noise.sample(
|
||||
global_x as f64 * 0.75,
|
||||
0.0,
|
||||
global_z as f64 * 0.75,
|
||||
) * 1.5)
|
||||
.abs();
|
||||
|
||||
let scaled_threshold = threshold * threshold * 2.5;
|
||||
let transformed_roof = (pillar_roof_noise * 50.0).ceil() + 24.0;
|
||||
let elevation = 64.0 + scaled_threshold.min(transformed_roof);
|
||||
let elevation_y = elevation.floor() as i32;
|
||||
if surface_y <= elevation_y {
|
||||
for y in (chunk.bottom_y() as i32..=elevation_y).rev() {
|
||||
let pos = Vector3::new(global_x, y, global_z);
|
||||
let block_id = chunk.get_block_state(&pos).to_block_id();
|
||||
if block_id == chunk.default_block.id.to_block_id() {
|
||||
break;
|
||||
}
|
||||
|
||||
if block_id == Block::WATER {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for y in (chunk.bottom_y() as i32..=elevation_y).rev() {
|
||||
let pos = Vector3::new(global_x, y, global_z);
|
||||
let block_state = chunk.get_block_state(&pos).to_state();
|
||||
if !block_state.is_air() {
|
||||
break;
|
||||
}
|
||||
|
||||
let default_block = &chunk.default_block;
|
||||
chunk.set_block_state(global_x, y, global_z, default_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SNOW_BLOCK: Block = Block::SNOW_BLOCK;
|
||||
const PACKED_ICE: Block = Block::PACKED_ICE;
|
||||
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
pub fn place_iceberg(
|
||||
&self,
|
||||
chunk: &mut ProtoChunk,
|
||||
biome: &Biome,
|
||||
x: i32,
|
||||
z: i32,
|
||||
estimated_surface_y: i32,
|
||||
current_top_y: i32,
|
||||
sea_level: i32,
|
||||
random_deriver: &XoroshiroSplitter,
|
||||
) {
|
||||
let iceburg_surface_noise =
|
||||
(self.iceberg_surface_noise.sample(x as f64, 0.0, z as f64) * 8.25).abs();
|
||||
|
||||
let iceburg_pillar_noise =
|
||||
self.iceberg_pillar_noise
|
||||
.sample(x as f64 * 1.28, 0.0, z as f64 * 1.28)
|
||||
* 15.0;
|
||||
|
||||
let threshold = iceburg_surface_noise.min(iceburg_pillar_noise);
|
||||
if threshold > 1.8 {
|
||||
let iceburg_pillar_roof_noise =
|
||||
(self
|
||||
.iceberg_pillar_roof_noise
|
||||
.sample(x as f64 * 1.17, 0.0, z as f64 * 1.17)
|
||||
* 1.5)
|
||||
.abs();
|
||||
|
||||
let scaled_threshold = threshold * threshold * 1.2;
|
||||
let scaled_roof_noise = (iceburg_pillar_roof_noise * 40.0).ceil() + 14.0;
|
||||
|
||||
let mut block_threshold = scaled_threshold.min(scaled_roof_noise);
|
||||
|
||||
// TODO: Cache this
|
||||
let temperature = biome
|
||||
.weather
|
||||
.compute_temperature(x as f64, sea_level, z as f64, sea_level);
|
||||
if temperature > 0.1f32 {
|
||||
block_threshold -= 2.0;
|
||||
}
|
||||
|
||||
let (top_block, bottom_block) = if block_threshold > 2.0 {
|
||||
let value = sea_level as f64 - block_threshold - 7.0;
|
||||
(block_threshold as i32 + sea_level, value as i32)
|
||||
} else {
|
||||
(0, 0)
|
||||
};
|
||||
|
||||
let mut rand = random_deriver.split_pos(x, 0, z);
|
||||
let snow_block_count = 2 + rand.next_bounded_i32(4);
|
||||
let snow_bottom = sea_level + 18 + rand.next_bounded_i32(10);
|
||||
let mut snow_blocks = 0;
|
||||
|
||||
let top_y = current_top_y.max(top_block + 1);
|
||||
|
||||
for y in (estimated_surface_y..=top_y).rev() {
|
||||
let pos = Vector3::new(x, y, z);
|
||||
let block_state = chunk.get_block_state(&pos);
|
||||
if (block_state.to_state().is_air() && y < top_block && rand.next_f64() > 0.01)
|
||||
|| (block_state.to_block_id() == WATER_BLOCK
|
||||
&& y > bottom_block
|
||||
&& y < sea_level
|
||||
&& bottom_block != 0
|
||||
&& rand.next_f64() > 0.15)
|
||||
{
|
||||
if snow_blocks <= snow_block_count && y > snow_bottom {
|
||||
chunk.set_block_state(x, y, z, Self::SNOW_BLOCK.default_state);
|
||||
snow_blocks += 1;
|
||||
} else {
|
||||
chunk.set_block_state(x, y, z, Self::PACKED_ICE.default_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_terracotta_block(&self, x: i32, y: i32, z: i32) -> &'static BlockState {
|
||||
let offset = (self
|
||||
.terracotta_bands_offset_noise
|
||||
.sample(x as f64, 0.0, z as f64)
|
||||
* 4.0)
|
||||
.round() as i32;
|
||||
let offset = y + offset;
|
||||
self.terracotta_bands[((offset as u64 + self.terracotta_bands.len() as u64)
|
||||
% self.terracotta_bands.len() as u64) as usize]
|
||||
.to_state()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user