package ru.betterend.blocks; import java.util.Random; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FluidDrainable; import net.minecraft.block.FluidFillable; import net.minecraft.block.Material; import net.minecraft.block.ShapeContext; import net.minecraft.entity.Entity; import net.minecraft.fluid.Fluid; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; import net.minecraft.particle.ParticleTypes; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; 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 ru.betterend.blocks.basis.BlockBaseNotFull; import ru.betterend.registry.EndBlocks; import ru.betterend.util.BlocksHelper; public class BlockVentBubbleColumn extends BlockBaseNotFull implements FluidDrainable, FluidFillable { public BlockVentBubbleColumn() { super(FabricBlockSettings.of(Material.BUBBLE_COLUMN).nonOpaque().noCollision().dropsNothing()); } @Override public Fluid tryDrainFluid(WorldAccess world, BlockPos pos, BlockState state) { world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11); return Fluids.WATER; } @Override public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.INVISIBLE; } @Override public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { BlockState blockState = world.getBlockState(pos.down()); return blockState.isOf(this) || blockState.isOf(EndBlocks.HYDROTHERMAL_VENT); } @Override public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return VoxelShapes.empty(); } @Override public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { if (!state.canPlaceAt(world, pos)) { return Blocks.WATER.getDefaultState(); } else { BlockPos up = pos.up(); if (world.getBlockState(up).isOf(Blocks.WATER)) { BlocksHelper.setWithoutUpdate(world, up, this); world.getBlockTickScheduler().schedule(up, this, 5); } } return state; } @Environment(EnvType.CLIENT) public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) { if (random.nextInt(4) == 0) { double px = pos.getX() + random.nextDouble(); double py = pos.getY() + random.nextDouble(); double pz = pos.getZ() + random.nextDouble(); world.addImportantParticle(ParticleTypes.BUBBLE_COLUMN_UP, px, py, pz, 0, 0.04, 0); } if (random.nextInt(200) == 0) { world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_BUBBLE_COLUMN_UPWARDS_AMBIENT, SoundCategory.BLOCKS, 0.2F + random.nextFloat() * 0.2F, 0.9F + random.nextFloat() * 0.15F, false); } } @Environment(EnvType.CLIENT) public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) { BlockState blockState = world.getBlockState(pos.up()); if (blockState.isAir()) { entity.onBubbleColumnSurfaceCollision(false); if (!world.isClient) { ServerWorld serverWorld = (ServerWorld) world; for (int i = 0; i < 2; ++i) { serverWorld.spawnParticles(ParticleTypes.SPLASH, (double) pos.getX() + world.random.nextDouble(), (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.0D, 0.0D, 1.0D); serverWorld.spawnParticles(ParticleTypes.BUBBLE, (double) pos.getX() + world.random.nextDouble(), (double) (pos.getY() + 1), (double) pos.getZ() + world.random.nextDouble(), 1, 0.0D, 0.01D, 0.0D, 0.2D); } } } else { entity.onBubbleColumnCollision(false); } } @Override public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) { return false; } @Override public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) { return false; } @Override public FluidState getFluidState(BlockState state) { return Fluids.WATER.getStill(false); } }