Fix formatting

This commit is contained in:
Nathan Ruiz 2022-10-24 16:08:30 +00:00
parent 4ac2a8dafa
commit ee8e6cb9f3
5 changed files with 213 additions and 96 deletions

View File

@ -6647,97 +6647,199 @@ mod tests {
#[test]
fn verify_blocks() {
let dirt = Block::Dirt { snowy: true, variant: DirtVariant::Normal };
let stone = Block::Stone { variant: StoneVariant::Normal };
let vine = Block::Vine { up: false, south: false, west: false, north: true, east: false };
let pumpkin_lit = Block::PumpkinLit { facing: Direction::North, without_face: true };
let cocoa = Block::Cocoa { age: 1, facing: Direction::North };
let leaves = Block::Leaves { variant: TreeVariant::Oak, decayable: false, check_decay: false, distance: 1 };
let leaves2 = Block::Leaves2 { variant: TreeVariant::Oak, decayable: false, check_decay: false };
let wool = Block::Wool { color: ColoredVariant::White };
let tall_seagrass = Block::TallSeagrass { half: TallSeagrassHalf::Upper };
let dirt = Block::Dirt {
snowy: true,
variant: DirtVariant::Normal,
};
let stone = Block::Stone {
variant: StoneVariant::Normal,
};
let vine = Block::Vine {
up: false,
south: false,
west: false,
north: true,
east: false,
};
let pumpkin_lit = Block::PumpkinLit {
facing: Direction::North,
without_face: true,
};
let cocoa = Block::Cocoa {
age: 1,
facing: Direction::North,
};
let leaves = Block::Leaves {
variant: TreeVariant::Oak,
decayable: false,
check_decay: false,
distance: 1,
};
let leaves2 = Block::Leaves2 {
variant: TreeVariant::Oak,
decayable: false,
check_decay: false,
};
let wool = Block::Wool {
color: ColoredVariant::White,
};
let tall_seagrass = Block::TallSeagrass {
half: TallSeagrassHalf::Upper,
};
let data = [
(dirt, None, Some(0.75)),
(dirt, Some(Tool::Shovel(ToolMaterial::Wood)), Some(0.4)),
(dirt, Some(Tool::Pickaxe(ToolMaterial::Wood)), Some(0.75)),
(stone, None, Some(7.5)),
(stone, Some(Tool::Shovel(ToolMaterial::Wood)), Some(7.5)),
(stone, Some(Tool::Pickaxe(ToolMaterial::Wood)), Some(1.15)),
(Block::Obsidian {}, None, Some(250.0)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Wood)), Some(125.0)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Stone)), Some(62.5)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Iron)), Some(41.7)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Diamond)), Some(9.4)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Netherite)), Some(8.35)),
(Block::Obsidian {}, Some(Tool::Pickaxe(ToolMaterial::Gold)), Some(20.85)),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Wood)),
Some(125.0),
),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Stone)),
Some(62.5),
),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Iron)),
Some(41.7),
),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Diamond)),
Some(9.4),
),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Netherite)),
Some(8.35),
),
(
Block::Obsidian {},
Some(Tool::Pickaxe(ToolMaterial::Gold)),
Some(20.85),
),
(Block::Bedrock {}, None, None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Wood)), None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Stone)), None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Iron)), None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Diamond)), None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Netherite)), None),
(Block::Bedrock {}, Some(Tool::Pickaxe(ToolMaterial::Gold)), None),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Wood)),
None,
),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Stone)),
None,
),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Iron)),
None,
),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Diamond)),
None,
),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Netherite)),
None,
),
(
Block::Bedrock {},
Some(Tool::Pickaxe(ToolMaterial::Gold)),
None,
),
(Block::Web {}, None, Some(20.0)),
(Block::Web {}, Some(Tool::Pickaxe(ToolMaterial::Wood)), Some(20.0)),
(
Block::Web {},
Some(Tool::Pickaxe(ToolMaterial::Wood)),
Some(20.0),
),
(vine, None, Some(0.3)),
(vine, Some(Tool::Pickaxe(ToolMaterial::Wood)), Some(0.3)),
(vine, Some(Tool::Axe(ToolMaterial::Wood)), Some(0.15)),
(vine, Some(Tool::Axe(ToolMaterial::Stone)), Some(0.1)),
(vine, Some(Tool::Axe(ToolMaterial::Iron)), Some(0.05)),
(vine, Some(Tool::Axe(ToolMaterial::Diamond)), Some(0.05)),
(wool, None, Some(1.2)),
(leaves, None, Some(0.3)),
(leaves, Some(Tool::Hoe(ToolMaterial::Wood)), Some(0.15)),
(leaves, Some(Tool::Hoe(ToolMaterial::Stone)), Some(0.1)),
(leaves, Some(Tool::Hoe(ToolMaterial::Iron)), Some(0.05)),
(leaves, Some(Tool::Hoe(ToolMaterial::Diamond)), Some(0.05)),
(leaves2, None, Some(0.3)),
(leaves2, Some(Tool::Hoe(ToolMaterial::Wood)), Some(0.15)),
(leaves2, Some(Tool::Hoe(ToolMaterial::Stone)), Some(0.1)),
(leaves2, Some(Tool::Hoe(ToolMaterial::Iron)), Some(0.05)),
(leaves2, Some(Tool::Hoe(ToolMaterial::Diamond)), Some(0.05)),
(Block::DeadBush {}, None, Some(0.05)),
(Block::DeadBush {}, Some(Tool::Shears), Some(0.05)),
(Block::Seagrass {}, None, Some(0.05)),
(Block::Seagrass {}, Some(Tool::Shears), Some(0.05)),
(tall_seagrass, None, Some(0.05)),
(tall_seagrass, Some(Tool::Shears), Some(0.05)),
(cocoa, None, Some(0.3)),
(cocoa, Some(Tool::Axe(ToolMaterial::Wood)), Some(0.15)),
(cocoa, Some(Tool::Axe(ToolMaterial::Stone)), Some(0.1)),
(cocoa, Some(Tool::Axe(ToolMaterial::Iron)), Some(0.05)),
(cocoa, Some(Tool::Axe(ToolMaterial::Diamond)), Some(0.05)),
(Block::MelonBlock {}, None, Some(1.5)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Wood)), Some(0.75)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Stone)), Some(0.4)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Iron)), Some(0.25)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Diamond)), Some(0.2)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Netherite)), Some(0.2)),
(Block::MelonBlock {}, Some(Tool::Axe(ToolMaterial::Gold)), Some(0.15)),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Wood)),
Some(0.75),
),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Stone)),
Some(0.4),
),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Iron)),
Some(0.25),
),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Diamond)),
Some(0.2),
),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Netherite)),
Some(0.2),
),
(
Block::MelonBlock {},
Some(Tool::Axe(ToolMaterial::Gold)),
Some(0.15),
),
(Block::Pumpkin {}, None, Some(1.5)),
(Block::Pumpkin {}, Some(Tool::Axe(ToolMaterial::Wood)), Some(0.75)),
(Block::Pumpkin {}, Some(Tool::Axe(ToolMaterial::Stone)), Some(0.4)),
(Block::Pumpkin {}, Some(Tool::Axe(ToolMaterial::Iron)), Some(0.25)),
(
Block::Pumpkin {},
Some(Tool::Axe(ToolMaterial::Wood)),
Some(0.75),
),
(
Block::Pumpkin {},
Some(Tool::Axe(ToolMaterial::Stone)),
Some(0.4),
),
(
Block::Pumpkin {},
Some(Tool::Axe(ToolMaterial::Iron)),
Some(0.25),
),
(pumpkin_lit, None, Some(1.5)),
(pumpkin_lit, Some(Tool::Axe(ToolMaterial::Wood)), Some(0.75)),
(pumpkin_lit, Some(Tool::Axe(ToolMaterial::Stone)), Some(0.4)),
(pumpkin_lit, Some(Tool::Axe(ToolMaterial::Iron)), Some(0.25)),
// TODO: Fix special sword rules
//(Block::Web {}, Some(Tool::Sword(ToolMaterial::Wood)), Some(0.4)),
//(Block::Web {}, Some(Tool::Sword(ToolMaterial::Stone)), Some(0.4)),
@ -8810,7 +8912,7 @@ impl ToolMaterial {
ToolMaterial::Gold => 12.0,
ToolMaterial::Iron => 6.0,
ToolMaterial::Diamond => 8.0,
ToolMaterial::Netherite => 9.0
ToolMaterial::Netherite => 9.0,
}
}
}
@ -8833,7 +8935,7 @@ impl Tool {
Tool::Shovel(m) => m.get_multiplier(),
Tool::Hoe(m) => m.get_multiplier(),
Tool::Sword(_) => 1.5, // TODO: Handle different block values.
Tool::Shears => 2.0, // TODO: Handle different block values.
Tool::Shears => 2.0, // TODO: Handle different block values.
}
}
}
}

