Skip to content

Commit 0419933

Browse files
fix: use ItemKind equippable attribute instead of hardcoding (#857)
1 parent 473d35f commit 0419933

File tree

3 files changed

+8
-39
lines changed

3 files changed

+8
-39
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hyperion-inventory/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ hyperion-crafting = {workspace = true}
33
roaring = {workspace = true}
44
snafu = {workspace = true}
55
valence_protocol = {workspace = true}
6+
valence_generated = {workspace = true}
67
flecs_ecs = {workspace = true}
78
derive_more = {workspace = true}
89
tracing = {workspace = true}

crates/hyperion-inventory/src/lib.rs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{cell::Cell, cmp::min, num::Wrapping};
44
use derive_more::{Deref, DerefMut};
55
use flecs_ecs::{core::Entity, macros::Component};
66
use tracing::debug;
7+
use valence_generated::item::EquipmentSlot;
78
use valence_protocol::{
89
ItemKind, ItemStack,
910
nbt::Compound,
@@ -544,56 +545,22 @@ pub trait ItemKindExt {
544545

545546
impl ItemKindExt for ItemKind {
546547
fn is_helmet(&self) -> bool {
547-
matches!(
548-
self,
549-
Self::LeatherHelmet
550-
| Self::ChainmailHelmet
551-
| Self::IronHelmet
552-
| Self::GoldenHelmet
553-
| Self::DiamondHelmet
554-
| Self::NetheriteHelmet
555-
| Self::TurtleHelmet
556-
| Self::PlayerHead
557-
)
548+
matches!(self.equippable(), Some(EquipmentSlot::Helmet))
558549
}
559550

560551
fn is_chestplate(&self) -> bool {
561-
matches!(
562-
self,
563-
Self::LeatherChestplate
564-
| Self::ChainmailChestplate
565-
| Self::IronChestplate
566-
| Self::GoldenChestplate
567-
| Self::DiamondChestplate
568-
| Self::NetheriteChestplate
569-
)
552+
matches!(self.equippable(), Some(EquipmentSlot::Chestplate))
570553
}
571554

572555
fn is_leggings(&self) -> bool {
573-
matches!(
574-
self,
575-
Self::LeatherLeggings
576-
| Self::ChainmailLeggings
577-
| Self::IronLeggings
578-
| Self::GoldenLeggings
579-
| Self::DiamondLeggings
580-
| Self::NetheriteLeggings
581-
)
556+
matches!(self.equippable(), Some(EquipmentSlot::Leggings))
582557
}
583558

584559
fn is_boots(&self) -> bool {
585-
matches!(
586-
self,
587-
Self::LeatherBoots
588-
| Self::ChainmailBoots
589-
| Self::IronBoots
590-
| Self::GoldenBoots
591-
| Self::DiamondBoots
592-
| Self::NetheriteBoots
593-
)
560+
matches!(self.equippable(), Some(EquipmentSlot::Boots))
594561
}
595562

596563
fn is_armor(&self) -> bool {
597-
self.is_helmet() || self.is_chestplate() || self.is_leggings() || self.is_boots()
564+
self.equippable().is_some()
598565
}
599566
}

0 commit comments

Comments
 (0)