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    
099                            if (var6 != Block.blockEmerald.blockID && var6 != Block.blockGold.blockID && var6 != Block.blockDiamond.blockID && var6 != Block.blockSteel.blockID)
100                            {
101                                var3 = false;
102                                break;
103                            }
104                        }
105                    }
106    
107                    if (!var3)
108                    {
109                        break;
110                    }
111                }
112    
113                if (this.field_82136_e == 0)
114                {
115                    this.field_82135_d = false;
116                }
117            }
118        }
119    
120        @SideOnly(Side.CLIENT)
121        public float func_82125_v_()
122        {
123            if (!this.field_82135_d)
124            {
125                return 0.0F;
126            }
127            else
128            {
129                int var1 = (int)(this.worldObj.func_82737_E() - this.field_82137_b);
130                this.field_82137_b = this.worldObj.func_82737_E();
131    
132                if (var1 > 1)
133                {
134                    this.field_82138_c -= (float)var1 / 40.0F;
135    
136                    if (this.field_82138_c < 0.0F)
137                    {
138                        this.field_82138_c = 0.0F;
139                    }
140                }
141    
142                this.field_82138_c += 0.025F;
143    
144                if (this.field_82138_c > 1.0F)
145                {
146                    this.field_82138_c = 1.0F;
147                }
148    
149                return this.field_82138_c;
150            }
151        }
152    
153        public int func_82126_i()
154        {
155            return this.field_82133_f;
156        }
157    
158        public int func_82132_j()
159        {
160            return this.field_82134_g;
161        }
162    
163        public int func_82130_k()
164        {
165            return this.field_82136_e;
166        }
167    
168        @SideOnly(Side.CLIENT)
169        public void func_82129_c(int par1)
170        {
171            this.field_82136_e = par1;
172        }
173    
174        public void func_82128_d(int par1)
175        {
176            this.field_82133_f = 0;
177    
178            for (int var2 = 0; var2 < this.field_82136_e && var2 < 3; ++var2)
179            {
180                Potion[] var3 = field_82139_a[var2];
181                int var4 = var3.length;
182    
183                for (int var5 = 0; var5 < var4; ++var5)
184                {
185                    Potion var6 = var3[var5];
186    
187                    if (var6.id == par1)
188                    {
189                        this.field_82133_f = par1;
190                        return;
191                    }
192                }
193            }
194        }
195    
196        public void func_82127_e(int par1)
197        {
198            this.field_82134_g = 0;
199    
200            if (this.field_82136_e >= 4)
201            {
202                for (int var2 = 0; var2 < 4; ++var2)
203                {
204                    Potion[] var3 = field_82139_a[var2];
205                    int var4 = var3.length;
206    
207                    for (int var5 = 0; var5 < var4; ++var5)
208                    {
209                        Potion var6 = var3[var5];
210    
211                        if (var6.id == par1)
212                        {
213                            this.field_82134_g = par1;
214                            return;
215                        }
216                    }
217                }
218            }
219        }
220    
221        /**
222         * Overriden in a sign to provide the text.
223         */
224        public Packet getDescriptionPacket()
225        {
226            NBTTagCompound var1 = new NBTTagCompound();
227            this.writeToNBT(var1);
228            return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 3, var1);
229        }
230    
231        @SideOnly(Side.CLIENT)
232        public double func_82115_m()
233        {
234            return 65536.0D;
235        }
236    
237        /**
238         * Reads a tile entity from NBT.
239         */
240        public void readFromNBT(NBTTagCompound par1NBTTagCompound)
241        {
242            super.readFromNBT(par1NBTTagCompound);
243            this.field_82133_f = par1NBTTagCompound.getInteger("Primary");
244            this.field_82134_g = par1NBTTagCompound.getInteger("Secondary");
245            this.field_82136_e = par1NBTTagCompound.getInteger("Levels");
246        }
247    
248        /**
249         * Writes a tile entity to NBT.
250         */
251        public void writeToNBT(NBTTagCompound par1NBTTagCompound)
252        {
253            super.writeToNBT(par1NBTTagCompound);
254            par1NBTTagCompound.setInteger("Primary", this.field_82133_f);
255            par1NBTTagCompound.setInteger("Secondary", this.field_82134_g);
256            par1NBTTagCompound.setInteger("Levels", this.field_82136_e);
257        }
258    
259        /**
260         * Returns the number of slots in the inventory.
261         */
262        public int getSizeInventory()
263        {
264            return 1;
265        }
266    
267        /**
268         * Returns the stack in slot i
269         */
270        public ItemStack getStackInSlot(int par1)
271        {
272            return par1 == 0 ? this.field_82140_h : null;
273        }
274    
275        /**
276         * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
277         * new stack.
278         */
279        public ItemStack decrStackSize(int par1, int par2)
280        {
281            if (par1 == 0 && this.field_82140_h != null)
282            {
283                if (par2 >= this.field_82140_h.stackSize)
284                {
285                    ItemStack var3 = this.field_82140_h;
286                    this.field_82140_h = null;
287                    return var3;
288                }
289                else
290                {
291                    this.field_82140_h.stackSize -= par2;
292                    return new ItemStack(this.field_82140_h.itemID, par2, this.field_82140_h.getItemDamage());
293                }
294            }
295            else
296            {
297                return null;
298            }
299        }
300    
301        /**
302         * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
303         * like when you close a workbench GUI.
304         */
305        public ItemStack getStackInSlotOnClosing(int par1)
306        {
307            if (par1 == 0 && this.field_82140_h != null)
308            {
309                ItemStack var2 = this.field_82140_h;
310                this.field_82140_h = null;
311                return var2;
312            }
313            else
314            {
315                return null;
316            }
317        }
318    
319        /**
320         * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
321         */
322        public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
323        {
324            if (par1 == 0)
325            {
326                this.field_82140_h = par2ItemStack;
327            }
328        }
329    
330        /**
331         * Returns the name of the inventory.
332         */
333        public String getInvName()
334        {
335            return "container.beacon";
336        }
337    
338        /**
339         * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
340         * this more of a set than a get?*
341         */
342        public int getInventoryStackLimit()
343        {
344            return 1;
345        }
346    
347        /**
348         * Do not make give this method the name canInteractWith because it clashes with Container
349         */
350        public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
351        {
352            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;
353        }
354    
355        public void openChest() {}
356    
357        public void closeChest() {}
358    }