Ejemplo n.º 1
0
        public static void CropMaceWorld(frmMace frmLogForm)
        {
            // thank you to Surrogard <*****@*****.**> for providing a linux friendly version of this code:
            Directory.CreateDirectory("macecopy".ToMinecraftSaveDirectory());
            AnvilWorld         awCopy = AnvilWorld.Create("macecopy".ToMinecraftSaveDirectory());
            RegionChunkManager cmCopy = awCopy.GetChunkManager();
            AnvilWorld         awCrop = AnvilWorld.Open("mace".ToMinecraftSaveDirectory());
            RegionChunkManager cmCrop = awCrop.GetChunkManager();

            foreach (ChunkRef chunk in cmCrop)
            {
                if (chunk.X >= -7 && chunk.X <= 11 && chunk.Z >= 0 && chunk.Z <= 11)
                {
                    Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z);
                    cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
                }
                cmCopy.Save();
            }
            awCopy.Level.GameType = GameType.CREATIVE;
            cmCopy.Save();
            awCopy.Save();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                Process.Start("explorer.exe", @"/select," + "macecopy".ToMinecraftSaveDirectory() + "\\level.dat");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("You must specify a target directory");
                return;
            }
            string dest = args[0];

            AnvilWorld   world = AnvilWorld.Open("F:\\Minecraft\\test");
            BlockManager bm    = world.GetBlockManager();

            bm.AutoLight = false;

            Grid grid = new Grid();

            grid.BuildInit(bm);

            Generator             gen   = new Generator();
            List <Generator.Edge> edges = gen.Generate();

            foreach (Generator.Edge e in edges)
            {
                int x1;
                int y1;
                int z1;
                gen.UnIndex(e.node1, out x1, out y1, out z1);

                int x2;
                int y2;
                int z2;
                gen.UnIndex(e.node2, out x2, out y2, out z2);

                grid.LinkRooms(bm, x1, y1, z1, x2, y2, z2);
            }

            // Entrance Room
            grid.BuildRoom(bm, 2, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 1, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 3, 5, 2);
            grid.LinkRooms(bm, 2, 5, 2, 2, 5, 1);
            grid.LinkRooms(bm, 2, 5, 2, 2, 5, 3);
            grid.LinkRooms(bm, 2, 4, 2, 2, 5, 2);

            // Exit Room
            grid.BuildRoom(bm, 2, -1, 2);
            grid.LinkRooms(bm, 2, -1, 2, 2, 0, 2);
            grid.AddPrize(bm, 2, -1, 2);

            Console.WriteLine("Relight Chunks");

            RegionChunkManager cm = world.GetChunkManager();

            cm.RelightDirtyChunks();

            world.Save();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("You must specify a target directory");
                return;
            }
            string dest = args[0];

            /*
             * NbtVerifier.InvalidTagType += (e) => {
             *  throw new Exception("Invalid Tag Type: " + e.TagName + " [" + e.Tag + "]");
             * };
             * NbtVerifier.InvalidTagValue += (e) => {
             *  throw new Exception("Invalid Tag Value: " + e.TagName + " [" + e.Tag + "]");
             * };
             * NbtVerifier.MissingTag += (e) => {
             *  throw new Exception("Missing Tag: " + e.TagName);
             * };
             */

            // Opening an NbtWorld will try to autodetect if a world is Alpha-style or Beta-style
            Console.WriteLine("AnvilWorld.Open(dest)");
            AnvilWorld world = AnvilWorld.Open(dest);

            // Grab a generic chunk manager reference
            Console.WriteLine("world.GetChunkManager()");
            IChunkManager cm = world.GetChunkManager();

            // Iterate through all the chunks
            foreach (ChunkRef chunk in cm)
            {
                // Check if Ocean chunk
                bool foundocean = false;
                for (int x = 0; x < 16; x++)
                {
                    for (int z = 0; z < 16; z++)
                    {
                        if (chunk.Biomes.GetBiome(x, z) == BiomeType.Ocean || chunk.Biomes.GetBiome(x, z) == BiomeType.DeepOcean || chunk.Biomes.GetBiome(x, z) == BiomeType.FrozenOcean)
                        {
                            foundocean = true;
                        }
                    }
                }
                // Or if old unpopulated chunk
                //set status as liquid_carved (or similar)
                if (foundocean == true)
                {
                    Console.WriteLine("Found ocean in chunk {0},{1}, setting status to liquid_carved", chunk.X, chunk.Z);
                    chunk.Status = "liquid_carved";
                }

                cm.Save();

                //Console.WriteLine("Repopulated Chunk {0},{1}", chunk.X, chunk.Z);
            }
        }
        public void ExportMap(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           path   = e.Argument as string;

            worker.ReportProgress(0, "Exporting map to " + path);

            AnvilWorld world = AnvilWorld.Create(path);

            world.Level.LevelName = "Dwarf Fortress World";
            world.Level.GameType  = GameType.CREATIVE;
            world.Level.Spawn     = new SpawnPoint(36, 255, 36);
            world.Save();
            var chunkManager = world.GetChunkManager();
            int total        = (Tiles[0].Height * tileWidth / 16) * (Tiles[0].Width * tileWidth / 16);
            int done         = 0;

            for (int chunkZ = 0; chunkZ < Tiles[0].Height * tileWidth / 16; chunkZ++)
            {
                for (int chunkX = 0; chunkX < Tiles[0].Width * tileWidth / 16; chunkX++)
                {
                    var chunk  = chunkManager.CreateChunk(chunkX, chunkZ);
                    var blocks = chunk.Blocks;
                    blocks.AutoLight         = false;
                    chunk.IsTerrainPopulated = true;
                    int chunkY = 0;
                    foreach (var level in Tiles)
                    {
                        if (!level.Enabled)
                        {
                            continue;
                        }
                        for (int y = 0; y < tileHeight; y++)
                        {
                            for (int z = 0; z < 16; z++)
                            {
                                for (int x = 0; x < 16; x++)
                                {
                                    blocks.SetBlock(x, y + (chunkY * tileHeight), z,
                                                    level.GetBlock(x + (chunkX * 16), y, z + (chunkZ * 16)));
                                }
                            }
                        }
                        chunkY++;
                    }
                    blocks.RebuildSkyLight();
                    blocks.RebuildBlockLight();
                    blocks.RebuildHeightMap();
                    chunkManager.Save();
                    done++;
                    worker.ReportProgress(done * 100 / total, "Generating Chunks");
                }
            }
            worker.ReportProgress(100, "Finished exporting map");
        }
