Skip to content
Draft
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
53 changes: 53 additions & 0 deletions steel-core/src/behavior/items/empty_map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::behavior::items::map::MapItem;
use crate::behavior::{InteractionResult, ItemBehavior, UseItemContext};
use crate::entity::Entity;
use crate::inventory::container::Container;
use crate::world::World;
use std::sync::Arc;
use steel_macros::item_behavior;
use steel_registry::sound_events;
use steel_registry::stat::vanilla_stat_types;

/// The empty map item
#[item_behavior]
pub struct EmptyMapItem;

impl ItemBehavior for EmptyMapItem {
fn use_item(&self, context: &mut UseItemContext) -> InteractionResult {
let world = context.world;
let player = context.player;

let (item_ref, hand_empty) = context.inv.with_item(|item| {
item.shrink(1);
(item.item(), item.is_empty())
});

player.award_stat(&vanilla_stat_types::ITEM_USED, item_ref);

world.play_sound_at(
&sound_events::UI_CARTOGRAPHY_TABLE_TAKE_RESULT,
player.sound_source(),
player.position(),
1.0,
1.0,
None,
);

let map = MapItem::create(
world,
player.block_position().x(),
player.block_position().z(),
0,
true,
false,
);

if hand_empty {
// TODO
}

player.add_item_or_drop(map);

InteractionResult::Success
}
}
50 changes: 50 additions & 0 deletions steel-core/src/behavior/items/map.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::behavior::ItemBehavior;
use crate::world::World;
use std::sync::Arc;
use steel_macros::item_behavior;
use steel_registry::data_components::vanilla_components::MAP_ID;
use steel_registry::data_components::{DataComponentType, MapId, vanilla_components};
use steel_registry::dimension_type::DimensionTypeRef;
use steel_registry::item_stack::ItemStack;
use steel_registry::vanilla_items;

/// The non-empty map item
#[item_behavior]
pub struct MapItem;

impl MapItem {
pub(crate) fn create(
level: &Arc<World>,
origin_x: i32,
origin_z: i32,
scale: i8,
track_position: bool,
unlimited_tracking: bool,
) -> ItemStack {
let mut map = ItemStack::new(&vanilla_items::FILLED_MAP);
let new_id = MapItem::create_new_saved_data(
level,
origin_x,
origin_z,
scale,
track_position,
unlimited_tracking,
level.dimension_type,
);
map.set(MAP_ID, new_id);
map
}

fn create_new_saved_data(
level: &Arc<World>,
origin_x: i32,
origin_z: i32,
scale: i8,
track_position: bool,
unlimited_tracking: bool,
dimension: DimensionTypeRef,
) -> MapId {
}
}

impl ItemBehavior for MapItem {}
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 @@ -37,8 +37,10 @@ mod standing_and_wall_block_item;
mod throwable_potion;
mod tipped_arrow;

mod empty_map;
mod flint_and_steel;
mod lead;
mod map;

pub use air::AirItem;
pub use axe::AxeItem;
Expand All @@ -51,6 +53,7 @@ pub use compass::CompassItem;
pub use default::DefaultItemBehavior;
pub use dye::DyeItem;
pub use egg::EggItem;
pub use empty_map::EmptyMapItem;
pub use ender_eye::EnderEyeItem;
pub use ender_pearl::EnderPearlItem;
pub use firework_rocket::FireworkRocketItem;
Expand Down
Loading