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"); } }
// ** Initialization and control public void Configure(RenderConfiguration Configuration) { _Config = Configuration; _ColourPalette = _Config.Palette; _Metrics = _Config.Metrics; _Chunks = Configuration.Chunks; if (_Config.AdvancedRenderOptions.Exists(x => x.Key.ToLower() == "mode")) { switch (_Config.AdvancedRenderOptions.Find(x => x.Key.ToLower() == "mode").Value) { case "c": _RenderStartY = GetStartRenderYCave; break; case "C": _RenderStartY = GetStartRenderYCaveAlternate; break; default: _RenderStartY = GetStartRenderYNormal; break; } } else { _RenderStartY = GetStartRenderYNormal; } }
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(); }
public static void CreateInitialChunks(RegionChunkManager 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(); }
public static void MoveChunks(AnvilWorld world, RegionChunkManager 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; biomes.Add(chunkActive.X + "." + chunkActive.Z, City.biome); cm.DeleteChunk(x, z); cm.Save(); world.Save(); } } }
public static void ResetLighting(AnvilWorld world, RegionChunkManager cm, frmMace frmLogForm) { int intChunksProcessed = 0, 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) { if (chunk.IsTerrainPopulated) { if (chunk.X * 16 >= 0 && chunk.X * 16 <= City.mapLength && chunk.Z * 16 >= -City.farmLength && chunk.Z * 16 <= City.mapLength) { // we process each chunk twice, hence this: intTotalChunks += 2; } } } foreach (ChunkRef chunk in cm) { if (chunk.IsTerrainPopulated) { if (chunk.X * 16 >= 0 && chunk.X * 16 <= City.mapLength && chunk.Z * 16 >= -City.farmLength && chunk.Z * 16 <= City.mapLength) { 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(0.5 + (intChunksProcessed * 0.45 / intTotalChunks)); } } } } foreach (ChunkRef chunk in cm) { if (chunk.IsTerrainPopulated) { if (chunk.X * 16 >= 0 && chunk.X * 16 <= City.mapLength && chunk.Z * 16 >= -City.farmLength && chunk.Z * 16 <= City.mapLength) { try { chunk.Blocks.RebuildBlockLight(); chunk.Blocks.RebuildSkyLight(); } catch (Exception) { Debug.WriteLine("Chunk rebuild light fail"); } if (++intChunksProcessed % 10 == 0) { cm.Save(); frmLogForm.UpdateProgress(0.5 + (intChunksProcessed * 0.45 / intTotalChunks)); } } } } world.Save(); }
static void FasterProcessChunk(RegionChunkManager rcm, int dimnumber, Dictionary<string,string> ReplaceList) { int currentchunk = 0; int chunktotal = 0; Stack<string> _TEList = new Stack<string>(); foreach (ChunkRef chunk in rcm) { chunktotal++; } foreach (ChunkRef chunk in rcm) { Stopwatch sw = new Stopwatch(); sw.Start(); currentchunk++; char[] metadata = {':'}; string blockOutput = ""; string tileOutput = ""; // 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; // 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++) { int currentID = chunk.Blocks.GetID(x,y,z); int currentData = chunk.Blocks.GetData(x,y,z); TileEntity TE = chunk.Blocks.GetTileEntity(x, y, z); TileEntityCleaner TC = new TileEntityCleaner(); if (TE != null) { if (TC.getDeleteList().Contains(TE.ID)) { chunk.Blocks.ClearTileEntity(x,y,z); Console.WriteLine("Tile Entity {0} found, cleared at {1},{2},{3}", TE.ID, x, y, z); } //if (TE != null) // Console.WriteLine(TE.ID.ToString()); //_TEList.Push(TE.ID); if (TE.ID == "factory_barrel") { Console.WriteLine("breakpoint"); FactoryBarrel barrel = new FactoryBarrel(TE) as FactoryBarrel; //Console.WriteLine(test.Item.ID.ToString()); //Console.ReadLine(); if (barrel.Item != null) { string _tmpBarrelItem = barrel.Item.ID.ToString() + ":" + barrel.Item.Damage.ToString(); if (ReplaceList.TryGetValue(_tmpBarrelItem,out tileOutput)) { string[] _strKey = tileOutput.Split(metadata); barrel.Item.ID = Convert.ToInt32(_strKey.GetValue(0)); barrel.Item.Damage = Convert.ToInt32(_strKey.GetValue(1)); chunk.Blocks.SetTileEntity(x,y,z,barrel); } } } if (IronChest.ChestTypes.Contains(TE.ID)) { //IronChest.ChestList.Push(TE); var temp = IronChest.getChestType(TE); for (int i = 0; i <= temp.Items.Capacity; i++) { Item item = temp.Items[i]; if (item != null) { string _tmpChestItem = item.ID.ToString() + ":" + item.Damage.ToString(); //Console.WriteLine(_tmpChestItem); if (ReplaceList.TryGetValue(_tmpChestItem,out tileOutput)) { string[] _strKey = tileOutput.Split(metadata); temp.Items[i].ID = Convert.ToInt32(_strKey.GetValue(0)); temp.Items[i].Damage = Convert.ToInt32(_strKey.GetValue(1)); } } } switch (currentData) { case 0: IronChest.SetTileEntity("IRON"); break; case 1: IronChest.SetTileEntity("GOLD"); break; case 2: IronChest.SetTileEntity("DIAMOND"); break; case 3: IronChest.SetTileEntity("COPPER"); break; case 4: IronChest.SetTileEntity("SILVER"); break; case 5: IronChest.SetTileEntity("CRYSTAL"); break; default: IronChest.SetTileEntity("IRON"); break; } chunk.Blocks.SetTileEntity(x,y,z,temp); } if (TE.ID == "Chest") { TileEntityChest temp = new TileEntityChest(TE); for (int i = 0; i <= temp.Items.Capacity; i++) { Item item = temp.Items[i]; if (item != null) { string _tmpChestItem = item.ID.ToString() + ":" + item.Damage.ToString(); //Console.WriteLine(_tmpChestItem); if (ReplaceList.TryGetValue(_tmpChestItem,out tileOutput)) { string[] _strKey = tileOutput.Split(metadata); temp.Items[i].ID = Convert.ToInt32(_strKey.GetValue(0)); temp.Items[i].Damage = Convert.ToInt32(_strKey.GetValue(1)); } } } chunk.Blocks.SetTileEntity(x,y,z, temp); } } string currentBlock = currentID.ToString() + ":" + currentData.ToString(); if (currentBlock == "750") { if (currentData >= 4096) { string _temp = currentBlock + ":" + currentData.ToString(); _TEList.Push(_temp); } } if (ReplaceList.TryGetValue(currentBlock, out blockOutput)) { string[] _strKey = blockOutput.Split(metadata); chunk.Blocks.SetID(x,y,z,(Convert.ToInt32(_strKey.GetValue(0)))); chunk.Blocks.SetData(x,y,z,(Convert.ToInt32(_strKey.GetValue(1)))); // Console.WriteLine("Block changed from ID {0}:{1} to {2}:{3} at {4},{5},{6}", // currentID, // currentData, // _strKey.GetValue(0), // _strKey.GetValue(1), // x, y, z); } } } } //ProcessModBlocks(); // Save the chunk rcm.Save(); sw.Stop(); switch (dimnumber) { case Dimension.DEFAULT: Console.WriteLine("Processed Chunk {0},{1}\t\t({2} of {3} in Overworld (DIM{4})", chunk.X, chunk.Z, currentchunk, chunktotal, Dimension.DEFAULT); break; case Dimension.NETHER: Console.WriteLine("Processed Chunk {0},{1}\t\t({2} of {3} in Nether (DIM{4})", chunk.X, chunk.Z, currentchunk, chunktotal, Dimension.NETHER); break; case Dimension.THE_END: Console.WriteLine("Processed Chunk {0},{1}\t\t({2} of {3} in The End (DIM{4})", chunk.X, chunk.Z, currentchunk, chunktotal, Dimension.THE_END); break; default: Console.WriteLine("Processed Chunk {0},{1}\t\t({2} of {3} in Mystcraft Age {4}) in {5}.{6}", chunk.X, chunk.Z, currentchunk, chunktotal, dimnumber, sw.Elapsed.Seconds.ToString(),sw.Elapsed.Milliseconds.ToString()); break; } //Console.WriteLine(sw.ElapsedMilliseconds.ToString()); //Console.ReadLine(); } switch (dimnumber) { case Dimension.DEFAULT: Console.WriteLine("Overworld (DIM{0}) completed.",Dimension.DEFAULT); break; case Dimension.NETHER: Console.WriteLine("Nether (DIM{0}) completed.",Dimension.DEFAULT); break; case Dimension.THE_END: Console.WriteLine("The End (DIM{0}) completed.",Dimension.THE_END); break; default: Console.WriteLine("Mystcraft Age {0} (DIM{0}) completed.", dimnumber); break; } foreach (string s in _TEList) { Console.WriteLine(s); } }
public int[] FindFreeLight(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z) { int[] position = { -9999, -9999, -9999, -999, -999 }; int cx = chunk.X; int cz = chunk.Z; int xdim = chunk.Blocks.XDim; int zdim = chunk.Blocks.ZDim; int xt = x; int zt = z; int chance = rand.Next(4); if (chance == 0) xt = x + 1; else if (chance == 1) xt = x - 1; else if (chance == 2) zt = z + 1; else zt = z - 1; int xtt = xt; int ztt = zt; int cxt = cx; int czt = cz; for (int a = 0; a <= 4; a++) { xt = x; zt = z; cxt = cx; czt = cz; if (a == 4) { y--; } else if ((xtt == x + 1) && (ztt == z)) { xt = x; zt = z + 1; } else if ((xtt == x) && (ztt == z + 1)) { xt = x - 1; zt = z; } else if ((xtt == x - 1) && (ztt == z)) { xt = x; zt = z - 1; } else if ((xtt == x) && (ztt == z - 1)) { xt = x + 1; zt = z; } xtt = xt; ztt = zt; // Jump into neighboring chunks if needed if (xt < 0) { cxt--; xt = xt + xdim; } else if (xt >= xdim) { cxt++; xt = xt - xdim; } if (zt < 0) { czt--; zt = zt + zdim; } else if (zt >= zdim) { czt++; zt = zt - zdim; } ChunkRef tchunk = chunkMan.GetChunkRef(cxt, czt); if (tchunk == null) { continue; } int resBlock = tchunk.Blocks.GetID(xt, y, zt); if (resBlock == 0 || smashBlock.Contains(resBlock)) { position[0] = xt; position[1] = zt; position[2] = y; position[3] = cxt; position[4] = czt; break; } } return position; }
// Function for cleaning clutter left by AgeChunk public void CleanChunk(ChunkRef chunk, RegionChunkManager chunkMan, Bitmap perlinMask, int perlinResolution, int[] minXZ) { int xdim = chunk.Blocks.XDim; int ydim = chunk.Blocks.YDim; int zdim = chunk.Blocks.ZDim; int checkx = 0; int checky = 0; int checkz = 0; int oldBlock; float natureKillChanceMin = (float)natureKillChance[0] / 100f; float natureKillChanceMax = (float)natureKillChance[1] / 100f - natureKillChanceMin; // Check all blocks in the chunk for (int x = 0; x < xdim; x++) { for (int z = 0; z < zdim; z++) { int px = Math.Abs(minXZ[0]) + (chunk.X * 16) + (x / perlinResolution); int py = Math.Abs(minXZ[1]) + (chunk.Z * 16) + (z / perlinResolution); px = Math.Min(Math.Max(px, 0), perlinMask.Width - 1); py = Math.Min(Math.Max(py, 0), perlinMask.Height - 1); Color perlinCol = perlinMask.GetPixel(px, py); double perlinMulti = (double)perlinCol.R / 255f; bool eroded = false; bool foundLeaves = false; for (int y = ydim - 2; y > 1; y--) { checkx = x; checky = y; checkz = z; // Attempt to replace block oldBlock = chunk.Blocks.GetID(x, y, z); int oldData = chunk.Blocks.GetData(x, y, z); // Destroy old trees if (natureRepopulation) { if (oldBlock == 18) { foundLeaves = true; } if (foundLeaves && oldBlock == 17) { chunk.Blocks.SetID(x, y, z, 0); } } if (oldBlock != 0 && !eroded && natureKillBlock.Length != 0) { foreach (int i in natureKillBlock) { if (oldBlock == i) { double c = rand.NextDouble(); if (c < natureKillChanceMin + (natureKillChanceMax * perlinMulti)) { chunk.Blocks.SetID(x, y, z, natureKillTo); } eroded = true; break; } } } // Check signs, ladders if (oldBlock == 65 || oldBlock == 68) { if (oldData == 2) { checkz = z + 1; } else if (oldData == 3) { checkz = z - 1; } else if (oldData == 4) { checkx = x + 1; } else if (oldData == 5) { checkx = x - 1; } int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); continue; } } // Check buttons if (oldBlock == 77) { if (oldData == 1) { checkx = x - 1; } else if (oldData == 2) { checkx = x + 1; } else if (oldData == 3) { checkz = z - 1; } else if (oldData == 4) { checkz = z + 1; } int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); continue; } } // Check torches and levers if (oldBlock == 50 || oldBlock == 69 || oldBlock == 75 || oldBlock == 76) { if (oldData == 1) { checkx = x - 1; } else if (oldData == 2) { checkx = x + 1; } else if (oldData == 3) { checkz = z - 1; } else if (oldData == 4) { checkz = z + 1; } else if (oldData == 5 || oldData == 6) { checky = y - 1; } int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); continue; } } // Check trapdoors if (oldBlock == 96) { if (oldData == 0) { checkz = z + 1; } else if (oldData == 1) { checkz = z - 1; } else if (oldData == 2) { checkx = x + 1; } else if (oldData == 3) { checkx = x - 1; } int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); continue; } } // Check doors if (oldBlock == 64 || oldBlock == 71) { int tchecky = y; if (oldData >= 8) { tchecky = y - 1; checky = y - 2; int airCheck = CheckAir(chunk, chunkMan, checkx, tchecky, checkz); if (airCheck != 64 && airCheck != 71) { chunk.Blocks.SetID(x, y, z, 0); continue; } airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); chunk.Blocks.SetID(x, y - 1, z, 0); continue; } } else { tchecky = y + 1; checky = y - 1; int airCheck = CheckAir(chunk, chunkMan, checkx, tchecky, checkz); if (airCheck != 64 && airCheck != 71) { chunk.Blocks.SetID(x, y, z, 0); continue; } airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); continue; } } } // Check the rest of supported blocks foreach (int i in supportedBlocks) { if (oldBlock == i) { checky = y - 1; int airCheck = CheckAir(chunk, chunkMan, checkx, checky, checkz); if (airCheck == 0) { chunk.Blocks.SetID(x, y, z, 0); } } } } } } }
public int[] FindFreeAir(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z) { int cx = chunk.X; int cz = chunk.Z; int[] position = { -9999, -9999, cx, cz }; int xdim = chunk.Blocks.XDim; int zdim = chunk.Blocks.ZDim; int xt; int zt; int cxt; int czt; for (int a = 0; a <= 8; a++) { xt = x + (-fallSpread + rand.Next(((1 + fallSpread) * 2))); zt = z + (-fallSpread + rand.Next(((1 + fallSpread) * 2))); cxt = cx; czt = cz; // Jump into neighboring chunks if needed if (xt < 0) { cxt--; xt = xt + xdim; } else if (xt >= xdim) { cxt++; xt = xt - xdim; } if (zt < 0) { czt--; zt = zt + zdim; } else if (zt >= zdim) { czt++; zt = zt - zdim; } ChunkRef tchunk = chunkMan.GetChunkRef(cxt, czt); if (tchunk == null) continue; int resBlock = tchunk.Blocks.GetID(xt, y, zt); if (resBlock == 0 || smashBlock.Contains(resBlock)) { position[0] = xt; position[1] = zt; position[2] = cxt; position[3] = czt; break; } } return position; }
public int CheckAir(ChunkRef chunk, RegionChunkManager chunkMan, int x, int y, int z) { int cx = chunk.X; int cz = chunk.Z; int xdim = chunk.Blocks.XDim; int zdim = chunk.Blocks.ZDim; int result = 0; if (x < 0) { cx--; x = x + xdim; } else if (x >= xdim) { cx++; x = x - xdim; } if (z < 0) { cz--; z = z + zdim; } else if (z >= zdim) { cz++; z = z - zdim; } ChunkRef tchunk = chunkMan.GetChunkRef(cx, cz); if (tchunk != null) { int resBlock = tchunk.Blocks.GetID(x, y, z); if (resBlock != 0) { result = resBlock; } } return result; }
// Function for falling and toppling blocks public void AgeChunk(ChunkRef chunk, RegionChunkManager chunkMan, Bitmap perlinMask, int perlinResolution, int[] minXZ) { int xdim = chunk.Blocks.XDim; int ydim = chunk.Blocks.YDim; int zdim = chunk.Blocks.ZDim; double c = 0; int xp; int yp; int zp; float fallChanceMin = (float)fallChance[0] / 100f; // Some lazy coding on my side float fallChanceMax = (float)fallChance[1] / 100f - fallChanceMin; float fallKillChanceMin = (float)fallKillChance[0] / 100f; float fallKillChanceMax = (float)fallKillChance[1] / 100f - fallKillChanceMin; float sidewaysFallChanceMin = (float)sidewaysFallChance[0] / 100f; float sidewaysFallChanceMax = (float)sidewaysFallChance[1] / 100f - sidewaysFallChanceMin; float stoneFallChanceMin = (float)stoneFallChance[0] / 100f; float stoneFallChanceMax = (float)stoneFallChance[1] / 100f - stoneFallChanceMin; float stoneFallKillChanceMin = (float)stoneFallKillChance[0] / 100f; float stoneFallKillChanceMax = (float)stoneFallKillChance[1] / 100f - stoneFallKillChanceMin; float stoneSidewaysFallChanceMin = (float)stoneSidewaysFallChance[0] / 100f; float stoneSidewaysFallChanceMax = (float)stoneSidewaysFallChance[1] / 100f - stoneSidewaysFallChanceMin; int[] airPos = { -9999, -9999, -999, -999 }; for (int pass = 1; pass <= passN; pass++) { // Check all blocks in the chunk for (int x = 0; x < xdim; x++) { for (int z = 0; z < zdim; z++) { if (chunk.Blocks.GetHeight(x, z) > 0 && chunk.Blocks.GetHeight(x, z) < 256) { // Reset the algorithm limiter int bottomY = ydim - 2; // Get the perlin mask multiplier int px = Math.Abs(minXZ[0] / perlinResolution) + (chunk.X * 16 / perlinResolution) + (x / perlinResolution); int py = Math.Abs(minXZ[1] / perlinResolution) + (chunk.Z * 16 / perlinResolution) + (z / perlinResolution); px = Math.Min(Math.Max(px, 0), perlinMask.Width - 1); py = Math.Min(Math.Max(py, 0), perlinMask.Height - 1); Color perlinCol = perlinMask.GetPixel(px, py); double perlinMulti = (double)perlinCol.R / 255f; int oldBlock; if (stoneAdvanced && pass <= stonePassN) // Stone displacement - advanced method { for (int y = chunk.Blocks.GetHeight(x, z); y > 1; y--) { bottomY = y; // Get the checked block's ID oldBlock = chunk.Blocks.GetID(x, y, z); if (oldBlock == 2 || oldBlock == 3 || oldBlock == 12 || oldBlock == 13) // Stop if encountered grass or dirt, should stop random underground space break; if (oldBlock == 1) { airPos = FindFreeLight(chunk, chunkMan, x, y, z); // Set the most bottom stone to be eroded, stop on grass if (((airPos[0] == -9999) && (airPos[1] == -9999))) { break; } } } for (int y = bottomY; y < ydim - 2; y++) { // Don't even try if out of limits if (y >= ydim - 2 || y <= 1) { continue; } // Get the checked block's ID oldBlock = chunk.Blocks.GetID(x, y, z); // Probability test c = rand.NextDouble(); if (c < stoneFallChanceMin + (stoneFallChanceMax * perlinMulti)) { if (oldBlock == 1) { // Random chance to destroy the block in fall c = rand.NextDouble(); if ((c < fallKillChanceMin + (fallKillChanceMax * perlinMulti)) && pass == 1) { // Kill the initial block chunk.Blocks.SetID(x, y, z, 0); continue; } airPos = FindFreeAir(chunk, chunkMan, x, y, z); // Skip to another column if we don't see light anymore if ((airPos[0] == -9999) && (airPos[1] == -9999)) { continue; } int xf = x; int zf = z; ChunkRef tchunk = chunk; // Random chance to topple c = rand.NextDouble(); if ((c < sidewaysFallChanceMin + (sidewaysFallChanceMax * perlinMulti)) && pass == 1) { xf = airPos[0]; zf = airPos[1]; if (((airPos[2] != chunk.X) || (airPos[3] != chunk.Z)) && ((airPos[2] != -999) && (airPos[3] != -999))) { tchunk = chunkMan.GetChunkRef(airPos[2], airPos[3]); } } // Kill the initial block chunk.Blocks.SetID(x, y, z, 0); for (int yf = y; yf > 1; yf--) { // Incoming! int destBlock = tchunk.Blocks.GetID(xf, yf - 1, zf); if (destBlock == 0 || fallThroughBlock.Contains(destBlock)) { continue; } // Smash weak blocks in the way if (smashBlock.Contains(destBlock)) { tchunk.Blocks.SetID(xf, yf - 1, zf, 0); continue; } tchunk.Blocks.SetID(xf, yf, zf, 1); break; } } } } } else // Stone displacement - simple method { for (int y = chunk.Blocks.GetHeight(x, z); y > 1; y--) { // Don't even try if out of limits if (y >= ydim - 2 || y <= 1) { continue; } // Get the checked block's ID oldBlock = chunk.Blocks.GetID(x, y, z); if (oldBlock == 2 || oldBlock == 3) // Stop if encountered grass or dirt, should stop random underground space break; if (oldBlock == 1) { // Probability test c = rand.NextDouble(); if (c < stoneFallChanceMin + (stoneFallChanceMax * perlinMulti)) { // Random chance to destroy the block in fall c = rand.NextDouble(); if ((c < stoneFallKillChanceMin + (stoneFallKillChanceMax * perlinMulti)) && pass == 1) { // Kill the initial block chunk.Blocks.SetID(x, y, z, 0); continue; } airPos = FindFreeLight(chunk, chunkMan, x, y, z); // Skip to another column if we don't see light anymore if ((airPos[0] == -9999) && (airPos[1] == -9999)) { break; } int xf = x; int yf = y; int zf = z; ChunkRef tchunk = chunk; // Random chance to topple c = rand.NextDouble(); if ((c < stoneSidewaysFallChanceMin + (stoneSidewaysFallChanceMin * perlinMulti)) && pass == 1) { xf = airPos[0]; zf = airPos[1]; yf = airPos[2]; if (((airPos[3] != chunk.X) || (airPos[4] != chunk.Z)) && ((airPos[3] != -999) && (airPos[4] != -999))) { tchunk = chunkMan.GetChunkRef(airPos[3], airPos[4]); } } // Kill the initial block chunk.Blocks.SetID(x, y, z, 0); for (yf = y; yf > 1; yf--) { // Incoming! int destBlock = tchunk.Blocks.GetID(xf, yf - 1, zf); if (destBlock == 0 || fallThroughBlock.Contains(destBlock)) { continue; } // Smash weak blocks in the way if (smashBlock.Contains(destBlock)) { tchunk.Blocks.SetID(xf, yf - 1, zf, 0); continue; } tchunk.Blocks.SetID(xf, yf, zf, 1); break; } } } } } for (int y = 1; y < ydim - 2; y++) // Manmade blocks displacement { // Get the checked block's ID oldBlock = chunk.Blocks.GetID(x, y, z); xp = x; yp = y; zp = z; // Try to look if (pass == 1) { // Loop through all entries in the mutateBlock array for (int i = 0; i < mutateBlock.GetUpperBound(0); i++) { if (oldBlock == 0) { break; } // If the checked block is not the what we want, jump to the next mutateBlock entry if (oldBlock != mutateBlock[i, 0]) { continue; } // Have a random chance of letting the block live float pMin = (mutateBlock[i, 2]) / 100f; float pMax = (mutateBlock[i, 3]) / 100f; c = rand.NextDouble(); if (c > pMin + (pMax * perlinMulti)) { break; } chunk.Blocks.SetID(x, y, z, mutateBlock[i, 1]); oldBlock = mutateBlock[i, 1]; break; } } foreach (int i in fallBlock) { if (oldBlock == i) { // Probability test c = rand.NextDouble(); if (c < fallChanceMin + (fallChanceMax * perlinMulti)) { int xtemp = x; int ztemp = z; // Random chance to destroy the block in fall c = rand.NextDouble(); if ((c < fallKillChanceMin + (fallKillChanceMin * perlinMulti)) && pass == 1) { chunk.Blocks.SetID(x, y, z, 0); break; } ChunkRef tchunk = chunk; // If we push blocks sideways if (pass <= sidewaysPassN) { // Look if the block has empty space below it int supportBlock = chunk.Blocks.GetID(x, y - 1, z); if (supportBlock != 0) { c = rand.NextDouble(); if (c < sidewaysFallChanceMin + (sidewaysFallChanceMin * perlinMulti)) { //Try to move the block sideways airPos = FindFreeAir(chunk, chunkMan, x, y, z); if ((airPos[0] == -9999) && (airPos[1] == -9999)) { break; } xtemp = airPos[0]; ztemp = airPos[1]; if (((airPos[2] != chunk.X) || (airPos[3] != chunk.Z)) && ((airPos[2] != -999) && (airPos[3] != -999))) { tchunk = chunkMan.GetChunkRef(airPos[2], airPos[3]); } } else { break; } } } int fallData = chunk.Blocks.GetData(x, y, z); TileEntity fallTE = chunk.Blocks.GetTileEntity(x, y, z); chunk.Blocks.SetID(x, y, z, 0); tchunk.Blocks.ClearTileEntity(x, y, z); for (int yf = y; yf > 1; yf--) { // It's raining blocks, halelujah, it's raining blocks... int destBlock = tchunk.Blocks.GetID(xtemp, yf - 1, ztemp); if (destBlock == 0 || fallThroughBlock.Contains(destBlock)) { continue; } // Smash weak blocks in the way if (smashBlock.Contains(destBlock)) { tchunk.Blocks.SetID(xtemp, yf - 1, ztemp, 0); tchunk.Blocks.ClearTileEntity(xtemp, yf - 1, ztemp); continue; } tchunk.Blocks.SetID(xtemp, yf, ztemp, i); tchunk.Blocks.SetData(xtemp, yf, ztemp, fallData); if (fallTE != null && fallTE.ID != "Sign" && AcceptsTileEntities(i)) { tchunk.Blocks.SetTileEntity(xtemp, yf, ztemp, fallTE); } xp = xtemp; yp = yf; zp = ztemp; break; } } } } } } } } } }
public static void SetupClass(BlockManager bmDest, RegionChunkManager cmDest) { _bmDest = bmDest; _cmDest = cmDest; }
public void Process(RegionChunkManager Chunks, WorldMetrics Metrics, String Filename) { // *** Accumulate list of sign types _SignMap = CreateSignMap(); int NumLen = Metrics.NumberOfChunks.ToString().Length; int NumCount = Metrics.NumberOfChunks; string NumFormat = "D" + NumLen; int ProcessedChunks = 0; Console.Write("Scanned " + 0.ToString(NumFormat) + " of " + Metrics.NumberOfChunks.ToString() + " chunks (0%)"); Point ProcessedCountPoint = new Point(8, Console.CursorTop); Point PercentageUpdatePoint = new Point(Console.CursorLeft - 3, Console.CursorTop); // *** Find all signs in the world and scan foreach (ChunkRef Chunk in Chunks) { ProcessedChunks++; Console.SetCursorPosition(ProcessedCountPoint.X, ProcessedCountPoint.Y); Console.Write(ProcessedChunks.ToString(NumFormat)); Console.SetCursorPosition(PercentageUpdatePoint.X, PercentageUpdatePoint.Y); Console.Write(((100 * ProcessedChunks) / NumCount).ToString() + "%)"); ProcessChunk(Chunk); } Console.WriteLine(""); Console.WriteLine("Scan completed. Saving sign data..."); XmlWriter Writer = XmlWriter.Create(Filename); Writer.WriteStartElement("Signs"); // *** Curly braces used to ensure that start and end element counts are matched. foreach (SignBase Sign in _ExportableSigns) { Writer.WriteStartElement("Sign"); { Writer.WriteAttributeString("Type", Sign.SignType()); Writer.WriteStartElement("Location"); { Writer.WriteElementString("X", Sign.Location.X.ToString()); Writer.WriteElementString("Y", Sign.Location.Y.ToString()); } Writer.WriteEndElement(); List <KeyValuePair <String, String> > Params = new List <KeyValuePair <string, string> >(); Sign.ExportParameters(Params); foreach (KeyValuePair <String, String> Param in Params) { Writer.WriteStartElement(Param.Key); { Writer.WriteString(Param.Value); } Writer.WriteEndElement(); } } Writer.WriteEndElement(); } Writer.WriteEndElement(); Writer.Flush(); Writer.Close(); Console.WriteLine("Wrote sign data to file " + Path.GetFileName(Filename)); }
private void btnLoad_Click(object sender, EventArgs e) { if(folderBrowser.ShowDialog() == DialogResult.OK) { selectedWorldPath = folderBrowser.SelectedPath; aDisplayReady = false; string worldPath = selectedWorldPath; aSelectedChunks.Clear(); zoomLabel.Text = "1"; NbtWorld world = NbtWorld.Open(worldPath); string worldName = world.Level.LevelName; RegionChunkManager chunkMan = (RegionChunkManager)world.GetChunkManager(0); aWorld = world; aChunkMan = chunkMan; Bitmap map = GenerateMap(world, chunkMan); mapBox.Image = map; mapBox.Width = map.Width; mapBox.Height = map.Height; handleGraphics(); /*string MapDirPath = System.IO.Directory.GetCurrentDirectory() + @"\MapData\"; if (!Directory.Exists(MapDirPath)) { Directory.CreateDirectory(MapDirPath); } map.Save(MapDirPath + worldName + ".png");*/ aDisplayReady = true; } }
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(_prefCacheSize); BetaRegionManager rm = new BetaRegionManager(path, cc); RegionChunkManager cm = new RegionChunkManager(rm, cc); BlockManager bm = new BlockManager(cm); _regionMgrs[dim] = rm; _chunkMgrs[dim] = cm; _blockMgrs[dim] = bm; _caches[dim] = cc; }
public Bitmap GenerateMap(NbtWorld world, RegionChunkManager chunkMan) { int[,] colors = { { 0, 255, 0, 255 }, { 1, 128, 128, 128 }, { 2, 64, 192, 64 }, { 3, 128, 48, 0 }, { 4, 64, 64, 64 }, { 5, 255, 128, 64 }, { 6, 0, 192, 0 }, { 7, 32, 32, 32 }, { 8, 16, 16, 128 }, { 9, 16, 16, 128 }, { 10, 255, 0, 0 }, { 11, 255, 0, 0 }, { 12, 255, 255, 192 }, { 13, 156, 128, 128 }, { 14, 192, 192, 128 }, { 15, 192, 128, 96 }, { 16, 48, 48, 32 }, { 17, 192, 96, 48 }, { 18, 0, 128, 0 }, { 19, 255, 255, 0 }, { 20, 224, 224, 224 }, { 21, 128, 128, 192 }, { 22, 64, 64, 255 }, { 23, 64, 64, 64 }, { 24, 128, 128, 96 }, { 25, 192, 96, 48 }, { 26, 255, 128, 128 }, { 27, 224, 128, 128 }, { 28, 224, 128, 128 }, { 29, 128, 192, 48 }, { 30, 224, 224, 224 }, { 31, 96, 32, 0 }, { 32, 128, 64, 32 }, { 33, 255, 192, 96 }, { 34, 255, 192, 96 }, { 35, 224, 224, 224 }, { 36, 0, 0, 0 }, { 37, 255, 255, 0 }, { 38, 255, 48, 48 }, { 39, 192, 128, 96 }, { 40, 255, 192, 96 }, { 41, 255, 255, 64 }, { 42, 192, 192, 192 }, { 43, 140, 140, 140 }, { 44, 150, 150, 150 }, { 45, 192, 64, 64 }, { 46, 128, 0, 0 }, { 47, 255, 128, 64 }, { 48, 64, 128, 64 }, { 49, 16, 16, 24 }, { 50, 255, 255, 0 }, { 51, 255, 224, 0 }, { 52, 96, 128, 192 }, { 53, 255, 192, 96 }, { 54, 224, 128, 64 }, { 55, 128, 0, 0 }, { 56, 128, 138, 92 }, { 57, 128, 192, 255 }, { 58, 192, 96, 48 }, { 59, 192, 255, 0 }, { 60, 192, 96, 0 }, { 61, 96, 96, 96 }, { 62, 96, 96, 96 }, { 63, 255, 128, 64 }, { 64, 255, 128, 64 }, { 65, 255, 128, 64 }, { 66, 224, 224, 192 }, { 67, 78, 78, 78 }, { 68, 255, 128, 64 }, { 69, 128, 96, 64 }, { 70, 133, 133, 133 }, { 71, 192, 192, 192 }, { 72, 255, 192, 128 }, { 73, 224, 128, 128 }, { 74, 224, 128, 128 }, { 75, 255, 64, 64 }, { 76, 255, 64, 64 }, { 77, 255, 64, 64 }, { 78, 255, 255, 255 }, { 79, 0, 192, 224 }, { 80, 255, 255, 255 }, { 81, 0, 192, 0 }, { 82, 170, 160, 170 }, { 83, 96, 255, 32 }, { 84, 192, 96, 48 }, { 85, 255, 128, 64 }, { 86, 255, 128, 0 }, { 87, 128, 24, 48 }, { 88, 128, 96, 64 }, { 89, 255, 224, 96 }, { 90, 128, 0, 255 }, { 91, 255, 128, 0 }, { 92, 255, 192, 192 }, { 93, 255, 96, 96 }, { 94, 255, 96, 96 }, { 95, 0, 0, 0 }, { 96, 255, 128, 64 } }; int[] minXZ = { 0, 0 }; int[] maxXZ = { 0, 0 }; foreach (ChunkRef chunk in chunkMan) { minXZ[0] = Math.Min(chunk.X * 16, minXZ[0]); minXZ[1] = Math.Min(chunk.Z * 16, minXZ[1]); maxXZ[0] = Math.Max(16 + chunk.X * 16, maxXZ[0]); maxXZ[1] = Math.Max(16 + chunk.Z * 16, maxXZ[1]); } aMinXZ = minXZ; int[] worldSize = { maxXZ[0] - minXZ[0], maxXZ[1] - minXZ[1] }; Bitmap map = new Bitmap(worldSize[0], worldSize[1]); int y; int block; int[] pixelpos = { 0, 0 }; Color color; long chunkCount = chunkMan.Count(); long chunkCurrent = 0; foreach (ChunkRef chunk in chunkMan) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { y = chunk.Blocks.GetHeight(x, z); if (y > 0 && y < 256) { block = chunk.Blocks.GetID(x, y - 1, z); int blockColor = block; if (blockColor < colors.GetUpperBound(0) + 1) { color = color = Color.FromArgb(colors[blockColor, 1], colors[blockColor, 2], colors[blockColor, 3]); } else { color = color = Color.FromArgb(255, 0, 255); } if (x == 0 || z == 0) { color = Color.FromArgb(color.R / 2, color.G / 2, color.B / 2); } } else { color = Color.Black; } pixelpos[0] = Math.Abs(minXZ[0]) + (chunk.X * 16) + x; pixelpos[1] = Math.Abs(minXZ[1]) + (chunk.Z * 16) + z; map.SetPixel(pixelpos[0], pixelpos[1], color); } } chunkCurrent++; pbProgress.Value = (int)(100.0 * ((double)chunkCurrent / (double)chunkCount)); pbProgress.PerformStep(); } pbProgress.Value = 0; pbProgress.PerformStep(); return map; }
private void OpenDimension (string dim) { string path = Path; if (String.IsNullOrEmpty(dim)) { path = IO.Path.Combine(path, _REGION_DIR); } else { path = IO.Path.Combine(path, dim); path = IO.Path.Combine(path, _REGION_DIR); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } ChunkCache cc = new ChunkCache(_prefCacheSize); AnvilRegionManager rm = new AnvilRegionManager(path, cc); RegionChunkManager cm = new RegionChunkManager(rm, cc); BlockManager bm = new AnvilBlockManager(cm); _regionMgrs[dim] = rm; _chunkMgrs[dim] = cm; _blockMgrs[dim] = bm; _caches[dim] = cc; }
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(); }
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); }
public static bool Generate(frmMace frmLogForm, AnvilWorld worldDest, RegionChunkManager 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, cmDest); BlockHelper.SetupClass(bmDest); NoticeBoard.SetupClass(); if (!SourceWorld.SetupClass(worldDest)) { return(false); } #endregion #region determine random options switch (City.wallMaterialID) { case BlockType.ICE: City.hasTorchesOnWalkways = false; City.outsideLightType = "None"; switch (City.moatType) { case "Fire": case "Lava": frmLogForm.UpdateLog("Fixing disaster configuration", true, true); City.moatType = "Water"; break; } break; 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.DoubleStoneSlab.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.STONE; City.pathExtends = 2; break; case "sandstone_raised": City.pathBlockID = BlockInfo.Sandstone.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.SANDSTONE; City.pathExtends = 2; break; case "wood_planks_raised": case "woodplanks_raised": City.pathBlockID = BlockInfo.WoodPlank.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.WOOD; City.pathExtends = 2; break; case "cobblestone_raised": City.pathBlockID = BlockInfo.Cobblestone.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.COBBLESTONE; City.pathExtends = 2; break; case "brick_raised": City.pathBlockID = BlockInfo.BrickBlock.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.BRICK; City.pathExtends = 2; break; case "stonebrick_raised": City.pathBlockID = BlockInfo.StoneBrick.ID; City.pathBlockData = 0; City.pathAlternativeBlockID = BlockInfo.StoneSlab.ID; City.pathAlternativeBlockData = (int)SlabType.STONE_BRICK; 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); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } Buildings.structPoint spMineshaftEntrance = new Buildings.structPoint(); if (City.hasWalls) { frmLogForm.UpdateLog("Creating walls", true, false); Walls.MakeWalls(worldDest, frmLogForm); } frmLogForm.UpdateProgress(0.24); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (City.hasDrawbridges) { frmLogForm.UpdateLog("Creating entrances", true, false); Entrances.MakeEntrances(bmDest); } frmLogForm.UpdateProgress(0.27); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (City.hasMoat) { frmLogForm.UpdateLog("Creating moat", true, false); Moat.MakeMoat(frmLogForm, bmDest); } frmLogForm.UpdateProgress(0.30); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } 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 (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (City.hasGuardTowers) { frmLogForm.UpdateLog("Creating guard towers", true, false); GuardTowers.MakeGuardTowers(bmDest, frmLogForm); } frmLogForm.UpdateProgress(0.42); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (City.hasFarms) { frmLogForm.UpdateLog("Creating farms", true, false); Farms2.MakeFarms(worldDest, bmDest); } frmLogForm.UpdateProgress(0.45); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (City.hasFlowers) { frmLogForm.UpdateLog("Creating flowers", true, false); Flowers.MakeFlowers(worldDest, bmDest); } frmLogForm.UpdateProgress(0.46); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } if (!City.hasValuableBlocks) { frmLogForm.UpdateLog("Replacing valuable blocks", true, true); cmDest.Save(); worldDest.Save(); Chunks.ReplaceValuableBlocks(worldDest, bmDest); } frmLogForm.UpdateProgress(0.48); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } frmLogForm.UpdateLog("Creating rail data", true, false); Chunks.PositionRails(worldDest, bmDest); frmLogForm.UpdateProgress(0.50); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } frmLogForm.UpdateLog("Creating lighting data", true, false); Chunks.ResetLighting(worldDest, cmDest, frmLogForm); frmLogForm.UpdateProgress(0.95); if (CheckCancelled(worldDest, frmLogForm)) { return(false); } #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 return(true); }