Do chores related to code quality

This commit is contained in:
Andrew-71 2023-09-25 10:51:32 +03:00
parent 2a6898b664
commit 2a695c6029
25 changed files with 126 additions and 174 deletions

View file

@ -8,7 +8,6 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
@ -28,25 +27,25 @@ public class CeilingFanBlock extends Block implements Waterloggable {
public CeilingFanBlock(Block.Settings settings) {
super(settings);
this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(WATERLOGGED, false));
this.setDefaultState(this.getDefaultState().with(ON, false).with(WATERLOGGED, false));
}
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return (BlockState)this.getDefaultState()
return this.getDefaultState()
.with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()))
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.setBlockState(pos, state.cycle(ON), 2);
}
}
}
@ -61,13 +60,13 @@ public class CeilingFanBlock extends Block implements Waterloggable {
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
}
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, WATERLOGGED});
builder.add(ON, WATERLOGGED);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -2,7 +2,6 @@ package su.a71.new_soviet.blocks;
import net.minecraft.block.*;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
@ -10,18 +9,15 @@ import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
public class CheckerBlock extends Block implements Waterloggable {
public static final int MAX_PICKLES = 4;
public static final IntProperty CHECKERS;
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape ONE_CHECKER;
@ -31,18 +27,18 @@ public class CheckerBlock extends Block implements Waterloggable {
public CheckerBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(CHECKERS, 1)).with(WATERLOGGED, true));
this.setDefaultState(this.stateManager.getDefaultState().with(CHECKERS, 1).with(WATERLOGGED, true));
}
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState blockState = ctx.getWorld().getBlockState(ctx.getBlockPos());
if (blockState.isOf(this)) {
return (BlockState)blockState.with(CHECKERS, Math.min(4, (Integer)blockState.get(CHECKERS) + 1));
return blockState.with(CHECKERS, Math.min(4, blockState.get(CHECKERS) + 1));
} else {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
boolean bl = fluidState.getFluid() == Fluids.WATER;
return (BlockState)super.getPlacementState(ctx).with(WATERLOGGED, bl);
return super.getPlacementState(ctx).with(WATERLOGGED, bl);
}
}
@ -59,7 +55,7 @@ public class CheckerBlock extends Block implements Waterloggable {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
} else {
if ((Boolean)state.get(WATERLOGGED)) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
@ -68,29 +64,24 @@ public class CheckerBlock extends Block implements Waterloggable {
}
public boolean canReplace(BlockState state, ItemPlacementContext context) {
return !context.shouldCancelInteraction() && context.getStack().isOf(this.asItem()) && (Integer) state.get(CHECKERS) < 4 || super.canReplace(state, context);
return !context.shouldCancelInteraction() && context.getStack().isOf(this.asItem()) && state.get(CHECKERS) < 4 || super.canReplace(state, context);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
switch ((Integer)state.get(CHECKERS)) {
case 1:
default:
return ONE_CHECKER;
case 2:
return TWO_CHECKER;
case 3:
return THREE_CHECKER;
case 4:
return FOUR_CHECKER;
}
return switch (state.get(CHECKERS)) {
default -> ONE_CHECKER;
case 2 -> TWO_CHECKER;
case 3 -> THREE_CHECKER;
case 4 -> FOUR_CHECKER;
};
}
public FluidState getFluidState(BlockState state) {
return (Boolean)state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{CHECKERS, WATERLOGGED});
builder.add(CHECKERS, WATERLOGGED);
}
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
@ -98,7 +89,7 @@ public class CheckerBlock extends Block implements Waterloggable {
}
static {
CHECKERS = IntProperty.of("checkers", 1, 4);;
CHECKERS = IntProperty.of("checkers", 1, 4);
WATERLOGGED = Properties.WATERLOGGED;
ONE_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 4.0, 14.0);
TWO_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 8.0, 14.0);

View file

