minecraft-source/src/net/minecraft/world/level/block/CocoaBlock.java

123 lines
5.8 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.block.state.StateDefinition;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.LevelReader;
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.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
public class CocoaBlock extends HorizontalDirectionalBlock implements BonemealableBlock {
public static final IntegerProperty AGE;
protected static final VoxelShape[] EAST_AABB;
protected static final VoxelShape[] WEST_AABB;
protected static final VoxelShape[] NORTH_AABB;
protected static final VoxelShape[] SOUTH_AABB;
public CocoaBlock(final Properties c) {
super(c);
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)CocoaBlock.FACING, Direction.NORTH)).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, 0));
}
@Override
public void tick(final BlockState byg, final ServerLevel xd, final BlockPos fk, final Random random) {
if (xd.random.nextInt(5) == 0) {
final int integer6 = byg.<Integer>getValue((Property<Integer>)CocoaBlock.AGE);
if (integer6 < 2) {
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, integer6 + 1), 2);
}
}
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
final Block bpe5 = bjw.getBlockState(fk.relative(byg.<Direction>getValue((Property<Direction>)CocoaBlock.FACING))).getBlock();
return bpe5.is(BlockTags.JUNGLE_LOGS);
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
final int integer6 = byg.<Integer>getValue((Property<Integer>)CocoaBlock.AGE);
switch (byg.<Direction>getValue((Property<Direction>)CocoaBlock.FACING)) {
case SOUTH: {
return CocoaBlock.SOUTH_AABB[integer6];
}
default: {
return CocoaBlock.NORTH_AABB[integer6];
}
case WEST: {
return CocoaBlock.WEST_AABB[integer6];
}
case EAST: {
return CocoaBlock.EAST_AABB[integer6];
}
}
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
BlockState byg3 = this.defaultBlockState();
final LevelReader bjw4 = bcn.getLevel();
final BlockPos fk5 = bcn.getClickedPos();
for (final Direction fp9 : bcn.getNearestLookingDirections()) {
if (fp9.getAxis().isHorizontal()) {
byg3 = ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Direction>setValue((Property<Comparable>)CocoaBlock.FACING, fp9);
if (byg3.canSurvive(bjw4, fk5)) {
return byg3;
}
}
}
return null;
}
@Override
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
if (fp == byg1.<Direction>getValue((Property<Direction>)CocoaBlock.FACING) && !byg1.canSurvive(bju, fk5)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
@Override
public boolean isValidBonemealTarget(final BlockGetter bjd, final BlockPos fk, final BlockState byg, final boolean boolean4) {
return byg.<Integer>getValue((Property<Integer>)CocoaBlock.AGE) < 2;
}
@Override
public boolean isBonemealSuccess(final Level bjt, final Random random, final BlockPos fk, final BlockState byg) {
return true;
}
@Override
public void performBonemeal(final ServerLevel xd, final Random random, final BlockPos fk, final BlockState byg) {
xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)CocoaBlock.AGE, byg.<Integer>getValue((Property<Integer>)CocoaBlock.AGE) + 1), 2);
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(CocoaBlock.FACING, CocoaBlock.AGE);
}
static {
AGE = BlockStateProperties.AGE_2;
EAST_AABB = new VoxelShape[] { Block.box(11.0, 7.0, 6.0, 15.0, 12.0, 10.0), Block.box(9.0, 5.0, 5.0, 15.0, 12.0, 11.0), Block.box(7.0, 3.0, 4.0, 15.0, 12.0, 12.0) };
WEST_AABB = new VoxelShape[] { Block.box(1.0, 7.0, 6.0, 5.0, 12.0, 10.0), Block.box(1.0, 5.0, 5.0, 7.0, 12.0, 11.0), Block.box(1.0, 3.0, 4.0, 9.0, 12.0, 12.0) };
NORTH_AABB = new VoxelShape[] { Block.box(6.0, 7.0, 1.0, 10.0, 12.0, 5.0), Block.box(5.0, 5.0, 1.0, 11.0, 12.0, 7.0), Block.box(4.0, 3.0, 1.0, 12.0, 12.0, 9.0) };
SOUTH_AABB = new VoxelShape[] { Block.box(6.0, 7.0, 11.0, 10.0, 12.0, 15.0), Block.box(5.0, 5.0, 9.0, 11.0, 12.0, 15.0), Block.box(4.0, 3.0, 7.0, 12.0, 12.0, 15.0) };
}
}