FastAsyncWorldedit/core/src/main/java/com/boydti/fawe/example/CharFaweChunk.java

255 lines
6.0 KiB
Java
Raw Normal View History

package com.boydti.fawe.example;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.util.FaweQueue;
2016-04-26 21:51:22 +02:00
import com.boydti.fawe.util.MainUtil;
import com.sk89q.worldedit.world.biome.BaseBiome;
import java.util.Arrays;
public abstract class CharFaweChunk<T> extends FaweChunk<T> {
2016-03-31 11:23:10 +02:00
public char[][] ids;
public short[] count;
public short[] air;
public short[] relight;
public int[][] biomes;
2016-03-31 11:23:10 +02:00
public T chunk;
2016-03-31 11:23:10 +02:00
/**
* A FaweSections object represents a chunk and the blocks that you wish to change in it.
*
* @param parent
* @param x
* @param z
*/
public CharFaweChunk(FaweQueue parent, int x, int z) {
super(parent, x, z);
2016-03-31 11:23:10 +02:00
this.ids = new char[16][];
this.count = new short[16];
this.air = new short[16];
this.relight = new short[16];
}
2016-03-31 11:23:10 +02:00
@Override
public T getChunk() {
2016-03-31 11:23:10 +02:00
if (this.chunk == null) {
this.chunk = getNewChunk();
}
2016-03-31 11:23:10 +02:00
return this.chunk;
}
2016-03-31 11:23:10 +02:00
public abstract T getNewChunk();
@Override
public void setLoc(final FaweQueue parent, int x, int z) {
super.setLoc(parent, x, z);
2016-03-31 11:23:10 +02:00
this.chunk = null;
}
2016-03-31 11:23:10 +02:00
/**
* Get the number of block changes in a specified section
* @param i
* @return
*/
public int getCount(final int i) {
2016-03-31 11:23:10 +02:00
return this.count[i];
}
2016-03-31 11:23:10 +02:00
public int getAir(final int i) {
2016-03-31 11:23:10 +02:00
return this.air[i];
}
2016-03-31 11:23:10 +02:00
public void setCount(final int i, final short value) {
this.count[i] = value;
}
/**
* Get the number of block changes in a specified section
* @param i
* @return
*/
public int getRelight(final int i) {
2016-03-31 11:23:10 +02:00
return this.relight[i];
}
public int getTotalCount() {
int total = 0;
for (int i = 0; i < 16; i++) {
total += Math.min(4096, this.count[i]);
}
return total;
}
2016-03-31 11:23:10 +02:00
public int getTotalRelight() {
2016-03-31 11:23:10 +02:00
if ((this.getTotalCount() == 0) && (this.biomes == null)) {
Arrays.fill(this.count, (short) 1);
Arrays.fill(this.relight, Short.MAX_VALUE);
return Short.MAX_VALUE;
}
int total = 0;
for (int i = 0; i < 16; i++) {
2016-03-31 11:23:10 +02:00
total += this.relight[i];
}
return total;
}
2016-03-31 11:23:10 +02:00
/**
* Get the raw data for a section
* @param i
* @return
*/
public char[] getIdArray(final int i) {
2016-03-31 11:23:10 +02:00
return this.ids[i];
}
2016-03-31 11:23:10 +02:00
2016-04-19 17:22:36 +02:00
public char[][] getIdArrays() {
return this.ids;
}
public int[][] getBiomeArray() {
2016-03-31 11:23:10 +02:00
return this.biomes;
}
@Override
public void setBlock(final int x, final int y, final int z, final int id, byte data) {
final int i = FaweCache.CACHE_I[y][x][z];
final int j = FaweCache.CACHE_J[y][x][z];
2016-03-31 11:23:10 +02:00
char[] vs = this.ids[i];
if (vs == null) {
2016-03-31 11:23:10 +02:00
vs = this.ids[i] = new char[4096];
this.count[i]++;
} else if (vs[j] == 0) {
2016-03-31 11:23:10 +02:00
this.count[i]++;
}
switch (id) {
case 0:
2016-03-31 11:23:10 +02:00
this.air[i]++;
vs[j] = (char) 1;
return;
case 10:
case 11:
case 39:
case 40:
case 51:
case 74:
case 89:
case 122:
case 124:
case 138:
case 169:
2016-03-31 11:23:10 +02:00
this.relight[i]++;
case 2:
case 4:
case 13:
case 14:
case 15:
case 20:
case 21:
case 22:
case 30:
case 32:
case 37:
case 41:
case 42:
case 45:
case 46:
case 47:
case 48:
case 49:
case 56:
case 57:
case 58:
case 60:
case 7:
case 8:
case 9:
case 73:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 85:
case 87:
case 88:
case 101:
case 102:
case 103:
case 110:
case 112:
case 113:
case 121:
case 129:
case 133:
case 165:
case 166:
case 170:
case 172:
case 173:
case 174:
case 181:
case 182:
case 188:
case 189:
case 190:
case 191:
case 192:
vs[j] = (char) (id << 4);
return;
case 130:
2016-01-12 13:07:34 +01:00
case 76:
case 62:
case 50:
2016-03-31 11:23:10 +02:00
this.relight[i]++;
case 54:
case 146:
case 61:
case 65:
case 68:
// if (data < 2) {
// data = 2;
// }
default:
vs[j] = (char) ((id << 4) + data);
return;
}
}
2016-03-31 11:23:10 +02:00
@Override
2016-03-31 11:23:10 +02:00
public void setBiome(final int x, final int z, final BaseBiome biome) {
if (this.biomes == null) {
this.biomes = new int[16][];
}
2016-03-31 11:23:10 +02:00
int[] index = this.biomes[x];
if (index == null) {
2016-03-31 11:23:10 +02:00
index = this.biomes[x] = new int[16];
}
index[z] = biome.getId();
}
2016-04-26 21:51:22 +02:00
@Override
public CharFaweChunk<T> copy(boolean shallow) {
CharFaweChunk<T> copy = (CharFaweChunk<T>) getParent().getChunk(getX(), getZ());
2016-04-26 21:51:22 +02:00
if (shallow) {
copy.ids = ids;
copy.air = air;
copy.biomes = biomes;
copy.chunk = chunk;
copy.count = count;
copy.relight = relight;
} else {
copy.ids = (char[][]) MainUtil.copyNd(ids);
copy.air = air.clone();
copy.biomes = biomes.clone();
copy.chunk = chunk;
copy.count = count.clone();
copy.relight = relight.clone();
}
return copy;
}
}