private void GenerateBase(Sector chunk, int ChunkZ)
        {
            Random ran = new Random();

            //Create Terrain
            for (int x = 0; x < Sector.Size.X; x++) {
                for (int y = 0; y < Sector.Size.Y; y++) {
                    for (int z = 0; z < Sector.Size.Z; z++) {
                        Vector3i Location = new Vector3i(x, y, z);
                        if (z + (ChunkZ * Sector.Size.Z) < current_heightmap.GetPixel(x, y).R - 100) {
                            if (z + (ChunkZ * Sector.Size.Z) > current_heightmap.GetPixel(x, y).R - 100 - (int)(5 + ran.Next(3))) {
                                chunk[Location] = new Block(DirtGuid);
                            } else {
                                chunk[Location] = new Block(GraniteGuid);
                            }
                        }

                        if (z + (ChunkZ * Sector.Size.Z) == current_heightmap.GetPixel(x, y).R - 100) {
                            chunk[Location] = new Block(GrassGuid);
                        }
                    }
                }
            }
        }
Example #2
0
 internal bool CanCombine(Block block)
 {
     if (block == null) return true;
     return this.BlockType == block.BlockType && this.BlockType.Liquid;
 }
Example #3
0
 internal void TryCombine(Block block)
 {
     if (CanCombine(block) && block != null) {
         this.Level += block.Level;
     }
 }
Example #4
0
        void AddBlock()
        {
            float bestDist = 100;
            int bestX = 0;
            int bestY = 0;
            int bestZ = 0;
            bool foundOne = false;

            int CDist = 5;

            int BestSide = NONE;

            Vector3 source = new Vector3();
            source.X = (float)xpos;
            source.Y = (float)ypos;
            source.Z = (float)(zpos + PlayerHeight);

            Vector3 dest = new Vector3();
            dest.X = LookingAtX(CDist);
            dest.Y = LookingAtY(CDist);
            dest.Z = LookingAtZ(CDist);

            for (int x = -CDist; x <= CDist; x++){
                for (int y = -CDist; y <= CDist; y++){
                    for (int z = -CDist; z <= CDist; z++){
                        Block BCDist = Game.World[new Vector3i((int)(xpos + x), (int)(ypos + y), (int)(zpos + z + PlayerHeight))];
                        if (BCDist != null && BCDist.IsSolid()) {
                            Vector3 B1 = new Vector3();
                            B1.X = (int)(xpos+x);
                            B1.Y = (int)(ypos+y);
                            B1.Z = (int)(zpos + z + PlayerHeight);

                            Vector3 B2 = new Vector3();
                            B2.X = B1.X + 1;
                            B2.Y = B1.Y + 1;
                            B2.Z = B1.Z + 1;

                            int clb = CheckLineBox(B1, B2, source, dest);
                            int[] temp = getBlockSide((int)(xpos+x),
                                    (int)(ypos+y),
                                    (int)(zpos + z + PlayerHeight),
                                    clb);
                            if (clb != NONE && clb != INSIDE &&
                                    CanPlaceBlock(new Vector3i(temp[0], temp[1], temp[2]))) {
                                foundOne = true;
                                float length = (float)Math.Sqrt(x*x + y*y + z*z);
                                if (length < bestDist){
                                    bestDist = length;
                                    bestX = (int)(xpos+x);
                                    bestY = (int)(ypos+y);
                                    bestZ = (int)(zpos + z + PlayerHeight);
                                    BestSide = clb;
                                }
                            }
                        }
                    }
                }
            }

            if (foundOne){

                int[] temp = getBlockSide(bestX, bestY, bestZ, BestSide);
                bestX = temp[0];
                bestY = temp[1];
                bestZ = temp[2];

                Guid BlockName = Inventory[SelectedItem].BlockTypeID;

                Block b = new Block(BlockName);

                Vector3i Location = new Vector3i(bestX, bestY, bestZ);
                Game.World[Location] = b;
                BlockAdd msg = new BlockAdd(Location, b);
                msg.Send();
            }
        }