@Override
public boolean onLeftClickEntity(ItemStack is, EntityPlayer player, Entity entity) {
if (entity instanceof EntityLivingBase) {
EntityLivingBase entity_base = (EntityLivingBase) entity;
if (player.worldObj.rand.nextInt(5) == 0) {
entity.playSound("random.explode", 1.0F, 1.0F);
entity_base.addPotionEffect(new PotionEffect(Potion.confusion.id, 0, 5));
//player.inventory.consumeInventoryItem(AlchemyBase.Needle);
//player.inventory.addItemStackToInventory(new ItemStack(AlchemyBase.NeedleWithBlood, 1));
for (int i = 0; i < 10; i++) {
entity.worldObj.spawnParticle("reddust", entity.posX, entity.posY + 0.5, entity.posZ, .0D, 0.1D, 0.0D);
}
is = addNBT(is, entity_base);
}
}
is.damageItem(1, player);
return true;
}
@Override
public String getUnlocalizedName(ItemStack is) {
NBTTagCompound nbt = is.getTagCompound();
if (nbt != null) {
if (nbt.hasKey("DNAP", NBT.TAG_STRING)) {
return "Иголка с ДНК.";
}
if (nbt.hasKey("DNAE", NBT.TAG_STRING)) {
return "Иголка с ДНК.";
}
} else return "Чистая иголка.";
return super.getUnlocalizedName();
}
@Override
public void addInformation(ItemStack is, EntityPlayer player, List list, boolean flag) {
NBTTagCompound nbt = is.getTagCompound();
if (nbt != null) {
if (nbt.hasKey("DNAP", NBT.TAG_STRING)) {
list.add("ДНК игрока: " + nbt.getString("DNAP") + ".");
}
if (nbt.hasKey("DNAE", NBT.TAG_STRING)) {
list.add("ДНК моба: " + StatCollector.translateToLocal(nbt.getString("DNAE")) + ".");
}
}
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs table, List list) {
list.add(addNBT(new ItemStack(item), null));
}
private static ItemStack addNBT(ItemStack is, EntityLivingBase entity) {
NBTTagCompound nbt = is.getTagCompound();
if (nbt == null) nbt = new NBTTagCompound();
if (entity != null) {
nbt.setString("DNA" + (entity instanceof EntityPlayer ? "P" : "E"), entity.getCommandSenderName());
}
is.setTagCompound(nbt);
return is;
}