Browse Source

Reformat all source with cargo fmt (#335)

pull/339/head
iceiix 1 year ago
committed by GitHub
parent
commit
518b6a07f8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 600
      blocks/src/lib.rs
  3. 1
      blocks/src/material.rs
  4. 8
      gl/build.rs
  5. 23
      protocol/src/format.rs
  6. 5
      protocol/src/item.rs
  7. 5
      protocol/src/lib.rs
  8. 2
      protocol/src/macros.rs
  9. 6
      protocol/src/nbt/mod.rs
  10. 47
      protocol/src/protocol/forge.rs
  11. 233
      protocol/src/protocol/mod.rs
  12. 95
      protocol/src/protocol/mojang.rs
  13. 158
      protocol/src/protocol/packet.rs
  14. 36
      protocol/src/protocol/versions.rs
  15. 2
      protocol/src/protocol/versions/v15w39c.rs
  16. 2
      protocol/src/protocol/versions/v18w50a.rs
  17. 2
      protocol/src/protocol/versions/v19w02a.rs
  18. 2
      protocol/src/protocol/versions/v1_10_2.rs
  19. 2
      protocol/src/protocol/versions/v1_11_2.rs
  20. 2
      protocol/src/protocol/versions/v1_12_2.rs
  21. 2
      protocol/src/protocol/versions/v1_13_2.rs
  22. 2
      protocol/src/protocol/versions/v1_14.rs
  23. 2
      protocol/src/protocol/versions/v1_14_1.rs
  24. 2
      protocol/src/protocol/versions/v1_14_2.rs
  25. 2
      protocol/src/protocol/versions/v1_14_3.rs
  26. 2
      protocol/src/protocol/versions/v1_14_4.rs
  27. 2
      protocol/src/protocol/versions/v1_15_1.rs
  28. 2
      protocol/src/protocol/versions/v1_7_10.rs
  29. 2
      protocol/src/protocol/versions/v1_8_9.rs
  30. 2
      protocol/src/protocol/versions/v1_9.rs
  31. 2
      protocol/src/protocol/versions/v1_9_2.rs
  32. 2
      protocol/src/types/bit/map.rs
  33. 4
      protocol/src/types/bit/mod.rs
  34. 4
      protocol/src/types/bit/set.rs
  35. 2
      protocol/src/types/hash.rs
  36. 97
      protocol/src/types/metadata.rs
  37. 2
      protocol/src/types/mod.rs
  38. 7
      protocol/src/types/nibble.rs
  39. 16
      resources/build.rs
  40. 1
      resources/src/lib.rs
  41. 3
      shared/src/axis.rs
  42. 11
      shared/src/direction.rs
  43. 1
      shared/src/lib.rs
  44. 9
      shared/src/position.rs
  45. 189
      src/chunk_builder.rs
  46. 93
      src/console/mod.rs
  47. 246
      src/ecs/mod.rs
  48. 9
      src/entity/block_entity/mod.rs
  49. 149
      src/entity/block_entity/sign.rs
  50. 29
      src/entity/mod.rs
  51. 421
      src/entity/player.rs
  52. 73
      src/entity/systems.rs
  53. 442
      src/gl/mod.rs
  54. 381
      src/main.rs
  55. 73
      src/model/liquid.rs
  56. 556
      src/model/mod.rs
  57. 20
      src/render/atlas.rs
  58. 53
      src/render/clouds.rs
  59. 7
      src/render/glsl.rs
  60. 586
      src/render/mod.rs
  61. 181
      src/render/model.rs
  62. 15
      src/render/shaders.rs
  63. 269
      src/render/ui.rs
  64. 149
      src/resources.rs
  65. 13
      src/screen/connecting.rs
  66. 25
      src/screen/edit_server.rs
  67. 38
      src/screen/login.rs
  68. 35
      src/screen/mod.rs
  69. 113
      src/screen/server_list.rs
  70. 87
      src/screen/settings_menu.rs
  71. 1230
      src/server/mod.rs
  72. 2
      src/server/plugin_messages.rs
  73. 123
      src/server/sun.rs
  74. 109
      src/server/target.rs
  75. 64
      src/settings.rs
  76. 30
      src/ui/logo.rs
  77. 403
      src/ui/mod.rs
  78. 21
      src/world/biome.rs
  79. 568
      src/world/mod.rs
  80. 10
      src/world/storage.rs

2
README.md

@ -97,7 +97,7 @@ There are a few basic ground-rules for contributors:
1. **Non-master branches** ought to be used for ongoing work.
1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors.
1. Internal pull-requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor.
1. Contributors should attempt to adhere to the prevailing code-style.
1. Contributors should attempt to adhere to the prevailing code-style. Please install and run [cargo fmt](https://github.com/rust-lang/rustfmt) before merging any changes.
### Changes to this arrangement

600
blocks/src/lib.rs

@ -1,11 +1,10 @@
#![recursion_limit="600"]
#![recursion_limit = "600"]
extern crate steven_shared as shared;
use crate::shared::{Axis, Direction, Position};
use collision::Aabb3;
use cgmath::Point3;
use collision::Aabb3;
use lazy_static::lazy_static;
use std::collections::HashMap;
@ -500,7 +499,7 @@ macro_rules! define_blocks {
#[derive(Clone, Copy)]
pub enum TintType {
Default,
Color{r: u8, g: u8, b: u8},
Color { r: u8, g: u8, b: u8 },
Grass,
Foliage,
}
@ -5625,59 +5624,65 @@ define_blocks! {
fn can_burn<W: WorldAccess>(world: &W, pos: Position) -> bool {
match world.get_block(pos) {
Block::Planks{..} |
Block::DoubleWoodenSlab{..} |
Block::WoodenSlab{..} |
Block::FenceGate{..} |
Block::SpruceFenceGate{..} |
Block::BirchFenceGate{..} |
Block::JungleFenceGate{..} |
Block::DarkOakFenceGate{..} |
Block::AcaciaFenceGate{..} |
Block::Fence{..} |
Block::SpruceFence{..} |
Block::BirchFence{..} |
Block::JungleFence{..} |
Block::DarkOakFence{..} |
Block::AcaciaFence{..} |
Block::OakStairs{..} |
Block::BirchStairs{..} |
Block::SpruceStairs{..} |
Block::JungleStairs{..} |
Block::AcaciaStairs{..} |
Block::DarkOakStairs{..} |
Block::Log{..} |
Block::Log2{..} |
Block::Leaves{..} |
Block::Leaves2{..} |
Block::BookShelf{..} |
Block::TNT{..} |
Block::TallGrass{..} |
Block::DoublePlant{..} |
Block::YellowFlower{..} |
Block::RedFlower{..} |
Block::DeadBush{..} |
Block::Wool{..} |
Block::Vine{..} |
Block::CoalBlock{..} |
Block::HayBlock{..} |
Block::Carpet{..} => true,
Block::Planks { .. }
| Block::DoubleWoodenSlab { .. }
| Block::WoodenSlab { .. }
| Block::FenceGate { .. }
| Block::SpruceFenceGate { .. }
| Block::BirchFenceGate { .. }
| Block::JungleFenceGate { .. }
| Block::DarkOakFenceGate { .. }
| Block::AcaciaFenceGate { .. }
| Block::Fence { .. }
| Block::SpruceFence { .. }
| Block::BirchFence { .. }
| Block::JungleFence { .. }
| Block::DarkOakFence { .. }
| Block::AcaciaFence { .. }
| Block::OakStairs { .. }
| Block::BirchStairs { .. }
| Block::SpruceStairs { .. }
| Block::JungleStairs { .. }
| Block::AcaciaStairs { .. }
| Block::DarkOakStairs { .. }
| Block::Log { .. }
| Block::Log2 { .. }
| Block::Leaves { .. }
| Block::Leaves2 { .. }
| Block::BookShelf { .. }
| Block::TNT { .. }
| Block::TallGrass { .. }
| Block::DoublePlant { .. }
| Block::YellowFlower { .. }
| Block::RedFlower { .. }
| Block::DeadBush { .. }
| Block::Wool { .. }
| Block::Vine { .. }
| Block::CoalBlock { .. }
| Block::HayBlock { .. }
| Block::Carpet { .. } => true,
_ => false,
}
}
fn is_snowy<W: WorldAccess>(world: &W, pos: Position) -> bool {
match world.get_block(pos.shift(Direction::Up)) {
Block::Snow{..} | Block::SnowLayer{..} => true,
Block::Snow { .. } | Block::SnowLayer { .. } => true,
_ => false,
}
}
fn can_connect_sides<F: Fn(Block) -> bool, W: WorldAccess>(world: &W, pos: Position, f: &F) -> (bool, bool, bool, bool) {
(can_connect(world, pos.shift(Direction::North), f),
can_connect(world, pos.shift(Direction::South), f),
can_connect(world, pos.shift(Direction::West), f),
can_connect(world, pos.shift(Direction::East), f))
fn can_connect_sides<F: Fn(Block) -> bool, W: WorldAccess>(
world: &W,
pos: Position,
f: &F,
) -> (bool, bool, bool, bool) {
(
can_connect(world, pos.shift(Direction::North), f),
can_connect(world, pos.shift(Direction::South), f),
can_connect(world, pos.shift(Direction::West), f),
can_connect(world, pos.shift(Direction::East), f),
)
}
fn can_connect<F: Fn(Block) -> bool, W: WorldAccess>(world: &W, pos: Position, f: &F) -> bool {
@ -5687,28 +5692,28 @@ fn can_connect<F: Fn(Block) -> bool, W: WorldAccess>(world: &W, pos: Position, f
fn can_connect_fence(block: Block) -> bool {
match block {
Block::Fence{..} |
Block::SpruceFence{..} |
Block::BirchFence{..} |
Block::JungleFence{..} |
Block::DarkOakFence{..} |
Block::AcaciaFence{..} |
Block::FenceGate{..} |
Block::SpruceFenceGate{..} |
Block::BirchFenceGate{..} |
Block::JungleFenceGate{..} |
Block::DarkOakFenceGate{..} |
Block::AcaciaFenceGate{..} => true,
Block::Fence { .. }
| Block::SpruceFence { .. }
| Block::BirchFence { .. }
| Block::JungleFence { .. }
| Block::DarkOakFence { .. }
| Block::AcaciaFence { .. }
| Block::FenceGate { .. }
| Block::SpruceFenceGate { .. }
| Block::BirchFenceGate { .. }
| Block::JungleFenceGate { .. }
| Block::DarkOakFenceGate { .. }
| Block::AcaciaFenceGate { .. } => true,
_ => false,
}
}
fn can_connect_glasspane(block: Block) -> bool {
match block {
Block::Glass{..} |
Block::StainedGlass{..} |
Block::GlassPane{..} |
Block::StainedGlassPane{..} => true,
Block::Glass { .. }
| Block::StainedGlass { .. }
| Block::GlassPane { .. }
| Block::StainedGlassPane { .. } => true,
_ => false,
}
}
@ -5721,7 +5726,11 @@ fn can_connect_redstone<W: WorldAccess>(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 match side_up {
Block::RedstoneWire { .. } => true,
_ => false,
} && !up.get_material().should_cull_against
{
return RedstoneSide::Up;
}
@ -5729,71 +5738,90 @@ fn can_connect_redstone<W: WorldAccess>(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 match block {
Block::RedstoneWire { .. } => true,
_ => false,
} || match side_down {
Block::RedstoneWire { .. } => true,
_ => false,
} {
return RedstoneSide::Side;
}
RedstoneSide::None
}
fn fence_gate_data(facing: Direction, in_wall: bool, open: bool, powered: bool) -> Option<usize> {
if in_wall || powered { return None; }
if in_wall || powered {
return None;
}
Some(facing.horizontal_index() | (if open { 0x4 } else { 0x0 }))
}
fn fence_gate_offset(facing: Direction, in_wall: bool, open: bool, powered: bool) -> Option<usize> {
Some(if powered { 0 } else { 1<<0 } +
if open { 0 } else { 1<<1 } +
if in_wall { 0 } else { 1<<2 } +
facing.horizontal_offset() * (1<<3))
Some(
if powered { 0 } else { 1 << 0 }
+ if open { 0 } else { 1 << 1 }
+ if in_wall { 0 } else { 1 << 2 }
+ facing.horizontal_offset() * (1 << 3),
)
}
fn fence_gate_collision(facing: Direction, in_wall: bool, open: bool) -> Vec<Aabb3<f64>> {
if open { return vec![]; }
if open {
return vec![];
}
let (min_x, min_y, min_z, max_x, max_y, max_z) = if in_wall {
match facing.axis() {
Axis::Z => (0.0, 0.0, 3.0/8.0, 1.0, 13.0/16.0, 5.0/8.0),
Axis::X => (3.0/8.0, 0.0, 0.0, 5.0/8.0, 13.0/16.0, 1.0),
Axis::Z => (0.0, 0.0, 3.0 / 8.0, 1.0, 13.0 / 16.0, 5.0 / 8.0),
Axis::X => (3.0 / 8.0, 0.0, 0.0, 5.0 / 8.0, 13.0 / 16.0, 1.0),
_ => unreachable!(),
}
} else {
match facing.axis() {
Axis::Z => (0.0, 0.0, 3.0/8.0, 1.0, 1.0, 5.0/8.0),
Axis::X => (3.0/8.0, 0.0, 0.0, 5.0/8.0, 1.0, 1.0),
Axis::Z => (0.0, 0.0, 3.0 / 8.0, 1.0, 1.0, 5.0 / 8.0),
Axis::X => (3.0 / 8.0, 0.0, 0.0, 5.0 / 8.0, 1.0, 1.0),
_ => unreachable!(),
}
};
vec![Aabb3::new(
Point3::new(min_x, min_y, min_z),
Point3::new(max_x, max_y, max_z)
Point3::new(max_x, max_y, max_z),
)]
}
fn fence_gate_update_state<W: WorldAccess>(world: &W, pos: Position, facing: Direction) -> bool {
if let Block::CobblestoneWall{..} = world.get_block(pos.shift(facing.clockwise())) {
if let Block::CobblestoneWall { .. } = world.get_block(pos.shift(facing.clockwise())) {
return true;
}
if let Block::CobblestoneWall{..} = world.get_block(pos.shift(facing.counter_clockwise())) {
if let Block::CobblestoneWall { .. } = world.get_block(pos.shift(facing.counter_clockwise())) {
return true;
}
false
}
fn door_data(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered: bool) -> Option<usize> {
fn door_data(
facing: Direction,
half: DoorHalf,
hinge: Side,
open: bool,
powered: bool,
) -> Option<usize> {
match half {
DoorHalf::Upper => {
if facing == Direction::North && open {
Some(0x8
| (if hinge == Side::Right { 0x1 } else { 0x0 })
| (if powered { 0x2 } else { 0x0 }))
Some(
0x8 | (if hinge == Side::Right { 0x1 } else { 0x0 })
| (if powered { 0x2 } else { 0x0 }),
)
} else {
None
}
},
}
DoorHalf::Lower => {
if hinge == Side::Left && !powered {
Some(facing.clockwise().horizontal_index() | (if open { 0x4 } else { 0x0 }))
@ -5804,26 +5832,83 @@ fn door_data(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered
}
}
fn door_offset(facing: Direction, half: DoorHalf, hinge: Side, open: bool, powered: bool) -> Option<usize> {
Some(if powered { 0 } else { 1<<0 } +
if open { 0 } else { 1<<1 } +
if hinge == Side::Left { 0 } else { 1<<2 } +
if half == DoorHalf::Upper { 0 } else { 1<<3 } +
facing.horizontal_offset() * (1<<4))
fn door_offset(
facing: Direction,
half: DoorHalf,
hinge: Side,
open: bool,
powered: bool,
) -> Option<usize> {
Some(
if powered { 0 } else { 1 << 0 }
+ if open { 0 } else { 1 << 1 }
+ if hinge == Side::Left { 0 } else { 1 << 2 }
+ if half == DoorHalf::Upper { 0 } else { 1 << 3 }
+ facing.horizontal_offset() * (1 << 4),
)
}
fn update_door_state<W: WorldAccess>(world: &W, pos: Position, ohalf: DoorHalf, ofacing: Direction, ohinge: Side, oopen: bool, opowered: bool) -> (Direction, Side, bool, bool) {
fn update_door_state<W: WorldAccess>(
world: &W,
pos: Position,
ohalf: DoorHalf,
ofacing: Direction,
ohinge: Side,
oopen: bool,
opowered: bool,
) -> (Direction, Side, bool, bool) {
let oy = if ohalf == DoorHalf::Upper { -1 } else { 1 };
match world.get_block(pos + (0, oy, 0)) {
Block::WoodenDoor{half, facing, hinge, open, powered} |
Block::SpruceDoor{half, facing, hinge, open, powered} |
Block::BirchDoor{half, facing, hinge, open, powered} |
Block::JungleDoor{half, facing, hinge, open, powered} |
Block::AcaciaDoor{half, facing, hinge, open, powered} |
Block::DarkOakDoor{half, facing, hinge, open, powered} |
Block::IronDoor{half, facing, hinge, open, powered} => {
Block::WoodenDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::SpruceDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::BirchDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::JungleDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::AcaciaDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::DarkOakDoor {
half,
facing,
hinge,
open,
powered,
}
| Block::IronDoor {
half,
facing,
hinge,
open,
powered,
} => {
if half != ohalf {
if ohalf == DoorHalf::Upper {
return (facing, ohinge, open, opowered);
@ -5831,8 +5916,8 @@ fn update_door_state<W: WorldAccess>(world: &W, pos: Position, ohalf: DoorHalf,
return (ofacing, hinge, oopen, powered);
}
}
},
_ => {},
}
_ => {}
}
(ofacing, ohinge, oopen, opowered)
@ -5842,7 +5927,7 @@ fn door_collision(facing: Direction, hinge: Side, open: bool) -> Vec<Aabb3<f64>>
use std::f64::consts::PI;
let mut bounds = Aabb3::new(
Point3::new(0.0, 0.0, 0.0),
Point3::new(1.0, 1.0, 3.0 / 16.0)
Point3::new(1.0, 1.0, 3.0 / 16.0),
);
let mut angle = match facing {
Direction::South => 0.0,
@ -5851,43 +5936,48 @@ fn door_collision(facing: Direction, hinge: Side, open: bool) -> Vec<Aabb3<f64>>
Direction::East => PI * 1.5,
_ => 0.0,
};
angle += if open {
PI * 0.5
} else {
0.0
} * match hinge { Side::Left => 1.0, Side::Right => -1.0 };
angle += if open { PI * 0.5 } else { 0.0 }
* match hinge {
Side::Left => 1.0,
Side::Right => -1.0,
};
let c = angle.cos();
let s = angle.sin();
let x = bounds.min.x - 0.5;
let z = bounds.min.z - 0.5;
bounds.min.x = 0.5 + (x*c - z*s);
bounds.min.z = 0.5 + (z*c + x*s);
bounds.min.x = 0.5 + (x * c - z * s);
bounds.min.z = 0.5 + (z * c + x * s);
let x = bounds.max.x - 0.5;
let z = bounds.max.z - 0.5;
bounds.max.x = 0.5 + (x*c - z*s);
bounds.max.z = 0.5 + (z*c + x*s);
bounds.max.x = 0.5 + (x * c - z * s);
bounds.max.z = 0.5 + (z * c + x * s);
vec![bounds]
}
fn update_repeater_state<W: WorldAccess>(world: &W, pos: Position, facing: Direction) -> bool {
let f = |dir| {
match world.get_block(pos.shift(dir)) {
Block::RepeaterPowered{..} => true,
_ => false,
}
let f = |dir| match world.get_block(pos.shift(dir)) {
Block::RepeaterPowered { .. } => true,
_ => false,
};
f(facing.clockwise()) || f(facing.counter_clockwise())
}
fn update_double_plant_state<W: WorldAccess>(world: &W, pos: Position, ohalf: BlockHalf, ovariant: DoublePlantVariant) -> (BlockHalf, DoublePlantVariant) {
if ohalf != BlockHalf::Upper { return (ohalf, ovariant); }
fn update_double_plant_state<W: WorldAccess>(
world: &W,
pos: Position,
ohalf: BlockHalf,
ovariant: DoublePlantVariant,
) -> (BlockHalf, DoublePlantVariant) {
if ohalf != BlockHalf::Upper {
return (ohalf, ovariant);
}
match world.get_block(pos.shift(Direction::Down)) {
Block::DoublePlant{variant, ..} => (ohalf, variant),
Block::DoublePlant { variant, .. } => (ohalf, variant),
_ => (ohalf, ovariant),
}
}
@ -5909,65 +5999,65 @@ fn piston_collision(extended: bool, facing: Direction) -> Vec<Aabb3<f64>> {
vec![Aabb3::new(
Point3::new(min_x, min_y, min_z),
Point3::new(max_x, max_y, max_z)
Point3::new(max_x, max_y, max_z),
)]
}
fn trapdoor_collision(facing: Direction, half: BlockHalf, open: bool) -> Vec<Aabb3<f64>> {
let (min_x, min_y, min_z, max_x, max_y, max_z) = if open {
match facing {
Direction::North => (0.0, 0.0, 3.0/16.0, 1.0, 1.0, 1.0),
Direction::South => (0.0, 0.0, 0.0, 1.0, 1.0, 3.0/16.0),
Direction::West => (3.0/16.0, 0.0, 0.0, 1.0, 1.0, 1.0),
Direction::East => (0.0, 0.0, 0.0, 3.0/16.0, 1.0, 1.0),
Direction::North => (0.0, 0.0, 3.0 / 16.0, 1.0, 1.0, 1.0),
Direction::South => (0.0, 0.0, 0.0, 1.0, 1.0, 3.0 / 16.0),
Direction::West => (3.0 / 16.0, 0.0, 0.0, 1.0, 1.0, 1.0),
Direction::East => (0.0, 0.0, 0.0, 3.0 / 16.0, 1.0, 1.0),
_ => unreachable!(),
}
} else {
match half {
BlockHalf::Bottom => (0.0, 0.0, 0.0, 1.0, 3.0/16.0, 1.0),
BlockHalf::Top => (0.0, 3.0/16.0, 0.0, 1.0, 1.0, 1.0),
BlockHalf::Bottom => (0.0, 0.0, 0.0, 1.0, 3.0 / 16.0, 1.0),
BlockHalf::Top => (0.0, 3.0 / 16.0, 0.0, 1.0, 1.0, 1.0),
_ => unreachable!(),
}
};
vec![Aabb3::new(
Point3::new(min_x, min_y, min_z),
Point3::new(max_x, max_y, max_z))
]
Point3::new(max_x, max_y, max_z),
)]
}
fn fence_collision(north: bool, south: bool, west: bool, east: bool) -> Vec<Aabb3<f64>> {
let mut collision = vec![Aabb3::new(
Point3::new(3.0/8.0, 0.0, 3.0/8.0),
Point3::new(5.0/8.0, 1.5, 5.0/8.0))
];
Point3::new(3.0 / 8.0, 0.0, 3.0 / 8.0),
Point3::new(5.0 / 8.0, 1.5, 5.0 / 8.0),
)];
if north {
collision.push(Aabb3::new(
Point3::new(3.0/8.0, 0.0, 0.0),
Point3::new(5.0/8.0, 1.5, 3.0/8.0))
);
Point3::new(3.0 / 8.0, 0.0, 0.0),
Point3::new(5.0 / 8.0, 1.5, 3.0 / 8.0),
));
}
if south {
collision.push(Aabb3::new(
Point3::new(3.0/8.0, 0.0, 5.0/8.0),
Point3::new(5.0/8.0, 1.5, 1.0))
);
Point3::new(3.0 / 8.0, 0.0, 5.0 / 8.0),
Point3::new(5.0 / 8.0, 1.5, 1.0),
));
}
if west {
collision.push(Aabb3::new(
Point3::new(0.0, 0.0, 3.0/8.0),
Point3::new(3.0/8.0, 1.5, 5.0/8.0))
);
Point3::new(0.0, 0.0, 3.0 / 8.0),
Point3::new(3.0 / 8.0, 1.5, 5.0 / 8.0),
));
}
if east {
collision.push(Aabb3::new(
Point3::new(5.0/8.0, 0.0, 3.0/8.0),
Point3::new(1.0, 1.5, 5.0/8.0))
);
Point3::new(5.0 / 8.0, 0.0, 3.0 / 8.0),
Point3::new(1.0, 1.5, 5.0 / 8.0),
));
}
collision
@ -5975,36 +6065,36 @@ fn fence_collision(north: bool, south: bool, west: bool, east: bool) -> Vec<Aabb
fn pane_collision(north: bool, south: bool, east: bool, west: bool) -> Vec<Aabb3<f64>> {
let mut collision = vec![Aabb3::new(
Point3::new(7.0/16.0, 0.0, 7.0/16.0),
Point3::new(9.0/16.0, 1.0, 9.0/16.0))
];
Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0),
Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0),
)];
if north {
collision.push(Aabb3::new(
Point3::new(7.0/16.0, 0.0, 0.0),
Point3::new(9.0/16.0, 1.0, 9.0/16.0))
);
Point3::new(7.0 / 16.0, 0.0, 0.0),
Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0),
));
}
if south {
collision.push(Aabb3::new(
Point3::new(7.0/16.0, 0.0, 7.0/16.0),
Point3::new(9.0/16.0, 1.0, 1.0))
);
Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0),
Point3::new(9.0 / 16.0, 1.0, 1.0),
));
}
if west {
collision.push(Aabb3::new(
Point3::new(0.0, 0.0, 7.0/16.0),
Point3::new(9.0/16.0, 1.0, 9.0/16.0))
);
Point3::new(0.0, 0.0, 7.0 / 16.0),
Point3::new(9.0 / 16.0, 1.0, 9.0 / 16.0),
));
}
if east {
collision.push(Aabb3::new(
Point3::new(7.0/16.0, 0.0, 7.0/16.0),
Point3::new(1.0, 1.0, 9.0/16.0))
);
Point3::new(7.0 / 16.0, 0.0, 7.0 / 16.0),
Point3::new(1.0, 1.0, 9.0 / 16.0),
));
}
collision
@ -6012,20 +6102,20 @@ fn pane_collision(north: bool, south: bool, east: bool, west: bool) -> Vec<Aabb3
fn get_stair_info<W: WorldAccess>(world: &W, pos: Position) -> Option<(Direction, BlockHalf)> {
match world.get_block(pos) {
Block::OakStairs{facing, half, ..} |
Block::StoneStairs{facing, half, ..} |
Block::BrickStairs{facing, half, ..} |
Block::StoneBrickStairs{facing, half, ..} |
Block::NetherBrickStairs{facing, half, ..} |
Block::SandstoneStairs{facing, half, ..} |
Block::SpruceStairs{facing, half, ..} |
Block::BirchStairs{facing, half, ..} |
Block::JungleStairs{facing, half, ..} |
Block::QuartzStairs{facing, half, ..} |
Block::AcaciaStairs{facing, half, ..} |
Block::DarkOakStairs{facing, half, ..} |
Block::RedSandstoneStairs{facing, half, ..} |
Block::PurpurStairs{facing, half, ..} => Some((facing, half)),
Block::OakStairs { facing, half, .. }
| Block::StoneStairs { facing, half, .. }
| Block::BrickStairs { facing, half, .. }
| Block::StoneBrickStairs { facing, half, .. }
| Block::NetherBrickStairs { facing, half, .. }
| Block::SandstoneStairs { facing, half, .. }
| Block::SpruceStairs { facing, half, .. }
| Block::BirchStairs { facing, half, .. }
| Block::JungleStairs { facing, half, .. }
| Block::QuartzStairs { facing, half, .. }
| Block::AcaciaStairs { facing, half, .. }
| Block::DarkOakStairs { facing, half, .. }
| Block::RedSandstoneStairs { facing, half, .. }
| Block::PurpurStairs { facing, half, .. } => Some((facing, half)),
_ => None,
}
}
@ -6054,18 +6144,34 @@ fn update_stair_shape<W: WorldAccess>(world: &W, pos: Position, facing: Directio
StairShape::Straight
}
fn stair_data(facing: Direction, half: BlockHalf, shape: StairShape, waterlogged: bool) -> Option<usize> {
if shape != StairShape::Straight { return None; }
if waterlogged { return None; }
fn stair_data(
facing: Direction,
half: BlockHalf,
shape: StairShape,
waterlogged: bool,
) -> Option<usize> {
if shape != StairShape::Straight {
return None;
}
if waterlogged {
return None;
}
Some((5 - facing.index()) | (if half == BlockHalf::Top { 0x4 } else { 0x0 }))
}
fn stair_offset(facing: Direction, half: BlockHalf, shape: StairShape, waterlogged: bool) -> Option<usize> {
Some(if waterlogged { 0 } else { 1 } +
shape.offset() * 2 +
if half == BlockHalf::Top { 0 } else { 2 * 5 } +
facing.horizontal_offset() * 2 * 5 * 2)
fn stair_offset(
facing: Direction,
half: BlockHalf,
shape: StairShape,
waterlogged: bool,
) -> Option<usize> {
Some(
if waterlogged { 0 } else { 1 }
+ shape.offset() * 2
+ if half == BlockHalf::Top { 0 } else { 2 * 5 }
+ facing.horizontal_offset() * 2 * 5 * 2,
)
}
#[allow(clippy::many_single_char_names)]
@ -6113,24 +6219,24 @@ fn stair_collision(facing: Direction, shape: StairShape, half: BlockHalf) -> Vec
for bound in &mut bounds {
let x = bound.min.x - 0.5;
let z = bound.min.z - 0.5;
bound.min.x = 0.5 + (x*c - z*s);
bound.min.z = 0.5 + (z*c + x*s);
bound.min.x = 0.5 + (x * c - z * s);
bound.min.z = 0.5 + (z * c + x * s);
let x = bound.max.x - 0.5;
let z = bound.max.z - 0.5;
bound.max.x = 0.5 + (x*c - z*s);
bound.max.z = 0.5 + (z*c + x*s);
bound.max.x = 0.5 + (x * c - z * s);
bound.max.z = 0.5 + (z * c + x * s);
if half == BlockHalf::Top {
let c = PI.cos();
let s = PI.sin();
let z = bound.min.z - 0.5;
let y = bound.min.y - 0.5;
bound.min.z = 0.5 + (z*c - y*s);
bound.min.y = 0.5 + (y*c + z*s);
bound.min.z = 0.5 + (z * c - y * s);
bound.min.y = 0.5 + (y * c + z * s);
let z = bound.max.z - 0.5;
let y = bound.max.y - 0.5;
bound.max.z = 0.5 + (z*c - y*s);
bound.max.y = 0.5 + (y*c + z*s);
bound.max.z = 0.5 + (z * c - y * s);
bound.max.y = 0.5 + (y * c + z * s);
bound.min.x = 1.0 - bound.min.x;
bound.max.x = 1.0 - bound.max.x;
@ -6150,7 +6256,7 @@ fn slab_collision(half: BlockHalf) -> Vec<Aabb3<f64>> {
vec![Aabb3::new(
Point3::new(min_x, min_y, min_z),
Point3::new(max_x, max_y, max_z)
Point3::new(max_x, max_y, max_z),
)]
}
@ -6218,7 +6324,7 @@ impl DirtVariant {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum BedPart {
Head,
Foot
Foot,
}
impl BedPart {
@ -6301,7 +6407,6 @@ impl NoteBlockInstrument {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum RedSandstoneVariant {
Normal,
@ -6382,67 +6487,91 @@ impl PrismarineVariant {
}
}
fn mushroom_block_data(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> Option<usize> {
Some(match
(is_stem, west, up, south, north, east, down) {
fn mushroom_block_data(
is_stem: bool,
west: bool,
up: bool,
south: bool,
north: bool,
east: bool,
down: bool,
) -> Option<usize> {
Some(match (is_stem, west, up, south, north, east, down) {
(false, false, false, false, false, false, false) => 0,
(false, true, false, false, true, false, false) => 1,
(false, false, false, false, true, false, false) => 2,
(false, false, false, false, true, true, false) => 3,
(false, true, false, false, false, false, false) => 4,
(false, false, true, false, false, false, false) => 5,
(false, false, false, false, false, true, false) => 6,
(false, true, false, true, false, false, false) => 7,
(false, false, false, true, false, false, false) => 8,
(false, false, false, true, false, true, false) => 9,
(false, true, false, true, true, true, false) => 10,
(false, true, true, true, true, true, true) => 14,
(true, false, false, false, false, false, false) => 15,
(false, true, false, false, true, false, false) => 1,
(false, false, false, false, true, false, false) => 2,
(false, false, false, false, true, true, false) => 3,
(false, true, false, false, false, false, false) => 4,
(false, false, true, false, false, false, false) => 5,
(false, false, false, false, false, true, false) => 6,
(false, true, false, true, false, false, false) => 7,
(false, false, false, true, false, false, false) => 8,
(false, false, false, true, false, true, false) => 9,
(false, true, false, true, true, true, false) => 10,
(false, true, true, true, true, true, true) => 14,
(true, false, false, false, false, false, false) => 15,
_ => return None,
})
}
fn mushroom_block_offset(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> Option<usize> {
fn mushroom_block_offset(
is_stem: bool,
west: bool,
up: bool,
south: bool,
north: bool,
east: bool,
down: bool,
) -> Option<usize> {
if is_stem {
None
} else {
Some(if west { 0 } else { 1<<0 } +
if up { 0 } else { 1<<1 } +
if south { 0 } else { 1<<2 } +
if north { 0 } else { 1<<3 } +
if east { 0 } else { 1<<4 } +
if down { 0 } else { 1<<5 })
Some(
if west { 0 } else { 1 << 0 }
+ if up { 0 } else { 1 << 1 }
+ if south { 0 } else { 1 << 2 }
+ if north { 0 } else { 1 << 3 }
+ if east { 0 } else { 1 << 4 }
+ if down { 0 } else { 1 << 5 },
)
}
}
fn mushroom_block_variant(is_stem: bool, west: bool, up: bool, south: bool, north: bool, east: bool, down: bool) -> String {
fn mushroom_block_variant(
is_stem: bool,
west: bool,
up: bool,
south: bool,
north: bool,
east: bool,
down: bool,
) -> String {
(if is_stem {
"all_stem"
} else {
match
(west, up, south, north, east, down) {
match (west, up, south, north, east, down) {
(false, false, false, false, false, false) => "all_inside",
(true, false, false, true, false, false) => "north_west",
(false, false, false, true, false, false) => "north",
(false, false, false, true, true, false) => "north_east",
(true, false, false, false, false, false) => "west",
(false, true, false, false, false, false) => "center",
(false, false, false, false, true, false) => "east",
(true, false, true, false, false, false) => "south_west",
(false, false, true, false, false, false) => "south",
(false, false, true, false, true, false) => "south_east",
(true, false, true, true, true, false) => "stem",
(true, true, true, true, true, true) => "all_outside",
(true, false, false, true, false, false) => "north_west",
(false, false, false, true, false, false) => "north",
(false, false, false, true, true, false) => "north_east",
(true, false, false, false, false, false) => "west",
(false, true, false, false, false, false) => "center",
(false, false, false, false, true, false) => "east",
(true, false, true, false, false, false) => "south_west",
(false, false, true, false, false, false) => "south",
(false, false, true, false, true, false) => "south_east",
(true, false, true, true, true, false) => "stem",
(true, true, true, true, true, true) => "all_outside",
_ => "all_stem",
}
}).to_string()
})
.to_string()
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum DoorHalf {
Upper,
Lower
Lower,
}
impl DoorHalf {
@ -6771,9 +6900,9 @@ impl StoneSlabVariant {
fn data(self) -> usize {
match self {
StoneSlabVariant::Stone |
StoneSlabVariant::RedSandstone |
StoneSlabVariant::Purpur => 0,
StoneSlabVariant::Stone | StoneSlabVariant::RedSandstone | StoneSlabVariant::Purpur => {
0
}
StoneSlabVariant::Sandstone => 1,
StoneSlabVariant::PetrifiedWood => 2,
StoneSlabVariant::Cobblestone => 3,
@ -7037,7 +7166,8 @@ impl AttachedFace {
(AttachedFace::Floor, Direction::East) => "up_x",
(AttachedFace::Ceiling, Direction::South) => "down_z",
_ => "north", // TODO: support 1.13.2+ new directions
}.to_owned()
}
.to_owned()
}
}
@ -7094,7 +7224,6 @@ impl StructureBlockMode {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TreeVariant {
Oak,
@ -7125,7 +7254,7 @@ impl TreeVariant {
TreeVariant::StrippedJungle => "stripped_jungle_log",
TreeVariant::StrippedAcacia => "stripped_acacia_log",
TreeVariant::StrippedDarkOak => "stripped_dark_oak_log",
TreeVariant::StrippedOak => "stripped_oak_log"
TreeVariant::StrippedOak => "stripped_oak_log",
}
}
@ -7388,4 +7517,3 @@ impl CoralVariant {
}
}
}

1
blocks/src/material.rs

@ -1,4 +1,3 @@
pub struct Material {
pub renderable: bool,
pub should_cull_against: bool,

8
gl/build.rs

@ -1,19 +1,15 @@
use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
use std::env;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
use gl_generator::{Registry, Api, Profile, Fallbacks, GlobalGenerator};
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest = Path::new(&out_dir);
let mut file = BufWriter::new(File::create(&dest.join("bindings.rs")).unwrap());
Registry::new(Api::Gl,
(3, 2),
Profile::Core,
Fallbacks::All,
[])
Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, [])
.write_bindings(GlobalGenerator, &mut file)
.unwrap();
}

23
protocol/src/format.rs

@ -22,7 +22,6 @@ pub enum Component {
}
impl Component {
pub fn from_string(str: &str) -> Self {
let mut component;
match serde_json::from_str::<serde_json::Value>(str) {
@ -31,7 +30,7 @@ impl Component {
Err(_) => {
component = Component::Text(TextComponent::new(str));
convert_legacy(&mut component);
},
}
}
component
}
@ -47,7 +46,9 @@ impl Component {
Component::Text(TextComponent::from_value(v, modifier))
} else if v.get("translate").is_some() {
// TODO: translations
Component::Text(TextComponent::new(v.get("translate").unwrap().as_str().unwrap()))
Component::Text(TextComponent::new(
v.get("translate").unwrap().as_str().unwrap(),
))
} else {
modifier.color = Some(Color::RGB(255, 0, 0));
Component::Text(TextComponent {
@ -100,9 +101,10 @@ impl Modifier {
underlined: v.get("underlined").map_or(Option::None, |v| v.as_bool()),
strikethrough: v.get("strikethrough").map_or(Option::None, |v| v.as_bool()),
obfuscated: v.get("obfuscated").map_or(Option::None, |v| v.as_bool()),
color: v.get("color")
.map_or(Option::None, |v| v.as_str())
.map(|v| Color::from_string(&v.to_owned())),
color: v
.get("color")
.map_or(Option::None, |v| v.as_str())
.map(|v| Color::from_string(&v.to_owned())),
extra: Option::None,
};
if let Some(extra) = v.get("extra") {
@ -132,7 +134,9 @@ impl TextComponent {
pub fn new(val: &str) -> TextComponent {
TextComponent {
text: val.to_owned(),
modifier: Modifier { ..Default::default() },
modifier: Modifier {
..Default::default()
},
}
}
@ -319,8 +323,9 @@ pub fn convert_legacy(c: &mut Component) {
current.text = txt.text[last..i].to_owned();
last = next.0 + 1;
let mut modifier = if (color_char >= 'a' && color_char <= 'f') ||
(color_char >= '0' && color_char <= '9') {
let mut modifier = if (color_char >= 'a' && color_char <= 'f')
|| (color_char >= '0' && color_char <= '9')
{
Default::default()
} else {
current.modifier.clone()

5
protocol/src/item.rs

@ -14,8 +14,8 @@
use crate::nbt;
use crate::protocol::{self, Serializable};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io;
use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
#[derive(Debug)]
pub struct Stack {
@ -25,7 +25,6 @@ pub struct Stack {
tag: Option<nbt::NamedTag>,
}
impl Default for Stack {
fn default() -> Stack {
Stack {
@ -44,7 +43,7 @@ impl Serializable for Option<Stack> {
if protocol_version >= 404 {
let present = buf.read_u8()? != 0;
if !present {
return Ok(None)
return Ok(None);
}
}

5
protocol/src/lib.rs

@ -1,10 +1,9 @@
#![recursion_limit="300"]
#![recursion_limit = "300"]
#[macro_use]
pub mod macros;
pub mod item;
pub mod format;
pub mod item;
pub mod nbt;
pub mod protocol;
pub mod types;

2
protocol/src/macros.rs

@ -1,5 +1,3 @@
#[doc(hidden)]
#[macro_export]
macro_rules! create_ids {

6
protocol/src/nbt/mod.rs

@ -16,9 +16,9 @@ use std::collections::HashMap;
use std::io;
use std::io::Read;
use super::protocol::Serializable;
use super::protocol;
use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
use super::protocol::Serializable;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
#[derive(Debug, Clone)]
pub enum Tag {
@ -41,7 +41,6 @@ pub enum Tag {
pub struct NamedTag(pub String, pub Tag);
impl Tag {
pub fn new_compound() -> Tag {
Tag::Compound(HashMap::new())
}
@ -163,7 +162,6 @@ impl Tag {
}
}
fn internal_id(&self) -> u8 {
match *self {
Tag::End => 0,