Skip to content

Commit

Permalink
Elaborate on hack against double updates for noteblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul1365972 committed Mar 30, 2024
1 parent a2a00f6 commit 7e3a526
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 4 additions & 1 deletion crates/core/src/redpiler/compile_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub enum NodeType {
Trapdoor,
Wire,
Constant,
NoteBlock { instrument: Instrument, note: u32 },
NoteBlock {
instrument: Instrument,
note: u32,
},
}

#[derive(Debug, Clone, Default)]
Expand Down
18 changes: 7 additions & 11 deletions crates/core/src/redstone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,14 @@ pub fn update(block: Block, world: &mut impl World, pos: BlockPos) {
Block::NoteBlock {
instrument: _instrument,
note,
powered,
..
} => {
let should_be_powered = redstone_lamp_should_be_lit(world, pos);
// We need to recheck if the live version of the block is powered,
// because the supplied block is cached and could be outdated
let Block::NoteBlock { powered, .. } = world.get_block(pos) else {
unreachable!("Underlying block changed, this should never happen")
};
if powered != should_be_powered {
// Hack: Update the instrument only just before the noteblock is updated
let instrument = noteblock::get_noteblock_instrument(world, pos);
Expand All @@ -242,16 +247,7 @@ pub fn update(block: Block, world: &mut impl World, pos: BlockPos) {
powered: should_be_powered,
};

// TODO: There is a weird double activation bug, so we need to check if block is not already powered
let is_not_powered = matches!(
world.get_block(pos),
Block::NoteBlock { powered: false, .. }
);

if should_be_powered
&& is_not_powered
&& noteblock::is_noteblock_unblocked(world, pos)
{
if should_be_powered && noteblock::is_noteblock_unblocked(world, pos) {
noteblock::play_note(world, pos, instrument, note);
}
world.set_block(pos, new_block);
Expand Down

0 comments on commit 7e3a526

Please sign in to comment.