More protection against exceptions for blocks at top of world

This commit is contained in:
Mike Primm 2012-05-23 08:13:47 -05:00
parent fc451fd002
commit 96673f0fb3

View File

@ -101,16 +101,21 @@ public class NewMapChunkCache implements MapChunkCache {
exceptions++; exceptions++;
} }
laststep = BlockStep.Y_MINUS; laststep = BlockStep.Y_MINUS;
typeid = blkdata = -1; if((y >= 0) && (y < worldheight))
typeid = blkdata = -1;
else
typeid = blkdata = 0;
} }
public final int getBlockTypeID() { public final int getBlockTypeID() {
if(typeid < 0) if(typeid < 0) {
typeid = snap.getBlockTypeId(bx, y, bz); typeid = snap.getBlockTypeId(bx, y, bz);
}
return typeid; return typeid;
} }
public final int getBlockData() { public final int getBlockData() {
if(blkdata < 0) if(blkdata < 0) {
blkdata = snap.getBlockData(bx, y, bz); blkdata = snap.getBlockData(bx, y, bz);
}
return blkdata; return blkdata;
} }
public int getBlockSkyLight() { public int getBlockSkyLight() {
@ -353,6 +358,8 @@ public class NewMapChunkCache implements MapChunkCache {
* Step current position in given direction * Step current position in given direction
*/ */
public final void stepPosition(BlockStep step) { public final void stepPosition(BlockStep step) {
typeid = -1;
blkdata = -1;
switch(step.ordinal()) { switch(step.ordinal()) {
case 0: case 0:
x++; x++;
@ -372,6 +379,9 @@ public class NewMapChunkCache implements MapChunkCache {
break; break;
case 1: case 1:
y++; y++;
if(y >= worldheight) {
typeid = blkdata = 0;
}
break; break;
case 2: case 2:
z++; z++;
@ -407,6 +417,9 @@ public class NewMapChunkCache implements MapChunkCache {
break; break;
case 4: case 4:
y--; y--;
if(y < 0) {
typeid = blkdata = 0;
}
break; break;
case 5: case 5:
z--; z--;
@ -426,8 +439,6 @@ public class NewMapChunkCache implements MapChunkCache {
break; break;
} }
laststep = step; laststep = step;
typeid = -1;
blkdata = -1;
} }
/** /**
* Unstep current position to previous position * Unstep current position to previous position
@ -449,8 +460,12 @@ public class NewMapChunkCache implements MapChunkCache {
else else
laststep = BlockStep.Y_MINUS; laststep = BlockStep.Y_MINUS;
this.y = y; this.y = y;
typeid = -1; if((y < 0) || (y >= worldheight)) {
blkdata = -1; typeid = blkdata = 0;
}
else {
typeid = blkdata = -1;
}
} }
public final int getX() { public final int getX() {
return x; return x;
@ -493,9 +508,12 @@ public class NewMapChunkCache implements MapChunkCache {
} }
@Override @Override
public final boolean isEmptySection() { public final boolean isEmptySection() {
if(isSectionNotEmpty[chunkindex] == null) try {
return !isSectionNotEmpty[chunkindex][y >> 4];
} catch (Exception x) {
initSectionData(chunkindex); initSectionData(chunkindex);
return !isSectionNotEmpty[chunkindex][y >> 4]; return !isSectionNotEmpty[chunkindex][y >> 4];
}
} }
} }