Sweet berries, carrots and potatoes are planted instead of eaten

A right click with food that is also a block item tried to eat it before
placing it: in creative always, in survival whenever the player was
hungry. BlockItem.useOn places first and only eats a consumable that could
not be placed (counting the use, as ItemStack.useOn does). Picking a sweet
berry bush or cave vines dropped nothing: the harvest loot
(Block.dropFromBlockInteractLootTable) is now rolled and popped. Bone meal
on a bush that can still grow grows it (SweetBerryBushBlock.useItemOn
passes it on) instead of picking it, and counts the use with its
item_interact_finish vibration. Every block placement played its sound
twice; BlockItem.place's level event is now the only one.

tools/test_use_item_on_parity.py drives vanilla's real
ServerPlayerGameMode.useItemOn (and Minecraft.startUseItem's useItem
fallback) against use_item_as_player in a headless game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-14 17:43:24 +02:00
parent 45663c9e39
commit 80645bf0de
8 changed files with 423 additions and 27 deletions
@@ -527,4 +527,28 @@ impl Behaviours {
self.sim(level, ticks)
.use_without_item(pos, face, hit, player)
}
/// `BlockState.useItemOn` with `item` in the main hand, then, when the
/// block asks to try with an empty hand (the default), `useWithoutItem`.
/// `SweetBerryBushBlock.useItemOn` passes bone meal on a bush that can
/// still grow on to the item.
#[allow(clippy::too_many_arguments)]
pub fn use_item_on<L: LevelAccess + ?Sized>(
&self,
level: &mut L,
ticks: &mut Ticks,
pos: BlockPos,
face: Direction,
hit: Vec3,
player: PlayerContext,
item: Option<&str>,
) -> InteractionResult {
let state = level.block_state(pos);
if item == Some("minecraft:bone_meal")
&& self.data(state).chain.contains(&Class::SweetBerryBush)
&& self.table.int(state, self.props.age) < 3
{
return InteractionResult::Pass;
}
self.use_without_item(level, ticks, pos, face, hit, player)
}
}