Fixed bugs. Currently only works with seed-start at 0,0

This commit is contained in:
tastybento 2023-01-29 22:20:58 -08:00
parent 54a559fc79
commit e8033dc18f
6 changed files with 50 additions and 29 deletions

View File

@ -19,10 +19,12 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.WorldInfo; import org.bukkit.generator.WorldInfo;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
import com.google.common.base.Enums; import com.google.common.base.Enums;
import world.bentobox.boxed.Boxed; import world.bentobox.boxed.Boxed;
import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore;
import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator;
/** /**
@ -88,14 +90,14 @@ public abstract class AbstractBoxedBiomeProvider extends BiomeProvider {
int chunkZ = z >> 4; int chunkZ = z >> 4;
chunkX = BoxedChunkGenerator.repeatCalc(chunkX); chunkX = BoxedChunkGenerator.repeatCalc(chunkX);
chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ); chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ);
ChunkSnapshot c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ); @Nullable ChunkStore c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ);
if (c != null) { if (c != null) {
int xx = Math.floorMod(x, 16); int xx = Math.floorMod(x, 16);
int zz = Math.floorMod(z, 16); int zz = Math.floorMod(z, 16);
int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot //int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot
Biome b = c.getBiome(xx, yy, zz); Biome b = c.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
// Some biomes should stay from the seed world. These are mostly underground biomes. // Some biomes should stay from the seed world. These are mostly underground biomes.
if (!b.equals(Biome.CUSTOM) && (b.equals(Biome.DRIPSTONE_CAVES) || b.equals(Biome.LUSH_CAVES) if (!b.equals(Biome.CUSTOM) && (b.equals(Biome.DRIPSTONE_CAVES) || b.equals(Biome.LUSH_CAVES)
|| b.equals(Biome.RIVER) || b.equals(Biome.DEEP_DARK))) { || b.equals(Biome.RIVER) || b.equals(Biome.DEEP_DARK))) {

View File

@ -8,8 +8,12 @@ import org.bukkit.World.Environment;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.WorldInfo; import org.bukkit.generator.WorldInfo;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.boxed.Boxed; import world.bentobox.boxed.Boxed;
import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore;
import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator;
/** /**
@ -32,19 +36,21 @@ public abstract class AbstractCopyBiomeProvider extends BiomeProvider {
@Override @Override
public Biome getBiome(WorldInfo worldInfo, int x, int y, int z) { public Biome getBiome(WorldInfo worldInfo, int x, int y, int z) {
int chunkX = (int)((double)x/16); int chunkX = x >> 4;
int chunkZ = (int)((double)z/16); int chunkZ = z >> 4;
chunkX = BoxedChunkGenerator.repeatCalc(chunkX); chunkX = BoxedChunkGenerator.repeatCalc(chunkX);
chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ); chunkZ = BoxedChunkGenerator.repeatCalc(chunkZ);
ChunkSnapshot c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ); @Nullable ChunkStore c = addon.getChunkGenerator(worldInfo.getEnvironment()).getChunk(chunkX, chunkZ);
if (c != null) { if (c != null) {
int xx = Math.floorMod(x, 16); int xx = Math.floorMod(x, 16);
int zz = Math.floorMod(z, 16); int zz = Math.floorMod(z, 16);
int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot //int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot
Biome biome = c.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
return c.getBiome(xx, yy, zz); BentoBox.getInstance().logDebug(biome);
return biome;
} else { } else {
BentoBox.getInstance().logDebug("Snapshot at " + chunkX + " " + chunkZ + " is not stored");
return defaultBiome; return defaultBiome;
} }
} }

View File

@ -25,9 +25,11 @@ import org.eclipse.jdt.annotation.NonNull;
import com.google.common.base.Enums; import com.google.common.base.Enums;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.util.Pair; import world.bentobox.bentobox.util.Pair;
import world.bentobox.boxed.Boxed; import world.bentobox.boxed.Boxed;
import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator; import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator;
import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore;
import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator;
/** /**
@ -120,7 +122,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
int chunkX = BoxedChunkGenerator.repeatCalc(x >> 4); int chunkX = BoxedChunkGenerator.repeatCalc(x >> 4);
int chunkZ = BoxedChunkGenerator.repeatCalc(z >> 4); int chunkZ = BoxedChunkGenerator.repeatCalc(z >> 4);
// Get the stored snapshot // Get the stored snapshot
ChunkSnapshot snapshot = this.seedGen.getChunk(chunkX, chunkZ); ChunkStore snapshot = this.seedGen.getChunk(chunkX, chunkZ);
if (snapshot == null) { if (snapshot == null) {
// This snapshot is not stored... // This snapshot is not stored...
return defaultBiome; return defaultBiome;
@ -128,9 +130,10 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
// Get the in-chunk coordinates // Get the in-chunk coordinates
int xx = Math.floorMod(x, 16); int xx = Math.floorMod(x, 16);
int zz = Math.floorMod(z, 16); int zz = Math.floorMod(z, 16);
int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot //int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot
Biome b = snapshot.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
Biome b = snapshot.getBiome(xx, yy, zz);
return Objects.requireNonNull(b); return Objects.requireNonNull(b);
} }
@ -156,10 +159,10 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
*/ */
// Try to get the cached value // Try to get the cached value
Biome result = biomeCache.get((new Pair<Integer, Integer>(x,z))); //Biome result = biomeCache.get((new Pair<Integer, Integer>(x,z)));
if (result != null) { //if (result != null) {
return result; //return result;
} //}
Vector s = new Vector(x, 0, z); Vector s = new Vector(x, 0, z);
Vector l = new Vector(spawnX,0,spawnZ); Vector l = new Vector(spawnX,0,spawnZ);
double dis = l.distance(s); double dis = l.distance(s);
@ -168,6 +171,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
return getVanillaBiome(worldInfo, x, y, z); return getVanillaBiome(worldInfo, x, y, z);
} }
// Provide custom biomes // Provide custom biomes
Biome result;
double d = dis / dist; // Normalize double d = dis / dist; // Normalize
Vector direction = s.subtract(l); Vector direction = s.subtract(l);
if (direction.getBlockX() <= 0 && direction.getBlockZ() <= 0) { if (direction.getBlockX() <= 0 && direction.getBlockZ() <= 0) {
@ -185,7 +189,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
} }
// Cache good result // Cache good result
biomeCache.put(new Pair<Integer, Integer>(x,z), result); //biomeCache.put(new Pair<Integer, Integer>(x,z), result);
return result; return result;
} }

View File

@ -7,6 +7,7 @@ import java.util.Map;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -26,7 +27,7 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator {
protected final Boxed addon; protected final Boxed addon;
protected static int size; protected static int size;
protected Map<Pair<Integer, Integer>, ChunkStore> chunks = new HashMap<>(); protected Map<Pair<Integer, Integer>, ChunkStore> chunks = new HashMap<>();
public record ChunkStore(ChunkSnapshot snapshot, List<EntityData> bpEnts, List<ChestData> chests) {}; public record ChunkStore(ChunkSnapshot snapshot, List<EntityData> bpEnts, List<ChestData> chests, Map<Vector, Biome> chunkBiomes) {};
public record EntityData(Vector relativeLoc, BlueprintEntity entity) {}; public record EntityData(Vector relativeLoc, BlueprintEntity entity) {};
public record ChestData(Vector relativeLoc, BlueprintBlock chest) {}; public record ChestData(Vector relativeLoc, BlueprintBlock chest) {};
@ -44,7 +45,15 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator {
* @param chunk the chunk to set * @param chunk the chunk to set
*/ */
public void setChunk(int x, int z, Chunk chunk) { public void setChunk(int x, int z, Chunk chunk) {
chunks.put(new Pair<>(x, z), new ChunkStore(chunk.getChunkSnapshot(false, true, false), getEnts(chunk), getChests(chunk))); Map<Vector, Biome> chunkBiomes = new HashMap<>();
for (int xx = 0; xx < 16; xx+=4) {
for (int zz = 0; zz < 16; zz+=4) {
for (int yy = chunk.getWorld().getMinHeight(); yy < chunk.getWorld().getMaxHeight(); yy+=4) { // TODO: every 4th yy?
chunkBiomes.put(new Vector(xx, yy, zz), chunk.getBlock(xx, yy, zz).getBiome());
}
}
}
chunks.put(new Pair<>(x, z), new ChunkStore(chunk.getChunkSnapshot(), getEnts(chunk), getChests(chunk), chunkBiomes));
} }
protected abstract List<EntityData> getEnts(Chunk chunk); protected abstract List<EntityData> getEnts(Chunk chunk);
@ -52,14 +61,14 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator {
protected abstract List<ChestData> getChests(Chunk chunk); protected abstract List<ChestData> getChests(Chunk chunk);
/** /**
* Get the chunk snapshot for these chunk coords or null if there is none. * Get the chunk store for these chunk coords or null if there is none.
* @param x chunk x * @param x chunk x
* @param z chunk z * @param z chunk z
* @return chunk snapshot or null if there is none * @return chunk store or null if there is none
*/ */
@Nullable @Nullable
public ChunkSnapshot getChunk(int x, int z) { public ChunkStore getChunk(int x, int z) {
return chunks.get(new Pair<>(x, z)).snapshot; return chunks.get(new Pair<>(x, z));
} }
@Override @Override

View File

@ -194,7 +194,7 @@ public class BoxedChunkGenerator extends AbstractBoxedChunkGenerator {
int minY = worldInfo.getMinHeight(); int minY = worldInfo.getMinHeight();
int xx = repeatCalc(chunkX); int xx = repeatCalc(chunkX);
int zz = repeatCalc(chunkZ); int zz = repeatCalc(chunkZ);
ChunkSnapshot chunk = this.getChunk(xx,zz); ChunkSnapshot chunk = this.getChunk(xx,zz).snapshot();
if (chunk == null) { if (chunk == null) {
// This should never be needed because islands should abut each other // This should never be needed because islands should abut each other
//cd.setRegion(0, minY, 0, 16, 0, 16, Material.WATER); //cd.setRegion(0, minY, 0, 16, 0, 16, Material.WATER);

View File

@ -34,12 +34,12 @@ world:
seed-start: seed-start:
normal: normal:
# Area seed center. This is where the areas are copied from. # Area seed center. This is where the areas are copied from.
x: 9920 x: 0
z: 9856 z: 0
nether: nether:
# Nether area seed center. This is where the areas are copied from. # Nether area seed center. This is where the areas are copied from.
x: 9999 x: 0
z: 10015 z: 0
end: end:
# End area seed center. This is where the areas are copied from. # End area seed center. This is where the areas are copied from.
x: 0 x: 0