Encasing blocks plays a placing sound

This commit is contained in:
NotSoEpic 2024-07-06 08:41:41 +08:00
parent 75d337ba8c
commit ee41e0f04e

View file

@ -3,12 +3,14 @@ package com.simibubi.create.content.decoration.encasing;
import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
@ -31,9 +33,16 @@ public interface EncasableBlock {
return InteractionResult.SUCCESS;
encased.handleEncasing(state, level, pos, heldItem, player, hand, ray);
playEncaseSound(level, pos);
return InteractionResult.SUCCESS;
}
}
return InteractionResult.PASS;
}
default void playEncaseSound(Level level, BlockPos pos) {
BlockState newState = level.getBlockState(pos);
SoundType soundType = newState.getSoundType();
level.playSound(null, pos, soundType.getPlaceSound(), SoundSource.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F);
}
}