EntityVillager .java

net.minecraft.entity.passive.EntityVillager (class): members: ListEnchantedBookForEmeralds, ListEnchantedItemForEmeralds, DEFAULT_TRADE_LIST_MAP, wealth.

net.minecraft.entity.passiveclass1,085 linescommonextends EntityAgeable43.2 KB

Implements

API Surface (49)

void onGrowingAdult()
void applyEntityAttributes()
void updateAITasks()
boolean interact(EntityPlayer player)
void entityInit()
void writeEntityToNBT(NBTTagCompound tagCompound)
void readEntityFromNBT(NBTTagCompound tagCompund)
boolean canDespawn()
String getLivingSound()
String getHurtSound()
String getDeathSound()
void setProfession(int professionId)
int getProfession()
boolean isMating()
void setMating(boolean mating)
void setPlaying(boolean playing)
boolean isPlaying()
void setRevengeTarget(EntityLivingBase livingBase)
void onDeath(DamageSource cause)
void setCustomer(EntityPlayer p_70932_1_)
EntityPlayer getCustomer()
boolean isTrading()
boolean getIsWillingToMate(boolean updateFirst)
void setIsWillingToMate(boolean willingToTrade)
void useRecipe(MerchantRecipe recipe)
void verifySellingItem(ItemStack stack)
MerchantRecipeList getRecipes(EntityPlayer p_70934_1_)
void setRecipes(MerchantRecipeList recipeList)
IChatComponent getDisplayName()
float getEyeHeight()
void handleStatusUpdate(byte id)
IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
void setLookingForHome()
EntityVillager createChild(EntityAgeable ageable)
boolean allowLeashing()
void onStruckByLightning(EntityLightningBolt lightningBolt)
InventoryBasic getVillagerInventory()
void updateEquipmentIfNeeded(EntityItem itemEntity)
boolean func_175553_cp()
boolean canAbondonItems()
boolean func_175557_cr()
boolean isFarmItemInInventory()
boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
int getPrice(Random rand)

Fields & Constants (17)

DEFAULT_TRADE_LIST_MAP
randomTickDivider
isMating
isPlaying
villageObj
buyingPlayer
buyingList
timeUntilReset
needsInitilization
isWillingToMate
wealth
lastBuyingPlayer
careerId
careerLevel
isLookingForHome
areAdditionalTasksSet
villagerInventory

String literals (26)

"Items"
"Profession"
"Riches"
"Career"
"CareerLevel"
"Willing"
"Offers"
"Inventory"
"mob.villager.haggle"
"mob.villager.idle"
"mob.villager.hit"
"mob.villager.death"
"mob.villager.yes"
"mob.villager.no"
"farmer"
"fisherman"
"shepherd"
"fletcher"
"librarian"
"cleric"
"armor"
"weapon"
"tool"
"butcher"

