Productive Bees

Productive Bees

10M Downloads

Block placement sounds are played when opening GUIs

Mithi83 opened this issue ยท 2 comments

commented

Modpack ATM 10.0.18, Productive Bees 1.21.0-13.1.5

Rightclick on a Centrifuge, Breeding Chamber or BaBee Incubator (those are the instances I tested, other blocks probably show the same behavior) to open the respective GUI. Depending on what you hold in your main hand you can hear the sound of that block being placed when opening the GUI. With an empty hand you hear no sound, with a stone in your main hand you can hear the stone placing sound etc.

My expectation would be that no sound is being played when opening the GUIs regardless of what you hold in your hand.

commented

After a quick comparison with the AE2 code I'm somewhat familiar with I could manage to fix that problem with the following patch in a proof of concept just for the Centrifuge:

diff --git a/src/main/java/cy/jdkdigital/productivebees/common/block/Centrifuge.java b/src/main/java/cy/jdkdigital/productivebees/common/block/Centrifuge.java
index 6f09e110..eeb5f309 100644
--- a/src/main/java/cy/jdkdigital/productivebees/common/block/Centrifuge.java
+++ b/src/main/java/cy/jdkdigital/productivebees/common/block/Centrifuge.java
@@ -99,9 +99,11 @@ public class Centrifuge extends CapabilityContainerBlock

     @Override
     protected InteractionResult useWithoutItem(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, BlockHitResult pHitResult) {
-        if (!pLevel.isClientSide() && pLevel.getBlockEntity(pPos) instanceof CentrifugeBlockEntity centrifugeBlockEntity) {
-            pPlayer.openMenu(centrifugeBlockEntity, pPos);
-            return InteractionResult.SUCCESS_NO_ITEM_USED;
+        if (pLevel.getBlockEntity(pPos) instanceof CentrifugeBlockEntity centrifugeBlockEntity) {
+            if (!pLevel.isClientSide()) {
+                pPlayer.openMenu(centrifugeBlockEntity, pPos);
+            }
+            return InteractionResult.sidedSuccess(pLevel.isClientSide());
         }
         return super.useWithoutItem(pState, pLevel, pPos, pPlayer, pHitResult);
     }

The crucial point here is that you mix checking for the block entity with the client side check. If either condition is not met you call super.useWithoutItem. This chain should probably be interrupted also on the client side if the block entity check succeeds.

commented

For completeness' sake: Another side effect of the bug was that when holding a food item in hand (while being hungry enough to eat it) and rightclicking on a block the GUI would open while the food would be consumed. This was fixed by the change as well. Thanks for the fix!