[PR #6261] [MERGED] Sheep grazing: the eat goal only changes the world with mobGriefing on #6750

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6261
Author: @CocofireHD
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/sheep-grazing-mob-griefing


📝 Commits (1)

  • 7d7a73e Sheep grazing: the eat goal only changes the world with mobGriefing on

📊 Changes

2 files changed (+137 additions, -11 deletions)

View changed files

📝 crates/horizon-client/src/mobs/goals.rs (+126 -10)
📝 crates/horizon-client/src/mobs/world.rs (+11 -1)

📄 Description

🤖 Opened by CocofireHD's AI agent (Hermes Agent, deepseek-v4.1-flash), not by CocofireHD personally.

Fixes #6221.

What was wrong

EatBlockGoal.tick wraps both world changes in the MOB_GRIEFING rule and leaves Mob.ate outside it. From the pinned 26.3 jar (javap -p -c net.minecraft.world.entity.ai.goal.EatBlockGoal):

 51:   ifeq 99          // not edible for sheep: look at the block below
 54-73:               Level.getServerLevel(level).getGameRules().get(MOB_GRIEFING).booleanValue()
 76:   ifeq 89          // off: the edible block is not broken
 79:                  Level.destroyBlock(pos, false)
 89:                  Mob.ate()                       // outside the gate
 96:   goto 189
 99:                  below = pos.below()
118:   ifeq 189         // below is not GRASS_BLOCK: return, no ate
121-140:             the same MOB_GRIEFING read
143:   ifeq 182         // off: no particles, no setBlock
146:                 Level.levelEvent(2001, below, Block.getId(GRASS_BLOCK.defaultBlockState()))
166:                 Level.setBlock(below, DIRT.defaultBlockState(), 2)
182:                 Mob.ate()                       // outside the gate
189:   return

mobs/goals.rs (EatBlock::tick) pushed MobEvent::BreakBlock and MobEvent::SetBlockName unconditionally, so a sheep ate with the rule off. MobWorld.mob_griefing was already there (mobs.rs:2342) and gates an allay's pickup, the dragon's block breaking, blasts and a mob's projectiles — this goal was the outlier.

What changes

  • Both MobEvent pushes sit behind cx.w.mob_griefing; super::ai::ate(m) stays outside the gate, so with the rule off the sheep still sheds its wool and a baby still ages up, as in vanilla.
  • mobs/world.rs: with_built_test_world now delegates to a new test-only with_built_test_world_rules(others, mob_griefing, build, f), so a test can reach the flag.
  • New mobs::goals::eat_block_tests, driven through the real goal (mobs::ai::tick, 6000 ticks on a 17×17 shelf, the goal fires at 1 in 1000 a tick), one case per half of the gate: sheep on top of grass blocks (the setBlock half) and sheep on short grass (the destroyBlock half).

Verification

cargo test -p horizon-client --lib eat_block — 2 passed, 0 failed. The whole mobs:: module: see the line below in the checks.

Both tests fail when the gate is inverted (if !cx.w.mob_griefing), so they are sensitive to the rule and not to the surrounding code:

mob_griefing on: 0
  the_eat_goal_turns_grass_to_dirt_only_with_mob_griefing
mob_griefing on: 0
  the_eat_goal_breaks_short_grass_only_with_mob_griefing
test result: FAILED. 0 passed; 2 failed; 1233 filtered out

With the gate removed from the grass-to-dirt branch only (the shape of the original bug), the dirt test reports assertion left == right failed: mob_griefing off must leave the grass alone / left: 4 / right: 0.

In a real build (cargo build --profile fast -p horizon-client, horizon-ctl, creative superflat, four sheep on a 5×5 grass shelf, gamerule mob_griefing toggled, one sample a second for 150 s per half):

build mob_griefing dirt blocks at the end of the window
unpatched false 0 → 1 (one block eaten at 41.6 s)
patched false 0 for the whole 150 s
patched true 5 (0 at 57.3 s, …, 5 at 139.6 s)

Rebased onto origin/main at dea6dea98 (the branch was 45 commits behind when it was opened). cargo fmt --all -- --check clean; cargo clippy -p horizon-client --lib -- -D warnings reports nothing.

Not done: tools/test_mob_ai_parity.py does not yet have a mob_griefing off scenario (VanillaMobAiOracle has no game-rule stub for it), so the differential harness does not cover this case; the Rust test is the guard for now. Happy to add the oracle case in a follow-up if you want it there instead.

Duplicate

#6256 (fix/gp-sheep-griefing) is the same one-line gate in the same function, opened 80 s before this one and without a reference to #6221. Same behaviour, different evidence: that one unit-tests a eat_block_bite helper it extracted, this one drives mobs::ai::tick and reads the events a real sheep produces. Merge whichever you prefer; the other can be closed.

🤖 Generated with Hermes Agent


🔄 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/6261 **Author:** [@CocofireHD](https://github.com/CocofireHD) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/sheep-grazing-mob-griefing` --- ### 📝 Commits (1) - [`7d7a73e`](https://github.com/horizon-rust/horizon/commit/7d7a73e84c3f628221e029679811a5e0cc7ceea1) Sheep grazing: the eat goal only changes the world with mobGriefing on ### 📊 Changes **2 files changed** (+137 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/goals.rs` (+126 -10) 📝 `crates/horizon-client/src/mobs/world.rs` (+11 -1) </details> ### 📄 Description > 🤖 Opened by CocofireHD's AI agent (Hermes Agent, deepseek-v4.1-flash), not by CocofireHD personally. Fixes #6221. ## What was wrong `EatBlockGoal.tick` wraps both world changes in the `MOB_GRIEFING` rule and leaves `Mob.ate` outside it. From the pinned 26.3 jar (`javap -p -c net.minecraft.world.entity.ai.goal.EatBlockGoal`): ``` 51: ifeq 99 // not edible for sheep: look at the block below 54-73: Level.getServerLevel(level).getGameRules().get(MOB_GRIEFING).booleanValue() 76: ifeq 89 // off: the edible block is not broken 79: Level.destroyBlock(pos, false) 89: Mob.ate() // outside the gate 96: goto 189 99: below = pos.below() 118: ifeq 189 // below is not GRASS_BLOCK: return, no ate 121-140: the same MOB_GRIEFING read 143: ifeq 182 // off: no particles, no setBlock 146: Level.levelEvent(2001, below, Block.getId(GRASS_BLOCK.defaultBlockState())) 166: Level.setBlock(below, DIRT.defaultBlockState(), 2) 182: Mob.ate() // outside the gate 189: return ``` `mobs/goals.rs` (`EatBlock::tick`) pushed `MobEvent::BreakBlock` and `MobEvent::SetBlockName` unconditionally, so a sheep ate with the rule off. `MobWorld.mob_griefing` was already there (`mobs.rs:2342`) and gates an allay's pickup, the dragon's block breaking, blasts and a mob's projectiles — this goal was the outlier. ## What changes - Both `MobEvent` pushes sit behind `cx.w.mob_griefing`; `super::ai::ate(m)` stays outside the gate, so with the rule off the sheep still sheds its wool and a baby still ages up, as in vanilla. - `mobs/world.rs`: `with_built_test_world` now delegates to a new test-only `with_built_test_world_rules(others, mob_griefing, build, f)`, so a test can reach the flag. - New `mobs::goals::eat_block_tests`, driven through the real goal (`mobs::ai::tick`, 6000 ticks on a 17×17 shelf, the goal fires at 1 in 1000 a tick), one case per half of the gate: sheep on top of grass blocks (the `setBlock` half) and sheep on short grass (the `destroyBlock` half). ## Verification `cargo test -p horizon-client --lib eat_block` — 2 passed, 0 failed. The whole `mobs::` module: see the line below in the checks. Both tests fail when the gate is inverted (`if !cx.w.mob_griefing`), so they are sensitive to the rule and not to the surrounding code: ``` mob_griefing on: 0 the_eat_goal_turns_grass_to_dirt_only_with_mob_griefing mob_griefing on: 0 the_eat_goal_breaks_short_grass_only_with_mob_griefing test result: FAILED. 0 passed; 2 failed; 1233 filtered out ``` With the gate removed from the grass-to-dirt branch only (the shape of the original bug), the dirt test reports `assertion left == right failed: mob_griefing off must leave the grass alone / left: 4 / right: 0`. In a real build (`cargo build --profile fast -p horizon-client`, `horizon-ctl`, creative superflat, four sheep on a 5×5 grass shelf, `gamerule mob_griefing` toggled, one sample a second for 150 s per half): | build | `mob_griefing` | dirt blocks at the end of the window | |---|---|---| | unpatched | false | 0 → 1 (one block eaten at 41.6 s) | | patched | false | 0 for the whole 150 s | | patched | true | 5 (0 at 57.3 s, …, 5 at 139.6 s) | Rebased onto `origin/main` at `dea6dea98` (the branch was 45 commits behind when it was opened). `cargo fmt --all -- --check` clean; `cargo clippy -p horizon-client --lib -- -D warnings` reports nothing. Not done: `tools/test_mob_ai_parity.py` does not yet have a `mob_griefing` off scenario (`VanillaMobAiOracle` has no game-rule stub for it), so the differential harness does not cover this case; the Rust test is the guard for now. Happy to add the oracle case in a follow-up if you want it there instead. ## Duplicate #6256 (`fix/gp-sheep-griefing`) is the same one-line gate in the same function, opened 80 s before this one and without a reference to #6221. Same behaviour, different evidence: that one unit-tests a `eat_block_bite` helper it extracted, this one drives `mobs::ai::tick` and reads the events a real sheep produces. Merge whichever you prefer; the other can be closed. 🤖 Generated with [Hermes Agent](https://hermes-agent.nousresearch.com) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:26:05 +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#6750
No description provided.