Merge pull request #2232 from kacpherek/fix/note-block-attack-and-heads

🤖 Agent: Merged by hand by Ludovic's AI agent (orchestrator) after the contribution gate. rdbtCVS's change request is addressed at this head; a re-review was asked, with no new objection since. Proven in wave 5's union run (cg21 union 65b0cb252 (main c1ebf5d1b + 72 kacpherek PRs) playhorizon 94/95, use_item_on fixed (#2126 523280e78).
This commit is contained in:
Ludovic Marie
2026-10-27 12:17:22 +01:00
committed by GitHub
3 changed files with 50 additions and 7 deletions
+6 -2
View File
@@ -2802,9 +2802,13 @@ impl Game<'_> {
self.process_level_events()
}
fn attack_block(&mut self, pos: [i32; 3]) -> Result<()> {
self.with_level(|b, level, ticks| {
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]));
let note = self.with_level(|b, level, ticks| {
b.attack_block(level, ticks, BlockPos::new(pos[0], pos[1], pos[2]))
});
// NoteBlock.attack awards the statistic.
if note {
self.stats.custom("play_noteblock", 1);
}
self.process_level_events()
}
/// Track which chunks are ticking (Ticks needs chunk load/unload).
@@ -992,6 +992,20 @@ impl Game<'_> {
// The pause between two blocks is the client's (MultiPlayerGameMode's
// destroyDelay); the server digs from the START it receives.
play.destroy_delay = 0;
// ServerPlayerGameMode.handleBlockBreakAction: a survival START
// attacks the block at once, so a tap released in the same tick
// still plays a note. The dig is marked begun for tick_mining.
let pos = a.pos;
self.as_guest(host, conn, |g| {
if g.may_build() && !g.creative {
let _ = g.attack_block(pos);
g.mining = Some(Mining {
pos,
progress: 0.0,
ticks: 0,
});
}
});
}
1 => {}
3 => {
+30 -5
View File
@@ -559,20 +559,26 @@ impl Behaviours {
sim.game_event_state(pos, "minecraft:block_change", next);
}
/// The state change of `RedStoneOreBlock.attack` when mining begins.
/// `BlockBehaviour.attack` when mining begins: `RedStoneOreBlock.attack`
/// lights the ore, `NoteBlock.attack` plays the note. True for a note
/// block, whose player also earns the `play_noteblock` statistic.
pub fn attack_block<L: LevelAccess + ?Sized>(
&self,
level: &mut L,
ticks: &mut Ticks,
pos: BlockPos,
) {
) -> bool {
let mut sim = self.sim(level, ticks);
let state = sim.state(pos);
if self.data(state).chain.contains(&Class::RedStoneOre)
&& !self.table.bool(state, self.props.lit)
{
let chain = &self.data(state).chain;
if chain.contains(&Class::Note) {
sim.note_play(pos, state);
return true;
}
if chain.contains(&Class::RedStoneOre) && !self.table.bool(state, self.props.lit) {
sim.set_block_and_update(pos, self.table.set_bool(state, self.props.lit, true));
}
false
}
/// `BlockState.useWithoutItem` for a right-click on `pos` (hit face and
@@ -641,6 +647,25 @@ impl Behaviours {
if self.data(state).chain.contains(&Class::CopperGolemStatue) {
return self.turn_statue(level, ticks, pos, state, item);
}
// NoteBlock.useItemOn: a mob head on the top face is placed, not tuned
// (`#minecraft:noteblock_top_instruments`).
if face == Direction::Up
&& self.data(state).chain.contains(&Class::Note)
&& item.is_some_and(|i| {
matches!(
i,
"minecraft:zombie_head"
| "minecraft:skeleton_skull"
| "minecraft:creeper_head"
| "minecraft:dragon_head"
| "minecraft:wither_skeleton_skull"
| "minecraft:piglin_head"
| "minecraft:player_head"
)
})
{
return InteractionResult::Pass;
}
self.use_without_item(level, ticks, pos, face, hit, player)
}