2016-04-29 23:24:59 +02:00
|
|
|
package com.boydti.fawe.example;
|
2015-11-18 08:49:57 +01:00
|
|
|
|
|
|
|
import com.boydti.fawe.FaweCache;
|
|
|
|
import com.boydti.fawe.object.FaweChunk;
|
2016-04-03 20:03:35 +02:00
|
|
|
import com.boydti.fawe.util.FaweQueue;
|
2016-04-26 21:51:22 +02:00
|
|
|
import com.boydti.fawe.util.MainUtil;
|
2015-11-18 08:49:57 +01:00
|
|
|
import com.sk89q.worldedit.world.biome.BaseBiome;
|
2016-04-03 20:03:35 +02:00
|
|
|
import java.util.Arrays;
|
2015-11-18 08:49:57 +01:00
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
public abstract class CharFaweChunk<T> extends FaweChunk<T> {
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2016-04-29 23:24:59 +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
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
public T chunk;
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
/**
|
|
|
|
* A FaweSections object represents a chunk and the blocks that you wish to change in it.
|
2016-04-29 23:24:59 +02:00
|
|
|
*
|
|
|
|
* @param parent
|
|
|
|
* @param x
|
|
|
|
* @param z
|
2015-11-18 08:49:57 +01:00
|
|
|
*/
|
2016-04-29 23:24:59 +02:00
|
|
|
public CharFaweChunk(FaweQueue parent, int x, int z) {
|
2016-04-03 20:03:35 +02:00
|
|
|
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];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
@Override
|
2016-04-29 23:24:59 +02:00
|
|
|
public T getChunk() {
|
2016-03-31 11:23:10 +02:00
|
|
|
if (this.chunk == null) {
|
2016-04-29 23:24:59 +02:00
|
|
|
this.chunk = getNewChunk();
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
return this.chunk;
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2016-04-29 23:24:59 +02:00
|
|
|
public abstract T getNewChunk();
|
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
@Override
|
2016-04-03 20:03:35 +02:00
|
|
|
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;
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01: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];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
public int getAir(final int i) {
|
2016-03-31 11:23:10 +02:00
|
|
|
return this.air[i];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 11:23:10 +02:00
|
|
|
public void setCount(final int i, final short value) {
|
|
|
|
this.count[i] = value;
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getTotalCount() {
|
|
|
|
int total = 0;
|
|
|
|
for (int i = 0; i < 16; i++) {
|
2016-05-01 03:10:39 +02:00
|
|
|
total += Math.min(4096, this.count[i]);
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01: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);
|
2015-11-18 08:49:57 +01:00
|
|
|
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];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01: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];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2016-04-19 17:22:36 +02:00
|
|
|
public char[][] getIdArrays() {
|
|
|
|
return this.ids;
|
|
|
|
}
|
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
public int[][] getBiomeArray() {
|
2016-03-31 11:23:10 +02:00
|
|
|
return this.biomes;
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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];
|
2015-11-18 08:49:57 +01:00
|
|
|
if (vs == null) {
|
2016-03-31 11:23:10 +02:00
|
|
|
vs = this.ids[i] = new char[4096];
|
|
|
|
this.count[i]++;
|
2015-11-18 08:49:57 +01:00
|
|
|
} else if (vs[j] == 0) {
|
2016-03-31 11:23:10 +02:00
|
|
|
this.count[i]++;
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
switch (id) {
|
|
|
|
case 0:
|
2016-03-31 11:23:10 +02:00
|
|
|
this.air[i]++;
|
2015-11-18 08:49:57 +01:00
|
|
|
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]++;
|
2015-11-18 08:49:57 +01:00
|
|
|
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:
|
2015-11-18 08:49:57 +01:00
|
|
|
case 62:
|
2016-04-29 23:24:59 +02:00
|
|
|
case 50:
|
2016-03-31 11:23:10 +02:00
|
|
|
this.relight[i]++;
|
2015-11-18 08:49:57 +01:00
|
|
|
case 54:
|
|
|
|
case 146:
|
|
|
|
case 61:
|
|
|
|
case 65:
|
|
|
|
case 68:
|
2016-04-29 23:24:59 +02:00
|
|
|
// if (data < 2) {
|
|
|
|
// data = 2;
|
|
|
|
// }
|
|
|
|
|
2015-11-18 08:49:57 +01:00
|
|
|
default:
|
|
|
|
vs[j] = (char) ((id << 4) + data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
|
2015-11-18 08:49:57 +01: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][];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
2016-03-31 11:23:10 +02:00
|
|
|
int[] index = this.biomes[x];
|
2015-11-18 08:49:57 +01:00
|
|
|
if (index == null) {
|
2016-03-31 11:23:10 +02:00
|
|
|
index = this.biomes[x] = new int[16];
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|
|
|
|
index[z] = biome.getId();
|
|
|
|
}
|
2016-04-26 21:51:22 +02:00
|
|
|
|
|
|
|
@Override
|
2016-04-29 23:24:59 +02:00
|
|
|
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;
|
|
|
|
}
|
2015-11-18 08:49:57 +01:00
|
|
|
}
|