diff --git a/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java b/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java index 1de6289..16f8838 100644 --- a/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java @@ -1,10 +1,13 @@ package su.a71.new_soviet.blocks; import net.minecraft.block.*; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; 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; @@ -13,25 +16,29 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; import net.minecraft.block.RedstoneLampBlock; import net.minecraft.block.TorchBlock; import org.jetbrains.annotations.Nullable; -public class CeilingFanBlock extends Block { +public class CeilingFanBlock extends Block implements Waterloggable { protected static final VoxelShape SHAPE; public static final BooleanProperty ON; + public static final BooleanProperty WATERLOGGED; public CeilingFanBlock(Block.Settings settings) { super(settings); - this.setDefaultState((BlockState)this.getDefaultState().with(ON, false)); + this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(WATERLOGGED, false)); } @Nullable public BlockState getPlacementState(ItemPlacementContext ctx) { - return (BlockState)this.getDefaultState().with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); + return (BlockState)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) { @@ -44,10 +51,17 @@ public class CeilingFanBlock extends Block { world.setBlockState(pos, (BlockState)state.cycle(ON), 2); } } - } } + @Override + public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (state.get(WATERLOGGED)) { + world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + } + return direction == Direction.UP && !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + 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); @@ -55,13 +69,17 @@ public class CeilingFanBlock extends Block { } protected void appendProperties(StateManager.Builder builder) { - builder.add(new Property[]{ON}); + builder.add(new Property[]{ON, WATERLOGGED}); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return SHAPE; } + public FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + } + public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { Direction direction = Direction.UP; return Block.sideCoversSmallSquare(world, pos.offset(direction), direction.getOpposite()); @@ -70,5 +88,6 @@ public class CeilingFanBlock extends Block { static { SHAPE = VoxelShapes.union(Block.createCuboidShape(4.0, 2.0, 4.0, 12.0, 7.0, 12.0), Block.createCuboidShape(7.0, 7.0, 7.0, 9.0, 13.0, 9.0), Block.createCuboidShape(6.0, 13.0, 6.0, 10.0, 16.0, 10.0)); ON = RedstoneTorchBlock.LIT; + WATERLOGGED = Properties.WATERLOGGED; } } \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java index 7e28816..2fe414a 100644 --- a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java @@ -3,6 +3,8 @@ package su.a71.new_soviet.blocks; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; @@ -10,6 +12,8 @@ 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; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -18,23 +22,28 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; 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; import su.a71.new_soviet.registration.NSE_Custom; -public class LightBulbBlock extends Block { +public class LightBulbBlock extends Block implements Waterloggable { protected static final VoxelShape SHAPE; public static final BooleanProperty ON; public static final BooleanProperty BROKEN; + public static final BooleanProperty WATERLOGGED; public LightBulbBlock(Block.Settings settings) { - super(settings); - this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(BROKEN, false)); + super(settings.luminance((BlockState state) -> state.get(ON) && !state.get(BROKEN) ? 12 : 0)); + this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(BROKEN, false).with(WATERLOGGED, false)); } @Nullable public BlockState getPlacementState(ItemPlacementContext ctx) { - return (BlockState)this.getDefaultState().with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())).with(BROKEN, false); + return (BlockState)this.getDefaultState() + .with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())) + .with(BROKEN, false) + .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) { @@ -50,6 +59,22 @@ public class LightBulbBlock extends Block { } } + @Override + public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { + if (state.get(WATERLOGGED)) { + world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); + } + return direction == Direction.UP && !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { +// if (!world.isClient && !state.get(BROKEN)) { +// world.setBlockState(pos, (BlockState)state.with(ON, !state.get(ON)), 1); +// } + return super.onUse(state, world, pos, player, hand, hit); + } + @Override public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) { if (!state.get(BROKEN)) { @@ -66,7 +91,11 @@ public class LightBulbBlock extends Block { } protected void appendProperties(StateManager.Builder builder) { - builder.add(new Property[]{ON, BROKEN}); + builder.add(new Property[]{ON, BROKEN, WATERLOGGED}); + } + + public FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { @@ -86,5 +115,6 @@ public class LightBulbBlock extends Block { SHAPE = VoxelShapes.union(Block.createCuboidShape(7, 15, 7, 9, 16, 9), Block.createCuboidShape(7, 6, 7, 9, 8, 9)); //VoxelShapes.union(Block.createCuboidShape(4.0, 2.0, 4.0, 12.0, 7.0, 12.0), Block.createCuboidShape(7.0, 7.0, 7.0, 9.0, 13.0, 9.0), Block.createCuboidShape(6.0, 13.0, 6.0, 10.0, 16.0, 10.0)); ON = RedstoneTorchBlock.LIT; BROKEN = Properties.CRACKED; + WATERLOGGED = Properties.WATERLOGGED; } } \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java b/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java index 9b6a378..9d87d0d 100644 --- a/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java @@ -90,11 +90,10 @@ public class SirenBlock extends HorizontalFacingBlock { public float getSirenVolume(World world, BlockPos pos) { return switch (world.getReceivedRedstonePower(pos)) { - case 1, 2, 3 -> 2f; - case 4, 5, 6 -> 3f; - case 7, 8, 9 -> 4f; - case 10, 11, 12 -> 5f; - case 13, 14, 15, 16 -> 6f; + case 4, 5, 6 -> 2f; + case 7, 8, 9 -> 3f; + case 10, 11, 12 -> 4f; + case 13, 14, 15, 16 -> 5f; default -> 1f; }; }