into develop
This commit is contained in:
tastybento 2023-02-11 08:32:58 -08:00
commit 77f182355e
5 changed files with 43 additions and 31 deletions

View File

@ -3,13 +3,16 @@ package world.bentobox.boxed.generators.biomes;
import java.util.Arrays;
import java.util.List;
import org.bukkit.ChunkSnapshot;
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 +35,19 @@ 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() - 1), worldInfo.getMinHeight()); // To handle bug in Spigot
return c.getBiome(xx, yy, zz);
Biome biome = c.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
return biome;
} else {
BentoBox.getInstance().logWarning("Snapshot at " + chunkX + " " + chunkZ + " is not stored");
return defaultBiome;
}
}

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -13,7 +12,6 @@ import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;
import org.bukkit.ChunkSnapshot;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.block.BlockFace;
@ -25,9 +23,9 @@ import org.eclipse.jdt.annotation.NonNull;
import com.google.common.base.Enums;
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;
/**
@ -51,7 +49,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
private final Boxed addon;
private final Biome defaultBiome;
private Map<Pair<Integer, Integer>, Biome> biomeCache = new HashMap<>();
//private Map<Pair<Integer, Integer>, Biome> biomeCache = new HashMap<>();
protected final int dist;
@ -120,7 +118,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 +126,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.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
Biome b = snapshot.getBiome(xx, yy, zz);
return Objects.requireNonNull(b);
}
@ -156,10 +155,10 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
*/
// Try to get the cached value
Biome result = biomeCache.get((new Pair<Integer, Integer>(x,z)));
if (result != null) {
return result;
}
//Biome result = biomeCache.get((new Pair<Integer, Integer>(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 +167,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 +185,7 @@ public abstract class AbstractSeedBiomeProvider extends BiomeProvider {
}
// Cache good result
biomeCache.put(new Pair<Integer, Integer>(x,z), result);
//biomeCache.put(new Pair<Integer, Integer>(x,z), result);
return result;
}

View File

@ -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<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 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<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);
@ -52,14 +61,14 @@ public abstract class AbstractBoxedChunkGenerator extends ChunkGenerator {
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 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

View File

@ -194,11 +194,11 @@ 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);
BentoBox.getInstance().logDebug("No chunks found for " + xx + " " + zz);
BentoBox.getInstance().logError("No chunks found for " + xx + " " + zz);
return;
}
// Copy the chunk

View File

@ -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