Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.57 KB | None | 0 0
  1. package net.minecraft.potion;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.init.Items;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12.  
  13. public class PotionEffect
  14. {
  15.     /** ID value of the potion this effect matches. */
  16.     private int potionID;
  17.     /** The duration of the potion effect */
  18.     public int duration;
  19.     /** The amplifier of the potion effect */
  20.     private int amplifier;
  21.     /** Whether the potion is a splash potion */
  22.     private boolean isSplashPotion;
  23.     /** Whether the potion effect came from a beacon */
  24.     private boolean isAmbient;
  25.     /** True if potion effect duration is at maximum, false otherwise. */
  26.     @SideOnly(Side.CLIENT)
  27.     private boolean isPotionDurationMax;
  28.     private static final String __OBFID = "CL_00001529";
  29.     /** List of ItemStack that can cure the potion effect **/
  30.     private List<ItemStack> curativeItems;
  31.  
  32.     public PotionEffect(int p_i1574_1_, int p_i1574_2_)
  33.     {
  34.         this(p_i1574_1_, p_i1574_2_, 0);
  35.     }
  36.  
  37.     public PotionEffect(int p_i1575_1_, int p_i1575_2_, int p_i1575_3_)
  38.     {
  39.         this(p_i1575_1_, p_i1575_2_, p_i1575_3_, false);
  40.     }
  41.  
  42.     public PotionEffect(int p_i1576_1_, int p_i1576_2_, int p_i1576_3_, boolean p_i1576_4_)
  43.     {
  44.         this.potionID = p_i1576_1_;
  45.         this.duration = p_i1576_2_;
  46.         this.amplifier = p_i1576_3_;
  47.         this.isAmbient = p_i1576_4_;
  48.         this.curativeItems = new ArrayList<ItemStack>();
  49.         this.curativeItems.add(new ItemStack(Items.milk_bucket));
  50.     }
  51.  
  52.     public PotionEffect(PotionEffect p_i1577_1_)
  53.     {
  54.         this.potionID = p_i1577_1_.potionID;
  55.         this.duration = p_i1577_1_.duration;
  56.         this.amplifier = p_i1577_1_.amplifier;
  57.         this.curativeItems = p_i1577_1_.curativeItems;
  58.     }
  59.  
  60.     /**
  61.      * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied
  62.      * potion effect is assumed to be greater.
  63.      */
  64.     public void combine(PotionEffect p_76452_1_)
  65.     {
  66.         if (this.potionID != p_76452_1_.potionID)
  67.         {
  68.             System.err.println("This method should only be called for matching effects!");
  69.         }
  70.  
  71.         if (p_76452_1_.amplifier > this.amplifier)
  72.         {
  73.             this.amplifier = p_76452_1_.amplifier;
  74.             this.duration = p_76452_1_.duration;
  75.         }
  76.         else if (p_76452_1_.amplifier == this.amplifier && this.duration < p_76452_1_.duration)
  77.         {
  78.             this.duration = p_76452_1_.duration;
  79.         }
  80.         else if (!p_76452_1_.isAmbient && this.isAmbient)
  81.         {
  82.             this.isAmbient = p_76452_1_.isAmbient;
  83.         }
  84.     }
  85.  
  86.     /**
  87.      * Retrieve the ID of the potion this effect matches.
  88.      */
  89.     public int getPotionID()
  90.     {
  91.         return this.potionID;
  92.     }
  93.  
  94.     public int getDuration()
  95.     {
  96.         return this.duration;
  97.     }
  98.  
  99.     public int getAmplifier()
  100.     {
  101.         return this.amplifier;
  102.     }
  103.  
  104.     /**
  105.      * Set whether this potion is a splash potion.
  106.      */
  107.     public void setSplashPotion(boolean p_82721_1_)
  108.     {
  109.         this.isSplashPotion = p_82721_1_;
  110.     }
  111.  
  112.     /**
  113.      * Gets whether this potion effect originated from a beacon
  114.      */
  115.     public boolean getIsAmbient()
  116.     {
  117.         return this.isAmbient;
  118.     }
  119.  
  120.     public boolean onUpdate(EntityLivingBase p_76455_1_)
  121.     {
  122.         if (this.duration > 0)
  123.         {
  124.             if (Potion.potionTypes[this.potionID].isReady(this.duration, this.amplifier))
  125.             {
  126.                 this.performEffect(p_76455_1_);
  127.             }
  128.  
  129.             this.deincrementDuration();
  130.         }
  131.  
  132.         return this.duration > 0;
  133.     }
  134.  
  135.     public int deincrementDuration()
  136.     {
  137.         return --this.duration;
  138.     }
  139.  
  140.     public void performEffect(EntityLivingBase p_76457_1_)
  141.     {
  142.         if (this.duration > 0)
  143.         {
  144.             Potion.potionTypes[this.potionID].performEffect(p_76457_1_, this.amplifier);
  145.         }
  146.     }
  147.  
  148.     public String getEffectName()
  149.     {
  150.         return Potion.potionTypes[this.potionID].getName();
  151.     }
  152.  
  153.     public int hashCode()
  154.     {
  155.         return this.potionID;
  156.     }
  157.  
  158.     public String toString()
  159.     {
  160.         String s = "";
  161.  
  162.         if (this.getAmplifier() > 0)
  163.         {
  164.             s = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration();
  165.         }
  166.         else
  167.         {
  168.             s = this.getEffectName() + ", Duration: " + this.getDuration();
  169.         }
  170.  
  171.         if (this.isSplashPotion)
  172.         {
  173.             s = s + ", Splash: true";
  174.         }
  175.  
  176.         return Potion.potionTypes[this.potionID].isUsable() ? "(" + s + ")" : s;
  177.     }
  178.  
  179.     public boolean equals(Object p_equals_1_)
  180.     {
  181.         if (!(p_equals_1_ instanceof PotionEffect))
  182.         {
  183.             return false;
  184.         }
  185.         else
  186.         {
  187.             PotionEffect potioneffect = (PotionEffect)p_equals_1_;
  188.             return this.potionID == potioneffect.potionID && this.amplifier == potioneffect.amplifier && this.duration == potioneffect.duration && this.isSplashPotion == potioneffect.isSplashPotion && this.isAmbient == potioneffect.isAmbient;
  189.         }
  190.     }
  191.  
  192.     /**
  193.      * Write a custom potion effect to a potion item's NBT data.
  194.      */
  195.     public NBTTagCompound writeCustomPotionEffectToNBT(NBTTagCompound p_82719_1_)
  196.     {
  197.         p_82719_1_.setByte("Id", (byte)this.getPotionID());
  198.         p_82719_1_.setByte("Amplifier", (byte)this.getAmplifier());
  199.         p_82719_1_.setInteger("Duration", this.getDuration());
  200.         p_82719_1_.setBoolean("Ambient", this.getIsAmbient());
  201.         return p_82719_1_;
  202.     }
  203.  
  204.     /**
  205.      * Read a custom potion effect from a potion item's NBT data.
  206.      */
  207.     public static PotionEffect readCustomPotionEffectFromNBT(NBTTagCompound p_82722_0_)
  208.     {
  209.         byte b0 = p_82722_0_.getByte("Id");
  210.  
  211.         if (b0 >= 0 && b0 < Potion.potionTypes.length && Potion.potionTypes[b0] != null)
  212.         {
  213.             byte b1 = p_82722_0_.getByte("Amplifier");
  214.             int i = p_82722_0_.getInteger("Duration");
  215.             boolean flag = p_82722_0_.getBoolean("Ambient");
  216.             return new PotionEffect(b0, i, b1, flag);
  217.         }
  218.         else
  219.         {
  220.             return null;
  221.         }
  222.     }
  223.  
  224.     /**
  225.      * Toggle the isPotionDurationMax field.
  226.      */
  227.     @SideOnly(Side.CLIENT)
  228.     public void setPotionDurationMax(boolean p_100012_1_)
  229.     {
  230.         this.isPotionDurationMax = p_100012_1_;
  231.     }
  232.  
  233.     @SideOnly(Side.CLIENT)
  234.     public boolean getIsPotionDurationMax()
  235.     {
  236.         return this.isPotionDurationMax;
  237.     }
  238.  
  239.     /* ======================================== FORGE START =====================================*/
  240.     /***
  241.      * Returns a list of curative items for the potion effect
  242.      * @return The list (ItemStack) of curative items for the potion effect
  243.      */
  244.     public List<ItemStack> getCurativeItems()
  245.     {
  246.         return this.curativeItems;
  247.     }
  248.  
  249.     /***
  250.      * Checks the given ItemStack to see if it is in the list of curative items for the potion effect
  251.      * @param stack The ItemStack being checked against the list of curative items for the potion effect
  252.      * @return true if the given ItemStack is in the list of curative items for the potion effect, false otherwise
  253.      */
  254.     public boolean isCurativeItem(ItemStack stack)
  255.     {
  256.         boolean found = false;
  257.         for (ItemStack curativeItem : this.curativeItems)
  258.         {
  259.             if (curativeItem.isItemEqual(stack))
  260.             {
  261.                 found = true;
  262.             }
  263.         }
  264.  
  265.         return found;
  266.     }
  267.  
  268.     /***
  269.      * Sets the array of curative items for the potion effect
  270.      * @param curativeItems The list of ItemStacks being set to the potion effect
  271.      */
  272.     public void setCurativeItems(List<ItemStack> curativeItems)
  273.     {
  274.         this.curativeItems = curativeItems;
  275.     }
  276.  
  277.     /***
  278.      * Adds the given stack to list of curative items for the potion effect
  279.      * @param stack The ItemStack being added to the curative item list
  280.      */
  281.     public void addCurativeItem(ItemStack stack)
  282.     {
  283.         boolean found = false;
  284.         for (ItemStack curativeItem : this.curativeItems)
  285.         {
  286.             if (curativeItem.isItemEqual(stack))
  287.             {
  288.                 found = true;
  289.             }
  290.         }
  291.         if (!found)
  292.         {
  293.             this.curativeItems.add(stack);
  294.         }
  295.     }
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement