Fixed crashing bugs on edge chunks with TP flag set. Made FixedMath mode default for oregen.

This commit is contained in:
Justin Aquadro 2011-03-13 07:26:54 +00:00
parent d58ed4f372
commit 45839d2416
6 changed files with 1176 additions and 1127 deletions

View file

@ -23,6 +23,11 @@ namespace NBToolkit
_chunkMan = cm; _chunkMan = cm;
_cx = cx; _cx = cx;
_cz = cz; _cz = cz;
Region r = cm.GetRegion(cx, cz);
if (r == null || !r.ChunkExists(LocalX, LocalZ)) {
throw new MissingChunkException();
}
} }
public int X public int X
@ -41,6 +46,22 @@ namespace NBToolkit
} }
} }
public int LocalX
{
get
{
return _cx & ChunkManager.REGION_XMASK;
}
}
public int LocalZ
{
get
{
return _cz & ChunkManager.REGION_ZMASK;
}
}
public bool Save () public bool Save ()
{ {
if (_dirty) { if (_dirty) {
@ -61,7 +82,11 @@ namespace NBToolkit
} }
Region r = _chunkMan.GetRegion(_cx, _cz); Region r = _chunkMan.GetRegion(_cx, _cz);
_nbt = r.GetChunkTree(_cx & ChunkManager.REGION_XMASK, _cz & ChunkManager.REGION_ZMASK); if (r == null || !r.ChunkExists(LocalX, LocalZ)) {
throw new MissingChunkException();
}
_nbt = r.GetChunkTree(LocalX, LocalZ);
return _nbt; return _nbt;
} }
@ -73,7 +98,11 @@ namespace NBToolkit
_data = null; _data = null;
Region r = _chunkMan.GetRegion(_cx, _cz); Region r = _chunkMan.GetRegion(_cx, _cz);
return r.SaveChunkTree(_cx & ChunkManager.REGION_XMASK, _cz & ChunkManager.REGION_ZMASK, _nbt); if (r == null || !r.ChunkExists(LocalX, LocalZ)) {
throw new MissingChunkException();
}
return r.SaveChunkTree(LocalX, LocalZ, _nbt);
} }
return false; return false;

View file

@ -31,22 +31,21 @@ namespace NBToolkit
{ {
ChunkKey k = new ChunkKey(cx, cz); ChunkKey k = new ChunkKey(cx, cz);
Chunk c = null; WeakReference chunkref = null;
if (_cache.ContainsKey(k)) { if (_cache.TryGetValue(k, out chunkref)) {
c = _cache[k].Target as Chunk; return chunkref.Target as Chunk;
}
else {
_cache.Add(k, new WeakReference(null));
} }
if (c != null) { _cache.Add(k, new WeakReference(null));
try {
Chunk c = new Chunk(this, cx, cz);
_cache[k].Target = c;
return c; return c;
} }
catch (MissingChunkException) {
c = new Chunk(this, cx, cz); return null;
_cache[k].Target = c; }
return c;
} }
public Chunk GetChunkInRegion (Region r, int lcx, int lcz) public Chunk GetChunkInRegion (Region r, int lcx, int lcz)
@ -101,4 +100,9 @@ namespace NBToolkit
return _regionMan; return _regionMan;
} }
} }
public class MissingChunkException : Exception
{
}
} }

View file

