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

97 lines
4.8 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 net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
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.level.block.state.properties.WoodType;
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 WallSignBlock extends SignBlock {
public static final DirectionProperty FACING;
private static final Map<Direction, VoxelShape> AABBS;
public WallSignBlock(final Properties c, final WoodType bzp) {
super(c, bzp);
this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)WallSignBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)WallSignBlock.WATERLOGGED, false));
}
@Override
public String getDescriptionId() {
return this.asItem().getDescriptionId();
}
@Override
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
return WallSignBlock.AABBS.get(byg.getValue((Property<Object>)WallSignBlock.FACING));
}
@Override
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
return bjw.getBlockState(fk.relative(byg.<Direction>getValue((Property<Direction>)WallSignBlock.FACING).getOpposite())).getMaterial().isSolid();
}
@Nullable
@Override
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
BlockState byg3 = this.defaultBlockState();
final FluidState cog4 = bcn.getLevel().getFluidState(bcn.getClickedPos());
final LevelReader bjw5 = bcn.getLevel();
final BlockPos fk6 = bcn.getClickedPos();
final Direction[] nearestLookingDirections;
final Direction[] arr7 = nearestLookingDirections = bcn.getNearestLookingDirections();
for (final Direction fp11 : nearestLookingDirections) {
if (fp11.getAxis().isHorizontal()) {
final Direction fp12 = fp11.getOpposite();
byg3 = ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Direction>setValue((Property<Comparable>)WallSignBlock.FACING, fp12);
if (byg3.canSurvive(bjw5, fk6)) {
return ((AbstractStateHolder<O, BlockState>)byg3).<Comparable, Boolean>setValue((Property<Comparable>)WallSignBlock.WATERLOGGED, cog4.getType() == Fluids.WATER);
}
}
}
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.getOpposite() == byg1.<Direction>getValue((Property<Direction>)WallSignBlock.FACING) && !byg1.canSurvive(bju, fk5)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
}
@Override
public BlockState rotate(final BlockState byg, final Rotation btr) {
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)WallSignBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)WallSignBlock.FACING)));
}
@Override
public BlockState mirror(final BlockState byg, final Mirror bsr) {
return byg.rotate(bsr.getRotation(byg.<Direction>getValue((Property<Direction>)WallSignBlock.FACING)));
}
@Override
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
a.add(WallSignBlock.FACING, WallSignBlock.WATERLOGGED);
}
static {
FACING = HorizontalDirectionalBlock.FACING;
AABBS = Maps.<Direction, Object>newEnumMap(ImmutableMap.<Direction, VoxelShape>of(Direction.NORTH, Block.box(0.0, 4.5, 14.0, 16.0, 12.5, 16.0), Direction.SOUTH, Block.box(0.0, 4.5, 0.0, 16.0, 12.5, 2.0), Direction.EAST, Block.box(0.0, 4.5, 0.0, 2.0, 12.5, 16.0), Direction.WEST, Block.box(14.0, 4.5, 0.0, 16.0, 12.5, 16.0)));
}
}