Skip to content
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/flint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Flint Tests

on:
push:
branches: ['**']
branches: ['master']
tags: ['**']
pull_request:

Expand Down Expand Up @@ -30,6 +30,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: JunkyDeveloper/FlintBenchmark
ref: walls
path: FlintBenchmark

- name: Setup Rust nightly
Expand Down
21 changes: 17 additions & 4 deletions steel-core/build/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub fn build(blocks: &[BlockClass]) -> String {
let mut wall_torch_blocks = Vec::new();
let mut redstone_torch_blocks = Vec::new();
let mut redstone_wall_torch_blocks = Vec::new();
let mut fire_blocks = Vec::new();
let mut nether_portal_blocks = Vec::new();
let mut weathering_full_blocks: Vec<(Ident, Ident)> = Vec::new();
let mut cactus_blocks = Vec::new();
let mut cactus_flower_blocks: Vec<Ident> = Vec::new();
Expand Down Expand Up @@ -128,6 +130,8 @@ pub fn build(blocks: &[BlockClass]) -> String {
}
"CactusBlock" => cactus_blocks.push(const_ident),
"CactusFlowerBlock" => cactus_flower_blocks.push(const_ident),
"FireBlock" => fire_blocks.push(const_ident),
"NetherPortalBlock" => nether_portal_blocks.push(const_ident),
_ => {}
}
}
Expand All @@ -148,6 +152,8 @@ pub fn build(blocks: &[BlockClass]) -> String {
let wall_torch_type = Ident::new("WallTorchBlock", Span::call_site());
let redstone_torch_type = Ident::new("RedstoneTorchBlock", Span::call_site());
let redstone_wall_torch_type = Ident::new("RedstoneWallTorchBlock", Span::call_site());
let fire_type = Ident::new("FireBlock", Span::call_site());
let nether_portal_block = Ident::new("NetherPortalBlock", Span::call_site());
let cactus_type = Ident::new("CactusBlock", Span::call_site());
let cactus_flower_type = Ident::new("CactusFlowerBlock", Span::call_site());

Expand Down Expand Up @@ -226,17 +232,22 @@ pub fn build(blocks: &[BlockClass]) -> String {
let cactus_registrations = generate_registrations(cactus_blocks.iter(), &cactus_type);
let cactus_flower_registrations =
generate_registrations(cactus_flower_blocks.iter(), &cactus_flower_type);
let fire_registrations = generate_registrations(fire_blocks.iter(), &fire_type);
let nether_portal_registrations =
generate_registrations(nether_portal_blocks.iter(), &nether_portal_block);

let output = quote! {
//! Generated block behavior assignments.

use steel_registry::{sound_events, vanilla_blocks, vanilla_fluids};
use crate::behavior::BlockBehaviorRegistry;
use crate::behavior::blocks::{
BarrelBlock, ButtonBlock, CandleBlock, CraftingTableBlock, CropBlock, EndPortalFrameBlock,
FarmlandBlock, FenceBlock, LiquidBlock, RotatedPillarBlock, StandingSignBlock, WallSignBlock,
CeilingHangingSignBlock, WallHangingSignBlock, TorchBlock, WallTorchBlock,
RedstoneTorchBlock, RedstoneWallTorchBlock, WeatherState, WeatheringCopperFullBlock, CactusBlock, CactusFlowerBlock,
BarrelBlock, ButtonBlock, CactusBlock, CactusFlowerBlock, CandleBlock,
CeilingHangingSignBlock, CraftingTableBlock, CropBlock, EndPortalFrameBlock,
FarmlandBlock, FenceBlock, FireBlock, LiquidBlock, NetherPortalBlock,
RedstoneTorchBlock, RedstoneWallTorchBlock, RotatedPillarBlock,
StandingSignBlock, TorchBlock, WallHangingSignBlock, WallSignBlock,
WallTorchBlock, WeatherState, WeatheringCopperFullBlock,
};

pub fn register_block_behaviors(registry: &mut BlockBehaviorRegistry) {
Expand All @@ -261,6 +272,8 @@ pub fn build(blocks: &[BlockClass]) -> String {
#weathering_full_block_registrations
#cactus_registrations
#cactus_flower_registrations
#fire_registrations
#nether_portal_registrations
}
};

Expand Down
9 changes: 8 additions & 1 deletion steel-core/build/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ fn generate_simple_registrations<'a>(
quote! { #(#registrations)* }
}

#[allow(clippy::too_many_lines)]
pub fn build(items: &[ItemClass]) -> String {
let mut block_items: Vec<(Ident, Ident)> = Vec::new();
let mut sign_items: Vec<(Ident, Ident, Ident)> = Vec::new();
let mut hanging_sign_items: Vec<(Ident, Ident, Ident)> = Vec::new();
let mut standing_and_wall_items: Vec<(Ident, Ident, Ident)> = Vec::new();
let mut ender_eye_items: Vec<Ident> = Vec::new();
let mut shovel_items: Vec<Ident> = Vec::new();
let mut flint_and_steel_items: Vec<Ident> = Vec::new();
let mut filled_bucket_items: Vec<(Ident, Ident)> = Vec::new();
let mut empty_bucket_items: Vec<Ident> = Vec::new();

Expand Down Expand Up @@ -181,6 +183,7 @@ pub fn build(items: &[ItemClass]) -> String {
}
"EnderEyeItem" => ender_eye_items.push(item_field),
"ShovelItem" => shovel_items.push(item_field),
"FlintAndSteelItem" => flint_and_steel_items.push(item_field),
"BucketItem" => {
let fluid = item.fluid.as_ref().expect("BucketItem missing `fluid`");
if fluid == "empty" {
Expand All @@ -205,6 +208,9 @@ pub fn build(items: &[ItemClass]) -> String {
generate_simple_registrations(ender_eye_items.iter(), &ender_eye_type);
let shovel_type = Ident::new("ShovelBehaviour", Span::call_site());
let shovel_registrations = generate_simple_registrations(shovel_items.iter(), &shovel_type);
let flint_and_steel_type = Ident::new("FlintAndSteelBehavior", Span::call_site());
let flint_and_steel_registrations =
generate_simple_registrations(flint_and_steel_items.iter(), &flint_and_steel_type);
let filled_bucket_registrations =
generate_filled_bucket_item_registrations(filled_bucket_items.iter());
let empty_bucket_type = Ident::new("EmptyBucketBehavior", Span::call_site());
Expand All @@ -216,7 +222,7 @@ pub fn build(items: &[ItemClass]) -> String {

use steel_registry::{vanilla_blocks, vanilla_items};
use crate::behavior::ItemBehaviorRegistry;
use crate::behavior::items::{BlockItemBehavior, EnderEyeBehavior, HangingSignItemBehavior, SignItemBehavior, StandingAndWallBlockItem, ShovelBehaviour, FilledBucketBehavior, EmptyBucketBehavior};
use crate::behavior::items::{BlockItemBehavior, EnderEyeBehavior, HangingSignItemBehavior, SignItemBehavior, StandingAndWallBlockItem, ShovelBehaviour, FilledBucketBehavior, FlintAndSteelBehavior, EmptyBucketBehavior};

pub fn register_item_behaviors(registry: &mut ItemBehaviorRegistry) {
#block_item_registrations
Expand All @@ -225,6 +231,7 @@ pub fn build(items: &[ItemClass]) -> String {
#standing_and_wall_item_registrations
#ender_eye_registrations
#shovel_registrations
#flint_and_steel_registrations
#filled_bucket_registrations
#empty_bucket_registrations
}
Expand Down
44 changes: 44 additions & 0 deletions steel-core/src/behavior/blocks/fire.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! fire block behavior implementation.

use steel_registry::blocks::BlockRef;
use steel_utils::{BlockPos, BlockStateId};

use crate::behavior::block::BlockBehaviour;
use crate::behavior::context::BlockPlaceContext;
use crate::portal::portal_shape::{PortalShape, nether_portal_config};
use crate::world::World;

/// Behavior for fire blocks.
///
/// Fire burns, makes hot, and hurts
pub struct FireBlock {
block: BlockRef,
}

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

impl BlockBehaviour for FireBlock {
fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
Some(self.block.default_state())
}

fn on_place(
&self,
_state: BlockStateId,
world: &World,
pos: BlockPos,
_old_state: BlockStateId,
_moved_by_piston: bool,
) {
if let Some(tester) = PortalShape::find_portal_shape(world, pos, &nether_portal_config()) {
tester.place_portal_blocks(world);
// TODO: Play ignite sound, damage item
}
}
}
4 changes: 4 additions & 0 deletions steel-core/src/behavior/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ mod crop_block;
mod end_portal_frame_block;
mod farmland_block;
mod fence_block;
mod fire;
mod liquid_block;
mod nether_portal_block;
mod redstone_torch_block;
mod rotated_pillar_block;
mod sign_block;
Expand All @@ -30,7 +32,9 @@ pub use crop_block::CropBlock;
pub use end_portal_frame_block::EndPortalFrameBlock;
pub use farmland_block::FarmlandBlock;
pub use fence_block::FenceBlock;
pub use fire::FireBlock;
pub use liquid_block::LiquidBlock;
pub use nether_portal_block::NetherPortalBlock;
pub use redstone_torch_block::{RedstoneTorchBlock, RedstoneWallTorchBlock};
pub use rotated_pillar_block::RotatedPillarBlock;
pub use sign_block::{
Expand Down
52 changes: 52 additions & 0 deletions steel-core/src/behavior/blocks/nether_portal_block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! Nether portal block behavior.

use crate::behavior::block::BlockBehaviour;
use crate::behavior::context::BlockPlaceContext;
use crate::portal::portal_shape::{PortalShape, nether_portal_config};
use crate::world::World;
use steel_registry::blocks::BlockRef;
use steel_registry::blocks::block_state_ext::BlockStateExt;
use steel_registry::blocks::properties::BlockStateProperties;
use steel_registry::vanilla_blocks::AIR;
use steel_utils::math::Axis;
use steel_utils::{BlockPos, BlockStateId, Direction};

/// Behavior for the nether portal block.
pub struct NetherPortalBlock {
block: BlockRef,
}
impl NetherPortalBlock {
/// Create a new `NetherPortalBlock`
#[must_use]
pub const fn new(block: BlockRef) -> Self {
Self { block }
}
}

impl BlockBehaviour for NetherPortalBlock {
fn update_shape(
&self,
state: BlockStateId,
world: &World,
pos: BlockPos,
direction: Direction,
_neighbor_pos: BlockPos,
neighbor_state: BlockStateId,
) -> BlockStateId {
let update_axis = direction.get_axis();
let axis: Axis = state.get_value(&BlockStateProperties::HORIZONTAL_AXIS);
let wrong_axis = axis != update_axis && update_axis != Axis::Y;

if !wrong_axis
&& neighbor_state.get_block() != self.block
&& PortalShape::find_any_shape(world, pos, axis, &nether_portal_config()).is_none()
{
return AIR.default_state();
}
state
}

fn get_state_for_placement(&self, _context: &BlockPlaceContext<'_>) -> Option<BlockStateId> {
None // TODO: add this functionality but has low priority
}
}
25 changes: 25 additions & 0 deletions steel-core/src/behavior/items/flint_and_steel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Flint and steel item behavior with portal ignition.

use crate::behavior::context::{InteractionResult, UseOnContext};
use crate::behavior::item::ItemBehavior;
use steel_registry::vanilla_blocks::FIRE;
use steel_utils::types::UpdateFlags;

/// Behavior for flint and steel items.
pub struct FlintAndSteelBehavior;

impl ItemBehavior for FlintAndSteelBehavior {
fn use_on(&self, context: &mut UseOnContext) -> InteractionResult {
let click_pos = context.hit_result.block_pos;
let fire_pos = click_pos.relative(context.hit_result.direction);

context.world.set_block(
fire_pos,
FIRE.default_state(),
UpdateFlags::UPDATE_NEIGHBORS,
);

// TODO: Place fire block at fire_pos if it's air on a solid block
InteractionResult::Pass
}
}
3 changes: 3 additions & 0 deletions steel-core/src/behavior/items/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ mod shovel;
mod sign_item;
mod standing_and_wall_block_item;

mod flint_and_steel;

pub use block_item::BlockItemBehavior;
pub use bucket::{EmptyBucketBehavior, FilledBucketBehavior};
pub use default::DefaultItemBehavior;
pub use ender_eye::EnderEyeBehavior;
pub use flint_and_steel::FlintAndSteelBehavior;
pub use shovel::ShovelBehaviour;
pub use sign_item::{HangingSignItemBehavior, SignItemBehavior};
pub use standing_and_wall_block_item::StandingAndWallBlockItem;
1 change: 1 addition & 0 deletions steel-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod level_data;
pub mod physics;
pub mod player;
pub mod poi;
pub mod portal;
pub mod server;
pub mod world;
pub mod worldgen;
2 changes: 2 additions & 0 deletions steel-core/src/portal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//! Dimension portal system for nether/end portals and future portal types.
pub mod portal_shape;
Loading
Loading