@ -1,9 +1,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<StartArguments>replace -b 18 -a 19 -w "F:\Minecraft\tps - Copy (10)" -v -cxa -1 -cxb -1 -cza 0 -czb 0</StartArguments> <StartArguments>oregen -w "E:\temp\worlds\testsave2" -b 112 -r 5 -s 5 -mindepth 1 -maxdepth 127 -oi 1 -d 2 -v</StartArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<StartArguments>replace -b 18 -a 19 -w "F:\Minecraft\tps - Copy (10)" -v -cxa -1 -cxb -1 -cza 0 -czb 0</StartArguments> <StartArguments>oregen -w "E:\temp\worlds\testsave2" -b 112 -r 5 -s 5 -mindepth 1 -maxdepth 127 -oi 1 -d 2 -v</StartArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory> <PublishUrlHistory>publish\</PublishUrlHistory>

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ namespace NBToolkit
public bool OPT_OO = false; public bool OPT_OO = false;
public bool OPT_OA = false; public bool OPT_OA = false;
public bool OPT_MATHFIX = false; public bool OPT_MATHFIX = true;
public List<int> OPT_OB_INCLUDE = new List<int>(); public List<int> OPT_OB_INCLUDE = new List<int>();
public List<int> OPT_OB_EXCLUDE = new List<int>(); public List<int> OPT_OB_EXCLUDE = new List<int>();
@ -72,8 +72,8 @@ namespace NBToolkit
v => OPT_OB_INCLUDE.Add(Convert.ToInt32(v) % 256) }, v => OPT_OB_INCLUDE.Add(Convert.ToInt32(v) % 256) },
{ "ox|OverrideExclude=", "Generated deposits can never replace the specified block type {ID} [repeatable]", { "ox|OverrideExclude=", "Generated deposits can never replace the specified block type {ID} [repeatable]",
v => OPT_OB_EXCLUDE.Add(Convert.ToInt32(v) % 256) }, v => OPT_OB_EXCLUDE.Add(Convert.ToInt32(v) % 256) },
{ "mf|MathFix", "Use MC native ore generation algorithm with distribution evenness patch", { "nu|NativeUnpatched", "Use MC native ore generation algorithm without distribution evenness patch",
v => OPT_MATHFIX = true }, v => OPT_MATHFIX = false },
}; };
_chunkFilter = new ChunkFilter(); _chunkFilter = new ChunkFilter();
@ -185,10 +185,14 @@ namespace NBToolkit
int affectedChunks = 0; int affectedChunks = 0;
foreach (Chunk chunk in new FilteredChunkList(world.GetChunkManager(), opt.GetChunkFilter())) { foreach (Chunk chunk in new FilteredChunkList(world.GetChunkManager(), opt.GetChunkFilter())) {
if (!chunk.IsPopulated()) { if (chunk == null || !chunk.IsPopulated()) {
continue; continue;
} }
if (opt.OPT_V) {
Console.WriteLine("Processing Chunk (" + chunk.X + "," + chunk.Z + ")");
}
affectedChunks++; affectedChunks++;
ApplyChunk(world, chunk); ApplyChunk(world, chunk);
@ -254,7 +258,13 @@ namespace NBToolkit
public override bool SetBlockID (int x, int y, int z, int id) public override bool SetBlockID (int x, int y, int z, int id)
{ {
int blockID = GetBlockID(x, y, z); int blockID = 0;
try {
blockID = GetBlockID(x, y, z);
}
catch {
return false;
}
if ( if (
((opt.OPT_OA) && (blockID != opt.OPT_ID)) || ((opt.OPT_OA) && (blockID != opt.OPT_ID)) ||

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.IO;
namespace NBToolkit namespace NBToolkit
{ {
@ -21,19 +22,24 @@ namespace NBToolkit
RegionKey k = new RegionKey(rx, rz); RegionKey k = new RegionKey(rx, rz);
Region r; Region r;
if (_cache.TryGetValue(k, out r) == false) { try {
r = new Region(this, rx, rz); if (_cache.TryGetValue(k, out r) == false) {
_cache.Add(k, r); r = new Region(this, rx, rz);
_cache.Add(k, r);
}
return r;
}
catch (FileNotFoundException) {
_cache.Add(k, null);
return null;
} }
return r;
} }
public Region GetRegion (string filename) public Region GetRegion (string filename)
{ {
int rx, rz; int rx, rz;
if (!Region.ParseFileName(filename, out rx, out rz)) { if (!Region.ParseFileName(filename, out rx, out rz)) {
throw new ArgumentException(); throw new ArgumentException("Malformed region file name: " + filename, "filename");
} }
return GetRegion(rx, rz); return GetRegion(rx, rz);