package net.minecraft.world.level.block;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LightLayer;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.ItemStack;
import javax.annotation.Nullable;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class IceBlock extends HalfTransparentBlock {
    public IceBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public void playerDestroy(final Level bjw, final Player ayj, final BlockPos fk, final BlockState byj, @Nullable final BlockEntity bwl, final ItemStack ben) {
        super.playerDestroy(bjw, ayj, fk, byj, bwl, ben);
        if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, ben) == 0) {
            if (bjw.dimension.isUltraWarm()) {
                bjw.removeBlock(fk, false);
                return;
            }
            final Material coo8 = bjw.getBlockState(fk.below()).getMaterial();
            if (coo8.blocksMotion() || coo8.isLiquid()) {
                bjw.setBlockAndUpdate(fk, Blocks.WATER.defaultBlockState());
            }
        }
    }
    
    @Override
    public void tick(final BlockState byj, final ServerLevel xd, final BlockPos fk, final Random random) {
        if (xd.getBrightness(LightLayer.BLOCK, fk) > 11 - byj.getLightBlock(xd, fk)) {
            this.melt(byj, xd, fk);
        }
    }
    
    protected void melt(final BlockState byj, final Level bjw, final BlockPos fk) {
        if (bjw.dimension.isUltraWarm()) {
            bjw.removeBlock(fk, false);
            return;
        }
        bjw.setBlockAndUpdate(fk, Blocks.WATER.defaultBlockState());
        bjw.neighborChanged(fk, Blocks.WATER, fk);
    }
    
    @Override
    public PushReaction getPistonPushReaction(final BlockState byj) {
        return PushReaction.NORMAL;
    }
    
    @Override
    public boolean isValidSpawn(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final EntityType<?> aku) {
        return aku == EntityType.POLAR_BEAR;
    }
}
