예제 #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());
            BetaWorld        bwCopy = BetaWorld.Create("macecopy".ToMinecraftSaveDirectory());
            BetaChunkManager cmCopy = bwCopy.GetChunkManager();
            BetaWorld        bwCrop = BetaWorld.Open("macemaster".ToMinecraftSaveDirectory());
            BetaChunkManager cmCrop = bwCrop.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();
            }
            bwCopy.Level.GameType = GameType.CREATIVE;
            cmCopy.Save();
            bwCopy.Save();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                Process.Start("explorer.exe", @"/select," + "macecopy".ToMinecraftSaveDirectory() + "\\level.dat");
            }
        }
예제 #2
0
        public static void ResetLighting(BetaWorld world, BetaChunkManager cm, frmMace frmLogForm)
        {
            int intChunksChecked   = 0;
            int intChunksProcessed = 0;
            // we process each chunk twice, hence this:
            int intTotalChunks = 0;

            //this code is based on a substrate example
            //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
            //see the <License Substrate.txt> file for copyright information
            foreach (ChunkRef chunk in cm)
            {
                intTotalChunks += 2;
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    intChunksChecked++;
                    try
                    {
                        chunk.Blocks.RebuildHeightMap();
                        chunk.Blocks.ResetBlockLight();
                        chunk.Blocks.ResetSkyLight();
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Chunk reset light fail");
                    }
                }
                if (++intChunksProcessed % 10 == 0)
                {
                    cm.Save();
                    frmLogForm.UpdateProgress(intChunksProcessed * 0.95 / intTotalChunks);
                }
            }
            foreach (ChunkRef chunk in cm)
            {
                if (chunk.IsTerrainPopulated)
                {
                    try
                    {
                        chunk.Blocks.RebuildBlockLight();
                        chunk.Blocks.RebuildSkyLight();
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Chunk rebuild light fail");
                    }
                }
                if (++intChunksProcessed % 10 == 0)
                {
                    cm.Save();
                    frmLogForm.UpdateProgress(intChunksProcessed * 0.95 / intTotalChunks);
                }
            }
            world.Save();
        }
예제 #3
0
        static void Main(string[] args)
        {
            string dest = "F:\\Minecraft\\test";
            int    xmin = -20;
            int    xmax = 20;
            int    zmin = -20;
            int    zmaz = 20;

            // This will instantly create any necessary directory structure
            BetaWorld        world = BetaWorld.Create(dest);
            BetaChunkManager cm    = world.GetChunkManager();

            // We can set different world parameters
            world.Level.LevelName = "Flatlands";
            world.Level.Spawn     = new SpawnPoint(20, 20, 70);

            // world.Level.SetDefaultPlayer();
            // We'll let MC create the player for us, but you could use the above
            // line to create the SSP player entry in level.dat.

            // We'll create chunks at chunk coordinates xmin,zmin to xmax,zmax
            for (int xi = xmin; xi < xmax; xi++)
            {
                for (int zi = zmin; zi < zmaz; zi++)
                {
                    // This line will create a default empty chunk, and create a
                    // backing region file if necessary (which will immediately be
                    // written to disk)
                    ChunkRef chunk = cm.CreateChunk(xi, zi);

                    // This will suppress generating caves, ores, and all those
                    // other goodies.
                    chunk.IsTerrainPopulated = true;

                    // Auto light recalculation is horrifically bad for creating
                    // chunks from scratch, because we're placing thousands
                    // of blocks.  Turn it off.
                    chunk.Blocks.AutoLight = false;

                    // Set the blocks
                    FlatChunk(chunk, 64);

                    // Reset and rebuild the lighting for the entire chunk at once
                    chunk.Blocks.RebuildBlockLight();
                    chunk.Blocks.RebuildSkyLight();

                    Console.WriteLine("Built Chunk {0},{1}", chunk.X, chunk.Z);

                    // Save the chunk to disk so it doesn't hang around in RAM
                    cm.Save();
                }
            }

            // Save all remaining data (including a default level.dat)
            // If we didn't save chunks earlier, they would be saved here
            world.Save();
        }
예제 #4
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: BlockReplace <world> <before-id> <after-id>");
                return;
            }

            string dest   = args[0];
            int    before = Convert.ToInt32(args[1]);
            int    after  = Convert.ToInt32(args[2]);

            // Open our world
            BetaWorld world = BetaWorld.Open(dest);

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

            foreach (ChunkRef chunk in cm)
            {
                // 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;

                chunk.Blocks.AutoFluid = true;

                // 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++)
                    {
                        for (int y = 0; y < ydim; y++)
                        {
                            // Replace the block with after if it matches before
                            if (chunk.Blocks.GetID(x, y, z) == before)
                            {
                                chunk.Blocks.SetData(x, y, z, 0);
                                chunk.Blocks.SetID(x, y, z, after);
                            }
                        }
                    }
                }

                // Save the chunk
                cm.Save();
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage: GoodyChest <world> <prob>");
                return;
            }

            string dest = args[0];
            double p    = Convert.ToDouble(args[1]);

            rand = new Random();

            // Open our world
            BetaWorld        world = BetaWorld.Open(dest);
            BetaChunkManager cm    = world.GetChunkManager();

            int added = 0;

            // Iterate through every chunk in the world
            // With proability p, pick a random location
            // inside the chunk to place a chest, above the
            // first solid block
            foreach (ChunkRef chunk in cm)
            {
                if (rand.NextDouble() < p)
                {
                    int x = rand.Next(chunk.Blocks.XDim);
                    int z = rand.Next(chunk.Blocks.ZDim);
                    int y = chunk.Blocks.GetHeight(x, z);

                    // Can't build this high (-2 to account for new MC 1.6 height limitation)
                    if (y >= chunk.Blocks.YDim - 2)
                    {
                        continue;
                    }

                    // Get a block object, then assign it to the chunk
                    AlphaBlock block = BuildChest();
                    chunk.Blocks.SetBlock(x, y + 1, z, block);

                    // Save the chunk
                    cm.Save();

                    added++;
                }
            }

            // And we're done
            Console.WriteLine("Added {0} goody chests to world", added);
        }
