[PR #115] [MERGED] Sweet berries can be planted; picking and bone meal work #2333

Closed
opened 2026-11-02 15:55:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/115
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: fix/sweet-berries-93


📝 Commits (1)

  • 80645bf Sweet berries, carrots and potatoes are planted instead of eaten

📊 Changes

8 files changed (+423 additions, -27 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+48 -27)
📝 crates/horizon-client/src/game/dispense_fixture.rs (+71 -0)
📝 crates/horizon-client/src/game/growth.rs (+11 -0)
📝 crates/horizon-client/src/game/spill.rs (+17 -0)
📝 crates/horizon-client/src/items.rs (+27 -0)
📝 crates/horizon-world/src/level/interact.rs (+24 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaDispenserOracle.java (+89 -0)
➕ tools/test_use_item_on_parity.py (+136 -0)

📄 Description

What was wrong

Sweet berries couldn't be planted (#93), and neither could carrots or potatoes in many cases. use_item_as_player started eating any food before it tried to place a block item: in creative always, in survival whenever the player was hungry. Only full survival players could plant.

Three related bugs turned up in the same path:

  • Picking a grown sweet berry bush, or glow berries off cave vines, gave nothing. PlayerEffect::InteractLoot was never handled.
  • Bone meal on a bush of age 0–2 picked it instead of growing it.
  • Every block placement played its place sound twice: once from BlockItem.place's level event, once explicitly.

What vanilla does (26.3)

  • ServerPlayerGameMode.useItemOn does three things in order:
    • the block's useItemOn (then useWithoutItem when it asks to try with an empty hand);
    • ItemStack.useOn, which awards minecraft:used for an item interaction;
    • Minecraft.startUseItem goes on to useItem only when that passed.
  • BlockItem.useOn places first; a consumable that couldn't be placed is then used (Item.use, starting to eat).
  • SweetBerryBushBlock:
    • mayPlaceOn is VegetationBlock's #supports_vegetation;
    • useItemOn passes bone meal on a bush that can still grow on to BoneMealItem.useOn;
    • useWithoutItem at age > 1 drops harvest/sweet_berry_bush (Block.dropFromBlockInteractLootTable, from its random sequence, popped with Block.popResource), plays block.sweet_berry_bush.pick_berries and sets age 1. Cave vines use harvest/cave_vine.
  • BoneMealItem.useOn calls ItemStack.causeUseVibration(item_interact_finish) after the stack shrank. An emptied stack has no use effects, so the last bone meal makes no vibration.

The fix

  • game.rs:
    • a food item that is also a block, aimed at a block, tries BlockItem.place first;
    • when placement fails, or the player can't build, it starts eating (start_eating), and the fallback counts used;
    • placement relies on the level event for its sound; the powder snow bucket swaps in its own.
  • horizon-world interact.rs: Behaviours::use_item_on implements the bush's useItemOn before useWithoutItem.
  • items.rs and spill.rs: interact_loot and drop_interact_loot roll a block_interact table with the block state (for match_block) and pop the stacks.
  • growth.rs: bone meal's used statistic and item_interact_finish vibration.

Tests

  • New tools/test_use_item_on_parity.py: 4000 random right clicks on the top of a block. The setup varies:

    • the clicked block: supports and non-supports (grass, dirt, podzol, coarse dirt, rooted dirt, moss, pale moss, mud, mangrove roots, farmland, stone, sand…), or a sweet berry bush of any age;
    • what's above: grass, snow, water…;
    • the held item: sweet/glow berries, carrots, potatoes, bone meal, seeds, apples, sticks, empty hand;
    • survival or creative, hungry or full, sneaking or not.

    Vanilla runs the real ServerPlayerGameMode.useItemOn (plus the client's useItem fallback) on the dispenser harness's headless level (VanillaDispenserOracle.useItem). Horizon runs the real use_item_as_player on that hit in a headless game (HORIZON_DISPENSE_FIXTURE, new use_item mode). Compared: block changes, dropped items, level events, sounds, game events, statistics, held stack, the item being eaten and the level random. Result: 4000/4000 match; vanilla planted in 688 cases and started eating in 1104. Before the fix, 1497/4000 matched.

  • test_dispenser_parity.py (6000/6000) and test_composter_parity.py (3000/3000) still match with the extended oracle and fixture.

  • On the Mac mini: cargo clippy --workspace --all-targets -D warnings, cargo fmt --check and cargo test -p horizon-client -p horizon-world (583 passed) pass. tools/check_public_tree.py passes.

  • Not checked on a vscreen: the desktop is off limits for builds right now. The harness drives the game's own use_item_as_player.

Not covered

  • Growth and bone-meal growth themselves were already ported and harness-covered (random_tick, bone meal), so they're unchanged. The berry-bush slowdown and pricking are #112.

Fixes #93

🤖 Generated with Claude Code


🔄 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/115 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/sweet-berries-93` --- ### 📝 Commits (1) - [`80645bf`](https://github.com/horizon-rust/horizon/commit/80645bf0de2fdd28a80a158e35c06436dba49653) Sweet berries, carrots and potatoes are planted instead of eaten ### 📊 Changes **8 files changed** (+423 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+48 -27) 📝 `crates/horizon-client/src/game/dispense_fixture.rs` (+71 -0) 📝 `crates/horizon-client/src/game/growth.rs` (+11 -0) 📝 `crates/horizon-client/src/game/spill.rs` (+17 -0) 📝 `crates/horizon-client/src/items.rs` (+27 -0) 📝 `crates/horizon-world/src/level/interact.rs` (+24 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaDispenserOracle.java` (+89 -0) ➕ `tools/test_use_item_on_parity.py` (+136 -0) </details> ### 📄 Description ## What was wrong Sweet berries couldn't be planted (#93), and neither could carrots or potatoes in many cases. `use_item_as_player` started eating any food before it tried to place a block item: in creative always, in survival whenever the player was hungry. Only full survival players could plant. Three related bugs turned up in the same path: - Picking a grown sweet berry bush, or glow berries off cave vines, gave nothing. `PlayerEffect::InteractLoot` was never handled. - Bone meal on a bush of age 0–2 picked it instead of growing it. - Every block placement played its place sound twice: once from `BlockItem.place`'s level event, once explicitly. ## What vanilla does (26.3) - `ServerPlayerGameMode.useItemOn` does three things in order: - the block's `useItemOn` (then `useWithoutItem` when it asks to try with an empty hand); - `ItemStack.useOn`, which awards `minecraft:used` for an item interaction; - `Minecraft.startUseItem` goes on to `useItem` only when that passed. - `BlockItem.useOn` places first; a consumable that couldn't be placed is then used (`Item.use`, starting to eat). - `SweetBerryBushBlock`: - `mayPlaceOn` is `VegetationBlock`'s `#supports_vegetation`; - `useItemOn` passes bone meal on a bush that can still grow on to `BoneMealItem.useOn`; - `useWithoutItem` at age > 1 drops `harvest/sweet_berry_bush` (`Block.dropFromBlockInteractLootTable`, from its random sequence, popped with `Block.popResource`), plays `block.sweet_berry_bush.pick_berries` and sets age 1. Cave vines use `harvest/cave_vine`. - `BoneMealItem.useOn` calls `ItemStack.causeUseVibration(item_interact_finish)` after the stack shrank. An emptied stack has no use effects, so the last bone meal makes no vibration. ## The fix - `game.rs`: - a food item that is also a block, aimed at a block, tries `BlockItem.place` first; - when placement fails, or the player can't build, it starts eating (`start_eating`), and the fallback counts `used`; - placement relies on the level event for its sound; the powder snow bucket swaps in its own. - `horizon-world` `interact.rs`: `Behaviours::use_item_on` implements the bush's `useItemOn` before `useWithoutItem`. - `items.rs` and `spill.rs`: `interact_loot` and `drop_interact_loot` roll a `block_interact` table with the block state (for `match_block`) and pop the stacks. - `growth.rs`: bone meal's `used` statistic and `item_interact_finish` vibration. ## Tests - New `tools/test_use_item_on_parity.py`: 4000 random right clicks on the top of a block. The setup varies: - the clicked block: supports and non-supports (grass, dirt, podzol, coarse dirt, rooted dirt, moss, pale moss, mud, mangrove roots, farmland, stone, sand…), or a sweet berry bush of any age; - what's above: grass, snow, water…; - the held item: sweet/glow berries, carrots, potatoes, bone meal, seeds, apples, sticks, empty hand; - survival or creative, hungry or full, sneaking or not. Vanilla runs the real `ServerPlayerGameMode.useItemOn` (plus the client's `useItem` fallback) on the dispenser harness's headless level (`VanillaDispenserOracle.useItem`). Horizon runs the real `use_item_as_player` on that hit in a headless game (`HORIZON_DISPENSE_FIXTURE`, new `use_item` mode). Compared: block changes, dropped items, level events, sounds, game events, statistics, held stack, the item being eaten and the level random. Result: **4000/4000 match**; vanilla planted in 688 cases and started eating in 1104. Before the fix, 1497/4000 matched. - `test_dispenser_parity.py` (6000/6000) and `test_composter_parity.py` (3000/3000) still match with the extended oracle and fixture. - On the Mac mini: `cargo clippy --workspace --all-targets -D warnings`, `cargo fmt --check` and `cargo test -p horizon-client -p horizon-world` (583 passed) pass. `tools/check_public_tree.py` passes. - Not checked on a vscreen: the desktop is off limits for builds right now. The harness drives the game's own `use_item_as_player`. ## Not covered - Growth and bone-meal growth themselves were already ported and harness-covered (`random_tick`, bone meal), so they're unchanged. The berry-bush slowdown and pricking are #112. Fixes #93 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:55:02 +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#2333
No description provided.