From 3fc3e6249545a1cc55a51aec0a36e7c9b90e6660 Mon Sep 17 00:00:00 2001 From: StackDoubleFlow Date: Mon, 18 Dec 2023 15:53:04 -0600 Subject: [PATCH] Rename BlockFace::to_direction to unwrap_direction and panic on invalid direction --- crates/blocks/src/lib.rs | 4 ++-- crates/core/src/interaction.rs | 12 ++++++------ crates/core/src/redpiler/passes/input_search.rs | 8 ++++---- crates/core/src/redstone/mod.rs | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/blocks/src/lib.rs b/crates/blocks/src/lib.rs index 66a881e9..e4a9c811 100644 --- a/crates/blocks/src/lib.rs +++ b/crates/blocks/src/lib.rs @@ -150,13 +150,13 @@ impl BlockFace { matches!(self, North | South | East | West) } - pub fn to_direction(self) -> BlockDirection { + pub fn unwrap_direction(self) -> BlockDirection { match self { BlockFace::North => BlockDirection::North, BlockFace::South => BlockDirection::South, BlockFace::East => BlockDirection::East, BlockFace::West => BlockDirection::West, - _ => BlockDirection::West, + _ => panic!("called `unwrap_direction` on {:?}", self), } } } diff --git a/crates/core/src/interaction.rs b/crates/core/src/interaction.rs index 7dff740a..b9f65825 100644 --- a/crates/core/src/interaction.rs +++ b/crates/core/src/interaction.rs @@ -121,7 +121,7 @@ pub fn get_state_for_placement( _ => LeverFace::Wall, }; let facing = if lever_face == LeverFace::Wall { - context.block_face.to_direction() + context.block_face.unwrap_direction() } else { context.player.get_direction() }; @@ -133,13 +133,13 @@ pub fn get_state_for_placement( BlockFace::Top | BlockFace::Bottom => Block::RedstoneTorch { lit: true }, face => Block::RedstoneWallTorch { lit: true, - facing: face.to_direction(), + facing: face.unwrap_direction(), }, }, Item::TripwireHook {} => match context.block_face { BlockFace::Bottom | BlockFace::Top => Block::Air {}, direction => Block::TripwireHook { - direction: direction.to_direction(), + direction: direction.unwrap_direction(), }, }, Item::StoneButton {} => { @@ -149,7 +149,7 @@ pub fn get_state_for_placement( _ => ButtonFace::Wall, }; let facing = if button_face == ButtonFace::Wall { - context.block_face.to_direction() + context.block_face.unwrap_direction() } else { context.player.get_direction() }; @@ -187,7 +187,7 @@ pub fn get_state_for_placement( }, _ => Block::WallSign { sign_type: SignType(sign_type), - facing: context.block_face.to_direction(), + facing: context.block_face.unwrap_direction(), }, }, Item::Redstone {} => Block::RedstoneWire { @@ -210,7 +210,7 @@ pub fn get_state_for_placement( powered: false, }, _ => Block::IronTrapdoor { - facing: context.block_face.to_direction(), + facing: context.block_face.unwrap_direction(), half: if context.cursor_y > 0.5 { TrapdoorHalf::Top } else { diff --git a/crates/core/src/redpiler/passes/input_search.rs b/crates/core/src/redpiler/passes/input_search.rs index faea0a88..ef9c6923 100644 --- a/crates/core/src/redpiler/passes/input_search.rs +++ b/crates/core/src/redpiler/passes/input_search.rs @@ -78,12 +78,12 @@ impl<'a, W: World> InputSearchState<'a, W> { Block::Lever { lever } => match side { BlockFace::Top => lever.face == LeverFace::Floor, BlockFace::Bottom => lever.face == LeverFace::Ceiling, - _ => lever.face == LeverFace::Wall && lever.facing == side.to_direction(), + _ => lever.face == LeverFace::Wall && lever.facing == side.unwrap_direction(), }, Block::StoneButton { button } => match side { BlockFace::Top => button.face == ButtonFace::Floor, BlockFace::Bottom => button.face == ButtonFace::Ceiling, - _ => button.face == ButtonFace::Wall && button.facing == side.to_direction(), + _ => button.face == ButtonFace::Wall && button.facing == side.unwrap_direction(), }, Block::RedstoneRepeater { .. } => self.provides_weak_power(block, side), Block::RedstoneComparator { .. } => self.provides_weak_power(block, side), @@ -125,7 +125,7 @@ impl<'a, W: World> InputSearchState<'a, W> { } BlockFace::Bottom => {} _ => { - let direction = side.to_direction(); + let direction = side.unwrap_direction(); if search_wire && !wire::get_current_side( wire::get_regulated_sides(wire, self.world, pos), @@ -150,7 +150,7 @@ impl<'a, W: World> InputSearchState<'a, W> { BlockFace::Top => self.search_wire(start_node, pos, link_ty, distance), BlockFace::Bottom => {} _ => { - let direction = side.to_direction(); + let direction = side.unwrap_direction(); if search_wire && !wire::get_current_side( wire::get_regulated_sides(wire, self.world, pos), diff --git a/crates/core/src/redstone/mod.rs b/crates/core/src/redstone/mod.rs index 46dc969c..7d173b92 100644 --- a/crates/core/src/redstone/mod.rs +++ b/crates/core/src/redstone/mod.rs @@ -49,7 +49,7 @@ fn get_weak_power( BlockFace::Top => wire.power, BlockFace::Bottom => 0, _ => { - let direction = side.to_direction(); + let direction = side.unwrap_direction(); if wire::get_current_side( wire::get_regulated_sides(wire, world, pos), direction.opposite(), @@ -80,14 +80,14 @@ fn get_strong_power( match side { BlockFace::Top => lever.face == LeverFace::Floor, BlockFace::Bottom => lever.face == LeverFace::Ceiling, - _ => lever.face == LeverFace::Wall && lever.facing == side.to_direction(), + _ => lever.face == LeverFace::Wall && lever.facing == side.unwrap_direction(), } && lever.powered, ), Block::StoneButton { button } => bool_to_ss( match side { BlockFace::Top => button.face == ButtonFace::Floor, BlockFace::Bottom => button.face == ButtonFace::Ceiling, - _ => button.face == ButtonFace::Wall && button.facing == side.to_direction(), + _ => button.face == ButtonFace::Wall && button.facing == side.unwrap_direction(), } && button.powered, ), Block::StonePressurePlate { powered: true } if side == BlockFace::Top => 15,