Add unique sounds for tv

This commit is contained in:
Andrew-71 2023-10-31 12:02:59 +03:00
parent 7204a7bfd8
commit b2fb521395
11 changed files with 53 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import net.minecraft.item.ItemPlacementContext;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
@ -26,7 +27,9 @@ import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.entities.TVBlockEntity;
import su.a71.new_soviet.registration.NSE_Items;
import su.a71.new_soviet.registration.NSE_Sounds;
import su.a71.new_soviet.util.Shapes;
@ -87,18 +90,29 @@ public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvide
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (state.get(BROKEN) && player.getInventory().getMainHandStack().getItem() == Blocks.GLASS_PANE.asItem()) {
if (!player.isCreative())
player.getInventory().getMainHandStack().decrement(1);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 0.8f, 1f);
world.setBlockState(pos, state.with(BROKEN, false));
return ActionResult.SUCCESS;
}
if (!world.isClient) {
world.setBlockState(pos, state.cycle(INVERTED), 2);
}
float f = state.get(ON) ? 1f : 0.9f;
world.playSound(null, pos, NSE_Sounds.SWITCH_PRESS, SoundCategory.BLOCKS, 0.6f, f);
BlockState newState = world.getBlockState(pos);
if (newState.get(ON) != newState.get(INVERTED)) {
world.playSound(null, pos, NSE_Sounds.TV_ON_SOUND, SoundCategory.BLOCKS, 0.6f, 1f);
} else {
world.playSound(null, pos, NSE_Sounds.TV_OFF_SOUND, SoundCategory.BLOCKS, 0.6f, 1f);
}
return ActionResult.SUCCESS;
}
@Override
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
if (!state.get(BROKEN)) {
world.playSound(null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.LIGHT_BULB_BROKEN_SOUND, SoundCategory.BLOCKS, 0.8f, 1f);
world.playSound(null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.TV_BREAK_SOUND, SoundCategory.BLOCKS, 0.8f, 1f);
}
world.setBlockState(hit.getBlockPos(), state.with(BROKEN, true), 2);
super.onProjectileHit(world, state, hit, projectile);

View file

@ -1,6 +1,7 @@
package su.a71.new_soviet.blocks.lamps;
import net.minecraft.block.*;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
@ -55,6 +56,7 @@ public class LightBulbLampBlock extends LampBlock {
if (world.isReceivingRedstonePower(pos) == state.get(INVERTED) || (NewSoviet.RANDOM.nextBetween(1, 32) == 1)) {
if (!player.isCreative())
player.getInventory().getMainHandStack().decrement(1);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 0.8f, 1f);
world.setBlockState(pos, state.with(BROKEN, false));
return ActionResult.SUCCESS;
} else {