예제 #6
0
        static void Main(string[] args)
        {
            BetaWorld    world = BetaWorld.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");

            BetaChunkManager cm = world.GetChunkManager();

            cm.RelightDirtyChunks();

            world.Save();
        }
예제 #7
0
        public static bool SetupClass(BetaWorld worldDest)
        {
            _AllEntityPainting = new EntityPainting[0];
            _AllBuildings      = new Building[0];
            _intHouseNumber    = 0;
            BetaWorld worldSource = BetaWorld.Open(Path.Combine("Resources", "Mace"));

            _bmSource = worldSource.GetBlockManager();
            _cmSource = worldSource.GetChunkManager();
            _cmDest   = worldDest.GetChunkManager();
            _lstCitySigns.Clear();
            _lstInstanceSigns.Clear();
            return(ReadBuildings());
        }
예제 #8
0
        public static bool SetupClass(BetaWorld worldDest, bool booIncludeItemsInChestsOriginal, bool booIncludeGhostdancerSpawners)
        {
            _AllEntityPainting = new EntityPainting[0];
            _AllBuildings      = new Building[0];
            _intHouseNumber    = 0;
            BetaWorld worldSource = BetaWorld.Open(Path.Combine("Resources", "Mace"));

            _bmSource = worldSource.GetBlockManager();
            _cmSource = worldSource.GetChunkManager();
            _cmDest   = worldDest.GetChunkManager();
            _lstCitySigns.Clear();
            _lstInstanceSigns.Clear();
            _booIncludeItemsInChests       = booIncludeItemsInChestsOriginal;
            _booIncludeGhostdancerSpawners = booIncludeGhostdancerSpawners;
            return(ReadBuildings());
        }
예제 #9
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage: CustomBlock <world>");
                return;
            }

            string dest = args[0];

            // Open our world
            BetaWorld world = BetaWorld.Open(dest);

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

            foreach (ChunkRef chunk in cm)
            {
                // 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;

                chunk.Blocks.AutoFluid = true;

                // 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++)
                    {
                        for (int y = 0; y < ydim; y++)
                        {
                            BlockInfo info = chunk.Blocks.GetInfo(x, y, z);
                            if (info.ID == BlockInfoM.LightSensor.ID)
                            {
                                Console.WriteLine("Found custom block '{0}' at {1}", info.Name, new BlockKey(x, y, z));
                            }
                        }
                    }
                }
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            // Process arguments
            if (args.Length != 2 && args.Length != 6)
            {
                Console.WriteLine("Usage: PurgeEntities <world> <entityID> [<x1> <z1> <x2> <z2>]");
                return;
            }
            string dest = args[0];
            string eid  = args[1];

            // Our initial bounding box is "infinite"
            int x1 = BlockManager.MIN_X;
            int x2 = BlockManager.MAX_X;
            int z1 = BlockManager.MIN_Z;
            int z2 = BlockManager.MAX_Z;

            // If we have all coordinate parameters, set the bounding box
            if (args.Length == 6)
            {
                x1 = Convert.ToInt32(args[2]);
                z1 = Convert.ToInt32(args[3]);
                x2 = Convert.ToInt32(args[4]);
                z2 = Convert.ToInt32(args[5]);
            }

            // Load world
            BetaWorld        world = BetaWorld.Open(dest);
            BetaChunkManager cm    = world.GetChunkManager();

            // Remove entities
            foreach (ChunkRef chunk in cm)
            {
                // Skip chunks that don't cover our selected area
                if (((chunk.X + 1) * chunk.Blocks.XDim < x1) ||
                    (chunk.X * chunk.Blocks.XDim >= x2) ||
                    ((chunk.Z + 1) * chunk.Blocks.ZDim < z1) ||
                    (chunk.Z * chunk.Blocks.ZDim >= z2))
                {
                    continue;
                }

                // Delete the specified entities
                chunk.Entities.RemoveAll(eid);
                cm.Save();
            }
        }
예제 #11
0
 public static void CreateInitialChunks(BetaChunkManager cm, int intEnd, frmMace frmLogForm)
 {
     int[, ,] intUndergroundTerrain = MakeUndergroundTerrain(intEnd * 16, 64, intEnd * 16);
     for (int xi = 0; xi < intEnd; xi++)
     {
         for (int zi = 0; zi < intEnd; zi++)
         {
             ChunkRef chunkActive = cm.CreateChunk(xi, zi);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight = false;
             CreateFlatChunk(chunkActive, intUndergroundTerrain);
             cm.Save();
         }
         frmLogForm.UpdateProgress((1 + xi) * 24 / intEnd);
     }
     cm.Save();
 }
예제 #12
0
 public static void CreateInitialChunks(BetaChunkManager cm, int intEnd, frmMace frmLogForm)
 {
     int[, ,] intUndergroundTerrain = MakeUndergroundTerrain(intEnd * 16, 64, intEnd * 16);
     for (int xi = 0; xi < intEnd; xi++)
     {
         for (int zi = 0; zi < intEnd; zi++)
         {
             ChunkRef chunkActive = cm.CreateChunk(xi, zi);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = false;
             CreateFlatChunk(chunkActive, intUndergroundTerrain);
             cm.Save();
         }
         frmLogForm.UpdateProgress((1 + xi) * 24 / intEnd);
     }
     cm.Save();
 }
예제 #13
0
 public static void CreateInitialChunks(BetaChunkManager cm, frmMace frmLogForm, string strUndergroundOres)
 {
     int[, ,] intUndergroundTerrain = MakeUndergroundTerrain(64, frmLogForm, strUndergroundOres);
     for (int xi = 0; xi < City.MapLength / 16; xi++)
     {
         for (int zi = -City.FarmLength / 16; zi < City.MapLength / 16; zi++)
         {
             ChunkRef chunkActive = cm.CreateChunk(xi, zi);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = false;
             CreateFlatChunk(chunkActive, intUndergroundTerrain);
             cm.Save();
         }
         frmLogForm.UpdateProgress(((1 + xi) * 24 / (City.MapLength / 16)) / 100);
     }
     cm.Save();
 }
