From e8033dc18fa992cc06f729ed6e76b4f8e9191c1c Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 29 Jan 2023 22:20:58 -0800 Subject: [PATCH] Fixed bugs. Currently only works with seed-start at 0,0 --- .../biomes/AbstractBoxedBiomeProvider.java | 8 ++++--- .../biomes/AbstractCopyBiomeProvider.java | 18 ++++++++++----- .../biomes/AbstractSeedBiomeProvider.java | 22 +++++++++++-------- .../chunks/AbstractBoxedChunkGenerator.java | 21 +++++++++++++----- .../chunks/BoxedChunkGenerator.java | 2 +- src/main/resources/config.yml | 8 +++---- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractBoxedBiomeProvider.java b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractBoxedBiomeProvider.java index eadd2a0..b572b44 100644 --- a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractBoxedBiomeProvider.java +++ b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractBoxedBiomeProvider.java @@ -19,10 +19,12 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.generator.BiomeProvider; import org.bukkit.generator.WorldInfo; import org.bukkit.util.Vector; +import org.eclipse.jdt.annotation.Nullable; import com.google.common.base.Enums; import world.bentobox.boxed.Boxed; +import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; /** @@ -88,14 +90,14 @@ public abstract class AbstractBoxedBiomeProvider extends BiomeProvider { int chunkZ = z >> 4; chunkX = BoxedChunkGenerator.repeatCalc(chunkX); 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) { int xx = Math.floorMod(x, 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. if (!b.equals(Biome.CUSTOM) && (b.equals(Biome.DRIPSTONE_CAVES) || b.equals(Biome.LUSH_CAVES) || b.equals(Biome.RIVER) || b.equals(Biome.DEEP_DARK))) { diff --git a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractCopyBiomeProvider.java b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractCopyBiomeProvider.java index 6a06525..9cbdec0 100644 --- a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractCopyBiomeProvider.java +++ b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractCopyBiomeProvider.java @@ -8,8 +8,12 @@ import org.bukkit.World.Environment; import org.bukkit.block.Biome; import org.bukkit.generator.BiomeProvider; 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.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; /** @@ -32,19 +36,21 @@ public abstract class AbstractCopyBiomeProvider extends BiomeProvider { @Override public Biome getBiome(WorldInfo worldInfo, int x, int y, int z) { - int chunkX = (int)((double)x/16); - int chunkZ = (int)((double)z/16); + int chunkX = x >> 4; + int chunkZ = z >> 4; chunkX = BoxedChunkGenerator.repeatCalc(chunkX); 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) { int xx = Math.floorMod(x, 16); int zz = Math.floorMod(z, 16); - int yy = Math.max(Math.min(y * 4, worldInfo.getMaxHeight()), worldInfo.getMinHeight()); // To handle bug in Spigot - - return c.getBiome(xx, yy, zz); + //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); + BentoBox.getInstance().logDebug(biome); + return biome; } else { + BentoBox.getInstance().logDebug("Snapshot at " + chunkX + " " + chunkZ + " is not stored"); return defaultBiome; } } diff --git a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java index 7ea5326..30eea46 100644 --- a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java +++ b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java @@ -25,9 +25,11 @@ import org.eclipse.jdt.annotation.NonNull; import com.google.common.base.Enums; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.util.Pair; import world.bentobox.boxed.Boxed; import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator; +import world.bentobox.boxed.generators.chunks.AbstractBoxedChunkGenerator.ChunkStore; import world.bentobox.boxed.generators.chunks.BoxedChunkGenerator; /** @@ -120,7 +122,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { int chunkX = BoxedChunkGenerator.repeatCalc(x >> 4); int chunkZ = BoxedChunkGenerator.repeatCalc(z >> 4); // Get the stored snapshot - ChunkSnapshot snapshot = this.seedGen.getChunk(chunkX, chunkZ); + ChunkStore snapshot = this.seedGen.getChunk(chunkX, chunkZ); if (snapshot == null) { // This snapshot is not stored... return defaultBiome; @@ -128,9 +130,10 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { // Get the in-chunk coordinates int xx = Math.floorMod(x, 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.getBiome(xx, yy, zz); + Biome b = snapshot.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome); + return Objects.requireNonNull(b); } @@ -143,7 +146,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { * @return Biome */ private Biome getMappedBiome(WorldInfo worldInfo, int x, int y, int z) { - + // Custom biomes are not 3D yet if (y < DEPTH) { Biome result = getVanillaBiome(worldInfo, x, y, z); @@ -156,10 +159,10 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { */ // Try to get the cached value - Biome result = biomeCache.get((new Pair(x,z))); - if (result != null) { - return result; - } + //Biome result = biomeCache.get((new Pair(x,z))); + //if (result != null) { + //return result; + //} Vector s = new Vector(x, 0, z); Vector l = new Vector(spawnX,0,spawnZ); double dis = l.distance(s); @@ -168,6 +171,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { return getVanillaBiome(worldInfo, x, y, z); } // Provide custom biomes + Biome result; double d = dis / dist; // Normalize Vector direction = s.subtract(l); if (direction.getBlockX() <= 0 && direction.getBlockZ() <= 0) { @@ -185,7 +189,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider { } // Cache good result - biomeCache.put(new Pair(x,z), result); + //biomeCache.put(new Pair(x,z), result); return result; } diff --git a/src/main/java/world/bentobox/boxed/generators/chunks/AbstractBoxedChunkGenerator.java b/src/main/java/world/bentobox/boxed/generators/chunks/AbstractBoxedChunkGenerator.java index ee8c8b1..8009aa9 100644 --- a/src/main/java/world/bentobox/boxed/generators/chunks/AbstractBoxedChunkGenerator.java +++ b/src/main/java/world/bentobox/boxed/generators/chunks/AbstractBoxedChunkGenerator.java @@ -7,6 +7,7 @@ import java.util.Map; import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator; import org.bukkit.util.Vector; import org.eclipse.jdt.annotation.Nullable; @@ -26,7 +27,7 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator { protected final Boxed addon; protected static int size; protected Map, ChunkStore> chunks = new HashMap<>(); - public record ChunkStore(ChunkSnapshot snapshot, List bpEnts, List chests) {}; + public record ChunkStore(ChunkSnapshot snapshot, List bpEnts, List chests, Map chunkBiomes) {}; public record EntityData(Vector relativeLoc, BlueprintEntity entity) {}; public record ChestData(Vector relativeLoc, BlueprintBlock chest) {}; @@ -44,7 +45,15 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator { * @param chunk the chunk to set */ 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 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 getEnts(Chunk chunk); @@ -52,14 +61,14 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator { protected abstract List 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 z chunk z - * @return chunk snapshot or null if there is none + * @return chunk store or null if there is none */ @Nullable - public ChunkSnapshot getChunk(int x, int z) { - return chunks.get(new Pair<>(x, z)).snapshot; + public ChunkStore getChunk(int x, int z) { + return chunks.get(new Pair<>(x, z)); } @Override diff --git a/src/main/java/world/bentobox/boxed/generators/chunks/BoxedChunkGenerator.java b/src/main/java/world/bentobox/boxed/generators/chunks/BoxedChunkGenerator.java index f809b0a..05cebf9 100644 --- a/src/main/java/world/bentobox/boxed/generators/chunks/BoxedChunkGenerator.java +++ b/src/main/java/world/bentobox/boxed/generators/chunks/BoxedChunkGenerator.java @@ -194,7 +194,7 @@ public class BoxedChunkGenerator extends AbstractBoxedChunkGenerator { int minY = worldInfo.getMinHeight(); int xx = repeatCalc(chunkX); int zz = repeatCalc(chunkZ); - ChunkSnapshot chunk = this.getChunk(xx,zz); + ChunkSnapshot chunk = this.getChunk(xx,zz).snapshot(); if (chunk == null) { // This should never be needed because islands should abut each other //cd.setRegion(0, minY, 0, 16, 0, 16, Material.WATER); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8771f83..a539303 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -34,12 +34,12 @@ world: seed-start: normal: # Area seed center. This is where the areas are copied from. - x: 9920 - z: 9856 + x: 0 + z: 0 nether: # Nether area seed center. This is where the areas are copied from. - x: 9999 - z: 10015 + x: 0 + z: 0 end: # End area seed center. This is where the areas are copied from. x: 0