Code Graph: Dependencies (61)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EntityVillager.java1085 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.passive;
2
3
import java.util.Random;
4
import net.minecraft.enchantment.Enchantment;
5
import net.minecraft.enchantment.EnchantmentData;
6
import net.minecraft.enchantment.EnchantmentHelper;
7
import net.minecraft.entity.Entity;
8
import net.minecraft.entity.EntityAgeable;
9
import net.minecraft.entity.EntityLiving;
10
import net.minecraft.entity.EntityLivingBase;
11
import net.minecraft.entity.IEntityLivingData;
12
import net.minecraft.entity.IMerchant;
13
import net.minecraft.entity.INpc;
14
import net.minecraft.entity.SharedMonsterAttributes;
15
import net.minecraft.entity.ai.EntityAIAvoidEntity;
16
import net.minecraft.entity.ai.EntityAIFollowGolem;
17
import net.minecraft.entity.ai.EntityAIHarvestFarmland;
18
import net.minecraft.entity.ai.EntityAILookAtTradePlayer;
19
import net.minecraft.entity.ai.EntityAIMoveIndoors;
20
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
21
import net.minecraft.entity.ai.EntityAIOpenDoor;
22
import net.minecraft.entity.ai.EntityAIPlay;
23
import net.minecraft.entity.ai.EntityAIRestrictOpenDoor;
24
import net.minecraft.entity.ai.EntityAISwimming;
25
import net.minecraft.entity.ai.EntityAITradePlayer;
26
import net.minecraft.entity.ai.EntityAIVillagerInteract;
27
import net.minecraft.entity.ai.EntityAIVillagerMate;
28
import net.minecraft.entity.ai.EntityAIWander;
29
import net.minecraft.entity.ai.EntityAIWatchClosest;
30
import net.minecraft.entity.ai.EntityAIWatchClosest2;
31
import net.minecraft.entity.effect.EntityLightningBolt;
32
import net.minecraft.entity.item.EntityItem;
33
import net.minecraft.entity.item.EntityXPOrb;
34
import net.minecraft.entity.monster.EntityWitch;
35
import net.minecraft.entity.monster.EntityZombie;
36
import net.minecraft.entity.monster.IMob;
37
import net.minecraft.entity.player.EntityPlayer;
38
import net.minecraft.init.Blocks;
39
import net.minecraft.init.Items;
40
import net.minecraft.inventory.InventoryBasic;
41
import net.minecraft.item.EnumDyeColor;
42
import net.minecraft.item.Item;
43
import net.minecraft.item.ItemStack;
44
import net.minecraft.nbt.NBTTagCompound;
45
import net.minecraft.nbt.NBTTagList;
46
import net.minecraft.pathfinding.PathNavigateGround;
47
import net.minecraft.potion.Potion;
48
import net.minecraft.potion.PotionEffect;
49
import net.minecraft.stats.StatList;
50
import net.minecraft.util.BlockPos;
51
import net.minecraft.util.ChatComponentText;
52
import net.minecraft.util.ChatComponentTranslation;
53
import net.minecraft.util.DamageSource;
54
import net.minecraft.util.EnumParticleTypes;
55
import net.minecraft.util.IChatComponent;
56
import net.minecraft.util.MathHelper;
57
import net.minecraft.util.Tuple;
58
import net.minecraft.village.MerchantRecipe;
59
import net.minecraft.village.MerchantRecipeList;
60
import net.minecraft.village.Village;
61
import net.minecraft.world.DifficultyInstance;
62
import net.minecraft.world.World;
63
64
public class EntityVillager extends EntityAgeable implements IMerchant, INpc
65
{
66
    private int randomTickDivider;
67
    private boolean isMating;
68
    private boolean isPlaying;
69
    Village villageObj;
70
71
    /** This villager's current customer. */
72
    private EntityPlayer buyingPlayer;
73
74
    /** Initialises the MerchantRecipeList.java */
75
    private MerchantRecipeList buyingList;
76
    private int timeUntilReset;
77
78
    /** addDefaultEquipmentAndRecipies is called if this is true */
79
    private boolean needsInitilization;
80
    private boolean isWillingToMate;
81
    private int wealth;
82
83
    /** Last player to trade with this villager, used for aggressivity. */
84
    private String lastBuyingPlayer;
85
    private int careerId;
86
87
    /** This is the EntityVillager's career level value */
88
    private int careerLevel;
89
    private boolean isLookingForHome;
90
    private boolean areAdditionalTasksSet;
91
    private InventoryBasic villagerInventory;
92
93
    /**
94
     * A multi-dimensional array mapping the various professions, careers and career levels that a Villager may offer
95
     */
96
    private static final EntityVillager.ITradeList[][][][] DEFAULT_TRADE_LIST_MAP = new EntityVillager.ITradeList[][][][] {{{{new EntityVillager.EmeraldForItems(Items.wheat, new EntityVillager.PriceInfo(18, 22)), new EntityVillager.EmeraldForItems(Items.potato, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.EmeraldForItems(Items.carrot, new EntityVillager.PriceInfo(15, 19)), new EntityVillager.ListItemForEmeralds(Items.bread, new EntityVillager.PriceInfo(-4, -2))}, {new EntityVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.pumpkin), new EntityVillager.PriceInfo(8, 13)), new EntityVillager.ListItemForEmeralds(Items.pumpkin_pie, new EntityVillager.PriceInfo(-3, -2))}, {new EntityVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.melon_block), new EntityVillager.PriceInfo(7, 12)), new EntityVillager.ListItemForEmeralds(Items.apple, new EntityVillager.PriceInfo(-5, -7))}, {new EntityVillager.ListItemForEmeralds(Items.cookie, new EntityVillager.PriceInfo(-6, -10)), new EntityVillager.ListItemForEmeralds(Items.cake, new EntityVillager.PriceInfo(1, 1))}}, {{new EntityVillager.EmeraldForItems(Items.string, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.EmeraldForItems(Items.coal, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ItemAndEmeraldToItem(Items.fish, new EntityVillager.PriceInfo(6, 6), Items.cooked_fish, new EntityVillager.PriceInfo(6, 6))}, {new EntityVillager.ListEnchantedItemForEmeralds(Items.fishing_rod, new EntityVillager.PriceInfo(7, 8))}}, {{new EntityVillager.EmeraldForItems(Item.getItemFromBlock(Blocks.wool), new EntityVillager.PriceInfo(16, 22)), new EntityVillager.ListItemForEmeralds(Items.shears, new EntityVillager.PriceInfo(3, 4))}, {new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 0), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 1), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 2), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 3), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 4), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 5), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 6), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 7), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 8), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 9), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 10), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 11), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 12), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 13), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 14), new EntityVillager.PriceInfo(1, 2)), new EntityVillager.ListItemForEmeralds(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, 15), new EntityVillager.PriceInfo(1, 2))}}, {{new EntityVillager.EmeraldForItems(Items.string, new EntityVillager.PriceInfo(15, 20)), new EntityVillager.ListItemForEmeralds(Items.arrow, new EntityVillager.PriceInfo(-12, -8))}, {new EntityVillager.ListItemForEmeralds(Items.bow, new EntityVillager.PriceInfo(2, 3)), new EntityVillager.ItemAndEmeraldToItem(Item.getItemFromBlock(Blocks.gravel), new EntityVillager.PriceInfo(10, 10), Items.flint, new EntityVillager.PriceInfo(6, 10))}}}, {{{new EntityVillager.EmeraldForItems(Items.paper, new EntityVillager.PriceInfo(24, 36)), new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.EmeraldForItems(Items.book, new EntityVillager.PriceInfo(8, 10)), new EntityVillager.ListItemForEmeralds(Items.compass, new EntityVillager.PriceInfo(10, 12)), new EntityVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.bookshelf), new EntityVillager.PriceInfo(3, 4))}, {new EntityVillager.EmeraldForItems(Items.written_book, new EntityVillager.PriceInfo(2, 2)), new EntityVillager.ListItemForEmeralds(Items.clock, new EntityVillager.PriceInfo(10, 12)), new EntityVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.glass), new EntityVillager.PriceInfo(-5, -3))}, {new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.ListEnchantedBookForEmeralds()}, {new EntityVillager.ListItemForEmeralds(Items.name_tag, new EntityVillager.PriceInfo(20, 22))}}}, {{{new EntityVillager.EmeraldForItems(Items.rotten_flesh, new EntityVillager.PriceInfo(36, 40)), new EntityVillager.EmeraldForItems(Items.gold_ingot, new EntityVillager.PriceInfo(8, 10))}, {new EntityVillager.ListItemForEmeralds(Items.redstone, new EntityVillager.PriceInfo(-4, -1)), new EntityVillager.ListItemForEmeralds(new ItemStack(Items.dye, 1, EnumDyeColor.BLUE.getDyeDamage()), new EntityVillager.PriceInfo(-2, -1))}, {new EntityVillager.ListItemForEmeralds(Items.ender_eye, new EntityVillager.PriceInfo(7, 11)), new EntityVillager.ListItemForEmeralds(Item.getItemFromBlock(Blocks.glowstone), new EntityVillager.PriceInfo(-3, -1))}, {new EntityVillager.ListItemForEmeralds(Items.experience_bottle, new EntityVillager.PriceInfo(3, 11))}}}, {{{new EntityVillager.EmeraldForItems(Items.coal, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.iron_helmet, new EntityVillager.PriceInfo(4, 6))}, {new EntityVillager.EmeraldForItems(Items.iron_ingot, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListItemForEmeralds(Items.iron_chestplate, new EntityVillager.PriceInfo(10, 14))}, {new EntityVillager.EmeraldForItems(Items.diamond, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.diamond_chestplate, new EntityVillager.PriceInfo(16, 19))}, {new EntityVillager.ListItemForEmeralds(Items.chainmail_boots, new EntityVillager.PriceInfo(5, 7)), new EntityVillager.ListItemForEmeralds(Items.chainmail_leggings, new EntityVillager.PriceInfo(9, 11)), new EntityVillager.ListItemForEmeralds(Items.chainmail_helmet, new EntityVillager.PriceInfo(5, 7)), new EntityVillager.ListItemForEmeralds(Items.chainmail_chestplate, new EntityVillager.PriceInfo(11, 15))}}, {{new EntityVillager.EmeraldForItems(Items.coal, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.iron_axe, new EntityVillager.PriceInfo(6, 8))}, {new EntityVillager.EmeraldForItems(Items.iron_ingot, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListEnchantedItemForEmeralds(Items.iron_sword, new EntityVillager.PriceInfo(9, 10))}, {new EntityVillager.EmeraldForItems(Items.diamond, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.diamond_sword, new EntityVillager.PriceInfo(12, 15)), new EntityVillager.ListEnchantedItemForEmeralds(Items.diamond_axe, new EntityVillager.PriceInfo(9, 12))}}, {{new EntityVillager.EmeraldForItems(Items.coal, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListEnchantedItemForEmeralds(Items.iron_shovel, new EntityVillager.PriceInfo(5, 7))}, {new EntityVillager.EmeraldForItems(Items.iron_ingot, new EntityVillager.PriceInfo(7, 9)), new EntityVillager.ListEnchantedItemForEmeralds(Items.iron_pickaxe, new EntityVillager.PriceInfo(9, 11))}, {new EntityVillager.EmeraldForItems(Items.diamond, new EntityVillager.PriceInfo(3, 4)), new EntityVillager.ListEnchantedItemForEmeralds(Items.diamond_pickaxe, new EntityVillager.PriceInfo(12, 15))}}}, {{{new EntityVillager.EmeraldForItems(Items.porkchop, new EntityVillager.PriceInfo(14, 18)), new EntityVillager.EmeraldForItems(Items.chicken, new EntityVillager.PriceInfo(14, 18))}, {new EntityVillager.EmeraldForItems(Items.coal, new EntityVillager.PriceInfo(16, 24)), new EntityVillager.ListItemForEmeralds(Items.cooked_porkchop, new EntityVillager.PriceInfo(-7, -5)), new EntityVillager.ListItemForEmeralds(Items.cooked_chicken, new EntityVillager.PriceInfo(-8, -6))}}, {{new EntityVillager.EmeraldForItems(Items.leather, new EntityVillager.PriceInfo(9, 12)), new EntityVillager.ListItemForEmeralds(Items.leather_leggings, new EntityVillager.PriceInfo(2, 4))}, {new EntityVillager.ListEnchantedItemForEmeralds(Items.leather_chestplate, new EntityVillager.PriceInfo(7, 12))}, {new EntityVillager.ListItemForEmeralds(Items.saddle, new EntityVillager.PriceInfo(8, 10))}}}};
97
98
    public EntityVillager(World worldIn)
99
    {
100
        this(worldIn, 0);
101
    }
102
103
    public EntityVillager(World worldIn, int professionId)
104
    {
105
        super(worldIn);
106
        this.villagerInventory = new InventoryBasic("Items", false, 8);
107
        this.setProfession(professionId);
108
        this.setSize(0.6F, 1.8F);
109
        ((PathNavigateGround)this.getNavigator()).setBreakDoors(true);
110
        ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
111
        this.tasks.addTask(0, new EntityAISwimming(this));
112
        this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.6D, 0.6D));
113
        this.tasks.addTask(1, new EntityAITradePlayer(this));
114
        this.tasks.addTask(1, new EntityAILookAtTradePlayer(this));
115
        this.tasks.addTask(2, new EntityAIMoveIndoors(this));
116
        this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this));
