Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ local.properties
.loadpath
/target
target/
*.iml
.idea/

# Eclipse Core
.project
Expand Down Expand Up @@ -43,4 +45,4 @@ target/

# STS (Spring Tool Suite)
.springBeans
/target/
/target/
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@
<parent>
<groupId>com.github.civclassic</groupId>
<artifactId>civclassic-parent</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>

<groupId>com.github.devotedmc</groupId>
<artifactId>hiddenore</artifactId>
<version>1.7.2</version>
<version>1.8.1</version>
<name>HiddenOre</name>

<repositories>
<repository>
<id>civ-github-repo</id>
<url>https://raw.githubusercontent.com/CivClassic/artifacts/master/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
* @author soerxpso, programmerdan
*/
public class BreakTracking {
private static final int POS_LAYERS = 320;
private static final int NEG_LAYERS = 64;
private static final int TOTAL_LAYERS = POS_LAYERS + NEG_LAYERS;
private static final int GEN = 1;
private static final int MAP = 0;
Map<UUID, Map<Long, short[]>> track;
Expand Down Expand Up @@ -80,7 +83,7 @@ public void load() {

while (dis.readBoolean()) {
Long chunk = dis.readLong();
short[] layers = new short[256];
short[] layers = new short[TOTAL_LAYERS];
for (int i = 0; i < layers.length; i++) {
layers[i] = dis.readShort();
}
Expand Down Expand Up @@ -133,7 +136,7 @@ public void load() {

while (dis.readBoolean()) {
Long chunk = dis.readLong();
long[][][] layers = new long[2][256][4];
long[][][] layers = new long[2][TOTAL_LAYERS][4];
for (int i = 0; i < layers[MAP].length; i++) {
for (int j = 0; j < 4; j++) {
layers[MAP][i][j] = dis.readLong(); // "map"
Expand Down Expand Up @@ -330,29 +333,29 @@ public boolean trackGen(Location loc) {
mapLayers = new long[2][256][4];
mapChunks.put(chunk_id, mapLayers);

for (int y = 0; y < 256; y++) {
for (int y = -NEG_LAYERS; y < POS_LAYERS; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block b = chunk.getBlock(x, y, z);
if (b.isEmpty() || b.isLiquid()) {
int bloc = (( x << 4) + z);
int quad = (block_id / 64);
long mask = (1l << (bloc % 64));
mapLayers[MAP][y][quad] |= mask; // if unset, set. Ignore complements basis.
mapLayers[GEN][y][quad] |= mask; // tracks for "breaks" and "gens".
mapLayers[MAP][y+NEG_LAYERS][quad] |= mask; // if unset, set. Ignore complements basis.
mapLayers[GEN][y+NEG_LAYERS][quad] |= mask; // tracks for "breaks" and "gens".
}
}
}
}
}

boolean ret = false;
if ((mapLayers[GEN][Y][quad_id] & mask_id) == mask_id) {
if ((mapLayers[GEN][Y+NEG_LAYERS][quad_id] & mask_id) == mask_id) {
ret = false; // already broken!
} else {
ret = true; // new break according to this tracking.
mapLayers[MAP][Y][quad_id] |= mask_id;
mapLayers[GEN][Y][quad_id] |= mask_id;
mapLayers[MAP][Y+NEG_LAYERS][quad_id] |= mask_id;
mapLayers[GEN][Y+NEG_LAYERS][quad_id] |= mask_id;
}

s = System.currentTimeMillis() - s;
Expand Down Expand Up @@ -403,7 +406,7 @@ public boolean testGen(Location loc) {
return true;
}

if ((mapLayers[GEN][Y][quad_id] & mask_id) == mask_id) {
if ((mapLayers[GEN][Y+NEG_LAYERS][quad_id] & mask_id) == mask_id) {
return false;
} else {
return true;
Expand Down Expand Up @@ -449,28 +452,28 @@ public void postTrackBreak(Location loc, boolean exp) {
return; // should be init'd or this is being improperly called.
}

mapLayers[GEN][Y][quad_id] |= mask_id;
mapLayers[GEN][Y+NEG_LAYERS][quad_id] |= mask_id;
if (exp) {
if (Y > 0) mapLayers[GEN][Y-1][quad_id] |= mask_id;
if (Y < 255) mapLayers[GEN][Y+1][quad_id] |= mask_id;
if (Y > -NEG_LAYERS) mapLayers[GEN][Y-1][quad_id] |= mask_id;
if (Y < POS_LAYERS) mapLayers[GEN][Y+1][quad_id] |= mask_id;

if (X > 0) {
int nblock_id = (((X-1) << 4) + Z);
int nquad_id = (nblock_id / 64);
long nmask_id = (1l << (nblock_id % 64));
mapLayers[GEN][Y][nquad_id] |= nmask_id;
mapLayers[GEN][Y+NEG_LAYERS][nquad_id] |= nmask_id;
} else postTrackBreak(loc.clone().add(-1, 0, 0), false);
if (X < 15) {
int nblock_id = (((X+1) << 4) + Z);
int nquad_id = (nblock_id / 64);
long nmask_id = (1l << (nblock_id % 64));
mapLayers[GEN][Y][nquad_id] |= nmask_id;
mapLayers[GEN][Y+NEG_LAYERS][nquad_id] |= nmask_id;
} else postTrackBreak(loc.clone().add(1, 0, 0), false);
if (Z > 0) {
int nblock_id = (((X) << 4) + (Z-1));
int nquad_id = (nblock_id / 64);
long nmask_id = (1l << (nblock_id % 64));
mapLayers[GEN][Y][nquad_id] |= nmask_id;
mapLayers[GEN][Y+NEG_LAYERS][nquad_id] |= nmask_id;
} else postTrackBreak(loc.clone().add(0, 0, -1), false);
if (Z < 15) {
int nblock_id = (((X) << 4) + (Z+1));
Expand All @@ -481,7 +484,7 @@ public void postTrackBreak(Location loc, boolean exp) {
}
if (Config.isDebug) {
HiddenOre.getPlugin().getLogger()
.info("now world " + world + " chunk " + chunk_id + " gent " + mapLayers[GEN][Y][quad_id]);
.info("now world " + world + " chunk " + chunk_id + " gent " + mapLayers[GEN][Y+NEG_LAYERS][quad_id]);
}
s = System.currentTimeMillis() - s;
if (s > 10l) {
Expand Down Expand Up @@ -527,7 +530,7 @@ public boolean trackBreak(Location loc) {
short[] layers = chunks.get(chunk_id);
if (layers == null) { // init layers
initLayers = System.nanoTime();
layers = new short[256];
layers = new short[TOTAL_LAYERS];
chunks.put(chunk_id, layers);
initLayers = System.nanoTime() - initLayers;
}
Expand All @@ -547,11 +550,11 @@ public boolean trackBreak(Location loc) {
long[][][] mapLayers = mapChunks.get(chunk_id);
if (mapLayers == null) { // init layers
initMapLayers = System.nanoTime();
mapLayers = new long[2][256][4];
mapLayers = new long[2][TOTAL_LAYERS][4];
mapChunks.put(chunk_id, mapLayers);
ChunkSnapshot chunkS = chunk.getChunkSnapshot();

for (int y = 0; y < 256; y++) {
for (int y = -NEG_LAYERS; y < POS_LAYERS; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
//Block b = chunk.getBlock(x, y, z);
Expand All @@ -561,44 +564,44 @@ public boolean trackBreak(Location loc) {
int bloc = ((x << 4) + z);
int quad = (block_id / 64);
long mask = (1l << (bloc % 64));
mapLayers[MAP][y][quad] |= mask; // if unset, set. Ignore complements basis.
mapLayers[GEN][y][quad] |= mask; // tracks for "breaks" and "gens".
mapLayers[MAP][y+NEG_LAYERS][quad] |= mask; // if unset, set. Ignore complements basis.
mapLayers[GEN][y+NEG_LAYERS][quad] |= mask; // tracks for "breaks" and "gens".
}
}
}
}
initMapLayers = System.nanoTime() - initMapLayers;
}

if ((mapLayers[MAP][Y][quad_id] & mask_id) == mask_id) {
if ((mapLayers[MAP][Y+NEG_LAYERS][quad_id] & mask_id) == mask_id) {
ret = false; // already broken!
} else {
ret = true; // new break according to this tracking.
mapLayers[MAP][Y][quad_id] |= mask_id;
mapLayers[GEN][Y][quad_id] |= mask_id;
mapLayers[MAP][Y+NEG_LAYERS][quad_id] |= mask_id;
mapLayers[GEN][Y+NEG_LAYERS][quad_id] |= mask_id;
}

spc = mapLayers[MAP][Y][quad_id];
spc = mapLayers[MAP][Y+NEG_LAYERS][quad_id];
}

if (layers[Y] == 0) {
if (layers[Y+NEG_LAYERS] == 0) {
scanLayer = System.nanoTime();
// quick layer scan for air and water
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block b = chunk.getBlock(x, Y, z);
if (b.isEmpty() || b.isLiquid()) {
layers[Y]++;
layers[Y+NEG_LAYERS]++;
}
}
}
scanLayer = System.nanoTime() - scanLayer;
}

if (layers[Y] >= 256) { // done
if (layers[Y+NEG_LAYERS] >= TOTAL_LAYERS) { // done
ret = false;
} else if (ret) {
layers[Y]++; // represent new break in layer.
layers[Y+NEG_LAYERS]++; // represent new break in layer.
ret = true;
}
if (ret) {
Expand Down Expand Up @@ -626,7 +629,7 @@ public boolean trackBreak(Location loc) {

if (Config.isDebug) {
HiddenOre.getPlugin().getLogger()
.info("now world " + world + " chunk " + chunk_id + " layersum " + layers[Y] + " map" + quad_id + ":" + mask_id + "t " + spc);
.info("now world " + world + " chunk " + chunk_id + " layersum " + layers[Y+NEG_LAYERS] + " map" + quad_id + ":" + mask_id + "t " + spc);
}

s = System.currentTimeMillis() - s;
Expand Down
Loading