Fix lack of handling of custom world heights in CharFilterBlock

This commit is contained in:
dordsor21 2021-09-20 14:15:08 +01:00
parent 7a9cbe5d77
commit 17a97f2f19
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
2 changed files with 21 additions and 58 deletions

View File

@ -31,6 +31,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
private static final SetDelegate FULL = (block, value) -> block.setArr[block.index] = value; private static final SetDelegate FULL = (block, value) -> block.setArr[block.index] = value;
private static final SetDelegate NULL = (block, value) -> block.initSet().set(block, value); private static final SetDelegate NULL = (block, value) -> block.initSet().set(block, value);
private int maxLayer;
private int minLayer;
private CharGetBlocks get; private CharGetBlocks get;
private IChunkSet set; private IChunkSet set;
private char[] getArr; private char[] getArr;
@ -65,6 +67,8 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public final ChunkFilterBlock initLayer(IBlocks iget, IChunkSet iset, int layer) { public final ChunkFilterBlock initLayer(IBlocks iget, IChunkSet iset, int layer) {
this.get = (CharGetBlocks) iget; this.get = (CharGetBlocks) iget;
minLayer = this.get.getMinSectionPosition();
maxLayer = this.get.getMaxSectionPosition();
this.layer = layer; this.layer = layer;
if (!iget.hasSection(layer)) { if (!iget.hasSection(layer)) {
getArr = FaweCache.IMP.EMPTY_CHAR_4096; getArr = FaweCache.IMP.EMPTY_CHAR_4096;
@ -327,7 +331,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (y > 0) { if (y > 0) {
return states[getArr[index - 256]]; return states[getArr[index - 256]];
} }
if (layer > 0) { if (layer > minLayer) {
final int newLayer = layer - 1; final int newLayer = layer - 1;
final CharGetBlocks chunk = this.get; final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index + 3840)]; return states[chunk.sections[newLayer].get(chunk, newLayer, index + 3840)];
@ -340,7 +344,7 @@ public class CharFilterBlock extends ChunkFilterBlock {
if (y < 16) { if (y < 16) {
return states[getArr[index + 256]]; return states[getArr[index + 256]];
} }
if (layer < 16) { if (layer < maxLayer) {
final int newLayer = layer + 1; final int newLayer = layer + 1;
final CharGetBlocks chunk = this.get; final CharGetBlocks chunk = this.get;
return states[chunk.sections[newLayer].get(chunk, newLayer, index - 3840)]; return states[chunk.sections[newLayer].get(chunk, newLayer, index - 3840)];
@ -352,52 +356,12 @@ public class CharFilterBlock extends ChunkFilterBlock {
public final BlockState getBlockRelativeY(int y) { public final BlockState getBlockRelativeY(int y) {
final int newY = this.y + y; final int newY = this.y + y;
final int layerAdd = newY >> 4; final int layerAdd = newY >> 4;
switch (layerAdd) { if (layerAdd == 0) {
case 0: return states[getArr[this.index + (y << 8)]];
return states[getArr[this.index + (y << 8)]]; } else if ((layerAdd > 0 && layerAdd < (maxLayer - layer)) || (layerAdd < 0 && layerAdd < (minLayer - layer))) {
case 1: final int newLayer = layer + layerAdd;
case 2: final int index = this.index + ((y & 15) << 8);
case 3: return states[get.sections[newLayer].get(get, newLayer, index)];
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15: {
final int newLayer = layer + layerAdd;
if (newLayer < 16) {
final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)];
}
break;
}
case -1:
case -2:
case -3:
case -4:
case -5:
case -6:
case -7:
case -8:
case -9:
case -10:
case -11:
case -12:
case -13:
case -14:
case -15:
final int newLayer = layer + layerAdd;
if (newLayer >= 0) {
final int index = this.index + ((y & 15) << 8);
return states[get.sections[newLayer].get(get, newLayer, index)];
}
break;
} }
return BlockTypes.__RESERVED__.getDefaultState(); return BlockTypes.__RESERVED__.getDefaultState();
} }

View File

@ -211,34 +211,33 @@ public abstract class CharBlocks implements IBlocks {
*/ */
public final char get(int layer, int index) { public final char get(int layer, int index) {
layer -= minSectionPosition; return sections[layer - minSectionPosition].get(this, layer, index);
return sections[layer].get(this, layer, index);
} }
public final void set(int layer, int index, char value) throws public final void set(int layer, int index, char value) throws ArrayIndexOutOfBoundsException {
ArrayIndexOutOfBoundsException { sections[layer - minSectionPosition].set(this, layer, index, value);
layer -= minSectionPosition;
sections[layer].set(this, layer, index, value);
} }
public abstract static class Section { public abstract static class Section {
public abstract char[] get(CharBlocks blocks, int layer); abstract char[] get(CharBlocks blocks, int layer);
public abstract char[] get(CharBlocks blocks, int layer, boolean aggressive); abstract char[] get(CharBlocks blocks, int layer, boolean aggressive);
public abstract boolean isFull(); public abstract boolean isFull();
public final char get(CharBlocks blocks, int layer, int index) { public final char get(CharBlocks blocks, int layer, int index) {
char[] section = get(blocks, layer); int normalized = layer - blocks.minSectionPosition;
char[] section = get(blocks, normalized);
if (section == null) { if (section == null) {
blocks.reset(layer); blocks.reset(layer);
section = blocks.empty.get(blocks, layer, false); section = blocks.empty.get(blocks, normalized, false);
} }
return section[index]; return section[index];
} }
public final synchronized void set(CharBlocks blocks, int layer, int index, char value) { public final synchronized void set(CharBlocks blocks, int layer, int index, char value) {
layer -= blocks.minSectionPosition;
get(blocks, layer)[index] = value; get(blocks, layer)[index] = value;
} }