[PR #5087] [MERGED] Let a mob pick up and equip what it finds, as vanilla's looting pass does #6053

Closed
opened 2026-11-03 05:16:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5087
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/mob-pick-up-item


📝 Commits (1)

  • 854c85b Let a mob pick up and equip what it finds, as vanilla's looting pass does

📊 Changes

6 files changed (+688 additions, -16 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/creatures.rs (+1 -0)
➕ crates/horizon-client/src/game/mob_looting.rs (+207 -0)
📝 crates/horizon-client/src/game/piglins.rs (+2 -16)
📝 crates/horizon-client/src/mobs.rs (+1 -0)
➕ crates/horizon-client/src/mobs/equip.rs (+476 -0)

📄 Description

Implements Mob.pickUpItem and its comparison helpers — the ledger rows for pickUpItem, canReplaceCurrentItem, compareArmor, compareWeapons, canReplaceEqualItem and getApproximateAttributeWith. (No issue.)

Vanilla's Mob.aiStep runs a looting pass for every mob with CanPickUpLoot while mob_griefing is on: each item entity within getPickupReach (1, 0, 1) that is not on pickup delay and passes wantsToPickUp is handed to pickUpItem, which asks equipItemIfPossible what to do with it. That is armour if it beats what is worn (armour, then toughness, then enchantments/damage/name), a main-hand weapon if it beats the held one (the preferred-weapon tags first for skeletons and drowned, then attack damage), an empty main hand for a piece that cannot replace worn armour, and nothing at all for an item with no slot. The replaced piece is dropped unless the drop-chance roll saves it (0.085 by default, nextFloat() - 0.1f against it), and the mob is marked persistent so it does not despawn carrying its prize.

Horizon rolled CanPickUpLoot at spawn for the zombie family and the skeletons and nothing read it: the only looting loops were the per-species copies (panda, villager, piglin, allay, sulfur cube), so a zombie stood next to a diamond sword and left it there.

The comparison rules are a new lib module, mobs::equip, pure and resource-free so they can be tested directly; the per-tick pass is game/mob_looting.rs, which reuses the existing plumbing (self.dropped, the same reach and add_pickup, the piglin equip's slot helpers) and is gated so it never overlaps the five species loops that already exist. The piglin path loses twelve lines of duplicated pickup code to the shared helper.

Proven: on a build box, cargo test -p horizon-client --lib mobs::equip → 8 passed (a better weapon replaces a worse one and not the reverse, armour by armour then toughness, an equal weapon by enchantments, a PREVENT_ARMOR_CHANGE piece never replaced, a preferred-tag weapon beating a stronger one outside it, attribute modifiers by slot group and operation, items going to their own slot, and the species pickup gate), and cargo check -p horizon-client --lib --bins is clean.

Not proven: nothing in a game, and no harness — a mob_ai/mob_gear scenario ("a zombie picks up and wears the dropped sword, the old one drops, the mob persists") is the obvious next step and I could not build one here.

Six known limits, each marked in the code rather than implied away: species with their own pickUpItem (raiders, fox, dolphin, villager, piglin, allay, panda, sulfur cube) are excluded by the gate, so pillagers still pick up nothing; worn gear's damage and custom name are not modelled, so an equal-item swap sees the worn piece as fresh; a hand takes one item rather than the whole stack (Horizon holds one item per slot); picked-up gear keeps its enchantments but loses trim, name and damage on the way in and out; no equip sound or minecraft:equip game event (the piglin equip omits it too); and Equippable.canBeEquippedBy is not modelled, mitigated by refusing the body and saddle slots. One pre-existing gap this makes visible rather than causes: a mob's melee still uses its attribute damage, so a picked-up sword changes what it holds and renders, not what it hits for.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5087 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/mob-pick-up-item` --- ### 📝 Commits (1) - [`854c85b`](https://github.com/horizon-rust/horizon/commit/854c85b235bcddde6001a5cd3baea8fd885c6d25) Let a mob pick up and equip what it finds, as vanilla's looting pass does ### 📊 Changes **6 files changed** (+688 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+1 -0) ➕ `crates/horizon-client/src/game/mob_looting.rs` (+207 -0) 📝 `crates/horizon-client/src/game/piglins.rs` (+2 -16) 📝 `crates/horizon-client/src/mobs.rs` (+1 -0) ➕ `crates/horizon-client/src/mobs/equip.rs` (+476 -0) </details> ### 📄 Description Implements `Mob.pickUpItem` and its comparison helpers — the ledger rows for `pickUpItem`, `canReplaceCurrentItem`, `compareArmor`, `compareWeapons`, `canReplaceEqualItem` and `getApproximateAttributeWith`. (No issue.) Vanilla's `Mob.aiStep` runs a looting pass for every mob with `CanPickUpLoot` while `mob_griefing` is on: each item entity within `getPickupReach` (1, 0, 1) that is not on pickup delay and passes `wantsToPickUp` is handed to `pickUpItem`, which asks `equipItemIfPossible` what to do with it. That is armour if it beats what is worn (armour, then toughness, then enchantments/damage/name), a main-hand weapon if it beats the held one (the preferred-weapon tags first for skeletons and drowned, then attack damage), an empty main hand for a piece that cannot replace worn armour, and nothing at all for an item with no slot. The replaced piece is dropped unless the drop-chance roll saves it (0.085 by default, `nextFloat() - 0.1f` against it), and the mob is marked persistent so it does not despawn carrying its prize. Horizon rolled `CanPickUpLoot` at spawn for the zombie family and the skeletons and **nothing read it**: the only looting loops were the per-species copies (panda, villager, piglin, allay, sulfur cube), so a zombie stood next to a diamond sword and left it there. The comparison rules are a new lib module, `mobs::equip`, pure and resource-free so they can be tested directly; the per-tick pass is `game/mob_looting.rs`, which reuses the existing plumbing (`self.dropped`, the same reach and `add_pickup`, the piglin equip's slot helpers) and is gated so it never overlaps the five species loops that already exist. The piglin path loses twelve lines of duplicated pickup code to the shared helper. **Proven:** on a build box, `cargo test -p horizon-client --lib mobs::equip` → 8 passed (a better weapon replaces a worse one and not the reverse, armour by armour then toughness, an equal weapon by enchantments, a `PREVENT_ARMOR_CHANGE` piece never replaced, a preferred-tag weapon beating a stronger one outside it, attribute modifiers by slot group and operation, items going to their own slot, and the species pickup gate), and `cargo check -p horizon-client --lib --bins` is clean. **Not proven:** nothing in a game, and no harness — a `mob_ai`/`mob_gear` scenario ("a zombie picks up and wears the dropped sword, the old one drops, the mob persists") is the obvious next step and I could not build one here. Six known limits, each marked in the code rather than implied away: species with their own `pickUpItem` (raiders, fox, dolphin, villager, piglin, allay, panda, sulfur cube) are excluded by the gate, so **pillagers still pick up nothing**; worn gear's damage and custom name are not modelled, so an equal-item swap sees the worn piece as fresh; a hand takes one item rather than the whole stack (Horizon holds one item per slot); picked-up gear keeps its enchantments but loses trim, name and damage on the way in and out; no equip sound or `minecraft:equip` game event (the piglin equip omits it too); and `Equippable.canBeEquippedBy` is not modelled, mitigated by refusing the body and saddle slots. One pre-existing gap this makes visible rather than causes: a mob's melee still uses its attribute damage, so a picked-up sword changes what it holds and renders, not what it hits for. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6053
No description provided.