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 akz, final Level bjw, final BlockPos fk, final int integer) {
        if (!akz.onGround) {
            return;
        }
        final BlockState byj5 = Blocks.FROSTED_ICE.defaultBlockState();
        final float float6 = (float)Math.min(16, 2 + integer);
        final BlockPos.MutableBlockPos a7 = new BlockPos.MutableBlockPos();
        for (final BlockPos fk2 : BlockPos.betweenClosed(fk.offset(-float6, -1.0, -float6), fk.offset(float6, -1.0, float6))) {
            if (fk2.closerThan(akz.position(), float6)) {
                a7.set(fk2.getX(), fk2.getY() + 1, fk2.getZ());
                final BlockState byj6 = bjw.getBlockState(a7);
                if (!byj6.isAir()) {
                    continue;
                }
                final BlockState byj7 = bjw.getBlockState(fk2);
                if (byj7.getMaterial() != Material.WATER || byj7.<Integer>getValue((Property<Integer>)LiquidBlock.LEVEL) != 0 || !byj5.canSurvive(bjw, fk2) || !bjw.isUnobstructed(byj5, fk2, CollisionContext.empty())) {
                    continue;
                }
                bjw.setBlockAndUpdate(fk2, byj5);
                bjw.getBlockTicks().scheduleTick(fk2, Blocks.FROSTED_ICE, Mth.nextInt(akz.getRandom(), 60, 120));
            }
        }
    }
    
    public boolean checkCompatibility(final Enchantment bhx) {
        return super.checkCompatibility(bhx) && bhx != Enchantments.DEPTH_STRIDER;
    }
}
