Advertisement
ViiRuS

Taming Template

Apr 14th, 2012
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.40 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.Random;
  4.  
  5. public class EntitySmartPhone extends EntityTameable
  6. {
  7.  
  8.     public EntitySmartPhone(World par1World)
  9.     {
  10.         super(par1World);
  11.         setSize(0.9F, 1.3F);
  12.         getNavigator().func_48664_a(true);
  13.         tasks.addTask(2, aiSit);
  14.         tasks.addTask(5, new EntityAIFollowOwner(this, 0.3F, 10F, 5F));
  15.         tasks.addTask(9, new EntityAIMate(this, 0.23F));
  16.         tasks.addTask(10, new EntityAIWander(this, 0.23F));
  17.         tasks.addTask(11, new EntityAIWatchClosest(this, net.minecraft.src.EntityPlayer.class, 10F));
  18.     }
  19.  
  20.     private static final ItemStack defaultHeldItem;
  21.  
  22.     protected void entityInit()
  23.     {
  24.         super.entityInit();
  25.         dataWatcher.addObject(18, Byte.valueOf((byte)0));
  26.     }
  27.  
  28.     public void onUpdate()
  29.     {
  30.         super.onUpdate();
  31.     }
  32.  
  33.     public boolean isAIEnabled()
  34.     {
  35.         return true;
  36.     }
  37.  
  38.     protected boolean canDespawn()
  39.     {
  40.         return !isTamed();
  41.     }
  42.  
  43.     protected void fall(float f)
  44.     {
  45.     }
  46.  
  47.     public int getMaxHealth()
  48.     {
  49.         return 10;
  50.     }
  51.  
  52.  
  53.     public String getTexture()
  54.     {
  55.         if(!isTamed())
  56.         {
  57.             if(on == true)
  58.             {
  59.                 return "/mods/on.png";
  60.             }
  61.             else
  62.             {
  63.                 return "/mods/off.png";
  64.             }
  65.  
  66.         }
  67.         else
  68.         {
  69.             if(on == true)
  70.             {
  71.                 return "/mods/tamedon.png";
  72.             }
  73.             else
  74.             {
  75.                 return "/mods/tamedoff.png";
  76.             }
  77.         }
  78.     }
  79.  
  80.     public int foodNum;
  81.     public int tamedNum;
  82.  
  83.     public void writeEntityToNBT(NBTTagCompound nbt)
  84.     {
  85.         super.writeEntityToNBT(nbt);
  86.         nbt.setBoolean("on", on);
  87.         nbt.setInteger("foodnum", foodNum);
  88.         nbt.setInteger("tamednum", tamedNum);
  89.  
  90.     }
  91.  
  92.  
  93.     public void readEntityFromNBT(NBTTagCompound nbt)
  94.     {
  95.         super.readEntityFromNBT(nbt);
  96.         on = nbt.getBoolean("on");
  97.         tamedNum = nbt.getInteger("tamednum");
  98.         foodNum = nbt.getInteger("foodnum");
  99.     }
  100.  
  101.     /*public ItemStack getHeldItem()
  102.     {
  103.         return defaultHeldItem;
  104.     }*/
  105.  
  106.     /*protected String getLivingSound()
  107.     {
  108.         return "mob.cow";
  109.     }
  110.  
  111.  
  112.     protected String getHurtSound()
  113.     {
  114.         return "mob.cowhurt";
  115.     }
  116.  
  117.  
  118.     protected String getDeathSound()
  119.     {
  120.         return "mob.cowhurt";
  121.     }*/
  122.  
  123.  
  124.     protected float getSoundVolume()
  125.     {
  126.         return 0.4F;
  127.     }
  128.  
  129.     protected void dropFewItems(boolean par1, int par2)
  130.     {
  131.         if(on == false)
  132.         {
  133.             boolean g = rand.nextBoolean();
  134.             if(g == true)
  135.             {
  136.                 int num = rand.nextInt(3) + 1;
  137.                 for(int k = 0; k < num; k++)
  138.                 {
  139.                     dropItem(Item.diamond.shiftedIndex, 1);
  140.                 }
  141.             }
  142.             else
  143.             {
  144.                 int lol = rand.nextInt(8);
  145.                 if(lol <= 3)
  146.                 {
  147.                     dropItem(Item.diamond.shiftedIndex, 1);
  148.                 }
  149.                 else if(lol >= 4 && lol <= 6)
  150.                 {
  151.                     dropItem(Item.diamond.shiftedIndex, 2);
  152.                 }
  153.                 else if(lol >= 7 && lol <= 8)
  154.                 {
  155.                     dropItem(Item.diamond.shiftedIndex, 3);
  156.                 }
  157.             }
  158.         }
  159.         else
  160.         {
  161.             int num = rand.nextInt(3) + 1;
  162.             switch(num)
  163.             {
  164.             case 1:
  165.                 dropItem(Item.diamond.shiftedIndex, 2);
  166.                 break;
  167.  
  168.             case 2:
  169.                 dropItem(Item.cookie.shiftedIndex, 2); 
  170.                 break;
  171.  
  172.             case 3:
  173.                 dropItem(Item.appleGold.shiftedIndex, 2);  
  174.                 break;
  175.  
  176.             case 4:
  177.                 dropItem(Item.swordDiamond.shiftedIndex, 2);   
  178.                 break;
  179.             }
  180.         }
  181.     }
  182.  
  183.     public boolean on;
  184.  
  185.     public boolean interact(EntityPlayer par1EntityPlayer)
  186.     {  
  187.         ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
  188.  
  189.         if(tamedNum == 0)
  190.         {
  191.             tamedNum = rand.nextInt(3) + 1;
  192.         }
  193.  
  194.         if (!isTamed())
  195.         {
  196.             //Taming
  197.             if (itemstack != null && itemstack.itemID == Block.dirt.blockID && par1EntityPlayer.getDistanceSqToEntity(this) < 9D)
  198.             {
  199.                 itemstack.stackSize--;
  200.                 foodNum++;
  201.                 if (itemstack.stackSize <= 0)
  202.                 {
  203.                     par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, null);
  204.                 }
  205.  
  206.                 if (!worldObj.isRemote && foodNum >= tamedNum)
  207.                 {
  208.                     setTamed(true);
  209.                     setOwner(par1EntityPlayer.username);
  210.                     aiSit.func_48407_a(true);
  211.                     worldObj.setEntityState(this, (byte)7);
  212.                     ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Tamed!");
  213.                 }
  214.                 else
  215.                 {
  216.                     ModLoader.getMinecraftInstance().thePlayer.addChatMessage(Integer.toString(tamedNum - foodNum));
  217.                 }
  218.             }
  219.  
  220.             return true;
  221.         }
  222.         else
  223.         {
  224.             on = !on;
  225.         }
  226.  
  227.         return super.interact(par1EntityPlayer);  
  228.     }
  229.  
  230.     public EntityAnimal spawnBabyAnimal(EntityAnimal par1EntityAnimal)
  231.     {
  232.         return new EntitySmartPhone(worldObj);
  233.     }
  234.  
  235.     public int func_48148_ad()
  236.     {
  237.         return dataWatcher.getWatchableObjectByte(18);
  238.     }
  239.  
  240.     static
  241.     {
  242.         defaultHeldItem = new ItemStack(Block.oreDiamond, 1);
  243.     }
  244.  
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement