/// <summary>
        /// Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
        /// their own) Args: x, y, z, neighbor BlockID
        /// </summary>
        public override void OnNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
        {
            base.OnNeighborBlockChange(par1World, par2, par3, par4, par5);
            TileEntityChest tileentitychest = (TileEntityChest)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitychest != null)
            {
                tileentitychest.UpdateContainingBlockInfo();
            }
        }
        /// <summary>
        /// Called whenever the block is removed.
        /// </summary>
        public override void OnBlockRemoval(World par1World, int par2, int par3, int par4)
        {
            TileEntityChest tileentitychest = (TileEntityChest)par1World.GetBlockTileEntity(par2, par3, par4);

            if (tileentitychest != null)
            {
                for (int i = 0; i < tileentitychest.GetSizeInventory(); i++)
                {
                    ItemStack itemstack = tileentitychest.GetStackInSlot(i);

                    if (itemstack == null)
                    {
                        continue;
                    }

                    float f  = Random.NextFloat() * 0.8F + 0.1F;
                    float f1 = Random.NextFloat() * 0.8F + 0.1F;
                    float f2 = Random.NextFloat() * 0.8F + 0.1F;

                    while (itemstack.StackSize > 0)
                    {
                        int j = Random.Next(21) + 10;

                        if (j > itemstack.StackSize)
                        {
                            j = itemstack.StackSize;
                        }

                        itemstack.StackSize -= j;
                        EntityItem entityitem = new EntityItem(par1World, (float)par2 + f, (float)par3 + f1, (float)par4 + f2, new ItemStack(itemstack.ItemID, j, itemstack.GetItemDamage()));
                        float      f3         = 0.05F;
                        entityitem.MotionX = (float)Random.NextGaussian() * f3;
                        entityitem.MotionY = (float)Random.NextGaussian() * f3 + 0.2F;
                        entityitem.MotionZ = (float)Random.NextGaussian() * f3;

                        if (itemstack.HasTagCompound())
                        {
                            entityitem.ItemStack.SetTagCompound((NBTTagCompound)itemstack.GetTagCompound().Copy());
                        }

                        par1World.SpawnEntityInWorld(entityitem);
                    }
                }
            }

            base.OnBlockRemoval(par1World, par2, par3, par4);
        }
        protected virtual void CreateTreasureChestAtCurrentPosition(World par1World, StructureBoundingBox par2StructureBoundingBox, Random par3Random, int par4, int par5, int par6, StructurePieceTreasure[] par7ArrayOfStructurePieceTreasure, int par8)
        {
            int i = GetXWithOffset(par4, par6);
            int j = GetYWithOffset(par5);
            int k = GetZWithOffset(par4, par6);

            if (par2StructureBoundingBox.IsVecInside(i, j, k) && par1World.GetBlockId(i, j, k) != Block.Chest.BlockID)
            {
                par1World.SetBlockWithNotify(i, j, k, Block.Chest.BlockID);
                TileEntityChest tileentitychest = (TileEntityChest)par1World.GetBlockTileEntity(i, j, k);

                if (tileentitychest != null)
                {
                    FillTreasureChestWithLoot(par3Random, par7ArrayOfStructurePieceTreasure, tileentitychest, par8);
                }
            }
        }
        /// <summary>
        /// Renders the TileEntity for the chest at a position.
        /// </summary>
        public virtual void RenderTileEntityChestAt(TileEntityChest par1TileEntityChest, double par2, double par4, double par6, float par8)
        {
            int i;

            if (par1TileEntityChest.WorldObj == null)
            {
                i = 0;
            }
            else
            {
                Block block = par1TileEntityChest.GetBlockType();
                i = par1TileEntityChest.GetBlockMetadata();

                if (block != null && i == 0)
                {
                    ((BlockChest)block).UnifyAdjacentChests(par1TileEntityChest.WorldObj, par1TileEntityChest.XCoord, par1TileEntityChest.YCoord, par1TileEntityChest.ZCoord);
                    i = par1TileEntityChest.GetBlockMetadata();
                }

                par1TileEntityChest.CheckForAdjacentChests();
            }

            if (par1TileEntityChest.AdjacentChestZNeg != null || par1TileEntityChest.AdjacentChestXNeg != null)
            {
                return;
            }

            ModelChest modelchest;

            if (par1TileEntityChest.AdjacentChestXPos != null || par1TileEntityChest.AdjacentChestZPos != null)
            {
                modelchest = LargeChestModel;
                BindTextureByName("/item/largechest.png");
            }
            else
            {
                modelchest = ChestModel;
                BindTextureByName("/item/chest.png");
            }

            //GL.PushMatrix();
            //GL.Enable(EnableCap.RescaleNormal);
            //GL.Color4(1.0F, 1.0F, 1.0F, 1.0F);
            //GL.Translate((float)par2, (float)par4 + 1.0F, (float)par6 + 1.0F);
            //GL.Scale(1.0F, -1F, -1F);
            //GL.Translate(0.5F, 0.5F, 0.5F);
            int j = 0;

            if (i == 2)
            {
                j = 180;
            }

            if (i == 3)
            {
                j = 0;
            }

            if (i == 4)
            {
                j = 90;
            }

            if (i == 5)
            {
                j = -90;
            }

            if (i == 2 && par1TileEntityChest.AdjacentChestXPos != null)
            {
                //GL.Translate(1.0F, 0.0F, 0.0F);
            }

            if (i == 5 && par1TileEntityChest.AdjacentChestZPos != null)
            {
                //GL.Translate(0.0F, 0.0F, -1F);
            }

            //GL.Rotate(j, 0.0F, 1.0F, 0.0F);
            //GL.Translate(-0.5F, -0.5F, -0.5F);
            float f = par1TileEntityChest.PrevLidAngle + (par1TileEntityChest.LidAngle - par1TileEntityChest.PrevLidAngle) * par8;

            if (par1TileEntityChest.AdjacentChestZNeg != null)
            {
                float f1 = par1TileEntityChest.AdjacentChestZNeg.PrevLidAngle + (par1TileEntityChest.AdjacentChestZNeg.LidAngle - par1TileEntityChest.AdjacentChestZNeg.PrevLidAngle) * par8;

                if (f1 > f)
                {
                    f = f1;
                }
            }

            if (par1TileEntityChest.AdjacentChestXNeg != null)
            {
                float f2 = par1TileEntityChest.AdjacentChestXNeg.PrevLidAngle + (par1TileEntityChest.AdjacentChestXNeg.LidAngle - par1TileEntityChest.AdjacentChestXNeg.PrevLidAngle) * par8;

                if (f2 > f)
                {
                    f = f2;
                }
            }

            f = 1.0F - f;
            f = 1.0F - f * f * f;
            modelchest.ChestLid.RotateAngleX = -((f * (float)Math.PI) / 2.0F);
            modelchest.RenderAll();
            //GL.Disable(EnableCap.RescaleNormal);
            //GL.PopMatrix();
            //GL.Color4(1.0F, 1.0F, 1.0F, 1.0F);
        }
