fix(entity): /effect crashes server on missing player attributes#1990
fix(entity): /effect crashes server on missing player attributes#1990MarkPLacer wants to merge 3 commits intoPumpkin-MC:masterfrom
Conversation
|
hardcoding the player attribute defaults in living.rs is a bit of a workaround, ideally EntityType::PLAYER in pumpkin-data should have its attributes populated properly the or_insert_with closures aren't needed here since AttributeInstance::new is cheap, plain or_insert would probs work better |
Thanks! Switched to |
|
I think the missing-attribute fallback in What feels misplaced is the It seems cleaner to populate |
Thanks for the feedback! I completely agree. The root cause was that Extractor skipped attribute injection for non-spawnable entities, such as players. I went ahead and modified the upstream Extractor to fetch attributes directly using |
|
Hold up, I've messed up in the latest commit, I believe |
that's to learn |
|
Actually, after looking into it, it was a false alarm on my end earlier... The latest commit in this PR is fine, I believe. The crash fix and the generated player attribute data change are separate from the movement-speed issue I hit while testing. I’m keeping this PR scoped to #1985, and I’ll investigate the speed/modifier behaviour separately |
Summary
Fixes #1985 — the server crashes when running
/effect give <player> minecraft:speed infinite 100.Root Cause
EntityType::PLAYERhas an emptyattributeslist inpumpkin-data. When a statuseffect modifier (e.g. Speed →
MOVEMENT_SPEED) is applied, the attribute lookup inLivingEntity::update_attributecalls.unwrap()onNone, causing a panic.Vanilla handles this gracefully:
MobEffect.addAttributeModifiers()does a null check(
if (attribute != null)) and silently skips missing attributes.Changes
Crash prevention: Replaced
.unwrap()inupdate_attributeandget_attribute_basewith
.map_or(attribute.default_value, |a| a.1), matching vanilla's null-safety pattern.Player attribute seeding: Added vanilla-accurate base attribute values for Players in
LivingEntity::new(), mirroringPlayer.createAttributes()from the vanilla source:MOVEMENT_SPEED: 0.1 (was falling back to generic 0.7)ATTACK_DAMAGE: 1.0 (was falling back to generic 2.0)ATTACK_SPEED: 4.0LUCK: 0.0BLOCK_INTERACTION_RANGE: 4.5ENTITY_INTERACTION_RANGE: 3.0Testing
cargo clippy --all-targets -- -D warnings: zero warningscargo test: 102/102 passed