implement block get

This commit is contained in:
Jesse Boyd
2019-05-01 02:19:10 +10:00
parent 6692a2eb92
commit 33e119ccb6
39 changed files with 1234 additions and 198 deletions

View File

@ -3,5 +3,93 @@ package com.boydti.fawe.beta.implementation.blocks;
import com.boydti.fawe.beta.IBlocks;
public class CharBlocks implements IBlocks {
protected char[][] blocks;
public final char[][] blocks;
public final Section[] sections;
public CharBlocks() {
blocks = new char[16][];
sections = new Section[16];
for (int i = 0; i < 16; i++) sections[i] = NULL;
}
@Override
public boolean trim(boolean aggressive) {
boolean result = true;
for (int i = 0; i < 16; i++) {
if (sections[i] == NULL) {
blocks[i] = null;
} else {
result = false;
}
}
return result;
}
@Override
public void reset() {
for (int i = 0; i < 16; i++) sections[i] = NULL;
}
protected char[] load(int layer) {
return new char[4096];
}
protected char[] load(int layer, char[] data) {
for (int i = 0; i < 4096; i++) data[i] = 0;
return data;
}
@Override
public boolean hasSection(int layer) {
return sections[layer] == FULL;
}
public char get(int x, int y, int z) {
int layer = y >> 4;
int index = ((y & 15) << 8) | (z << 4) | (x & 15);
return sections[layer].get(this, layer, index);
}
public char set(int x, int y, int z, char value) {
int layer = y >> 4;
int index = ((y & 15) << 8) | (z << 4) | (x & 15);
return sections[layer].set(this, layer, index, value);
}
/*
Section
*/
public static abstract class Section {
public abstract char[] get(CharBlocks blocks, int layer);
public final char get(CharBlocks blocks, int layer, int index) {
return get(blocks, layer)[index];
}
public final char set(CharBlocks blocks, int layer, int index, char value) {
return get(blocks, layer)[index] = value;
}
}
public static final Section NULL = new Section() {
@Override
public final char[] get(CharBlocks blocks, int layer) {
blocks.sections[layer] = FULL;
char[] arr = blocks.blocks[layer];
if (arr == null) {
arr = blocks.blocks[layer] = blocks.load(layer);
} else {
blocks.blocks[layer] = blocks.load(layer, arr);
}
return arr;
}
};
public static final Section FULL = new Section() {
@Override
public final char[] get(CharBlocks blocks, int layer) {
return blocks.blocks[layer];
}
};
}