Advertisement
ViiRuS

Taming and Saddling Template

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