001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.util.Iterator; 006 import java.util.List; 007 008 public class TileEntityBeacon extends TileEntity implements IInventory 009 { 010 public static final Potion[][] field_82139_a = new Potion[][] {{Potion.moveSpeed, Potion.digSpeed}, {Potion.resistance, Potion.jump}, {Potion.damageBoost}, {Potion.regeneration}}; 011 @SideOnly(Side.CLIENT) 012 private long field_82137_b; 013 @SideOnly(Side.CLIENT) 014 private float field_82138_c; 015 private boolean field_82135_d; 016 private int field_82136_e = -1; 017 private int field_82133_f; 018 private int field_82134_g; 019 private ItemStack field_82140_h; 020 021 /** 022 * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count 023 * ticks and creates a new spawn inside its implementation. 024 */ 025 public void updateEntity() 026 { 027 if (this.worldObj.func_82737_E() % 80L == 0L) 028 { 029 this.func_82131_u(); 030 this.func_82124_t(); 031 } 032 } 033 034 private void func_82124_t() 035 { 036 if (this.field_82135_d && this.field_82136_e > 0 && !this.worldObj.isRemote && this.field_82133_f > 0) 037 { 038 double var1 = (double)(this.field_82136_e * 8 + 8); 039 byte var3 = 0; 040 041 if (this.field_82136_e >= 4 && this.field_82133_f == this.field_82134_g) 042 { 043 var3 = 1; 044 } 045 046 AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)).expand(var1, var1, var1); 047 List var5 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, var4); 048 Iterator var6 = var5.iterator(); 049 EntityPlayer var7; 050 051 while (var6.hasNext()) 052 { 053 var7 = (EntityPlayer)var6.next(); 054 var7.addPotionEffect(new PotionEffect(this.field_82133_f, 180, var3, true)); 055 } 056 057 if (this.field_82136_e >= 4 && this.field_82133_f != this.field_82134_g && this.field_82134_g > 0) 058 { 059 var6 = var5.iterator(); 060 061 while (var6.hasNext()) 062 { 063 var7 = (EntityPlayer)var6.next(); 064 var7.addPotionEffect(new PotionEffect(this.field_82134_g, 180, 0, true)); 065 } 066 } 067 } 068 } 069 070 private void func_82131_u() 071 { 072 if (!this.worldObj.canBlockSeeTheSky(this.xCoord, this.yCoord + 1, this.zCoord)) 073 { 074 this.field_82135_d = false; 075 this.field_82136_e = 0; 076 } 077 else 078 { 079 this.field_82135_d = true; 080 this.field_82136_e = 0; 081 082 for (int var1 = 1; var1 <= 4; this.field_82136_e = var1++) 083 { 084 int var2 = this.yCoord - var1; 085 086 if (var2 < 1) 087 { 088 break; 089 } 090 091 boolean var3 = true; 092 093 for (int var4 = this.xCoord - var1; var4 <= this.xCoord + var1 && var3; ++var4) 094 { 095 for (int var5 = this.zCoord - var1; var5 <= this.zCoord + var1; ++var5) 096 { 097 int var6 = this.worldObj.getBlockId(var4, var2, var5); 098 Block block = Block.blocksList[var6]; 099 100 if (block == null || !block.isBeaconBase(worldObj, var4, var2, var5, xCoord, yCoord, zCoord)) 101 { 102 var3 = false; 103 break; 104 } 105 } 106 } 107 108 if (!var3) 109 { 110 break; 111 } 112 } 113 114 if (this.field_82136_e == 0) 115 { 116 this.field_82135_d = false; 117 } 118 } 119 } 120 121 @SideOnly(Side.CLIENT) 122 public float func_82125_v_() 123 { 124 if (!this.field_82135_d) 125 { 126 return 0.0F; 127 } 128 else 129 { 130 int var1 = (int)(this.worldObj.func_82737_E() - this.field_82137_b); 131 this.field_82137_b = this.worldObj.func_82737_E(); 132 133 if (var1 > 1) 134 { 135 this.field_82138_c -= (float)var1 / 40.0F; 136 137 if (this.field_82138_c < 0.0F) 138 { 139 this.field_82138_c = 0.0F; 140 } 141 } 142 143 this.field_82138_c += 0.025F; 144 145 if (this.field_82138_c > 1.0F) 146 { 147 this.field_82138_c = 1.0F; 148 } 149 150 return this.field_82138_c; 151 } 152 } 153 154 public int func_82126_i() 155 { 156 return this.field_82133_f; 157 } 158 159 public int func_82132_j() 160 { 161 return this.field_82134_g; 162 } 163 164 public int func_82130_k() 165 { 166 return this.field_82136_e; 167 } 168 169 @SideOnly(Side.CLIENT) 170 public void func_82129_c(int par1) 171 { 172 this.field_82136_e = par1; 173 } 174 175 public void func_82128_d(int par1) 176 { 177 this.field_82133_f = 0; 178 179 for (int var2 = 0; var2 < this.field_82136_e && var2 < 3; ++var2) 180 { 181 Potion[] var3 = field_82139_a[var2]; 182 int var4 = var3.length; 183 184 for (int var5 = 0; var5 < var4; ++var5) 185 { 186 Potion var6 = var3[var5]; 187 188 if (var6.id == par1) 189 { 190 this.field_82133_f = par1; 191 return; 192 } 193 } 194 } 195 } 196 197 public void func_82127_e(int par1) 198 { 199 this.field_82134_g = 0; 200 201 if (this.field_82136_e >= 4) 202 { 203 for (int var2 = 0; var2 < 4; ++var2) 204 { 205 Potion[] var3 = field_82139_a[var2]; 206 int var4 = var3.length; 207 208 for (int var5 = 0; var5 < var4; ++var5) 209 { 210 Potion var6 = var3[var5]; 211 212 if (var6.id == par1) 213 { 214 this.field_82134_g = par1; 215 return; 216 } 217 } 218 } 219 } 220 } 221 222 /** 223 * Overriden in a sign to provide the text. 224 */ 225 public Packet getDescriptionPacket() 226 { 227 NBTTagCompound var1 = new NBTTagCompound(); 228 this.writeToNBT(var1); 229 return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 3, var1); 230 } 231 232 @SideOnly(Side.CLIENT) 233 public double func_82115_m() 234 { 235 return 65536.0D; 236 } 237 238 /** 239 * Reads a tile entity from NBT. 240 */ 241 public void readFromNBT(NBTTagCompound par1NBTTagCompound) 242 { 243 super.readFromNBT(par1NBTTagCompound); 244 this.field_82133_f = par1NBTTagCompound.getInteger("Primary"); 245 this.field_82134_g = par1NBTTagCompound.getInteger("Secondary"); 246 this.field_82136_e = par1NBTTagCompound.getInteger("Levels"); 247 } 248 249 /** 250 * Writes a tile entity to NBT. 251 */ 252 public void writeToNBT(NBTTagCompound par1NBTTagCompound) 253 { 254 super.writeToNBT(par1NBTTagCompound); 255 par1NBTTagCompound.setInteger("Primary", this.field_82133_f); 256 par1NBTTagCompound.setInteger("Secondary", this.field_82134_g); 257 par1NBTTagCompound.setInteger("Levels", this.field_82136_e); 258 } 259 260 /** 261 * Returns the number of slots in the inventory. 262 */ 263 public int getSizeInventory() 264 { 265 return 1; 266 } 267 268 /** 269 * Returns the stack in slot i 270 */ 271 public ItemStack getStackInSlot(int par1) 272 { 273 return par1 == 0 ? this.field_82140_h : null; 274 } 275 276 /** 277 * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a 278 * new stack. 279 */ 280 public ItemStack decrStackSize(int par1, int par2) 281 { 282 if (par1 == 0 && this.field_82140_h != null) 283 { 284 if (par2 >= this.field_82140_h.stackSize) 285 { 286 ItemStack var3 = this.field_82140_h; 287 this.field_82140_h = null; 288 return var3; 289 } 290 else 291 { 292 this.field_82140_h.stackSize -= par2; 293 return new ItemStack(this.field_82140_h.itemID, par2, this.field_82140_h.getItemDamage()); 294 } 295 } 296 else 297 { 298 return null; 299 } 300 } 301 302 /** 303 * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - 304 * like when you close a workbench GUI. 305 */ 306 public ItemStack getStackInSlotOnClosing(int par1) 307 { 308 if (par1 == 0 && this.field_82140_h != null) 309 { 310 ItemStack var2 = this.field_82140_h; 311 this.field_82140_h = null; 312 return var2; 313 } 314 else 315 { 316 return null; 317 } 318 } 319 320 /** 321 * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). 322 */ 323 public void setInventorySlotContents(int par1, ItemStack par2ItemStack) 324 { 325 if (par1 == 0) 326 { 327 this.field_82140_h = par2ItemStack; 328 } 329 } 330 331 /** 332 * Returns the name of the inventory. 333 */ 334 public String getInvName() 335 { 336 return "container.beacon"; 337 } 338 339 /** 340 * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't 341 * this more of a set than a get?* 342 */ 343 public int getInventoryStackLimit() 344 { 345 return 1; 346 } 347 348 /** 349 * Do not make give this method the name canInteractWith because it clashes with Container 350 */ 351 public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) 352 { 353 return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; 354 } 355 356 public void openChest() {} 357 358 public void closeChest() {} 359 }