Skip to content

Commit

Permalink
Rename BlockFace::to_direction to unwrap_direction and panic on inval…
Browse files Browse the repository at this point in the history
…id direction
  • Loading branch information
StackDoubleFlow committed Dec 18, 2023
1 parent 923f47c commit 3fc3e62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/blocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/core/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand All @@ -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 {} => {
Expand All @@ -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()
};
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/redpiler/passes/input_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/redstone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3fc3e62

Please sign in to comment.