[PR #3943] [CLOSED] Mobs pick up dropped items, foxes and ocelots can trust players #5305

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3943
Author: @kacpherek
Created: 10/29/2026
Status: ❌ Closed

Base: main ← Head: fix/split-mob-pickup-trust


📝 Commits (10+)

  • 04d3dea Keep the stack size in a mob's main hand
  • 0ff60f9 Let mob goals see the dropped items of the level
  • 2f69509 Let mobs that can pick up loot take dropped gear
  • c0856a5 Make a fox's mouth take only what it has room for
  • 1e5ce00 Let foxes search for and pick up items
  • 9d4a238 Let dolphins pick up items dropped in the water
  • 4c70f1a Make dolphins throw the items they hold back
  • 8ff56a2 Make dolphins swim to floating items and play with them
  • 3788037 Let pillagers pick up banners lying on the ground
  • 6e2699c Remember which player put an animal in love

📊 Changes

25 files changed (+1268 additions, -65 deletions)

View changed files

📝 crates/horizon-client/examples/probe/mob_ai_probe.rs (+6 -3)
📝 crates/horizon-client/src/entity_nbt.rs (+34 -4)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/creatures.rs (+50 -1)
📝 crates/horizon-client/src/game/lan.rs (+23 -1)
📝 crates/horizon-client/src/game/llamas.rs (+2 -1)
➕ crates/horizon-client/src/game/mob_pickup.rs (+242 -0)
📝 crates/horizon-client/src/game/mounts.rs (+2 -1)
📝 crates/horizon-client/src/game/nautili.rs (+2 -1)
📝 crates/horizon-client/src/game/pandas.rs (+3 -2)
📝 crates/horizon-client/src/game/raids.rs (+7 -0)
📝 crates/horizon-client/src/game/remote_mob_data.rs (+7 -0)
📝 crates/horizon-client/src/mobs.rs (+35 -1)
📝 crates/horizon-client/src/mobs/ai.rs (+13 -6)
📝 crates/horizon-client/src/mobs/aquatic.rs (+2 -0)
📝 crates/horizon-client/src/mobs/dolphin.rs (+112 -3)
📝 crates/horizon-client/src/mobs/drops.rs (+3 -3)
📝 crates/horizon-client/src/mobs/finalize.rs (+12 -5)
📝 crates/horizon-client/src/mobs/fox.rs (+266 -15)
📝 crates/horizon-client/src/mobs/goals.rs (+19 -4)

...and 5 more files

📄 Description

What and why

  • Stack size in a mob's hand: main keeps the stack in a mob's hand in the save (count and components). This keeps it in the other places a stack picked up by a dolphin, panda or zombie was cut to one item: the equipment packet sent to guests and the drop on death. The panda now uses the main hand stack instead of its own count field.
  • Mob goals see dropped items: goals can now look up the item entities of the level (box query and in-water test), which the fox and dolphin search goals need.
  • Loot pickup for zombies, skeletons, husks, drowned, vindicators and wither skeletons: mobs that can pick up loot now equip gear lying at their feet, replace worse gear and drop the old item with its drop chance.
  • Fox mouth: a fox takes an item only if it has room: an empty mouth takes anything, a full one only food after it has eaten.
  • Foxes search for and pick up items: a fox with an empty mouth walks to an item within 8 blocks, keeps one item and spits out what it held.
  • Dolphins pick up items dropped in the water: with an empty mouth a dolphin takes the whole stack.
  • Dolphins throw held items back: a dolphin holding an item throws it with a 40 tick pickup delay.
  • Dolphins swim to floating items and play with them: they notice items in the water within 8 blocks, swim to them, then let go of what they hold.
  • Pillagers pick up banners: during a raid they take banners from the ground, with the ominous banner going to the captain pickup.
  • Love cause: #3873 keeps which connection fed an animal (for the bred advancement), and that stays as it is. This adds the feeding player's UUID on the animal itself, saved as LoveCause, so a fox can tell who bred it and the cause survives a reload. It replaces the love_player flag, which nothing reads any more.
  • Foxes have a saved, synced trusted list of up to two players, so a loaded or joined world keeps it.
  • Ocelots have a saved, synced trusting flag, so every ocelot no longer stays wild after a reload.
  • Foxes trust the players who bred them, or who used a spawn egg on them.
  • Foxes stop running from trusted players and stay asleep near them.
  • Foxes defend trusted players: when a trusted player is hurt by a mob, the fox targets it, growls and wakes up.
  • Wild ocelots can come to trust a player who feeds them raw cod or salmon (one time in three), with hearts or smoke.
  • Trusting ocelots stop running from players.
  • Trusting ocelots are not scared off while following a player holding fish.
  • Wild ocelots despawn when far away after 2400 ticks, trusting ones do not.
  • Doc comment fixes for the fox trust methods and the ocelot trust roll.

Old saves and the wire

LoveCause, Trusted and Trusting are vanilla's own save tags and the trusted and trusting synched data are vanilla's entries (fox 20 and 21, ocelot 18), so this adds no format of its own. Saves written by Horizon before this, and saves from vanilla, load like this:

  • LoveCause is written only when an animal has one. A save without it loads with no cause, as an animal fed before the update; the bred advancement does not depend on it (that is the connection map from #3873, which is not saved either).
  • Trusted: Horizon used to write an empty list, which loads as nobody trusted. A vanilla list loads as vanilla does: the list is cleared, then each UUID is added, and a third one replaces the second. A UUID given as an int array or as text is read.
  • Trusting missing loads as false (a wild ocelot); a vanilla ocelot that trusts keeps it.
  • A mob's main hand with no count loads as one item; one with a count keeps it (main's stack load).

Vanilla reference

  • Stack size in main hand: Mob.getItemBySlot(MAINHAND).getCount()
  • Dropped items for goals: Level.getEntitiesOfClass(ItemEntity.class, area)
  • Loot pickup: Mob.aiStep, Mob.pickUpItem, Mob.java
  • Fox mouth: Fox.canHoldItem, Fox.java
  • Fox item search: Fox.FoxSearchForItemsGoal, Fox.pickUpItem, Fox.java
  • Dolphin pickup: Dolphin.pickUpItem, Dolphin.java
  • Dolphin throwing: Dolphin.ItemGoal.dropItem, Dolphin.PlayWithItemsGoal, Dolphin.java
  • Dolphin swimming to items: Dolphin.DolphinMoveToItemGoal, Dolphin.java
  • Pillager banners: Pillager.pickUpItem, Raider.pickUpItem, Pillager.java, Raider.java
  • Love cause: Animal.setInLove, Animal.java (lines 173, 101, 108)
  • Fox trusted list: Fox.getTrustedEntities, Fox.addTrustedEntity, Fox.java (418-461, 703)
  • Ocelot trusting flag: Ocelot.setTrusting, DATA_TRUSTING, Ocelot.java (76-96)
  • Fox trust from breeding: Fox.FoxBreedGoal.breed, Fox.onOffspringSpawnedFromEgg, Fox.java (599, 889-899)
  • Fox avoids players: Fox.registerGoals, Fox.FoxAlertableEntitiesSelector.test, Fox.trusts, Fox.java (188, 836-838, 703)
  • Fox defends: Fox.DefendTrustedTargetGoal, Fox.java (208-211, 642-647, 748-790, 247-249, 1037-1042, 1141)
  • Ocelot trust by feeding: Ocelot.mobInteract, Ocelot.spawnTrustingParticles, Ocelot.java (166-186, 204-214)
  • Ocelot stops fleeing: Ocelot.reassessTrustingGoals, Ocelot.OcelotAvoidEntityGoal, Ocelot.java (215-224, 288-298)
  • Ocelot tempt goal: Ocelot.OcelotTemptGoal.canScare, Ocelot.java (303-311)
  • Ocelot despawn: Ocelot.removeWhenFarAway, Ocelot.java (137-140)

Self-check

Main is merged in (it conflicted in entity_nbt.rs, commands/items.rs, dispenser.rs, zombie_villagers.rs and more). Where main already did it, main's code stays: the held stack and its save and load (main_hand_stack), the connection map for the bred advancement (#3873), and the else of feed_animal. A first version of this branch had cargo check and clippy -D warnings passing for horizon-client; the merge and the changes that follow it were made without a build, so CI is the first compile. Not run in game.

Split out of #3926.


🔄 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/3943 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/split-mob-pickup-trust` --- ### 📝 Commits (10+) - [`04d3dea`](https://github.com/horizon-rust/horizon/commit/04d3dea5b0f7c00171e25089815c558e5ed48d7c) Keep the stack size in a mob's main hand - [`0ff60f9`](https://github.com/horizon-rust/horizon/commit/0ff60f9d396e60d2c560e23ad61810a61370195e) Let mob goals see the dropped items of the level - [`2f69509`](https://github.com/horizon-rust/horizon/commit/2f695096470851a34e126a508e634f1d7d7a7208) Let mobs that can pick up loot take dropped gear - [`c0856a5`](https://github.com/horizon-rust/horizon/commit/c0856a5c2f65d3bb6a8a3b82bb4ed15117afb2f2) Make a fox's mouth take only what it has room for - [`1e5ce00`](https://github.com/horizon-rust/horizon/commit/1e5ce00c9a8b938cf111d637dc14233335476e45) Let foxes search for and pick up items - [`9d4a238`](https://github.com/horizon-rust/horizon/commit/9d4a238cfa232c036983c06a9ef71dc2658a7a9f) Let dolphins pick up items dropped in the water - [`4c70f1a`](https://github.com/horizon-rust/horizon/commit/4c70f1a4d6a0e845fd9a2e0d301fe120577f39d6) Make dolphins throw the items they hold back - [`8ff56a2`](https://github.com/horizon-rust/horizon/commit/8ff56a2478e81a193dcd4be32090c94fb8fce725) Make dolphins swim to floating items and play with them - [`3788037`](https://github.com/horizon-rust/horizon/commit/378803768bb010242e6730c710faa82b35612141) Let pillagers pick up banners lying on the ground - [`6e2699c`](https://github.com/horizon-rust/horizon/commit/6e2699c74200bcbcf49461fe5f3fd39e7ce0dc6a) Remember which player put an animal in love ### 📊 Changes **25 files changed** (+1268 additions, -65 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/mob_ai_probe.rs` (+6 -3) 📝 `crates/horizon-client/src/entity_nbt.rs` (+34 -4) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+50 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+23 -1) 📝 `crates/horizon-client/src/game/llamas.rs` (+2 -1) ➕ `crates/horizon-client/src/game/mob_pickup.rs` (+242 -0) 📝 `crates/horizon-client/src/game/mounts.rs` (+2 -1) 📝 `crates/horizon-client/src/game/nautili.rs` (+2 -1) 📝 `crates/horizon-client/src/game/pandas.rs` (+3 -2) 📝 `crates/horizon-client/src/game/raids.rs` (+7 -0) 📝 `crates/horizon-client/src/game/remote_mob_data.rs` (+7 -0) 📝 `crates/horizon-client/src/mobs.rs` (+35 -1) 📝 `crates/horizon-client/src/mobs/ai.rs` (+13 -6) 📝 `crates/horizon-client/src/mobs/aquatic.rs` (+2 -0) 📝 `crates/horizon-client/src/mobs/dolphin.rs` (+112 -3) 📝 `crates/horizon-client/src/mobs/drops.rs` (+3 -3) 📝 `crates/horizon-client/src/mobs/finalize.rs` (+12 -5) 📝 `crates/horizon-client/src/mobs/fox.rs` (+266 -15) 📝 `crates/horizon-client/src/mobs/goals.rs` (+19 -4) _...and 5 more files_ </details> ### 📄 Description ## What and why - Stack size in a mob's hand: main keeps the stack in a mob's hand in the save (count and components). This keeps it in the other places a stack picked up by a dolphin, panda or zombie was cut to one item: the equipment packet sent to guests and the drop on death. The panda now uses the main hand stack instead of its own count field. - Mob goals see dropped items: goals can now look up the item entities of the level (box query and in-water test), which the fox and dolphin search goals need. - Loot pickup for zombies, skeletons, husks, drowned, vindicators and wither skeletons: mobs that can pick up loot now equip gear lying at their feet, replace worse gear and drop the old item with its drop chance. - Fox mouth: a fox takes an item only if it has room: an empty mouth takes anything, a full one only food after it has eaten. - Foxes search for and pick up items: a fox with an empty mouth walks to an item within 8 blocks, keeps one item and spits out what it held. - Dolphins pick up items dropped in the water: with an empty mouth a dolphin takes the whole stack. - Dolphins throw held items back: a dolphin holding an item throws it with a 40 tick pickup delay. - Dolphins swim to floating items and play with them: they notice items in the water within 8 blocks, swim to them, then let go of what they hold. - Pillagers pick up banners: during a raid they take banners from the ground, with the ominous banner going to the captain pickup. - Love cause: #3873 keeps which connection fed an animal (for the bred advancement), and that stays as it is. This adds the feeding player's UUID on the animal itself, saved as `LoveCause`, so a fox can tell who bred it and the cause survives a reload. It replaces the `love_player` flag, which nothing reads any more. - Foxes have a saved, synced trusted list of up to two players, so a loaded or joined world keeps it. - Ocelots have a saved, synced trusting flag, so every ocelot no longer stays wild after a reload. - Foxes trust the players who bred them, or who used a spawn egg on them. - Foxes stop running from trusted players and stay asleep near them. - Foxes defend trusted players: when a trusted player is hurt by a mob, the fox targets it, growls and wakes up. - Wild ocelots can come to trust a player who feeds them raw cod or salmon (one time in three), with hearts or smoke. - Trusting ocelots stop running from players. - Trusting ocelots are not scared off while following a player holding fish. - Wild ocelots despawn when far away after 2400 ticks, trusting ones do not. - Doc comment fixes for the fox trust methods and the ocelot trust roll. ## Old saves and the wire `LoveCause`, `Trusted` and `Trusting` are vanilla's own save tags and the trusted and trusting synched data are vanilla's entries (fox 20 and 21, ocelot 18), so this adds no format of its own. Saves written by Horizon before this, and saves from vanilla, load like this: - `LoveCause` is written only when an animal has one. A save without it loads with no cause, as an animal fed before the update; the bred advancement does not depend on it (that is the connection map from #3873, which is not saved either). - `Trusted`: Horizon used to write an empty list, which loads as nobody trusted. A vanilla list loads as vanilla does: the list is cleared, then each UUID is added, and a third one replaces the second. A UUID given as an int array or as text is read. - `Trusting` missing loads as false (a wild ocelot); a vanilla ocelot that trusts keeps it. - A mob's main hand with no `count` loads as one item; one with a count keeps it (main's stack load). ## Vanilla reference - Stack size in main hand: Mob.getItemBySlot(MAINHAND).getCount() - Dropped items for goals: Level.getEntitiesOfClass(ItemEntity.class, area) - Loot pickup: Mob.aiStep, Mob.pickUpItem, Mob.java - Fox mouth: Fox.canHoldItem, Fox.java - Fox item search: Fox.FoxSearchForItemsGoal, Fox.pickUpItem, Fox.java - Dolphin pickup: Dolphin.pickUpItem, Dolphin.java - Dolphin throwing: Dolphin.ItemGoal.dropItem, Dolphin.PlayWithItemsGoal, Dolphin.java - Dolphin swimming to items: Dolphin.DolphinMoveToItemGoal, Dolphin.java - Pillager banners: Pillager.pickUpItem, Raider.pickUpItem, Pillager.java, Raider.java - Love cause: Animal.setInLove, Animal.java (lines 173, 101, 108) - Fox trusted list: Fox.getTrustedEntities, Fox.addTrustedEntity, Fox.java (418-461, 703) - Ocelot trusting flag: Ocelot.setTrusting, DATA_TRUSTING, Ocelot.java (76-96) - Fox trust from breeding: Fox.FoxBreedGoal.breed, Fox.onOffspringSpawnedFromEgg, Fox.java (599, 889-899) - Fox avoids players: Fox.registerGoals, Fox.FoxAlertableEntitiesSelector.test, Fox.trusts, Fox.java (188, 836-838, 703) - Fox defends: Fox.DefendTrustedTargetGoal, Fox.java (208-211, 642-647, 748-790, 247-249, 1037-1042, 1141) - Ocelot trust by feeding: Ocelot.mobInteract, Ocelot.spawnTrustingParticles, Ocelot.java (166-186, 204-214) - Ocelot stops fleeing: Ocelot.reassessTrustingGoals, Ocelot.OcelotAvoidEntityGoal, Ocelot.java (215-224, 288-298) - Ocelot tempt goal: Ocelot.OcelotTemptGoal.canScare, Ocelot.java (303-311) - Ocelot despawn: Ocelot.removeWhenFarAway, Ocelot.java (137-140) ## Self-check Main is merged in (it conflicted in entity_nbt.rs, commands/items.rs, dispenser.rs, zombie_villagers.rs and more). Where main already did it, main's code stays: the held stack and its save and load (`main_hand_stack`), the connection map for the bred advancement (#3873), and the `else` of `feed_animal`. A first version of this branch had cargo check and clippy -D warnings passing for horizon-client; the merge and the changes that follow it were made without a build, so CI is the first compile. Not run in game. Split out of #3926. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:11:40 +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#5305
No description provided.