Skip to content

Instantly share code, notes, and snippets.

@Gargaj
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gargaj/2891b8fc558e01b8ddf2 to your computer and use it in GitHub Desktop.
Save Gargaj/2891b8fc558e01b8ddf2 to your computer and use it in GitHub Desktop.
MC 1.8 chest fix
using System;
using Substrate;
using Substrate.Core;
class Program
{
static void Main (string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Usage: {0} [worldpath]", System.AppDomain.CurrentDomain.FriendlyName);
return;
}
string dest;
if (args[0].Contains("\\"))
dest = args[0];
else
dest = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\.minecraft\\saves\\" + args[0];
if (!System.IO.File.Exists(dest + "\\level.dat"))
{
Console.WriteLine("Couldn't find level.dat in '{0}'!", dest);
return;
}
NbtWorld world = NbtWorld.Open(dest);
int total = 0;
total += FixChestsInDimension(world, 0);
total += FixChestsInDimension(world, -1);
total += FixChestsInDimension(world, 1);
Console.WriteLine("\n\nFixed {0} chests in total!", total);
//Console.ReadKey();
}
private static int FixChestsInDimension(NbtWorld world, int dim)
{
Console.WriteLine("--- Fixing chests in dimension {0}", dim);
IChunkManager cm = world.GetChunkManager(dim);
if (cm == null) return 0;
int total = 0;
foreach (ChunkRef chunk in cm) total++;
int n = 0;
int fix = 0;
foreach (ChunkRef chunk in cm)
{
int xdim = chunk.Blocks.XDim;
int ydim = chunk.Blocks.YDim;
int zdim = chunk.Blocks.ZDim;
for (int x = 0; x < xdim; x++)
{
for (int z = 0; z < zdim; z++)
{
for (int y = 0; y < ydim; y++)
{
if (chunk.Blocks.GetID(x, y, z) == BlockType.CHEST && chunk.Blocks.GetData(x, y, z) == 0)
{
chunk.Blocks.SetData(x, y, z, 5);
Console.WriteLine("Fixed chest at {0}, {1}, {2} ", chunk.X * xdim + x, y, chunk.Z * zdim + z);
fix++;
}
}
}
}
// Save the chunk
cm.Save();
Console.Write("Processed Chunk {0}, {1} ({2} / {3})\r", chunk.X, chunk.Z, n, total);
n++;
}
return fix;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment