| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.util.BlockUtil;
|
| 5 | import net.minecraft.util.RandomSource;
|
| 6 | import net.minecraft.world.InteractionResult;
|
| 7 | import net.minecraft.world.entity.player.Player;
|
| 8 | import net.minecraft.world.level.BlockGetter;
|
| 9 | import net.minecraft.world.level.Level;
|
| 10 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 11 | import net.minecraft.world.level.block.state.BlockState;
|
| 12 | import net.minecraft.world.level.border.WorldBorder;
|
| 13 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 14 | import net.minecraft.world.phys.BlockHitResult;
|
| 15 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 16 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 17 |
|
| 18 | public class DragonEggBlock extends FallingBlock {
|
| 19 | public static final int HORIZONTAL_TELEPORT_RADIUS = 16;
|
| 20 | public static final int VERTICAL_TELEPORT_RADIUS = 8;
|
| 21 | private static final VoxelShape SHAPE = Block.column(14.0, 0.0, 16.0);
|
| 22 |
|
| 23 | public DragonEggBlock(final BlockBehaviour.Properties properties) {
|
| 24 | super(properties);
|
| 25 | }
|
| 26 |
|
| 27 | @Override
|
| 28 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 29 | return SHAPE;
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
|
| 34 | this.teleport(state, level, pos);
|
| 35 | return InteractionResult.SUCCESS;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | protected void attack(final BlockState state, final Level level, final BlockPos pos, final Player player) {
|
| 40 | this.teleport(state, level, pos);
|
| 41 | }
|
| 42 |
|
| 43 | private void teleport(final BlockState state, final Level level, final BlockPos pos) {
|
| 44 | if (!level.isClientSide()) {
|
| 45 | WorldBorder worldBorder = level.getWorldBorder();
|
| 46 | RandomSource random = level.getRandom();
|
| 47 |
|
| 48 | for (int i = 0; i < 1000; i++) {
|
| 49 | BlockPos testPos = pos.offset(random.nextInt(16) - random.nextInt(16), random.nextInt(8) - random.nextInt(8), random.nextInt(16) - random.nextInt(16));
|
| 50 | if (level.getBlockState(testPos).isAir()
|
| 51 | && !level.getBlockState(testPos.below()).isAir()
|
| 52 | && worldBorder.isWithinBounds(testPos)
|
| 53 | && level.isInsideBuildHeight(testPos)) {
|
| 54 | int packedDiff = BlockUtil.packDifferenceInPosition(pos, testPos, 16, 8, 16);
|
| 55 | level.levelEvent(2015, pos, packedDiff);
|
| 56 | level.setBlock(testPos, state, 2);
|
| 57 | level.removeBlock(pos, false);
|
| 58 | return;
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | protected int getDelayAfterPlace() {
|
| 66 | return 5;
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 71 | return false;
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public int getDustColor(final BlockState blockState, final BlockGetter level, final BlockPos pos) {
|
| 76 | return -16777216;
|
| 77 | }
|
| 78 | }
|
| 79 |
|