// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 

package net.minecraft.server;

import java.util.Random;

// Referenced classes of package net.minecraft.src:
//            TileEntity, IInventory, ItemStack, NBTTagCompound, 
//            NBTTagList, World, EntityHuman, Block, 
//            TileEntityChest

public class EntityTumba extends TileEntity
    implements IInventory
{

    private ItemStack chestContents[];
    public boolean field_35155_a;
    public TileEntityChest field_35152_b;
    public TileEntityChest field_35153_c;
    public TileEntityChest field_35150_d;
    public TileEntityChest field_35151_e;
    public float field_35148_f;
    public float field_35149_g;
    public int field_35156_h;
    private int field_35154_q;

    public EntityTumba()
    {
        chestContents = new ItemStack[36];
        field_35155_a = false;
    }

    public int getSize()
    {
        return 27;
    }

    public ItemStack getItem(int i)
    {
        return chestContents[i];
    }

    public ItemStack splitStack(int i, int j)
    {
        if(chestContents[i] != null)
        {
            if(chestContents[i].count <= j)
            {
                ItemStack itemstack = chestContents[i];
                chestContents[i] = null;
                update();
                return itemstack;
            }
            ItemStack itemstack1 = chestContents[i].a(j);
            if(chestContents[i].count == 0)
            {
                chestContents[i] = null;
            }
            update();
            return itemstack1;
        } else
        {
            return null;
        }
    }

    public void setItem(int i, ItemStack itemstack)
    {
        chestContents[i] = itemstack;
        if(itemstack != null && itemstack.count > getMaxStackSize())
        {
            itemstack.count = getMaxStackSize();
        }
        update();
    }

    public String getName()
    {
        return "\u041A\u0443\u0445\u043E\u043D\u043D\u0430\u044F \u0442\u0443\u043C\u0431\u0430";
    }

    public void a(NBTTagCompound nbttagcompound)
    {
        super.a(nbttagcompound);
        NBTTagList nbttaglist = nbttagcompound.getList("Items");
        chestContents = new ItemStack[getSize()];
        for(int i = 0; i < nbttaglist.size(); i++)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.get(i);
            int j = nbttagcompound1.getByte("Slot") & 0xff;
            if(j >= 0 && j < chestContents.length)
            {
                chestContents[j] = ItemStack.a(nbttagcompound1);
            }
        }

    }

    public void b(NBTTagCompound nbttagcompound)
    {
        super.b(nbttagcompound);
        NBTTagList nbttaglist = new NBTTagList();
        for(int i = 0; i < chestContents.length; i++)
        {
            if(chestContents[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                chestContents[i].b(nbttagcompound1);
                nbttaglist.add(nbttagcompound1);
            }
        }

        nbttagcompound.set("Items", nbttaglist);
    }

    public int getMaxStackSize()
    {
        return 64;
    }

    public boolean a(EntityHuman entityhuman)
    {
        if(world.getTileEntity(x, y, z) != this)
        {
            return false;
        } else
        {
            return entityhuman.e((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D) <= 64D;
        }
    }

    public void func_35144_b()
    {
        super.d();
        field_35155_a = false;
    }

    public void func_35147_g()
    {
        if(field_35155_a)
        {
            return;
        }
        field_35155_a = true;
        field_35152_b = null;
        field_35153_c = null;
        field_35150_d = null;
        field_35151_e = null;
        if(world.getTypeId(x - 1, y, z) == Block.CHEST.id)
        {
            field_35150_d = (TileEntityChest)world.getTileEntity(x - 1, y, z);
        }
        if(world.getTypeId(x + 1, y, z) == Block.CHEST.id)
        {
            field_35153_c = (TileEntityChest)world.getTileEntity(x + 1, y, z);
        }
        if(world.getTypeId(x, y, z - 1) == Block.CHEST.id)
        {
            field_35152_b = (TileEntityChest)world.getTileEntity(x, y, z - 1);
        }
        if(world.getTypeId(x, y, z + 1) == Block.CHEST.id)
        {
            field_35151_e = (TileEntityChest)world.getTileEntity(x, y, z + 1);
        }
        if(field_35152_b != null)
        {
            field_35152_b.d();
        }
        if(field_35151_e != null)
        {
            field_35151_e.d();
        }
        if(field_35153_c != null)
        {
            field_35153_c.d();
        }
        if(field_35150_d != null)
        {
            field_35150_d.d();
        }
    }

    public void l_()
    {
        super.l_();
        func_35147_g();
        if((++field_35154_q % 20) * 4 == 0)
        {
            world.playNote(x, y, z, 1, field_35156_h);
        }
        field_35149_g = field_35148_f;
        float f = 0.1F;
        if(field_35156_h > 0 && field_35148_f == 0.0F && field_35152_b == null && field_35150_d == null)
        {
            double d = (double)x + 0.5D;
            double d2 = (double)z + 0.5D;
            if(field_35151_e != null)
            {
                d2 += 0.5D;
            }
            if(field_35153_c != null)
            {
                d += 0.5D;
            }
            world.makeSound(d, (double)y + 0.5D, d2, "random.door_open", 1.0F, world.random.nextFloat() * 0.1F + 0.9F);
        }
        if(field_35156_h == 0 && field_35148_f > 0.0F || field_35156_h > 0 && field_35148_f < 1.0F)
        {
            if(field_35156_h > 0)
            {
                field_35148_f += f;
            } else
            {
                field_35148_f -= f;
            }
            if(field_35148_f > 1.0F)
            {
                field_35148_f = 1.0F;
            }
            if(field_35148_f < 0.0F)
            {
                field_35148_f = 0.0F;
                if(field_35152_b == null && field_35150_d == null)
                {
                    double d1 = (double)x + 0.5D;
                    double d3 = (double)z + 0.5D;
                    if(field_35151_e != null)
                    {
                        d3 += 0.5D;
                    }
                    if(field_35153_c != null)
                    {
                        d1 += 0.5D;
                    }
                    world.makeSound(d1, (double)y + 0.5D, d3, "random.door_close", 1.0F, world.random.nextFloat() * 0.1F + 0.9F);
                }
            }
        }
    }

    public void func_35143_b(int i, int j)
    {
        if(i == 1)
        {
            field_35156_h = j;
        }
    }

    public void f()
    {
        field_35156_h++;
        world.playNote(x, y, z, 1, field_35156_h);
    }

    public void g()
    {
        field_35156_h--;
        world.playNote(x, y, z, 1, field_35156_h);
    }

    public void i()
    {
        func_35144_b();
        func_35147_g();
        super.i();
    }

	@Override
	public ItemStack[] getContents() {
		// TODO Auto-generated method stub
		return null;
	}
}
