-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement item durability #714
base: master
Are you sure you want to change the base?
Conversation
…nt is not considered since enchantments are not yet implement)
3e353c0
to
58f755c
Compare
@@ -31,6 +32,19 @@ impl ItemMetadata for HoeItem { | |||
|
|||
#[async_trait] | |||
impl PumpkinItem for HoeItem { | |||
async fn on_after_dig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this vanilla ?
@@ -13,6 +14,17 @@ pub trait ItemMetadata { | |||
#[async_trait] | |||
pub trait PumpkinItem: Send + Sync { | |||
async fn normal_use(&self, _block: &Item, _player: &Player) {} | |||
async fn on_attack(&self, _item: &Item, _victim: &Entity) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this vanilla?
I also wonder if the slot components are properly saved, so if you rejoin or the server restarts its saved in the player data |
i also think instead of using duplicated logic for all the tools you can just use a trait like Mojang does (abstract class) |
I did not create a trait for that because not all items is damaged after the same events. For instance. All tools are damaged after breaking a block or using it in a block (if it's possible). Also if you hit an entity. Swords break when hitting an entity. Fishing rod does not break when you hit someone or break a block, but does when you fish. Elytra breaks when in the chest slot and flying others... |
@Snowiiii I like the explicit way of saying "hey, after this event happen (normal use, use on block etc) damage the item |
i don't like the private int calculateDamage(int baseDamage, ServerWorld world, @Nullable ServerPlayerEntity player) {
if (!this.isDamageable()) {
return 0;
}
if (player != null && player.isInCreativeMode()) {
return 0;
}
if (baseDamage > 0) {
return EnchantmentHelper.getItemDamage(world, this, baseDamage);
}
return baseDamage;
} Other tools like Shovels or Swords are missing |
Description
What was changed?
Why were these changes necessary?
It is part of the vanilla game.
What is the impact of this change?
This is the first step to read and write item components (data) when saving/reading a player's data in a world. Also this change introduces a way of sending structured components for a given
Slot
.Are there any known issues or limitations?
This PR does not account for the unbreakable enchantment since it's not yet implemented.
Demo
Turn sound on 🔊 to hear the breaking sound :D
item-durability-demo-2025-04-06_16.39.08.1.mp4