81 lines
3.6 KiB
Java
81 lines
3.6 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import com.google.common.collect.Maps;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.util.Mth;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.LevelReader;
|
|
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.world.item.DyeColor;
|
|
import java.util.Map;
|
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
|
|
|
public class BannerBlock extends AbstractBannerBlock {
|
|
public static final IntegerProperty ROTATION;
|
|
private static final Map<DyeColor, Block> BY_COLOR;
|
|
private static final VoxelShape SHAPE;
|
|
|
|
public BannerBlock(final DyeColor bdg, final Properties c) {
|
|
super(bdg, c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, 0));
|
|
BannerBlock.BY_COLOR.put(bdg, this);
|
|
}
|
|
|
|
@Override
|
|
public boolean canSurvive(final BlockState byg, final LevelReader bjw, final BlockPos fk) {
|
|
return bjw.getBlockState(fk.below()).getMaterial().isSolid();
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return BannerBlock.SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, Mth.floor((180.0f + bcn.getRotation()) * 16.0f / 360.0f + 0.5) & 0xF);
|
|
}
|
|
|
|
@Override
|
|
public BlockState updateShape(final BlockState byg1, final Direction fp, final BlockState byg3, final LevelAccessor bju, final BlockPos fk5, final BlockPos fk6) {
|
|
if (fp == Direction.DOWN && !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, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, btr.rotate(byg.<Integer>getValue((Property<Integer>)BannerBlock.ROTATION), 16));
|
|
}
|
|
|
|
@Override
|
|
public BlockState mirror(final BlockState byg, final Mirror bsr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Integer>setValue((Property<Comparable>)BannerBlock.ROTATION, bsr.mirror(byg.<Integer>getValue((Property<Integer>)BannerBlock.ROTATION), 16));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(BannerBlock.ROTATION);
|
|
}
|
|
|
|
public static Block byColor(final DyeColor bdg) {
|
|
return BannerBlock.BY_COLOR.getOrDefault(bdg, Blocks.WHITE_BANNER);
|
|
}
|
|
|
|
static {
|
|
ROTATION = BlockStateProperties.ROTATION_16;
|
|
BY_COLOR = Maps.newHashMap();
|
|
SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 16.0, 12.0);
|
|
}
|
|
}
|