94 lines
4.6 KiB
Java
94 lines
4.6 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.core.Direction;
|
|
import java.util.Map;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
public class BaseCoralWallFanBlock extends BaseCoralFanBlock {
|
|
public static final DirectionProperty FACING;
|
|
private static final Map<Direction, VoxelShape> SHAPES;
|
|
|
|
protected BaseCoralWallFanBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)BaseCoralWallFanBlock.WATERLOGGED, true));
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return BaseCoralWallFanBlock.SHAPES.get(byg.getValue((Property<Object>)BaseCoralWallFanBlock.FACING));
|
|
}
|
|
|
|
@Override
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(BaseCoralWallFanBlock.FACING, BaseCoralWallFanBlock.WATERLOGGED);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (byg1.<Boolean>getValue((Property<Boolean>)BaseCoralWallFanBlock.WATERLOGGED)) {
|
|
bju.getLiquidTicks().scheduleTick(fk5, Fluids.WATER, Fluids.WATER.getTickDelay(bju));
|
|
}
|
|
if (fp.getOpposite() == byg1.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING) && !byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return byg1;
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
final Direction fp5 = byg.<Direction>getValue((Property<Direction>)BaseCoralWallFanBlock.FACING);
|
|
final BlockPos fk2 = fk.relative(fp5.getOpposite());
|
|
final BlockState byg2 = bjw.getBlockState(fk2);
|
|
return byg2.isFaceSturdy(bjw, fk2, fp5);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
BlockState byg3 = super.getStateForPlacement(bcn);
|
|
final LevelReader bjw4 = bcn.getLevel();
|
|
final BlockPos fk5 = bcn.getClickedPos();
|
|
final Direction[] nearestLookingDirections;
|
|
final Direction[] arr6 = nearestLookingDirections = bcn.getNearestLookingDirections();
|
|
for (final Direction fp10 : nearestLookingDirections) {
|
|
if (fp10.getAxis().isHorizontal()) {
|
|
byg3 = ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, fp10.getOpposite());
|
|
if (byg3.canSurvive(bjw4, fk5)) {
|
|
return byg3;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static {
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
SHAPES = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(0.0, 4.0, 5.0, 16.0, 12.0, 16.0), Direction.SOUTH, Block.box(0.0, 4.0, 0.0, 16.0, 12.0, 11.0), Direction.WEST, Block.box(5.0, 4.0, 0.0, 16.0, 12.0, 16.0), Direction.EAST, Block.box(0.0, 4.0, 0.0, 11.0, 12.0, 16.0)));
|
|
}
|
|
}
|