package net.minecraft.world.level.block;

import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
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.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;

public class DragonEggBlock extends FallingBlock {
    protected static final VoxelShape SHAPE;
    
    public DragonEggBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public VoxelShape getShape(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final CollisionContext cvq) {
        return DragonEggBlock.SHAPE;
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        this.teleport(byj, bjw, fk);
        return InteractionResult.SUCCESS;
    }
    
    @Override
    public void attack(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj) {
        this.teleport(byj, bjw, fk);
    }
    
    private void teleport(final BlockState byj, final Level bjw, final BlockPos fk) {
        for (int integer5 = 0; integer5 < 1000; ++integer5) {
            final BlockPos fk2 = fk.offset(bjw.random.nextInt(16) - bjw.random.nextInt(16), bjw.random.nextInt(8) - bjw.random.nextInt(8), bjw.random.nextInt(16) - bjw.random.nextInt(16));
            if (bjw.getBlockState(fk2).isAir()) {
                if (bjw.isClientSide) {
                    for (int integer6 = 0; integer6 < 128; ++integer6) {
                        final double double8 = bjw.random.nextDouble();
                        final float float10 = (bjw.random.nextFloat() - 0.5f) * 0.2f;
                        final float float11 = (bjw.random.nextFloat() - 0.5f) * 0.2f;
                        final float float12 = (bjw.random.nextFloat() - 0.5f) * 0.2f;
                        final double double9 = Mth.lerp(double8, fk2.getX(), fk.getX()) + (bjw.random.nextDouble() - 0.5) + 0.5;
                        final double double10 = Mth.lerp(double8, fk2.getY(), fk.getY()) + bjw.random.nextDouble() - 0.5;
                        final double double11 = Mth.lerp(double8, fk2.getZ(), fk.getZ()) + (bjw.random.nextDouble() - 0.5) + 0.5;
                        bjw.addParticle(ParticleTypes.PORTAL, double9, double10, double11, float10, float11, float12);
                    }
                }
                else {
                    bjw.setBlock(fk2, byj, 2);
                    bjw.removeBlock(fk, false);
                }
                return;
            }
        }
    }
    
    @Override
    public int getTickDelay(final LevelReader bjz) {
        return 5;
    }
    
    @Override
    public boolean isPathfindable(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final PathComputationType cqr) {
        return false;
    }
    
    static {
        SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 16.0, 15.0);
    }
}
