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;
_cx = cx;
_cz = cz;
Region r = cm.GetRegion(cx, cz);
if (r == null || !r.ChunkExists(LocalX, LocalZ)) {
throw new MissingChunkException();
}
}
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 ()
{
if (_dirty) {
@ -61,7 +82,11 @@ namespace NBToolkit
}
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;
}
@ -73,7 +98,11 @@ namespace NBToolkit
_data = null;
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;

View file

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

View file

@ -1,9 +1,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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 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>
<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_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_EXCLUDE = new List<int>();
@ -72,8 +72,8 @@ namespace NBToolkit
v => OPT_OB_INCLUDE.Add(Convert.ToInt32(v) % 256) },
{ "ox|OverrideExclude=", "Generated deposits can never replace the specified block type {ID} [repeatable]",
v => OPT_OB_EXCLUDE.Add(Convert.ToInt32(v) % 256) },
{ "mf|MathFix", "Use MC native ore generation algorithm with distribution evenness patch",
v => OPT_MATHFIX = true },
{ "nu|NativeUnpatched", "Use MC native ore generation algorithm without distribution evenness patch",
v => OPT_MATHFIX = false },
};
_chunkFilter = new ChunkFilter();
@ -185,10 +185,14 @@ namespace NBToolkit
int affectedChunks = 0;
foreach (Chunk chunk in new FilteredChunkList(world.GetChunkManager(), opt.GetChunkFilter())) {
if (!chunk.IsPopulated()) {
if (chunk == null || !chunk.IsPopulated()) {
continue;
}
if (opt.OPT_V) {
Console.WriteLine("Processing Chunk (" + chunk.X + "," + chunk.Z + ")");
}
affectedChunks++;
ApplyChunk(world, chunk);
@ -254,7 +258,13 @@ namespace NBToolkit
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 (
((opt.OPT_OA) && (blockID != opt.OPT_ID)) ||

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace NBToolkit
{
@ -21,19 +22,24 @@ namespace NBToolkit
RegionKey k = new RegionKey(rx, rz);
Region r;
if (_cache.TryGetValue(k, out r) == false) {
r = new Region(this, rx, rz);
_cache.Add(k, r);
try {
if (_cache.TryGetValue(k, out r) == false) {
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)
{
int rx, 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);