117
        this.tasks.addTask(4, new EntityAIOpenDoor(this, true));
118
        this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 0.6D));
119
        this.tasks.addTask(6, new EntityAIVillagerMate(this));
120
        this.tasks.addTask(7, new EntityAIFollowGolem(this));
121
        this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F));
122
        this.tasks.addTask(9, new EntityAIVillagerInteract(this));
123
        this.tasks.addTask(9, new EntityAIWander(this, 0.6D));
124
        this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F));
125
        this.setCanPickUpLoot(true);
126
    }
127
128
    private void setAdditionalAItasks()
129
    {
130
        if (!this.areAdditionalTasksSet)
131
        {
132
            this.areAdditionalTasksSet = true;
133
134
            if (this.isChild())
135
            {
136
                this.tasks.addTask(8, new EntityAIPlay(this, 0.32D));
137
            }
138
            else if (this.getProfession() == 0)
139
            {
140
                this.tasks.addTask(6, new EntityAIHarvestFarmland(this, 0.6D));
141
            }
142
        }
143
    }
144
145
    /**
146
     * This is called when Entity's growing age timer reaches 0 (negative values are considered as a child, positive as
147
     * an adult)
148
     */
149
    protected void onGrowingAdult()
150
    {
151
        if (this.getProfession() == 0)
152
        {
153
            this.tasks.addTask(8, new EntityAIHarvestFarmland(this, 0.6D));
154
        }
155
156
        super.onGrowingAdult();
157
    }
