81 lines
3.1 KiB
Java
81 lines
3.1 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.BlockParticleOption;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.world.level.material.Material;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.item.FallingBlockEntity;
|
|
import java.util.Random;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class FallingBlock extends Block {
|
|
public FallingBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
bjt.getBlockTicks().scheduleTick(fk, this, this.getTickDelay(bjt));
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, this.getTickDelay(bju));
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (!isFree(xd.getBlockState(fk.below())) || fk.getY() < 0) {
|
|
return;
|
|
}
|
|
final FallingBlockEntity avx6 = new FallingBlockEntity(xd, fk.getX() + 0.5, fk.getY(), fk.getZ() + 0.5, xd.getBlockState(fk));
|
|
this.falling(avx6);
|
|
xd.addFreshEntity(avx6);
|
|
}
|
|
|
|
protected void falling(final FallingBlockEntity avx) {
|
|
}
|
|
|
|
@Override
|
|
public int getTickDelay(final LevelReader bjw) {
|
|
return 2;
|
|
}
|
|
|
|
public static boolean isFree(final BlockState byg) {
|
|
final Block bpe2 = byg.getBlock();
|
|
final Material cok3 = byg.getMaterial();
|
|
return byg.isAir() || bpe2 == Blocks.FIRE || cok3.isLiquid() || cok3.isReplaceable();
|
|
}
|
|
|
|
public void onLand(final Level bjt, final BlockPos fk, final BlockState byg3, final BlockState byg4) {
|
|
}
|
|
|
|
public void onBroken(final Level bjt, final BlockPos fk) {
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
|
|
if (random.nextInt(16) == 0) {
|
|
final BlockPos fk2 = fk.below();
|
|
if (isFree(bjt.getBlockState(fk2))) {
|
|
final double double7 = fk.getX() + (double)random.nextFloat();
|
|
final double double8 = fk.getY() - 0.05;
|
|
final double double9 = fk.getZ() + (double)random.nextFloat();
|
|
bjt.addParticle(new BlockParticleOption(ParticleTypes.FALLING_DUST, byg), double7, double8, double9, 0.0, 0.0, 0.0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public int getDustColor(final BlockState byg) {
|
|
return -16777216;
|
|
}
|
|
}
|