Fix: Clippy & fmt
This commit is contained in:
parent
b7a4b9da2c
commit
49dfc18818
@ -12,18 +12,6 @@ pub struct PlayerInventory {
|
|||||||
selected: usize,
|
selected: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Hotbar<'a>(&'a mut [Option<Item>;9]);
|
|
||||||
|
|
||||||
impl Hotbar<'_> {
|
|
||||||
fn get_mut(&mut self, index: usize) -> &mut Option<Item> {
|
|
||||||
&mut self.0[index]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Armor<'a>(&'a mut [Option<Item>; 4]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Default for PlayerInventory {
|
impl Default for PlayerInventory {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
@ -60,14 +48,10 @@ impl PlayerInventory {
|
|||||||
// TODO: Add crafting check here
|
// TODO: Add crafting check here
|
||||||
self.crafting_output = item
|
self.crafting_output = item
|
||||||
}
|
}
|
||||||
1..=4 => {
|
1..=4 => self.crafting[slot - 1] = item,
|
||||||
self.crafting[slot-1] = item
|
|
||||||
}
|
|
||||||
5..=8 => {
|
5..=8 => {
|
||||||
match item {
|
match item {
|
||||||
None => {
|
None => self.armor[slot - 4] = None,
|
||||||
self.armor[slot-4] = None
|
|
||||||
},
|
|
||||||
Some(item) => {
|
Some(item) => {
|
||||||
// TODO: Replace asserts with error handling
|
// TODO: Replace asserts with error handling
|
||||||
match slot - 5 {
|
match slot - 5 {
|
||||||
@ -87,7 +71,7 @@ impl PlayerInventory {
|
|||||||
assert!(item.is_boots() || item_allowed_override);
|
assert!(item.is_boots() || item_allowed_override);
|
||||||
self.armor[3] = Some(item)
|
self.armor[3] = Some(item)
|
||||||
}
|
}
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +82,7 @@ impl PlayerInventory {
|
|||||||
45 => {
|
45 => {
|
||||||
self.offhand = item;
|
self.offhand = item;
|
||||||
}
|
}
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
|
use crate::VarInt;
|
||||||
|
use pumpkin_world::item::Item;
|
||||||
use serde::{
|
use serde::{
|
||||||
de::{self, SeqAccess, Visitor},
|
de::{self, SeqAccess, Visitor},
|
||||||
Deserialize,
|
Deserialize,
|
||||||
};
|
};
|
||||||
use pumpkin_world::item::Item;
|
|
||||||
use crate::VarInt;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -16,9 +16,6 @@ pub struct Slot {
|
|||||||
components_to_remove: Option<Vec<VarInt>>,
|
components_to_remove: Option<Vec<VarInt>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Slot {
|
impl<'de> Deserialize<'de> for Slot {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@ -91,7 +88,7 @@ impl From<Slot> for Item {
|
|||||||
fn from(slot: Slot) -> Self {
|
fn from(slot: Slot) -> Self {
|
||||||
Item {
|
Item {
|
||||||
item_count: slot.item_count.0.try_into().unwrap(),
|
item_count: slot.item_count.0.try_into().unwrap(),
|
||||||
item_id: slot.item_id.unwrap().0.try_into().unwrap()
|
item_id: slot.item_id.unwrap().0.try_into().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,9 +37,12 @@ pub fn get_default<'a>(category: &str) -> Option<&'a str> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_minecraft_id(category: &str, protocol_id: u32) -> Option<&str> {
|
pub fn find_minecraft_id(category: &str, protocol_id: u32) -> Option<&str> {
|
||||||
REGISTRY.get(category)?
|
REGISTRY
|
||||||
|
.get(category)?
|
||||||
.entries
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_,other_protocol_id)|*other_protocol_id.get("protocol_id").unwrap()==protocol_id)
|
.find(|(_, other_protocol_id)| {
|
||||||
|
*other_protocol_id.get("protocol_id").unwrap() == protocol_id
|
||||||
|
})
|
||||||
.map(|(id, _)| id.as_str())
|
.map(|(id, _)| id.as_str())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,72 +4,54 @@ impl Item {
|
|||||||
pub fn is_helmet(&self) -> bool {
|
pub fn is_helmet(&self) -> bool {
|
||||||
[
|
[
|
||||||
// Leather
|
// Leather
|
||||||
856,
|
856, // Netherite
|
||||||
// Netherite
|
876, // Turtle helmet
|
||||||
876,
|
794, // Chainmail
|
||||||
// Turtle helmet
|
860, // Diamond
|
||||||
794,
|
868, // Gold
|
||||||
// Chainmail
|
872, // Iron
|
||||||
860,
|
864,
|
||||||
// Diamond
|
]
|
||||||
868,
|
.contains(&self.item_id)
|
||||||
// Gold
|
|
||||||
872,
|
|
||||||
// Iron
|
|
||||||
864
|
|
||||||
].contains(&self.item_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_chestplate(&self) -> bool {
|
pub fn is_chestplate(&self) -> bool {
|
||||||
[
|
[
|
||||||
// Leather
|
// Leather
|
||||||
857,
|
857, // Netherite
|
||||||
// Netherite
|
877, // Chainmail
|
||||||
877,
|
861, // Diamond
|
||||||
// Chainmail
|
869, // Gold
|
||||||
861,
|
873, // Iron
|
||||||
// Diamond
|
865, // Elytra
|
||||||
869,
|
|
||||||
// Gold
|
|
||||||
873,
|
|
||||||
// Iron
|
|
||||||
865,
|
|
||||||
// Elytra
|
|
||||||
773,
|
773,
|
||||||
].contains(&self.item_id)
|
]
|
||||||
|
.contains(&self.item_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_leggings(&self) -> bool {
|
pub fn is_leggings(&self) -> bool {
|
||||||
[
|
[
|
||||||
// Leather
|
// Leather
|
||||||
858,
|
858, // Netherite
|
||||||
// Netherite
|
878, // Chainmail
|
||||||
878,
|
862, // Diamond
|
||||||
// Chainmail
|
870, // Gold
|
||||||
862,
|
874, // Iron
|
||||||
// Diamond
|
866,
|
||||||
870,
|
]
|
||||||
// Gold
|
.contains(&self.item_id)
|
||||||
874,
|
|
||||||
// Iron
|
|
||||||
866
|
|
||||||
].contains(&self.item_id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_boots(&self) -> bool {
|
pub fn is_boots(&self) -> bool {
|
||||||
[
|
[
|
||||||
// Leather
|
// Leather
|
||||||
859,
|
859, // Netherite
|
||||||
// Netherite
|
879, // Chainmail
|
||||||
879,
|
863, // Diamond
|
||||||
// Chainmail
|
871, // Gold
|
||||||
863,
|
875, // Iron
|
||||||
// Diamond
|
867,
|
||||||
871,
|
]
|
||||||
// Gold
|
.contains(&self.item_id)
|
||||||
875,
|
|
||||||
// Iron
|
|
||||||
867
|
|
||||||
].contains(&self.item_id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
mod item_registry;
|
|
||||||
mod item_categories;
|
mod item_categories;
|
||||||
|
mod item_registry;
|
||||||
pub use item_registry::ITEMS;
|
pub use item_registry::ITEMS;
|
||||||
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
commands::{handle_command, CommandSender},
|
||||||
|
entity::player::{ChatMode, GameMode, Hand},
|
||||||
|
server::Server,
|
||||||
|
util::math::wrap_degrees,
|
||||||
|
};
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use pumpkin_entity::EntityId;
|
use pumpkin_entity::EntityId;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
@ -17,12 +23,6 @@ use pumpkin_protocol::{
|
|||||||
use pumpkin_text::TextComponent;
|
use pumpkin_text::TextComponent;
|
||||||
use pumpkin_world::block::BlockFace;
|
use pumpkin_world::block::BlockFace;
|
||||||
use pumpkin_world::global_registry;
|
use pumpkin_world::global_registry;
|
||||||
use crate::{
|
|
||||||
commands::{handle_command, CommandSender},
|
|
||||||
entity::player::{ChatMode, GameMode, Hand},
|
|
||||||
server::Server,
|
|
||||||
util::math::wrap_degrees,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{Client, PlayerConfig};
|
use super::{Client, PlayerConfig};
|
||||||
|
|
||||||
@ -322,9 +322,19 @@ impl Client {
|
|||||||
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
|
let face = BlockFace::from_i32(use_item_on.face.0).unwrap();
|
||||||
let location = WorldPosition(location.0 + face.to_offset());
|
let location = WorldPosition(location.0 + face.to_offset());
|
||||||
if let Some(item) = self.player.as_ref().unwrap().inventory.held_item() {
|
if let Some(item) = self.player.as_ref().unwrap().inventory.held_item() {
|
||||||
let minecraft_id = global_registry::find_minecraft_id(global_registry::ITEM_REGISTRY,item.item_id).expect("All item ids are in the global registry");
|
let minecraft_id =
|
||||||
if let Ok(block_state_id) = pumpkin_world::block::block_registry::block_id_and_properties_to_block_state_id(minecraft_id,None) {
|
global_registry::find_minecraft_id(global_registry::ITEM_REGISTRY, item.item_id)
|
||||||
server.broadcast_packet(self, &CBlockUpdate::new(location, (block_state_id as i32).into()));
|
.expect("All item ids are in the global registry");
|
||||||
|
if let Ok(block_state_id) =
|
||||||
|
pumpkin_world::block::block_registry::block_id_and_properties_to_block_state_id(
|
||||||
|
minecraft_id,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
server.broadcast_packet(
|
||||||
|
self,
|
||||||
|
&CBlockUpdate::new(location, (block_state_id as i32).into()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,9 +349,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) {
|
pub fn handle_set_creative_slot(&mut self, _server: &mut Server, packet: SSetCreativeSlot) {
|
||||||
let inventory = &mut self.player.as_mut()
|
let inventory = &mut self.player.as_mut().unwrap().inventory;
|
||||||
.unwrap()
|
|
||||||
.inventory;
|
|
||||||
|
|
||||||
inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false);
|
inventory.set_slot(packet.slot as usize, packet.clicked_item.to_item(), false);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user