Only play a sound when the stack changes

This commit is contained in:
Sollace 2021-11-17 22:33:20 +02:00
parent 68bcd5a467
commit c8fc88711d

View file

@ -398,13 +398,16 @@ public class SpellbookScreenHandler extends ScreenHandler {
public void setCrafted(ItemStack crafted) { public void setCrafted(ItemStack crafted) {
uncrafted = uncrafted.or(() -> Optional.of(getStack())); uncrafted = uncrafted.or(() -> Optional.of(getStack()));
ItemStack old = getStack();
setStack(crafted); setStack(crafted);
if (!ItemStack.areEqual(old, crafted)) {
player.playSound(SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.MASTER, 1, 0.3F); player.playSound(SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.MASTER, 1, 0.3F);
} }
}
public void setUncrafted() { public void setUncrafted() {
player.playSound(SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.MASTER, 0.2F, 0.2F);
uncrafted = uncrafted.filter(stack -> { uncrafted = uncrafted.filter(stack -> {
player.playSound(SoundEvents.BLOCK_END_PORTAL_FRAME_FILL, SoundCategory.MASTER, 0.2F, 0.2F);
setStack(stack); setStack(stack);
return false; return false;
}); });