package net.minecraft.world.level.block;

import net.minecraft.world.level.pathfinder.PathComputationType;
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.level.block.state.BlockBehaviour;
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 cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return DragonEggBlock.SHAPE;
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        this.teleport(cfj, bqb, fu);
        return InteractionResult.sidedSuccess(bqb.isClientSide);
    }
    
    @Override
    public void attack(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec) {
        this.teleport(cfj, bqb, fu);
    }
    
    private void teleport(final BlockState cfj, final Level bqb, final BlockPos fu) {
        for (int integer5 = 0; integer5 < 1000; ++integer5) {
            final BlockPos fu2 = fu.offset(bqb.random.nextInt(16) - bqb.random.nextInt(16), bqb.random.nextInt(8) - bqb.random.nextInt(8), bqb.random.nextInt(16) - bqb.random.nextInt(16));
            if (bqb.getBlockState(fu2).isAir()) {
                if (bqb.isClientSide) {
                    for (int integer6 = 0; integer6 < 128; ++integer6) {
                        final double double8 = bqb.random.nextDouble();
                        final float float10 = (bqb.random.nextFloat() - 0.5f) * 0.2f;
                        final float float11 = (bqb.random.nextFloat() - 0.5f) * 0.2f;
                        final float float12 = (bqb.random.nextFloat() - 0.5f) * 0.2f;
                        final double double9 = Mth.lerp(double8, fu2.getX(), fu.getX()) + (bqb.random.nextDouble() - 0.5) + 0.5;
                        final double double10 = Mth.lerp(double8, fu2.getY(), fu.getY()) + bqb.random.nextDouble() - 0.5;
                        final double double11 = Mth.lerp(double8, fu2.getZ(), fu.getZ()) + (bqb.random.nextDouble() - 0.5) + 0.5;
                        bqb.addParticle(ParticleTypes.PORTAL, double9, double10, double11, float10, float11, float12);
                    }
                }
                else {
                    bqb.setBlock(fu2, cfj, 2);
                    bqb.removeBlock(fu, false);
                }
                return;
            }
        }
    }
    
    @Override
    protected int getDelayAfterPlace() {
        return 5;
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
    
    static {
        SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 16.0, 15.0);
    }
}
