133 lines
5.6 KiB
Java
133 lines
5.6 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.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.core.Vec3i;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.Level;
|
|
import java.util.Random;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
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;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class LeavesBlock extends Block {
|
|
public static final IntegerProperty DISTANCE;
|
|
public static final BooleanProperty PERSISTENT;
|
|
|
|
public LeavesBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)LeavesBlock.DISTANCE, 7)).<Comparable, Boolean>setValue((Property<Comparable>)LeavesBlock.PERSISTENT, false));
|
|
}
|
|
|
|
@Override
|
|
public boolean isRandomlyTicking(final BlockState byg) {
|
|
return byg.<Integer>getValue((Property<Integer>)LeavesBlock.DISTANCE) == 7 && !byg.<Boolean>getValue((Property<Boolean>)LeavesBlock.PERSISTENT);
|
|
}
|
|
|
|
@Override
|
|
public void randomTick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
if (!byg.<Boolean>getValue((Property<Boolean>)LeavesBlock.PERSISTENT) && byg.<Integer>getValue((Property<Integer>)LeavesBlock.DISTANCE) == 7) {
|
|
Block.dropResources(byg, xd, fk);
|
|
xd.removeBlock(fk, false);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
|
|
xd.setBlock(fk, updateDistance(byg, xd, fk), 3);
|
|
}
|
|
|
|
@Override
|
|
public int getLightBlock(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return 1;
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
final int integer8 = getDistanceAt(byg3) + 1;
|
|
if (integer8 != 1 || byg1.<Integer>getValue((Property<Integer>)LeavesBlock.DISTANCE) != integer8) {
|
|
bju.getBlockTicks().scheduleTick(fk5, this, 1);
|
|
}
|
|
return byg1;
|
|
}
|
|
|
|
private static BlockState updateDistance(final BlockState byg, final LevelAccessor bju, final BlockPos fk) {
|
|
int integer4 = 7;
|
|
try (final BlockPos.PooledMutableBlockPos b5 = BlockPos.PooledMutableBlockPos.acquire()) {
|
|
for (final Direction fp10 : Direction.values()) {
|
|
b5.set((Vec3i)fk).move(fp10);
|
|
integer4 = Math.min(integer4, getDistanceAt(bju.getBlockState(b5)) + 1);
|
|
if (integer4 == 1) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)LeavesBlock.DISTANCE, integer4);
|
|
}
|
|
|
|
private static int getDistanceAt(final BlockState byg) {
|
|
if (BlockTags.LOGS.contains(byg.getBlock())) {
|
|
return 0;
|
|
}
|
|
if (byg.getBlock() instanceof LeavesBlock) {
|
|
return byg.<Integer>getValue((Property<Integer>)LeavesBlock.DISTANCE);
|
|
}
|
|
return 7;
|
|
}
|
|
|
|
@Override
|
|
public void animateTick(final BlockState byg, final Level bjt, final BlockPos fk, final Random random) {
|
|
if (!bjt.isRainingAt(fk.above())) {
|
|
return;
|
|
}
|
|
if (random.nextInt(15) != 1) {
|
|
return;
|
|
}
|
|
final BlockPos fk2 = fk.below();
|
|
final BlockState byg2 = bjt.getBlockState(fk2);
|
|
if (byg2.canOcclude() && byg2.isFaceSturdy(bjt, fk2, Direction.UP)) {
|
|
return;
|
|
}
|
|
final double double8 = fk.getX() + random.nextFloat();
|
|
final double double9 = fk.getY() - 0.05;
|
|
final double double10 = fk.getZ() + random.nextFloat();
|
|
bjt.addParticle(ParticleTypes.DRIPPING_WATER, double8, double9, double10, 0.0, 0.0, 0.0);
|
|
}
|
|
|
|
@Override
|
|
public boolean isSuffocating(final BlockState byg, final BlockGetter bjd, final BlockPos fk) {
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidSpawn(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final EntityType<?> akr) {
|
|
return akr == EntityType.OCELOT || akr == EntityType.PARROT;
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(LeavesBlock.DISTANCE, LeavesBlock.PERSISTENT);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
return updateDistance(((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)LeavesBlock.PERSISTENT, true), bcn.getLevel(), bcn.getClickedPos());
|
|
}
|
|
|
|
static {
|
|
DISTANCE = BlockStateProperties.DISTANCE;
|
|
PERSISTENT = BlockStateProperties.PERSISTENT;
|
|
}
|
|
}
|