78 lines
3.4 KiB
Java
78 lines
3.4 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.LevelAccessor;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.AttachFace;
|
|
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
|
|
|
public class FaceAttachedHorizontalDirectionalBlock extends HorizontalDirectionalBlock {
|
|
public static final EnumProperty<AttachFace> FACE;
|
|
|
|
protected FaceAttachedHorizontalDirectionalBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
return canAttach(bjw, fk, getConnectedDirection(byg).getOpposite());
|
|
}
|
|
|
|
public static boolean canAttach(final LevelReader bjw, final BlockPos fk, final Direction fp) {
|
|
final BlockPos fk2 = fk.relative(fp);
|
|
return bjw.getBlockState(fk2).isFaceSturdy(bjw, fk2, fp.getOpposite());
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
for (final Direction fp6 : bcn.getNearestLookingDirections()) {
|
|
BlockState byg7;
|
|
if (fp6.getAxis() == Direction.Axis.Y) {
|
|
byg7 = (((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue(FaceAttachedHorizontalDirectionalBlock.FACE, (fp6 == Direction.UP) ? AttachFace.CEILING : AttachFace.FLOOR)).<Comparable, Direction>setValue((Property<Comparable>)FaceAttachedHorizontalDirectionalBlock.FACING, bcn.getHorizontalDirection());
|
|
}
|
|
else {
|
|
byg7 = (((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).setValue(FaceAttachedHorizontalDirectionalBlock.FACE, AttachFace.WALL)).<Comparable, Direction>setValue((Property<Comparable>)FaceAttachedHorizontalDirectionalBlock.FACING, fp6.getOpposite());
|
|
}
|
|
if (byg7.canSurvive(bcn.getLevel(), bcn.getClickedPos())) {
|
|
return byg7;
|
|
}
|
|
}
|
|
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 (getConnectedDirection(byg1).getOpposite() == fp && !byg1.canSurvive(bju, fk5)) {
|
|
return Blocks.AIR.defaultBlockState();
|
|
}
|
|
return super.updateShape(byg1, fp, byg3, bju, fk5, fk6);
|
|
}
|
|
|
|
protected static Direction getConnectedDirection(final BlockState byg) {
|
|
switch (byg.<AttachFace>getValue(FaceAttachedHorizontalDirectionalBlock.FACE)) {
|
|
case CEILING: {
|
|
return Direction.DOWN;
|
|
}
|
|
case FLOOR: {
|
|
return Direction.UP;
|
|
}
|
|
default: {
|
|
return byg.<Direction>getValue((Property<Direction>)FaceAttachedHorizontalDirectionalBlock.FACING);
|
|
}
|
|
}
|
|
}
|
|
|
|
static {
|
|
FACE = BlockStateProperties.ATTACH_FACE;
|
|
}
|
|
}
|