mojira.dev
MC-310632

Farmer villagers no longer throw excess wheat to other villagers

The bug

Farmer villagers with more than half a stack of wheat used to throw half of it to a nearby
villager they were interacting with. Since 26.3 Snapshot 4 they never do. The code path that
performs the throw is now unreachable because it tests for a data component that wheat does
not have.

Steps to Reproduce

  1. Create a Survival world in 26.3 Snapshot 6.

  2. Get a farmer villager and one other villager standing within about 2 blocks of each other,
    away from any composter or farmland (so the farmer does not consume the wheat itself).

  3. Drop a stack of 40 wheat at the farmer's feet. Wheat is in #minecraft:villager_picks_up, so
    the farmer picks it up.

  4. Wait for the two villagers to face each other and interact.

Observed Results

The farmer never throws any wheat, no matter how long you wait or how much wheat it holds.

Expected Results

The farmer throws roughly half of its wheat to the other villager, as it does in 26.2.

Control tests

  • Same setup in 26.2: the farmer visibly throws wheat.

  • Same setup in 26.3 Snapshot 6 but with 40 bread instead of wheat: the bread is thrown
    normally. This shows the throwing mechanic itself still works and only the wheat branch is
    broken.

Cause

In TradeWithVillager, the wheat branch reads:

if (isFarmer && body.getInventory().countItem(Items.WHEAT) > Items.WHEAT.getDefaultMaxStackSize() / 2) {
throwHalfStack(body, itemStack -> itemStack.is(Items.WHEAT) && itemStack.has(DataComponents.VILLAGER_FOOD), target);
}

The outer condition can be satisfied, but the predicate also demands the villager_food
component, and wheat does not have it. In 26.3 Snapshot 6 exactly four items carry
villager_food: bread, carrot, potato and beetroot. So the predicate can never match and the
branch is dead code.

In 26.2 the same line was:

throwHalfStack(body, ImmutableSet.of(Items.WHEAT), target);

with no component test. The villager_food component was introduced in 26.3 Snapshot 4, and the
migration of the general food branch immediately above it is faithful — 26.2's
Villager.FOOD_POINTS was exactly {bread, potato, carrot, beetroot}, matching the four items
that now carry the component. Only the wheat branch gained a clause it can never satisfy.

Impact

Low visibility but continuous: farmers hoard wheat instead of redistributing it. Breeding is
unaffected because the breeding foods are bread, carrot, potato and beetroot.

Comments 0

No comments.

yuluo

etanaratsastaja

Confirmed

Platform HC

Important

Mob behaviour

26.3 Snapshot 6

26.3 Snapshot 8

Retrieved