158
159
    protected void applyEntityAttributes()
160
    {
161
        super.applyEntityAttributes();
162
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
163
    }
164
165
    protected void updateAITasks()
166
    {
167
        if (--this.randomTickDivider <= 0)
168
        {
169
            BlockPos blockpos = new BlockPos(this);
170
            this.worldObj.getVillageCollection().addToVillagerPositionList(blockpos);
171
            this.randomTickDivider = 70 + this.rand.nextInt(50);
172
            this.villageObj = this.worldObj.getVillageCollection().getNearestVillage(blockpos, 32);
173
174
            if (this.villageObj == null)
175
            {
176
                this.detachHome();
177
            }
178
            else
179
            {
180
                BlockPos blockpos1 = this.villageObj.getCenter();
181
                this.setHomePosAndDistance(blockpos1, (int)((float)this.villageObj.getVillageRadius() * 1.0F));
182
183
                if (this.isLookingForHome)
184
                {
185
                    this.isLookingForHome = false;
186
                    this.villageObj.setDefaultPlayerReputation(5);
187
                }
188
            }
189
        }
190
191
        if (!this.isTrading() && this.timeUntilReset > 0)
192
        {
193
            --this.timeUntilReset;
194
195
            if (this.timeUntilReset <= 0)
196
            {
197
                if (this.needsInitilization)
198
                {
199
                    for (MerchantRecipe merchantrecipe : this.buyingList)
200
                    {
201
                        if (merchantrecipe.isRecipeDisabled())
202
                        {
203
                            merchantrecipe.increaseMaxTradeUses(this.rand.nextInt(6) + this.rand.nextInt(6) + 2);
204
                        }
205
                    }
206
207
                    this.populateBuyingList();
208
                    this.needsInitilization = false;
209
210
                    if (this.villageObj != null && this.lastBuyingPlayer != null)
211
                    {
212
                        this.worldObj.setEntityState(this, (byte)14);
213
                        this.villageObj.setReputationForPlayer(this.lastBuyingPlayer, 1);
214
                    }
215
                }
216
217
                this.addPotionEffect(new PotionEffect(Potion.regeneration.id, 200, 0));
218
            }
219
        }
220
221
        super.updateAITasks();
222
    }
223
224
    /**
225
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
226
     */
227
    public boolean interact(EntityPlayer player)
228
    {
229
        ItemStack itemstack = player.inventory.getCurrentItem();
230
        boolean flag = itemstack != null && itemstack.getItem() == Items.spawn_egg;
231
232
        if (!flag && this.isEntityAlive() && !this.isTrading() && !this.isChild())
233
        {
234
            if (!this.worldObj.isRemote && (this.buyingList == null || this.buyingList.size() > 0))
235
            {
236
                this.setCustomer(player);
237
                player.displayVillagerTradeGui(this);
238
            }
239
240
            player.triggerAchievement(StatList.timesTalkedToVillagerStat);
241
            return true;
242
        }
243
        else
244
        {
245
            return super.interact(player);
246
        }
247
    }
248
249
    protected void entityInit()
250
    {
251
        super.entityInit();
252
        this.dataWatcher.addObject(16, Integer.valueOf(0));
253
    }
254
255
    /**
256
     * (abstract) Protected helper method to write subclass entity data to NBT.
257
     */
258
    public void writeEntityToNBT(NBTTagCompound tagCompound)
259
    {
260
        super.writeEntityToNBT(tagCompound);
261
        tagCompound.setInteger("Profession", this.getProfession());
262
        tagCompound.setInteger("Riches", this.wealth);
263
        tagCompound.setInteger("Career", this.careerId);
264
        tagCompound.setInteger("CareerLevel", this.careerLevel);
265
        tagCompound.setBoolean("Willing", this.isWillingToMate);
266
267
        if (this.buyingList != null)
268
        {
269
            tagCompound.setTag("Offers", this.buyingList.getRecipiesAsTags());
270
        }
271
272
        NBTTagList nbttaglist = new NBTTagList();
273
274
        for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
275
        {
276
            ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
277
278
            if (itemstack != null)
279
            {
280
                nbttaglist.appendTag(itemstack.writeToNBT(new NBTTagCompound()));
281
            }
282
        }
283
284
        tagCompound.setTag("Inventory", nbttaglist);
285
    }
286
287
    /**
288
     * (abstract) Protected helper method to read subclass entity data from NBT.
289
     */
290
    public void readEntityFromNBT(NBTTagCompound tagCompund)
291
    {
292
        super.readEntityFromNBT(tagCompund);
293
        this.setProfession(tagCompund.getInteger("Profession"));
294
        this.wealth = tagCompund.getInteger("Riches");
295
        this.careerId = tagCompund.getInteger("Career");
296
        this.careerLevel = tagCompund.getInteger("CareerLevel");
297
        this.isWillingToMate = tagCompund.getBoolean("Willing");
298
299
        if (tagCompund.hasKey("Offers", 10))
300
        {
301
            NBTTagCompound nbttagcompound = tagCompund.getCompoundTag("Offers");
302
            this.buyingList = new MerchantRecipeList(nbttagcompound);
303
        }
304
305
        NBTTagList nbttaglist = tagCompund.getTagList("Inventory", 10);
306
307
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
308
        {
309
            ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i));
310
311
            if (itemstack != null)
312
            {
313
                this.villagerInventory.func_174894_a(itemstack);
314
            }
315
        }
316
317
        this.setCanPickUpLoot(true);
318
        this.setAdditionalAItasks();
319
    }