@ -1,10 +1,8 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
@ -16,7 +14,7 @@ import net.minecraft.world.WorldView;
public class ChessBlock extends HorizontalFacingBlock {
private VoxelShape blockShape;
private final VoxelShape blockShape;
public ChessBlock(AbstractBlock.Settings settings, VoxelShape blockShape) {
super(settings.notSolid().nonOpaque().noBlockBreakParticles().pistonBehavior(PistonBehavior.DESTROY).strength(0.1f, 2f));

View file

@ -1,6 +1,5 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
@ -15,7 +14,6 @@ import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
import su.a71.new_soviet.util.Shapes;
public class ChessBlockKnight extends HorizontalFacingBlock {

View file

@ -131,7 +131,7 @@ public class HandrailBlock extends HorizontalFacingBlock implements BlockEntityP
SHAPE2 = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 15.0, 16.0, 17.0, 16.0), List.of(0.0, 17.0, 14.5, 16.0, 19.0, 16.5)));
SHAPE1 = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 15.0, 8.0, 18.0, 16.0), List.of(8.0, -8.0, 15.0, 16.0, 10.0, 16.0)));
SHAPE3 = new Shapes.HorizontalShape(List.of(List.of(0.0, -8.0, 15.0, 8.0, 10.0, 16.0), List.of(8.0, 0.0, 15.0, 16.0, 18.0, 16.0)));
ROTATION = IntProperty.of("rotate", 1, 3);;
ROTATION = IntProperty.of("rotate", 1, 3);
WATERLOGGED = Properties.WATERLOGGED;
}
}

View file

@ -121,7 +121,7 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return (BlockState)this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -3,7 +3,6 @@ package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
@ -41,13 +40,13 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.setBlockState(pos, state.cycle(ON), 2);
world.scheduleBlockTick(pos, this, 140);
}
}
@ -57,18 +56,13 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
switch(dir) {
case NORTH:
return Block.createCuboidShape(3.5, 2, 11, 12.5, 15, 16);
case SOUTH:
return Block.createCuboidShape(3.5, 2, 0, 12.5, 15, 5);
case EAST:
return Block.createCuboidShape(0, 2, 3.5, 5, 15, 12.5);
case WEST:
return Block.createCuboidShape(11, 2, 3.5, 16, 15, 12.5);
default:
return VoxelShapes.fullCube();
}
return switch (dir) {
case NORTH -> Block.createCuboidShape(3.5, 2, 11, 12.5, 15, 16);
case SOUTH -> Block.createCuboidShape(3.5, 2, 0, 12.5, 15, 5);
case EAST -> Block.createCuboidShape(0, 2, 3.5, 5, 15, 12.5);
case WEST -> Block.createCuboidShape(11, 2, 3.5, 16, 15, 12.5);
default -> VoxelShapes.fullCube();
};
}
@Override
@ -80,17 +74,17 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction direction = (Direction)state.get(FACING);
Direction direction = state.get(FACING);
BlockPos blockPos = pos.offset(direction.getOpposite());
BlockState blockState = world.getBlockState(blockPos);
return direction.getAxis().isHorizontal() && blockState.isSideSolidFullSquare(world, blockPos, direction);
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
} else {
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.scheduleBlockTick(pos, this, 140);
}
}

View file