View File

@ -197,4 +197,4 @@ impl MouseButtons {
pub fn new() -> Self {
Default::default()
}
}
}

View File

@ -1,5 +1,6 @@
use super::{
Bounds, GameInfo, Gravity, Light, Position, Rotation, TargetPosition, TargetRotation, Velocity, MouseButtons, Digging
Bounds, Digging, GameInfo, Gravity, Light, MouseButtons, Position, Rotation, TargetPosition,
TargetRotation, Velocity,
};
use crate::ecs;
use crate::format;

View File

@ -311,11 +311,7 @@ impl ApplyDigging {
}
}
fn send_packet(&self,
conn: &mut Conn,
target: &DiggingState,
state: i32
) {
fn send_packet(&self, conn: &mut Conn, target: &DiggingState, state: i32) {
match state {
0 => debug!("Send start dig packet {:?}", target),
1 => debug!("Send cancel dig packet {:?}", target),
@ -325,32 +321,44 @@ impl ApplyDigging {
match conn.protocol_version {
// 1.7.10
5 => conn.write_packet(packet::play::serverbound::PlayerDigging_u8_u8y {
status: state as u8,
x: target.position.x,
y: target.position.y as u8,
z: target.position.z,
face: target.face.index() as u8,
}).unwrap(),
5 => conn
.write_packet(packet::play::serverbound::PlayerDigging_u8_u8y {
status: state as u8,
x: target.position.x,
y: target.position.y as u8,
z: target.position.z,
face: target.face.index() as u8,
})
.unwrap(),
// 1.8.9 or v15w39c
47|74 => conn.write_packet(packet::play::serverbound::PlayerDigging_u8 {
status: state as u8,
location: target.position,
face: target.face.index() as u8,
}).unwrap(),
47 | 74 => conn
.write_packet(packet::play::serverbound::PlayerDigging_u8 {
status: state as u8,
location: target.position,
face: target.face.index() as u8,
})
.unwrap(),
// 1.9+
_ => conn.write_packet(packet::play::serverbound::PlayerDigging {
status: protocol::VarInt(state),
location: target.position,
face: target.face.index() as u8,
}).unwrap(),
_ => conn
.write_packet(packet::play::serverbound::PlayerDigging {
status: protocol::VarInt(state),
location: target.position,
face: target.face.index() as u8,
})
.unwrap(),
}
}
fn next_state(&self,
fn next_state(
&self,
last: &Option<DiggingState>,
mouse_buttons: &MouseButtons,
target: Option<(shared::Position, block::Block, shared::Direction, Vector3<f64>)>
target: Option<(
shared::Position,
block::Block,
shared::Direction,
Vector3<f64>,
)>,
) -> Option<DiggingState> {
// Figure out the next state
if !mouse_buttons.left {
@ -360,7 +368,9 @@ impl ApplyDigging {
match (last, target) {
// Started digging
(None, Some((position, block, face, _))) => Some(DiggingState {
block, face, position,
block,
face,
position,
start: std::time::Instant::now(),
finished: false,
}),
@ -372,7 +382,9 @@ impl ApplyDigging {
// Start digging a different block.
Some(DiggingState {
block, face, position,
block,
face,
position,
start: std::time::Instant::now(),
finished: false,
})
@ -388,7 +400,7 @@ impl ApplyDigging {
Some(mining_time) => {
let finish_time = state.start + mining_time;
finish_time > std::time::Instant::now()
},
}
None => false,
}
}
@ -399,12 +411,21 @@ impl ecs::System for ApplyDigging {
&self.filter
}
fn update(&mut self, m: &mut ecs::Manager, world: &mut world::World, renderer: &mut render::Renderer) {
use crate::server::target::{trace_ray, test_block};
fn update(
&mut self,
m: &mut ecs::Manager,
world: &mut world::World,
renderer: &mut render::Renderer,
) {
use crate::server::target::{test_block, trace_ray};
use cgmath::EuclideanSpace;
let world_entity = m.get_world();
let mut conn = m.get_component(world_entity, self.conn).unwrap().write().unwrap();
let mut conn = m
.get_component(world_entity, self.conn)
.unwrap()
.write()
.unwrap();
let conn = match conn.as_mut() {
Some(conn) => conn,
// Don't keep processing digging operations if the connection was
@ -442,14 +463,14 @@ impl ecs::System for ApplyDigging {
}
// Start the new digging operation.
self.send_packet(conn, current, 0);
},
}
// Finish the new digging operation.
(Some(_), Some(current)) if !self.is_finished(current) && !current.finished => {
self.send_packet(conn, current, 2);
current.finished = true;
},
_ => {},
}
_ => {}
}
}
}
}
}

View File

@ -797,9 +797,7 @@ impl Server {
pub fn on_left_mouse_button(&mut self, pressed: bool) {
if let Some(player) = self.player {
if let Some(mouse_buttons) = self
.entities
.get_component_mut(player, self.mouse_buttons)
if let Some(mouse_buttons) = self.entities.get_component_mut(player, self.mouse_buttons)
{
mouse_buttons.left = pressed;
}
@ -808,9 +806,7 @@ impl Server {
pub fn on_right_mouse_button(&mut self, pressed: bool) {
if let Some(player) = self.player {
if let Some(mouse_buttons) = self
.entities
.get_component_mut(player, self.mouse_buttons)
if let Some(mouse_buttons) = self.entities.get_component_mut(player, self.mouse_buttons)
{
mouse_buttons.right = pressed;
}
@ -1079,10 +1075,7 @@ impl Server {
fn write_plugin_message(&mut self, channel: &str, data: &[u8]) {
let mut conn = self.conn.write().unwrap();
let _ = conn
.as_mut()
.unwrap()
.write_plugin_message(channel, data); // TODO handle errors
let _ = conn.as_mut().unwrap().write_plugin_message(channel, data); // TODO handle errors
}
fn on_game_join_worldnames_ishard_simdist(