diff --git a/blocks/src/lib.rs b/blocks/src/lib.rs index 64f0551..01ff0f3 100644 --- a/blocks/src/lib.rs +++ b/blocks/src/lib.rs @@ -2244,10 +2244,7 @@ define_blocks! { model { ("minecraft", "iron_bars") }, collision pane_collision(north, south, east, west), update_state (world, pos) => { - let f = |block| match block { - Block::IronBars{..} => true, - _ => false, - }; + let f = |block| matches!(block, Block::IronBars{..}); let (north, south, west, east) = can_connect_sides(world, pos, &f); Block::IronBars{north, south, west, east, waterlogged} @@ -2573,16 +2570,13 @@ define_blocks! { model { ("minecraft", "nether_brick_fence") }, collision fence_collision(north, south, west, east), update_state (world, pos) => { - let f = |block| match block { - Block::NetherBrickFence{..} | + let f = |block| matches!(block, Block::NetherBrickFence{..} | Block::FenceGate{..} | Block::SpruceFenceGate{..} | Block::BirchFenceGate{..} | Block::JungleFenceGate{..} | Block::DarkOakFenceGate{..} | - Block::AcaciaFenceGate{..} => true, - _ => false, - }; + Block::AcaciaFenceGate{..}); let (north, south, west, east) = can_connect_sides(world, pos, &f); Block::NetherBrickFence{north, south, west, east, waterlogged} @@ -3074,22 +3068,17 @@ define_blocks! { material material::NON_SOLID, model { ("minecraft", format!("{}_wall", variant.as_string())) }, update_state (world, pos) => { - let f = |block| match block { - Block::CobblestoneWall{..} | + let f = |block| matches!(block, Block::CobblestoneWall{..} | Block::FenceGate{..} | Block::SpruceFenceGate{..} | Block::BirchFenceGate{..} | Block::JungleFenceGate{..} | Block::DarkOakFenceGate{..} | - Block::AcaciaFenceGate{..} => true, - _ => false, - }; + Block::AcaciaFenceGate{..}); let (north, south, west, east) = can_connect_sides(world, pos, &f); - let up = !(match world.get_block(pos.shift(Direction::Up)) { - Block::Air{..} => true, - _ => false, - }) || !((north && south && !west && !east) || (!north && !south && west && east)); + let up = !(matches!(world.get_block(pos.shift(Direction::Up)), Block::Air{..})) + || !((north && south && !west && !east) || (!north && !south && west && east)); Block::CobblestoneWall{up, north, south, west, east, variant, waterlogged} }, multipart (key, val) => match key { @@ -4685,12 +4674,12 @@ define_blocks! { collision }, update_state (world, pos) => Block::ChorusPlant { - up: match world.get_block(pos.shift(Direction::Up)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} => true, _ => false,}, - down: match world.get_block(pos.shift(Direction::Down)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} | Block::EndStone{..} => true, _ => false,}, - north: match world.get_block(pos.shift(Direction::North)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} => true, _ => false,}, - south: match world.get_block(pos.shift(Direction::South)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} => true, _ => false,}, - west: match world.get_block(pos.shift(Direction::West)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} => true, _ => false,}, - east: match world.get_block(pos.shift(Direction::East)) { Block::ChorusPlant{..} | Block::ChorusFlower{..} => true, _ => false,}, + up: matches!(world.get_block(pos.shift(Direction::Up)), Block::ChorusPlant{..} | Block::ChorusFlower{..}), + down: matches!(world.get_block(pos.shift(Direction::Down)), Block::ChorusPlant{..} | Block::ChorusFlower{..} | Block::EndStone{..}), + north: matches!(world.get_block(pos.shift(Direction::North)), Block::ChorusPlant{..} | Block::ChorusFlower{..}), + south: matches!(world.get_block(pos.shift(Direction::South)), Block::ChorusPlant{..} | Block::ChorusFlower{..}), + west: matches!(world.get_block(pos.shift(Direction::West)), Block::ChorusPlant{..} | Block::ChorusFlower{..}), + east: matches!(world.get_block(pos.shift(Direction::East)), Block::ChorusPlant{..} | Block::ChorusFlower{..}), }, multipart (key, val) => match key { "up" => up == (val == "true"), @@ -5625,8 +5614,7 @@ define_blocks! { } fn can_burn(world: &W, pos: Position) -> bool { - match world.get_block(pos) { - Block::Planks { .. } + matches!(world.get_block(pos), Block::Planks { .. } | Block::DoubleWoodenSlab { .. } | Block::WoodenSlab { .. } | Block::FenceGate { .. } @@ -5662,16 +5650,11 @@ fn can_burn(world: &W, pos: Position) -> bool { | Block::Vine { .. } | Block::CoalBlock { .. } | Block::HayBlock { .. } - | Block::Carpet { .. } => true, - _ => false, - } + | Block::Carpet { .. }) } fn is_snowy(world: &W, pos: Position) -> bool { - match world.get_block(pos.shift(Direction::Up)) { - Block::Snow { .. } | Block::SnowLayer { .. } => true, - _ => false, - } + matches!(world.get_block(pos.shift(Direction::Up)), Block::Snow { .. } | Block::SnowLayer { .. }) } fn can_connect_sides bool, W: WorldAccess>( @@ -5693,8 +5676,7 @@ fn can_connect bool, W: WorldAccess>(world: &W, pos: Position, f } fn can_connect_fence(block: Block) -> bool { - match block { - Block::Fence { .. } + matches!(block, Block::Fence { .. } | Block::SpruceFence { .. } | Block::BirchFence { .. } | Block::JungleFence { .. } @@ -5705,19 +5687,14 @@ fn can_connect_fence(block: Block) -> bool { | Block::BirchFenceGate { .. } | Block::JungleFenceGate { .. } | Block::DarkOakFenceGate { .. } - | Block::AcaciaFenceGate { .. } => true, - _ => false, - } + | Block::AcaciaFenceGate { .. }) } fn can_connect_glasspane(block: Block) -> bool { - match block { - Block::Glass { .. } + matches!(block, Block::Glass { .. } | Block::StainedGlass { .. } | Block::GlassPane { .. } - | Block::StainedGlassPane { .. } => true, - _ => false, - } + | Block::StainedGlassPane { .. }) } fn can_connect_redstone(world: &W, pos: Position, dir: Direction) -> RedstoneSide { @@ -5728,11 +5705,7 @@ fn can_connect_redstone(world: &W, pos: Position, dir: Direction let side_up = world.get_block(shift_pos.shift(Direction::Up)); let up = world.get_block(pos.shift(Direction::Up)); - if match side_up { - Block::RedstoneWire { .. } => true, - _ => false, - } && !up.get_material().should_cull_against - { + if matches!(side_up, Block::RedstoneWire { .. }) && !up.get_material().should_cull_against { return RedstoneSide::Up; } @@ -5740,13 +5713,9 @@ fn can_connect_redstone(world: &W, pos: Position, dir: Direction } let side_down = world.get_block(shift_pos.shift(Direction::Down)); - if match block { - Block::RedstoneWire { .. } => true, - _ => false, - } || match side_down { - Block::RedstoneWire { .. } => true, - _ => false, - } { + if matches!(block, Block::RedstoneWire { .. }) + || matches!(side_down, Block::RedstoneWire { .. }) + { return RedstoneSide::Side; } RedstoneSide::None @@ -5960,10 +5929,7 @@ fn door_collision(facing: Direction, hinge: Side, open: bool) -> Vec> } fn update_repeater_state(world: &W, pos: Position, facing: Direction) -> bool { - let f = |dir| match world.get_block(pos.shift(dir)) { - Block::RepeaterPowered { .. } => true, - _ => false, - }; + let f = |dir| matches!(world.get_block(pos.shift(dir)), Block::RepeaterPowered { .. }); f(facing.clockwise()) || f(facing.counter_clockwise()) } diff --git a/protocol/src/nbt/mod.rs b/protocol/src/nbt/mod.rs index 72fce8b..7ddd5d5 100644 --- a/protocol/src/nbt/mod.rs +++ b/protocol/src/nbt/mod.rs @@ -72,10 +72,7 @@ impl Tag { } pub fn is_compound(&self) -> bool { - match *self { - Tag::Compound(_) => true, - _ => false, - } + matches!(*self, Tag::Compound(_)) } pub fn as_byte(&self) -> Option { diff --git a/protocol/src/types/mod.rs b/protocol/src/types/mod.rs index b2ceaac..4eb41fd 100644 --- a/protocol/src/types/mod.rs +++ b/protocol/src/types/mod.rs @@ -39,23 +39,14 @@ impl Gamemode { } pub fn can_fly(&self) -> bool { - match *self { - Gamemode::Creative | Gamemode::Spectator => true, - _ => false, - } + matches!(*self, Gamemode::Creative | Gamemode::Spectator) } pub fn always_fly(&self) -> bool { - match *self { - Gamemode::Spectator => true, - _ => false, - } + matches!(*self, Gamemode::Spectator) } pub fn noclip(&self) -> bool { - match *self { - Gamemode::Spectator => true, - _ => false, - } + matches!(*self, Gamemode::Spectator) } } diff --git a/src/model/mod.rs b/src/model/mod.rs index 7a6c365..f08fe3d 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1110,11 +1110,7 @@ fn calculate_light( let lz = (z + oz + dz).round() as i32; let mut bl = snapshot.get_block_light(lx, ly, lz); let mut sl = snapshot.get_sky_light(lx, ly, lz); - if (force - && match snapshot.get_block(lx, ly, lz) { - block::Air {} => false, - _ => true, - }) + if (force && !matches!(snapshot.get_block(lx, ly, lz), block::Air {})) || (sl == 0 && bl == 0) { bl = s_block_light;