320
321
    /**
322
     * Determines if an entity can be despawned, used on idle far away entities
323
     */
324
    protected boolean canDespawn()
325
    {
326
        return false;
327
    }
328
329
    /**
330
     * Returns the sound this mob makes while it's alive.
331
     */
332
    protected String getLivingSound()
333
    {
334
        return this.isTrading() ? "mob.villager.haggle" : "mob.villager.idle";
335
    }
336
337
    /**
338
     * Returns the sound this mob makes when it is hurt.
339
     */
340
    protected String getHurtSound()
341
    {
342
        return "mob.villager.hit";
343
    }
344
345
    /**
346
     * Returns the sound this mob makes on death.
347
     */
348
    protected String getDeathSound()
349
    {
350
        return "mob.villager.death";
351
    }
352
353
    public void setProfession(int professionId)
354
    {
355
        this.dataWatcher.updateObject(16, Integer.valueOf(professionId));
356
    }
357
358
    public int getProfession()
359
    {
360
        return Math.max(this.dataWatcher.getWatchableObjectInt(16) % 5, 0);
361
    }
362
363
    public boolean isMating()
364
    {
365
        return this.isMating;
366
    }
367
368
    public void setMating(boolean mating)
369
    {
370
        this.isMating = mating;
371
    }
372
373
    public void setPlaying(boolean playing)
374
    {
375
        this.isPlaying = playing;
376
    }
377
378
    public boolean isPlaying()
379
    {
380
        return this.isPlaying;
381
    }
382
383
    public void setRevengeTarget(EntityLivingBase livingBase)
384
    {
385
        super.setRevengeTarget(livingBase);
386
387
        if (this.villageObj != null && livingBase != null)
388
        {
389
            this.villageObj.addOrRenewAgressor(livingBase);
390
391
            if (livingBase instanceof EntityPlayer)
392
            {
393
                int i = -1;
394
395
                if (this.isChild())
396
                {
397
                    i = -3;
398
                }
399
400
                this.villageObj.setReputationForPlayer(livingBase.getName(), i);
401
402
                if (this.isEntityAlive())
403
                {
404
                    this.worldObj.setEntityState(this, (byte)13);
405
                }
406
            }
407
        }
408
    }
409
410
    /**
411
     * Called when the mob's health reaches 0.
412
     */
413
    public void onDeath(DamageSource cause)
414
    {
415
        if (this.villageObj != null)
416
        {
417
            Entity entity = cause.getEntity();
418
419
            if (entity != null)
420
            {
421
                if (entity instanceof EntityPlayer)
422
                {
423
                    this.villageObj.setReputationForPlayer(entity.getName(), -2);
424
                }
425
                else if (entity instanceof IMob)
426
                {
427
                    this.villageObj.endMatingSeason();
428
                }
429
            }
430
            else
431
            {
432
                EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, 16.0D);
433
434
                if (entityplayer != null)
435
                {
436
                    this.villageObj.endMatingSeason();
437
                }
438
            }
439
        }
440
441
        super.onDeath(cause);
442
    }
443
444
    public void setCustomer(EntityPlayer p_70932_1_)
445
    {
446
        this.buyingPlayer = p_70932_1_;
447
    }
448
449
    public EntityPlayer getCustomer()
450
    {
451
        return this.buyingPlayer;
452
    }
453
454
    public boolean isTrading()
455
    {
456
        return this.buyingPlayer != null;
457
    }
458
459
    /**
460
     * Returns current or updated value of {@link #isWillingToMate}
461
     */
462
    public boolean getIsWillingToMate(boolean updateFirst)
463
    {
464
        if (!this.isWillingToMate && updateFirst && this.func_175553_cp())
465
        {
466
            boolean flag = false;
467
468
            for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
469
            {
470
                ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
471
472
                if (itemstack != null)
473
                {
474
                    if (itemstack.getItem() == Items.bread && itemstack.stackSize >= 3)
475
                    {
476
                        flag = true;
477
                        this.villagerInventory.decrStackSize(i, 3);
478
                    }
479
                    else if ((itemstack.getItem() == Items.potato || itemstack.getItem() == Items.carrot) && itemstack.stackSize >= 12)
480
                    {
481
                        flag = true;
482
                        this.villagerInventory.decrStackSize(i, 12);
483
                    }
484
                }
485
486
                if (flag)
487
                {
488
                    this.worldObj.setEntityState(this, (byte)18);
489
                    this.isWillingToMate = true;
490
                    break;
491
                }
492
            }
493
        }
494
495
        return this.isWillingToMate;
496
    }
497
498
    public void setIsWillingToMate(boolean willingToTrade)
499
    {
500
        this.isWillingToMate = willingToTrade;
501
    }
502
503
    public void useRecipe(MerchantRecipe recipe)
504
    {
505
        recipe.incrementToolUses();
506
        this.livingSoundTime = -this.getTalkInterval();
507
        this.playSound("mob.villager.yes", this.getSoundVolume(), this.getSoundPitch());
508
        int i = 3 + this.rand.nextInt(4);
509
510
        if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0)
511
        {
512
            this.timeUntilReset = 40;
513
            this.needsInitilization = true;
514
            this.isWillingToMate = true;
515
516
            if (this.buyingPlayer != null)
517
            {
518
                this.lastBuyingPlayer = this.buyingPlayer.getName();
519
            }
520
            else
521
            {
522
                this.lastBuyingPlayer = null;
523
            }
524
525
            i += 5;
526
        }
527
528
        if (recipe.getItemToBuy().getItem() == Items.emerald)
529
        {
530
            this.wealth += recipe.getItemToBuy().stackSize;
531
        }
532
533
        if (recipe.getRewardsExp())
534
        {
535
            this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY + 0.5D, this.posZ, i));
536
        }
537
    }
538
539
    /**
540
     * Notifies the merchant of a possible merchantrecipe being fulfilled or not. Usually, this is just a sound byte
541
     * being played depending if the suggested itemstack is not null.
542
     */
