package net.minecraft.world.level.block;

import com.google.common.collect.Maps;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Silverfish;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Map;

public class InfestedBlock extends Block {
    private final Block hostBlock;
    private static final Map<Block, Block> BLOCK_BY_HOST_BLOCK;
    
    public InfestedBlock(final Block bph, final Properties c) {
        super(c);
        this.hostBlock = bph;
        InfestedBlock.BLOCK_BY_HOST_BLOCK.put(bph, this);
    }
    
    public Block getHostBlock() {
        return this.hostBlock;
    }
    
    public static boolean isCompatibleHostBlock(final BlockState byj) {
        return InfestedBlock.BLOCK_BY_HOST_BLOCK.containsKey(byj.getBlock());
    }
    
    @Override
    public void spawnAfterBreak(final BlockState byj, final Level bjw, final BlockPos fk, final ItemStack ben) {
        super.spawnAfterBreak(byj, bjw, fk, ben);
        if (!bjw.isClientSide && bjw.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS) && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, ben) == 0) {
            final Silverfish axf6 = EntityType.SILVERFISH.create(bjw);
            axf6.moveTo(fk.getX() + 0.5, fk.getY(), fk.getZ() + 0.5, 0.0f, 0.0f);
            bjw.addFreshEntity(axf6);
            axf6.spawnAnim();
        }
    }
    
    public static BlockState stateByHostBlock(final Block bph) {
        return InfestedBlock.BLOCK_BY_HOST_BLOCK.get(bph).defaultBlockState();
    }
    
    static {
        BLOCK_BY_HOST_BLOCK = Maps.newIdentityHashMap();
    }
}
