001 package net.minecraft.src; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 public class PotionEffect 007 { 008 /** ID value of the potion this effect matches. */ 009 private int potionID; 010 011 /** The duration of the potion effect */ 012 private int duration; 013 014 /** The amplifier of the potion effect */ 015 private int amplifier; 016 017 /** List of ItemStack that can cure the potion effect **/ 018 private List<ItemStack> curativeItems; 019 020 public PotionEffect(int par1, int par2, int par3) 021 { 022 this.potionID = par1; 023 this.duration = par2; 024 this.amplifier = par3; 025 this.curativeItems = new ArrayList<ItemStack>(); 026 this.curativeItems.add(new ItemStack(Item.bucketMilk)); 027 } 028 029 public PotionEffect(PotionEffect par1PotionEffect) 030 { 031 this.potionID = par1PotionEffect.potionID; 032 this.duration = par1PotionEffect.duration; 033 this.amplifier = par1PotionEffect.amplifier; 034 this.curativeItems = par1PotionEffect.getCurativeItems(); 035 } 036 037 /** 038 * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied 039 * potion effect is assumed to be greater. 040 */ 041 public void combine(PotionEffect par1PotionEffect) 042 { 043 if (this.potionID != par1PotionEffect.potionID) 044 { 045 System.err.println("This method should only be called for matching effects!"); 046 } 047 048 if (par1PotionEffect.amplifier > this.amplifier) 049 { 050 this.amplifier = par1PotionEffect.amplifier; 051 this.duration = par1PotionEffect.duration; 052 } 053 else if (par1PotionEffect.amplifier == this.amplifier && this.duration < par1PotionEffect.duration) 054 { 055 this.duration = par1PotionEffect.duration; 056 } 057 } 058 059 /** 060 * Retrieve the ID of the potion this effect matches. 061 */ 062 public int getPotionID() 063 { 064 return this.potionID; 065 } 066 067 public int getDuration() 068 { 069 return this.duration; 070 } 071 072 public int getAmplifier() 073 { 074 return this.amplifier; 075 } 076 077 /*** 078 * Returns a list of curative items for the potion effect 079 * @return The list (ItemStack) of curative items for the potion effect 080 */ 081 public List<ItemStack> getCurativeItems() 082 { 083 return this.curativeItems; 084 } 085 086 /*** 087 * Checks the given ItemStack to see if it is in the list of curative items for the potion effect 088 * @param stack The ItemStack being checked against the list of curative items for the potion effect 089 * @return true if the given ItemStack is in the list of curative items for the potion effect, false otherwise 090 */ 091 public boolean isCurativeItem(ItemStack stack) 092 { 093 boolean found = false; 094 for (ItemStack curativeItem : this.curativeItems) 095 { 096 if (curativeItem.isItemEqual(stack)) 097 { 098 found = true; 099 } 100 } 101 102 return found; 103 } 104 105 /*** 106 * Sets the array of curative items for the potion effect 107 * @param curativeItems The list of ItemStacks being set to the potion effect 108 */ 109 public void setCurativeItems(List<ItemStack> curativeItems) 110 { 111 this.curativeItems = curativeItems; 112 } 113 114 /*** 115 * Adds the given stack to list of curative items for the potion effect 116 * @param stack The ItemStack being added to the curative item list 117 */ 118 public void addCurativeItem(ItemStack stack) 119 { 120 boolean found = false; 121 for (ItemStack curativeItem : this.curativeItems) 122 { 123 if (curativeItem.isItemEqual(stack)) 124 { 125 found = true; 126 } 127 } 128 if (!found) 129 { 130 this.curativeItems.add(stack); 131 } 132 } 133 134 public boolean onUpdate(EntityLiving par1EntityLiving) 135 { 136 if (this.duration > 0) 137 { 138 if (Potion.potionTypes[this.potionID].isReady(this.duration, this.amplifier)) 139 { 140 this.performEffect(par1EntityLiving); 141 } 142 143 this.deincrementDuration(); 144 } 145 146 return this.duration > 0; 147 } 148 149 private int deincrementDuration() 150 { 151 return --this.duration; 152 } 153 154 public void performEffect(EntityLiving par1EntityLiving) 155 { 156 if (this.duration > 0) 157 { 158 Potion.potionTypes[this.potionID].performEffect(par1EntityLiving, this.amplifier); 159 } 160 } 161 162 public String getEffectName() 163 { 164 return Potion.potionTypes[this.potionID].getName(); 165 } 166 167 public int hashCode() 168 { 169 return this.potionID; 170 } 171 172 public String toString() 173 { 174 String var1 = ""; 175 176 if (this.getAmplifier() > 0) 177 { 178 var1 = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration(); 179 } 180 else 181 { 182 var1 = this.getEffectName() + ", Duration: " + this.getDuration(); 183 } 184 185 return Potion.potionTypes[this.potionID].isUsable() ? "(" + var1 + ")" : var1; 186 } 187 188 public boolean equals(Object par1Obj) 189 { 190 if (!(par1Obj instanceof PotionEffect)) 191 { 192 return false; 193 } 194 else 195 { 196 PotionEffect var2 = (PotionEffect)par1Obj; 197 return this.potionID == var2.potionID && this.amplifier == var2.amplifier && this.duration == var2.duration; 198 } 199 } 200 }