Lothrazar / Cyclic

Minecraft mod written in Java
MIT License
156 stars 95 forks source link

[Feature Request] Add Mekanism machine support to Soundproofing block #2389

Open sehrgut opened 3 months ago

sehrgut commented 3 months ago

I use Cyclic Soundproofing blocks in my machine rooms on DW20, and they muffle all machine sounds except for Mekanism machines. I believe this proposal could cover Mekanism machines as well with no to minimal side effects. As Cyclic and Mekanism end up in many of the same modpacks, increased interoperability between them will be a definite player experience improvement.

I haven't read the Mekanism source in detail, just enough to find the root cause and potential implementation strategy I'm giving here, so I don't know if this is feasible.

Mekanism uses tickable sounds for their machine sounds (See TileTickableSound here: https://github.com/mekanism/Mekanism/blob/1.20.4/src/main/java/mekanism/client/sound/SoundHandler.java), effectively masking them from the Cyclic soundproofing block. A check on TickableSoundInstance instances to see if they're created/managed by Mekanism TileTickableSound, and if so, considering them also muffleable may be possible.

I have found that Mekanism TileTickableSounds have soundCategory=SoundSource.BLOCKS, and it seems likely that the majority of environmental and background music TickableSoundInstances will not have that category value, so this may be feasible by changing event.getSound() instanceof TickableSoundInstance to (event.getSound() instanceof TickableSoundInstance && event.getSoundCategory() != SoundSource.BLOCKS) in the onPlaySound handler.

I may be missing something, and that would cast too wide a net, but this might be a simple addition for Mekanism compatiblity.