The Meaning of Life, the Universe, and Everything.
Join Date:
6/27/2011
Posts:
50
Member Details
I'm trying to get a villager to follow the player when holding an item I've added along with the mod. I came across an old post on how to remove and add a entity spawn to the world, however I don't know if I'm doing it right.
Here is part of my custom villager class, this is where I added the new task to give the villager a 'temptation' item.
protected void initEntityAI()
{
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAITradePlayer(this));
this.tasks.addTask(1, new EntityAILookAtTradePlayer(this));
this.tasks.addTask(2, new EntityAIMoveIndoors(this));
this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this));
this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
this.tasks.addTask(6, new EntityAIVillagerMate(this));
this.tasks.addTask(7, new EntityAIFollowGolem(this));
this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));
this.tasks.addTask(9, new EntityAIVillagerInteract(this));
this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 0.6D));
this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
//This is the one i added
this.tasks.addTask(10, new EntityAITempt(this, 3.0D, ModItems.newitem, false));
}
Here is my main mod init method where I thought the EntityRegistry events should go. I'm guessing this might be the problem because it was an old post I saw it on.
public class CustomVillager extends EntityVillager
{
private static final Logger LOGGER = LogManager.getLogger();
private static final DataParameter<Integer> PROFESSION = EntityDataManager.<Integer>createKey(CustomVillager.class, DataSerializers.VARINT);
private int randomTickDivider;
private boolean isMating;
private boolean isPlaying;
Village villageObj;
/** This villager's current customer. */
private EntityPlayer buyingPlayer;
/** Initialises the MerchantRecipeList.java */
@Nullable
private MerchantRecipeList buyingList;
private int timeUntilReset;
/** addDefaultEquipmentAndRecipies is called if this is true */
private boolean needsInitilization;
private boolean isWillingToMate;
private int wealth;
/** Last player to trade with this villager, used for aggressivity. */
private String lastBuyingPlayer;
private int careerId;
/** This is the EntityVillager's career level value */
private int careerLevel;
private boolean isLookingForHome;
private boolean areAdditionalTasksSet;
private final InventoryBasic villagerInventory;
/** A multi-dimensional array mapping the various professions, careers and career levels that a Villager may offer */
@Deprecated //Use VillagerRegistry
private static final CustomVillager.ITradeList[][][][] DEFAULT_TRADE_LIST_MAP = new CustomVillager.ITradeList[][][][] {{{{new CustomVillager.EmeraldForItems(Items.WHEAT, new CustomVillager.PriceInfo(18, 22)), new CustomVillager.EmeraldForItems(Items.POTATO, new CustomVillager.PriceInfo(15, 19)), new CustomVillager.EmeraldForItems(Items.CARROT, new CustomVillager.PriceInfo(15, 19)), new CustomVillager.ListItemForEmeralds(Items.BREAD, new CustomVillager.PriceInfo(-4, -2))}, {new CustomVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.PUMPKIN), new CustomVillager.PriceInfo(8, 13)), new CustomVillager.ListItemForEmeralds(Items.PUMPKIN_PIE, new CustomVillager.PriceInfo(-3, -2))}, {new CustomVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.MELON_BLOCK), new CustomVillager.PriceInfo(7, 12)), new CustomVillager.ListItemForEmeralds(Items.APPLE, new CustomVillager.PriceInfo(-7, -5))}, {new CustomVillager.ListItemForEmeralds(Items.COOKIE, new CustomVillager.PriceInfo(-10, -6)), new CustomVillager.ListItemForEmeralds(Items.CAKE, new CustomVillager.PriceInfo(1, 1))}}, {{new CustomVillager.EmeraldForItems(Items.STRING, new CustomVillager.PriceInfo(15, 20)), new CustomVillager.EmeraldForItems(Items.COAL, new CustomVillager.PriceInfo(16, 24)), new CustomVillager.ItemAndEmeraldToItem(Items.FISH, new CustomVillager.PriceInfo(6, 6), Items.COOKED_FISH, new CustomVillager.PriceInfo(6, 6))}, {new CustomVillager.ListEnchantedItemForEmeralds(Items.FISHING_ROD, new CustomVillager.PriceInfo(7, 8))}}, {{new CustomVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.WOOL), new CustomVillager.PriceInfo(16, 22)), new CustomVillager.ListItemForEmeralds(Items.SHEARS, new CustomVillager.PriceInfo(3, 4))}, {new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL)), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 1), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 2), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 3), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 4), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 5), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 6), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 7), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 8), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 9), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 10), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 11), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 12), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 13), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 14), new CustomVillager.PriceInfo(1, 2)), new CustomVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.WOOL), 1, 15), new CustomVillager.PriceInfo(1, 2))}}, {{new CustomVillager.EmeraldForItems(Items.STRING, new CustomVillager.PriceInfo(15, 20)), new CustomVillager.ListItemForEmeralds(Items.ARROW, new CustomVillager.PriceInfo(-12, -8))}, {new CustomVillager.ListItemForEmeralds(Items.BOW, new CustomVillager.PriceInfo(2, 3)), new CustomVillager.ItemAndEmeraldToItem(Item.getItemFromBlock(Blocks.GRAVEL), new CustomVillager.PriceInfo(10, 10), Items.FLINT, new CustomVillager.PriceInfo(6, 10))}}}, {{{new CustomVillager.EmeraldForItems(Items.PAPER, new CustomVillager.PriceInfo(24, 36)), new CustomVillager.ListEnchantedBookForEmeralds()}, {new CustomVillager.EmeraldForItems(Items.BOOK, new CustomVillager.PriceInfo(8, 10)), new CustomVillager.ListItemForEmeralds(Items.COMPASS, new CustomVillager.PriceInfo(10, 12)), new CustomVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.BOOKSHELF), new CustomVillager.PriceInfo(3, 4))}, {new CustomVillager.EmeraldForItems(Items.WRITTEN_BOOK, new CustomVillager.PriceInfo(2, 2)), new CustomVillager.ListItemForEmeralds(Items.CLOCK, new CustomVillager.PriceInfo(10, 12)), new CustomVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.GLASS), new CustomVillager.PriceInfo(-5, -3))}, {new CustomVillager.ListEnchantedBookForEmeralds()}, {new CustomVillager.ListEnchantedBookForEmeralds()}, {new CustomVillager.ListItemForEmeralds(Items.NAME_TAG, new CustomVillager.PriceInfo(20, 22))}}, {{new CustomVillager.EmeraldForItems(Items.PAPER, new CustomVillager.PriceInfo(24, 36))}, {new CustomVillager.EmeraldForItems(Items.COMPASS, new CustomVillager.PriceInfo(1, 1))}, {new CustomVillager.ListItemForEmeralds(Items.MAP, new CustomVillager.PriceInfo(7, 11))}, {new CustomVillager.TreasureMapForEmeralds(new CustomVillager.PriceInfo(12, 20), "Monument", MapDecoration.Type.MONUMENT), new CustomVillager.TreasureMapForEmeralds(new CustomVillager.PriceInfo(16, 28), "Mansion", MapDecoration.Type.MANSION)}}}, {{{new CustomVillager.EmeraldForItems(Items.ROTTEN_FLESH, new CustomVillager.PriceInfo(36, 40)), new CustomVillager.EmeraldForItems(Items.GOLD_INGOT, new CustomVillager.PriceInfo(8, 10))}, {new CustomVillager.ListItemForEmeralds(Items.REDSTONE, new CustomVillager.PriceInfo(-4, -1)), new CustomVillager.ListItemForEmeralds(new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()), new CustomVillager.PriceInfo(-2, -1))}, {new CustomVillager.ListItemForEmeralds(Items.ENDER_PEARL, new CustomVillager.PriceInfo(4, 7)), new CustomVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.GLOWSTONE), new CustomVillager.PriceInfo(-3, -1))}, {new CustomVillager.ListItemForEmeralds(Items.EXPERIENCE_BOTTLE, new CustomVillager.PriceInfo(3, 11))}}}, {{{new CustomVillager.EmeraldForItems(Items.COAL, new CustomVillager.PriceInfo(16, 24)), new CustomVillager.ListItemForEmeralds(Items.IRON_HELMET, new CustomVillager.PriceInfo(4, 6))}, {new CustomVillager.EmeraldForItems(Items.IRON_INGOT, new CustomVillager.PriceInfo(7, 9)), new CustomVillager.ListItemForEmeralds(Items.IRON_CHESTPLATE, new CustomVillager.PriceInfo(10, 14))}, {new CustomVillager.EmeraldForItems(Items.DIAMOND, new CustomVillager.PriceInfo(3, 4)), new CustomVillager.ListEnchantedItemForEmeralds(Items.DIAMOND_CHESTPLATE, new CustomVillager.PriceInfo(16, 19))}, {new CustomVillager.ListItemForEmeralds(Items.CHAINMAIL_BOOTS, new CustomVillager.PriceInfo(5, 7)), new CustomVillager.ListItemForEmeralds(Items.CHAINMAIL_LEGGINGS, new CustomVillager.PriceInfo(9, 11)), new CustomVillager.ListItemForEmeralds(Items.CHAINMAIL_HELMET, new CustomVillager.PriceInfo(5, 7)), new CustomVillager.ListItemForEmeralds(Items.CHAINMAIL_CHESTPLATE, new CustomVillager.PriceInfo(11, 15))}}, {{new CustomVillager.EmeraldForItems(Items.COAL, new CustomVillager.PriceInfo(16, 24)), new CustomVillager.ListItemForEmeralds(Items.IRON_AXE, new CustomVillager.PriceInfo(6, 8))}, {new CustomVillager.EmeraldForItems(Items.IRON_INGOT, new CustomVillager.PriceInfo(7, 9)), new CustomVillager.ListEnchantedItemForEmeralds(Items.IRON_SWORD, new CustomVillager.PriceInfo(9, 10))}, {new CustomVillager.EmeraldForItems(Items.DIAMOND, new CustomVillager.PriceInfo(3, 4)), new CustomVillager.ListEnchantedItemForEmeralds(Items.DIAMOND_SWORD, new CustomVillager.PriceInfo(12, 15)), new CustomVillager.ListEnchantedItemForEmeralds(Items.DIAMOND_AXE, new CustomVillager.PriceInfo(9, 12))}}, {{new CustomVillager.EmeraldForItems(Items.COAL, new CustomVillager.PriceInfo(16, 24)), new CustomVillager.ListEnchantedItemForEmeralds(Items.IRON_SHOVEL, new CustomVillager.PriceInfo(5, 7))}, {new CustomVillager.EmeraldForItems(Items.IRON_INGOT, new CustomVillager.PriceInfo(7, 9)), new CustomVillager.ListEnchantedItemForEmeralds(Items.IRON_PICKAXE, new CustomVillager.PriceInfo(9, 11))}, {new CustomVillager.EmeraldForItems(Items.DIAMOND, new CustomVillager.PriceInfo(3, 4)), new CustomVillager.ListEnchantedItemForEmeralds(Items.DIAMOND_PICKAXE, new CustomVillager.PriceInfo(12, 15))}}}, {{{new CustomVillager.EmeraldForItems(Items.PORKCHOP, new CustomVillager.PriceInfo(14, 18)), new CustomVillager.EmeraldForItems(Items.CHICKEN, new CustomVillager.PriceInfo(14, 18))}, {new CustomVillager.EmeraldForItems(Items.COAL, new CustomVillager.PriceInfo(16, 24)), new CustomVillager.ListItemForEmeralds(Items.COOKED_PORKCHOP, new CustomVillager.PriceInfo(-7, -5)), new CustomVillager.ListItemForEmeralds(Items.COOKED_CHICKEN, new CustomVillager.PriceInfo(-8, -6))}}, {{new CustomVillager.EmeraldForItems(Items.LEATHER, new CustomVillager.PriceInfo(9, 12)), new CustomVillager.ListItemForEmeralds(Items.LEATHER_LEGGINGS, new CustomVillager.PriceInfo(2, 4))}, {new CustomVillager.ListEnchantedItemForEmeralds(Items.LEATHER_CHESTPLATE, new CustomVillager.PriceInfo(7, 12))}, {new CustomVillager.ListItemForEmeralds(Items.SADDLE, new CustomVillager.PriceInfo(8, 10))}}}, {new CustomVillager.ITradeList[0][]}};
public CustomVillager(World worldIn)
{
this(worldIn, 0);
}
public CustomVillager(World worldIn, int professionId)
{
super(worldIn);
this.villagerInventory = new InventoryBasic("Items", false, 8);
this.setProfession(professionId);
this.setSize(0.6F, 1.95F);
((PathNavigateGround)this.getNavigator()).setBreakDoors(true);
this.setCanPickUpLoot(true);
}
protected void initEntityAI()
{
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAITradePlayer(this));
this.tasks.addTask(1, new EntityAILookAtTradePlayer(this));
this.tasks.addTask(2, new EntityAIMoveIndoors(this));
this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this));
this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
this.tasks.addTask(6, new EntityAIVillagerMate(this));
this.tasks.addTask(7, new EntityAIFollowGolem(this));
this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));
this.tasks.addTask(9, new EntityAIVillagerInteract(this));
this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 0.6D));
this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
//This is the one i added
this.tasks.addTask(10, new EntityAITempt(this, 3.0D, ModItems.newitem, false));
}
private void setAdditionalAItasks()
{
if (!this.areAdditionalTasksSet)
{
this.areAdditionalTasksSet = true;
if (this.isChild())
{
this.tasks.addTask(8, new EntityAIPlay(this, 0.32D));
this.tasks.addTask(1, new EntityAITempt(this, 3.0D, ModItems.lolipop, false));
}
else if (this.getProfession() == 0)
{
this.tasks.addTask(6, new EntityAIHarvestFarmland(this, 0.6D));
}
}
}
/**
* This is called when Entity's growing age timer reaches 0 (negative values are considered as a child, positive as
* an adult)
*/
protected void onGrowingAdult()
{
if (this.getProfession() == 0)
{
this.tasks.addTask(8, new EntityAIHarvestFarmland(this, 0.6D));
}
super.onGrowingAdult();
}
protected void applyEntityAttributes()
{
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5D);
}
protected void updateAITasks()
{
if (--this.randomTickDivider <= 0)
{
BlockPos blockpos = new BlockPos(this);
this.world.getVillageCollection().addToVillagerPositionList(blockpos);
this.randomTickDivider = 70 + this.rand.nextInt(50);
this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32);
if (this.villageObj == null)
{
this.detachHome();
}
else
{
BlockPos blockpos1 = this.villageObj.getCenter();
this.setHomePosAndDistance(blockpos1, this.villageObj.getVillageRadius());
if (this.isLookingForHome)
{
this.isLookingForHome = false;
this.villageObj.setDefaultPlayerReputation(5);
}
}
}
if (!this.isTrading() && this.timeUntilReset > 0)
{
--this.timeUntilReset;
if (this.timeUntilReset <= 0)
{
if (this.needsInitilization)
{
for (MerchantRecipe merchantrecipe : this.buyingList)
{
if (merchantrecipe.isRecipeDisabled())
{
merchantrecipe.increaseMaxTradeUses(this.rand.nextInt(6) + this.rand.nextInt(6) + 2);
}
}
this.populateBuyingList();
this.needsInitilization = false;
if (this.villageObj != null && this.lastBuyingPlayer != null)
{
this.world.setEntityState(this, (byte)14);
this.villageObj.modifyPlayerReputation(this.lastBuyingPlayer, 1);
}
}
this.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 0));
}
}
super.updateAITasks();
}
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
ItemStack itemstack = player.getHeldItem(hand);
boolean flag = itemstack.getItem() == Items.NAME_TAG;
if (flag)
{
itemstack.interactWithEntity(player, this, hand);
return true;
}
else if (!this.holdingSpawnEggOfClass(itemstack, this.getClass()) && this.isEntityAlive() && !this.isTrading() && !this.isChild())
{
if (this.buyingList == null)
{
this.populateBuyingList();
}
if (hand == EnumHand.MAIN_HAND)
{
player.addStat(StatList.TALKED_TO_VILLAGER);
}
if (!this.world.isRemote && !this.buyingList.isEmpty())
{
this.setCustomer(player);
player.displayVillagerTradeGui(this);
}
else if (this.buyingList.isEmpty())
{
return super.processInteract(player, hand);
}
return true;
}
else
{
return super.processInteract(player, hand);
}
}
protected void entityInit()
{
super.entityInit();
this.dataManager.register(PROFESSION, Integer.valueOf(0));
}
public static void registerFixesVillager(DataFixer fixer)
{
EntityLiving.registerFixesMob(fixer, CustomVillager.class);
fixer.registerWalker(FixTypes.ENTITY, new ItemStackDataLists(CustomVillager.class, new String[] {"Inventory"}));
fixer.registerWalker(FixTypes.ENTITY, new IDataWalker()
{
public NBTTagCompound process(IDataFixer fixer, NBTTagCompound compound, int versionIn)
{
if (EntityList.getKey(CustomVillager.class).equals(new ResourceLocation(compound.getString("id"))) && compound.hasKey("Offers", 10))
{
NBTTagCompound nbttagcompound = compound.getCompoundTag("Offers");
if (nbttagcompound.hasKey("Recipes", 9))
{
NBTTagList nbttaglist = nbttagcompound.getTagList("Recipes", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
DataFixesManager.processItemStack(fixer, nbttagcompound1, versionIn, "buy");
DataFixesManager.processItemStack(fixer, nbttagcompound1, versionIn, "buyB");
DataFixesManager.processItemStack(fixer, nbttagcompound1, versionIn, "sell");
nbttaglist.set(i, nbttagcompound1);
}
}
}
return compound;
}
});
}
/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*/
public void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
compound.setInteger("Profession", this.getProfession());
compound.setString("ProfessionName", this.getProfessionForge().getRegistryName().toString());
compound.setInteger("Riches", this.wealth);
compound.setInteger("Career", this.careerId);
compound.setInteger("CareerLevel", this.careerLevel);
compound.setBoolean("Willing", this.isWillingToMate);
if (this.buyingList != null)
{
compound.setTag("Offers", this.buyingList.getRecipiesAsTags());
}
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
{
ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
if (!itemstack.isEmpty())
{
nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound()));
}
}
compound.setTag("Inventory", nbttaglist);
}
/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*/
public void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
this.setProfession(compound.getInteger("Profession"));
if (compound.hasKey("ProfessionName"))
{
net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession p =
net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation(compound.getString("ProfessionName")));
if (p == null)
p = net.minecraftforge.fml.common.registry.VillagerRegistry.instance().getRegistry().getValue(new net.minecraft.util.ResourceLocation("minecraft:farmer"));
this.setProfession(p);
}
this.wealth = compound.getInteger("Riches");
this.careerId = compound.getInteger("Career");
this.careerLevel = compound.getInteger("CareerLevel");
this.isWillingToMate = compound.getBoolean("Willing");
if (compound.hasKey("Offers", 10))
{
NBTTagCompound nbttagcompound = compound.getCompoundTag("Offers");
this.buyingList = new MerchantRecipeList(nbttagcompound);
}
NBTTagList nbttaglist = compound.getTagList("Inventory", 10);
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
ItemStack itemstack = new ItemStack(nbttaglist.getCompoundTagAt(i));
if (!itemstack.isEmpty())
{
this.villagerInventory.addItem(itemstack);
}
}
this.setCanPickUpLoot(true);
this.setAdditionalAItasks();
}
/**
* Determines if an entity can be despawned, used on idle far away entities
*/
protected boolean canDespawn()
{
return false;
}
protected SoundEvent getAmbientSound()
{
return this.isTrading() ? SoundEvents.ENTITY_VILLAGER_TRADING : SoundEvents.ENTITY_VILLAGER_AMBIENT;
}
protected SoundEvent getHurtSound()
{
return SoundEvents.ENTITY_VILLAGER_HURT;
}
protected SoundEvent getDeathSound()
{
return SoundEvents.ENTITY_VILLAGER_DEATH;
}
@Nullable
protected ResourceLocation getLootTable()
{
return LootTableList.ENTITIES_VILLAGER;
}
public void setProfession(int professionId)
{
this.dataManager.set(PROFESSION, Integer.valueOf(professionId));
net.minecraftforge.fml.common.registry.VillagerRegistry.onSetProfession(this, professionId);
}
@Deprecated //Use Forge Variant below
public int getProfession()
{
return Math.max(((Integer)this.dataManager.get(PROFESSION)).intValue() % 6, 0);
}
private net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof;
public void setProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession prof)
{
this.prof = prof;
this.setProfession(net.minecraftforge.fml.common.registry.VillagerRegistry.getId(prof));
}
public net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession getProfessionForge()
{
if (this.prof == null)
{
this.prof = net.minecraftforge.fml.common.registry.VillagerRegistry.getById(this.getProfession());
if (this.prof == null)
return net.minecraftforge.fml.common.registry.VillagerRegistry.getById(0); //Farmer
}
return this.prof;
}
@Override
public void notifyDataManagerChange(DataParameter<?> key)
{
super.notifyDataManagerChange(key);
if (key.equals(PROFESSION))
{
net.minecraftforge.fml.common.registry.VillagerRegistry.onSetProfession(this, this.dataManager.get(PROFESSION));
}
}
public boolean isMating()
{
return this.isMating;
}
public void setMating(boolean mating)
{
this.isMating = mating;
}
public void setPlaying(boolean playing)
{
this.isPlaying = playing;
}
public boolean isPlaying()
{
return this.isPlaying;
}
public void setRevengeTarget(@Nullable EntityLivingBase livingBase)
{
super.setRevengeTarget(livingBase);
if (this.villageObj != null && livingBase != null)
{
this.villageObj.addOrRenewAgressor(livingBase);
if (livingBase instanceof EntityPlayer)
{
int i = -1;
if (this.isChild())
{
i = -3;
}
this.villageObj.modifyPlayerReputation(livingBase.getName(), i);
if (this.isEntityAlive())
{
this.world.setEntityState(this, (byte)13);
}
}
}
}
/**
* Called when the mob's health reaches 0.
*/
public void onDeath(DamageSource cause)
{
if (this.villageObj != null)
{
Entity entity = cause.getEntity();
if (entity != null)
{
if (entity instanceof EntityPlayer)
{
this.villageObj.modifyPlayerReputation(entity.getName(), -2);
}
else if (entity instanceof IMob)
{
this.villageObj.endMatingSeason();
}
}
else
{
EntityPlayer entityplayer = this.world.getClosestPlayerToEntity(this, 16.0D);
if (entityplayer != null)
{
this.villageObj.endMatingSeason();
}
}
}
super.onDeath(cause);
}
public void setCustomer(EntityPlayer player)
{
this.buyingPlayer = player;
}
public EntityPlayer getCustomer()
{
return this.buyingPlayer;
}
public boolean isTrading()
{
return this.buyingPlayer != null;
}
/**
* Returns current or updated value of {@link #isWillingToMate}
*/
public boolean getIsWillingToMate(boolean updateFirst)
{
if (!this.isWillingToMate && updateFirst && this.hasEnoughFoodToBreed())
{
boolean flag = false;
for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
{
ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
if (!itemstack.isEmpty())
{
if (itemstack.getItem() == Items.BREAD && itemstack.getCount() >= 3)
{
flag = true;
this.villagerInventory.decrStackSize(i, 3);
}
else if ((itemstack.getItem() == Items.POTATO || itemstack.getItem() == Items.CARROT) && itemstack.getCount() >= 12)
{
flag = true;
this.villagerInventory.decrStackSize(i, 12);
}
}
if (flag)
{
this.world.setEntityState(this, (byte)18);
this.isWillingToMate = true;
break;
}
}
}
return this.isWillingToMate;
}
public void setIsWillingToMate(boolean isWillingToMate)
{
this.isWillingToMate = isWillingToMate;
}
public void useRecipe(MerchantRecipe recipe)
{
recipe.incrementToolUses();
this.livingSoundTime = -this.getTalkInterval();
this.playSound(SoundEvents.ENTITY_VILLAGER_YES, this.getSoundVolume(), this.getSoundPitch());
int i = 3 + this.rand.nextInt(4);
if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0)
{
this.timeUntilReset = 40;
this.needsInitilization = true;
this.isWillingToMate = true;
if (this.buyingPlayer != null)
{
this.lastBuyingPlayer = this.buyingPlayer.getName();
}
else
{
this.lastBuyingPlayer = null;
}
i += 5;
}
if (recipe.getItemToBuy().getItem() == Items.EMERALD)
{
this.wealth += recipe.getItemToBuy().getCount();
}
if (recipe.getRewardsExp())
{
this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY + 0.5D, this.posZ, i));
}
}
/**
* Notifies the merchant of a possible merchantrecipe being fulfilled or not. Usually, this is just a sound byte
* being played depending if the suggested itemstack is not null.
*/
public void verifySellingItem(ItemStack stack)
{
if (!this.world.isRemote && this.livingSoundTime > -this.getTalkInterval() + 20)
{
this.livingSoundTime = -this.getTalkInterval();
this.playSound(stack.isEmpty() ? SoundEvents.ENTITY_VILLAGER_NO : SoundEvents.ENTITY_VILLAGER_YES, this.getSoundVolume(), this.getSoundPitch());
}
}
@Nullable
public MerchantRecipeList getRecipes(EntityPlayer player)
{
if (this.buyingList == null)
{
this.populateBuyingList();
}
return this.buyingList;
}
private void populateBuyingList()
{
if (this.careerId != 0 && this.careerLevel != 0)
{
++this.careerLevel;
}
else
{
this.careerId = this.getProfessionForge().getRandomCareer(this.rand) + 1;
this.careerLevel = 1;
}
if (this.buyingList == null)
{
this.buyingList = new MerchantRecipeList();
}
int i = this.careerId - 1;
int j = this.careerLevel - 1;
List<net.minecraft.entity.passive.EntityVillager.ITradeList> trades = this.getProfessionForge().getCareer(i).getTrades(j);
if (trades != null)
{
for (net.minecraft.entity.passive.EntityVillager.ITradeList entityvillager$itradelist : trades)
{
entityvillager$itradelist.addMerchantRecipe(this, this.buyingList, this.rand);
}
}
}
@SideOnly(Side.CLIENT)
public void setRecipes(@Nullable MerchantRecipeList recipeList)
{
}
public World getWorld()
{
return this.world;
}
public BlockPos getPos()
{
return new BlockPos(this);
}
/**
* Get the formatted ChatComponent that will be used for the sender's username in chat
*/
public ITextComponent getDisplayName()
{
Team team = this.getTeam();
String s = this.getCustomNameTag();
if (s != null && !s.isEmpty())
{
TextComponentString textcomponentstring = new TextComponentString(ScorePlayerTeam.formatPlayerName(team, s));
textcomponentstring.getStyle().setHoverEvent(this.getHoverEvent());
textcomponentstring.getStyle().setInsertion(this.getCachedUniqueIdString());
return textcomponentstring;
}
else
{
if (this.buyingList == null)
{
this.populateBuyingList();
}
String s1 = null;
switch (this.getProfession())
{
case 0:
if (this.careerId == 1)
{
s1 = "farmer";
}
else if (this.careerId == 2)
{
s1 = "fisherman";
}
else if (this.careerId == 3)
{
s1 = "shepherd";
}
else if (this.careerId == 4)
{
s1 = "fletcher";
}
break;
case 1:
if (this.careerId == 1)
{
s1 = "librarian";
}
else if (this.careerId == 2)
{
s1 = "cartographer";
}
break;
case 2:
s1 = "cleric";
break;
case 3:
if (this.careerId == 1)
{
s1 = "armor";
}
else if (this.careerId == 2)
{
s1 = "weapon";
}
else if (this.careerId == 3)
{
s1 = "tool";
}
break;
case 4:
if (this.careerId == 1)
{
s1 = "butcher";
}
else if (this.careerId == 2)
{
s1 = "leather";
}
break;
case 5:
s1 = "nitwit";
}
s1 = this.getProfessionForge().getCareer(this.careerId-1).getName();
{
ITextComponent itextcomponent = new TextComponentTranslation("entity.Villager." + s1, new Object[0]);
itextcomponent.getStyle().setHoverEvent(this.getHoverEvent());
itextcomponent.getStyle().setInsertion(this.getCachedUniqueIdString());
if (team != null)
{
itextcomponent.getStyle().setColor(team.getChatFormat());
}
return itextcomponent;
}
}
}
public float getEyeHeight()
{
return this.isChild() ? 0.81F : 1.62F;
}
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id)
{
if (id == 12)
{
this.spawnParticles(EnumParticleTypes.HEART);
}
else if (id == 13)
{
this.spawnParticles(EnumParticleTypes.VILLAGER_ANGRY);
}
else if (id == 14)
{
this.spawnParticles(EnumParticleTypes.VILLAGER_HAPPY);
}
else
{
super.handleStatusUpdate(id);
}
}
@SideOnly(Side.CLIENT)
private void spawnParticles(EnumParticleTypes particleType)
{
for (int i = 0; i < 5; ++i)
{
double d0 = this.rand.nextGaussian() * 0.02D;
double d1 = this.rand.nextGaussian() * 0.02D;
double d2 = this.rand.nextGaussian() * 0.02D;
this.world.spawnParticle(particleType, this.posX + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, this.posY + 1.0D + (double)(this.rand.nextFloat() * this.height), this.posZ + (double)(this.rand.nextFloat() * this.width * 2.0F) - (double)this.width, d0, d1, d2, new int[0]);
}
}
/**
* Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
* when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
*/
@Nullable
public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, @Nullable IEntityLivingData livingdata)
{
return this.finalizeMobSpawn(difficulty, livingdata, true);
}
public IEntityLivingData finalizeMobSpawn(DifficultyInstance p_190672_1_, @Nullable IEntityLivingData p_190672_2_, boolean p_190672_3_)
{
p_190672_2_ = super.onInitialSpawn(p_190672_1_, p_190672_2_);
if (p_190672_3_)
{
net.minecraftforge.fml.common.registry.VillagerRegistry.setRandomProfession(this, this.world.rand);
}
this.setAdditionalAItasks();
this.populateBuyingList();
return p_190672_2_;
}
public void setLookingForHome()
{
this.isLookingForHome = true;
}
public CustomVillager createChild(EntityAgeable ageable)
{
CustomVillager entityvillager = new CustomVillager(this.world);
entityvillager.onInitialSpawn(this.world.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null);
return entityvillager;
}
public boolean canBeLeashedTo(EntityPlayer player)
{
return false;
}
/**
* Called when a lightning bolt hits the entity.
*/
public void onStruckByLightning(EntityLightningBolt lightningBolt)
{
if (!this.world.isRemote && !this.isDead)
{
EntityWitch entitywitch = new EntityWitch(this.world);
entitywitch.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
entitywitch.onInitialSpawn(this.world.getDifficultyForLocation(new BlockPos(entitywitch)), (IEntityLivingData)null);
entitywitch.setNoAI(this.isAIDisabled());
if (this.hasCustomName())
{
entitywitch.setCustomNameTag(this.getCustomNameTag());
entitywitch.setAlwaysRenderNameTag(this.getAlwaysRenderNameTag());
}
this.world.spawnEntity(entitywitch);
this.setDead();
}
}
public InventoryBasic getVillagerInventory()
{
return this.villagerInventory;
}
/**
* Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is
* better.
*/
protected void updateEquipmentIfNeeded(EntityItem itemEntity)
{
ItemStack itemstack = itemEntity.getEntityItem();
Item item = itemstack.getItem();
if (this.canVillagerPickupItem(item))
{
ItemStack itemstack1 = this.villagerInventory.addItem(itemstack);
if (itemstack1.isEmpty())
{
itemEntity.setDead();
}
else
{
itemstack.setCount(itemstack1.getCount());
}
}
}
private boolean canVillagerPickupItem(Item itemIn)
{
return itemIn == Items.BREAD || itemIn == Items.POTATO || itemIn == Items.CARROT || itemIn == Items.WHEAT || itemIn == Items.WHEAT_SEEDS || itemIn == Items.BEETROOT || itemIn == Items.BEETROOT_SEEDS;
}
public boolean hasEnoughFoodToBreed()
{
return this.hasEnoughItems(1);
}
/**
* Used by {@link net.minecraft.entity.ai.EntityAIVillagerInteract EntityAIVillagerInteract} to check if the
* villager can give some items from an inventory to another villager.
*/
public boolean canAbondonItems()
{
return this.hasEnoughItems(2);
}
public boolean wantsMoreFood()
{
boolean flag = this.getProfession() == 0;
return flag ? !this.hasEnoughItems(5) : !this.hasEnoughItems(1);
}
/**
* Returns true if villager has enough items in inventory
*/
private boolean hasEnoughItems(int multiplier)
{
boolean flag = this.getProfession() == 0;
for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
{
ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
if (!itemstack.isEmpty())
{
if (itemstack.getItem() == Items.BREAD && itemstack.getCount() >= 3 * multiplier || itemstack.getItem() == Items.POTATO && itemstack.getCount() >= 12 * multiplier || itemstack.getItem() == Items.CARROT && itemstack.getCount() >= 12 * multiplier || itemstack.getItem() == Items.BEETROOT && itemstack.getCount() >= 12 * multiplier)
{
return true;
}
if (flag && itemstack.getItem() == Items.WHEAT && itemstack.getCount() >= 9 * multiplier)
{
return true;
}
}
}
return false;
}
/**
* Returns true if villager has seeds, potatoes or carrots in inventory
*/
public boolean isFarmItemInInventory()
{
for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
{
ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
if (!itemstack.isEmpty() && (itemstack.getItem() == Items.WHEAT_SEEDS || itemstack.getItem() == Items.POTATO || itemstack.getItem() == Items.CARROT || itemstack.getItem() == Items.BEETROOT_SEEDS))
{
return true;
}
}
return false;
}
public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
{
if (super.replaceItemInInventory(inventorySlot, itemStackIn))
{
return true;
}
else
{
int i = inventorySlot - 300;
if (i >= 0 && i < this.villagerInventory.getSizeInventory())
{
this.villagerInventory.setInventorySlotContents(i, itemStackIn);
return true;
}
else
{
return false;
}
}
}
public static class EmeraldForItems implements CustomVillager.ITradeList
{
public Item buyingItem;
public CustomVillager.PriceInfo price;
public EmeraldForItems(Item itemIn, CustomVillager.PriceInfo priceIn)
{
this.buyingItem = itemIn;
this.price = priceIn;
}
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
int i = 1;
if (this.price != null)
{
i = this.price.getPrice(random);
}
recipeList.add(new MerchantRecipe(new ItemStack(this.buyingItem, i, 0), Items.EMERALD));
}
}
public interface ITradeList
{
void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random);
}
public static class ItemAndEmeraldToItem implements CustomVillager.ITradeList
{
/**
* The itemstack to buy with an emerald. The Item and damage value is used only, any tag data is not
* retained.
*/
public ItemStack buyingItemStack;
/** The price info defining the amount of the buying item required with 1 emerald to match the selling item. */
public CustomVillager.PriceInfo buyingPriceInfo;
/** The itemstack to sell. The item and damage value are used only, any tag data is not retained. */
public ItemStack sellingItemstack;
public CustomVillager.PriceInfo sellingPriceInfo;
public ItemAndEmeraldToItem(Item p_i45813_1_, CustomVillager.PriceInfo p_i45813_2_, Item p_i45813_3_, CustomVillager.PriceInfo p_i45813_4_)
{
this.buyingItemStack = new ItemStack(p_i45813_1_);
this.buyingPriceInfo = p_i45813_2_;
this.sellingItemstack = new ItemStack(p_i45813_3_);
this.sellingPriceInfo = p_i45813_4_;
}
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
int i = this.buyingPriceInfo.getPrice(random);
int j = this.sellingPriceInfo.getPrice(random);
recipeList.add(new MerchantRecipe(new ItemStack(this.buyingItemStack.getItem(), i, this.buyingItemStack.getMetadata()), new ItemStack(Items.EMERALD), new ItemStack(this.sellingItemstack.getItem(), j, this.sellingItemstack.getMetadata())));
}
}
public static class ListEnchantedBookForEmeralds implements CustomVillager.ITradeList
{
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
Enchantment enchantment = (Enchantment)Enchantment.REGISTRY.getRandomObject(random);
int i = MathHelper.getInt(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
ItemStack itemstack = Items.ENCHANTED_BOOK.getEnchantedItemStack(new EnchantmentData(enchantment, i));
int j = 2 + random.nextInt(5 + i * 10) + 3 * i;
if (enchantment.isTreasureEnchantment())
{
j *= 2;
}
if (j > 64)
{
j = 64;
}
recipeList.add(new MerchantRecipe(new ItemStack(Items.BOOK), new ItemStack(Items.EMERALD, j), itemstack));
}
}
public static class ListEnchantedItemForEmeralds implements CustomVillager.ITradeList
{
/** The enchanted item stack to sell */
public ItemStack enchantedItemStack;
/** The price info determining the amount of emeralds to trade in for the enchanted item */
public CustomVillager.PriceInfo priceInfo;
public ListEnchantedItemForEmeralds(Item p_i45814_1_, CustomVillager.PriceInfo p_i45814_2_)
{
this.enchantedItemStack = new ItemStack(p_i45814_1_);
this.priceInfo = p_i45814_2_;
}
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
int i = 1;
if (this.priceInfo != null)
{
i = this.priceInfo.getPrice(random);
}
ItemStack itemstack = new ItemStack(Items.EMERALD, i, 0);
ItemStack itemstack1 = EnchantmentHelper.addRandomEnchantment(random, new ItemStack(this.enchantedItemStack.getItem(), 1, this.enchantedItemStack.getMetadata()), 5 + random.nextInt(15), false);
recipeList.add(new MerchantRecipe(itemstack, itemstack1));
}
}
//MODDERS DO NOT USE OR EDIT THIS IN ANY WAY IT WILL HAVE NO EFFECT, THIS IS JUST IN HERE TO ALLOW FORGE TO ACCESS IT
//public static ITradeList[][][][] GET_TRADES_DONT_USE(){ return DEFAULT_TRADE_LIST_MAP; }
public static class ListItemForEmeralds implements CustomVillager.ITradeList
{
/** The item that is being bought for emeralds */
public ItemStack itemToBuy;
/**
* The price info for the amount of emeralds to sell for, or if negative, the amount of the item to buy for
* an emerald.
*/
public CustomVillager.PriceInfo priceInfo;
public ListItemForEmeralds(Item par1Item, CustomVillager.PriceInfo priceInfo)
{
this.itemToBuy = new ItemStack(par1Item);
this.priceInfo = priceInfo;
}
public ListItemForEmeralds(ItemStack stack, CustomVillager.PriceInfo priceInfo)
{
this.itemToBuy = stack;
this.priceInfo = priceInfo;
}
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
int i = 1;
if (this.priceInfo != null)
{
i = this.priceInfo.getPrice(random);
}
ItemStack itemstack;
ItemStack itemstack1;
if (i < 0)
{
itemstack = new ItemStack(Items.EMERALD);
itemstack1 = new ItemStack(this.itemToBuy.getItem(), -i, this.itemToBuy.getMetadata());
}
else
{
itemstack = new ItemStack(Items.EMERALD, i, 0);
itemstack1 = new ItemStack(this.itemToBuy.getItem(), 1, this.itemToBuy.getMetadata());
}
recipeList.add(new MerchantRecipe(itemstack, itemstack1));
}
}
public static class PriceInfo extends Tuple<Integer, Integer>
{
public PriceInfo(int p_i45810_1_, int p_i45810_2_)
{
super(Integer.valueOf(p_i45810_1_), Integer.valueOf(p_i45810_2_));
if (p_i45810_2_ < p_i45810_1_)
{
CustomVillager.LOGGER.warn("PriceRange({}, {}) invalid, {} smaller than {}", new Object[] {Integer.valueOf(p_i45810_1_), Integer.valueOf(p_i45810_2_), Integer.valueOf(p_i45810_2_), Integer.valueOf(p_i45810_1_)});
}
}
public int getPrice(Random rand)
{
return ((Integer)this.getFirst()).intValue() >= ((Integer)this.getSecond()).intValue() ? ((Integer)this.getFirst()).intValue() : ((Integer)this.getFirst()).intValue() + rand.nextInt(((Integer)this.getSecond()).intValue() - ((Integer)this.getFirst()).intValue() + 1);
}
}
static class TreasureMapForEmeralds implements CustomVillager.ITradeList
{
public CustomVillager.PriceInfo value;
public String destination;
public MapDecoration.Type destinationType;
public TreasureMapForEmeralds(CustomVillager.PriceInfo p_i47340_1_, String p_i47340_2_, MapDecoration.Type p_i47340_3_)
{
this.value = p_i47340_1_;
this.destination = p_i47340_2_;
this.destinationType = p_i47340_3_;
}
public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random)
{
int i = this.value.getPrice(random);
World world = merchant.getWorld();
BlockPos blockpos = world.findNearestStructure(this.destination, merchant.getPos(), true);
if (blockpos != null)
{
ItemStack itemstack = ItemMap.setupNewMap(world, (double)blockpos.getX(), (double)blockpos.getZ(), (byte)2, true, true);
ItemMap.renderBiomePreviewMap(world, itemstack);
MapData.addTargetDecoration(itemstack, blockpos, "+", this.destinationType);
itemstack.setTranslatableName("filled_map." + this.destination.toLowerCase(Locale.ROOT));
recipeList.add(new MerchantRecipe(new ItemStack(Items.EMERALD, i), new ItemStack(Items.COMPASS), itemstack));
}
}
}
}
So, does anyone have an idea of how I can solve my problem? I need the villager to follow the player when holding the item I've added. I thought a custom villager entity would be what I need, but is there a way to use an event handler perhaps?
I know it's solved, but couldn't the AI be added using the EntityJoinWorldEvent rather than checking every tick?
That is a great idea, thank you! I will try this out later to see if how it works.
EDIT: This worked and I noticed it ran much smoother. As in the actual villager ran constantly toward me instead of staggering around. I put the speed up to 1.0 and they keep up with the player.
I'm trying to get a villager to follow the player when holding an item I've added along with the mod. I came across an old post on how to remove and add a entity spawn to the world, however I don't know if I'm doing it right.
Here is part of my custom villager class, this is where I added the new task to give the villager a 'temptation' item.
{
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityEvoker.class, 12.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVindicator.class, 8.0F, 0.8D, 0.8D));
this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityVex.class, 8.0F, 0.6D, 0.6D));
this.tasks.addTask(1, new EntityAITradePlayer(this));
this.tasks.addTask(1, new EntityAILookAtTradePlayer(this));
this.tasks.addTask(2, new EntityAIMoveIndoors(this));
this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this));
this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
this.tasks.addTask(6, new EntityAIVillagerMate(this));
this.tasks.addTask(7, new EntityAIFollowGolem(this));
this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));
this.tasks.addTask(9, new EntityAIVillagerInteract(this));
this.tasks.addTask(9, new EntityAIWanderAvoidWater(this, 0.6D));
this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
//This is the one i added
this.tasks.addTask(10, new EntityAITempt(this, 3.0D, ModItems.newitem, false));
}
Here is my main mod init method where I thought the EntityRegistry events should go. I'm guessing this might be the problem because it was an old post I saw it on.
Here is a link to the old post I saw.
Also, the complete custom villager class I've got
So, does anyone have an idea of how I can solve my problem? I need the villager to follow the player when holding the item I've added. I thought a custom villager entity would be what I need, but is there a way to use an event handler perhaps?
Thank you! This is exactly what I was looking for. I knew there had to be a way to use the LivingUpdateEvent for this somehow.
It worked perfectly, thank you!
I know it's solved, but couldn't the AI be added using the EntityJoinWorldEvent rather than checking every tick?
That is a great idea, thank you! I will try this out later to see if how it works.
EDIT: This worked and I noticed it ran much smoother. As in the actual villager ran constantly toward me instead of staggering around. I put the speed up to 1.0 and they keep up with the player.