Skip to content

Commit

Permalink
implement iron trapdoor placement (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
BramOtte authored Oct 23, 2022
1 parent 47f6b24 commit 1f4e5c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions crates/blocks/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ items! {
from_id(_id): 221 => {},
block: true,
},
IronTrapdoor {
props: {},
get_id: 640,
from_id(_id): 640 => {},
block: true,
},
Unknown {
props: {
id: u32
Expand Down
11 changes: 9 additions & 2 deletions crates/core/src/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ impl Block {
Item::StainedGlass { color } => Block::StainedGlass { color },
Item::SmoothStoneSlab {} => Block::SmoothStoneSlab {},
Item::QuartzSlab {} => Block::QuartzSlab {},
Item::IronTrapdoor {} => {
match context.block_face {
BlockFace::Bottom => Block::IronTrapdoor { facing: context.player.get_direction().opposite(), half: TrapdoorHalf::Top, powered: false },
BlockFace::Top => Block::IronTrapdoor { facing: context.player.get_direction().opposite(), half: TrapdoorHalf::Bottom, powered: false },
_ => Block::IronTrapdoor { facing: context.block_face.to_direction(), half: if context.cursor_y > 0.5 {TrapdoorHalf::Top} else {TrapdoorHalf::Bottom} , powered: false }
}
},
_ => Block::Air {},
};
if block.is_valid_position(world, pos) {
Expand Down Expand Up @@ -1671,7 +1678,7 @@ blocks! {
},
IronTrapdoor {
props: {
facing: BlockFacing,
facing: BlockDirection,
half: TrapdoorHalf,
powered: bool
},
Expand All @@ -1683,7 +1690,7 @@ blocks! {
},
from_id_offset: 7788,
from_id(id): 7788..=7850 => {
facing: BlockFacing::from_id(id >> 4),
facing: BlockDirection::from_id(id >> 4),
half: TrapdoorHalf::from_id((id >> 3) & 1),
powered: ((id >> 1) & 1) == 0
},
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct UseOnBlockContext<'a> {
pub block_pos: BlockPos,
pub block_face: BlockFace,
pub player: &'a mut Player,
pub cursor_y: f32,
}

/// returns true if cancelled
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/plot/packet_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl ServerBoundPacketHandler for Plot {
block_face,
block_pos,
player: &mut self.players[player],
cursor_y: player_block_placement.cursor_y,
},
);
if cancelled {
Expand Down

0 comments on commit 1f4e5c0

Please sign in to comment.