예제 #14
0
 public static void MoveChunks(BetaWorld world, BetaChunkManager cm, int CityX, int CityZ)
 {
     cm.Save();
     world.Save();
     for (int x = 0; x < City.MapLength / 16; x++)
     {
         for (int z = 0; z < City.MapLength / 16; z++)
         {
             cm.CopyChunk(x, z, CityX + x + 30, CityZ + z + 30);
             ChunkRef chunkActive = cm.GetChunkRef(CityX + x + 30, CityZ + z + 30);
             chunkActive.IsTerrainPopulated = true;
             cm.DeleteChunk(x, z);
             cm.Save();
             world.Save();
         }
     }
     world.Save();
 }
예제 #15
0
 public static void MoveChunks(BetaWorld world, BetaChunkManager cm, int CityX, int CityZ)
 {
     cm.Save();
     world.Save();
     for (int x = 0; x < City.MapLength / 16; x++)
     {
         for (int z = -City.FarmLength / 16; z < City.MapLength / 16; z++)
         {
             cm.CopyChunk(x, z, CityX + x + CITY_RELOCATION_CHUNKS, CityZ + z + CITY_RELOCATION_CHUNKS);
             ChunkRef chunkActive = cm.GetChunkRef(CityX + x + CITY_RELOCATION_CHUNKS, CityZ + z + CITY_RELOCATION_CHUNKS);
             chunkActive.IsTerrainPopulated = true;
             chunkActive.Blocks.AutoLight   = true;
             cm.DeleteChunk(x, z);
             cm.Save();
             world.Save();
         }
     }
 }
예제 #16
0
        public static void CropMaceWorld(frmMace frmLogForm)
        {
            // thank you to Surrogard <*****@*****.**> for providing a linux friendly version of this code:
            Directory.CreateDirectory(Utils.GetMinecraftSavesDirectory("macecopy"));
            BetaWorld        bwCopy = BetaWorld.Create(Utils.GetMinecraftSavesDirectory("macecopy"));
            BetaChunkManager cmCopy = bwCopy.GetChunkManager();
            BetaWorld        bwCrop = BetaWorld.Open(Utils.GetMinecraftSavesDirectory("mace"));
            BetaChunkManager cmCrop = bwCrop.GetChunkManager();

            foreach (ChunkRef chunk in cmCrop)
            {
                if (chunk.X >= 0 && chunk.X <= 7 && chunk.Z >= 0 && chunk.Z <= 10)
                {
                    Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z);
                    cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef());
                }
            }
            cmCopy.Save();
            bwCopy.Save();
        }
예제 #17
0
        public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager cmDest, BlockManager bmDest, int x, int z)
        {
            #region create a city name
            string strStart, strEnd;
            do
            {
                strStart  = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNamePrefixFilename));
                strEnd    = RandomHelper.RandomFileLine(Path.Combine("Resources", City.CityNameSuffixFilename));
                City.Name = "City of " + strStart + strEnd;
            } while (GenerateWorld.lstCityNames.Contains(City.Name) ||
                     strStart.ToLower().Trim() == strEnd.ToLower().Trim() ||
                     (strStart + strEnd).Length > 14);
            GenerateWorld.lstCityNames.Add(City.Name);
            #endregion

            #region determine block sizes
            City.CityLength *= 16; // chunk length
            City.FarmLength  = City.HasFarms ? 32 : 8;
            City.MapLength   = City.CityLength + (City.FarmLength * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest);
            BlockHelper.SetupClass(bmDest);
            NoticeBoard.SetupClass();
            if (!SourceWorld.SetupClass(worldDest))
            {
                return;
            }
            #endregion

            #region determine random options
#pragma warning disable
            switch (City.WallMaterialID)
            {
            case BlockType.WOOD_PLANK:
            case BlockType.WOOD:
            case BlockType.LEAVES:
            case BlockType.VINES:
            case BlockType.WOOL:
            case BlockType.BOOKSHELF:
                switch (City.OutsideLightType)
                {
                case "Fire":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.OutsideLightType = "Torches";
                    break;
                }
                switch (City.MoatType)
                {
                case "Fire":
                case "Lava":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.MoatType = "Water";
                    break;
                }
                break;
            }
#pragma warning restore
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating the " + City.Name, false, false);
            frmLogForm.UpdateLog("City length in blocks: " + City.MapLength, true, true);
            frmLogForm.UpdateLog("City position in blocks: " + ((x + 30) * 16) + "," + ((z + 30) * 16), true, true);
            frmLogForm.UpdateLog("Theme: " + City.ThemeName, true, true);
            frmLogForm.UpdateLog("Creating underground terrain", true, false);
            Chunks.CreateInitialChunks(cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.35);

            Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint();

            if (City.HasWalls)
            {
                frmLogForm.UpdateLog("Creating walls", true, false);
                Walls.MakeWalls(worldDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.45);
            if (City.HasBuildings || City.HasPaths)
            {
                frmLogForm.UpdateLog("Creating paths", true, false);
                int[,] intArea = Paths.MakePaths(worldDest, bmDest);
                frmLogForm.UpdateProgress(0.50);
                if (City.HasBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings", true, false);
                    spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm);
                    frmLogForm.UpdateProgress(0.55);
                    if (City.HasMineshaft)
                    {
                        frmLogForm.UpdateLog("Creating mineshaft", true, false);
                        Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm);
                    }
                }
            }
            frmLogForm.UpdateProgress(0.60);

            if (City.HasMoat)
            {
                frmLogForm.UpdateLog("Creating moat", true, false);
                Moat.MakeMoat(frmLogForm);
            }
            frmLogForm.UpdateProgress(0.65);

            if (City.HasDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges", true, false);
                Drawbridge.MakeDrawbridges(bmDest);
            }
            frmLogForm.UpdateProgress(0.70);

            if (City.HasGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers", true, false);
                GuardTowers.MakeGuardTowers(bmDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.75);

            if (City.HasFarms)
            {
                frmLogForm.UpdateLog("Creating farms", true, false);
                Farms.MakeFarms(worldDest, bmDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.80);

            if (!City.HasValuableBlocks)
            {
                frmLogForm.UpdateLog("Replacing valuable blocks", true, true);
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.90);
            frmLogForm.UpdateLog("Creating rail data", true, false);
            Chunks.PositionRails(worldDest, bmDest);
            frmLogForm.UpdateProgress(0.95);
            frmLogForm.UpdateLog("Creating position data", true, false);

            Chunks.MoveChunks(worldDest, cmDest, x, z);
            frmLogForm.UpdateProgress(1);
            #endregion
        }
예제 #18
0
        private void OpenDimension(int dim)
        {
            string path = Path;
            if (dim == Dimension.DEFAULT) {
                path = IO.Path.Combine(path, _REGION_DIR);
            }
            else {
                path = IO.Path.Combine(path, "DIM" + dim);
                path = IO.Path.Combine(path, _REGION_DIR);
            }

            if (!Directory.Exists(path)) {
                Directory.CreateDirectory(path);
            }

            ChunkCache cc = new ChunkCache();

            RegionManager rm = new RegionManager(path, cc);
            BetaChunkManager cm = new BetaChunkManager(rm, cc);
            BlockManager bm = new BlockManager(cm);

            _regionMgrs[dim] = rm;
            _chunkMgrs[dim] = cm;
            _blockMgrs[dim] = bm;
        }
예제 #19
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();

            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
            BetaWorld worldDest = BetaWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            BetaChunkManager 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
            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");
            }
            #endregion
            GenerateCityLocations(TotalCities, ChunksBetweenCities);

            int intRandomCity = RNG.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID, strSelectedNPCs);
                GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z, booExportSchematics, strUndergroundOres);
                #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