543
    public void verifySellingItem(ItemStack stack)
544
    {
545
        if (!this.worldObj.isRemote && this.livingSoundTime > -this.getTalkInterval() + 20)
546
        {
547
            this.livingSoundTime = -this.getTalkInterval();
548
549
            if (stack != null)
550
            {
551
                this.playSound("mob.villager.yes", this.getSoundVolume(), this.getSoundPitch());
552
            }
553
            else
554
            {
555
                this.playSound("mob.villager.no", this.getSoundVolume(), this.getSoundPitch());
556
            }
557
        }
558
    }
559
560
    public MerchantRecipeList getRecipes(EntityPlayer p_70934_1_)
561
    {
562
        if (this.buyingList == null)
563
        {
564
            this.populateBuyingList();
565
        }
566
567
        return this.buyingList;
568
    }
569
570
    private void populateBuyingList()
571
    {
572
        EntityVillager.ITradeList[][][] aentityvillager$itradelist = DEFAULT_TRADE_LIST_MAP[this.getProfession()];
573
574
        if (this.careerId != 0 && this.careerLevel != 0)
575
        {
576
            ++this.careerLevel;
577
        }
578
        else
579
        {
580
            this.careerId = this.rand.nextInt(aentityvillager$itradelist.length) + 1;
581
            this.careerLevel = 1;
582
        }
583
584
        if (this.buyingList == null)
585
        {
586
            this.buyingList = new MerchantRecipeList();
587
        }
588
589
        int i = this.careerId - 1;
590
        int j = this.careerLevel - 1;
591
        EntityVillager.ITradeList[][] aentityvillager$itradelist1 = aentityvillager$itradelist[i];
592
593
        if (j >= 0 && j < aentityvillager$itradelist1.length)
594
        {
595
            EntityVillager.ITradeList[] aentityvillager$itradelist2 = aentityvillager$itradelist1[j];
596
597
            for (EntityVillager.ITradeList entityvillager$itradelist : aentityvillager$itradelist2)
598
            {
599
                entityvillager$itradelist.modifyMerchantRecipeList(this.buyingList, this.rand);
600
            }
601
        }
602
    }
603
604
    public void setRecipes(MerchantRecipeList recipeList)
605
    {
606
    }
607
608
    /**
609
     * Get the formatted ChatComponent that will be used for the sender's username in chat
610
     */
611
    public IChatComponent getDisplayName()
612
    {
613
        String s = this.getCustomNameTag();
614
615
        if (s != null && s.length() > 0)
616
        {
617
            ChatComponentText chatcomponenttext = new ChatComponentText(s);
618
            chatcomponenttext.getChatStyle().setChatHoverEvent(this.getHoverEvent());
619
            chatcomponenttext.getChatStyle().setInsertion(this.getUniqueID().toString());
620
            return chatcomponenttext;
621
        }
622
        else
623
        {
624
            if (this.buyingList == null)
625
            {
626
                this.populateBuyingList();
627
            }
628
629
            String s1 = null;
630
631
            switch (this.getProfession())
632
            {
633
                case 0:
634
                    if (this.careerId == 1)
635
                    {
636
                        s1 = "farmer";
637
                    }
638
                    else if (this.careerId == 2)
639
                    {
640
                        s1 = "fisherman";
641
                    }
642
                    else if (this.careerId == 3)
643
                    {
644
                        s1 = "shepherd";
645
                    }
646
                    else if (this.careerId == 4)
647
                    {
648
                        s1 = "fletcher";
649
                    }
650
651
                    break;
652
653
                case 1:
654
                    s1 = "librarian";
655
                    break;
656
657
                case 2:
658
                    s1 = "cleric";
659
                    break;
660
661
                case 3:
662
                    if (this.careerId == 1)
663
                    {
664
                        s1 = "armor";
665
                    }
666
                    else if (this.careerId == 2)
667
                    {
668
                        s1 = "weapon";
669
                    }
670
                    else if (this.careerId == 3)
671
                    {
672
                        s1 = "tool";
673
                    }
674
675
                    break;
676
677
                case 4:
678
                    if (this.careerId == 1)
679
                    {
680
                        s1 = "butcher";
681
                    }
682
                    else if (this.careerId == 2)
683
                    {
684
                        s1 = "leather";
685
                    }
686
            }
687
688
            if (s1 != null)
689
            {
690
                ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("entity.Villager." + s1, new Object[0]);
691
                chatcomponenttranslation.getChatStyle().setChatHoverEvent(this.getHoverEvent());
692
                chatcomponenttranslation.getChatStyle().setInsertion(this.getUniqueID().toString());
693
                return chatcomponenttranslation;
694
            }
695
            else
696
            {
697
                return super.getDisplayName();
698
            }
699
        }
700
    }
701
702
    public float getEyeHeight()
703
    {
704
        float f = 1.62F;
705
706
        if (this.isChild())
707
        {
708
            f = (float)((double)f - 0.81D);
709
        }
710
711
        return f;
712
    }
713
714
    public void handleStatusUpdate(byte id)
715
    {
716
        if (id == 12)
717
        {
718
            this.spawnParticles(EnumParticleTypes.HEART);
719
        }
720
        else if (id == 13)
721
        {
722
            this.spawnParticles(EnumParticleTypes.VILLAGER_ANGRY);
723
        }
724
        else if (id == 14)
725
        {
726
            this.spawnParticles(EnumParticleTypes.VILLAGER_HAPPY);
727
        }
728
        else
729
        {
730
            super.handleStatusUpdate(id);
731
        }
732
    }
733
734
    private void spawnParticles(EnumParticleTypes particleType)
735
    {
736
        for (int i = 0; i < 5; ++i)
737
        {
738
            double d0 = this.rand.nextGaussian() * 0.02D;
739
            double d1 = this.rand.nextGaussian() * 0.02D;
740
            double d2 = this.rand.nextGaussian() * 0.02D;
741
            this.worldObj.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]);
