Advertisement
Guest User

VillagerShop

a guest
May 29th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.25 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. import net.minecraft.server.v1_7_R1.DamageSource;
  4. import net.minecraft.server.v1_7_R1.EntityAgeable;
  5. import net.minecraft.server.v1_7_R1.EntityHuman;
  6. import net.minecraft.server.v1_7_R1.EntityVillager;
  7. import net.minecraft.server.v1_7_R1.IMerchant;
  8. import net.minecraft.server.v1_7_R1.ItemStack;
  9. import net.minecraft.server.v1_7_R1.Items;
  10. import net.minecraft.server.v1_7_R1.MerchantRecipe;
  11. import net.minecraft.server.v1_7_R1.MerchantRecipeList;
  12. import net.minecraft.server.v1_7_R1.NBTTagCompound;
  13. import net.minecraft.server.v1_7_R1.NPC;
  14. import net.minecraft.server.v1_7_R1.World;
  15.  
  16. public class VillagerShop extends EntityAgeable implements NPC, IMerchant {
  17.    
  18.     private MerchantRecipeList bu;
  19.     private int riches;
  20.    
  21.     public VillagerShop(World paramWorld) {
  22.         this(paramWorld, 0);
  23.     }
  24.    
  25.     public VillagerShop(World paramWorld, int paramInt) {
  26.         super(paramWorld);
  27.         setProfession(paramInt);
  28.         a(0.6F, 1.8F);
  29.        
  30.         getNavigation().b(false);
  31.         getNavigation().a(false);
  32.     }
  33.    
  34.     public boolean bk() {
  35.         return true;
  36.     }
  37.    
  38.     public boolean a(EntityHuman e) {
  39.         if(e.inventory.getItemInHand() != null && e.inventory.getItemInHand().getItem() == Items.DIAMOND){
  40.             Random r = new Random();
  41.             int randX = r.nextInt(40);
  42.             int randZ = r.nextInt(40);
  43.             this.getNavigation().a(this.lastX + randX - 20, e.lastY, this.lastZ + randZ - 20, 1D);
  44.         }else{
  45.             this.getNavigation().a(e.lastX, e.lastY, e.lastZ, 0.5D);
  46.         }
  47.         return true;
  48.     }
  49.    
  50.     protected void c() {
  51.         super.c();
  52.         this.datawatcher.a(16, Integer.valueOf(0));
  53.     }
  54.    
  55.     public void b(NBTTagCompound paramNBTTagCompound) {
  56.         super.b(paramNBTTagCompound);
  57.         paramNBTTagCompound.setInt("Profession", getProfession());
  58.         paramNBTTagCompound.setInt("Riches", this.riches);
  59.         if(this.bu != null) paramNBTTagCompound.set("Offers", this.bu.a());
  60.     }
  61.    
  62.     public void a(NBTTagCompound paramNBTTagCompound) {
  63.         super.a(paramNBTTagCompound);
  64.         setProfession(paramNBTTagCompound.getInt("Profession"));
  65.         this.riches = paramNBTTagCompound.getInt("Riches");
  66.         if(paramNBTTagCompound.hasKeyOfType("Offers", 10)) {
  67.             NBTTagCompound localNBTTagCompound = paramNBTTagCompound.getCompound("Offers");
  68.             this.bu = new MerchantRecipeList(localNBTTagCompound);
  69.         }
  70.     }
  71.    
  72.     protected String t() {
  73.         if(ca()) { return "mob.villager.haggle"; }
  74.         return "mob.villager.idle";
  75.     }
  76.    
  77.     protected String aT() {
  78.         return "mob.villager.hit";
  79.     }
  80.    
  81.     protected String aU() {
  82.         return "mob.villager.death";
  83.     }
  84.    
  85.     public void setProfession(int paramInt) {
  86.         this.datawatcher.watch(16, Integer.valueOf(paramInt));
  87.     }
  88.    
  89.     public int getProfession() {
  90.         return this.datawatcher.getInt(16);
  91.     }
  92.    
  93.     public void die(DamageSource paramDamageSource) {
  94.         super.die(paramDamageSource);
  95.     }
  96.    
  97.     public void a_(EntityHuman paramEntityHuman) {}
  98.    
  99.     public EntityHuman b() {
  100.         return null;
  101.     }
  102.    
  103.     public boolean ca() {
  104.         return false;
  105.     }
  106.    
  107.     public void a(MerchantRecipe paramMerchantRecipe) {}
  108.    
  109.     public void a_(ItemStack paramItemStack) {}
  110.    
  111.     public MerchantRecipeList getOffers(EntityHuman paramEntityHuman) {
  112.         return this.bu;
  113.     }
  114.    
  115.     @Override
  116.     public EntityAgeable createChild(EntityAgeable arg0) {
  117.         EntityVillager localEntityVillager = new EntityVillager(this.world);
  118.         return localEntityVillager;
  119.     }
  120.    
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement