static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: MoveSpawn <world> <x> <y> <z>"); return; } string dest = args[0]; int x = Convert.ToInt32(args[1]); int y = Convert.ToInt32(args[2]); int z = Convert.ToInt32(args[3]); // Open our world BetaWorld world = BetaWorld.Open(dest); // Set the level's spawn // Note: Players do not have separate spawns by default // If you wanted to change a player's spawn, you must set all // 3 coordinates for it to stick. It will not take the level's defaults. world.Level.Spawn = new SpawnPoint(x, y, z); // Save the changes world.Save(); }
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"); } }
public static void SetupClass() { intHouseNumber = 0; BetaWorld worldSource = BetaWorld.Open("Resources\\Mace"); bmSource = worldSource.GetBlockManager(); ReadBuildings(); }
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(); } }
public static void SetupClass(BetaWorld worldDest) { AllBuildings = new Building[0]; intHouseNumber = 0; BetaWorld worldSource = BetaWorld.Open("Resources\\Mace"); bmSource = worldSource.GetBlockManager(); cmSource = worldSource.GetChunkManager(); cmDest = worldDest.GetChunkManager(); lstCitySigns.Clear(); lstInstanceSigns.Clear(); ReadBuildings(); }
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); }
public static bool SetupClass(BetaWorld worldDest, bool booIncludeItemsInChestsOriginal) { 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; return(ReadBuildings()); }
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(); }
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()); }
static void Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Usage: Convert <world> <dest> <a|b>"); return; } string src = args[0]; string dst = args[1]; string srctype = args[2]; // Open source and destrination worlds depending on conversion type NbtWorld srcWorld; NbtWorld dstWorld; if (srctype == "a") { srcWorld = AlphaWorld.Open(src); dstWorld = BetaWorld.Create(dst); } else { srcWorld = BetaWorld.Open(src); dstWorld = AlphaWorld.Create(dst); } // Grab chunk managers to copy chunks IChunkManager cmsrc = srcWorld.GetChunkManager(); IChunkManager cmdst = dstWorld.GetChunkManager(); // Copy each chunk from source to dest foreach (ChunkRef chunk in cmsrc) { cmdst.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef()); } // Copy level data from source to dest dstWorld.Level.LoadTreeSafe(srcWorld.Level.BuildTree()); // If we're creating an alpha world, get rid of the version field if (srctype == "b") { dstWorld.Level.Version = 0; } // Save level.dat dstWorld.Level.Save(); }
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()); }
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)); } } } } } }
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(); } }
public void CropMaceWorld(frmMace frmLogForm) { Directory.CreateDirectory(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\macecopy"); BetaWorld bwCopy = BetaWorld.Create(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\macecopy"); ChunkManager cmCopy = bwCopy.GetChunkManager(); BetaWorld bwCrop = BetaWorld.Open(Environment.GetEnvironmentVariable("APPDATA") + "\\.minecraft\\saves\\mace"); ChunkManager cmCrop = bwCrop.GetChunkManager(); foreach (ChunkRef chunk in cmCrop) { Debug.WriteLine("Copying chunk " + chunk.X + "," + chunk.Z); cmCopy.SetChunk(chunk.X, chunk.Z, chunk.GetChunkRef()); } cmCopy.Save(); bwCopy.Save(); }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: GiveItem <world> <player> <item-id> <cnt>"); return; } string dest = args[0]; string player = args[1]; int itemid = Convert.ToInt32(args[2]); int count = Convert.ToInt32(args[3]); // Open the world and grab its player manager BetaWorld world = BetaWorld.Open(dest); PlayerManager pm = world.GetPlayerManager(); // Check that the named player exists if (!pm.PlayerExists(player)) { Console.WriteLine("No such player {0}!", player); return; } // Get player (returned object is independent of the playermanager) Player p = pm.GetPlayer(player); // Find first slot to place item for (int i = 0; i < p.Items.Capacity; i++) { if (!p.Items.ItemExists(i)) { // Create the item and set its stack count Item item = new Item(itemid); item.Count = count; p.Items[i] = item; // Don't keep adding items break; } } // Save the player pm.SetPlayer(player, p); }
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(); }
public NbtWorld GetWorld(TKOptions opt) { NbtWorld world = null; try { if (opt.OPT_ALPHA) { world = AlphaWorld.Open(opt.OPT_WORLD); } else { world = BetaWorld.Open(opt.OPT_WORLD); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Environment.Exit(1); } return(world); }
public World ConvertWorld(String mcDirectory) { String segmentDirectory = Path.Combine(FCEDirectory, "Segments"); if (!Directory.Exists(FCEDirectory)) { Directory.CreateDirectory(FCEDirectory); } if (!Directory.Exists(Path.Combine(FCEDirectory, segmentDirectory))) { Directory.CreateDirectory(segmentDirectory); } Boolean anvil = true; NbtWorld nbtWorld = AnvilWorld.Open(mcDirectory); String worldName = nbtWorld.Level.LevelName; IChunkManager chunkManager = nbtWorld.GetChunkManager(); try { // Try to test for mc world type // Don't know how this is supposed to work, but it presumably throws an exception // on a non-Anvil world. chunkManager.Count(); } catch { anvil = false; nbtWorld = BetaWorld.Open(mcDirectory); worldName = nbtWorld.Level.LevelName; chunkManager = nbtWorld.GetChunkManager(); } Int32 spawnChunkX = nbtWorld.Level.Spawn.X >> 4; Int32 spawnChunkZ = nbtWorld.Level.Spawn.Z >> 4; WorldSettings settings = new WorldSettings(); settings.Name = worldName; var fceWorld = World.Create(FCEDirectory, settings); var segmentManager = fceWorld.SegmentManager; _totalSegments = chunkManager.LongCount() * (anvil ? 16 : 8); _segmentsLeft = _totalSegments; StartSaveThread(fceWorld); foreach (ChunkRef chunk in chunkManager) { // If the save thread is too slow, wait until it has caught up before adding to it to prevent high ram usage while (_saveQueue.Count > 5000) { Thread.Sleep(500); } if (chunk.Blocks == null) { _segmentsLeft -= (anvil ? 16 : 8); continue; } Int32 spawnOffsetX = UseSpawnAsOrigin ? spawnChunkX - chunk.X : -chunk.X; Int32 spawnOffsetZ = UseSpawnAsOrigin ? spawnChunkZ - chunk.Z : -chunk.Z; // Minecraft has different x/y directions so we must reverse z so the world isn't mirrored var chunkCoords = new SegmentCoords(spawnOffsetX, 0, -spawnOffsetZ) + SegmentCoords.WorldCenter; for (Int32 i = 0; i < (anvil ? 16 : 8); i++) { SegmentCoords segCoords = chunkCoords + SegmentCoords.Above * i; var segment = new Segment(segmentManager, segCoords); var array = new Cube[16, 16, 16]; for (Byte x = 0; x < 16; x++) { for (Byte y = 0; y < 16; y++) { for (Byte z = 0; z < 16; z++) { // Minecraft has different x/y directions so we must reverse z so the world isn't mirrored AlphaBlock block = chunk.Blocks.GetBlock(15 - z, y + i * 16, x); UInt32 mcIdData = (UInt32)block.ID << 16 | (UInt16)block.Data; Cube cube; if (!_mcIdDataToFCECube.TryGetValue(mcIdData, out cube)) { cube = new Cube(1, 0, 0, 0); if (!UnknownBlocks.ContainsKey((UInt16)block.ID)) { UnknownBlocks.Add((UInt16)block.ID, block.Info.Name); } } array[z, y, x] = cube; } } } segment.CubeData = array; _segmentsLeft--; _saveQueue.Enqueue(segment); } // Pad the area above the converted world with 11 blank segments to prevent world gen from occuring // Possibly replace this in the future with simply shifting the world up for (Int32 i = (anvil ? 16 : 8); i < 27; i++) { var padding = new Segment(segmentManager, chunkCoords + SegmentCoords.Above * i); padding.CubeData = Segment.GetBlankSegment().CubeData; padding.IsEmpty = true; _saveQueue.Enqueue(padding); } } Task.WaitAll(_saveTask); return(fceWorld); }