package net.minecraft.world.item.enchantment;

import java.util.Iterator;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.Position;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EquipmentSlot;

public class FrostWalkerEnchantment extends Enchantment {
    public FrostWalkerEnchantment(final Rarity a, final EquipmentSlot... arr) {
        super(a, EnchantmentCategory.ARMOR_FEET, arr);
    }
    
    @Override
    public int getMinCost(final int integer) {
        return integer * 10;
    }
    
    @Override
    public int getMaxCost(final int integer) {
        return this.getMinCost(integer) + 15;
    }
    
    @Override
    public boolean isTreasureOnly() {
        return true;
    }
    
    @Override
    public int getMaxLevel() {
        return 2;
    }
    
    public static void onEntityMoved(final LivingEntity aoy, final Level bqb, final BlockPos fu, final int integer) {
        if (!aoy.isOnGround()) {
            return;
        }
        final BlockState cfj5 = Blocks.FROSTED_ICE.defaultBlockState();
        final float float6 = (float)Math.min(16, 2 + integer);
        final BlockPos.MutableBlockPos a7 = new BlockPos.MutableBlockPos();
        for (final BlockPos fu2 : BlockPos.betweenClosed(fu.offset(-float6, -1.0, -float6), fu.offset(float6, -1.0, float6))) {
            if (fu2.closerThan(aoy.position(), float6)) {
                a7.set(fu2.getX(), fu2.getY() + 1, fu2.getZ());
                final BlockState cfj6 = bqb.getBlockState(a7);
                if (!cfj6.isAir()) {
                    continue;
                }
                final BlockState cfj7 = bqb.getBlockState(fu2);
                if (cfj7.getMaterial() != Material.WATER || cfj7.<Integer>getValue((Property<Integer>)LiquidBlock.LEVEL) != 0 || !cfj5.canSurvive(bqb, fu2) || !bqb.isUnobstructed(cfj5, fu2, CollisionContext.empty())) {
                    continue;
                }
                bqb.setBlockAndUpdate(fu2, cfj5);
                bqb.getBlockTicks().scheduleTick(fu2, Blocks.FROSTED_ICE, Mth.nextInt(aoy.getRandom(), 60, 120));
            }
        }
    }
    
    public boolean checkCompatibility(final Enchantment bnw) {
        return super.checkCompatibility(bnw) && bnw != Enchantments.DEPTH_STRIDER;
    }
}
