package rip.tilly.bedwars.customvillager;

import net.minecraft.server.v1_8_R3.DamageSource;
import net.minecraft.server.v1_8_R3.EntityVillager;
import net.minecraft.server.v1_8_R3.NBTTagCompound;
import net.minecraft.server.v1_8_R3.World;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftVillager;
import org.bukkit.event.entity.CreatureSpawnEvent;
import rip.tilly.bedwars.utils.CC;

public class CustomVillager extends EntityVillager {

    public CustomVillager(World world, String name) {
        super(world);

        this.setCustomName(CC.translate(name));
        this.setCustomNameVisible(true);
        this.noMove();

        this.setInvisible(false);
        ((CraftVillager) this.getBukkitEntity()).getHandle().setInvisible(false);

        this.world.addEntity(this, CreatureSpawnEvent.SpawnReason.CUSTOM);
    }

    public void noMove() {
        NBTTagCompound tag = this.getNBTTag();
        if(tag == null) {
            tag = new NBTTagCompound();
        }

        this.c(tag);
        tag.setInt("NoAI", 1);
        this.f(tag);
    }

    @Override
    public void makeSound(String s, float f, float f1) {
        return;
    }

    @Override
    public boolean damageEntity(DamageSource source, float f) {
        return false;
    }
}
