Advertisement
Guest User

Untitled

a guest
Aug 21st, 2012
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. package Tutorial.common;
  2.  
  3. import net.minecraft.src.CreativeTabs;
  4. import net.minecraft.src.EntityPlayer;
  5. import net.minecraft.src.EnumAction;
  6. import net.minecraft.src.Item;
  7. import net.minecraft.src.ItemFood;
  8. import net.minecraft.src.ItemStack;
  9. import net.minecraft.src.PotionEffect;
  10. import net.minecraft.src.World;
  11.  
  12. public class ItemTutorialFood extends ItemFood
  13. {
  14. /** Number of ticks to run while 'EnumAction'ing until result. */
  15. public final int itemUseDuration;
  16.  
  17. /** The amount this food item heals the player. */
  18. private final int healAmount;
  19. private final float saturationModifier;
  20.  
  21. /** Whether wolves like this food (true for raw and cooked porkchop). */
  22. private final boolean isWolfsFavoriteMeat;
  23.  
  24. /**
  25. * If this field is true, the food can be consumed even if the player don't need to eat.
  26. */
  27. private boolean alwaysEdible;
  28.  
  29. /**
  30. * represents the potion effect that will occurr upon eating this food. Set by setPotionEffect
  31. */
  32. private int potionId;
  33.  
  34. /** set by setPotionEffect */
  35. private int potionDuration;
  36.  
  37. /** set by setPotionEffect */
  38. private int potionAmplifier;
  39.  
  40. /** probably of the set potion effect occurring */
  41. private float potionEffectProbability;
  42.  
  43. public ItemTutorialFood(int par1, int par2, float par3, boolean par4)
  44. {
  45. super(par1, par2, par3, par4);
  46. this.itemUseDuration = 32;
  47. this.healAmount = par2;
  48. this.isWolfsFavoriteMeat = par4;
  49. this.saturationModifier = par3;
  50. this.setTabToDisplayOn(CreativeTabs.tabFood);
  51. }
  52.  
  53. public String getTextureFile()
  54. {
  55. return "/TutTextures.png";
  56. }
  57.  
  58. public ItemTutorialFood(int par1, int par2, boolean par3)
  59. {
  60. this(par1, par2, 0.6F, par3);
  61. }
  62.  
  63. public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  64. {
  65. --par1ItemStack.stackSize;
  66. par3EntityPlayer.getFoodStats().addStats(this);
  67. par2World.playSoundAtEntity(par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F);
  68. this.func_77849_c(par1ItemStack, par2World, par3EntityPlayer);
  69. return par1ItemStack;
  70. }
  71.  
  72. protected void func_77849_c(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  73. {
  74. if (!par2World.isRemote && this.potionId > 0 && par2World.rand.nextFloat() < this.potionEffectProbability)
  75. {
  76. par3EntityPlayer.addPotionEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier));
  77. }
  78. }
  79.  
  80. /**
  81. * How long it takes to use or consume an item
  82. */
  83. public int getMaxItemUseDuration(ItemStack par1ItemStack)
  84. {
  85. return 32;
  86. }
  87.  
  88. /**
  89. * returns the action that specifies what animation to play when the items is being used
  90. */
  91. public EnumAction getItemUseAction(ItemStack par1ItemStack)
  92. {
  93. return EnumAction.eat;
  94. }
  95.  
  96. /**
  97. * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  98. */
  99. public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  100. {
  101. if (par3EntityPlayer.canEat(this.alwaysEdible))
  102. {
  103. par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  104. }
  105.  
  106. return par1ItemStack;
  107. }
  108.  
  109. public int getHealAmount()
  110. {
  111. return this.healAmount;
  112. }
  113.  
  114. /**
  115. * gets the saturationModifier of the ItemFood
  116. */
  117. public float getSaturationModifier()
  118. {
  119. return this.saturationModifier;
  120. }
  121.  
  122. /**
  123. * Whether wolves like this food (true for raw and cooked porkchop).
  124. */
  125. public boolean isWolfsFavoriteMeat()
  126. {
  127. return this.isWolfsFavoriteMeat;
  128. }
  129.  
  130. /**
  131. * sets a potion effect on the item. Args: int potionId, int duration (will be multiplied by 20), int amplifier,
  132. * float probability of effect happening
  133. */
  134. public ItemTutorialFood setPotionEffect(int par1, int par2, int par3, float par4)
  135. {
  136. this.potionId = par1;
  137. this.potionDuration = par2;
  138. this.potionAmplifier = par3;
  139. this.potionEffectProbability = par4;
  140. return this;
  141. }
  142.  
  143. /**
  144. * Set the field 'alwaysEdible' to true, and make the food edible even if the player don't need to eat.
  145. */
  146. public ItemTutorialFood setAlwaysEdible()
  147. {
  148. this.alwaysEdible = true;
  149. return this;
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement