Alexander Medvedev committed 2026-04-21 21:45:26 +02:00
1 parent be4496c25b
commit b5b1c0727c
4 files changed
+25 -56

No files matched your search

@@ -360,8 +360,6 @@ impl Cache {
self.chunks[mid].get_proto_chunk_mut().set_structure_starts( self.chunks[mid].get_proto_chunk_mut().set_structure_starts(
random_config, random_config,
settings, settings,
&dimension,
noise_router,
global_structure_cache, global_structure_cache,
); );
} }
+5 -37
View File
@@ -764,24 +764,15 @@ impl ProtoChunk {
noise_sampler.interpolate_z(local_z as f64 * delta_x_z_step); noise_sampler.interpolate_z(local_z as f64 * delta_x_z_step);
let block_z = block_z_base + local_z; let block_z = block_z_base + local_z;
// The `cell_offset` calculations are still a good idea for clarity and correctness
// but let's confirm the values.
// block_x = start_block_x + cell_x*H + local_x
// sample_start_x = start_cell_x*H + cell_x*H = (start_cell_x+cell_x)*H
// These can be simplified.
let cell_offset_x = local_x;
let cell_offset_y = block_y - sample_start_y;
let cell_offset_z = local_z;
let block_state = noise_sampler let block_state = noise_sampler
.sample_block_state( .sample_block_state(
ore_random_deriver, ore_random_deriver,
sample_start_x, sample_start_x,
sample_start_y, sample_start_y,
sample_start_z, sample_start_z,
cell_offset_x, local_x,
cell_offset_y, block_y - sample_start_y,
cell_offset_z, local_z,
surface_height_estimate_sampler, surface_height_estimate_sampler,
) )
.unwrap_or(self.default_block); .unwrap_or(self.default_block);
@@ -1132,32 +1123,11 @@ impl ProtoChunk {
&mut self, &mut self,
random_config: &GlobalRandomConfig, random_config: &GlobalRandomConfig,
settings: &GenerationSettings, settings: &GenerationSettings,
dimension: &Dimension, // <-- Added Parameter
noise_router: &ProtoNoiseRouters, // <-- Added Parameter
global_cache: &GlobalStructureCache, global_cache: &GlobalStructureCache,
) { ) {
let seed = random_config.seed; let seed = random_config.seed;
let calculator = StructurePlacementCalculator::new(seed as i64); let calculator = StructurePlacementCalculator::new(seed as i64);
// Initialize mathematical biome tools for ConcentricRings snapping
let active_supplier = if *dimension == Dimension::THE_END {
ActiveSupplier::End(TheEndBiomeSupplier)
} else if *dimension == Dimension::THE_NETHER {
ActiveSupplier::Nether(MultiNoiseBiomeSupplier::NETHER)
} else {
ActiveSupplier::Overworld(MultiNoiseBiomeSupplier::OVERWORLD)
};
let base_supplier: &dyn BiomeSupplier = match &active_supplier {
ActiveSupplier::End(s) => s,
ActiveSupplier::Nether(s) => s,
ActiveSupplier::Overworld(s) => s,
};
let biome_supplier = Blender::NO_BLEND.get_biome_supplier(base_supplier);
let multi_noise_config = MultiNoiseSamplerBuilderOptions::new(0, 0, 0);
let mut multi_noise_sampler =
MultiNoiseSampler::generate(&noise_router.multi_noise, &multi_noise_config);
for set in StructureSet::ALL { for set in StructureSet::ALL {
let allowed_biomes = Self::get_allowed_biomes(set); let allowed_biomes = Self::get_allowed_biomes(set);
@@ -1167,8 +1137,7 @@ impl ProtoChunk {
self.x, self.x,
self.z, self.z,
global_cache, global_cache,
&biome_supplier, self,
&mut multi_noise_sampler,
&allowed_biomes, &allowed_biomes,
) { ) {
continue; continue;
@@ -1305,8 +1274,7 @@ impl ProtoChunk {
let strongholds = global_cache.get_or_calculate_strongholds( let strongholds = global_cache.get_or_calculate_strongholds(
seed, seed,
rings, rings,
&biome_supplier, self,
&mut multi_noise_sampler,
&allowed_biomes, &allowed_biomes,
); );
for &(cx, cz) in strongholds { for &(cx, cz) in strongholds {
@@ -12,8 +12,7 @@ use pumpkin_util::{
use std::f64::consts::PI; use std::f64::consts::PI;
use std::sync::OnceLock; use std::sync::OnceLock;
use crate::biome::BiomeSupplier; use crate::ProtoChunk;
use crate::generation::noise::router::multi_noise_sampler::MultiNoiseSampler;
/// A thread-safe global cache for structures that require world-wide placement calculations /// A thread-safe global cache for structures that require world-wide placement calculations
/// rather than localized chunk-based math (e.g., Strongholds using Concentric Rings). /// rather than localized chunk-based math (e.g., Strongholds using Concentric Rings).
/// ///
@@ -45,8 +44,7 @@ impl GlobalStructureCache {
&self, &self,
seed: i64, seed: i64,
placement: &ConcentricRingsStructurePlacement, placement: &ConcentricRingsStructurePlacement,
biome_supplier: &dyn BiomeSupplier, biome_supplier: &ProtoChunk,
multi_noise_sampler: &mut MultiNoiseSampler,
allowed_biomes: &[u16], allowed_biomes: &[u16],
) -> &[(i32, i32)] { ) -> &[(i32, i32)] {
self.stronghold_chunks.get_or_init(|| { self.stronghold_chunks.get_or_init(|| {
@@ -100,12 +98,7 @@ impl GlobalStructureCache {
let test_x = center_block_x + dx; let test_x = center_block_x + dx;
let test_z = center_block_z + dz; let test_z = center_block_z + dz;
let biome_x = crate::generation::biome_coords::from_block(test_x); let biome = biome_supplier.get_biome(test_x, 0, test_z);
let biome_y = crate::generation::biome_coords::from_block(0);
let biome_z = crate::generation::biome_coords::from_block(test_z);
let biome =
biome_supplier.biome(biome_x, biome_y, biome_z, multi_noise_sampler);
if allowed_biomes.contains(&(biome.id as u16)) { if allowed_biomes.contains(&(biome.id as u16)) {
found_count += 1; found_count += 1;
@@ -147,15 +140,14 @@ impl Default for GlobalStructureCache {
} }
#[must_use] #[must_use]
#[expect(clippy::too_many_arguments)] // #[expect(clippy::too_many_arguments)]
pub fn should_generate_structure( pub fn should_generate_structure(
placement: &StructurePlacement, placement: &StructurePlacement,
calculator: &StructurePlacementCalculator, calculator: &StructurePlacementCalculator,
chunk_x: i32, chunk_x: i32,
chunk_z: i32, chunk_z: i32,
global_cache: &GlobalStructureCache, global_cache: &GlobalStructureCache,
biome_supplier: &dyn BiomeSupplier, biome_supplier: &ProtoChunk,
multi_noise_sampler: &mut MultiNoiseSampler,
allowed_biomes: &[u16], allowed_biomes: &[u16],
) -> bool { ) -> bool {
is_start_chunk( is_start_chunk(
@@ -166,7 +158,6 @@ pub fn should_generate_structure(
placement.salt, placement.salt,
global_cache, global_cache,
biome_supplier, biome_supplier,
multi_noise_sampler,
allowed_biomes, allowed_biomes,
) && apply_frequency_reduction( ) && apply_frequency_reduction(
placement.frequency_reduction_method, placement.frequency_reduction_method,
@@ -238,8 +229,7 @@ fn is_start_chunk(
chunk_z: i32, chunk_z: i32,
salt: u32, salt: u32,
global_cache: &GlobalStructureCache, global_cache: &GlobalStructureCache,
biome_supplier: &dyn BiomeSupplier, biome_supplier: &ProtoChunk,
multi_noise_sampler: &mut MultiNoiseSampler,
allowed_biomes: &[u16], allowed_biomes: &[u16],
) -> bool { ) -> bool {
match placement_type { match placement_type {
@@ -251,7 +241,6 @@ fn is_start_chunk(
calculator.seed, calculator.seed,
placement, placement,
biome_supplier, biome_supplier,
multi_noise_sampler,
allowed_biomes, allowed_biomes,
); );
strongholds.contains(&(chunk_x, chunk_z)) strongholds.contains(&(chunk_x, chunk_z))
+14
View File
@@ -10,6 +10,7 @@ use pumpkin_data::entity::EntityType;
use pumpkin_data::item::Item; use pumpkin_data::item::Item;
use pumpkin_data::item_stack::ItemStack; use pumpkin_data::item_stack::ItemStack;
use pumpkin_data::{Block, BlockDirection}; use pumpkin_data::{Block, BlockDirection};
use pumpkin_util::math::boundingbox::BoundingBox;
use pumpkin_util::math::position::BlockPos; use pumpkin_util::math::position::BlockPos;
use pumpkin_util::math::vector3::Vector3; use pumpkin_util::math::vector3::Vector3;
@@ -40,6 +41,19 @@ impl ItemBehaviour for EndCrystalItem {
} }
let location = location.up(); let location = location.up();
let location_vec = location.0.to_f64();
if !world.get_block_state(&location).await.is_air()
|| !world
.get_entities_at_box(&BoundingBox::new(
Vector3::new(location_vec.x, location_vec.y, location_vec.z),
Vector3::new(location_vec.x + 1.0, location_vec.y + 2.0, location_vec.z),
))
.is_empty()
{
return;
}
let entity = Entity::new(world.clone(), location.to_f64(), &EntityType::END_CRYSTAL); let entity = Entity::new(world.clone(), location.to_f64(), &EntityType::END_CRYSTAL);
let end_crystal = Arc::new(EndCrystalEntity::new(entity)); let end_crystal = Arc::new(EndCrystalEntity::new(entity));
world.spawn_entity(end_crystal.clone()).await; world.spawn_entity(end_crystal.clone()).await;