示例#1
0
        static int RemoveFire(McaFile mca)
        {
            int removed = 0;

            foreach (var c in mca.chunks)
            {
                if (c == null)
                {
                    continue;
                }
                var sections = c.Tag ["Level"] ["Sections"] as TagList <TagCompound>;
                foreach (TagCompound s in sections.List)
                {
                    byte[] blocks = s ["Blocks"].ByteArray;
                    for (int n = 0; n < blocks.Length; n++)
                    {
                        if (blocks [n] == (byte)BlockID.Sand)
                        {
                            removed   += 1;
                            blocks [n] = 0;
                        }
                    }
                }
            }
            return(removed);
        }
示例#2
0
        static int Custom()
        {
            //Manual work
            string  path = "/home/nuxas/Traveler/current/world/region/r.0.-5.mca";
            McaFile mca  = McaFile.Load(path);

            Console.WriteLine(mca.chunks [0, 0].Tag);
            mca.chunks [15, 23] = null;
            mca.chunks [16, 23] = null;
            mca.chunks [14, 24] = null;
            mca.chunks [11, 22] = null;
            mca.chunks [10, 21] = null;

            //Clear entities
            foreach (var c in mca.chunks)
            {
                if (c == null)
                {
                    continue;
                }
                var l = c.Tag ["Level"] ["Entities"] as TagList <TagCompound>;
                if (l == null)
                {
                    continue;///empty lists are of type list<tagbyte>
                }
                l.List.Clear();
            }

            mca.SaveAs(path + ".temp");
            File.Delete(path);
            File.Move(path + ".temp", path);
            return(0);
        }
示例#3
0
        static int DeleteChunk(McaFile mca, string[] args)
        {
            for (int n = 2; n < args.Length; n++)
            {
                string[] p  = args [n].Split('.');
                int      dx = int.Parse(p [0]);
                int      dz = int.Parse(p [1]);

                mca.chunks [dx, dz] = null;
            }
            return(0);
        }
示例#4
0
        static int CleanEntities(McaFile mca)
        {
            int removed = 0;

            foreach (var c in mca.chunks)
            {
                if (c == null)
                {
                    continue;
                }
                var l = c.Tag ["Level"] ["Entities"] as TagList <TagCompound>;
                if (l == null)
                {
                    continue;///empty lists are of type list<tagbyte>
                }
                removed += l.List.Count;
                l.List.Clear();
            }
            return(removed);
        }
示例#5
0
        public static int Command(string[] args)
        {
            McaFile mca = McaFile.Load(args [0]);

            if (args.Length == 1)
            {
                Console.WriteLine(mca);
                return(0);
            }

            switch (args [1].ToLowerInvariant())
            {
            case "nop":
                mca.SaveAs(args [2]);
                Console.WriteLine("Saved as is");
                return(0);

            case "cleanentities":
                int removed = CleanEntities(mca);
                mca.Save();
                Console.WriteLine("Removed " + removed);
                return(0);

            case "deletechunk":
                DeleteChunk(mca, args);
                mca.Save();
                Console.WriteLine("Removed chunks");
                return(0);

            case "nofire":
                int fires = RemoveFire(mca);
                Console.WriteLine("Removed " + fires + " fires");
                mca.Save();
                return(0);

            default:
                Console.Error.WriteLine("Unknown command: " + args [1]);
                return(-1);
            }
        }
示例#6
0
        public static void Paint(Graphics g, MapControl map, int Width, int Height, CoordDouble center, float scale)
        {
            if (map.Dimension > Dimensions.End)
            {
                return;
            }

            CoordDouble topleft = center - new CoordDouble(Width / 2 * scale, 0, Height / 2 * scale);

            //Determine center region
            int rx = (int)center.X & -512;
            int rz = (int)center.Z & -512;
            //Sub region chunk index
            int scx = (((int)center.X) >> 4) & 0x1F;
            int scz = (((int)center.Z) >> 4) & 0x1F;

            //Region changed
            if (rx != lastCX || rz != lastCY)
            {
                lastCX = rx;
                lastCY = rz;
                //Load region
                //lastReg = McaFile.Load(map.Dimension, rx, rz);
            }

            //..
            if (scale < 1)
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            }
            else
            {
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            }


            float drawSize = regionSize / scale - 1;

            int xStart = (int)Math.Floor(topleft.X / regionSize) * regionSize;
            int xEnd   = (int)Math.Ceiling((topleft.X + Width * scale) / regionSize) * regionSize;
            int yStart = (int)Math.Floor(topleft.Z / regionSize) * regionSize;
            int yEnd   = (int)Math.Ceiling((topleft.Z + Height * scale) / regionSize) * regionSize;

            for (int x = xStart; x <= xEnd; x += regionSize)
            {
                for (int z = yStart; z <= yEnd; z += regionSize)
                {
                    float px = ((x - (float)topleft.X) / scale);
                    float py = ((z - (float)topleft.Z) / scale);

                    if (lastReg != null)
                    {
                        if (x == rx && z == rz)
                        {
                            int subSize = (int)(drawSize / 32) - 1;
                            for (int dx = 0; dx < 32; dx++)
                            {
                                for (int dz = 0; dz < 32; dz++)
                                {
                                    float pdx = ((x + (dx << 4) - (float)topleft.X) / scale);
                                    float pdy = ((z + (dz << 4) - (float)topleft.Z) / scale);

                                    if (lastReg.HasChunk(dx, dz))
                                    {
                                        if (dx == scx && dz == scz)
                                        {
                                            //Highlighted
                                            g.FillRectangle(Brushes.Orange, pdx, pdy, subSize, subSize);
                                            McaChunk c = lastReg.chunks [dx, dz];
                                            g.DrawString(c.ToString(), font, Brushes.Black, pdx, pdy);
                                        }
                                        else
                                        {
                                            g.FillRectangle(Brushes.Green, pdx, pdy, subSize, subSize);
                                        }
                                    }
                                }
                            }
                            //Console.WriteLine (lastReg);
                            //using (Image b = Bitmap.FromFile(basePath+path))
                            //	g.DrawImage (b, px, py, drawSize, drawSize);
                        }
                    }

                    string path = McaFile.Path(map.Dimension, x, z);
                    if (File.Exists(path))
                    {
                        //Draw Age border
                        Color c = Color.FromArgb(128, AgeColor(File.GetLastWriteTime(path)));
                        using (Pen p = new Pen(c))
                        {
                            p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

                            g.DrawRectangle(p, px, py, drawSize, drawSize);
                        }
                        g.DrawString((x >> 9) + "," + (z >> 9), font, Brushes.GreenYellow, px, py);
                    }
                    else
                    {
                        //g.DrawRectangle (Pens.Orange, px, py, drawSize, drawSize);
                        //g.DrawString (path, font, Brushes.Purple, px, py);
                        //g.DrawString (scale.ToString (), font, Brushes.Purple, px, py);
                    }
                }
            }
        }