742
        }
743
    }
744
745
    /**
746
     * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
747
     * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
748
     */
749
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
750
    {
751
        livingdata = super.onInitialSpawn(difficulty, livingdata);
752
        this.setProfession(this.worldObj.rand.nextInt(5));
753
        this.setAdditionalAItasks();
754
        return livingdata;
755
    }
756
757
    public void setLookingForHome()
758
    {
759
        this.isLookingForHome = true;
760
    }
761
762
    public EntityVillager createChild(EntityAgeable ageable)
763
    {
764
        EntityVillager entityvillager = new EntityVillager(this.worldObj);
765
        entityvillager.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData)null);
766
        return entityvillager;
767
    }
768
769
    public boolean allowLeashing()
770
    {
771
        return false;
772
    }
773
774
    /**
775
     * Called when a lightning bolt hits the entity.
776
     */
777
    public void onStruckByLightning(EntityLightningBolt lightningBolt)
778
    {
779
        if (!this.worldObj.isRemote && !this.isDead)
780
        {
781
            EntityWitch entitywitch = new EntityWitch(this.worldObj);
782
            entitywitch.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
783
            entitywitch.onInitialSpawn(this.worldObj.getDifficultyForLocation(new BlockPos(entitywitch)), (IEntityLivingData)null);
784
            entitywitch.setNoAI(this.isAIDisabled());
785
786
            if (this.hasCustomName())
787
            {
788
                entitywitch.setCustomNameTag(this.getCustomNameTag());
789
                entitywitch.setAlwaysRenderNameTag(this.getAlwaysRenderNameTag());
790
            }
791
792
            this.worldObj.spawnEntityInWorld(entitywitch);
793
            this.setDead();
794
        }
795
    }
796
797
    public InventoryBasic getVillagerInventory()
798
    {
799
        return this.villagerInventory;
800
    }
801
802
    /**
803
     * Tests if this entity should pickup a weapon or an armor. Entity drops current weapon or armor if the new one is
804
     * better.
805
     */
806
    protected void updateEquipmentIfNeeded(EntityItem itemEntity)
807
    {
808
        ItemStack itemstack = itemEntity.getEntityItem();
809
        Item item = itemstack.getItem();
810
811
        if (this.canVillagerPickupItem(item))
812
        {
813
            ItemStack itemstack1 = this.villagerInventory.func_174894_a(itemstack);
814
815
            if (itemstack1 == null)
816
            {
817
                itemEntity.setDead();
818
            }
819
            else
820
            {
821
                itemstack.stackSize = itemstack1.stackSize;
822
            }
823
        }
824
    }
825
826
    private boolean canVillagerPickupItem(Item itemIn)
827
    {
828
        return itemIn == Items.bread || itemIn == Items.potato || itemIn == Items.carrot || itemIn == Items.wheat || itemIn == Items.wheat_seeds;
829
    }
830
831
    public boolean func_175553_cp()
832
    {
833
        return this.hasEnoughItems(1);
834
    }
835
836
    /**
837
     * Used by {@link net.minecraft.entity.ai.EntityAIVillagerInteract EntityAIVillagerInteract} to check if the
838
     * villager can give some items from an inventory to another villager.
839
     */
840
    public boolean canAbondonItems()
841
    {
842
        return this.hasEnoughItems(2);
843
    }
844
845
    public boolean func_175557_cr()
846
    {
847
        boolean flag = this.getProfession() == 0;
848
        return flag ? !this.hasEnoughItems(5) : !this.hasEnoughItems(1);
849
    }
850
851
    /**
852
     * Returns true if villager has enough items in inventory
853
     */
854
    private boolean hasEnoughItems(int multiplier)
855
    {
856
        boolean flag = this.getProfession() == 0;
857
858
        for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
859
        {
860
            ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
861
862
            if (itemstack != null)
863
            {
864
                if (itemstack.getItem() == Items.bread && itemstack.stackSize >= 3 * multiplier || itemstack.getItem() == Items.potato && itemstack.stackSize >= 12 * multiplier || itemstack.getItem() == Items.carrot && itemstack.stackSize >= 12 * multiplier)
865
                {
866
                    return true;
867
                }
868
869
                if (flag && itemstack.getItem() == Items.wheat && itemstack.stackSize >= 9 * multiplier)
870
                {
871
                    return true;
872
                }
873
            }
874
        }
875
876
        return false;
877
    }
878
879
    /**
880
     * Returns true if villager has seeds, potatoes or carrots in inventory
881
     */
882
    public boolean isFarmItemInInventory()
883
    {
884
        for (int i = 0; i < this.villagerInventory.getSizeInventory(); ++i)
885
        {
886
            ItemStack itemstack = this.villagerInventory.getStackInSlot(i);
887
888
            if (itemstack != null && (itemstack.getItem() == Items.wheat_seeds || itemstack.getItem() == Items.potato || itemstack.getItem() == Items.carrot))
889
            {
890
                return true;
891
            }
892
        }
893
894
        return false;
895
    }
896
897
    public boolean replaceItemInInventory(int inventorySlot, ItemStack itemStackIn)
898
    {
899
        if (super.replaceItemInInventory(inventorySlot, itemStackIn))
900
        {
901
            return true;
902
        }
903
        else
904
        {
905
            int i = inventorySlot - 300;
906
907
            if (i >= 0 && i < this.villagerInventory.getSizeInventory())
908
            {
909
                this.villagerInventory.setInventorySlotContents(i, itemStackIn);
910
                return true;
911
            }
912
            else
913
            {
914
                return false;
915
            }
916
        }
917
    }
918
919
    static class EmeraldForItems implements EntityVillager.ITradeList
