mirror of
https://github.com/BentoBoxWorld/Boxed.git
synced 2024-12-11 14:37:52 +01:00
Fixed bugs. Currently only works with seed-start at 0,0
This commit is contained in:
parent
54a559fc79
commit
e8033dc18f
@ -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))) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.chunkBiomes().getOrDefault(new Vector(xx, y, zz), defaultBiome);
|
||||
|
||||
Biome b = snapshot.getBiome(xx, yy, zz);
|
||||
return Objects.requireNonNull(b);
|
||||
}
|
||||
|
||||
@ -156,10 +159,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 +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<Integer, Integer>(x,z), result);
|
||||
//biomeCache.put(new Pair<Integer, Integer>(x,z), result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user