Add some extra array bounds protection

This commit is contained in:
Mike Primm 2012-02-11 23:28:44 -06:00
parent ab436f9e1c
commit e5a336bbe2

View file

@ -160,44 +160,56 @@ public class NewMapChunkCache implements MapChunkCache {
} }
public final BiomeMap getBiome() { public final BiomeMap getBiome() {
return biomemap[x - x_base][z - z_base]; try {
return biomemap[x - x_base][z - z_base];
} catch (Exception ex) {
return BiomeMap.NULL;
}
} }
public final int countSmoothedSwampBiomes() { public final int countSmoothedSwampBiomes() {
return swampcnt[x - x_base][z - z_base]; try {
return swampcnt[x - x_base][z - z_base];
} catch (Exception ex) {
return 0;
}
} }
public final int countSmoothedSwampBiomes(int sx, int sz, int scale) { public final int countSmoothedSwampBiomes(int sx, int sz, int scale) {
int xx = x - x_base; try {
int zz = z - z_base; int xx = x - x_base;
sx <<= 1; int zz = z - z_base;
sz <<= 1; sx <<= 1;
int s0 = swampcnt[xx][zz]; sz <<= 1;
int w; int s0 = swampcnt[xx][zz];
int tot; int w;
if(sx < scale) { int tot;
w = scale - sx; if(sx < scale) {
tot = (w * swampcnt[xx-1][zz]) + ((scale - w) * s0); w = scale - sx;
tot = (w * swampcnt[xx-1][zz]) + ((scale - w) * s0);
}
else if(sx > scale) {
w = sx - scale;
tot = (w * swampcnt[xx+1][zz]) + ((scale - w) * s0);
}
else {
tot = scale * s0;
}
if(sz < scale) {
w = scale - sz;
tot += (w * swampcnt[xx][zz-1]) + ((scale - w) * s0);
}
else if(sz > scale) {
w = sz - scale;
tot += (w * swampcnt[xx][zz+1]) + ((scale - w) * s0);
}
else {
tot += scale * s0;
}
return tot;
} catch (Exception ex) {
return 0;
} }
else if(sx > scale) {
w = sx - scale;
tot = (w * swampcnt[xx+1][zz]) + ((scale - w) * s0);
}
else {
tot = scale * s0;
}
if(sz < scale) {
w = scale - sz;
tot += (w * swampcnt[xx][zz-1]) + ((scale - w) * s0);
}
else if(sz > scale) {
w = sz - scale;
tot += (w * swampcnt[xx][zz+1]) + ((scale - w) * s0);
}
else {
tot += scale * s0;
}
return tot;
} }
public final double getRawBiomeTemperature() { public final double getRawBiomeTemperature() {