Skip to content

Commit eaffe46

Browse files
authored
Libcraft item refactoring (#527)
1 parent 7c7e418 commit eaffe46

File tree

4 files changed

+382
-159
lines changed

4 files changed

+382
-159
lines changed

libcraft/items/src/enchantment.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use serde::{Deserialize, Serialize};
55
/// An enchantment attached to an item.
66
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
77
pub struct Enchantment {
8+
/// The type of the enchantment.
89
#[serde(rename = "id")]
910
kind: EnchantmentKind,
11+
/// Enchantment level, represented by an `i8` for vanilla compatibility
1012
#[serde(rename = "lvl")]
1113
level: i8,
1214
}
@@ -21,6 +23,8 @@ impl Enchantment {
2123
///
2224
/// The level is capped at `i8::MAX` for compatability
2325
/// with Vanilla.
26+
#[must_use]
27+
#[allow(clippy::cast_possible_truncation)]
2428
pub fn new(kind: EnchantmentKind, level: u32) -> Self {
2529
Self {
2630
kind,
@@ -29,11 +33,14 @@ impl Enchantment {
2933
}
3034

3135
/// Gets the kind of this enchantment.
32-
pub fn kind(&self) -> EnchantmentKind {
36+
#[must_use]
37+
pub const fn kind(&self) -> EnchantmentKind {
3338
self.kind
3439
}
3540

3641
/// Gets the level of this enchantment.
42+
#[must_use]
43+
#[allow(clippy::cast_sign_loss)]
3744
pub fn level(&self) -> u32 {
3845
self.level.max(0) as u32
3946
}
@@ -48,6 +55,7 @@ impl Enchantment {
4855
/// Sets the level of this enchantment.
4956
///
5057
/// The level is capped to `i8::MAX`.
58+
#[allow(clippy::cast_possible_truncation)]
5159
pub fn set_level(&mut self, level: u32) {
5260
self.level = level.min(i8::MAX as u32) as i8;
5361
}

0 commit comments

Comments
 (0)