| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import com.mojang.math.OctahedralGroup;
|
| 4 | import java.util.Map;
|
| 5 | import net.minecraft.core.BlockPos;
|
| 6 | import net.minecraft.core.Direction;
|
| 7 | import net.minecraft.util.Util;
|
| 8 | import net.minecraft.world.InteractionResult;
|
| 9 | import net.minecraft.world.attribute.BedRule;
|
| 10 | import net.minecraft.world.attribute.EnvironmentAttribute;
|
| 11 | import net.minecraft.world.attribute.EnvironmentAttributes;
|
| 12 | import net.minecraft.world.entity.player.Player;
|
| 13 | import net.minecraft.world.item.DyeColor;
|
| 14 | import net.minecraft.world.level.BlockGetter;
|
| 15 | import net.minecraft.world.level.Level;
|
| 16 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.phys.Vec3;
|
| 19 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 20 | import net.minecraft.world.phys.shapes.Shapes;
|
| 21 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 22 |
|
| 23 | public class BedBlock extends AbstractBedBlock {
|
| 24 | private final DyeColor color;
|
| 25 | private static final Map<Direction, VoxelShape> SHAPES = Util.make(() -> {
|
| 26 | VoxelShape northWestLeg = Block.box(0.0, 0.0, 0.0, 3.0, 3.0, 3.0);
|
| 27 | VoxelShape northEastLeg = Shapes.rotate(northWestLeg, OctahedralGroup.BLOCK_ROT_Y_90);
|
| 28 | return Shapes.rotateHorizontal(Shapes.or(Block.column(16.0, 3.0, 9.0), northWestLeg, northEastLeg));
|
| 29 | });
|
| 30 |
|
| 31 | public BedBlock(final DyeColor color, final BlockBehaviour.Properties properties) {
|
| 32 | super(properties);
|
| 33 | this.color = color;
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 38 | return SHAPES.get(getConnectedDirection(state).getOpposite());
|
| 39 | }
|
| 40 |
|
| 41 | @Override
|
| 42 | protected EnvironmentAttribute<BedRule> getBedEnvironmentAttribute() {
|
| 43 | return EnvironmentAttributes.BED_RULE;
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | protected InteractionResult destroyOnUse(final BlockState state, final Level level, BlockPos pos, final Player player) {
|
| 48 | level.removeBlock(pos, false);
|
| 49 | BlockPos blockPos = pos.relative(state.getValue(FACING).getOpposite());
|
| 50 | if (level.getBlockState(blockPos).is(this)) {
|
| 51 | level.removeBlock(blockPos, false);
|
| 52 | }
|
| 53 |
|
| 54 | Vec3 boomPos = Vec3.atCenterOf(pos);
|
| 55 | level.explode(null, level.damageSources().badRespawnPointExplosion(boomPos), null, boomPos, 5.0F, true, Level.ExplosionInteraction.BLOCK);
|
| 56 | return InteractionResult.SUCCESS_SERVER;
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected void destroyOnLeave(final Level level, final BlockPos pos) {
|
| 61 | }
|
| 62 |
|
| 63 | public DyeColor getColor() {
|
| 64 | return this.color;
|
| 65 | }
|
| 66 | }
|
| 67 |
|