Example #5
0
        public override bool Generate(World par1World, Random par2Random, int par3, int par4, int par5)
        {
            sbyte byte0 = 3;
            int   i     = par2Random.Next(2) + 2;
            int   j     = par2Random.Next(2) + 2;
            int   k     = 0;

            for (int l = par3 - i - 1; l <= par3 + i + 1; l++)
            {
                for (int k1 = par4 - 1; k1 <= par4 + byte0 + 1; k1++)
                {
                    for (int j2 = par5 - j - 1; j2 <= par5 + j + 1; j2++)
                    {
                        Material material = par1World.GetBlockMaterial(l, k1, j2);

                        if (k1 == par4 - 1 && !material.IsSolid())
                        {
                            return(false);
                        }

                        if (k1 == par4 + byte0 + 1 && !material.IsSolid())
                        {
                            return(false);
                        }

                        if ((l == par3 - i - 1 || l == par3 + i + 1 || j2 == par5 - j - 1 || j2 == par5 + j + 1) && k1 == par4 && par1World.IsAirBlock(l, k1, j2) && par1World.IsAirBlock(l, k1 + 1, j2))
                        {
                            k++;
                        }
                    }
                }
            }

            if (k < 1 || k > 5)
            {
                return(false);
            }

            for (int i1 = par3 - i - 1; i1 <= par3 + i + 1; i1++)
            {
                for (int l1 = par4 + byte0; l1 >= par4 - 1; l1--)
                {
                    for (int k2 = par5 - j - 1; k2 <= par5 + j + 1; k2++)
                    {
                        if (i1 == par3 - i - 1 || l1 == par4 - 1 || k2 == par5 - j - 1 || i1 == par3 + i + 1 || l1 == par4 + byte0 + 1 || k2 == par5 + j + 1)
                        {
                            if (l1 >= 0 && !par1World.GetBlockMaterial(i1, l1 - 1, k2).IsSolid())
                            {
                                par1World.SetBlockWithNotify(i1, l1, k2, 0);
                                continue;
                            }

                            if (!par1World.GetBlockMaterial(i1, l1, k2).IsSolid())
                            {
                                continue;
                            }

                            if (l1 == par4 - 1 && par2Random.Next(4) != 0)
                            {
                                par1World.SetBlockWithNotify(i1, l1, k2, Block.CobblestoneMossy.BlockID);
                            }
                            else
                            {
                                par1World.SetBlockWithNotify(i1, l1, k2, Block.Cobblestone.BlockID);
                            }
                        }
                        else
                        {
                            par1World.SetBlockWithNotify(i1, l1, k2, 0);
                        }
                    }
                }
            }

            for (int j1 = 0; j1 < 2; j1++)
            {
label0:

                for (int i2 = 0; i2 < 3; i2++)
                {
                    int l2 = (par3 + par2Random.Next(i * 2 + 1)) - i;
                    int i3 = par4;
                    int j3 = (par5 + par2Random.Next(j * 2 + 1)) - j;

                    if (!par1World.IsAirBlock(l2, i3, j3))
                    {
                        continue;
                    }

                    int k3 = 0;

                    if (par1World.GetBlockMaterial(l2 - 1, i3, j3).IsSolid())
                    {
                        k3++;
                    }

                    if (par1World.GetBlockMaterial(l2 + 1, i3, j3).IsSolid())
                    {
                        k3++;
                    }

                    if (par1World.GetBlockMaterial(l2, i3, j3 - 1).IsSolid())
                    {
                        k3++;
                    }

                    if (par1World.GetBlockMaterial(l2, i3, j3 + 1).IsSolid())
                    {
                        k3++;
                    }

                    if (k3 != 1)
                    {
                        continue;
                    }

                    par1World.SetBlockWithNotify(l2, i3, j3, Block.Chest.BlockID);
                    TileEntityChest tileentitychest = (TileEntityChest)par1World.GetBlockTileEntity(l2, i3, j3);

                    if (tileentitychest == null)
                    {
                        break;
                    }

                    int l3 = 0;

                    do
                    {
                        if (l3 >= 8)
                        {
                            goto label0;
                        }

                        ItemStack itemstack = PickCheckLootItem(par2Random);

                        if (itemstack != null)
                        {
                            tileentitychest.SetInventorySlotContents(par2Random.Next(tileentitychest.GetSizeInventory()), itemstack);
                        }

                        l3++;
                    }while (true);
                }
            }

            par1World.SetBlockWithNotify(par3, par4, par5, Block.MobSpawner.BlockID);
            TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)par1World.GetBlockTileEntity(par3, par4, par5);

            if (tileentitymobspawner != null)
            {
                tileentitymobspawner.SetMobID(PickMobSpawner(par2Random));
            }
            else
            {
                Console.Error.WriteLine((new StringBuilder()).Append("Failed to fetch mob spawner entity at (").Append(par3).Append(", ").Append(par4).Append(", ").Append(par5).Append(")").ToString());
            }

            return(true);
        }
        private static void FillTreasureChestWithLoot(Random par0Random, StructurePieceTreasure[] par1ArrayOfStructurePieceTreasure, TileEntityChest par2TileEntityChest, int par3)
        {
            for (int i = 0; i < par3; i++)
            {
                StructurePieceTreasure structurepiecetreasure = (StructurePieceTreasure)WeightedRandom.GetRandomItem(par0Random, par1ArrayOfStructurePieceTreasure);
                int j = structurepiecetreasure.MinItemStack + par0Random.Next((structurepiecetreasure.MaxItemStack - structurepiecetreasure.MinItemStack) + 1);

                if (Item.ItemsList[structurepiecetreasure.ItemID].GetItemStackLimit() >= j)
                {
                    par2TileEntityChest.SetInventorySlotContents(par0Random.Next(par2TileEntityChest.GetSizeInventory()), new ItemStack(structurepiecetreasure.ItemID, j, structurepiecetreasure.ItemMetadata));
                    continue;
                }

                for (int k = 0; k < j; k++)
                {
                    par2TileEntityChest.SetInventorySlotContents(par0Random.Next(par2TileEntityChest.GetSizeInventory()), new ItemStack(structurepiecetreasure.ItemID, 1, structurepiecetreasure.ItemMetadata));
                }
            }
        }