162 lines
7.5 KiB
Java
162 lines
7.5 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.material.Fluid;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import java.util.Random;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.core.particles.SimpleParticleType;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|
|
|
public class BubbleColumnBlock extends Block implements BucketPickup {
|
|
public static final BooleanProperty DRAG_DOWN;
|
|
|
|
public BubbleColumnBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Boolean>setValue((Property<Comparable>)BubbleColumnBlock.DRAG_DOWN, true));
|
|
}
|
|
|
|
@Override
|
|
public void entityInside(final BlockState byg, final Level bjt, final BlockPos fk, final Entity akn) {
|
|
final BlockState byg2 = bjt.getBlockState(fk.above());
|
|
if (byg2.isAir()) {
|
|
akn.onAboveBubbleCol(byg.<Boolean>getValue((Property<Boolean>)BubbleColumnBlock.DRAG_DOWN));
|
|
if (!bjt.isClientSide) {
|
|
final ServerLevel xd7 = (ServerLevel)bjt;
|
|
for (int integer8 = 0; integer8 < 2; ++integer8) {
|
|
xd7.<SimpleParticleType>sendParticles(ParticleTypes.SPLASH, fk.getX() + bjt.random.nextFloat(), fk.getY() + 1, fk.getZ() + bjt.random.nextFloat(), 1, 0.0, 0.0, 0.0, 1.0);
|
|
xd7.<SimpleParticleType>sendParticles(ParticleTypes.BUBBLE, fk.getX() + bjt.random.nextFloat(), fk.getY() + 1, fk.getZ() + bjt.random.nextFloat(), 1, 0.0, 0.01, 0.0, 0.2);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
akn.onInsideBubbleColumn(byg.<Boolean>getValue((Property<Boolean>)BubbleColumnBlock.DRAG_DOWN));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
growColumn(bjt, fk.above(), getDrag(bjt, fk.below()));
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
growColumn(xd, fk.above(), getDrag(xd, fk));
|
|
}
|
|
|
|
@Override
|
|
public FluidState getFluidState(final BlockState byg) {
|
|
return Fluids.WATER.getSource(false);
|
|
}
|
|
|
|
public static void growColumn(final LevelAccessor bju, final BlockPos fk, final boolean boolean3) {
|
|
if (canExistIn(bju, fk)) {
|
|
bju.setBlock(fk, ((AbstractStateHolder<O, BlockState>)Blocks.BUBBLE_COLUMN.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)BubbleColumnBlock.DRAG_DOWN, boolean3), 2);
|
|
}
|
|
}
|
|
|
|
public static boolean canExistIn(final LevelAccessor bju, final BlockPos fk) {
|
|
final FluidState cog3 = bju.getFluidState(fk);
|
|
return bju.getBlockState(fk).getBlock() == Blocks.WATER && cog3.getAmount() >= 8 && cog3.isSource();
|
|
}
|
|
|
|
private static boolean getDrag(final BlockGetter bjd, final BlockPos fk) {
|
|
final BlockState byg3 = bjd.getBlockState(fk);
|
|
final Block bpe4 = byg3.getBlock();
|
|
if (bpe4 == Blocks.BUBBLE_COLUMN) {
|
|
return byg3.<Boolean>getValue((Property<Boolean>)BubbleColumnBlock.DRAG_DOWN);
|
|
}
|
|
return bpe4 != Blocks.SOUL_SAND;
|
|
}
|
|
|
|
@Override
|
|
public int getTickDelay(final LevelReader bjw) {
|
|
return 5;
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
|
|
final double double6 = fk.getX();
|
|
final double double7 = fk.getY();
|
|
final double double8 = fk.getZ();
|
|
if (byg.<Boolean>getValue((Property<Boolean>)BubbleColumnBlock.DRAG_DOWN)) {
|
|
bjt.addAlwaysVisibleParticle(ParticleTypes.CURRENT_DOWN, double6 + 0.5, double7 + 0.8, double8, 0.0, 0.0, 0.0);
|
|
if (random.nextInt(200) == 0) {
|
|
bjt.playLocalSound(double6, double7, double8, SoundEvents.BUBBLE_COLUMN_WHIRLPOOL_AMBIENT, SoundSource.BLOCKS, 0.2f + random.nextFloat() * 0.2f, 0.9f + random.nextFloat() * 0.15f, false);
|
|
}
|
|
}
|
|
else {
|
|
bjt.addAlwaysVisibleParticle(ParticleTypes.BUBBLE_COLUMN_UP, double6 + 0.5, double7, double8 + 0.5, 0.0, 0.04, 0.0);
|
|
bjt.addAlwaysVisibleParticle(ParticleTypes.BUBBLE_COLUMN_UP, double6 + random.nextFloat(), double7 + random.nextFloat(), double8 + random.nextFloat(), 0.0, 0.04, 0.0);
|
|
if (random.nextInt(200) == 0) {
|
|
bjt.playLocalSound(double6, double7, double8, SoundEvents.BUBBLE_COLUMN_UPWARDS_AMBIENT, SoundSource.BLOCKS, 0.2f + random.nextFloat() * 0.2f, 0.9f + random.nextFloat() * 0.15f, false);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (!byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.WATER.defaultBlockState();
|
|
}
|
|
if (fp == Direction.DOWN) {
|
|
bju.setBlock(fk5, ((AbstractStateHolder<O, BlockState>)Blocks.BUBBLE_COLUMN.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)BubbleColumnBlock.DRAG_DOWN, getDrag(bju, fk6)), 2);
|
|
}
|
|
else if (fp == Direction.UP && byg3.getBlock() != Blocks.BUBBLE_COLUMN && canExistIn(bju, fk6)) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, this.getTickDelay(bju));
|
|
}
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final Block bpe5 = bjw.getBlockState(fk.below()).getBlock();
|
|
return bpe5 == Blocks.BUBBLE_COLUMN || bpe5 == Blocks.MAGMA_BLOCK || bpe5 == Blocks.SOUL_SAND;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return Shapes.empty();
|
|
}
|
|
|
|
@Override
|
|
public RenderShape getRenderShape(final BlockState byg) {
|
|
return RenderShape.INVISIBLE;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(BubbleColumnBlock.DRAG_DOWN);
|
|
}
|
|
|
|
@Override
|
|
public Fluid takeLiquid(final LevelAccessor bju, final BlockPos fk, final BlockState byg) {
|
|
bju.setBlock(fk, Blocks.AIR.defaultBlockState(), 11);
|
|
return Fluids.WATER;
|
|
}
|
|
|
|
static {
|
|
DRAG_DOWN = BlockStateProperties.DRAG;
|
|
}
|
|
}
|