Advertisement
Guest User

Untitled

a guest
Jan 13th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.50 KB | None | 0 0
  1. package MultiTech;
  2.  
  3. import java.util.List;
  4.  
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7. import ic2.api.ElectricItem;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.entity.EntityLiving;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.EnumAction;
  12. import net.minecraft.item.ItemFood;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.potion.PotionEffect;
  15. import net.minecraft.world.World;
  16. import ic2.api.ElectricItem;
  17. import ic2.api.IElectricItem;
  18. import net.minecraft.item.*;
  19.  
  20.  
  21. public class ItemUUFood extends ItemFood implements IElectricItem
  22. {
  23.     public int mCharge, mTransfer, mTier;
  24.    
  25.    
  26.    
  27.     /** Number of ticks to run while 'EnumAction'ing until result. */
  28.     public final int itemUseDuration;
  29.  
  30.     /** The amount this food item heals the player. */
  31.     private final int healAmount;
  32.     private final float saturationModifier;
  33.  
  34.     /** Whether wolves like this food (true for raw and cooked porkchop). */
  35.     private final boolean isWolfsFavoriteMeat;
  36.  
  37.     /**
  38.      * If this field is true, the food can be consumed even if the player don't need to eat.
  39.      */
  40.     private boolean alwaysEdible;
  41.  
  42.     /**
  43.      * represents the potion effect that will occurr upon eating this food. Set by setPotionEffect
  44.      */
  45.     private int potionId;
  46.  
  47.     /** set by setPotionEffect */
  48.     private int potionDuration;
  49.  
  50.     /** set by setPotionEffect */
  51.     private int potionAmplifier;
  52.  
  53.     /** probably of the set potion effect occurring */
  54.     private float potionEffectProbability;
  55.  
  56.     public ItemUUFood(int par1, int par2, float par3, boolean par4)
  57.     {
  58.         super(par1, par2, par3, par4);
  59.         this.itemUseDuration = 32;
  60.         this.healAmount = par2;
  61.         this.isWolfsFavoriteMeat = par4;
  62.         this.saturationModifier = par3;
  63.         this.setCreativeTab(CreativeTabs.tabFood);
  64.         this.setNoRepair();
  65.         this.setMaxStackSize(1);
  66.         setMaxDamage(100);
  67.         setNoRepair();
  68.         mCharge = 100000;
  69.         mTransfer = 512;
  70.         mTier = 1;
  71.        
  72.        
  73.     }
  74.    
  75.     public String getTextureFile()
  76.     {
  77.             return CommonProxy.ITEMS_PNG;
  78.     }
  79.    
  80.     public ItemUUFood(int par1, int par2, boolean par3)
  81.     {
  82.         this(par1, par2, 0.6F, par3);
  83.     }
  84.  
  85.     public ItemStack onFoodEaten(ItemStack var1, World var2, int var3, int var4, int var5, int var6, EntityLiving var7, EntityPlayer var8)
  86.     {
  87.        
  88.         var8.getFoodStats().addStats(this);
  89.         var2.playSoundAtEntity(var8, "random.burp", 0.5F, var2.rand.nextFloat() * 0.1F + 0.9F);
  90.         if (var8 instanceof EntityPlayer) {
  91.             ElectricItem.use(var1, 500, (EntityPlayer)var8);
  92.         } else {
  93.             ElectricItem.discharge(var1, 500, mTier, true, false);
  94.         }
  95.         return var1;
  96.     }
  97.  
  98.     protected void func_77849_c(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  99.     {
  100.         if (!par2World.isRemote && this.potionId > 0 && par2World.rand.nextFloat() < this.potionEffectProbability)
  101.         {
  102.             par3EntityPlayer.addPotionEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier));
  103.         }
  104.     }
  105.  
  106.     /**
  107.      * How long it takes to use or consume an item
  108.      */
  109.     @Override
  110.     public boolean onItemUse(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int aSide, float var8, float var9, float var10) {
  111.         ElectricItem.use(aStack, 0, aPlayer);
  112.         return true;
  113.     }
  114.    
  115.     @Override
  116.     public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
  117.     }
  118.    
  119.     @Override
  120.     public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) {
  121.         return false;
  122.     }
  123.    
  124.    
  125.     public int getMaxItemUseDuration(ItemStack par1ItemStack)
  126.     {
  127.         return 32;
  128.     }
  129.  
  130.     /**
  131.      * returns the action that specifies what animation to play when the items is being used
  132.      */
  133.     public EnumAction getItemUseAction(ItemStack par1ItemStack)
  134.     {
  135.         return EnumAction.eat;
  136.     }
  137.  
  138.     /**
  139.      * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  140.      */
  141.     public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  142.     {
  143.         if (par3EntityPlayer.canEat(this.alwaysEdible))
  144.         {
  145.             par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  146.         }
  147.  
  148.         return par1ItemStack;
  149.     }
  150.  
  151.     public int getHealAmount()
  152.     {
  153.         return this.healAmount;
  154.     }
  155.  
  156.     /**
  157.      * gets the saturationModifier of the ItemFood
  158.      */
  159.     public float getSaturationModifier()
  160.     {
  161.         return this.saturationModifier;
  162.     }
  163.  
  164.     /**
  165.      * Whether wolves like this food (true for raw and cooked porkchop).
  166.      */
  167.     public boolean isWolfsFavoriteMeat()
  168.     {
  169.         return this.isWolfsFavoriteMeat;
  170.     }
  171.  
  172.     /**
  173.      * sets a potion effect on the item. Args: int potionId, int duration (will be multiplied by 20), int amplifier,
  174.      * float probability of effect happening
  175.      */
  176.     public ItemUUFood setPotionEffect(int par1, int par2, int par3, float par4)
  177.     {
  178.         this.potionId = par1;
  179.         this.potionDuration = par2;
  180.         this.potionAmplifier = par3;
  181.         this.potionEffectProbability = par4;
  182.         return this;
  183.     }
  184.  
  185.     /**
  186.      * Set the field 'alwaysEdible' to true, and make the food edible even if the player don't need to eat.
  187.      */
  188.     public ItemUUFood setAlwaysEdible()
  189.     {
  190.         this.alwaysEdible = true;
  191.         return this;
  192.     }
  193.    
  194.  
  195.     @Override
  196.     @SideOnly(Side.CLIENT)
  197.     public void getSubItems(int var1, CreativeTabs var2, List var3) {
  198.         ItemStack tCharged = new ItemStack(this, 1), tUncharged = new ItemStack(this, 1, getMaxDamage());
  199.         ElectricItem.charge(tCharged, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false);
  200.         var3.add(tCharged);
  201.         var3.add(tUncharged);
  202.     }
  203.  
  204.     @Override
  205.     public boolean getShareTag() {
  206.         return true;
  207.     }
  208.    
  209.     @Override
  210.     public boolean canProvideEnergy() {
  211.         return false;
  212.     }
  213.    
  214.     @Override
  215.     public int getChargedItemId() {
  216.         return itemID;
  217.     }
  218.    
  219.     @Override
  220.     public int getEmptyItemId() {
  221.         return itemID;
  222.     }
  223.    
  224.     @Override
  225.     public int getMaxCharge() {
  226.         return mCharge;
  227.     }
  228.    
  229.     @Override
  230.     public int getTier() {
  231.         return mTier;
  232.     }
  233.    
  234.     @Override
  235.     public int getTransferLimit() {
  236.         return mTransfer;
  237.     }
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement