Now with correct math for repeating islands

This commit is contained in:
tastybento 2022-11-26 23:01:20 -08:00
parent 0da54b7530
commit 99e50f4af3
2 changed files with 22 additions and 20 deletions

View File

@ -85,8 +85,8 @@ public abstract class AbstractBoxedBiomeProvider extends BiomeProvider {
int chunkX = (int)((double)x/16);
int chunkZ = (int)((double)z/16);
int size = (int)(dist / 16D); // Convert to chunk
chunkX = Math.floorMod(chunkX, chunkX < 0 ? -size: size);
chunkZ = Math.floorMod(chunkZ, chunkZ < 0 ? -size : size);
chunkX = BoxedChunkGenerator.repeatCalc(chunkX, size);
chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ, size);
ChunkSnapshot c = addon.getChunkGenerator().getChunk(chunkX, chunkZ);
if (c != null) {

View File

@ -40,6 +40,7 @@ public class BoxedChunkGenerator extends ChunkGenerator {
* @param chunk the chunk to set
*/
public void setChunk(ChunkSnapshot chunk) {
// Make the coords always positive
chunks.putIfAbsent(new Pair<>(chunk.getX(), chunk.getZ()), chunk);
}
@ -49,9 +50,7 @@ public class BoxedChunkGenerator extends ChunkGenerator {
* @return chunk snapshot or null if there is none
*/
public ChunkSnapshot getChunk(int x, int z) {
int xx = Math.floorMod(x, size);
int zz = Math.floorMod(z, size);
return chunks.get(new Pair<>(xx, zz));
return chunks.get(new Pair<>(x, z));
}
/**
@ -72,11 +71,8 @@ public class BoxedChunkGenerator extends ChunkGenerator {
int height = worldInfo.getMaxHeight();
int minY = worldInfo.getMinHeight();
// Repeat islands
int xx = Math.floorMod(chunkX, chunkX < 0 ? -size: size);
int zz = Math.floorMod(chunkZ, chunkZ < 0 ? -size : size);
int xx = repeatCalc(chunkX, size);
int zz = repeatCalc(chunkZ, size);
Pair<Integer, Integer> coords = new Pair<>(xx, zz);
if (!chunks.containsKey(coords)) {
// This should never be needed because islands should abut each other
@ -112,6 +108,22 @@ public class BoxedChunkGenerator extends ChunkGenerator {
}
}
/**
* Calculates the repeating value for a given size
* @param chunkCoord chunk coord
* @param size
* @return mapped chunk coord
*/
public static int repeatCalc(int chunkCoord, int s) {
int xx;
if (chunkCoord > 0) {
xx = Math.floorMod(chunkCoord + s, s*2) - s;
} else {
xx = Math.floorMod(chunkCoord - s, -s*2) + s;
}
return xx;
}
/**
* @return the chunks
*/
@ -374,14 +386,4 @@ public class BoxedChunkGenerator extends ChunkGenerator {
return this.addon.getSettings().isAllowStructures();
}
public ChunkSnapshot getChunkFromXZ(int x, int z) {
int chunkX = (int)((double)x/16);
int chunkZ = (int)((double)z/16);
return this.getChunk(chunkX, chunkZ);
}
}