920
    {
921
        public Item sellItem;
922
        public EntityVillager.PriceInfo price;
923
924
        public EmeraldForItems(Item itemIn, EntityVillager.PriceInfo priceIn)
925
        {
926
            this.sellItem = itemIn;
927
            this.price = priceIn;
928
        }
929
930
        public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
931
        {
932
            int i = 1;
933
934
            if (this.price != null)
935
            {
936
                i = this.price.getPrice(random);
937
            }
938
939
            recipeList.add(new MerchantRecipe(new ItemStack(this.sellItem, i, 0), Items.emerald));
940
        }
941
    }
942
943
    interface ITradeList
944
    {
945
        void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random);
946
    }
947
948
    static class ItemAndEmeraldToItem implements EntityVillager.ITradeList
949
    {
950
        public ItemStack buyingItemStack;
951
        public EntityVillager.PriceInfo buyingPriceInfo;
952
        public ItemStack sellingItemstack;
953
        public EntityVillager.PriceInfo field_179408_d;
954
955
        public ItemAndEmeraldToItem(Item p_i45813_1_, EntityVillager.PriceInfo p_i45813_2_, Item p_i45813_3_, EntityVillager.PriceInfo p_i45813_4_)
956
        {
957
            this.buyingItemStack = new ItemStack(p_i45813_1_);
958
            this.buyingPriceInfo = p_i45813_2_;
959
            this.sellingItemstack = new ItemStack(p_i45813_3_);
960
            this.field_179408_d = p_i45813_4_;
961
        }
962
963
        public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
964
        {
965
            int i = 1;
966
967
            if (this.buyingPriceInfo != null)
968
            {
969
                i = this.buyingPriceInfo.getPrice(random);
970
            }
971
972
            int j = 1;
973
974
            if (this.field_179408_d != null)
975
            {
976
                j = this.field_179408_d.getPrice(random);
977
            }
978
979
            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())));
980
        }
981
    }
982
983
    static class ListEnchantedBookForEmeralds implements EntityVillager.ITradeList
984
    {
985
        public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
986
        {
987
            Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)];
988
            int i = MathHelper.getRandomIntegerInRange(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
989
            ItemStack itemstack = Items.enchanted_book.getEnchantedItemStack(new EnchantmentData(enchantment, i));
990
            int j = 2 + random.nextInt(5 + i * 10) + 3 * i;
991
992
            if (j > 64)
993
            {
994
                j = 64;
995
            }
996
997
            recipeList.add(new MerchantRecipe(new ItemStack(Items.book), new ItemStack(Items.emerald, j), itemstack));
998
        }
999
    }
1000
1001
    static class ListEnchantedItemForEmeralds implements EntityVillager.ITradeList
1002
    {
1003
        public ItemStack enchantedItemStack;
1004
        public EntityVillager.PriceInfo priceInfo;
1005
1006
        public ListEnchantedItemForEmeralds(Item p_i45814_1_, EntityVillager.PriceInfo p_i45814_2_)
1007
        {
1008
            this.enchantedItemStack = new ItemStack(p_i45814_1_);
1009
            this.priceInfo = p_i45814_2_;
1010
        }
1011
1012
        public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
1013
        {
1014
            int i = 1;
1015
1016
            if (this.priceInfo != null)
1017
            {
1018
                i = this.priceInfo.getPrice(random);
1019
            }
1020
1021
            ItemStack itemstack = new ItemStack(Items.emerald, i, 0);
1022
            ItemStack itemstack1 = new ItemStack(this.enchantedItemStack.getItem(), 1, this.enchantedItemStack.getMetadata());
1023
            itemstack1 = EnchantmentHelper.addRandomEnchantment(random, itemstack1, 5 + random.nextInt(15));
1024
            recipeList.add(new MerchantRecipe(itemstack, itemstack1));
1025
        }
1026
    }
1027
1028
    static class ListItemForEmeralds implements EntityVillager.ITradeList
1029
    {
1030
        public ItemStack itemToBuy;
1031
        public EntityVillager.PriceInfo priceInfo;
1032
1033
        public ListItemForEmeralds(Item par1Item, EntityVillager.PriceInfo priceInfo)
1034
        {
1035
            this.itemToBuy = new ItemStack(par1Item);
1036
            this.priceInfo = priceInfo;
1037
        }
1038
1039
        public ListItemForEmeralds(ItemStack stack, EntityVillager.PriceInfo priceInfo)
1040
        {
1041
            this.itemToBuy = stack;
1042
            this.priceInfo = priceInfo;
1043
        }
1044
1045
        public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
1046
        {
1047
            int i = 1;
1048
1049
            if (this.priceInfo != null)
1050
            {
1051
                i = this.priceInfo.getPrice(random);
1052
            }
1053
1054
            ItemStack itemstack;
1055
            ItemStack itemstack1;
1056
1057
            if (i < 0)
1058
            {
1059
                itemstack = new ItemStack(Items.emerald, 1, 0);
1060
                itemstack1 = new ItemStack(this.itemToBuy.getItem(), -i, this.itemToBuy.getMetadata());
1061
            }
1062
            else
1063
            {
1064
                itemstack = new ItemStack(Items.emerald, i, 0);
1065
                itemstack1 = new ItemStack(this.itemToBuy.getItem(), 1, this.itemToBuy.getMetadata());
1066
            }
1067
1068
            recipeList.add(new MerchantRecipe(itemstack, itemstack1));
1069
        }
1070
    }
1071
1072
    static class PriceInfo extends Tuple<Integer, Integer>
1073
    {
1074
        public PriceInfo(int p_i45810_1_, int p_i45810_2_)
1075
        {
1076
            super(Integer.valueOf(p_i45810_1_), Integer.valueOf(p_i45810_2_));
1077
        }
1078
1079
        public int getPrice(Random rand)
1080
        {
1081
            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);
1082
        }
1083
    }
1084
}
1085

Deobfuscated MCP 1.8.9 source of EntityVillager from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/passive/EntityVillager.java), stored verbatim.