#if RELEASE
            frmLogForm.UpdateLog("Setting weather", false, true);
            worldDest.Level.Time = RNG.Next(24000);
            if (RNG.NextDouble() < 0.2)
            {
                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;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            #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)
            {
                worldDest.Level.RandomSeed = strWorldSeed.ToJavaHashCode();
                frmLogForm.UpdateLog("Specified world seed: " + 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();

            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);
        }
예제 #20
0
        public static void Generate(frmMace frmLogForm, string strUserCityName,
                                    bool booIncludeFarms, bool booIncludeMoat, bool booIncludeWalls,
                                    bool booIncludeDrawbridges, bool booIncludeGuardTowers, bool booIncludeBuildings,
                                    bool booIncludePaths, bool booIncludeMineshaft, bool booIncludeItemsInChests,
                                    bool booIncludeValuableBlocks, bool booIncludeGhostdancerSpawners,
                                    string strCitySize, string strMoatType, string strCityEmblem,
                                    string strOutsideLights, string strTowerAddition, string strWallMaterial,
                                    string strCitySeed, string strWorldSeed, bool booExportSchematic)
        {
            #region seed the random number generators
            int    intCitySeed, intWorldSeed;
            Random randSeeds = new Random();
            if (strCitySeed.Length == 0)
            {
                intCitySeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random city seed: " + intCitySeed);
            }
            else
            {
                intCitySeed = JavaStringHashCode(strCitySeed);
                frmLogForm.UpdateLog("Random city seed: " + strCitySeed);
            }
            if (strWorldSeed.Length == 0)
            {
                intWorldSeed = randSeeds.Next();
                frmLogForm.UpdateLog("Random world seed: " + intWorldSeed);
            }
            else
            {
                intWorldSeed = JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Random world seed: " + strWorldSeed);
            }
            RandomHelper.SetSeed(intCitySeed);
            #endregion

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

            strUserCityName = SafeFilename(strUserCityName);
            if (strUserCityName.ToLower().Trim().Length == 0)
            {
                strUserCityName = "random";
            }

            if (strUserCityName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDirectory(strUserCityName)))
                {
                    if (MessageBox.Show("A world called \"" + strUserCityName + "\" 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.");
                        return;
                    }
                }
                else
                {
                    strCityName = strUserCityName;
                    strFolder   = Utils.GetMinecraftSavesDirectory(strCityName);
                }
            }
            if (strCityName.Length == 0)
            {
                string strStart, strEnd;
                do
                {
                    strStart    = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityAdj.txt"));
                    strEnd      = RandomHelper.RandomFileLine(Path.Combine("Resources", "CityNoun.txt"));
                    strCityName = "City of " + strStart + strEnd;
                    strFolder   = Utils.GetMinecraftSavesDirectory(strCityName);
                } while (strStart.ToLower().Trim() == strEnd.ToLower().Trim() || Directory.Exists(strFolder) || (strStart + strEnd).Length > 14);
            }
            Directory.CreateDirectory(strFolder);
            RandomHelper.SetSeed(intCitySeed);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld        worldDest = BetaWorld.Create(@strFolder);
            BetaChunkManager cmDest    = worldDest.GetChunkManager();
            BlockManager     bmDest    = worldDest.GetBlockManager();
            bmDest.AutoLight = false;
            #endregion

            #region determine block sizes
            // first we set the city size by chunks
            int intCitySize = 12;
            switch (strCitySize)
            {
            case "Random":
                intCitySize = RandomHelper.Next(8, 16);
                break;

            case "Very small":
                intCitySize = 5;
                break;

            case "Small":
                intCitySize = 8;
                break;

            case "Medium":
                intCitySize = 12;
                break;

            case "Large":
                intCitySize = 16;
                break;

            case "Very large":
                intCitySize = 25;
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            // then we multiply by 16, because that's the x and z of a chunk
            intCitySize *= 16;
            int intFarmLength = booIncludeFarms ? 32 : 8;
            int intMapLength  = intCitySize + (intFarmLength * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest, intMapLength);
            BlockHelper.SetupClass(bmDest, intMapLength);
            if (!SourceWorld.SetupClass(worldDest, booIncludeItemsInChests, booIncludeGhostdancerSpawners))
            {
                return;
            }
            NoticeBoard.SetupClass(intCitySeed, intWorldSeed);
            #endregion

            #region determine random options
            // ensure selected options take priority, but don't set things on fire
            if (strTowerAddition == "Random")
            {
                strTowerAddition = RandomHelper.RandomString("Fire beacon", "Flag");
            }
            if (strWallMaterial.StartsWith("Wood"))
            {
                if (strMoatType == "Lava" || strMoatType == "Fire" || strMoatType == "Random")
                {
                    strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                }
                strOutsideLights = "Torches";
            }
            if (strWallMaterial == "Random")
            {
                if (strMoatType == "Lava" || strMoatType == "Fire" || strOutsideLights == "Fire")
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone", "Stone");
                }
                else
                {
                    strWallMaterial = RandomHelper.RandomString("Brick", "Cobblestone", "Sandstone",
                                                                "Stone", "Wood Planks");
                    if (strWallMaterial.StartsWith("Wood"))
                    {
                        if (strMoatType == "Random")
                        {
                            strMoatType = RandomHelper.RandomString("Drop to Bedrock", "Cactus", "Water");
                        }
                        strOutsideLights = "Torches";
                    }
                }
            }
            if (strOutsideLights == "Random")
            {
                strOutsideLights = RandomHelper.RandomString("Fire", "Torches");
            }
            if (strMoatType == "Random")
            {
                int intRand = RandomHelper.Next(100);
                if (intRand >= 90)
                {
                    strMoatType = "Drop to Bedrock";
                }
                else if (intRand >= 80)
                {
                    strMoatType = "Cactus";
                }
                else if (intRand >= 50)
                {
                    strMoatType = "Lava";
                }
                else if (intRand >= 40)
                {
                    strMoatType = "Fire";
                }
                else
                {
                    strMoatType = "Water";
                }
            }

            int intWallMaterial = BlockType.STONE;
            switch (strWallMaterial)
            {
            case "Brick":
                intWallMaterial = BlockType.BRICK_BLOCK;
                break;

            case "Cobblestone":
                intWallMaterial = BlockType.COBBLESTONE;
                break;

            case "Sandstone":
                intWallMaterial = BlockType.SANDSTONE;
                break;

            case "Stone":
                intWallMaterial = BlockType.STONE;
                break;

            case "Wood Planks":
                intWallMaterial = BlockType.WOOD_PLANK;
                break;

            case "Wood Logs":
                intWallMaterial = BlockType.WOOD;
                break;

            case "Bedrock":
                intWallMaterial = BlockType.BEDROCK;
                break;

            case "Mossy Cobblestone":
                intWallMaterial = BlockType.MOSS_STONE;
                break;

            case "Netherrack":
                intWallMaterial = BlockType.NETHERRACK;
                break;

            case "Glass":
                intWallMaterial = BlockType.GLASS;
                break;

            case "Ice":
                intWallMaterial = BlockType.ICE;
                break;

            case "Snow":
                intWallMaterial = BlockType.SNOW_BLOCK;
                break;

            case "Glowstone":
                intWallMaterial = BlockType.GLOWSTONE_BLOCK;
                break;

            case "Dirt":
                intWallMaterial = BlockType.DIRT;
                break;

            case "Obsidian":
                intWallMaterial = BlockType.OBSIDIAN;
                break;

            case "Jack-o-Lantern":
                intWallMaterial = BlockType.JACK_O_LANTERN;
                break;

            case "Soul sand":
                intWallMaterial = BlockType.SOUL_SAND;
                break;

            case "Gold":
                intWallMaterial = BlockType.GOLD_BLOCK;
                break;

            case "Diamond":
                intWallMaterial = BlockType.DIAMOND_BLOCK;
                break;

            default:
                Debug.Fail("Invalid switch result");
                break;
            }
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating underground terrain");
            Chunks.CreateInitialChunks(cmDest, intMapLength / 16, frmLogForm);
            frmLogForm.UpdateProgress(25);

            Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint();

            if (booIncludeWalls)
            {
                frmLogForm.UpdateLog("Creating walls");
                Walls.MakeWalls(worldDest, intFarmLength, intMapLength, strCityEmblem, strOutsideLights, intWallMaterial);
            }
            frmLogForm.UpdateProgress(34);
            if (booIncludeBuildings || booIncludePaths)
            {
                frmLogForm.UpdateLog("Creating paths");
                int[,] intArea = Paths.MakePaths(worldDest, bmDest, intFarmLength, intMapLength, strCitySize,
                                                 booIncludeMineshaft);
                frmLogForm.UpdateProgress(36);
                if (booIncludeBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings");
                    spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, intFarmLength, intMapLength, booIncludePaths);
                    frmLogForm.UpdateProgress(45);
                    if (booIncludeMineshaft)
                    {
                        frmLogForm.UpdateLog("Creating mineshaft");
                        Mineshaft.MakeMineshaft(worldDest, bmDest, intFarmLength, intMapLength, spMineshaftEntrance);
                    }
                }
            }
            frmLogForm.UpdateProgress(51);

            if (booIncludeMoat)
            {
                frmLogForm.UpdateLog("Creating moat");
                Moat.MakeMoat(intFarmLength, intMapLength, strMoatType, booIncludeGuardTowers);
            }
            frmLogForm.UpdateProgress(52);

            if (booIncludeDrawbridges)
            {
                frmLogForm.UpdateLog("Creating drawbridges");
                Drawbridge.MakeDrawbridges(bmDest, intFarmLength, intMapLength, booIncludeMoat,
                                           booIncludeWalls, booIncludeItemsInChests, intWallMaterial, strMoatType, strCityName);
            }
            frmLogForm.UpdateProgress(53);

            if (booIncludeGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers");
                GuardTowers.MakeGuardTowers(bmDest, intFarmLength, intMapLength, booIncludeWalls,
                                            strOutsideLights, strTowerAddition, booIncludeItemsInChests, intWallMaterial);
            }
            frmLogForm.UpdateProgress(54);

            if (booIncludeFarms)
            {
                frmLogForm.UpdateLog("Creating farms");
                Farms.MakeFarms(worldDest, bmDest, intFarmLength, intMapLength);
            }
            frmLogForm.UpdateProgress(58);

            if (!booIncludeValuableBlocks)
            {
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest, intMapLength, intWallMaterial);
            }
            frmLogForm.UpdateProgress(60);
            Chunks.PositionRails(worldDest, bmDest, intMapLength);
            frmLogForm.UpdateProgress(62);
            #endregion

            #region world settings
            // spawn looking at one of the city entrances
            if (booIncludeFarms)
            {
                SpawnPoint spLevel = new SpawnPoint(7, 11, 13);
                worldDest.Level.Spawn = spLevel;
                worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 10));
            }
            else
            {
                worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength - (intFarmLength - 7));
            }
            // spawn in the middle of the city
