Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions steel-core/src/behavior/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ pub use vegetation::{
BaseCoralFanBlock, BaseCoralPlantBlock, BaseCoralWallFanBlock, BigDripleafBlock,
BigDripleafStemBlock, BushBlock, CarpetBlock, CaveVinesBlock, CaveVinesPlantBlock,
ChorusFlowerBlock, ChorusPlantBlock, CoralFanBlock, CoralPlantBlock, CoralWallFanBlock,
DryVegetationBlock, EyeblossomBlock, EyeblossomType, FarmlandBlock, FireflyBushBlock,
FlowerBedBlock, GlowLichenBlock, HangingMossBlock, HangingRootsBlock, KelpBlock,
KelpPlantBlock, LeafLitterBlock, LilyPadBlock, MangrovePropaguleBlock, MossyCarpetBlock,
MushroomBlock, NetherFungusBlock, NetherRootsBlock, PointedDripstoneBlock, SaplingBlock,
SculkVeinBlock, SeaPickleBlock, ShortDryGrassBlock, SmallDripleafBlock, SnowLayerBlock,
SporeBlossomBlock, SulfurSpikeBlock, TallDryGrassBlock, TwistingVinesBlock,
DirtPathBlock, DryVegetationBlock, EyeblossomBlock, EyeblossomType, FarmlandBlock,
FireflyBushBlock, FlowerBedBlock, GlowLichenBlock, HangingMossBlock, HangingRootsBlock,
KelpBlock, KelpPlantBlock, LeafLitterBlock, LilyPadBlock, MangrovePropaguleBlock,
MossyCarpetBlock, MushroomBlock, NetherFungusBlock, NetherRootsBlock, PointedDripstoneBlock,
SaplingBlock, SculkVeinBlock, SeaPickleBlock, ShortDryGrassBlock, SmallDripleafBlock,
SnowLayerBlock, SporeBlossomBlock, SulfurSpikeBlock, TallDryGrassBlock, TwistingVinesBlock,
TwistingVinesPlantBlock, VineBlock, WeepingVinesBlock, WeepingVinesPlantBlock, WitherRoseBlock,
};
78 changes: 78 additions & 0 deletions steel-core/src/behavior/blocks/vegetation/dirt_path_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use std::sync::Arc;

use steel_macros::block_behavior;
use steel_registry::blocks::BlockRef;
use steel_registry::blocks::block_state_ext::BlockStateExt;
use steel_registry::vanilla_block_tags::BlockTag;
use steel_registry::vanilla_blocks;
use steel_utils::{BlockPos, BlockStateId, Direction};

use crate::behavior::block::{BlockBehavior, push_entities_up};
use crate::behavior::context::BlockPlaceContext;
use crate::entity::ai::path::PathComputationType;
use crate::world::{LevelReader, ScheduledTickAccess, World};

use super::FarmlandBlock;

/// Behavior for dirt path blocks.
#[block_behavior]
pub struct DirtPathBlock {
block: BlockRef,
}

impl DirtPathBlock {
/// Creates a new dirt path block behavior.
#[must_use]
pub const fn new(block: BlockRef) -> Self {
Self { block }
}
}

impl BlockBehavior for DirtPathBlock {
fn get_state_for_placement(&self, context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
let path_state = self.block.default_state();
let pos = context.place_pos();
if self.can_survive(path_state, context.world, pos) {
Some(path_state)
} else {
Some(push_entities_up(
path_state,
vanilla_blocks::DIRT.default_state(),
context.world,
pos,
))
}
}

fn can_survive(&self, _state: BlockStateId, world: &dyn LevelReader, pos: BlockPos) -> bool {
let above = world.get_block_state(pos.above());
!above.is_solid() || above.get_block().has_tag(&BlockTag::FENCE_GATES)
}

fn update_shape(
&self,
state: BlockStateId,
world: &dyn ScheduledTickAccess,
pos: BlockPos,
direction: Direction,
_neighbor_pos: BlockPos,
_neighbor_state: BlockStateId,
) -> BlockStateId {
if direction == Direction::Up && !self.can_survive(state, world, pos) {
let _ = world.schedule_block_tick_default(pos, self.block, 1);
}
state
}

fn tick(&self, state: BlockStateId, world: &Arc<World>, pos: BlockPos) {
FarmlandBlock::turn_to_dirt(state, world, pos, None);
}

fn is_pathfindable(
&self,
_state: BlockStateId,
_computation_type: PathComputationType,
) -> bool {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl FarmlandBlock {
}

/// Turns the farmland into dirt.
fn turn_to_dirt(
pub(crate) fn turn_to_dirt(
state: BlockStateId,
world: &Arc<World>,
pos: BlockPos,
Expand Down
2 changes: 2 additions & 0 deletions steel-core/src/behavior/blocks/vegetation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod coral_fan_block;
mod coral_plant_block;
mod coral_wall_fan_block;
mod crop_block;
mod dirt_path_block;
mod double_plant_block;
mod dry_vegetation_block;
mod eyeblossom_block;
Expand Down Expand Up @@ -101,6 +102,7 @@ pub use coral_fan_block::CoralFanBlock;
pub use coral_plant_block::CoralPlantBlock;
pub use coral_wall_fan_block::CoralWallFanBlock;
pub use crop_block::CropBlock;
pub use dirt_path_block::DirtPathBlock;
pub use double_plant_block::DoublePlantBlock;
pub use dry_vegetation_block::DryVegetationBlock;
pub use eyeblossom_block::{EyeblossomBlock, EyeblossomType};
Expand Down
Loading