Ejemplo n.º 5
0
        static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed,
                                    string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes,
                                    int ChunksBetweenCities, string strSpawnPoint, bool booExportSchematics,
                                    string strSelectedNPCs, string strUndergroundOres)
        {
            frmLogForm.UpdateLog("Started at " + DateTime.Now.ToLocalTime(), false, true);

            worldCities = new WorldCity[TotalCities];
            lstCityNames.Clear();
            Chunks.biomes.Clear();

            RNG.SetRandomSeed();

            #region create minecraft world directory from a random unused world name
            string strFolder = String.Empty, strWorldName = String.Empty;

            UserWorldName = UserWorldName.ToSafeFilename();
            if (UserWorldName.Trim().Length == 0)
            {
                UserWorldName = "random";
            }

            if (UserWorldName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(UserWorldName.ToMinecraftSaveDirectory()))
                {
                    if (MessageBox.Show("A world called \"" + UserWorldName + "\" already exists. " +
                                        "Would you like to use a random name instead?", "World already exists",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                    {
                        frmLogForm.UpdateLog("Cancelled, because a world with this name already exists.", false, false);
                        return;
                    }
                }
                else
                {
                    strWorldName = UserWorldName;
                    strFolder    = strWorldName.ToMinecraftSaveDirectory();
                }
            }
            if (strWorldName.Length == 0)
            {
                strWorldName = Utils.GenerateWorldName();
                strFolder    = strWorldName.ToMinecraftSaveDirectory();
            }
            Directory.CreateDirectory(strFolder);
            frmLogForm.btnSaveLogNormal.Tag  = Path.Combine(strFolder, "LogNormal.txt");
            frmLogForm.btnSaveLogVerbose.Tag = Path.Combine(strFolder, "LogVerbose.txt");
            frmLogForm.UpdateLog("World name: " + strWorldName, false, true);
            #endregion

            #region get handles to world, chunk manager and block manager
            AnvilWorld worldDest = AnvilWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            RegionChunkManager cmDest = worldDest.GetChunkManager();
            BlockManager       bmDest = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region Determine themes
            // "how does this work, robson?"
            // well, I'm glad you asked!
            // we keep selecting a random unused checked theme, until they've all been used once.
            // after that, all other cities will have a random checked theme

            int maxFarmSize = 0;

            strCheckedThemes = RNG.ShuffleArray(strCheckedThemes);
            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                if (CurrentCityID <= strCheckedThemes.GetUpperBound(0))
                {
                    worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID];
                }
                else
                {
                    worldCities[CurrentCityID].ThemeName = RNG.RandomItem(strCheckedThemes);
                }
                City.themeName = worldCities[CurrentCityID].ThemeName;
                worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size");
                int farmSize = GetThemeLastXMLElementNumber("options", "farm_size");
                maxFarmSize = Math.Max(maxFarmSize, farmSize);
            }
            #endregion

            GenerateCityLocations(TotalCities, ChunksBetweenCities + maxFarmSize);

            int intRandomCity = RNG.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID, strSelectedNPCs);
                if (!GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z, booExportSchematics, strUndergroundOres))
                {
                    frmLogForm.UpdateLog("World generation failed/cancelled.", false, false);
                    return;
                }
                #region set spawn point
                if (City.id == intRandomCity)
                {
                    switch (strSpawnPoint)
                    {
                    case "Away from the cities":
                        worldDest.Level.Spawn = new SpawnPoint(0, 65, 0);
                        break;

                    case "Inside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2));
                        break;

                    case "Outside a random city":
                        worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + (City.mapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + Chunks.CITY_RELOCATION_CHUNKS) * 16) + 2);
                        break;

                    default:
                        Debug.Fail("invalid spawn point");
                        break;
                    }
                    frmLogForm.UpdateLog("Spawn point set to " + worldDest.Level.Spawn.X + "," + worldDest.Level.Spawn.Y + "," + worldDest.Level.Spawn.Z, false, true);
                }
                #endregion
            }

            #region weather
            frmLogForm.UpdateLog("Setting weather", false, true);
            worldDest.Level.Time = RNG.Next(24000);
            if (RNG.NextDouble() < 0.15)
            {
                frmLogForm.UpdateLog("Rain", false, true);
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RNG.Next(6000, 18000);
                if (RNG.NextDouble() < 0.25)
                {
                    frmLogForm.UpdateLog("Thunder", false, true);
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
            #endregion

            #region world details
            worldDest.Level.LevelName = strWorldName;
            frmLogForm.UpdateLog("Setting world type: " + strWorldType, false, true);
            switch (strWorldType.ToLower())
            {
            case "creative":
                worldDest.Level.GameType = GameType.CREATIVE;
                break;

            case "survival":
                worldDest.Level.GameType = GameType.SURVIVAL;
                break;

            case "hardcore":
                worldDest.Level.GameType = GameType.SURVIVAL;
                worldDest.Level.Hardcore = true;
                break;

            default:
                Debug.Fail("Invalidate world type selected.");
                break;
            }
            frmLogForm.UpdateLog("World map features: " + booWorldMapFeatures.ToString(), false, true);
            worldDest.Level.UseMapFeatures = booWorldMapFeatures;
            if (strWorldSeed != String.Empty)
            {
                long seed = 0;
                if (long.TryParse(strWorldSeed, out seed))
                {
                    worldDest.Level.RandomSeed = seed;
                    frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true);
                }
                else
                {
                    worldDest.Level.RandomSeed = strWorldSeed.ToJavaHashCode();
                    frmLogForm.UpdateLog("Specified world seed: " + strWorldSeed, false, true);
                    frmLogForm.UpdateLog("Specified world seed converted to a number: " + worldDest.Level.RandomSeed, false, true);
                }
            }
            else
            {
                worldDest.Level.RandomSeed = RNG.Next();
                frmLogForm.UpdateLog("Random world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            worldDest.Level.LastPlayed = (DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks) / 10000;
            frmLogForm.UpdateLog("World time: " + worldDest.Level.LastPlayed, false, true);
            #endregion

            cmDest.Save();
            worldDest.Save();

            Chunks.SetBiomeData(@strFolder);

            frmLogForm.UpdateLog("\nCreated the " + strWorldName + "!", false, false);
            frmLogForm.UpdateLog("It'll be at the top of your MineCraft world list.", false, false);

            frmLogForm.UpdateLog("Finished at " + DateTime.Now.ToLocalTime(), false, true);
        }
Ejemplo n.º 6
0
        private void Render(bool IsPreview)
        {
            _Abort = false;

            ToggleControls(!IsPreview, true, IsPreview);
            SetStatus("Initializing...");
            IRenderer Renderer = null;

            // *** Set up renderer config
            _RenderingConfig.IsPreview       = IsPreview;
            _RenderingConfig.Chunks          = _World.GetChunkManager(_RenderingConfig.Dimension);
            _RenderingConfig.Palette         = new BlockPalette();
            _RenderingConfig.RenderSubregion = cbCropMap.Checked;
            _RenderingConfig.MaxThreads      = cbMultithread.Checked ? (int)nudThreads.Value : 1;

            // ReSharper disable once InconsistentlySynchronizedField
            // *** This section of code is run before the parallel processing begins, so there is no danger of sync issues.
            _SkipErrors.Clear();

            if (IsPreview)
            {
                _RenderingConfig.RenderSubregion = true;
                _RenderingConfig.SubregionChunks = new Rectangle(-15, -15, 31, 31);
            }
            else if (_RenderingConfig.RenderSubregion)
            {
                _RenderingConfig.SubregionChunks = new Rectangle((int)nudXMin.Value, (int)nudZMin.Value, (int)nudXMax.Value - (int)nudXMin.Value + 1, (int)nudZMax.Value - (int)nudZMin.Value + 1);
            }
            else
            {
                _RenderingConfig.SubregionChunks = new Rectangle(_RenderingConfig.Metrics.MinX, _RenderingConfig.Metrics.MinZ, _RenderingConfig.Metrics.MaxX - _RenderingConfig.Metrics.MinX, _RenderingConfig.Metrics.MaxZ - _RenderingConfig.Metrics.MinZ);
            }

            if (_Abort)
            {
                goto Cleanup;
            }

            foreach (DataGridViewRow Row in dgPalettes.Rows)
            {
                ((PaletteFile)Row.Tag).Selected = (bool)Row.Cells[0].Value;
            }


            // *** Set up palettes
            foreach (String Palette in from PaletteFile File in PaletteManager.Instance().AllPalettes where File.Selected select File.PalettePath)
            {
                try
                {
                    _RenderingConfig.Palette.LoadPalette(Palette);
                }
                catch (BlockPalette.PaletteExecutionException Ex)
                {
                    MessageBox.Show(string.Format("The palette file {0} is invalid and will be skipped:\r\n{1}", Path.GetFileName(Palette), Ex.Message), "Palette Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    PaletteManager.Instance().AllPalettes.First(x => x.PalettePath == Palette).Selected = false;
                }
            }

            if (_Abort)
            {
                goto Cleanup;
            }

            UpdatePaletteSelection();

            _RenderingConfig.Palette.AssembleLookupTables();

            // *** Initialize renderer
            Renderer = RendererManager.Instance().InstantiateRenderer((_SelectedRenderer).RendererName);

            Renderer.ProgressUpdate += DoUpdate;
            Renderer.RenderError    += HandleError;

            Renderer.Configure(_RenderingConfig);
            Renderer.Initialize();

            _AbortRender = Renderer.Abort;

            // *** Render
            if (IsPreview)
            {
                pbPreview.Image = Renderer.Preview();
            }
            else
            {
                Renderer.Render();
            }


Cleanup:

            // *** Clean up
            if (Renderer != null)
            {
                Renderer.ProgressUpdate -= DoUpdate;
                Renderer.RenderError    -= HandleError;
            }

            ToggleControls(false, _World != null, false);
            SetStatus(_Abort ? "Aborted" : "Finished", "Render " + (_Abort ? "Aborted" : "Finished"));
            SetProgress(0);
            _AbortRender = null;
            _Abort       = false;
        }
Ejemplo n.º 7
0
 private void Measure(AnvilWorld World)
 {
     Measure(World.GetChunkManager(Dimension));
 }
Ejemplo n.º 8
0
        void GenerateList()
        {
            StreamWriter wr = new StreamWriter(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "HiveList.txt"), false);

            int totalcount = 0;
            int ore        = 2646;
            int oreMeta    = 6;
            int hive       = 627;

            // Open our world

            AnvilWorld world = AnvilWorld.Open(worldPath);

            // The chunk manager is more efficient than the block manager for
            // this purpose, since we'll inspect every block
            RegionChunkManager rcm = world.GetChunkManager(0);

            pbChunks.Maximum = rcm.Count();
            pbChunks.Minimum = 0;
            pbChunks.Value   = 0;

            foreach (ChunkRef chunk in rcm)
            {
                pbChunks.Value++;
                //if (chunk.X < 0 || chunk.Z < 0 || chunk.Z > 134 || chunk.X > 111)
                //{
                //    continue;
                //}

                // You could hardcode your dimensions, but maybe some day they
                // won't always be 16.  Also the CLR is a bit stupid and has
                // trouble optimizing repeated calls to Chunk.Blocks.xx, so we
                // cache them in locals
                int xdim = chunk.Blocks.XDim;
                int ydim = chunk.Blocks.YDim;
                int zdim = chunk.Blocks.ZDim;


                AnvilBiomeCollection chunkBiome = chunk.Biomes;

                // x, z, y is the most efficient order to scan blocks (not that
                // you should care about internal detail)
                for (int x = 0; x < xdim; x++)
                {
                    for (int z = 0; z < zdim; z++)
                    {
                        int biome = chunkBiome.GetBiome(x, z);

                        for (int y = 0; y < ydim; y++)
                        {
                            int cid = chunk.Blocks.GetID(x, y, z);
                            if (y > 1)
                            {
                                if (cid == hive)
                                {
                                    int cdata = chunk.Blocks.GetData(x, y, z);
                                    //if (cdata == oreMeta)
                                    //{
                                    wr.WriteLine("H;{0};{1};{2};{3},{4}", chunk.X * xdim + x, chunk.Z * zdim + z, y, biome, cdata);
                                    totalcount++;
                                    //}
                                }
                            }
                            //Break when hitting daylight.
                            int light = chunk.Blocks.GetSkyLight(x, y, z);
                            if (light == 12)
                            {
                                break;
                            }
                        }
                    }
                }
                if (pbChunks.Value % 32 == 0)
                {
                    txtDebug.Text = string.Format("Processed Chunk {0},{1}", chunk.X, chunk.Z) + Environment.NewLine;
                    Application.DoEvents();
                }
            }

            txtDebug.Text += string.Format("Found ore count:{0}", totalcount) + Environment.NewLine;
            wr.Close();
        }