//#if DEBUG
            //worldDest.Level.Spawn = new SpawnPoint(intMapLength / 2, 64, intMapLength / 2);
//#endif
            if (strWorldSeed.Length > 0)
            {
                worldDest.Level.RandomSeed = intWorldSeed;
            }

#if RELEASE
            worldDest.Level.Time = RandomHelper.Next(24000);

            if (RandomHelper.NextDouble() < 0.15)
            {
                worldDest.Level.IsRaining = true;
                // one-quarter to three-quarters of a day
                worldDest.Level.RainTime = RandomHelper.Next(6000, 18000);
                if (RandomHelper.NextDouble() < 0.25)
                {
                    worldDest.Level.IsThundering = true;
                    worldDest.Level.ThunderTime  = worldDest.Level.RainTime;
                }
            }
#endif
            #endregion

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            frmLogForm.UpdateLog("Creating lighting data");
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm, (int)Math.Pow(intMapLength / 16, 2));

            worldDest.Level.LevelName = strCityName;
            worldDest.Save();

            if (booExportSchematic)
            {
                frmLogForm.UpdateLog("Creating schematic");
                AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength);
                for (int x = 0; x < intMapLength; x++)
                {
                    for (int z = 0; z < intMapLength; z++)
                    {
                        for (int y = 0; y < 128; y++)
                        {
                            abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z));
                        }
                    }
                }
                Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength);
                CitySchematic.Blocks = abcExport;
                CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic");
            }

            frmLogForm.UpdateLog("\r\nCreated the " + strCityName + "!");
            frmLogForm.UpdateLog("It'll be at the end of your MineCraft world list.");
        }
