Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add noteblocks and instruments #133

Merged
merged 9 commits into from
Apr 7, 2024
Merged

Conversation

Paul1365972
Copy link
Contributor

This PR adds the noteblock and all blocks necessary to at play each instrument.
Not all blocks are implemented like logs or planks, but substibutes exist for each instrument (see: https://minecraft.wiki/w/Note_Block#Instruments).

This is still WIP for now and does not work with the redpiler yet.

Also small warning: The World trait now has a play_sound function, this will probably be a breaking change some software I don't know about. However adding it to the World trait still seemed like the best choice architectually.

@BramOtte
Copy link
Contributor

BramOtte commented Dec 2, 2023

If you are concerned changing the World trait will break some other application you could add a default implementation to the new function you are adding.

@Paul1365972
Copy link
Contributor Author

The implementation for the direct backend is a bit hacky, but it was the best thing I could come up with without rewriting major parts and thereby breaking most other PRs. There is also a bit of logic duplication for noteblocks and their sounds and I am not entirely sure where such utility functions should belong.
Would also like feedback on the decision to store events in the Backend instead of the TickScheduler. I know it's a minor thing, but which of those makes more sense?

@Paul1365972 Paul1365972 marked this pull request as ready for review December 4, 2023 23:04
Copy link
Member

@StackDoubleFlow StackDoubleFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, do you know if this would negatively impact performance after #129?

crates/blocks/src/blocks/props.rs Outdated Show resolved Hide resolved
@Paul1365972 Paul1365972 force-pushed the noteblocks branch 2 times, most recently from 53c79d7 to 3c113bc Compare December 14, 2023 18:21
@Paul1365972
Copy link
Contributor Author

Rebased and benchmarked against current master. Performance is suprisingly enough exacltly the same.

crates/blocks/src/blocks/props.rs Outdated Show resolved Hide resolved
powered: should_be_powered,
};

// TODO: There is a weird double activation bug, so we need to check if block is not already powered
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going on here? I'm not sure what you mean by double activation bug. Is it simply that the block updates multiple times? That's no guarantee it'll update only once after any change in surrounding state, or in response to a state change in general.

We already have block and powered. That state shouldn't have changed by this point, so I don't see why we need to retrieve and check it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block that is passed to the update method can definitely be outdated.
You are right that in nearly all cases the block is up-to-date as it fetched right before the update call, however in the update call in turbo::breadth_first_walk an old block instance is sometimes used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it a bit more and the comment on line 303 of turbo.rs basically explains it.

This only works because updating any other block than a wire will never change the state of the block. If that changes in the future, the cached state will need to be updated

Noteblocks break that assumption as they do change state on update.
All other blocks are correctly unaffected by "double updates", either because they schedule a tick (repeaters, torches etc.) or because only the final state matters (trapdoors etc.).

crates/core/src/redpiler/backend/direct.rs Outdated Show resolved Hide resolved
@Paul1365972 Paul1365972 force-pushed the noteblocks branch 2 times, most recently from b4c7ba2 to 55ab46a Compare January 9, 2024 23:00
@Paul1365972
Copy link
Contributor Author

Fixed all conflicts with the refactored redpiler and also updated the logic where necessary.
Feel free to re-review when you find the time.
I also changed the direct backend a bit so now each noteblock gets assigned a unique u16 id that is used to lookup the BlockPos, instrument and pitch (16 chunks full of noteblocks should be more than enough, I hope). For reference, originally it used a hashmap and the noteid as key.
Not sure if you want to have a look at the turbo backend issue, but my small hack still seems to work fine for now.

Copy link
Member

@StackDoubleFlow StackDoubleFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The turbo wire impl should probably change wrt its incorrect assumption, but I don't think it's that important right now.

@StackDoubleFlow StackDoubleFlow merged commit 8c5e762 into MCHPR:master Apr 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants