/// <summary> /// Creates a new Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it. /// </summary> /// <param name="path">The path to the directory where the new world should be stored.</param> /// <param name="cacheSize">The preferred cache size in chunks for each opened dimension in this world.</param> /// <returns>A new <see cref="BetaWorld"/> object representing a new world.</returns> /// <remarks>This method will attempt to create the specified directory immediately if it does not exist, but will not /// write out any world data unless it is explicitly saved at a later time.</remarks> public static AnvilWorld Create(string path, int cacheSize) { AnvilWorld world = new AnvilWorld().CreateWorld(path); world._prefCacheSize = cacheSize; return world; }
internal static void OnResolveOpen(object sender, OpenWorldEventArgs e) { try { AnvilWorld world = new AnvilWorld().OpenWorld(e.Path); if (world == null) { return; } string regPath = IO.Path.Combine(e.Path, _REGION_DIR); if (!Directory.Exists(regPath)) { return; } if (world.Level.Version < 19133) { return; } e.AddHandler(Open); } catch (Exception) { return; } }
/// <summary> /// Creates a new Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it. /// </summary> /// <param name="path">The path to the directory where the new world should be stored.</param> /// <param name="cacheSize">The preferred cache size in chunks for each opened dimension in this world.</param> /// <returns>A new <see cref="BetaWorld"/> object representing a new world.</returns> /// <remarks>This method will attempt to create the specified directory immediately if it does not exist, but will not /// write out any world data unless it is explicitly saved at a later time.</remarks> public static AnvilWorld Create(string path, int cacheSize) { AnvilWorld world = new AnvilWorld().CreateWorld(path); world._prefCacheSize = cacheSize; return(world); }
public BuildingBlocks(AnvilWorld world, ModelData md, BuildingType buildingType) { BlockManager bm = world.GetBlockManager(); ModelDataModel mdm = md.GetModelByTypeId((int)buildingType); if (mdm == null) { // This can happen until we have models for everything in the config file Height = 0; GroundLevelOffset = 0; return; } GroundLevelOffset = mdm.GroundLevelOffset; IntVector3 corner1 = new IntVector3(); corner1.X = mdm.Corner1[0].x; corner1.Y = mdm.Corner1[0].y; corner1.Z = mdm.Corner1[0].z; IntVector3 corner2 = new IntVector3(); corner2.X = mdm.Corner2[0].x; corner2.Y = mdm.Corner2[0].y; corner2.Z = mdm.Corner2[0].z; // Handle rotation /* * Block entities aren't drawing right. We're flipping the Z-axis here which might be the cause.. * blocks = new AlphaBlock[Math.Abs(corner1.X - corner2.X) + 1, Math.Abs(corner1.Y - corner2.Y) + 1, Math.Abs(corner1.Z - corner2.Z) + 1]; for (int x = corner1.X; x <= corner2.X; x++) { for (int y = corner1.Y; y <= corner2.Y; y++) { for (int z = 0; z <= Math.Abs(corner2.Z - corner1.Z); z++) { blocks[x - corner1.X, y - corner1.Y, z] = bm.GetBlock(x, y, corner2.Z - z); } } } */ blocks = new AlphaBlock[Math.Abs(corner1.X - corner2.X) + 1, Math.Abs(corner1.Y - corner2.Y) + 1, Math.Abs(corner1.Z - corner2.Z) + 1]; for (int x = corner1.X; x <= corner2.X; x++) { for (int y = corner1.Y; y <= corner2.Y; y++) { for (int z = corner1.Z; z <= corner2.Z; z++) { blocks[x - corner1.X, y - corner1.Y, z - corner1.Z] = bm.GetBlock(x, y, z); } } } Height = Math.Abs(corner1.Y - corner2.Y) + 1; }
public TerrainGenerator(SimCity2000Save simCity, AnvilWorld world, BuildingSource buildingSource) { terrain = simCity.TerrainSection; altitude = simCity.AltitudeSection; buildings = simCity.BuildingSection; zones = simCity.ZoneSection; this.world = world; this.buildingSource = buildingSource; seaLevel = simCity.MiscSection.SeaLevel; }
internal static void OnResolveOpen (object sender, OpenWorldEventArgs e) { try { AnvilWorld world = new AnvilWorld().OpenWorld(e.Path); if (world == null) { return; } string regPath = IO.Path.Combine(e.Path, _REGION_DIR); if (!Directory.Exists(regPath)) { return; } if (world.Level.Version < 19133) { return; } e.AddHandler(Open); } catch (Exception) { return; } }
/// <summary> /// Opens an existing Beta-compatible Minecraft world and returns a new <see cref="BetaWorld"/> to represent it. /// </summary> /// <param name="path">The path to the directory containing the world's level.dat, or the path to level.dat itself.</param> /// <param name="cacheSize">The preferred cache size in chunks for each opened dimension in this world.</param> /// <returns>A new <see cref="BetaWorld"/> object representing an existing world on disk.</returns> public static AnvilWorld Open (string path, int cacheSize) { AnvilWorld world = new AnvilWorld().OpenWorld(path); world._prefCacheSize = cacheSize; return world; }
public void LoadLevel() { int verticalOffset = 85; Debug.Log("About to load level folder: " + _fullMapPath + "."); Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath); Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager(); BlockSet blockSet = _map.GetBlockSet(); _map.GetSunLightmap().SetSunHeight(3, 3, 3); foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager) { // Loop through x-axis of chunks in this region for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) { // Loop through z-axis of chunks in this region. for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) { // Retrieve the chunk at the current position in our 2D loop... Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ); if (mcChunkRef != null) { if (mcChunkRef.IsTerrainPopulated) { // Ok...now to stick the blocks in... for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) { for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) { for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) { int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ); Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY + verticalOffset, iMCChunkInternalZ); if (iBlockID != 0) { switch (iBlockID) { case 3: // Dirt to first grass iBlockID = 1; break; case 12: // Grass to grass iBlockID = 1; break; case 13: // Gravel to stone iBlockID = 4; break; case 1: // Stone to second stone iBlockID = 5; break; case 16: // Coal ore to fungus iBlockID = 17; break; case 15: // Iron ore to pumpkin iBlockID = 20; break; case 9: // Water to water iBlockID = 8; break; default: Debug.Log("Unmapped BlockID: " + iBlockID); break; } Block newBlock = blockSet.GetBlock(iBlockID); _map.SetBlock(new BlockData(newBlock), blockPos); Vector3i chunkPos = Chunk.ToChunkPosition(blockPos); _map.SetDirty(chunkPos); } } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) } // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) } // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) } // End if (mcChunkRef.IsTerrainPopulated) } // End if (mcChunkRef != null) } // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) } // End for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) } // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager ) Debug.Log("Loaded level: " + _fullMapPath + "."); _map.AddColliders(); // List3D<Chunk> chunkList = _map.GetChunks (); // // for (int minX = chunkList.GetMinX(); minX < chunkList.GetMaxX(); minX++) // { // for (int minY = chunkList.GetMinY(); minY < chunkList.GetMaxY(); minY++) // { // for (int minZ = chunkList.GetMinZ(); minZ < chunkList.GetMaxZ(); minZ++) // { // Vector3i chunkPos = new Vector3i(minX, minY, minZ); // // Chunk mapChunk = _map.GetChunk (chunkPos); // // Debug.Log ("LOL [" + minX + ", " + minY + ", " + minZ + "]."); // } // } // } // // foreach (Chunk loadedChunk in _map.Get // { // Vector3i loadedChunkPos = loadedChunk.GetPosition(); // Debug.Log ("MOG A CHUNK!!! [" + loadedChunkPos.x + ", " + loadedChunkPos.y + ", " + loadedChunkPos.z + "]."); // } } // End public void LoadLevel()
public void LoadLevel() { int verticalOffset = 85; Debug.Log("About to load level folder: " + _fullMapPath + "."); Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath); Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager(); OpenCog.BlockSet.OCBlockSet blockSet = _map.GetBlockSet(); //_map.GetSunLightmap().SetSunHeight(20, 4, 4); int createCount = 0; System.Collections.Generic.Dictionary <int, int> unmappedBlockTypes = new System.Collections.Generic.Dictionary <int, int>(); //Debug.Log("In LoadLevel, there are " + blockSet.BlockCount + " blocks available."); foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager) { // Loop through x-axis of chunks in this region for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) { // Loop through z-axis of chunks in this region. for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) { // Retrieve the chunk at the current position in our 2D loop... Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ); if (mcChunkRef != null) { if (mcChunkRef.IsTerrainPopulated) { // Ok...now to stick the blocks in... int iMCChunkY = 0; OCChunk chunk = null; //new OCChunk(_map, new Vector3i(iMCChunkX, iMCChunkY, iMCChunkZ)); OCChunk lastChunk = null; Vector3i chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), iMCChunkY + verticalOffset, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); Vector3i lastChunkPos = Vector3i.zero; chunk = _map.GetChunkInstance(chunkPos); for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) { if (iMCChunkInternalY / OCChunk.SIZE_Y > iMCChunkY) { lastChunk = chunk; lastChunkPos = chunkPos; chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), (iMCChunkInternalY + verticalOffset) / OCChunk.SIZE_Y, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); chunk = _map.GetChunkInstance(chunkPos); } for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) { for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) { int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ); if (iBlockID != 0) { Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY % OCChunk.SIZE_Y, iMCChunkInternalZ); int ourBlockID = -1; // switch (iBlockID) // { // case 3: // Dirt to first grass // ourBlockID = 1; // break; // case 12: // Grass to grass // ourBlockID = 1; // break; // case 13: // Gravel to stone // ourBlockID = 4; // break; // case 1: // Stone to second stone // ourBlockID = 5; // break; // case 16: // Coal ore to fungus // ourBlockID = 17; // break; // case 15: // Iron ore to pumpkin // ourBlockID = 20; // break; // case 9: // Water to water // ourBlockID = 8; // //Debug.Log ("Creating some water at [" + blockPos.x + ", " + blockPos.y + ", " + blockPos.z + "]"); // break; //// case 2: //// iBlockID = 16; //// break; //// case 4: //// iBlockID = 16; //// break; //// case 18: //// iBlockID = 16; //// break; // default: // { // //Debug.Log ("Unmapped BlockID: " + iBlockID); // // if (!unmappedBlockTypes.ContainsKey (iBlockID)) // { // unmappedBlockTypes.Add (iBlockID, 1); // } // else // { // unmappedBlockTypes[iBlockID] += 1; // } // // break; // } // } if (mcToOCBlockDictionary.ContainsKey(iBlockID)) { ourBlockID = mcToOCBlockDictionary[iBlockID]; } else { if (!unmappedBlockTypes.ContainsKey(iBlockID)) { unmappedBlockTypes.Add(iBlockID, 1); } else { unmappedBlockTypes[iBlockID] += 1; } } if (ourBlockID != -1) { OCBlock newBlock = blockSet.GetBlock(ourBlockID); //OCBlockData block = new OpenCog.Map.OCBlockData(newBlock, blockPos); OCBlockData block = (OCBlockData)OCScriptableObject.CreateInstance <OCBlockData>(); block.Init(newBlock, blockPos); chunk.SetBlock(block, blockPos); OpenCog.Map.Lighting.OCLightComputer.RecomputeLightAtPosition(_map, blockPos); if (block.block.GetName() == "Battery") { GameObject batteryPrefab = OCMap.Instance.BatteryPrefab; if (batteryPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, batteryPrefab == null"); } else { GameObject battery = (GameObject)GameObject.Instantiate(batteryPrefab); battery.transform.position = blockPos; battery.name = "Battery"; battery.transform.parent = OCMap.Instance.BatteriesSceneObject.transform; } } if (block.block.GetName() == "Hearth") { GameObject hearthPrefab = OCMap.Instance.HearthPrefab; if (hearthPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, hearthPrefab == null"); } else { GameObject hearth = (GameObject)GameObject.Instantiate(hearthPrefab); hearth.transform.position = blockPos; hearth.name = "Hearth"; hearth.transform.parent = OCMap.Instance.HearthsSceneObject.transform; } } createCount += 1; } } } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) } // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) string chunkCoord = chunkPos.x + ", " + chunkPos.z; if (!chunkList.ContainsKey(chunkCoord)) { chunkList.Add(chunkCoord, chunkPos); } if (iMCChunkY < iMCChunkInternalY / OCChunk.SIZE_Y) { _map.Chunks.AddOrReplace(lastChunk, lastChunkPos); _map.UpdateChunkLimits(lastChunkPos); _map.SetDirty(lastChunkPos); iMCChunkY = iMCChunkInternalY / OCChunk.SIZE_Y; } } // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) } // End if (mcChunkRef.IsTerrainPopulated) } // End if (mcChunkRef != null) } // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) } // End for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) } // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager ) foreach (Vector3i chunkToLight in chunkList.Values) { OpenCog.Map.Lighting.OCChunkSunLightComputer.ComputeRays(_map, chunkToLight.x, chunkToLight.z); OpenCog.Map.Lighting.OCChunkSunLightComputer.Scatter(_map, null, chunkToLight.x, chunkToLight.z); } foreach (System.Collections.Generic.KeyValuePair <int, int> unmappedBlockData in unmappedBlockTypes) { UnityEngine.Debug.Log("Unmapped BlockID '" + unmappedBlockData.Key + "' found " + unmappedBlockData.Value + " times."); } Debug.Log("Loaded level: " + _fullMapPath + ", created " + createCount + " blocks."); _map.AddColliders(); } // End public void LoadLevel()
public static void openFile( Form plcType, Form main, ComboBox height, ToolStripProgressBar mLoad, ToolStripStatusLabel mStatus ) { bool noFile = true, cancel = false; OpenFileDialog openDiag; DialogResult res; String filename; mnuHeight = height; mnuLoad = mLoad; mnuStatus = mStatus; init = true; plcType.Hide(); while( noFile ^ cancel ) { openDiag = new OpenFileDialog(); openDiag.Multiselect = false; openDiag.AddExtension = true; openDiag.DefaultExt = "dat"; openDiag.Filter = "Minecraft Levels (*.dat)|*.dat|" + "All Files (*.*)|*.*"; res = openDiag.ShowDialog(); plcType.Show(); if( res == DialogResult.Cancel ) cancel = true; else { filename = openDiag.FileName; noFile = false; openDiag.Dispose(); lvl = AnvilWorld.Open( filename ); if( lvl == null ) MessageBox.Show( "That file was not a compatible Minecraft level.", "Open File Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); else { regDiag = new SelectRegion( lvl.GetRegionManager(), main ); loadLimits(); selectRegion( true ); } } } }
public BuildingSource(AnvilWorld inputWorld, ModelData md) { world = inputWorld; modelData = md; Buildings = new Dictionary<BuildingType, BuildingBlocks>(); }