예제 #21
0
        // todo low: long code is long
        static public void Generate(frmMace frmLogForm, string UserWorldName, string strWorldSeed,
                                    string strWorldType, bool booWorldMapFeatures, int TotalCities, string[] strCheckedThemes,
                                    int ChunksBetweenCities, string strSpawnPoint)
        {
            worldCities = new WorldCity[TotalCities];
            lstCityNames.Clear();

            RandomHelper.SetRandomSeed();

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

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

            if (UserWorldName.ToLower().Trim() != "random")
            {
                if (Directory.Exists(Utils.GetMinecraftSavesDirectory(UserWorldName)))
                {
                    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    = Utils.GetMinecraftSavesDirectory(strWorldName);
                }
            }
            if (strWorldName.Length == 0)
            {
                strWorldName = Utils.GenerateWorldName();
                strFolder    = Utils.GetMinecraftSavesDirectory(strWorldName);
            }
            Directory.CreateDirectory(strFolder);
            frmLogForm.UpdateLog("World name: " + strWorldName, false, true);
            #endregion

            #region get handles to world, chunk manager and block manager
            BetaWorld worldDest = BetaWorld.Create(@strFolder);
            worldDest.Level.LevelName = "Creating. Don't open until Mace is finished.";
            BetaChunkManager 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
            strCheckedThemes = RandomHelper.ShuffleArray(strCheckedThemes);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                if (CurrentCityID <= strCheckedThemes.GetUpperBound(0))
                {
                    worldCities[CurrentCityID].ThemeName = strCheckedThemes[CurrentCityID];
                }
                else
                {
                    worldCities[CurrentCityID].ThemeName = RandomHelper.RandomString(strCheckedThemes);
                }
                Debug.WriteLine(worldCities[CurrentCityID].ThemeName);
                City.ThemeName = worldCities[CurrentCityID].ThemeName;
                worldCities[CurrentCityID].ChunkLength = GetThemeRandomXMLElementNumber("options", "city_size");
            }
            #endregion

            GenerateCityLocations(TotalCities, ChunksBetweenCities);

            int intRandomCity = RandomHelper.Next(TotalCities);

            for (int CurrentCityID = 0; CurrentCityID < TotalCities; CurrentCityID++)
            {
                MakeCitySettings(frmLogForm, worldCities[CurrentCityID].ThemeName, CurrentCityID);
                GenerateCity.Generate(frmLogForm, worldDest, cmDest, bmDest, worldCities[CurrentCityID].x, worldCities[CurrentCityID].z);
                #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 + 30) * 16) + (City.MapLength / 2),
                                                               65,
                                                               ((worldCities[intRandomCity].z + 30) * 16) + (City.MapLength / 2));
                        break;

                    case "Outside a random city":
                        if (City.HasFarms)
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 16) + 20);
                        }
                        else
                        {
                            worldDest.Level.Spawn = new SpawnPoint(((worldCities[intRandomCity].x + 30) * 16) + (City.MapLength / 2),
                                                                   65,
                                                                   ((worldCities[intRandomCity].z + 30) * 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
            }

            City.ID = TotalCities;
            frmLogForm.UpdateProgress(0);

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

#if DEBUG
            MakeHelperChest(bmDest, worldDest.Level.Spawn.X + 2, worldDest.Level.Spawn.Y, worldDest.Level.Spawn.Z + 2);
#endif

            #region lighting
            frmLogForm.UpdateLog("\nCreating world lighting data", false, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            #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.UseHardcoreMode = 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)
            {
                worldDest.Level.RandomSeed = Utils.JavaStringHashCode(strWorldSeed);
                frmLogForm.UpdateLog("Specified world seed: " + worldDest.Level.RandomSeed, false, true);
            }
            else
            {
                worldDest.Level.RandomSeed = RandomHelper.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

            worldDest.Save();
            frmLogForm.UpdateProgress(1);

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

            // todo low: export schematic
            #region export schematic
            //if (booExportSchematic)
            //{
            //    frmLogForm.UpdateLog("Creating schematic");
            //    AlphaBlockCollection abcExport = new AlphaBlockCollection(intMapLength, 128, intMapLength);
            //    for (int x = 0; x < intMapLength; x++)
            //    {
            //        for (int z = 0; z < intMapLength; z++)
            //        {
            //            for (int y = 0; y < 128; y++)
            //            {
            //                abcExport.SetBlock(x, y, z, bmDest.GetBlock(x, y, z));
            //            }
            //        }
            //    }
            //    Schematic CitySchematic = new Schematic(intMapLength, 128, intMapLength);
            //    CitySchematic.Blocks = abcExport;
            //    CitySchematic.Export(Utils.GetMinecraftSavesDirectory(strCityName) + "\\" + strCityName + ".schematic");
            //}
            #endregion
        }
예제 #22
0
        public static void Generate(frmMace frmLogForm, BetaWorld worldDest, BetaChunkManager cmDest, BlockManager bmDest,
                                    int x, int z, bool booExportSchematics, string strUndergroundOres)
        {
            #region create a city name
            string strStart, strEnd;
            do
            {
                strStart  = RNG.RandomFileLine(Path.Combine("Resources", City.CityNamePrefixFilename));
                strEnd    = RNG.RandomFileLine(Path.Combine("Resources", City.CityNameSuffixFilename));
                City.Name = City.CityNamePrefix + strStart + strEnd;
            } while (GenerateWorld.lstCityNames.Contains(City.Name) ||
                     strStart.ToLower().Trim() == strEnd.ToLower().Trim() ||
                     (strStart + strEnd).Length > 14);
            GenerateWorld.lstCityNames.Add(City.Name);
            #endregion

            #region determine block sizes
            City.CityLength *= 16;
            City.FarmLength *= 16;
            City.EdgeLength  = 8;
            City.MapLength   = City.CityLength + (City.EdgeLength * 2);
            #endregion

            #region setup classes
            BlockShapes.SetupClass(bmDest);
            BlockHelper.SetupClass(bmDest);
            NoticeBoard.SetupClass();
            if (!SourceWorld.SetupClass(worldDest))
            {
                return;
            }
            #endregion

            #region determine random options
            switch (City.WallMaterialID)
            {
            case BlockType.WOOD_PLANK:
            case BlockType.WOOD:
            case BlockType.LEAVES:
            case BlockType.VINES:
            case BlockType.WOOL:
            case BlockType.BOOKSHELF:
                switch (City.OutsideLightType)
                {
                case "Fire":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.OutsideLightType = "Torches";
                    break;
                }
                switch (City.MoatType)
                {
                case "Fire":
                case "Lava":
                    frmLogForm.UpdateLog("Fixing fire-spreading combination", true, true);
                    City.MoatType = "Water";
                    break;
                }
                break;
            }
            switch (City.PathType.ToLower().Trim())
            {
            case "stone_raised":
                City.PathBlockID              = BlockInfo.DoubleSlab.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 2;
                break;

            case "sandstone_raised":
                City.PathBlockID              = BlockInfo.Sandstone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 1;
                City.PathExtends              = 2;
                break;

            case "woodplanks_raised":
                City.PathBlockID              = BlockInfo.WoodPlank.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 2;
                City.PathExtends              = 2;
                break;

            case "cobblestone_raised":
                City.PathBlockID              = BlockInfo.Cobblestone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 3;
                City.PathExtends              = 2;
                break;

            case "brick_raised":
                City.PathBlockID              = BlockInfo.BrickBlock.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 4;
                City.PathExtends              = 2;
                break;

            case "stonebrick_raised":
                City.PathBlockID              = BlockInfo.StoneBrick.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = BlockInfo.Slab.ID;
                City.PathAlternativeBlockData = 5;
                City.PathExtends              = 2;
                break;

            case "stonebrick":
                City.PathBlockID              = BlockInfo.StoneBrick.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = 0;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 1;
                break;

            case "sandstone":
                City.PathBlockID              = BlockInfo.Sandstone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = 0;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 1;
                break;

            case "stone":
                City.PathBlockID              = BlockInfo.Stone.ID;
                City.PathBlockData            = 0;
                City.PathAlternativeBlockID   = 0;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 1;
                break;

            case "wood":
                City.PathBlockID              = BlockInfo.Wood.ID;
                City.PathBlockData            = RNG.Next(0, 2);
                City.PathAlternativeBlockID   = 0;
                City.PathAlternativeBlockData = 0;
                City.PathExtends              = 1;
                break;
            }
            #endregion

            #region make the city
            frmLogForm.UpdateLog("Creating the " + City.Name, false, false);
            frmLogForm.UpdateLog("City length in blocks: " + City.MapLength, true, true);
            frmLogForm.UpdateLog("Edge length in blocks: " + City.EdgeLength, true, true);
            frmLogForm.UpdateLog("Farm length in blocks: " + City.FarmLength, true, true);
            frmLogForm.UpdateLog("City position in blocks: " + ((x + Chunks.CITY_RELOCATION_CHUNKS) * 16) + "," +
                                 ((z + Chunks.CITY_RELOCATION_CHUNKS) * 16), true, true);
            frmLogForm.UpdateLog("Theme: " + City.ThemeName, true, true);
            frmLogForm.UpdateLog("Creating underground terrain", true, false);
            Chunks.CreateInitialChunks(cmDest, frmLogForm, strUndergroundOres);
            frmLogForm.UpdateProgress(0.21);

            Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint();

            if (City.HasWalls)
            {
                frmLogForm.UpdateLog("Creating walls", true, false);
                Walls.MakeWalls(worldDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.24);

            if (City.HasDrawbridges)
            {
                frmLogForm.UpdateLog("Creating entrances", true, false);
                Entrances.MakeEntrances(bmDest);
            }
            frmLogForm.UpdateProgress(0.27);

            if (City.HasMoat)
            {
                frmLogForm.UpdateLog("Creating moat", true, false);
                Moat.MakeMoat(frmLogForm, bmDest);
            }
            frmLogForm.UpdateProgress(0.30);

            if (City.HasBuildings || City.HasPaths)
            {
                frmLogForm.UpdateLog("Creating paths", true, false);
                frmLogForm.UpdateLog("Path type: " + City.PathType, true, true);
                int[,] intArea = Paths.MakePaths(worldDest, bmDest);
                frmLogForm.UpdateProgress(0.33);
                if (City.HasBuildings)
                {
                    frmLogForm.UpdateLog("Creating buildings", true, false);
                    spMineshaftEntrance = Buildings.MakeInsideCity(bmDest, worldDest, intArea, frmLogForm);
                    frmLogForm.UpdateProgress(0.36);
                    if (City.HasMineshaft)
                    {
                        frmLogForm.UpdateLog("Creating mineshaft", true, false);
                        Mineshaft.MakeMineshaft(worldDest, bmDest, spMineshaftEntrance, frmLogForm);
                    }
                }
            }
            frmLogForm.UpdateProgress(0.39);

            if (City.HasGuardTowers)
            {
                frmLogForm.UpdateLog("Creating guard towers", true, false);
                GuardTowers.MakeGuardTowers(bmDest, frmLogForm);
            }
            frmLogForm.UpdateProgress(0.42);

            if (City.HasFarms)
            {
                frmLogForm.UpdateLog("Creating farms", true, false);
                Farms2.MakeFarms(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.45);

            if (City.HasFlowers)
            {
                frmLogForm.UpdateLog("Creating flowers", true, false);
                Flowers.MakeFlowers(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.46);

            if (!City.HasValuableBlocks)
            {
                frmLogForm.UpdateLog("Replacing valuable blocks", true, true);
                cmDest.Save();
                worldDest.Save();
                Chunks.ReplaceValuableBlocks(worldDest, bmDest);
            }
            frmLogForm.UpdateProgress(0.48);

            frmLogForm.UpdateLog("Creating rail data", true, false);
            Chunks.PositionRails(worldDest, bmDest);
            frmLogForm.UpdateProgress(0.50);

            frmLogForm.UpdateLog("Creating lighting data", true, false);
            Chunks.ResetLighting(worldDest, cmDest, frmLogForm);
            frmLogForm.UpdateProgress(0.95);
            #endregion

            #region export schematic
            if (booExportSchematics)
            {
                frmLogForm.UpdateLog("Creating schematic in world folder", true, false);
                AlphaBlockCollection abcExport = new AlphaBlockCollection(City.MapLength, 128, City.MapLength + City.FarmLength);
                for (int xBlock = 0; xBlock < City.MapLength; xBlock++)
                {
                    for (int zBlock = -City.FarmLength; zBlock < City.MapLength; zBlock++)
                    {
                        for (int y = 0; y < 128; y++)
                        {
                            abcExport.SetBlock(xBlock, y, City.FarmLength + zBlock, bmDest.GetBlock(xBlock, y, zBlock));
                        }
                    }
                }
                Schematic CitySchematic = new Schematic(City.MapLength, 128, City.MapLength + City.FarmLength);
                CitySchematic.Blocks = abcExport;
                CitySchematic.Export(worldDest.Path + "\\" + City.Name + ".schematic");
            }
            #endregion

            #region positioning
            frmLogForm.UpdateLog("Creating position data", true, false);
            Chunks.MoveChunks(worldDest, cmDest, x, z);
            frmLogForm.UpdateProgress(1);
            #endregion
        }
예제 #23
0
 public static bool SetupClass(BetaWorld worldDest, bool booIncludeItemsInChestsOriginal, bool booIncludeGhostdancerSpawners)
 {
     _AllEntityPainting = new EntityPainting[0];
     _AllBuildings = new Building[0];
     _intHouseNumber = 0;
     BetaWorld worldSource = BetaWorld.Open(Path.Combine("Resources", "Mace"));
     _bmSource = worldSource.GetBlockManager();
     _cmSource = worldSource.GetChunkManager();
     _cmDest = worldDest.GetChunkManager();
     _lstCitySigns.Clear();
     _lstInstanceSigns.Clear();
     _booIncludeItemsInChests = booIncludeItemsInChestsOriginal;
     _booIncludeGhostdancerSpawners = booIncludeGhostdancerSpawners;
     return ReadBuildings();
 }
예제 #24
0
 public static void ResetLighting(BetaWorld world, BetaChunkManager cm, frmMace frmLogForm, int intTotalChunks)
 {
     int intChunksProcessed = 0;
     // we process each chunk twice, hence this:
     intTotalChunks *= 2;
     //this code is based on a substrate example
     //http://code.google.com/p/substrate-minecraft/source/browse/trunk/Substrate/SubstrateCS/Examples/Relight/Program.cs
     //see the <License Substrate.txt> file for copyright information
     foreach (ChunkRef chunk in cm)
     {
         try
         {
             chunk.Blocks.RebuildHeightMap();
             chunk.Blocks.ResetBlockLight();
             chunk.Blocks.ResetSkyLight();
         }
         catch (Exception)
         {
             Debug.WriteLine("Chunk reset light fail");
         }
         if (++intChunksProcessed % 10 == 0)
         {
             cm.Save();
             frmLogForm.UpdateProgress(62 + ((intChunksProcessed * (100 - 62)) / intTotalChunks));
         }
     }
     foreach (ChunkRef chunk in cm)
     {
         try
         {
             chunk.Blocks.RebuildBlockLight();
             chunk.Blocks.RebuildSkyLight();
         }
         catch (Exception)
         {
             Debug.WriteLine("Chunk rebuild light fail");
         }
         if (++intChunksProcessed % 10 == 0)
         {
             cm.Save();
             frmLogForm.UpdateProgress(62 + ((intChunksProcessed * (100 - 62)) / intTotalChunks));
         }
     }
     world.Save();
 }