SetBlockAt() публичный абстрактный Метод

public abstract SetBlockAt ( int x, int y, int z, byte val ) : void
x int
y int
z int
val byte
Результат void
Пример #1
0
        /*
         * note, foliage will disintegrate if there is no foliage below, or
         * if there is no "log" block within range 2 (square) at the same level or
         * one level below
         */
        public override void MakeFoliage(ref IMapHandler map)
        {
            Console.WriteLine("Adding tree at {0}", Pos);
            int topy  = (int)Pos.Y + Height - 1;
            int start = topy - 2;
            int end   = topy + 2;

            for (int y = start; y < end; y++)
            {
                int rad = 0;
                if (y > start + 1)
                {
                    rad = 1;
                }
                else
                {
                    rad = 2;
                }
                for (int xoff = -rad; xoff < rad + 1; xoff++)
                {
                    for (int zoff = -rad; zoff < rad + 1; zoff++)
                    {
                        if (Math.Abs(xoff) == Math.Abs(zoff) && Math.Abs(xoff) == rad)
                        {
                            continue;
                        }

                        int x = (int)Pos.X + xoff;
                        int z = (int)Pos.Z + zoff;

                        map.SetBlockAt(x, y, z, 18);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Create a round section of type matidx in blocklist.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="vCenter">the coordinates of the center block</param>
        /// <param name="radius">the radius of the section.</param>
        /// <param name="diraxis">The list index for the axis to make the section perpendicular to.  0 indicates the x axis, 1 the y, 2 the z.  The section will extend along the other two axies.</param>
        /// <param name="mat">What to make the section out of</param>
        public void crossection(ref IMapHandler map, Vector3i vCenter, double radius, int diraxis, byte mat)
        {
            long[] centArray = vCenter.ToArray();
            int    rad       = (int)(radius + .618d);
            int    secidx1   = (diraxis - 1) % 3;
            int    secidx2   = (1 + diraxis) % 3;

            int[] coord = new int [] { 0, 0, 0 };
            for (int off1 = -rad; off1 < rad + 1; off1++)
            {
                for (int off2 = -rad; off2 < rad + 1; off2++)
                {
                    double thisdist = Math.Sqrt(Math.Pow((double)Math.Abs(off1) + .5d, 2d) + Math.Pow((double)Math.Abs(off2) + .5d, 2));
                    if (thisdist > radius)
                    {
                        continue;
                    }
                    int pri  = (int)centArray[diraxis];
                    int sec1 = (int)centArray[secidx1] + off1;
                    int sec2 = (int)centArray[secidx2] + off2;
                    coord[diraxis] = pri;
                    coord[secidx1] = sec1;
                    coord[secidx2] = sec2;
                    map.SetBlockAt(coord[0], coord[1], coord[2], mat);
                }
            }
        }
Пример #3
0
        public Cave(ref Random rnd, ref IMapHandler mh, Vector3i StartingPoint)
        {
            mMap = mh;
            rand = rnd;
            AddPoint(StartingPoint);
            // We need at least 4 points.
            int numPoints2Make = rand.Next(3, 10);
            for(int i=0;i<numPoints2Make;i++)
            {
                i++;
                AddPoint(new Vector3i(StartingPoint.X+rand.Next(-16, 16), StartingPoint.Y+rand.Next(-16, 16), StartingPoint.Z+rand.Next(-16, 16)));
            }
            Profiler profSphere = new Profiler("MakeSphere");
            Profiler profSpline = new Profiler("GetInterpolatedSplinePoint");
            int rad = rand.Next(1, 3);
            for(int p = 0;p<20;p++)
            {
                double t = (double)p/(double)(Points.Count*32);
                // Between 2/10 radius.
                profSpline.Start();
                Vector3i derp = this.GetInterpolatedSplinePoint(t);
                profSpline.Stop();

                mMap.SetBlockAt(derp.X, derp.Y, derp.Z, 0);

                profSphere.Start();
                MakeSphere(derp, rad);
                profSphere.Stop();
                //Console.WriteLine("MakeSphere r={0} @ t={1}", rad, t);
                //t += 0.05;
            }
            mMap.SaveAll();
            Console.WriteLine(profSpline.ToString());
            Console.WriteLine(profSphere.ToString());
        }
Пример #4
0
        /*
        note, foliage will disintegrate if there is no foliage below, or
        if there is no "log" block within range 2 (square) at the same level or
        one level below
        */
        public override void MakeFoliage(ref IMapHandler map)
        {
            Console.WriteLine("Adding tree at {0}", Pos);
            int topy = (int)Pos.Y + Height - 1;
            int start = topy - 2;
            int end = topy + 2;
            for(int y = start;y<end;y++)
            {
                int rad=0;
                if(y > start + 1)
                    rad = 1;
                else
                    rad = 2;
                for(int xoff = -rad;xoff<rad+1;xoff++)
                {
                    for(int zoff = -rad;zoff<rad+1;zoff++)
                    {

                        if (Math.Abs(xoff) == Math.Abs(zoff) && Math.Abs(xoff) == rad)
                            continue;

                        int x = (int)Pos.X + xoff;
                        int z = (int)Pos.Z + zoff;

                        map.SetBlockAt(x,y,z,18);
                    }
                }
            }
        }
Пример #5
0
        public override void  MakeFoliage(ref IMapHandler map)
        {
            List <Vector3i> foliage_coords = foliage_cords;

            foreach (Vector3i coord in foliage_coords)
            {
                foliagecluster(ref map, coord);
            }
            foreach (Vector3i cord in foliage_coords)
            {
                map.SetBlockAt(cord.X, cord.Y, cord.Z, 17);
                if (LIGHTTREE == 1)
                {
                    map.SetBlockAt(cord.X, cord.Y + 1, cord.Z, 50);
                    map.SetBlockAt(cord.X, cord.Y + 2, cord.Z, 17);
                }
                else if (LIGHTTREE == 2 || LIGHTTREE == 4)
                {
                    map.SetBlockAt(cord.X + 1, cord.Y, cord.Z, 50);
                    map.SetBlockAt(cord.X - 1, cord.Y, cord.Z, 50);
                    if (LIGHTTREE == 4)
                    {
                        map.SetBlockAt(cord.X, cord.Y, cord.Z + 1, 50);
                        map.SetBlockAt(cord.X, cord.Y, cord.Z - 1, 50);
                    }
                }
            }
        }
Пример #6
0
        public override void  MakeTrunk(ref IMapHandler map)
        {
            int x = (int)Pos.X;
            int y = (int)Pos.Y;
            int z = (int)Pos.Z;

            for (int i = 0; i < Height; i++)
            {
                map.SetBlockAt(x, y, z, 17);
                y += 1;
            }
        }
Пример #7
0
        public override void MakeTrunk(ref IMapHandler map)
        {
            int x = (int)Pos.X;
            int y = (int)Pos.Y;
            int z = (int)Pos.Z;

            for (int i = 0; i<Height;i++)
            {
                map.SetBlockAt(x, y, z, 17);
                y += 1;
            }
        }
Пример #8
0
        private void MakeSphere(Vector3i pos, int rad)
        {
            Profiler profRead  = new Profiler("Read");
            Profiler profWrite = new Profiler("Write");
            int      radsq     = rad ^ 2; // So we don't have to do sqrt, which is slow

            for (int x = (int)pos.X - rad; x < pos.X + rad; x++)
            {
                for (int y = (int)pos.Y - rad; y < pos.Y + rad; y++)
                {
                    for (int z = (int)pos.Z - rad; z < pos.Z + rad; z++)
                    {
                        if (y < 0 || y >= mMap.ChunkScale.Y - 1)
                        {
                            continue;
                        }

                        profRead.Start();
                        byte block = mMap.GetBlockAt(x, y, z);
                        profRead.Stop();
                        //byte blockabove = mMap.GetBlockAt(x,y+1,z);

                        // If water/sand/gravel, or the block above is, abort
                        if (block == 0 || block == 8 || block == 9 || block == 12 || block == 13 || block == KnownBlocks.Error)
                        {
                            continue;
                        }
                        //if (blockabove == 0 || blockabove == 8 || blockabove == 9 || blockabove == 12 || blockabove == 13)
                        //    continue;

                        int distsq = (x - (int)pos.X) ^ 2 + (y - (int)pos.Y) ^ 2 + (z - (int)pos.Z);
                        if (distsq <= radsq)
                        {
                            profWrite.Start();
                            mMap.SetBlockAt(x, y, z, 0);
                            profWrite.Stop();
                        }
                    }
                }
            }

            Console.WriteLine(profRead.ToString());
            Console.WriteLine(profWrite.ToString());
        }
Пример #9
0
        public Cave(ref Random rnd, ref IMapHandler mh, Vector3i StartingPoint)
        {
            mMap = mh;
            rand = rnd;
            AddPoint(StartingPoint);
            // We need at least 4 points.
            int numPoints2Make = rand.Next(3, 10);

            for (int i = 0; i < numPoints2Make; i++)
            {
                i++;
                AddPoint(new Vector3i(StartingPoint.X + rand.Next(-16, 16), StartingPoint.Y + rand.Next(-16, 16), StartingPoint.Z + rand.Next(-16, 16)));
            }
            Profiler profSphere = new Profiler("MakeSphere");
            Profiler profSpline = new Profiler("GetInterpolatedSplinePoint");
            int      rad        = rand.Next(1, 3);

            for (int p = 0; p < 20; p++)
            {
                double t = (double)p / (double)(Points.Count * 32);
                // Between 2/10 radius.
                profSpline.Start();
                Vector3i derp = this.GetInterpolatedSplinePoint(t);
                profSpline.Stop();


                mMap.SetBlockAt(derp.X, derp.Y, derp.Z, 0);

                profSphere.Start();
                MakeSphere(derp, rad);
                profSphere.Stop();
                //Console.WriteLine("MakeSphere r={0} @ t={1}", rad, t);
                //t += 0.05;
            }
            mMap.SaveAll();
            Console.WriteLine(profSpline.ToString());
            Console.WriteLine(profSphere.ToString());
        }
Пример #10
0
        public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H)
        {
            int             xo           = (int)(X * mh.ChunkScale.X);
            int             zo           = (int)(Z * mh.ChunkScale.Z);
            List <Vector2i> PlantedTrees = new List <Vector2i>();
            int             DistanceReqd = 3;

            for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++)
            {
                Vector2i me = new Vector2i(rand.Next(0, 15), rand.Next(0, 15));
                if (!Biome.NeedsTrees(biomes[me.X, me.Y]))
                {
                    continue;
                }
                bool tooclose = false;
                foreach (Vector2i tree in PlantedTrees)
                {
                    if (Vector2i.Distance(tree, me) < DistanceReqd)
                    {
                        tooclose = true;
                        break;
                    }
                }

                if (tooclose)
                {
                    continue;
                }
                bool founddert = false;
                for (int y = (int)H - 10; y > 0; y--)
                {
                    switch (mh.GetBlockAt(me.X + xo, y, me.Y + zo))
                    {
                    case 0:     // Air
                    case 78:    // Snow cover
                        continue;

                    // case 1: // ROCK
                    case 2:                                            // GRASS
                    case 3:                                            // DIRT
                        //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y);
                        mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling
                        mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15.

                        /*
                         * Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8));
                         * tree.MakeTrunk(ref mh);
                         * tree.MakeFoliage(ref mh);
                         */
                        mh.SaveAll();
                        founddert = true;
                        break;

                    case 11:     // SAND
                        //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y);
                        break;

                    default:
                        founddert = true;
                        break;
                    }
                    if (founddert)
                    {
                        break;
                    }
                }
                PlantedTrees.Add(me);
            }
        }
Пример #11
0
 public override void MakeFoliage(ref IMapHandler map)
 {
     List<Vector3i> foliage_coords = foliage_cords;
     foreach(Vector3i coord in foliage_coords)
     {
         foliagecluster(ref map,coord);
     }
     foreach(Vector3i cord in foliage_coords)
     {
         map.SetBlockAt(cord.X,cord.Y,cord.Z,17);
         if(LIGHTTREE == 1)
         {
             map.SetBlockAt(cord.X,cord.Y+1,cord.Z,50);
             map.SetBlockAt(cord.X,cord.Y+2,cord.Z,17);
         }
         else if (LIGHTTREE == 2 || LIGHTTREE == 4)
         {
             map.SetBlockAt(cord.X+1,cord.Y,cord.Z,50);
             map.SetBlockAt(cord.X-1,cord.Y,cord.Z,50);
             if(LIGHTTREE == 4)
             {
                 map.SetBlockAt(cord.X,cord.Y,cord.Z+1,50);
                 map.SetBlockAt(cord.X,cord.Y,cord.Z-1,50);
             }
         }
     }
 }
Пример #12
0
 /// <summary>
 /// Create a round section of type matidx in blocklist.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="vCenter">the coordinates of the center block</param>
 /// <param name="radius">the radius of the section.</param>
 /// <param name="diraxis">The list index for the axis to make the section perpendicular to.  0 indicates the x axis, 1 the y, 2 the z.  The section will extend along the other two axies.</param>
 /// <param name="mat">What to make the section out of</param>
 public void crossection(ref IMapHandler map, Vector3i vCenter, double radius, int diraxis, byte mat)
 {
     long[] centArray=vCenter.ToArray();
     int rad = (int)(radius + .618d);
     int secidx1 = (diraxis - 1)%3;
     int secidx2 = (1 + diraxis)%3;
     int[] coord = new int []{0,0,0};
     for(int off1 =-rad; off1<rad+1;off1++)
     {
         for(int off2 =-rad; off2<rad+1;off2++)
         {
             double thisdist = Math.Sqrt(Math.Pow((double)Math.Abs(off1)+.5d,2d) + Math.Pow((double)Math.Abs(off2) + .5d,2));
             if(thisdist > radius)
                 continue;
             int pri = (int)centArray[diraxis];
             int sec1 = (int)centArray[secidx1] + off1;
             int sec2 = (int)centArray[secidx2] + off2;
             coord[diraxis] = pri;
             coord[secidx1] = sec1;
             coord[secidx2] = sec2;
             map.SetBlockAt(coord[0],coord[1],coord[2],mat);
         }
     }
 }
Пример #13
0
        public virtual void AddTrees(ref IMapHandler mh, BiomeType[,] biomes, ref Random rand, int X, int Z, int H)
        {
            int xo = (int)(X * mh.ChunkScale.X);
            int zo = (int)(Z * mh.ChunkScale.Z);
            List<Vector2i> PlantedTrees = new List<Vector2i>();
            int DistanceReqd = 3;
            for (int t = 0; t < (int)((HumidityNoise.Noise((double)(xo) / BIOME_SCALE, (double)(zo) / BIOME_SCALE, 0) + HumidityOffset) * 5.0); t++)
            {
                Vector2i me = new Vector2i(rand.Next(0, 15),rand.Next(0, 15));
                if (!Biome.NeedsTrees(biomes[me.X, me.Y]))
                    continue;
                bool tooclose=false;
                foreach (Vector2i tree in PlantedTrees)
                {
                    if (Vector2i.Distance(tree, me) < DistanceReqd)
                    {
                        tooclose = true;
                        break;
                    }
                }

                if (tooclose) continue;
                bool founddert = false;
                for (int y = (int)H - 10; y > 0; y--)
                {
                    switch (mh.GetBlockAt(me.X+xo, y, me.Y+zo))
                    {
                        case 0: // Air
                        case 78: // Snow cover
                            continue;
                        // case 1: // ROCK
                        case 2: // GRASS
                        case 3: // DIRT
                            //Utils.GrowTree(ref blocks, rand, (int)me.X, (int)y + 1, (int)me.Y);
                            mh.SetBlockAt(me.X + xo, y + 1, me.Y + zo, 6); // Sapling
                            mh.SetDataAt(me.X + xo, y + 1, me.Y + zo, 15); // Growth stage 15.
                            /*
                            Tree tree = new NormalTree(me.X + xo, y + 1, me.Y + zo, rand.Next(5, 8));
                            tree.MakeTrunk(ref mh);
                            tree.MakeFoliage(ref mh);
                            */
                            mh.SaveAll();
                            founddert = true;
                            break;
                        case 11: // SAND
                            //Utils.GrowCactus(ref b, rand, me.X, y + 1, me.Y);
                            break;
                        default:
                            founddert = true;
                            break;
                    }
                    if (founddert) break;
                }
                PlantedTrees.Add(me);
            }
        }