mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
fix clippy issues and improve formatting everywhere
This commit is contained in:
parent
a64c650504
commit
ae4b1e85e6
84 changed files with 425 additions and 378 deletions
|
@ -3,13 +3,14 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
path::PathBuf,
|
||||
time::{Instant, SystemTime, UNIX_EPOCH},
|
||||
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
use thiserror::Error;
|
||||
use tokio::time::sleep;
|
||||
use tracing::{error, trace};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -75,8 +76,9 @@ pub async fn auth(email: &str, opts: AuthOpts<'_>) -> Result<AuthResult, AuthErr
|
|||
None
|
||||
};
|
||||
|
||||
if cached_account.is_some() && !cached_account.as_ref().unwrap().mca.is_expired() {
|
||||
let account = cached_account.as_ref().unwrap();
|
||||
if let Some(account) = &cached_account
|
||||
&& !account.mca.is_expired()
|
||||
{
|
||||
// the minecraft auth data is cached and not expired, so we can just
|
||||
// use that instead of doing auth all over again :)
|
||||
|
||||
|
@ -129,8 +131,8 @@ pub async fn auth(email: &str, opts: AuthOpts<'_>) -> Result<AuthResult, AuthErr
|
|||
|
||||
let profile: ProfileResponse = get_profile(&client, &res.minecraft_access_token).await?;
|
||||
|
||||
if let Some(cache_file) = opts.cache_file {
|
||||
if let Err(e) = cache::set_account_in_cache(
|
||||
if let Some(cache_file) = opts.cache_file
|
||||
&& let Err(e) = cache::set_account_in_cache(
|
||||
&cache_file,
|
||||
email,
|
||||
CachedAccount {
|
||||
|
@ -142,9 +144,8 @@ pub async fn auth(email: &str, opts: AuthOpts<'_>) -> Result<AuthResult, AuthErr
|
|||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
error!("{}", e);
|
||||
}
|
||||
{
|
||||
error!("{}", e);
|
||||
}
|
||||
|
||||
Ok(AuthResult {
|
||||
|
@ -328,7 +329,7 @@ pub async fn get_ms_link_code(
|
|||
|
||||
Ok(client
|
||||
.post("https://login.live.com/oauth20_connect.srf")
|
||||
.form(&vec![
|
||||
.form(&[
|
||||
("scope", scope),
|
||||
("client_id", client_id),
|
||||
("response_type", "device_code"),
|
||||
|
@ -354,17 +355,17 @@ pub async fn get_ms_auth_token(
|
|||
CLIENT_ID
|
||||
};
|
||||
|
||||
let login_expires_at = Instant::now() + std::time::Duration::from_secs(res.expires_in);
|
||||
let login_expires_at = Instant::now() + Duration::from_secs(res.expires_in);
|
||||
|
||||
while Instant::now() < login_expires_at {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(res.interval)).await;
|
||||
sleep(Duration::from_secs(res.interval)).await;
|
||||
|
||||
trace!("Polling to check if user has logged in...");
|
||||
let res = client
|
||||
.post(format!(
|
||||
"https://login.live.com/oauth20_token.srf?client_id={client_id}"
|
||||
))
|
||||
.form(&vec![
|
||||
.form(&[
|
||||
("client_id", client_id),
|
||||
("device_code", &res.device_code),
|
||||
("grant_type", "urn:ietf:params:oauth:grant-type:device_code"),
|
||||
|
@ -375,8 +376,8 @@ pub async fn get_ms_auth_token(
|
|||
.await;
|
||||
if let Ok(access_token_response) = res {
|
||||
trace!("access_token_response: {:?}", access_token_response);
|
||||
let expires_at = SystemTime::now()
|
||||
+ std::time::Duration::from_secs(access_token_response.expires_in);
|
||||
let expires_at =
|
||||
SystemTime::now() + Duration::from_secs(access_token_response.expires_in);
|
||||
return Ok(ExpiringValue {
|
||||
data: access_token_response,
|
||||
expires_at: expires_at
|
||||
|
@ -428,7 +429,7 @@ pub async fn refresh_ms_auth_token(
|
|||
|
||||
let access_token_response_text = client
|
||||
.post("https://login.live.com/oauth20_token.srf")
|
||||
.form(&vec![
|
||||
.form(&[
|
||||
("scope", scope),
|
||||
("client_id", client_id),
|
||||
("grant_type", "refresh_token"),
|
||||
|
@ -441,8 +442,7 @@ pub async fn refresh_ms_auth_token(
|
|||
let access_token_response: AccessTokenResponse =
|
||||
serde_json::from_str(&access_token_response_text)?;
|
||||
|
||||
let expires_at =
|
||||
SystemTime::now() + std::time::Duration::from_secs(access_token_response.expires_in);
|
||||
let expires_at = SystemTime::now() + Duration::from_secs(access_token_response.expires_in);
|
||||
Ok(ExpiringValue {
|
||||
data: access_token_response,
|
||||
expires_at: expires_at
|
||||
|
@ -558,7 +558,7 @@ async fn auth_with_minecraft(
|
|||
.await?;
|
||||
trace!("{:?}", res);
|
||||
|
||||
let expires_at = SystemTime::now() + std::time::Duration::from_secs(res.expires_in);
|
||||
let expires_at = SystemTime::now() + Duration::from_secs(res.expires_in);
|
||||
Ok(ExpiringValue {
|
||||
data: res,
|
||||
// to seconds since epoch
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
//! Cache auth information
|
||||
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
use tokio::fs::File;
|
||||
use tokio::fs::{self, File};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tracing::{debug, trace};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CacheError {
|
||||
#[error("Failed to read cache file: {0}")]
|
||||
Read(std::io::Error),
|
||||
Read(io::Error),
|
||||
#[error("Failed to write cache file: {0}")]
|
||||
Write(std::io::Error),
|
||||
Write(io::Error),
|
||||
#[error("Failed to create cache file directory: {0}")]
|
||||
MkDir(std::io::Error),
|
||||
MkDir(io::Error),
|
||||
#[error("Failed to parse cache file: {0}")]
|
||||
Parse(serde_json::Error),
|
||||
}
|
||||
|
@ -94,7 +95,9 @@ async fn set_entire_cache(cache_file: &Path, cache: Vec<CachedAccount>) -> Resul
|
|||
"Making cache file parent directory at {}",
|
||||
cache_file_parent.to_string_lossy()
|
||||
);
|
||||
std::fs::create_dir_all(cache_file_parent).map_err(CacheError::MkDir)?;
|
||||
fs::create_dir_all(cache_file_parent)
|
||||
.await
|
||||
.map_err(CacheError::MkDir)?;
|
||||
}
|
||||
let mut cache_file = File::create(cache_file).await.map_err(CacheError::Write)?;
|
||||
let cache = serde_json::to_string_pretty(&cache).map_err(CacheError::Parse)?;
|
||||
|
|
|
@ -104,7 +104,7 @@ impl AzaleaRead for BlockState {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for BlockState {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u32::azalea_write_var(&(self.id as u32), buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::{fmt::Debug, sync::Arc};
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
|
@ -184,7 +187,7 @@ impl<S> ArgumentBuilder<S> {
|
|||
}
|
||||
|
||||
impl<S> Debug for ArgumentBuilder<S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ArgumentBuilder")
|
||||
.field("arguments", &self.arguments)
|
||||
// .field("command", &self.command)
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
use std::{any::Any, collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
|
||||
use std::{
|
||||
any::Any,
|
||||
collections::HashMap,
|
||||
fmt::{self, Debug},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
|
@ -40,7 +46,7 @@ impl<S> Clone for CommandContext<S> {
|
|||
}
|
||||
|
||||
impl<S> Debug for CommandContext<S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("CommandContext")
|
||||
// .field("source", &self.source)
|
||||
.field("input", &self.input)
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
use std::{collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{self, Debug},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use parking_lot::RwLock;
|
||||
|
||||
|
@ -140,7 +145,7 @@ impl<'a, S> CommandContextBuilder<'a, S> {
|
|||
}
|
||||
|
||||
impl<S> Debug for CommandContextBuilder<'_, S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("CommandContextBuilder")
|
||||
// .field("arguments", &self.arguments)
|
||||
.field("root", &self.root)
|
||||
|
|
|
@ -28,9 +28,7 @@ impl<S> ContextChain<S> {
|
|||
let child = current.child.clone();
|
||||
let Some(child) = child else {
|
||||
// Last entry must be executable command
|
||||
if current.command.is_none() {
|
||||
return None;
|
||||
}
|
||||
current.command.as_ref()?;
|
||||
|
||||
return Some(ContextChain::new(modifiers, current));
|
||||
};
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use std::{collections::HashMap, fmt::Debug, rc::Rc};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{self, Debug},
|
||||
rc::Rc,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
context::CommandContextBuilder, errors::CommandSyntaxError, string_reader::StringReader,
|
||||
|
@ -12,7 +16,7 @@ pub struct ParseResults<'a, S> {
|
|||
}
|
||||
|
||||
impl<S> Debug for ParseResults<'_, S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ParseResults")
|
||||
.field("context", &self.context)
|
||||
// .field("reader", &self.reader)
|
||||
|
|
|
@ -5,8 +5,10 @@ mod suggestions_builder;
|
|||
#[cfg(feature = "azalea-buf")]
|
||||
use std::io::Write;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
fmt::{self, Display},
|
||||
hash::Hash,
|
||||
io,
|
||||
};
|
||||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
|
@ -95,7 +97,7 @@ impl Suggestion {
|
|||
}
|
||||
|
||||
impl SuggestionValue {
|
||||
pub fn cmp_ignore_case(&self, other: &Self) -> std::cmp::Ordering {
|
||||
pub fn cmp_ignore_case(&self, other: &Self) -> Ordering {
|
||||
match (self, other) {
|
||||
(SuggestionValue::Text(a), SuggestionValue::Text(b)) => {
|
||||
a.to_lowercase().cmp(&b.to_lowercase())
|
||||
|
@ -120,7 +122,7 @@ impl Display for SuggestionValue {
|
|||
}
|
||||
|
||||
impl Ord for SuggestionValue {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
match (self, other) {
|
||||
(SuggestionValue::Text(a), SuggestionValue::Text(b)) => a.cmp(b),
|
||||
(SuggestionValue::Integer(a), SuggestionValue::Integer(b)) => a.cmp(b),
|
||||
|
@ -133,14 +135,14 @@ impl Ord for SuggestionValue {
|
|||
}
|
||||
}
|
||||
impl PartialOrd for SuggestionValue {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
impl AzaleaWrite for Suggestion {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.value.to_string().azalea_write(buf)?;
|
||||
self.tooltip
|
||||
.clone()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[cfg(feature = "azalea-buf")]
|
||||
use std::io::{Cursor, Write};
|
||||
use std::{collections::HashSet, hash::Hash};
|
||||
use std::{collections::HashSet, hash::Hash, io};
|
||||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
|
@ -107,7 +107,7 @@ impl AzaleaRead for Suggestions {
|
|||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
impl AzaleaWrite for Suggestions {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(self.range.start() as u32).azalea_write_var(buf)?;
|
||||
(self.range.length() as u32).azalea_write_var(buf)?;
|
||||
self.suggestions.azalea_write(buf)?;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
fmt::Debug,
|
||||
hash::Hash,
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
ptr,
|
||||
sync::Arc,
|
||||
};
|
||||
|
@ -236,7 +236,7 @@ impl<S> CommandNode<S> {
|
|||
}
|
||||
|
||||
impl<S> Debug for CommandNode<S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("CommandNode")
|
||||
// .field("value", &self.value)
|
||||
.field("children", &self.children)
|
||||
|
@ -268,7 +268,7 @@ impl<S> Default for CommandNode<S> {
|
|||
}
|
||||
|
||||
impl<S> Hash for CommandNode<S> {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// hash the children
|
||||
for (k, v) in &self.children {
|
||||
k.hash(state);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{ops::Deref, sync::Arc};
|
||||
use std::{mem, ops::Deref, sync::Arc};
|
||||
|
||||
use azalea_brigadier::prelude::*;
|
||||
use bevy_app::App;
|
||||
|
@ -172,7 +172,7 @@ impl WorldAccessor {
|
|||
|
||||
/// Swap the internal [`World`] with the given one.
|
||||
fn swap(&mut self, world: &mut World) {
|
||||
std::mem::swap(&mut *self.lock(), world);
|
||||
mem::swap(&mut *self.lock(), world);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ fn merge_single() {
|
|||
StringRange::at(5),
|
||||
vec![Suggestion::new(StringRange::at(5), "ar")],
|
||||
);
|
||||
let merged = Suggestions::merge("foo b", &[suggestions.clone()]);
|
||||
let merged = Suggestions::merge("foo b", std::slice::from_ref(&suggestions));
|
||||
assert_eq!(merged, suggestions);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{
|
|||
backtrace::Backtrace,
|
||||
collections::HashMap,
|
||||
hash::Hash,
|
||||
io::{Cursor, Read},
|
||||
io::{self, Cursor, Read},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub enum BufReadError {
|
|||
Io {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
source: std::io::Error,
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("Invalid UTF-8: {bytes:?} (lossy: {lossy:?})")]
|
||||
InvalidUtf8 {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl AzaleaRead for Uuid {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Uuid {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let [a, b, c, d] = self.to_int_array();
|
||||
a.azalea_write(buf)?;
|
||||
b.azalea_write(buf)?;
|
||||
|
|
|
@ -8,7 +8,7 @@ use byteorder::{BigEndian, WriteBytesExt};
|
|||
|
||||
use super::{MAX_STRING_LENGTH, UnsizedByteArray};
|
||||
|
||||
fn write_utf_with_len(buf: &mut impl Write, string: &str, len: usize) -> Result<(), io::Error> {
|
||||
fn write_utf_with_len(buf: &mut impl Write, string: &str, len: usize) -> io::Result<()> {
|
||||
if string.len() > len {
|
||||
panic!(
|
||||
"String too big (was {} bytes encoded, max {})",
|
||||
|
@ -21,21 +21,21 @@ fn write_utf_with_len(buf: &mut impl Write, string: &str, len: usize) -> Result<
|
|||
}
|
||||
|
||||
pub trait AzaleaWrite {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error>;
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub trait AzaleaWriteVar {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error>;
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()>;
|
||||
}
|
||||
|
||||
impl AzaleaWrite for i32 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_i32::<BigEndian>(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWriteVar for i32 {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut buffer = [0];
|
||||
let mut value = *self;
|
||||
if value == 0 {
|
||||
|
@ -54,24 +54,24 @@ impl AzaleaWriteVar for i32 {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for UnsizedByteArray {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
buf.write_all(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AzaleaWrite> AzaleaWrite for Vec<T> {
|
||||
default fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
default fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self[..].azalea_write(buf)
|
||||
}
|
||||
}
|
||||
impl<T: AzaleaWrite> AzaleaWrite for Box<[T]> {
|
||||
default fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
default fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self[..].azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AzaleaWrite> AzaleaWrite for [T] {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(self.len() as u32).azalea_write_var(buf)?;
|
||||
for item in self {
|
||||
T::azalea_write(item, buf)?;
|
||||
|
@ -81,7 +81,7 @@ impl<T: AzaleaWrite> AzaleaWrite for [T] {
|
|||
}
|
||||
|
||||
impl<K: AzaleaWrite, V: AzaleaWrite> AzaleaWrite for HashMap<K, V> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u32::azalea_write_var(&(self.len() as u32), buf)?;
|
||||
for (key, value) in self {
|
||||
key.azalea_write(buf)?;
|
||||
|
@ -93,7 +93,7 @@ impl<K: AzaleaWrite, V: AzaleaWrite> AzaleaWrite for HashMap<K, V> {
|
|||
}
|
||||
|
||||
impl<K: AzaleaWrite, V: AzaleaWriteVar> AzaleaWriteVar for HashMap<K, V> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u32::azalea_write_var(&(self.len() as u32), buf)?;
|
||||
for (key, value) in self {
|
||||
key.azalea_write(buf)?;
|
||||
|
@ -105,38 +105,38 @@ impl<K: AzaleaWrite, V: AzaleaWriteVar> AzaleaWriteVar for HashMap<K, V> {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Vec<u8> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(self.len() as u32).azalea_write_var(buf)?;
|
||||
buf.write_all(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for String {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
write_utf_with_len(buf, self, MAX_STRING_LENGTH.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for &str {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
write_utf_with_len(buf, self, MAX_STRING_LENGTH.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for u32 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i32::azalea_write(&(*self as i32), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWriteVar for u32 {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i32::azalea_write_var(&(*self as i32), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWriteVar for i64 {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut buffer = [0];
|
||||
let mut value = *self;
|
||||
if value == 0 {
|
||||
|
@ -155,25 +155,25 @@ impl AzaleaWriteVar for i64 {
|
|||
}
|
||||
|
||||
impl AzaleaWriteVar for u64 {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i64::azalea_write_var(&(*self as i64), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for u16 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i16::azalea_write(&(*self as i16), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWriteVar for u16 {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i32::azalea_write_var(&(*self as i32), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AzaleaWriteVar> AzaleaWriteVar for [T] {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u32::azalea_write_var(&(self.len() as u32), buf)?;
|
||||
for i in self {
|
||||
i.azalea_write_var(buf)?;
|
||||
|
@ -182,67 +182,67 @@ impl<T: AzaleaWriteVar> AzaleaWriteVar for [T] {
|
|||
}
|
||||
}
|
||||
impl<T: AzaleaWriteVar> AzaleaWriteVar for Vec<T> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self[..].azalea_write_var(buf)
|
||||
}
|
||||
}
|
||||
impl<T: AzaleaWriteVar> AzaleaWriteVar for Box<[T]> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self[..].azalea_write_var(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for u8 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_u8(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for i16 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_i16::<BigEndian>(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for i64 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_i64::<BigEndian>(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for u64 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
i64::azalea_write(&(*self as i64), buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for bool {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let byte = u8::from(*self);
|
||||
byte.azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for i8 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(*self as u8).azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for f32 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_f32::<BigEndian>(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl AzaleaWrite for f64 {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
WriteBytesExt::write_f64::<BigEndian>(buf, *self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AzaleaWrite> AzaleaWrite for Option<T> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
if let Some(s) = self {
|
||||
true.azalea_write(buf)?;
|
||||
s.azalea_write(buf)?;
|
||||
|
@ -254,7 +254,7 @@ impl<T: AzaleaWrite> AzaleaWrite for Option<T> {
|
|||
}
|
||||
|
||||
impl<T: AzaleaWriteVar> AzaleaWriteVar for Option<T> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
if let Some(s) = self {
|
||||
true.azalea_write(buf)?;
|
||||
s.azalea_write_var(buf)?;
|
||||
|
@ -267,7 +267,7 @@ impl<T: AzaleaWriteVar> AzaleaWriteVar for Option<T> {
|
|||
|
||||
// [T; N]
|
||||
impl<T: AzaleaWrite, const N: usize> AzaleaWrite for [T; N] {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
for i in self {
|
||||
i.azalea_write(buf)?;
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ impl<T: AzaleaWrite, const N: usize> AzaleaWrite for [T; N] {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for simdnbt::owned::NbtTag {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut data = Vec::new();
|
||||
self.write(&mut data);
|
||||
buf.write_all(&data)
|
||||
|
@ -284,7 +284,7 @@ impl AzaleaWrite for simdnbt::owned::NbtTag {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for simdnbt::owned::NbtCompound {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut data = Vec::new();
|
||||
simdnbt::owned::NbtTag::Compound(self.clone()).write(&mut data);
|
||||
buf.write_all(&data)
|
||||
|
@ -292,7 +292,7 @@ impl AzaleaWrite for simdnbt::owned::NbtCompound {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for simdnbt::owned::Nbt {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut data = Vec::new();
|
||||
self.write_unnamed(&mut data);
|
||||
buf.write_all(&data)
|
||||
|
@ -303,20 +303,20 @@ impl<T> AzaleaWrite for Box<T>
|
|||
where
|
||||
T: AzaleaWrite,
|
||||
{
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
T::azalea_write(&**self, buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AzaleaWrite, B: AzaleaWrite> AzaleaWrite for (A, B) {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.0.azalea_write(buf)?;
|
||||
self.1.azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AzaleaWrite> AzaleaWrite for Arc<T> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
T::azalea_write(&**self, buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use std::{fmt::Display, sync::LazyLock};
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
io::{self, Cursor, Write},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
|
@ -269,13 +273,12 @@ impl<'de> Deserialize<'de> for FormattedText {
|
|||
// string to with_array otherwise add the component
|
||||
// to the array
|
||||
let c = FormattedText::deserialize(item).map_err(de::Error::custom)?;
|
||||
if let FormattedText::Text(text_component) = c {
|
||||
if text_component.base.siblings.is_empty()
|
||||
&& text_component.base.style.is_empty()
|
||||
{
|
||||
with_array.push(StringOrComponent::String(text_component.text));
|
||||
continue;
|
||||
}
|
||||
if let FormattedText::Text(text_component) = c
|
||||
&& text_component.base.siblings.is_empty()
|
||||
&& text_component.base.style.is_empty()
|
||||
{
|
||||
with_array.push(StringOrComponent::String(text_component.text));
|
||||
continue;
|
||||
}
|
||||
with_array.push(StringOrComponent::FormattedText(
|
||||
FormattedText::deserialize(item).map_err(de::Error::custom)?,
|
||||
|
@ -465,13 +468,12 @@ impl FormattedText {
|
|||
with_array.push(StringOrComponent::String("?".to_string()));
|
||||
}
|
||||
} else if let Some(c) = FormattedText::from_nbt_compound(item) {
|
||||
if let FormattedText::Text(text_component) = c {
|
||||
if text_component.base.siblings.is_empty()
|
||||
&& text_component.base.style.is_empty()
|
||||
{
|
||||
with_array.push(StringOrComponent::String(text_component.text));
|
||||
continue;
|
||||
}
|
||||
if let FormattedText::Text(text_component) = c
|
||||
&& text_component.base.siblings.is_empty()
|
||||
&& text_component.base.style.is_empty()
|
||||
{
|
||||
with_array.push(StringOrComponent::String(text_component.text));
|
||||
continue;
|
||||
}
|
||||
with_array.push(StringOrComponent::FormattedText(
|
||||
FormattedText::from_nbt_compound(item)?,
|
||||
|
@ -547,7 +549,7 @@ impl From<&simdnbt::Mutf8Str> for FormattedText {
|
|||
#[cfg(feature = "azalea-buf")]
|
||||
#[cfg(feature = "simdnbt")]
|
||||
impl AzaleaRead for FormattedText {
|
||||
fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
let nbt = simdnbt::borrow::read_optional_tag(buf)?;
|
||||
match nbt {
|
||||
Some(nbt) => FormattedText::from_nbt_tag(nbt.as_tag()).ok_or(BufReadError::Custom(
|
||||
|
@ -561,7 +563,7 @@ impl AzaleaRead for FormattedText {
|
|||
#[cfg(feature = "azalea-buf")]
|
||||
#[cfg(feature = "simdnbt")]
|
||||
impl AzaleaWrite for FormattedText {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut out = Vec::new();
|
||||
simdnbt::owned::BaseNbt::write_unnamed(&(self.clone().to_compound().into()), &mut out);
|
||||
buf.write_all(&out)
|
||||
|
@ -583,7 +585,7 @@ impl From<&str> for FormattedText {
|
|||
}
|
||||
|
||||
impl Display for FormattedText {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
FormattedText::Text(c) => c.fmt(f),
|
||||
FormattedText::Translatable(c) => c.fmt(f),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Contains a few ways to style numbers. At the time of writing, Minecraft only
|
||||
//! uses this for rendering scoreboard objectives.
|
||||
|
||||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
|
@ -35,7 +35,7 @@ impl AzaleaRead for NumberFormat {
|
|||
|
||||
#[cfg(feature = "azalea-buf")]
|
||||
impl AzaleaWrite for NumberFormat {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
NumberFormat::Blank => NumberFormatKind::Blank.azalea_write(buf)?,
|
||||
NumberFormat::Styled { style } => {
|
||||
|
|
|
@ -595,29 +595,29 @@ impl Style {
|
|||
pub fn get_html_style(&self) -> String {
|
||||
let mut style = String::new();
|
||||
if let Some(color) = &self.color {
|
||||
style.push_str(&format!("color: {};", color.format_value()));
|
||||
style.push_str(&format!("color:{};", color.format_value()));
|
||||
}
|
||||
if let Some(bold) = self.bold {
|
||||
style.push_str(&format!(
|
||||
"font-weight: {};",
|
||||
"font-weight:{};",
|
||||
if bold { "bold" } else { "normal" }
|
||||
));
|
||||
}
|
||||
if let Some(italic) = self.italic {
|
||||
style.push_str(&format!(
|
||||
"font-style: {};",
|
||||
"font-style:{};",
|
||||
if italic { "italic" } else { "normal" }
|
||||
));
|
||||
}
|
||||
if let Some(underlined) = self.underlined {
|
||||
style.push_str(&format!(
|
||||
"text-decoration: {};",
|
||||
"text-decoration:{};",
|
||||
if underlined { "underline" } else { "none" }
|
||||
));
|
||||
}
|
||||
if let Some(strikethrough) = self.strikethrough {
|
||||
style.push_str(&format!(
|
||||
"text-decoration: {};",
|
||||
"text-decoration:{};",
|
||||
if strikethrough {
|
||||
"line-through"
|
||||
} else {
|
||||
|
@ -625,10 +625,10 @@ impl Style {
|
|||
}
|
||||
));
|
||||
}
|
||||
if let Some(obfuscated) = self.obfuscated {
|
||||
if obfuscated {
|
||||
style.push_str("filter: blur(2px);");
|
||||
}
|
||||
if let Some(obfuscated) = self.obfuscated
|
||||
&& obfuscated
|
||||
{
|
||||
style.push_str("filter:blur(2px);");
|
||||
}
|
||||
|
||||
style
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::fmt::Display;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
|
||||
|
||||
|
@ -142,7 +142,7 @@ impl TextComponent {
|
|||
}
|
||||
|
||||
impl Display for TextComponent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// this contains the final string will all the ansi escape codes
|
||||
for component in FormattedText::Text(self.clone()).into_iter() {
|
||||
let component_text = match &component {
|
||||
|
@ -191,9 +191,9 @@ mod tests {
|
|||
format!(
|
||||
"{GREEN}Hypixel Network {END_SPAN}{RED}[1.8-1.18]<br>{END_SPAN}{BOLD_AQUA}HAPPY HOLIDAYS{END_SPAN}",
|
||||
END_SPAN = "</span>",
|
||||
GREEN = "<span style=\"color: #55FF55;\">",
|
||||
RED = "<span style=\"color: #FF5555;\">",
|
||||
BOLD_AQUA = "<span style=\"color: #55FFFF;font-weight: bold;\">",
|
||||
GREEN = "<span style=\"color:#55FF55;\">",
|
||||
RED = "<span style=\"color:#FF5555;\">",
|
||||
BOLD_AQUA = "<span style=\"color:#55FFFF;font-weight: bold;\">",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -207,8 +207,8 @@ mod tests {
|
|||
format!(
|
||||
"{GREEN}<b>&<br>{END_SPAN}{AQUA}</b>{END_SPAN}",
|
||||
END_SPAN = "</span>",
|
||||
GREEN = "<span style=\"color: #55FF55;\">",
|
||||
AQUA = "<span style=\"color: #55FFFF;\">",
|
||||
GREEN = "<span style=\"color:#55FF55;\">",
|
||||
AQUA = "<span style=\"color:#55FFFF;\">",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::fmt::{self, Display, Formatter};
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use serde::{__private::ser::FlatMapSerializer, Serialize, Serializer, ser::SerializeMap};
|
||||
#[cfg(feature = "simdnbt")]
|
||||
|
@ -189,7 +189,7 @@ impl TranslatableComponent {
|
|||
}
|
||||
|
||||
impl Display for TranslatableComponent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// this contains the final string will all the ansi escape codes
|
||||
for component in FormattedText::Translatable(self.clone()).into_iter() {
|
||||
let component_text = match &component {
|
||||
|
@ -208,7 +208,7 @@ impl Display for TranslatableComponent {
|
|||
}
|
||||
|
||||
impl Display for StringOrComponent {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match self {
|
||||
StringOrComponent::String(s) => write!(f, "{s}"),
|
||||
StringOrComponent::FormattedText(c) => write!(f, "{c}"),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{any, sync::Arc};
|
||||
|
||||
use bevy_ecs::{
|
||||
component::Component,
|
||||
|
@ -29,7 +29,7 @@ impl Client {
|
|||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Our client is missing a required component {:?}",
|
||||
std::any::type_name::<D>()
|
||||
any::type_name::<D>()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ impl Client {
|
|||
let components = q.get(&ecs, entity).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Entity is missing a required component {:?}",
|
||||
std::any::type_name::<Q>()
|
||||
any::type_name::<Q>()
|
||||
)
|
||||
});
|
||||
components.clone()
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
use std::{collections::HashMap, io, sync::Arc};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error, io,
|
||||
sync::{Arc, PoisonError},
|
||||
};
|
||||
|
||||
use azalea_auth::game_profile::GameProfile;
|
||||
use azalea_core::game_type::GameMode;
|
||||
|
@ -169,13 +173,13 @@ pub enum HandlePacketError {
|
|||
#[error(transparent)]
|
||||
Io(#[from] io::Error),
|
||||
#[error(transparent)]
|
||||
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
|
||||
Other(#[from] Box<dyn error::Error + Send + Sync>),
|
||||
#[error("{0}")]
|
||||
Send(#[from] mpsc::error::SendError<AzaleaEvent>),
|
||||
}
|
||||
|
||||
impl<T> From<std::sync::PoisonError<T>> for HandlePacketError {
|
||||
fn from(e: std::sync::PoisonError<T>) -> Self {
|
||||
impl<T> From<PoisonError<T>> for HandlePacketError {
|
||||
fn from(e: PoisonError<T>) -> Self {
|
||||
HandlePacketError::Poison(e.to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,10 +102,10 @@ pub fn request_certs_if_needed(
|
|||
>,
|
||||
) {
|
||||
for (entity, account, only_refresh_certs_after, chat_signing_session) in query.iter_mut() {
|
||||
if let Some(only_refresh_certs_after) = only_refresh_certs_after {
|
||||
if only_refresh_certs_after.refresh_at > Instant::now() {
|
||||
continue;
|
||||
}
|
||||
if let Some(only_refresh_certs_after) = only_refresh_certs_after
|
||||
&& only_refresh_certs_after.refresh_at > Instant::now()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let certs = account.certs.lock();
|
||||
|
@ -124,20 +124,18 @@ pub fn request_certs_if_needed(
|
|||
};
|
||||
drop(certs);
|
||||
|
||||
if should_refresh {
|
||||
if let Some(access_token) = &account.access_token {
|
||||
let task_pool = IoTaskPool::get();
|
||||
if should_refresh && let Some(access_token) = &account.access_token {
|
||||
let task_pool = IoTaskPool::get();
|
||||
|
||||
let access_token = access_token.lock().clone();
|
||||
debug!("Started task to fetch certs");
|
||||
let task = task_pool.spawn(async_compat::Compat::new(async move {
|
||||
azalea_auth::certs::fetch_certificates(&access_token).await
|
||||
}));
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(RequestCertsTask(task))
|
||||
.remove::<OnlyRefreshCertsAfter>();
|
||||
}
|
||||
let access_token = access_token.lock().clone();
|
||||
debug!("Started task to fetch certs");
|
||||
let task = task_pool.spawn(async_compat::Compat::new(async move {
|
||||
azalea_auth::certs::fetch_certificates(&access_token).await
|
||||
}));
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(RequestCertsTask(task))
|
||||
.remove::<OnlyRefreshCertsAfter>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,14 +84,12 @@ pub fn handle_receive_chunk_events(
|
|||
let shared_chunk = instance.chunks.get(&pos);
|
||||
let this_client_has_chunk = partial_instance.chunks.limited_get(&pos).is_some();
|
||||
|
||||
if !this_client_has_chunk {
|
||||
if let Some(shared_chunk) = shared_chunk {
|
||||
trace!("Skipping parsing chunk {pos:?} because we already know about it");
|
||||
partial_instance
|
||||
.chunks
|
||||
.limited_set(&pos, Some(shared_chunk));
|
||||
continue;
|
||||
}
|
||||
if !this_client_has_chunk && let Some(shared_chunk) = shared_chunk {
|
||||
trace!("Skipping parsing chunk {pos:?} because we already know about it");
|
||||
partial_instance
|
||||
.chunks
|
||||
.limited_set(&pos, Some(shared_chunk));
|
||||
continue;
|
||||
}
|
||||
|
||||
let heightmaps = &event.packet.chunk_data.heightmaps;
|
||||
|
|
|
@ -170,17 +170,17 @@ impl Inventory {
|
|||
}
|
||||
if let QuickCraftStatus::Add { slot } = quick_craft.status {
|
||||
let slot_item = self.menu().slot(slot as usize);
|
||||
if let Some(slot_item) = slot_item {
|
||||
if let ItemStack::Present(carried) = &self.carried {
|
||||
// minecraft also checks slot.may_place(carried) and
|
||||
// menu.can_drag_to(slot)
|
||||
// but they always return true so they're not relevant for us
|
||||
if can_item_quick_replace(slot_item, &self.carried, true)
|
||||
&& (self.quick_craft_kind == QuickCraftKind::Right
|
||||
|| carried.count as usize > self.quick_craft_slots.len())
|
||||
{
|
||||
self.quick_craft_slots.insert(slot);
|
||||
}
|
||||
if let Some(slot_item) = slot_item
|
||||
&& let ItemStack::Present(carried) = &self.carried
|
||||
{
|
||||
// minecraft also checks slot.may_place(carried) and
|
||||
// menu.can_drag_to(slot)
|
||||
// but they always return true so they're not relevant for us
|
||||
if can_item_quick_replace(slot_item, &self.carried, true)
|
||||
&& (self.quick_craft_kind == QuickCraftKind::Right
|
||||
|| carried.count as usize > self.quick_craft_slots.len())
|
||||
{
|
||||
self.quick_craft_slots.insert(slot);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -468,26 +468,23 @@ impl Inventory {
|
|||
for i in iterator {
|
||||
if target_slot_item.count < target_slot_item.kind.max_stack_size() {
|
||||
let checking_slot = self.menu().slot(i).unwrap();
|
||||
if let ItemStack::Present(checking_item) = checking_slot {
|
||||
if can_item_quick_replace(checking_slot, &target_slot, true)
|
||||
&& self.menu().may_pickup(i)
|
||||
&& (round != 0
|
||||
|| checking_item.count
|
||||
!= checking_item.kind.max_stack_size())
|
||||
{
|
||||
// get the checking_slot and checking_item again but mutable
|
||||
let checking_slot = self.menu_mut().slot_mut(i).unwrap();
|
||||
if let ItemStack::Present(checking_item) = checking_slot
|
||||
&& can_item_quick_replace(checking_slot, &target_slot, true)
|
||||
&& self.menu().may_pickup(i)
|
||||
&& (round != 0
|
||||
|| checking_item.count != checking_item.kind.max_stack_size())
|
||||
{
|
||||
// get the checking_slot and checking_item again but mutable
|
||||
let checking_slot = self.menu_mut().slot_mut(i).unwrap();
|
||||
|
||||
let taken_item =
|
||||
checking_slot.split(checking_slot.count() as u32);
|
||||
let taken_item = checking_slot.split(checking_slot.count() as u32);
|
||||
|
||||
// now extend the carried item
|
||||
let target_slot = &mut self.carried;
|
||||
let ItemStack::Present(target_slot_item) = target_slot else {
|
||||
unreachable!("target slot is not empty but is not present");
|
||||
};
|
||||
target_slot_item.count += taken_item.count();
|
||||
}
|
||||
// now extend the carried item
|
||||
let target_slot = &mut self.carried;
|
||||
let ItemStack::Present(target_slot_item) = target_slot else {
|
||||
unreachable!("target slot is not empty but is not present");
|
||||
};
|
||||
target_slot_item.count += taken_item.count();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,20 +96,20 @@ pub fn handle_start_join_server_event(
|
|||
debug!("Reusing entity {entity:?} for client");
|
||||
|
||||
// check if it's already connected
|
||||
if let Ok(conn) = connection_query.get(entity) {
|
||||
if conn.is_alive() {
|
||||
if let Some(start_join_callback_tx) = &event.start_join_callback_tx {
|
||||
warn!(
|
||||
"Received StartJoinServerEvent for {entity:?} but it's already connected. Ignoring the event but replying with Ok."
|
||||
);
|
||||
let _ = start_join_callback_tx.0.send(Ok(entity));
|
||||
} else {
|
||||
warn!(
|
||||
"Received StartJoinServerEvent for {entity:?} but it's already connected. Ignoring the event."
|
||||
);
|
||||
}
|
||||
return;
|
||||
if let Ok(conn) = connection_query.get(entity)
|
||||
&& conn.is_alive()
|
||||
{
|
||||
if let Some(start_join_callback_tx) = &event.start_join_callback_tx {
|
||||
warn!(
|
||||
"Received StartJoinServerEvent for {entity:?} but it's already connected. Ignoring the event but replying with Ok."
|
||||
);
|
||||
let _ = start_join_callback_tx.0.send(Ok(entity));
|
||||
} else {
|
||||
warn!(
|
||||
"Received StartJoinServerEvent for {entity:?} but it's already connected. Ignoring the event."
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
entity
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::backtrace::Backtrace;
|
||||
use std::io;
|
||||
|
||||
use azalea_core::position::Vec3;
|
||||
use azalea_core::tick::GameTick;
|
||||
|
@ -28,7 +29,7 @@ pub enum MovePlayerError {
|
|||
#[error("Player is not in world")]
|
||||
PlayerNotInWorld(Backtrace),
|
||||
#[error("{0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
Io(#[from] io::Error),
|
||||
}
|
||||
|
||||
impl From<MoveEntityError> for MovePlayerError {
|
||||
|
|
|
@ -28,11 +28,11 @@ fn reply_to_ping_with_pong() {
|
|||
simulation
|
||||
.app
|
||||
.add_observer(move |trigger: Trigger<SendConfigPacketEvent>| {
|
||||
if trigger.sent_by == simulation.entity {
|
||||
if let ServerboundConfigPacket::Pong(packet) = &trigger.packet {
|
||||
assert_eq!(packet.id, 321);
|
||||
*reply_count_clone.lock() += 1;
|
||||
}
|
||||
if trigger.sent_by == simulation.entity
|
||||
&& let ServerboundConfigPacket::Pong(packet) = &trigger.packet
|
||||
{
|
||||
assert_eq!(packet.id, 321);
|
||||
*reply_count_clone.lock() += 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -63,11 +63,11 @@ fn reply_to_ping_with_pong() {
|
|||
simulation
|
||||
.app
|
||||
.add_observer(move |trigger: Trigger<SendPacketEvent>| {
|
||||
if trigger.sent_by == simulation.entity {
|
||||
if let ServerboundGamePacket::Pong(packet) = &trigger.packet {
|
||||
assert_eq!(packet.id, 123);
|
||||
*reply_count_clone.lock() += 1;
|
||||
}
|
||||
if trigger.sent_by == simulation.entity
|
||||
&& let ServerboundGamePacket::Pong(packet) = &trigger.packet
|
||||
{
|
||||
assert_eq!(packet.id, 123);
|
||||
*reply_count_clone.lock() += 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
|
||||
|
||||
|
@ -177,7 +177,7 @@ impl<const N: usize> AzaleaWrite for FixedBitSet<N>
|
|||
where
|
||||
[u8; bits_to_bytes(N)]: Sized,
|
||||
{
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
for i in 0..bits_to_bytes(N) {
|
||||
self.data[i].azalea_write(buf)?;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
fmt::{Debug, Error, Formatter},
|
||||
io::{Cursor, Write},
|
||||
fmt::{self, Debug},
|
||||
io::{self, Cursor, Write},
|
||||
};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
|
@ -18,7 +18,7 @@ pub enum Err {
|
|||
}
|
||||
|
||||
impl Debug for Err {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Err::InvalidDifficulty(s) => write!(f, "Invalid difficulty: {s}"),
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ impl AzaleaRead for Difficulty {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Difficulty {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u8::azalea_write(&self.id(), buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaReadLimited, AzaleaReadVar, AzaleaWrite};
|
||||
|
||||
|
@ -9,7 +9,7 @@ pub struct Filterable<T> {
|
|||
}
|
||||
|
||||
impl<T: AzaleaWrite> azalea_buf::AzaleaWrite for Filterable<T> {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.raw.azalea_write(buf)?;
|
||||
self.filtered.azalea_write(buf)?;
|
||||
Ok(())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, BufReadError};
|
||||
use azalea_chat::translatable_component::TranslatableComponent;
|
||||
|
@ -108,7 +108,7 @@ impl AzaleaRead for GameMode {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for GameMode {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u8::azalea_write(&self.to_id(), buf)
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ impl AzaleaRead for OptionalGameType {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for OptionalGameType {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
GameMode::to_optional_id(*self).azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
fmt::{self, Display, Formatter},
|
||||
fmt::{self, Display},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub enum ObjectiveCriteria {
|
|||
}
|
||||
|
||||
impl Display for ObjectiveCriteria {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
ObjectiveCriteria::Integer => write!(f, "integer"),
|
||||
ObjectiveCriteria::Hearts => write!(f, "hearts"),
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
//! The most common ones are [`Vec3`] and [`BlockPos`], which are usually used
|
||||
//! for entity positions and block positions, respectively.
|
||||
|
||||
use std::hash::Hasher;
|
||||
use std::io;
|
||||
use std::str::FromStr;
|
||||
use std::{
|
||||
fmt,
|
||||
|
@ -477,7 +479,7 @@ impl AzaleaRead for ChunkPos {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for ChunkPos {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
u64::from(*self).azalea_write(buf)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -485,7 +487,7 @@ impl AzaleaWrite for ChunkPos {
|
|||
|
||||
impl Hash for ChunkPos {
|
||||
#[inline]
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// optimized hash that only calls hash once
|
||||
u64::from(*self).hash(state);
|
||||
}
|
||||
|
@ -526,7 +528,7 @@ impl ChunkBlockPos {
|
|||
impl Hash for ChunkBlockPos {
|
||||
// optimized hash that only calls hash once
|
||||
#[inline]
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
u64::from(*self).hash(state);
|
||||
}
|
||||
}
|
||||
|
@ -570,7 +572,7 @@ impl Add<ChunkSectionBlockPos> for ChunkSectionPos {
|
|||
impl Hash for ChunkSectionBlockPos {
|
||||
// optimized hash that only calls hash once
|
||||
#[inline]
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
u16::from(*self).hash(state);
|
||||
}
|
||||
}
|
||||
|
@ -782,7 +784,7 @@ impl AzaleaRead for ChunkSectionPos {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for BlockPos {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut val: u64 = 0;
|
||||
val |= ((self.x as u64) & PACKED_X_MASK) << X_OFFSET;
|
||||
val |= (self.y as u64) & PACKED_Y_MASK;
|
||||
|
@ -792,7 +794,7 @@ impl AzaleaWrite for BlockPos {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for GlobalPos {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
ResourceLocation::azalea_write(&self.world, buf)?;
|
||||
BlockPos::azalea_write(&self.pos, buf)?;
|
||||
|
||||
|
@ -801,7 +803,7 @@ impl AzaleaWrite for GlobalPos {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ChunkSectionPos {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let long = (((self.x & 0x3FFFFF) as i64) << 42)
|
||||
| (self.y & 0xFFFFF) as i64
|
||||
| (((self.z & 0x3FFFFF) as i64) << 20);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{
|
||||
fmt,
|
||||
io::{Cursor, Write},
|
||||
io::{self, Cursor, Write},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
|
@ -67,7 +67,7 @@ impl AzaleaRead for ResourceLocation {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for ResourceLocation {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.to_string().azalea_write(buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Define some types needed for entity metadata.
|
||||
|
||||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
use azalea_chat::FormattedText;
|
||||
|
@ -43,7 +43,7 @@ impl AzaleaRead for EntityMetadataItems {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for EntityMetadataItems {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
for item in &self.0 {
|
||||
item.index.azalea_write(buf)?;
|
||||
item.value.azalea_write(buf)?;
|
||||
|
@ -128,7 +128,7 @@ impl AzaleaRead for OptionalUnsignedInt {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for OptionalUnsignedInt {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self.0 {
|
||||
Some(val) => (val + 1).azalea_write_var(buf),
|
||||
None => 0u32.azalea_write_var(buf),
|
||||
|
|
|
@ -12,7 +12,7 @@ mod plugin;
|
|||
pub mod vec_delta_codec;
|
||||
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
|
@ -133,7 +133,7 @@ impl EntityUuid {
|
|||
}
|
||||
}
|
||||
impl Debug for EntityUuid {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
(self.0).fmt(f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt::Debug,
|
||||
fmt::{self, Debug},
|
||||
};
|
||||
|
||||
use azalea_core::position::ChunkPos;
|
||||
|
@ -115,7 +115,7 @@ impl EntityIdIndex {
|
|||
}
|
||||
|
||||
impl Debug for EntityUuidIndex {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("EntityUuidIndex").finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
use core::f64;
|
||||
use std::{any::Any, collections::HashMap, io::Cursor};
|
||||
use std::{
|
||||
any::Any,
|
||||
collections::HashMap,
|
||||
io::{self, Cursor},
|
||||
};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_chat::FormattedText;
|
||||
|
@ -23,11 +27,11 @@ pub trait DataComponent: Send + Sync + Any {
|
|||
}
|
||||
|
||||
pub trait EncodableDataComponent: Send + Sync + Any {
|
||||
fn encode(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error>;
|
||||
fn encode(&self, buf: &mut Vec<u8>) -> io::Result<()>;
|
||||
// using the Clone trait makes it not be object-safe, so we have our own clone
|
||||
// function instead
|
||||
fn clone(&self) -> Box<dyn EncodableDataComponent>;
|
||||
// same deal here
|
||||
// same thing here
|
||||
fn eq(&self, other: Box<dyn EncodableDataComponent>) -> bool;
|
||||
}
|
||||
|
||||
|
@ -35,7 +39,7 @@ impl<T> EncodableDataComponent for T
|
|||
where
|
||||
T: DataComponent + Clone + AzaleaWrite + AzaleaRead + PartialEq,
|
||||
{
|
||||
fn encode(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
fn encode(&self, buf: &mut Vec<u8>) -> io::Result<()> {
|
||||
self.azalea_write(buf)
|
||||
}
|
||||
fn clone(&self) -> Box<dyn EncodableDataComponent> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
any::Any,
|
||||
fmt,
|
||||
io::{Cursor, Write},
|
||||
io::{self, Cursor, Write},
|
||||
};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
|
@ -73,10 +73,10 @@ impl ItemStack {
|
|||
|
||||
/// Update whether this slot is empty, based on the count.
|
||||
pub fn update_empty(&mut self) {
|
||||
if let ItemStack::Present(i) = self {
|
||||
if i.is_empty() {
|
||||
*self = ItemStack::Empty;
|
||||
}
|
||||
if let ItemStack::Present(i) = self
|
||||
&& i.is_empty()
|
||||
{
|
||||
*self = ItemStack::Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ impl AzaleaRead for ItemStack {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ItemStack {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
ItemStack::Empty => 0_i32.azalea_write_var(buf)?,
|
||||
ItemStack::Present(i) => {
|
||||
|
@ -256,7 +256,7 @@ impl AzaleaRead for DataComponentPatch {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for DataComponentPatch {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut components_with_data_count: u32 = 0;
|
||||
let mut components_without_data_count: u32 = 0;
|
||||
for component in self.components.values() {
|
||||
|
|
|
@ -151,12 +151,11 @@ fn clip_with_interaction_override(
|
|||
// compostors, hoppers, and scaffolding.
|
||||
let interaction_shape = &*EMPTY_SHAPE;
|
||||
let interaction_hit_result = interaction_shape.clip(from, to, block_pos);
|
||||
if let Some(interaction_hit_result) = interaction_hit_result {
|
||||
if interaction_hit_result.location.distance_squared_to(from)
|
||||
if let Some(interaction_hit_result) = interaction_hit_result
|
||||
&& interaction_hit_result.location.distance_squared_to(from)
|
||||
< block_hit_result.location.distance_squared_to(from)
|
||||
{
|
||||
return Some(block_hit_result.with_direction(interaction_hit_result.direction));
|
||||
}
|
||||
{
|
||||
return Some(block_hit_result.with_direction(interaction_hit_result.direction));
|
||||
}
|
||||
|
||||
Some(block_hit_result)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::cmp;
|
||||
|
||||
use azalea_core::{
|
||||
bitset::BitSet,
|
||||
direction::{Axis, AxisCycle},
|
||||
|
@ -146,12 +148,12 @@ impl BitSetDiscreteVoxelShape {
|
|||
fn fill_update_bounds(&mut self, x: u32, y: u32, z: u32, update: bool) {
|
||||
self.storage.set(self.get_index(x, y, z));
|
||||
if update {
|
||||
self.x_min = std::cmp::min(self.x_min, x as i32);
|
||||
self.y_min = std::cmp::min(self.y_min, y as i32);
|
||||
self.z_min = std::cmp::min(self.z_min, z as i32);
|
||||
self.x_max = std::cmp::max(self.x_max, (x + 1) as i32);
|
||||
self.y_max = std::cmp::max(self.y_max, (y + 1) as i32);
|
||||
self.z_max = std::cmp::max(self.z_max, (z + 1) as i32);
|
||||
self.x_min = cmp::min(self.x_min, x as i32);
|
||||
self.y_min = cmp::min(self.y_min, y as i32);
|
||||
self.z_min = cmp::min(self.z_min, z as i32);
|
||||
self.x_max = cmp::max(self.x_max, (x + 1) as i32);
|
||||
self.y_max = cmp::max(self.y_max, (y + 1) as i32);
|
||||
self.z_max = cmp::max(self.z_max, (z + 1) as i32);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,24 +203,24 @@ impl BitSetDiscreteVoxelShape {
|
|||
var12.try_into().unwrap(),
|
||||
var14.try_into().unwrap(),
|
||||
));
|
||||
var7[2] = std::cmp::min(var7[2], var14);
|
||||
var7[5] = std::cmp::max(var7[5], var14);
|
||||
var7[2] = cmp::min(var7[2], var14);
|
||||
var7[5] = cmp::max(var7[5], var14);
|
||||
var13[0] = true;
|
||||
}
|
||||
|
||||
true
|
||||
});
|
||||
if var13[0] {
|
||||
var7[1] = std::cmp::min(var7[1], var12);
|
||||
var7[4] = std::cmp::max(var7[4], var12);
|
||||
var7[1] = cmp::min(var7[1], var12);
|
||||
var7[4] = cmp::max(var7[4], var12);
|
||||
var10[0] = true;
|
||||
}
|
||||
|
||||
true
|
||||
});
|
||||
if var10[0] {
|
||||
var7[0] = std::cmp::min(var7[0], var9);
|
||||
var7[3] = std::cmp::max(var7[3], var9);
|
||||
var7[0] = cmp::min(var7[0], var9);
|
||||
var7[3] = cmp::max(var7[3], var9);
|
||||
}
|
||||
|
||||
true
|
||||
|
|
|
@ -23,7 +23,7 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
|
|||
|
||||
let contents = quote! {
|
||||
impl #ident {
|
||||
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
pub fn write(&self, buf: &mut impl std::io::Write) -> std::io::Result<()> {
|
||||
azalea_buf::AzaleaWrite::azalea_write(self, buf)
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> std::io::Result<()> {
|
||||
match self {
|
||||
#serverbound_write_match_contents
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn write(&self, buf: &mut impl std::io::Write) -> std::io::Result<()> {
|
||||
match self {
|
||||
#clientbound_write_match_contents
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::io::{self, Cursor};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
|
||||
use azalea_core::bitset::FixedBitSet;
|
||||
use bevy_ecs::component::Component;
|
||||
|
@ -96,7 +98,7 @@ impl Default for ModelCustomization {
|
|||
}
|
||||
|
||||
impl AzaleaRead for ModelCustomization {
|
||||
fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
|
||||
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
|
||||
let set = FixedBitSet::<7>::azalea_read(buf)?;
|
||||
Ok(Self {
|
||||
cape: set.index(0),
|
||||
|
@ -111,7 +113,7 @@ impl AzaleaRead for ModelCustomization {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ModelCustomization {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl io::Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<7>::new();
|
||||
if self.cape {
|
||||
set.set(0);
|
||||
|
|
|
@ -48,7 +48,7 @@ impl AzaleaRead for RelativeMovements {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for RelativeMovements {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<32>::new();
|
||||
let mut set_bit = |index: usize, value: bool| {
|
||||
if value {
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
// this is necessary for thiserror backtraces
|
||||
#![feature(error_generic_member_access)]
|
||||
|
||||
use std::{fmt::Display, net::SocketAddr, str::FromStr};
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
net::SocketAddr,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
pub mod common;
|
||||
#[cfg(feature = "connecting")]
|
||||
|
@ -79,7 +83,7 @@ impl From<SocketAddr> for ServerAddress {
|
|||
}
|
||||
|
||||
impl Display for ServerAddress {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.host, self.port)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor};
|
||||
use std::ops::Deref;
|
||||
use std::{collections::HashMap, io::Write};
|
||||
|
||||
|
@ -40,7 +40,7 @@ impl AzaleaRead for TagMap {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for TagMap {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(self.len() as u32).azalea_write_var(buf)?;
|
||||
for (k, v) in &self.0 {
|
||||
k.azalea_write(buf)?;
|
||||
|
@ -58,7 +58,7 @@ impl AzaleaRead for Tags {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Tags {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.name.azalea_write(buf)?;
|
||||
self.elements.azalea_write_var(buf)?;
|
||||
Ok(())
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::io;
|
||||
use std::io::Cursor;
|
||||
use std::io::Write;
|
||||
|
||||
|
@ -43,7 +44,7 @@ impl AzaleaRead for Operation {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Operation {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
Operation::Add(add) => {
|
||||
0u32.azalea_write_var(buf)?;
|
||||
|
@ -126,7 +127,7 @@ impl AzaleaRead for Properties {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Properties {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<3>::new();
|
||||
if self.darken_screen {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation};
|
||||
|
@ -61,7 +61,7 @@ impl<T: AzaleaRead> AzaleaRead for BrigadierNumber<T> {
|
|||
}
|
||||
}
|
||||
impl<T: AzaleaWrite> AzaleaWrite for BrigadierNumber<T> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut flags = FixedBitSet::<2>::new();
|
||||
if self.min.is_some() {
|
||||
flags.set(0);
|
||||
|
@ -166,7 +166,7 @@ impl AzaleaRead for EntityParser {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for EntityParser {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut flags = FixedBitSet::<2>::new();
|
||||
if self.single {
|
||||
flags.set(0);
|
||||
|
@ -242,7 +242,7 @@ impl AzaleaRead for BrigadierNodeStub {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for BrigadierNodeStub {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut flags = FixedBitSet::<4>::new();
|
||||
if self.is_executable {
|
||||
flags.set(2);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar};
|
||||
use azalea_core::position::Vec3;
|
||||
|
@ -27,7 +27,7 @@ impl AzaleaRead for OptionalEntityId {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for OptionalEntityId {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self.0 {
|
||||
Some(id) => (id + 1).azalea_write_var(buf),
|
||||
None => 0u32.azalea_write_var(buf),
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
|
||||
use azalea_chat::FormattedText;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
@ -27,7 +29,7 @@ pub struct MapDecoration {
|
|||
pub struct OptionalMapPatch(pub Option<MapPatch>);
|
||||
|
||||
impl AzaleaRead for OptionalMapPatch {
|
||||
fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
|
||||
fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result<Self, azalea_buf::BufReadError> {
|
||||
let pos = buf.position();
|
||||
Ok(Self(if u8::azalea_read(buf)? == 0 {
|
||||
None
|
||||
|
@ -39,7 +41,7 @@ impl AzaleaRead for OptionalMapPatch {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for OptionalMapPatch {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match &self.0 {
|
||||
None => 0u8.azalea_write(buf),
|
||||
Some(m) => m.azalea_write(buf),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, BufReadError};
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
|
@ -34,7 +34,7 @@ impl AzaleaRead for PlayerAbilitiesFlags {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for PlayerAbilitiesFlags {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<4>::new();
|
||||
if self.invulnerable {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
use azalea_chat::{
|
||||
|
@ -142,7 +142,7 @@ impl AzaleaRead for PackedMessageSignature {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for PackedMessageSignature {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
PackedMessageSignature::Signature(full_signature) => {
|
||||
0u32.azalea_write_var(buf)?;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
io::{Cursor, Write},
|
||||
io::{self, Cursor, Write},
|
||||
};
|
||||
|
||||
use azalea_auth::game_profile::{GameProfile, ProfilePropertyValue};
|
||||
|
@ -119,7 +119,7 @@ impl AzaleaRead for ClientboundPlayerInfoUpdate {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ClientboundPlayerInfoUpdate {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.actions.azalea_write(buf)?;
|
||||
|
||||
(self.entries.len() as u32).azalea_write_var(buf)?;
|
||||
|
@ -198,7 +198,7 @@ impl AzaleaRead for ActionEnumSet {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ActionEnumSet {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<7>::new();
|
||||
if self.add_player {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_block::BlockState;
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
|
@ -34,7 +34,7 @@ impl AzaleaRead for BlockStateWithPosition {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for BlockStateWithPosition {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let data = ((self.state.id() as u64) << 12)
|
||||
| ((u64::from(self.pos.x) << 8) | (u64::from(self.pos.z) << 4) | u64::from(self.pos.y));
|
||||
u64::azalea_write_var(&data, buf)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, BufReadError};
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
|
@ -41,7 +41,7 @@ impl AzaleaRead for EquipmentSlots {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for EquipmentSlots {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
for i in 0..self.slots.len() {
|
||||
let (equipment_slot, item) = &self.slots[i];
|
||||
let mut equipment_byte = *equipment_slot as u8;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
|
||||
use azalea_chat::{numbers::NumberFormat, FormattedText};
|
||||
use azalea_chat::{FormattedText, numbers::NumberFormat};
|
||||
use azalea_core::objectives::ObjectiveCriteria;
|
||||
use azalea_protocol_macros::ClientboundGamePacket;
|
||||
|
||||
|
@ -53,7 +53,7 @@ impl AzaleaRead for Method {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Method {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
Method::Add {
|
||||
display_name,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation};
|
||||
|
@ -31,7 +31,7 @@ impl AzaleaRead for ClientboundStopSound {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ClientboundStopSound {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<2>::new();
|
||||
if self.source.is_some() {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::AzBuf;
|
||||
use azalea_chat::FormattedText;
|
||||
|
@ -38,7 +38,7 @@ pub struct DisplayInfo {
|
|||
}
|
||||
|
||||
impl azalea_buf::AzaleaWrite for DisplayInfo {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.title.azalea_write(buf)?;
|
||||
self.description.azalea_write(buf)?;
|
||||
self.icon.azalea_write(buf)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor};
|
||||
use std::ops::Deref;
|
||||
use std::{collections::HashMap, io::Write};
|
||||
|
||||
|
@ -40,7 +40,7 @@ impl AzaleaRead for TagMap {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for TagMap {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(self.len() as u32).azalea_write_var(buf)?;
|
||||
for (k, v) in &self.0 {
|
||||
k.azalea_write(buf)?;
|
||||
|
@ -58,7 +58,7 @@ impl AzaleaRead for Tags {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Tags {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.name.azalea_write(buf)?;
|
||||
self.elements.azalea_write_var(buf)?;
|
||||
Ok(())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar};
|
||||
use azalea_core::position::Vec3;
|
||||
|
@ -29,7 +29,7 @@ pub enum ActionType {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ActionType {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
ActionType::Interact { hand } => {
|
||||
0u32.azalea_write_var(buf)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
use azalea_core::bitset::FixedBitSet;
|
||||
|
@ -21,7 +21,7 @@ impl AzaleaRead for ServerboundPlayerAbilities {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ServerboundPlayerAbilities {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<2>::new();
|
||||
if self.is_flying {
|
||||
set.set(1);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::BufReadError;
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
|
@ -32,7 +32,7 @@ impl AzaleaRead for ServerboundPlayerInput {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ServerboundPlayerInput {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<7>::new();
|
||||
if self.forward {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite};
|
||||
use azalea_core::resource_location::ResourceLocation;
|
||||
|
@ -31,7 +31,7 @@ impl AzaleaRead for ServerboundSeenAdvancements {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ServerboundSeenAdvancements {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.action.azalea_write(buf)?;
|
||||
if let Some(tab) = &self.tab {
|
||||
tab.azalea_write(buf)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::Cursor;
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, BufReadError};
|
||||
use azalea_core::{bitset::FixedBitSet, position::BlockPos};
|
||||
|
@ -43,7 +43,7 @@ impl AzaleaRead for ServerboundSetCommandBlock {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ServerboundSetCommandBlock {
|
||||
fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.pos.azalea_write(buf)?;
|
||||
self.command.azalea_write(buf)?;
|
||||
self.mode.azalea_write(buf)?;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use std::io;
|
||||
use std::io::Cursor;
|
||||
use std::io::Write;
|
||||
|
||||
|
@ -41,7 +42,7 @@ impl AzaleaRead for JointType {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for JointType {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
JointType::Rollable => "rollable".to_string().azalea_write(buf)?,
|
||||
JointType::Aligned => "aligned".to_string().azalea_write(buf)?,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::AzBuf;
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite};
|
||||
|
@ -83,7 +83,7 @@ impl AzaleaRead for Flags {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Flags {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let mut set = FixedBitSet::<3>::new();
|
||||
if self.ignore_entities {
|
||||
set.set(0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_core::{
|
||||
|
@ -35,7 +35,7 @@ pub struct BlockHit {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for BlockHit {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.block_pos.azalea_write(buf)?;
|
||||
self.direction.azalea_write(buf)?;
|
||||
f32::azalea_write(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_chat::FormattedText;
|
||||
|
@ -21,7 +21,7 @@ impl AzaleaRead for ClientboundLoginDisconnect {
|
|||
Err(err) => {
|
||||
return Err(BufReadError::Custom(format!(
|
||||
"Failed to deserialize disconnect JSON {disconnect_string:?}: {err}"
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl AzaleaRead for ClientboundLoginDisconnect {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ClientboundLoginDisconnect {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let status_string = FormattedText::serialize(&self.reason, serde_json::value::Serializer)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
|
|
@ -5,7 +5,7 @@ pub mod handshake;
|
|||
pub mod login;
|
||||
pub mod status;
|
||||
|
||||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
|
||||
|
||||
|
@ -53,7 +53,7 @@ where
|
|||
/// Read a packet by its id, `ConnectionProtocol`, and flow
|
||||
fn read(id: u32, buf: &mut Cursor<&[u8]>) -> Result<Self, Box<ReadPacketError>>;
|
||||
|
||||
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
|
||||
fn write(&self, buf: &mut impl Write) -> io::Result<()>;
|
||||
}
|
||||
|
||||
pub trait Packet<Protocol> {
|
||||
|
@ -98,7 +98,7 @@ impl azalea_buf::AzaleaRead for ClientIntention {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ClientIntention {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
(*self as i32).azalea_write_var(buf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
use azalea_chat::FormattedText;
|
||||
|
@ -51,7 +51,7 @@ impl AzaleaRead for ClientboundStatusResponse {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for ClientboundStatusResponse {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
let status_string = ClientboundStatusResponse::serialize(self, Serializer)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//! Read packets from a stream.
|
||||
|
||||
use std::backtrace::Backtrace;
|
||||
use std::env;
|
||||
use std::sync::LazyLock;
|
||||
use std::{env, io};
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
io::{Cursor, Read},
|
||||
|
@ -53,7 +53,7 @@ pub enum ReadPacketError {
|
|||
IoError {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
source: std::io::Error,
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("Connection closed")]
|
||||
ConnectionClosed,
|
||||
|
@ -70,7 +70,7 @@ pub enum FrameSplitterError {
|
|||
Io {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
source: std::io::Error,
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("Packet is longer than {max} bytes (is {size})")]
|
||||
BadLength { max: usize, size: usize },
|
||||
|
@ -171,7 +171,7 @@ pub enum DecompressionError {
|
|||
Io {
|
||||
#[from]
|
||||
#[backtrace]
|
||||
source: std::io::Error,
|
||||
source: io::Error,
|
||||
},
|
||||
#[error("Badly compressed packet - size of {size} is below server threshold of {threshold}")]
|
||||
BelowCompressionThreshold { size: u32, threshold: u32 },
|
||||
|
|
|
@ -42,7 +42,7 @@ impl<T: Registry> AzaleaRead for OptionalRegistry<T> {
|
|||
}
|
||||
}
|
||||
impl<T: Registry> AzaleaWrite for OptionalRegistry<T> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match &self.0 {
|
||||
None => 0u32.azalea_write_var(buf),
|
||||
Some(value) => (value.to_u32() + 1).azalea_write_var(buf),
|
||||
|
@ -67,7 +67,7 @@ impl<D: Registry, C: AzaleaRead + AzaleaWrite> AzaleaRead for CustomRegistry<D,
|
|||
}
|
||||
}
|
||||
impl<D: Registry, C: AzaleaRead + AzaleaWrite> AzaleaWrite for CustomRegistry<D, C> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
CustomRegistry::Direct(direct_registry) => {
|
||||
// write the id + 1
|
||||
|
@ -115,7 +115,7 @@ impl<D: Registry, ResourceLocation: AzaleaRead + AzaleaWrite> AzaleaRead
|
|||
impl<D: Registry, ResourceLocation: AzaleaRead + AzaleaWrite> AzaleaWrite
|
||||
for HolderSet<D, ResourceLocation>
|
||||
{
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
Self::Direct { contents } => {
|
||||
(contents.len() as i32 + 1).azalea_write_var(buf)?;
|
||||
|
@ -167,7 +167,7 @@ impl<R: Registry, Direct: AzaleaRead + AzaleaWrite> AzaleaRead for Holder<R, Dir
|
|||
}
|
||||
}
|
||||
impl<R: Registry, Direct: AzaleaRead + AzaleaWrite> AzaleaWrite for Holder<R, Direct> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
Self::Reference(value) => (value.to_u32() + 1).azalea_write_var(buf),
|
||||
Self::Direct(value) => {
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
io::{Cursor, Write},
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
use std::{fmt, io};
|
||||
|
||||
use azalea_block::block_state::{BlockState, BlockStateIntegerRepr};
|
||||
use azalea_block::fluid_state::FluidState;
|
||||
|
@ -414,7 +415,7 @@ pub fn get_block_state_from_sections(
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Chunk {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
for section in &self.sections {
|
||||
section.azalea_write(buf)?;
|
||||
}
|
||||
|
@ -423,7 +424,7 @@ impl AzaleaWrite for Chunk {
|
|||
}
|
||||
|
||||
impl Debug for PartialChunkStorage {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("PartialChunkStorage")
|
||||
.field("view_center", &self.view_center)
|
||||
.field("chunk_radius", &self.chunk_radius)
|
||||
|
@ -466,7 +467,7 @@ impl AzaleaRead for Section {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Section {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.block_count.azalea_write(buf)?;
|
||||
self.states.azalea_write(buf)?;
|
||||
self.biomes.azalea_write(buf)?;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::{fmt::Display, str::FromStr};
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use azalea_block::BlockState;
|
||||
use azalea_buf::AzBuf;
|
||||
|
@ -161,7 +164,7 @@ impl FromStr for HeightmapKind {
|
|||
}
|
||||
|
||||
impl Display for HeightmapKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
HeightmapKind::WorldSurfaceWg => write!(f, "WORLD_SURFACE_WG"),
|
||||
HeightmapKind::WorldSurface => write!(f, "WORLD_SURFACE"),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{Cursor, Write};
|
||||
use std::io::{self, Cursor, Write};
|
||||
|
||||
use azalea_block::BlockState;
|
||||
use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError};
|
||||
|
@ -232,7 +232,7 @@ impl PalettedContainer {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for PalettedContainer {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
self.bits_per_entry.azalea_write(buf)?;
|
||||
self.palette.azalea_write(buf)?;
|
||||
self.storage.data.azalea_write(buf)?;
|
||||
|
@ -272,7 +272,7 @@ impl Palette {
|
|||
}
|
||||
|
||||
impl AzaleaWrite for Palette {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl Write) -> io::Result<()> {
|
||||
match self {
|
||||
Palette::SingleValue(value) => {
|
||||
value.azalea_write(buf)?;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::fmt::{self, Display, Formatter};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::io::{self, Cursor};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt::Debug,
|
||||
fmt::{self, Display},
|
||||
hash::{Hash, Hasher},
|
||||
io::{self, Cursor},
|
||||
};
|
||||
|
||||
use azalea_block::BlockState;
|
||||
|
@ -84,7 +84,7 @@ impl AzaleaRead for MinecraftEntityId {
|
|||
}
|
||||
}
|
||||
impl AzaleaWrite for MinecraftEntityId {
|
||||
fn azalea_write(&self, buf: &mut impl io::Write) -> Result<(), io::Error> {
|
||||
fn azalea_write(&self, buf: &mut impl io::Write) -> io::Result<()> {
|
||||
i32::azalea_write(&self.0, buf)
|
||||
}
|
||||
}
|
||||
|
@ -94,12 +94,12 @@ impl AzaleaReadVar for MinecraftEntityId {
|
|||
}
|
||||
}
|
||||
impl AzaleaWriteVar for MinecraftEntityId {
|
||||
fn azalea_write_var(&self, buf: &mut impl io::Write) -> Result<(), io::Error> {
|
||||
fn azalea_write_var(&self, buf: &mut impl io::Write) -> io::Result<()> {
|
||||
i32::azalea_write_var(&self.0, buf)
|
||||
}
|
||||
}
|
||||
impl Display for MinecraftEntityId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "eid({})", self.0)
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ impl Instance {
|
|||
}
|
||||
|
||||
impl Debug for PartialInstance {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("PartialInstance")
|
||||
.field("chunks", &self.chunks)
|
||||
.field("entity_infos", &self.entity_infos)
|
||||
|
|
|
@ -18,13 +18,14 @@ async fn main() {
|
|||
pub struct State {}
|
||||
|
||||
async fn handle(bot: Client, event: Event, _state: State) -> anyhow::Result<()> {
|
||||
if let Event::Chat(m) = event {
|
||||
if let (Some(sender), content) = m.split_sender_and_content() {
|
||||
if sender == bot.username() {
|
||||
return Ok(()); // ignore our own messages
|
||||
}
|
||||
bot.chat(&content);
|
||||
};
|
||||
if let Event::Chat(m) = event
|
||||
&& let (Some(sender), content) = m.split_sender_and_content()
|
||||
{
|
||||
if sender == bot.username() {
|
||||
// ignore our own messages
|
||||
return Ok(());
|
||||
}
|
||||
bot.chat(&content);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Commands for debugging and getting the current state of the bot.
|
||||
|
||||
use std::{env, fs::File, io::Write, thread, time::Duration};
|
||||
use std::{env, fs::File, io::Write, process, thread, time::Duration};
|
||||
|
||||
use azalea::{
|
||||
BlockPos,
|
||||
|
@ -288,7 +288,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
|
|||
thread::spawn(move || {
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
|
||||
std::process::exit(0);
|
||||
process::exit(0);
|
||||
});
|
||||
|
||||
1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::fmt::Formatter;
|
||||
|
||||
use azalea_client::packet::game::ReceiveGamePacketEvent;
|
||||
use azalea_client::{
|
||||
|
@ -121,7 +121,7 @@ pub struct ContainerHandleRef {
|
|||
client: Client,
|
||||
}
|
||||
impl Debug for ContainerHandleRef {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ContainerHandle")
|
||||
.field("id", &self.id())
|
||||
.finish()
|
||||
|
@ -192,7 +192,7 @@ impl Drop for ContainerHandle {
|
|||
}
|
||||
}
|
||||
impl Debug for ContainerHandle {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ContainerHandle")
|
||||
.field("id", &self.id())
|
||||
.finish()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::{
|
||||
cmp::{self},
|
||||
collections::BinaryHeap,
|
||||
fmt::Debug,
|
||||
fmt::{self, Debug},
|
||||
hash::{BuildHasherDefault, Hash},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
@ -251,7 +251,7 @@ pub struct Movement<P: Hash + Copy, M> {
|
|||
}
|
||||
|
||||
impl<P: Hash + Copy + Debug, M: Debug> Debug for Movement<P, M> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Movement")
|
||||
.field("target", &self.target)
|
||||
.field("data", &self.data)
|
||||
|
|
|
@ -1189,6 +1189,7 @@ mod tests {
|
|||
use std::{
|
||||
collections::HashSet,
|
||||
sync::Arc,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
|
@ -1270,7 +1271,7 @@ mod tests {
|
|||
&& start_time.elapsed() < Duration::from_millis(500)
|
||||
{
|
||||
simulation.tick();
|
||||
std::thread::yield_now();
|
||||
thread::yield_now();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
pub mod basic;
|
||||
pub mod parkour;
|
||||
|
||||
use std::{fmt::Debug, sync::Arc};
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use azalea_block::BlockState;
|
||||
use azalea_client::{
|
||||
|
@ -40,7 +43,7 @@ pub struct MoveData {
|
|||
pub is_reached: &'static (dyn Fn(IsReachedCtx) -> bool + Send + Sync),
|
||||
}
|
||||
impl Debug for MoveData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("MoveData")
|
||||
// .field("move_kind", &self.move_kind)
|
||||
.finish()
|
||||
|
|
Loading…
Add table
Reference in a new issue