mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
clippo
This commit is contained in:
parent
978880b756
commit
e8deda5d2e
12 changed files with 48 additions and 56 deletions
|
@ -36,7 +36,7 @@ struct BlockDefinition {
|
||||||
properties_and_defaults: Vec<PropertyAndDefault>,
|
properties_and_defaults: Vec<PropertyAndDefault>,
|
||||||
}
|
}
|
||||||
impl PropertyAndDefault {
|
impl PropertyAndDefault {
|
||||||
fn into_property_with_name_and_default(&self, name: String) -> PropertyWithNameAndDefault {
|
fn as_property_with_name_and_default(&self, name: String) -> PropertyWithNameAndDefault {
|
||||||
PropertyWithNameAndDefault {
|
PropertyWithNameAndDefault {
|
||||||
name,
|
name,
|
||||||
struct_name: self.struct_name.clone(),
|
struct_name: self.struct_name.clone(),
|
||||||
|
@ -110,11 +110,7 @@ impl Parse for BlockDefinition {
|
||||||
|
|
||||||
let mut properties_and_defaults = Vec::new();
|
let mut properties_and_defaults = Vec::new();
|
||||||
|
|
||||||
loop {
|
while let Ok(property) = content.parse() {
|
||||||
let property = match content.parse() {
|
|
||||||
Ok(property) => property,
|
|
||||||
Err(_) => break,
|
|
||||||
};
|
|
||||||
content.parse::<Token![=]>()?;
|
content.parse::<Token![=]>()?;
|
||||||
let property_default = content.parse()?;
|
let property_default = content.parse()?;
|
||||||
properties_and_defaults.push(PropertyAndDefault {
|
properties_and_defaults.push(PropertyAndDefault {
|
||||||
|
@ -248,7 +244,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
|
||||||
for property_name in block_property_names {
|
for property_name in block_property_names {
|
||||||
let property_variants = properties_map
|
let property_variants = properties_map
|
||||||
.get(property_name)
|
.get(property_name)
|
||||||
.expect(format!("Property '{}' not found", property_name).as_str())
|
.unwrap_or_else(|| panic!("Property '{}' not found", property_name))
|
||||||
.clone();
|
.clone();
|
||||||
block_properties_vec.push(property_variants);
|
block_properties_vec.push(property_variants);
|
||||||
}
|
}
|
||||||
|
@ -274,13 +270,13 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
|
||||||
};
|
};
|
||||||
let mut property_name = property_struct_names_to_names
|
let mut property_name = property_struct_names_to_names
|
||||||
.get(&property.struct_name.to_string())
|
.get(&property.struct_name.to_string())
|
||||||
.expect(format!("Property '{}' is bad", property.struct_name).as_str())
|
.unwrap_or_else(|| panic!("Property '{}' is bad", property.struct_name))
|
||||||
.clone();
|
.clone();
|
||||||
if let Some(index) = index {
|
if let Some(index) = index {
|
||||||
property_name.push_str(&format!("_{}", &index.to_string()));
|
property_name.push_str(&format!("_{}", &index.to_string()));
|
||||||
}
|
}
|
||||||
properties_with_name
|
properties_with_name
|
||||||
.push(property.into_property_with_name_and_default(property_name.clone()));
|
.push(property.as_property_with_name_and_default(property_name.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub face: properties::Face,
|
// pub face: properties::Face,
|
||||||
|
@ -297,7 +293,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
|
||||||
{
|
{
|
||||||
// let property_name_snake =
|
// let property_name_snake =
|
||||||
// Ident::new(&property.to_string(), proc_macro2::Span::call_site());
|
// Ident::new(&property.to_string(), proc_macro2::Span::call_site());
|
||||||
let name_ident = Ident::new(&name, proc_macro2::Span::call_site());
|
let name_ident = Ident::new(name, proc_macro2::Span::call_site());
|
||||||
block_struct_fields.extend(quote! {
|
block_struct_fields.extend(quote! {
|
||||||
pub #name_ident: #struct_name,
|
pub #name_ident: #struct_name,
|
||||||
})
|
})
|
||||||
|
@ -317,7 +313,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
|
||||||
let first_state_id = state_id;
|
let first_state_id = state_id;
|
||||||
|
|
||||||
// if there's no properties, then the block is just a single state
|
// if there's no properties, then the block is just a single state
|
||||||
if block_properties_vec.len() == 0 {
|
if block_properties_vec.is_empty() {
|
||||||
block_state_enum_variants.extend(quote! {
|
block_state_enum_variants.extend(quote! {
|
||||||
#block_name_pascal_case,
|
#block_name_pascal_case,
|
||||||
});
|
});
|
||||||
|
@ -418,7 +414,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
|
||||||
let block_behavior = &block.behavior;
|
let block_behavior = &block.behavior;
|
||||||
let block_id = block.name.to_string();
|
let block_id = block.name.to_string();
|
||||||
|
|
||||||
let from_block_to_state_match = if block.properties_and_defaults.len() > 0 {
|
let from_block_to_state_match = if !block.properties_and_defaults.is_empty() {
|
||||||
quote! {
|
quote! {
|
||||||
match b {
|
match b {
|
||||||
#from_block_to_state_match_inner
|
#from_block_to_state_match_inner
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
|
pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
|
||||||
let mut combinations = Vec::new();
|
let mut combinations = Vec::new();
|
||||||
if items.len() == 0 {
|
if items.is_empty() {
|
||||||
return combinations;
|
return combinations;
|
||||||
};
|
};
|
||||||
if items.len() == 1 {
|
if items.len() == 1 {
|
||||||
|
@ -13,8 +13,7 @@ pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
|
||||||
for i in 0..items[0].len() {
|
for i in 0..items[0].len() {
|
||||||
let item = &items[0][i];
|
let item = &items[0][i];
|
||||||
for other_combinations in combinations_of(&items[1..]) {
|
for other_combinations in combinations_of(&items[1..]) {
|
||||||
let mut combination = Vec::new();
|
let mut combination = vec![item.clone()];
|
||||||
combination.push(item.clone());
|
|
||||||
combination.extend(other_combinations);
|
combination.extend(other_combinations);
|
||||||
combinations.push(combination);
|
combinations.push(combination);
|
||||||
}
|
}
|
||||||
|
@ -29,13 +28,11 @@ pub fn to_pascal_case(s: &str) -> String {
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
if c == '_' {
|
if c == '_' {
|
||||||
prev_was_underscore = true;
|
prev_was_underscore = true;
|
||||||
|
} else if prev_was_underscore {
|
||||||
|
result.push(c.to_ascii_uppercase());
|
||||||
|
prev_was_underscore = false;
|
||||||
} else {
|
} else {
|
||||||
if prev_was_underscore {
|
result.push(c);
|
||||||
result.push(c.to_ascii_uppercase());
|
|
||||||
prev_was_underscore = false;
|
|
||||||
} else {
|
|
||||||
result.push(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|
|
@ -7,8 +7,10 @@ pub use blocks::*;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
impl BlockState {
|
impl BlockState {
|
||||||
/// Transmutes a u32 to a block state. UB if the value is not a valid block
|
/// Transmutes a u32 to a block state.
|
||||||
/// state.
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// The `state_id` should be a valid block state.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn from_u32_unsafe(state_id: u32) -> Self {
|
pub unsafe fn from_u32_unsafe(state_id: u32) -> Self {
|
||||||
mem::transmute::<u32, BlockState>(state_id)
|
mem::transmute::<u32, BlockState>(state_id)
|
||||||
|
|
|
@ -231,7 +231,7 @@ impl McBufVarReadable for i64 {
|
||||||
for i in 0..8 {
|
for i in 0..8 {
|
||||||
buf.read_exact(&mut buffer)
|
buf.read_exact(&mut buffer)
|
||||||
.map_err(|_| "Invalid VarLong".to_string())?;
|
.map_err(|_| "Invalid VarLong".to_string())?;
|
||||||
ans |= ((buffer[0] & 0b0111_1111) as i64) << 7 * i;
|
ans |= ((buffer[0] & 0b0111_1111) as i64) << (7 * i);
|
||||||
if buffer[0] & 0b1000_0000 == 0 {
|
if buffer[0] & 0b1000_0000 == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl McBufVarWritable for i64 {
|
||||||
}
|
}
|
||||||
// this only writes a single byte, so write_all isn't necessary
|
// this only writes a single byte, so write_all isn't necessary
|
||||||
// the let _ = is so clippy doesn't complain
|
// the let _ = is so clippy doesn't complain
|
||||||
let _ = buf.write(&mut buffer)?;
|
let _ = buf.write(&buffer)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl TranslatableComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&self) -> Result<String, fmt::Error> {
|
pub fn read(&self) -> Result<String, fmt::Error> {
|
||||||
let template = azalea_language::get(&self.key).unwrap_or_else(|| &self.key);
|
let template = azalea_language::get(&self.key).unwrap_or(&self.key);
|
||||||
// decode the % things
|
// decode the % things
|
||||||
|
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
|
|
|
@ -155,8 +155,8 @@ impl Client {
|
||||||
|
|
||||||
// we got the GameConnection, so the server is now connected :)
|
// we got the GameConnection, so the server is now connected :)
|
||||||
let client = Client {
|
let client = Client {
|
||||||
game_profile: game_profile.clone(),
|
game_profile,
|
||||||
conn: conn.clone(),
|
conn,
|
||||||
player: Arc::new(Mutex::new(Player::default())),
|
player: Arc::new(Mutex::new(Player::default())),
|
||||||
dimension: Arc::new(Mutex::new(None)),
|
dimension: Arc::new(Mutex::new(None)),
|
||||||
};
|
};
|
||||||
|
@ -167,7 +167,7 @@ impl Client {
|
||||||
// read the error to see where the issue is
|
// read the error to see where the issue is
|
||||||
// you might be able to just drop the lock or put it in its own scope to fix
|
// you might be able to just drop the lock or put it in its own scope to fix
|
||||||
tokio::spawn(Self::protocol_loop(client.clone(), tx.clone()));
|
tokio::spawn(Self::protocol_loop(client.clone(), tx.clone()));
|
||||||
tokio::spawn(Self::game_tick_loop(client.clone(), tx.clone()));
|
tokio::spawn(Self::game_tick_loop(client.clone(), tx));
|
||||||
|
|
||||||
Ok((client, rx))
|
Ok((client, rx))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,20 +5,20 @@ use azalea_protocol::packets::game::serverbound_move_player_packet_pos_rot::Serv
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Set the client's position to the given coordinates.
|
/// Set the client's position to the given coordinates.
|
||||||
pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), String> {
|
pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), String> {
|
||||||
let mut dimension_lock = self.dimension.lock().unwrap();
|
{
|
||||||
let dimension = dimension_lock.as_mut().unwrap();
|
let mut dimension_lock = self.dimension.lock().unwrap();
|
||||||
|
let dimension = dimension_lock.as_mut().unwrap();
|
||||||
|
|
||||||
let player_lock = self.player.lock().unwrap();
|
let player_lock = self.player.lock().unwrap();
|
||||||
|
|
||||||
let player_id = if let Some(player_lock) = player_lock.entity(dimension) {
|
let player_id = if let Some(player_lock) = player_lock.entity(dimension) {
|
||||||
player_lock.id
|
player_lock.id
|
||||||
} else {
|
} else {
|
||||||
return Err("Player entity not found".to_string());
|
return Err("Player entity not found".to_string());
|
||||||
};
|
};
|
||||||
|
|
||||||
dimension.move_entity(player_id, new_pos)?;
|
dimension.move_entity(player_id, new_pos)?;
|
||||||
drop(dimension_lock);
|
}
|
||||||
drop(player_lock);
|
|
||||||
|
|
||||||
self.conn
|
self.conn
|
||||||
.lock()
|
.lock()
|
||||||
|
|
|
@ -182,9 +182,9 @@ impl From<ChunkSectionPos> for ChunkPos {
|
||||||
impl From<&BlockPos> for ChunkBlockPos {
|
impl From<&BlockPos> for ChunkBlockPos {
|
||||||
fn from(pos: &BlockPos) -> Self {
|
fn from(pos: &BlockPos) -> Self {
|
||||||
ChunkBlockPos {
|
ChunkBlockPos {
|
||||||
x: pos.x.rem_euclid(16).abs() as u8,
|
x: pos.x.rem_euclid(16).unsigned_abs() as u8,
|
||||||
y: pos.y,
|
y: pos.y,
|
||||||
z: pos.z.rem_euclid(16).abs() as u8,
|
z: pos.z.rem_euclid(16).unsigned_abs() as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,9 +192,9 @@ impl From<&BlockPos> for ChunkBlockPos {
|
||||||
impl From<&BlockPos> for ChunkSectionBlockPos {
|
impl From<&BlockPos> for ChunkSectionBlockPos {
|
||||||
fn from(pos: &BlockPos) -> Self {
|
fn from(pos: &BlockPos) -> Self {
|
||||||
ChunkSectionBlockPos {
|
ChunkSectionBlockPos {
|
||||||
x: pos.x.rem(16).abs() as u8,
|
x: pos.x.rem(16).unsigned_abs() as u8,
|
||||||
y: pos.y.rem(16).abs() as u8,
|
y: pos.y.rem(16).unsigned_abs() as u8,
|
||||||
z: pos.z.rem(16).abs() as u8,
|
z: pos.z.rem(16).unsigned_abs() as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ impl From<&ChunkBlockPos> for ChunkSectionBlockPos {
|
||||||
fn from(pos: &ChunkBlockPos) -> Self {
|
fn from(pos: &ChunkBlockPos) -> Self {
|
||||||
ChunkSectionBlockPos {
|
ChunkSectionBlockPos {
|
||||||
x: pos.x,
|
x: pos.x,
|
||||||
y: pos.y.rem(16).abs() as u8,
|
y: pos.y.rem(16).unsigned_abs() as u8,
|
||||||
z: pos.z,
|
z: pos.z,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,12 @@ impl McBufReadable for BlockStateWithPosition {
|
||||||
let data = u64::var_read_from(buf)?;
|
let data = u64::var_read_from(buf)?;
|
||||||
let position_part = data & 4095;
|
let position_part = data & 4095;
|
||||||
let state = (data >> 12) as u32;
|
let state = (data >> 12) as u32;
|
||||||
let position = ChunkSectionBlockPos {
|
let pos = ChunkSectionBlockPos {
|
||||||
x: (position_part >> 8 & 15) as u8,
|
x: (position_part >> 8 & 15) as u8,
|
||||||
y: (position_part >> 0 & 15) as u8,
|
y: (position_part & 15) as u8,
|
||||||
z: (position_part >> 4 & 15) as u8,
|
z: (position_part >> 4 & 15) as u8,
|
||||||
};
|
};
|
||||||
Ok(BlockStateWithPosition {
|
Ok(BlockStateWithPosition { pos, state })
|
||||||
pos: position,
|
|
||||||
state: state,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ impl ConnectionProtocol {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Packet {
|
pub enum Packet {
|
||||||
Game(game::GamePacket),
|
Game(Box<game::GamePacket>),
|
||||||
Handshake(handshake::HandshakePacket),
|
Handshake(Box<handshake::HandshakePacket>),
|
||||||
Login(login::LoginPacket),
|
Login(Box<login::LoginPacket>),
|
||||||
Status(Box<status::StatusPacket>),
|
Status(Box<status::StatusPacket>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let dimension = dimension_lock.as_ref().unwrap();
|
let dimension = dimension_lock.as_ref().unwrap();
|
||||||
let player = client.player.lock().unwrap();
|
let player = client.player.lock().unwrap();
|
||||||
let entity = player
|
let entity = player
|
||||||
.entity(&dimension)
|
.entity(dimension)
|
||||||
.expect("Player entity is not in world");
|
.expect("Player entity is not in world");
|
||||||
entity.pos().add_y(0.5)
|
entity.pos().add_y(0.5)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue