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
+27
View File
@@ -754,6 +754,33 @@ impl Items {
.as_str()
.map(str::to_owned)
}
/// `Block.dropFromBlockInteractLootTable`: the `block_interact` table `id`
/// for a right click on `state` (its `match_block` conditions see the
/// state), from the table's random sequence when it has one.
pub fn interact_loot(
&self,
id: &str,
registry: &BlockRegistry,
state: BlockStateId,
random: &mut impl RandomSource,
sequences: &mut crate::random_sequences::RandomSequences,
seed: i64,
) -> Vec<ItemStack> {
let (Some(table), Some(block)) = (self.loot.get(id), registry.state(state)) else {
return vec![];
};
let ctx = LootContext {
items: self,
block: &block.name,
properties: &block.properties,
held: None,
killed_by_player: false,
};
match table.get("random_sequence").and_then(Value::as_str) {
Some(sequence) => ctx.evaluate(table, sequences.get(sequence, seed)),
None => ctx.evaluate(table, random),
}
}
/// `loot_table` drawing from any random (a random sequence).
pub fn loot_table_from(
&self,