001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import cpw.mods.fml.common.registry.VillagerRegistry; 006 007 import java.util.Collections; 008 import java.util.HashMap; 009 import java.util.Iterator; 010 import java.util.Map; 011 import java.util.Random; 012 013 public class EntityVillager extends EntityAgeable implements INpc, IMerchant 014 { 015 private int randomTickDivider; 016 private boolean isMating; 017 private boolean isPlaying; 018 Village villageObj; 019 020 /** This villager's current customer. */ 021 private EntityPlayer buyingPlayer; 022 023 /** Initialises the MerchantRecipeList.java */ 024 private MerchantRecipeList buyingList; 025 private int timeUntilReset; 026 027 /** addDefaultEquipmentAndRecipies is called if this is true */ 028 private boolean needsInitilization; 029 private int wealth; 030 031 /** Last player to trade with this villager, used for aggressivity. */ 032 private String lastBuyingPlayer; 033 private boolean field_82190_bM; 034 private float field_82191_bN; 035 036 /** 037 * a villagers recipe list is intialized off this list ; the 2 params are min/max amount they will trade for 1 038 * emerald 039 */ 040 public static final Map villagerStockList = new HashMap(); 041 042 /** 043 * Selling list of Blacksmith items. negative numbers mean 1 emerald for n items, positive numbers are n emeralds 044 * for 1 item 045 */ 046 public static final Map blacksmithSellingList = new HashMap(); 047 048 public EntityVillager(World par1World) 049 { 050 this(par1World, 0); 051 } 052 053 public EntityVillager(World par1World, int par2) 054 { 055 super(par1World); 056 this.randomTickDivider = 0; 057 this.isMating = false; 058 this.isPlaying = false; 059 this.villageObj = null; 060 this.setProfession(par2); 061 this.texture = "/mob/villager/villager.png"; 062 this.moveSpeed = 0.5F; 063 this.getNavigator().setBreakDoors(true); 064 this.getNavigator().setAvoidsWater(true); 065 this.tasks.addTask(0, new EntityAISwimming(this)); 066 this.tasks.addTask(1, new EntityAIAvoidEntity(this, EntityZombie.class, 8.0F, 0.3F, 0.35F)); 067 this.tasks.addTask(1, new EntityAITradePlayer(this)); 068 this.tasks.addTask(1, new EntityAILookAtTradePlayer(this)); 069 this.tasks.addTask(2, new EntityAIMoveIndoors(this)); 070 this.tasks.addTask(3, new EntityAIRestrictOpenDoor(this)); 071 this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); 072 this.tasks.addTask(5, new EntityAIMoveTwardsRestriction(this, 0.3F)); 073 this.tasks.addTask(6, new EntityAIVillagerMate(this)); 074 this.tasks.addTask(7, new EntityAIFollowGolem(this)); 075 this.tasks.addTask(8, new EntityAIPlay(this, 0.32F)); 076 this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityPlayer.class, 3.0F, 1.0F)); 077 this.tasks.addTask(9, new EntityAIWatchClosest2(this, EntityVillager.class, 5.0F, 0.02F)); 078 this.tasks.addTask(9, new EntityAIWander(this, 0.3F)); 079 this.tasks.addTask(10, new EntityAIWatchClosest(this, EntityLiving.class, 8.0F)); 080 } 081 082 /** 083 * Returns true if the newer Entity AI code should be run 084 */ 085 public boolean isAIEnabled() 086 { 087 return true; 088 } 089 090 /** 091 * main AI tick function, replaces updateEntityActionState 092 */ 093 protected void updateAITick() 094 { 095 if (--this.randomTickDivider <= 0) 096 { 097 this.worldObj.villageCollectionObj.addVillagerPosition(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ)); 098 this.randomTickDivider = 70 + this.rand.nextInt(50); 099 this.villageObj = this.worldObj.villageCollectionObj.findNearestVillage(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ), 32); 100 101 if (this.villageObj == null) 102 { 103 this.detachHome(); 104 } 105 else 106 { 107 ChunkCoordinates var1 = this.villageObj.getCenter(); 108 this.setHomeArea(var1.posX, var1.posY, var1.posZ, (int)((float)this.villageObj.getVillageRadius() * 0.6F)); 109 110 if (this.field_82190_bM) 111 { 112 this.field_82190_bM = false; 113 this.villageObj.func_82683_b(5); 114 } 115 } 116 } 117 118 if (!this.isTrading() && this.timeUntilReset > 0) 119 { 120 --this.timeUntilReset; 121 122 if (this.timeUntilReset <= 0) 123 { 124 if (this.needsInitilization) 125 { 126 if (this.buyingList.size() > 1) 127 { 128 Iterator var3 = this.buyingList.iterator(); 129 130 while (var3.hasNext()) 131 { 132 MerchantRecipe var2 = (MerchantRecipe)var3.next(); 133 134 if (var2.func_82784_g()) 135 { 136 var2.func_82783_a(this.rand.nextInt(6) + this.rand.nextInt(6) + 2); 137 } 138 } 139 } 140 141 this.addDefaultEquipmentAndRecipies(1); 142 this.needsInitilization = false; 143 144 if (this.villageObj != null && this.lastBuyingPlayer != null) 145 { 146 this.worldObj.setEntityState(this, (byte)14); 147 this.villageObj.setReputationForPlayer(this.lastBuyingPlayer, 1); 148 } 149 } 150 151 this.addPotionEffect(new PotionEffect(Potion.regeneration.id, 200, 0)); 152 } 153 } 154 155 super.updateAITick(); 156 } 157 158 /** 159 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 160 */ 161 public boolean interact(EntityPlayer par1EntityPlayer) 162 { 163 if (this.isEntityAlive() && !this.isTrading() && !this.isChild()) 164 { 165 if (!this.worldObj.isRemote) 166 { 167 this.setCustomer(par1EntityPlayer); 168 par1EntityPlayer.displayGUIMerchant(this); 169 } 170 171 return true; 172 } 173 else 174 { 175 return super.interact(par1EntityPlayer); 176 } 177 } 178 179 protected void entityInit() 180 { 181 super.entityInit(); 182 this.dataWatcher.addObject(16, Integer.valueOf(0)); 183 } 184 185 public int getMaxHealth() 186 { 187 return 20; 188 } 189 190 /** 191 * (abstract) Protected helper method to write subclass entity data to NBT. 192 */ 193 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 194 { 195 super.writeEntityToNBT(par1NBTTagCompound); 196 par1NBTTagCompound.setInteger("Profession", this.getProfession()); 197 par1NBTTagCompound.setInteger("Riches", this.wealth); 198 199 if (this.buyingList != null) 200 { 201 par1NBTTagCompound.setCompoundTag("Offers", this.buyingList.getRecipiesAsTags()); 202 } 203 } 204 205 /** 206 * (abstract) Protected helper method to read subclass entity data from NBT. 207 */ 208 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 209 { 210 super.readEntityFromNBT(par1NBTTagCompound); 211 this.setProfession(par1NBTTagCompound.getInteger("Profession")); 212 this.wealth = par1NBTTagCompound.getInteger("Riches"); 213 214 if (par1NBTTagCompound.hasKey("Offers")) 215 { 216 NBTTagCompound var2 = par1NBTTagCompound.getCompoundTag("Offers"); 217 this.buyingList = new MerchantRecipeList(var2); 218 } 219 } 220 221 @SideOnly(Side.CLIENT) 222 223 /** 224 * Returns the texture's file path as a String. 225 */ 226 public String getTexture() 227 { 228 switch (this.getProfession()) 229 { 230 case 0: 231 return "/mob/villager/farmer.png"; 232 case 1: 233 return "/mob/villager/librarian.png"; 234 case 2: 235 return "/mob/villager/priest.png"; 236 case 3: 237 return "/mob/villager/smith.png"; 238 case 4: 239 return "/mob/villager/butcher.png"; 240 default: 241 return VillagerRegistry.getVillagerSkin(this.getProfession(), super.getTexture()); 242 } 243 } 244 245 /** 246 * Determines if an entity can be despawned, used on idle far away entities 247 */ 248 protected boolean canDespawn() 249 { 250 return false; 251 } 252 253 /** 254 * Returns the sound this mob makes while it's alive. 255 */ 256 protected String getLivingSound() 257 { 258 return "mob.villager.default"; 259 } 260 261 /** 262 * Returns the sound this mob makes when it is hurt. 263 */ 264 protected String getHurtSound() 265 { 266 return "mob.villager.defaulthurt"; 267 } 268 269 /** 270 * Returns the sound this mob makes on death. 271 */ 272 protected String getDeathSound() 273 { 274 return "mob.villager.defaultdeath"; 275 } 276 277 public void setProfession(int par1) 278 { 279 this.dataWatcher.updateObject(16, Integer.valueOf(par1)); 280 } 281 282 public int getProfession() 283 { 284 return this.dataWatcher.getWatchableObjectInt(16); 285 } 286 287 public boolean isMating() 288 { 289 return this.isMating; 290 } 291 292 public void setMating(boolean par1) 293 { 294 this.isMating = par1; 295 } 296 297 public void setPlaying(boolean par1) 298 { 299 this.isPlaying = par1; 300 } 301 302 public boolean isPlaying() 303 { 304 return this.isPlaying; 305 } 306 307 public void setRevengeTarget(EntityLiving par1EntityLiving) 308 { 309 super.setRevengeTarget(par1EntityLiving); 310 311 if (this.villageObj != null && par1EntityLiving != null) 312 { 313 this.villageObj.addOrRenewAgressor(par1EntityLiving); 314 315 if (par1EntityLiving instanceof EntityPlayer) 316 { 317 byte var2 = -1; 318 319 if (this.isChild()) 320 { 321 var2 = -3; 322 } 323 324 this.villageObj.setReputationForPlayer(((EntityPlayer)par1EntityLiving).getCommandSenderName(), var2); 325 326 if (this.isEntityAlive()) 327 { 328 this.worldObj.setEntityState(this, (byte)13); 329 } 330 } 331 } 332 } 333 334 /** 335 * Called when the mob's health reaches 0. 336 */ 337 public void onDeath(DamageSource par1DamageSource) 338 { 339 if (this.villageObj != null) 340 { 341 Entity var2 = par1DamageSource.getEntity(); 342 343 if (var2 != null) 344 { 345 if (var2 instanceof EntityPlayer) 346 { 347 this.villageObj.setReputationForPlayer(((EntityPlayer)var2).getCommandSenderName(), -2); 348 } 349 else if (var2 instanceof IMob) 350 { 351 this.villageObj.func_82692_h(); 352 } 353 } 354 else if (var2 == null) 355 { 356 EntityPlayer var3 = this.worldObj.getClosestPlayerToEntity(this, 16.0D); 357 358 if (var3 != null) 359 { 360 this.villageObj.func_82692_h(); 361 } 362 } 363 } 364 365 super.onDeath(par1DamageSource); 366 } 367 368 public void setCustomer(EntityPlayer par1EntityPlayer) 369 { 370 this.buyingPlayer = par1EntityPlayer; 371 } 372 373 public EntityPlayer getCustomer() 374 { 375 return this.buyingPlayer; 376 } 377 378 public boolean isTrading() 379 { 380 return this.buyingPlayer != null; 381 } 382 383 public void useRecipe(MerchantRecipe par1MerchantRecipe) 384 { 385 par1MerchantRecipe.incrementToolUses(); 386 387 if (par1MerchantRecipe.hasSameIDsAs((MerchantRecipe)this.buyingList.get(this.buyingList.size() - 1))) 388 { 389 this.timeUntilReset = 40; 390 this.needsInitilization = true; 391 392 if (this.buyingPlayer != null) 393 { 394 this.lastBuyingPlayer = this.buyingPlayer.getCommandSenderName(); 395 } 396 else 397 { 398 this.lastBuyingPlayer = null; 399 } 400 } 401 402 if (par1MerchantRecipe.getItemToBuy().itemID == Item.emerald.shiftedIndex) 403 { 404 this.wealth += par1MerchantRecipe.getItemToBuy().stackSize; 405 } 406 } 407 408 public MerchantRecipeList getRecipes(EntityPlayer par1EntityPlayer) 409 { 410 if (this.buyingList == null) 411 { 412 this.addDefaultEquipmentAndRecipies(1); 413 } 414 415 return this.buyingList; 416 } 417 418 private float func_82188_j(float par1) 419 { 420 float var2 = par1 + this.field_82191_bN; 421 return var2 > 0.9F ? 0.9F - (var2 - 0.9F) : var2; 422 } 423 424 /** 425 * based on the villagers profession add items, equipment, and recipies adds par1 random items to the list of things 426 * that the villager wants to buy. (at most 1 of each wanted type is added) 427 */ 428 private void addDefaultEquipmentAndRecipies(int par1) 429 { 430 if (this.buyingList != null) 431 { 432 this.field_82191_bN = MathHelper.sqrt_float((float)this.buyingList.size()) * 0.2F; 433 } 434 else 435 { 436 this.field_82191_bN = 0.0F; 437 } 438 439 MerchantRecipeList var2; 440 var2 = new MerchantRecipeList(); 441 VillagerRegistry.manageVillagerTrades(var2, this, this.getProfession(), this.rand); 442 label48: 443 444 switch (this.getProfession()) 445 { 446 case 0: 447 addMerchantItem(var2, Item.wheat.shiftedIndex, this.rand, this.func_82188_j(0.9F)); 448 addMerchantItem(var2, Block.cloth.blockID, this.rand, this.func_82188_j(0.5F)); 449 addMerchantItem(var2, Item.chickenRaw.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 450 addMerchantItem(var2, Item.fishCooked.shiftedIndex, this.rand, this.func_82188_j(0.4F)); 451 addBlacksmithItem(var2, Item.bread.shiftedIndex, this.rand, this.func_82188_j(0.9F)); 452 addBlacksmithItem(var2, Item.melon.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 453 addBlacksmithItem(var2, Item.appleRed.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 454 addBlacksmithItem(var2, Item.cookie.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 455 addBlacksmithItem(var2, Item.shears.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 456 addBlacksmithItem(var2, Item.flintAndSteel.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 457 addBlacksmithItem(var2, Item.chickenCooked.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 458 addBlacksmithItem(var2, Item.arrow.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 459 460 if (this.rand.nextFloat() < this.func_82188_j(0.5F)) 461 { 462 var2.add(new MerchantRecipe(new ItemStack(Block.gravel, 10), new ItemStack(Item.emerald), new ItemStack(Item.flint.shiftedIndex, 4 + this.rand.nextInt(2), 0))); 463 } 464 465 break; 466 case 1: 467 addMerchantItem(var2, Item.paper.shiftedIndex, this.rand, this.func_82188_j(0.8F)); 468 addMerchantItem(var2, Item.book.shiftedIndex, this.rand, this.func_82188_j(0.8F)); 469 addMerchantItem(var2, Item.writtenBook.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 470 addBlacksmithItem(var2, Block.bookShelf.blockID, this.rand, this.func_82188_j(0.8F)); 471 addBlacksmithItem(var2, Block.glass.blockID, this.rand, this.func_82188_j(0.2F)); 472 addBlacksmithItem(var2, Item.compass.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 473 addBlacksmithItem(var2, Item.pocketSundial.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 474 break; 475 case 2: 476 addBlacksmithItem(var2, Item.eyeOfEnder.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 477 addBlacksmithItem(var2, Item.expBottle.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 478 addBlacksmithItem(var2, Item.redstone.shiftedIndex, this.rand, this.func_82188_j(0.4F)); 479 addBlacksmithItem(var2, Block.glowStone.blockID, this.rand, this.func_82188_j(0.3F)); 480 int[] var3 = new int[] {Item.swordSteel.shiftedIndex, Item.swordDiamond.shiftedIndex, Item.plateSteel.shiftedIndex, Item.plateDiamond.shiftedIndex, Item.axeSteel.shiftedIndex, Item.axeDiamond.shiftedIndex, Item.pickaxeSteel.shiftedIndex, Item.pickaxeDiamond.shiftedIndex}; 481 int[] var4 = var3; 482 int var5 = var3.length; 483 int var6 = 0; 484 485 while (true) 486 { 487 if (var6 >= var5) 488 { 489 break label48; 490 } 491 492 int var7 = var4[var6]; 493 494 if (this.rand.nextFloat() < this.func_82188_j(0.05F)) 495 { 496 var2.add(new MerchantRecipe(new ItemStack(var7, 1, 0), new ItemStack(Item.emerald, 2 + this.rand.nextInt(3), 0), EnchantmentHelper.addRandomEnchantment(this.rand, new ItemStack(var7, 1, 0), 5 + this.rand.nextInt(15)))); 497 } 498 499 ++var6; 500 } 501 case 3: 502 addMerchantItem(var2, Item.coal.shiftedIndex, this.rand, this.func_82188_j(0.7F)); 503 addMerchantItem(var2, Item.ingotIron.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 504 addMerchantItem(var2, Item.ingotGold.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 505 addMerchantItem(var2, Item.diamond.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 506 addBlacksmithItem(var2, Item.swordSteel.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 507 addBlacksmithItem(var2, Item.swordDiamond.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 508 addBlacksmithItem(var2, Item.axeSteel.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 509 addBlacksmithItem(var2, Item.axeDiamond.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 510 addBlacksmithItem(var2, Item.pickaxeSteel.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 511 addBlacksmithItem(var2, Item.pickaxeDiamond.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 512 addBlacksmithItem(var2, Item.shovelSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 513 addBlacksmithItem(var2, Item.shovelDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 514 addBlacksmithItem(var2, Item.hoeSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 515 addBlacksmithItem(var2, Item.hoeDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 516 addBlacksmithItem(var2, Item.bootsSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 517 addBlacksmithItem(var2, Item.bootsDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 518 addBlacksmithItem(var2, Item.helmetSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 519 addBlacksmithItem(var2, Item.helmetDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 520 addBlacksmithItem(var2, Item.plateSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 521 addBlacksmithItem(var2, Item.plateDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 522 addBlacksmithItem(var2, Item.legsSteel.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 523 addBlacksmithItem(var2, Item.legsDiamond.shiftedIndex, this.rand, this.func_82188_j(0.2F)); 524 addBlacksmithItem(var2, Item.bootsChain.shiftedIndex, this.rand, this.func_82188_j(0.1F)); 525 addBlacksmithItem(var2, Item.helmetChain.shiftedIndex, this.rand, this.func_82188_j(0.1F)); 526 addBlacksmithItem(var2, Item.plateChain.shiftedIndex, this.rand, this.func_82188_j(0.1F)); 527 addBlacksmithItem(var2, Item.legsChain.shiftedIndex, this.rand, this.func_82188_j(0.1F)); 528 break; 529 case 4: 530 addMerchantItem(var2, Item.coal.shiftedIndex, this.rand, this.func_82188_j(0.7F)); 531 addMerchantItem(var2, Item.porkRaw.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 532 addMerchantItem(var2, Item.beefRaw.shiftedIndex, this.rand, this.func_82188_j(0.5F)); 533 addBlacksmithItem(var2, Item.saddle.shiftedIndex, this.rand, this.func_82188_j(0.1F)); 534 addBlacksmithItem(var2, Item.plateLeather.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 535 addBlacksmithItem(var2, Item.bootsLeather.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 536 addBlacksmithItem(var2, Item.helmetLeather.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 537 addBlacksmithItem(var2, Item.legsLeather.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 538 addBlacksmithItem(var2, Item.porkCooked.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 539 addBlacksmithItem(var2, Item.beefCooked.shiftedIndex, this.rand, this.func_82188_j(0.3F)); 540 } 541 542 if (var2.isEmpty()) 543 { 544 addMerchantItem(var2, Item.ingotGold.shiftedIndex, this.rand, 1.0F); 545 } 546 547 Collections.shuffle(var2); 548 549 if (this.buyingList == null) 550 { 551 this.buyingList = new MerchantRecipeList(); 552 } 553 554 for (int var8 = 0; var8 < par1 && var8 < var2.size(); ++var8) 555 { 556 this.buyingList.addToListWithCheck((MerchantRecipe)var2.get(var8)); 557 } 558 } 559 560 @SideOnly(Side.CLIENT) 561 public void setRecipes(MerchantRecipeList par1MerchantRecipeList) {} 562 563 /** 564 * each recipie takes a random stack from villagerStockList and offers it for 1 emerald 565 */ 566 public static void addMerchantItem(MerchantRecipeList par0MerchantRecipeList, int par1, Random par2Random, float par3) 567 { 568 if (par2Random.nextFloat() < par3) 569 { 570 par0MerchantRecipeList.add(new MerchantRecipe(getRandomSizedStack(par1, par2Random), Item.emerald)); 571 } 572 } 573 574 private static ItemStack getRandomSizedStack(int par0, Random par1Random) 575 { 576 return new ItemStack(par0, getRandomCountForItem(par0, par1Random), 0); 577 } 578 579 /** 580 * default to 1, and villagerStockList contains a min/max amount for each index 581 */ 582 private static int getRandomCountForItem(int par0, Random par1Random) 583 { 584 Tuple var2 = (Tuple)villagerStockList.get(Integer.valueOf(par0)); 585 return var2 == null ? 1 : (((Integer)var2.getFirst()).intValue() >= ((Integer)var2.getSecond()).intValue() ? ((Integer)var2.getFirst()).intValue() : ((Integer)var2.getFirst()).intValue() + par1Random.nextInt(((Integer)var2.getSecond()).intValue() - ((Integer)var2.getFirst()).intValue())); 586 } 587 588 public static void addBlacksmithItem(MerchantRecipeList par0MerchantRecipeList, int par1, Random par2Random, float par3) 589 { 590 if (par2Random.nextFloat() < par3) 591 { 592 int var4 = getRandomCountForBlacksmithItem(par1, par2Random); 593 ItemStack var5; 594 ItemStack var6; 595 596 if (var4 < 0) 597 { 598 var5 = new ItemStack(Item.emerald.shiftedIndex, 1, 0); 599 var6 = new ItemStack(par1, -var4, 0); 600 } 601 else 602 { 603 var5 = new ItemStack(Item.emerald.shiftedIndex, var4, 0); 604 var6 = new ItemStack(par1, 1, 0); 605 } 606 607 par0MerchantRecipeList.add(new MerchantRecipe(var5, var6)); 608 } 609 } 610 611 private static int getRandomCountForBlacksmithItem(int par0, Random par1Random) 612 { 613 Tuple var2 = (Tuple)blacksmithSellingList.get(Integer.valueOf(par0)); 614 return var2 == null ? 1 : (((Integer)var2.getFirst()).intValue() >= ((Integer)var2.getSecond()).intValue() ? ((Integer)var2.getFirst()).intValue() : ((Integer)var2.getFirst()).intValue() + par1Random.nextInt(((Integer)var2.getSecond()).intValue() - ((Integer)var2.getFirst()).intValue())); 615 } 616 617 @SideOnly(Side.CLIENT) 618 public void handleHealthUpdate(byte par1) 619 { 620 if (par1 == 12) 621 { 622 this.generateRandomParticles("heart"); 623 } 624 else if (par1 == 13) 625 { 626 this.generateRandomParticles("angryVillager"); 627 } 628 else if (par1 == 14) 629 { 630 this.generateRandomParticles("happyVillager"); 631 } 632 else 633 { 634 super.handleHealthUpdate(par1); 635 } 636 } 637 638 @SideOnly(Side.CLIENT) 639 640 /** 641 * par1 is the particleName 642 */ 643 private void generateRandomParticles(String par1Str) 644 { 645 for (int var2 = 0; var2 < 5; ++var2) 646 { 647 double var3 = this.rand.nextGaussian() * 0.02D; 648 double var5 = this.rand.nextGaussian() * 0.02D; 649 double var7 = this.rand.nextGaussian() * 0.02D; 650 this.worldObj.spawnParticle(par1Str, 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, var3, var5, var7); 651 } 652 } 653 654 /** 655 * Initialize this creature. 656 */ 657 public void initCreature() 658 { 659 VillagerRegistry.applyRandomTrade(this, worldObj.rand); 660 } 661 662 public void func_82187_q() 663 { 664 this.field_82190_bM = true; 665 } 666 667 static 668 { 669 villagerStockList.put(Integer.valueOf(Item.coal.shiftedIndex), new Tuple(Integer.valueOf(16), Integer.valueOf(24))); 670 villagerStockList.put(Integer.valueOf(Item.ingotIron.shiftedIndex), new Tuple(Integer.valueOf(8), Integer.valueOf(10))); 671 villagerStockList.put(Integer.valueOf(Item.ingotGold.shiftedIndex), new Tuple(Integer.valueOf(8), Integer.valueOf(10))); 672 villagerStockList.put(Integer.valueOf(Item.diamond.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(6))); 673 villagerStockList.put(Integer.valueOf(Item.paper.shiftedIndex), new Tuple(Integer.valueOf(24), Integer.valueOf(36))); 674 villagerStockList.put(Integer.valueOf(Item.book.shiftedIndex), new Tuple(Integer.valueOf(11), Integer.valueOf(13))); 675 villagerStockList.put(Integer.valueOf(Item.writtenBook.shiftedIndex), new Tuple(Integer.valueOf(1), Integer.valueOf(1))); 676 villagerStockList.put(Integer.valueOf(Item.enderPearl.shiftedIndex), new Tuple(Integer.valueOf(3), Integer.valueOf(4))); 677 villagerStockList.put(Integer.valueOf(Item.eyeOfEnder.shiftedIndex), new Tuple(Integer.valueOf(2), Integer.valueOf(3))); 678 villagerStockList.put(Integer.valueOf(Item.porkRaw.shiftedIndex), new Tuple(Integer.valueOf(14), Integer.valueOf(18))); 679 villagerStockList.put(Integer.valueOf(Item.beefRaw.shiftedIndex), new Tuple(Integer.valueOf(14), Integer.valueOf(18))); 680 villagerStockList.put(Integer.valueOf(Item.chickenRaw.shiftedIndex), new Tuple(Integer.valueOf(14), Integer.valueOf(18))); 681 villagerStockList.put(Integer.valueOf(Item.fishCooked.shiftedIndex), new Tuple(Integer.valueOf(9), Integer.valueOf(13))); 682 villagerStockList.put(Integer.valueOf(Item.seeds.shiftedIndex), new Tuple(Integer.valueOf(34), Integer.valueOf(48))); 683 villagerStockList.put(Integer.valueOf(Item.melonSeeds.shiftedIndex), new Tuple(Integer.valueOf(30), Integer.valueOf(38))); 684 villagerStockList.put(Integer.valueOf(Item.pumpkinSeeds.shiftedIndex), new Tuple(Integer.valueOf(30), Integer.valueOf(38))); 685 villagerStockList.put(Integer.valueOf(Item.wheat.shiftedIndex), new Tuple(Integer.valueOf(18), Integer.valueOf(22))); 686 villagerStockList.put(Integer.valueOf(Block.cloth.blockID), new Tuple(Integer.valueOf(14), Integer.valueOf(22))); 687 villagerStockList.put(Integer.valueOf(Item.rottenFlesh.shiftedIndex), new Tuple(Integer.valueOf(36), Integer.valueOf(64))); 688 blacksmithSellingList.put(Integer.valueOf(Item.flintAndSteel.shiftedIndex), new Tuple(Integer.valueOf(3), Integer.valueOf(4))); 689 blacksmithSellingList.put(Integer.valueOf(Item.shears.shiftedIndex), new Tuple(Integer.valueOf(3), Integer.valueOf(4))); 690 blacksmithSellingList.put(Integer.valueOf(Item.swordSteel.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(11))); 691 blacksmithSellingList.put(Integer.valueOf(Item.swordDiamond.shiftedIndex), new Tuple(Integer.valueOf(12), Integer.valueOf(14))); 692 blacksmithSellingList.put(Integer.valueOf(Item.axeSteel.shiftedIndex), new Tuple(Integer.valueOf(6), Integer.valueOf(8))); 693 blacksmithSellingList.put(Integer.valueOf(Item.axeDiamond.shiftedIndex), new Tuple(Integer.valueOf(9), Integer.valueOf(12))); 694 blacksmithSellingList.put(Integer.valueOf(Item.pickaxeSteel.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(9))); 695 blacksmithSellingList.put(Integer.valueOf(Item.pickaxeDiamond.shiftedIndex), new Tuple(Integer.valueOf(10), Integer.valueOf(12))); 696 blacksmithSellingList.put(Integer.valueOf(Item.shovelSteel.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(6))); 697 blacksmithSellingList.put(Integer.valueOf(Item.shovelDiamond.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(8))); 698 blacksmithSellingList.put(Integer.valueOf(Item.hoeSteel.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(6))); 699 blacksmithSellingList.put(Integer.valueOf(Item.hoeDiamond.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(8))); 700 blacksmithSellingList.put(Integer.valueOf(Item.bootsSteel.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(6))); 701 blacksmithSellingList.put(Integer.valueOf(Item.bootsDiamond.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(8))); 702 blacksmithSellingList.put(Integer.valueOf(Item.helmetSteel.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(6))); 703 blacksmithSellingList.put(Integer.valueOf(Item.helmetDiamond.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(8))); 704 blacksmithSellingList.put(Integer.valueOf(Item.plateSteel.shiftedIndex), new Tuple(Integer.valueOf(10), Integer.valueOf(14))); 705 blacksmithSellingList.put(Integer.valueOf(Item.plateDiamond.shiftedIndex), new Tuple(Integer.valueOf(16), Integer.valueOf(19))); 706 blacksmithSellingList.put(Integer.valueOf(Item.legsSteel.shiftedIndex), new Tuple(Integer.valueOf(8), Integer.valueOf(10))); 707 blacksmithSellingList.put(Integer.valueOf(Item.legsDiamond.shiftedIndex), new Tuple(Integer.valueOf(11), Integer.valueOf(14))); 708 blacksmithSellingList.put(Integer.valueOf(Item.bootsChain.shiftedIndex), new Tuple(Integer.valueOf(5), Integer.valueOf(7))); 709 blacksmithSellingList.put(Integer.valueOf(Item.helmetChain.shiftedIndex), new Tuple(Integer.valueOf(5), Integer.valueOf(7))); 710 blacksmithSellingList.put(Integer.valueOf(Item.plateChain.shiftedIndex), new Tuple(Integer.valueOf(11), Integer.valueOf(15))); 711 blacksmithSellingList.put(Integer.valueOf(Item.legsChain.shiftedIndex), new Tuple(Integer.valueOf(9), Integer.valueOf(11))); 712 blacksmithSellingList.put(Integer.valueOf(Item.bread.shiftedIndex), new Tuple(Integer.valueOf(-4), Integer.valueOf(-2))); 713 blacksmithSellingList.put(Integer.valueOf(Item.melon.shiftedIndex), new Tuple(Integer.valueOf(-8), Integer.valueOf(-4))); 714 blacksmithSellingList.put(Integer.valueOf(Item.appleRed.shiftedIndex), new Tuple(Integer.valueOf(-8), Integer.valueOf(-4))); 715 blacksmithSellingList.put(Integer.valueOf(Item.cookie.shiftedIndex), new Tuple(Integer.valueOf(-10), Integer.valueOf(-7))); 716 blacksmithSellingList.put(Integer.valueOf(Block.glass.blockID), new Tuple(Integer.valueOf(-5), Integer.valueOf(-3))); 717 blacksmithSellingList.put(Integer.valueOf(Block.bookShelf.blockID), new Tuple(Integer.valueOf(3), Integer.valueOf(4))); 718 blacksmithSellingList.put(Integer.valueOf(Item.plateLeather.shiftedIndex), new Tuple(Integer.valueOf(4), Integer.valueOf(5))); 719 blacksmithSellingList.put(Integer.valueOf(Item.bootsLeather.shiftedIndex), new Tuple(Integer.valueOf(2), Integer.valueOf(4))); 720 blacksmithSellingList.put(Integer.valueOf(Item.helmetLeather.shiftedIndex), new Tuple(Integer.valueOf(2), Integer.valueOf(4))); 721 blacksmithSellingList.put(Integer.valueOf(Item.legsLeather.shiftedIndex), new Tuple(Integer.valueOf(2), Integer.valueOf(4))); 722 blacksmithSellingList.put(Integer.valueOf(Item.saddle.shiftedIndex), new Tuple(Integer.valueOf(6), Integer.valueOf(8))); 723 blacksmithSellingList.put(Integer.valueOf(Item.expBottle.shiftedIndex), new Tuple(Integer.valueOf(-4), Integer.valueOf(-1))); 724 blacksmithSellingList.put(Integer.valueOf(Item.redstone.shiftedIndex), new Tuple(Integer.valueOf(-4), Integer.valueOf(-1))); 725 blacksmithSellingList.put(Integer.valueOf(Item.compass.shiftedIndex), new Tuple(Integer.valueOf(10), Integer.valueOf(12))); 726 blacksmithSellingList.put(Integer.valueOf(Item.pocketSundial.shiftedIndex), new Tuple(Integer.valueOf(10), Integer.valueOf(12))); 727 blacksmithSellingList.put(Integer.valueOf(Block.glowStone.blockID), new Tuple(Integer.valueOf(-3), Integer.valueOf(-1))); 728 blacksmithSellingList.put(Integer.valueOf(Item.porkCooked.shiftedIndex), new Tuple(Integer.valueOf(-7), Integer.valueOf(-5))); 729 blacksmithSellingList.put(Integer.valueOf(Item.beefCooked.shiftedIndex), new Tuple(Integer.valueOf(-7), Integer.valueOf(-5))); 730 blacksmithSellingList.put(Integer.valueOf(Item.chickenCooked.shiftedIndex), new Tuple(Integer.valueOf(-8), Integer.valueOf(-6))); 731 blacksmithSellingList.put(Integer.valueOf(Item.eyeOfEnder.shiftedIndex), new Tuple(Integer.valueOf(7), Integer.valueOf(11))); 732 blacksmithSellingList.put(Integer.valueOf(Item.arrow.shiftedIndex), new Tuple(Integer.valueOf(-12), Integer.valueOf(-8))); 733 } 734 }