MCHPR / MCHPRS

A multithreaded Minecraft server built for redstone.
MIT License
1.55k stars 68 forks source link

Add noteblocks and instruments #133

Closed Paul1365972 closed 3 months ago

Paul1365972 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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 commented 6 months ago

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

Paul1365972 commented 3 months ago

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.