@ -40,15 +40,11 @@ public class StoveBlock extends BlockWithEntity {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
switch(dir) {
case NORTH, SOUTH:
return VoxelShapes.cuboid(0.0625f, 0.0f, 0.3125f, 0.9375f, 0.5625f, 0.6875f);
case EAST, WEST:
return VoxelShapes.cuboid(0.3125f, 0.0f, 0.0625f, 0.6875f, 0.5625f, 0.9375f);
default:
return VoxelShapes.fullCube();
}
return switch (state.get(FACING)) {
case NORTH, SOUTH -> VoxelShapes.cuboid(0.0625f, 0.0f, 0.3125f, 0.9375f, 0.5625f, 0.6875f);
case EAST, WEST -> VoxelShapes.cuboid(0.3125f, 0.0f, 0.0625f, 0.6875f, 0.5625f, 0.9375f);
default -> VoxelShapes.fullCube();
};
}
@Override
@ -57,11 +53,11 @@ public class StoveBlock extends BlockWithEntity {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {

View file

@ -4,7 +4,6 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.enums.WallMountLocation;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.sound.BlockSoundGroup;
@ -17,7 +16,6 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
@ -26,6 +24,8 @@ import net.minecraft.world.event.GameEvent;
import su.a71.new_soviet.registration.NSE_Sounds;
import java.util.Objects;
public class SwitchBlock extends LeverBlock {
public static final BooleanProperty POWERED = Properties.POWERED;
protected static final VoxelShape NORTH_WALL_SHAPE = Block.createCuboidShape(5.5, 5.5, 15, 10.5, 10.5, 16);
@ -39,39 +39,29 @@ public class SwitchBlock extends LeverBlock {
public SwitchBlock(FabricBlockSettings fabricBlockSettings) {
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY).strength(1f, 2f).mapColor(MapColor.TERRACOTTA_WHITE).noCollision());
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(FACING, Direction.NORTH)).with(POWERED, false)).with(FACE, WallMountLocation.WALL));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(POWERED, false).with(FACE, WallMountLocation.WALL));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
switch ((WallMountLocation)state.get(FACE)) {
switch (state.get(FACE)) {
case FLOOR: {
switch (state.get(FACING).getAxis()) {
case X: {
return FLOOR_X_AXIS_SHAPE;
}
if (Objects.requireNonNull(state.get(FACING).getAxis()) == Direction.Axis.X) {
return FLOOR_X_AXIS_SHAPE;
}
return FLOOR_Z_AXIS_SHAPE;
}
case WALL: {
switch (state.get(FACING)) {
case EAST: {
return EAST_WALL_SHAPE;
}
case WEST: {
return WEST_WALL_SHAPE;
}
case SOUTH: {
return SOUTH_WALL_SHAPE;
}
}
return NORTH_WALL_SHAPE;
return switch (state.get(FACING)) {
case EAST -> EAST_WALL_SHAPE;
case WEST -> WEST_WALL_SHAPE;
case SOUTH -> SOUTH_WALL_SHAPE;
default -> NORTH_WALL_SHAPE;
};
}
}
switch (state.get(FACING).getAxis()) {
case X: {
return CEILING_X_AXIS_SHAPE;
}
if (Objects.requireNonNull(state.get(FACING).getAxis()) == Direction.Axis.X) {
return CEILING_X_AXIS_SHAPE;
}
return CEILING_Z_AXIS_SHAPE;
}
@ -79,13 +69,13 @@ public class SwitchBlock extends LeverBlock {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
BlockState blockState = (BlockState)state.cycle(POWERED);
state.cycle(POWERED);
return ActionResult.SUCCESS;
}
BlockState blockState = this.togglePower(state, world, pos);
float f = blockState.get(POWERED) ? 1f : 0.9f;
world.playSound(null, pos, NSE_Sounds.SWITCH_PRESS, SoundCategory.BLOCKS, 0.6f, f);
world.emitGameEvent((Entity)player, blockState.get(POWERED) ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
world.emitGameEvent(player, blockState.get(POWERED) ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
return ActionResult.CONSUME;
}
@ -98,14 +88,6 @@ public class SwitchBlock extends LeverBlock {
world.addParticle(new DustParticleEffect(DustParticleEffect.RED, alpha), d, e, f, 0.0, 0.0, 0.0);
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(POWERED) && random.nextFloat() < 0.25f) {
//SwitchBlock.spawnParticles(state, world, pos, 0.5f);
}
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACE, FACING, POWERED);

View file

@ -43,8 +43,7 @@ public class GoldenTableLampBlock extends LampBlock {
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction dir = state.get(FACING);
return switch (dir) {
return switch (state.get(FACING)) {
case NORTH -> SHAPE.north();
case SOUTH -> SHAPE.south();
case EAST -> SHAPE.east();
@ -65,11 +64,11 @@ public class GoldenTableLampBlock extends LampBlock {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {

View file

@ -11,7 +11,6 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
@ -65,7 +64,7 @@ public abstract class LampBlock extends Block implements Waterloggable {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
world.setBlockState(pos, (BlockState)state.cycle(INVERTED), 2);
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);
@ -73,7 +72,7 @@ public abstract class LampBlock extends Block implements Waterloggable {
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, WATERLOGGED, INVERTED});
builder.add(ON, WATERLOGGED, INVERTED);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -94,20 +93,20 @@ public abstract class LampBlock extends Block implements Waterloggable {
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.setBlockState(pos, state.cycle(ON), 2);
}
}
}
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
}
}

View file

@ -9,7 +9,6 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
@ -24,7 +23,6 @@ import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.blocks.lamps.LampBlock;
import su.a71.new_soviet.registration.NSE_Items;
import su.a71.new_soviet.registration.NSE_Sounds;
@ -47,7 +45,7 @@ public class LightBulbLampBlock extends LampBlock {
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return (BlockState)this.getDefaultState()
return this.getDefaultState()
.with(BROKEN, false);
}
@ -57,12 +55,12 @@ 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.setBlockState(pos, (BlockState)state.with(BROKEN, false));
world.setBlockState(pos, state.with(BROKEN, false));
return ActionResult.SUCCESS;
} else {
player.getItemCooldownManager().set(NSE_Items.LIGHT_BULB, 10);
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized").formatted(Formatting.YELLOW), true);
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
if (!player.isCreative()) {
player.damage(world.getDamageSources().lightningBolt(), NewSoviet.RANDOM.nextBetween(1, 4));
}
@ -79,14 +77,14 @@ public class LightBulbLampBlock extends LampBlock {
@Override
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
if (!state.get(BROKEN)) {
world.playSound((PlayerEntity)null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.LIGHT_BULB_BROKEN_SOUND, SoundCategory.NEUTRAL, 0.8f, 1f);
world.playSound(null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.LIGHT_BULB_BROKEN_SOUND, SoundCategory.NEUTRAL, 0.8f, 1f);
}
world.setBlockState(hit.getBlockPos(), (BlockState)state.with(BROKEN, true), 2);
world.setBlockState(hit.getBlockPos(), state.with(BROKEN, true), 2);
super.onProjectileHit(world, state, hit, projectile);
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, BROKEN, WATERLOGGED, INVERTED});
builder.add(ON, BROKEN, WATERLOGGED, INVERTED);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -10,7 +10,7 @@ import net.minecraft.world.WorldView;
import su.a71.new_soviet.blocks.lamps.LampBlock;
public class TableLampBlock extends LampBlock {
protected final VoxelShape SHAPE = getStandingShape();;
protected final VoxelShape SHAPE = getStandingShape();
public TableLampBlock(AbstractBlock.Settings settings) {
super(settings, true, null);

View file

@ -36,7 +36,7 @@ public class LampPostBaseBlock extends Block implements Waterloggable {
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
if (state.get(Properties.ATTACHED)) {
return SHAPE_ATTACHED;
};
}
return SHAPE_BASE;
}

View file

@ -9,7 +9,6 @@ import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
@ -37,8 +36,7 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction dir = state.get(FACING);
return switch (dir) {
return switch (state.get(FACING)) {
case NORTH -> SHAPE.north();
case SOUTH -> SHAPE.south();
case EAST -> SHAPE.east();
@ -70,7 +68,7 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{WATERLOGGED, Properties.HORIZONTAL_FACING});
builder.add(WATERLOGGED, Properties.HORIZONTAL_FACING);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -90,11 +88,11 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {