remove uses of TerraWorld#getBiomeProvider

This commit is contained in:
dfsek 2021-07-22 13:32:34 -07:00
parent a91a5019f8
commit 2948f25b50
13 changed files with 21 additions and 19 deletions

View File

@ -48,7 +48,7 @@ public class NoiseChunkGenerator3D implements TerraChunkGenerator {
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4); int zOrig = (chunkZ << 4);
long seed = world.getSeed(); long seed = world.getSeed();
BiomeProvider grid = main.getWorld(world).getBiomeProvider(); BiomeProvider grid = world.getBiomeProvider();
for(int x = 0; x < 4; x++) { for(int x = 0; x < 4; x++) {
for(int z = 0; z < 4; z++) { for(int z = 0; z < 4; z++) {
int cx = xOrig + (x << 2); int cx = xOrig + (x << 2);
@ -76,7 +76,7 @@ public class NoiseChunkGenerator3D implements TerraChunkGenerator {
public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) { public ChunkData generateChunkData(@NotNull World world, Random random, int chunkX, int chunkZ, ChunkData chunk) {
try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) { try(ProfileFrame ignore = main.getProfiler().profile("chunk_base_3d")) {
TerraWorld tw = main.getWorld(world); TerraWorld tw = main.getWorld(world);
BiomeProvider grid = tw.getBiomeProvider(); BiomeProvider grid = world.getBiomeProvider();
int xOrig = (chunkX << 4); int xOrig = (chunkX << 4);
int zOrig = (chunkZ << 4); int zOrig = (chunkZ << 4);
@ -169,7 +169,7 @@ public class NoiseChunkGenerator3D implements TerraChunkGenerator {
@Override @Override
public BlockState getBlock(World world, int x, int y, int z) { public BlockState getBlock(World world, int x, int y, int z) {
TerraWorld terraWorld = main.getWorld(world); TerraWorld terraWorld = main.getWorld(world);
BiomeProvider provider = terraWorld.getBiomeProvider(); BiomeProvider provider = world.getBiomeProvider();
TerraBiome biome = provider.getBiome(x, z, world.getSeed()); TerraBiome biome = provider.getBiome(x, z, world.getSeed());
Sampler sampler = terraWorld.getConfig().getSamplerCache().get(x, z); Sampler sampler = terraWorld.getConfig().getSamplerCache().get(x, z);

View File

@ -37,7 +37,7 @@ public class BiomeCommand implements CommandTemplate {
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
BiomeProvider provider = main.getWorld(player.world()).getBiomeProvider(); BiomeProvider provider = player.world().getBiomeProvider();
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.position(), player.world().getSeed()); UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(player.position(), player.world().getSeed());
sender.sendMessage("You are standing in " + biome.getID()); sender.sendMessage("You are standing in " + biome.getID());
} }

View File

@ -62,7 +62,7 @@ public class BiomeLocateCommand implements CommandTemplate {
Player player = (Player) sender; Player player = (Player) sender;
new Thread(new AsyncBiomeFinder(main.getWorld(player.world()).getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> { new Thread(new AsyncBiomeFinder(player.world().getBiomeProvider(), biome, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
if(location != null) { if(location != null) {
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position()))); sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", biome.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) { if(teleport) {

View File

@ -26,12 +26,12 @@ public class CarverCache {
public CarverCache(World w, TerraPlugin main, UserDefinedCarver carver) { public CarverCache(World w, TerraPlugin main, UserDefinedCarver carver) {
this.carver = carver; this.carver = carver;
cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getCarverCacheSize()) cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getCarverCacheSize())
.build(new CacheLoader<Long, List<Worm.WormPoint>>() { .build(new CacheLoader<>() {
@Override @Override
public List<Worm.WormPoint> load(@NotNull Long key) { public List<Worm.WormPoint> load(@NotNull Long key) {
int chunkX = (int) (key >> 32); int chunkX = (int) (key >> 32);
int chunkZ = (int) key.longValue(); int chunkZ = (int) key.longValue();
BiomeProvider provider = main.getWorld(w).getBiomeProvider(); BiomeProvider provider = w.getBiomeProvider();
if(CarverCache.this.carver.isChunkCarved(w, chunkX, chunkZ, new Random(PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + CarverCache.this.carver.hashCode())))) { if(CarverCache.this.carver.isChunkCarved(w, chunkX, chunkZ, new Random(PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + CarverCache.this.carver.hashCode())))) {
long seed = PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed()); long seed = PopulationUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
Random r = new Random(seed); Random r = new Random(seed);

View File

@ -31,7 +31,7 @@ public class OrePopulator implements TerraGenerationStage {
Random random = new Random(PopulationUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed())); Random random = new Random(PopulationUtil.getCarverChunkSeed(chunk.getX() + cx, chunk.getZ() + cz, world.getSeed()));
int originX = ((chunk.getX() + cx) << 4); int originX = ((chunk.getX() + cx) << 4);
int originZ = ((chunk.getZ() + cz) << 4); int originZ = ((chunk.getZ() + cz) << 4);
TerraBiome b = tw.getBiomeProvider().getBiome(originX + 8, originZ + 8, world.getSeed()); TerraBiome b = world.getBiomeProvider().getBiome(originX + 8, originZ + 8, world.getSeed());
/* /*
BiomeTemplate config = ((UserDefinedBiome) b).getConfig(); BiomeTemplate config = ((UserDefinedBiome) b).getConfig();
int finalCx = cx; int finalCx = cx;

View File

@ -34,7 +34,7 @@ public class StructurePopulator implements TerraGenerationStage, Chunkified {
int cx = (chunk.getX() << 4); int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4); int cz = (chunk.getZ() << 4);
BiomeProvider provider = tw.getBiomeProvider(); BiomeProvider provider = world.getBiomeProvider();
WorldConfig config = tw.getConfig(); WorldConfig config = tw.getConfig();
for(ConfiguredStructure conf : config.getRegistry(TerraStructure.class).entries()) { for(ConfiguredStructure conf : config.getRegistry(TerraStructure.class).entries()) {
Vector3 spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()); Vector3 spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed());

View File

@ -61,7 +61,7 @@ public class StructureLocateCommand implements CommandTemplate {
public void execute(CommandSender sender) { public void execute(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
new Thread(new AsyncStructureFinder(main.getWorld(player.world()).getBiomeProvider(), structure, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> { new Thread(new AsyncStructureFinder(player.world().getBiomeProvider(), structure, player.position().clone().multiply((1D / main.getTerraConfig().getBiomeSearchResolution())), player.world(), 0, radius, location -> {
if(location != null) { if(location != null) {
sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position()))); sender.sendMessage(String.format("The nearest %s is at [%d, ~, %d] (%.1f blocks away)", structure.getID().toLowerCase(Locale.ROOT), location.getBlockX(), location.getBlockZ(), location.add(new Vector3(0, player.position().getY(), 0)).distance(player.position())));
if(teleport) { if(teleport) {

View File

@ -31,7 +31,7 @@ public class FeatureGenerationStage implements TerraGenerationStage {
int tx = cx + x; int tx = cx + x;
int tz = cz + z; int tz = cz + z;
ColumnImpl column = new ColumnImpl(tx, tz, world); ColumnImpl column = new ColumnImpl(tx, tz, world);
terraWorld.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> { world.getBiomeProvider().getBiome(tx, tz, seed).getContext().get(BiomeFeatures.class).getFeatures().forEach(feature -> {
if(feature.getDistributor().matches(tx, tz, seed)) { if(feature.getDistributor().matches(tx, tz, seed)) {
feature.getLocator() feature.getLocator()
.getSuitableCoordinates(column) .getSuitableCoordinates(column)

View File

@ -34,7 +34,7 @@ public class FloraGenerationStage implements TerraGenerationStage {
if(tw.getConfig().disableFlora()) return; if(tw.getConfig().disableFlora()) return;
long seed = world.getSeed(); long seed = world.getSeed();
BiomeProvider provider = tw.getBiomeProvider(); BiomeProvider provider = world.getBiomeProvider();
Map<Vector2, List<FloraLayer>> layers = new HashMap<>(); Map<Vector2, List<FloraLayer>> layers = new HashMap<>();
for(int x = 0; x < 16; x++) { for(int x = 0; x < 16; x++) {
for(int z = 0; z < 16; z++) { for(int z = 0; z < 16; z++) {

View File

@ -38,7 +38,7 @@ public class BiomeFunction implements Function<String> {
RotationUtil.rotateVector(xz, arguments.getRotation()); RotationUtil.rotateVector(xz, arguments.getRotation());
BiomeProvider grid = main.getWorld(arguments.getWorld()).getBiomeProvider(); BiomeProvider grid = arguments.getWorld().getBiomeProvider();
return grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ()))), arguments.getWorld().getSeed()).getID(); return grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ()))), arguments.getWorld().getSeed()).getID();
} }

View File

@ -15,12 +15,12 @@ public class SamplerCacheImpl implements com.dfsek.terra.api.world.generator.Sam
public SamplerCacheImpl(TerraPlugin main, TerraWorld world) { public SamplerCacheImpl(TerraPlugin main, TerraWorld world) {
cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getSamplerCache()) cache = CacheBuilder.newBuilder().maximumSize(main.getTerraConfig().getSamplerCache())
.build(new CacheLoader<Long, Sampler>() { .build(new CacheLoader<>() {
@Override @Override
public Sampler load(@NotNull Long key) { public Sampler load(@NotNull Long key) {
int cx = (int) (key >> 32); int cx = (int) (key >> 32);
int cz = (int) key.longValue(); int cz = (int) key.longValue();
return world.getWorld().getTerraGenerator().createSampler(cx, cz, world.getBiomeProvider(), world.getWorld(), world.getConfig().elevationBlend()); return world.getWorld().getTerraGenerator().createSampler(cx, cz, world.getWorld().getBiomeProvider(), world.getWorld(), world.getConfig().elevationBlend());
} }
}); });
} }

View File

@ -3,6 +3,7 @@ package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure; import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
import com.dfsek.terra.api.world.TerraWorld; import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.world.population.items.TerraStructure; import com.dfsek.terra.world.population.items.TerraStructure;
@ -22,10 +23,10 @@ public class PaperListener implements Listener {
if(!BukkitAdapter.adapt(e.getWorld()).isTerraWorld()) return; if(!BukkitAdapter.adapt(e.getWorld()).isTerraWorld()) return;
String name = "minecraft:" + e.getType().getName(); String name = "minecraft:" + e.getType().getName();
main.getDebugLogger().info("Overriding structure location for \"" + name + "\""); main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld())); World w = BukkitAdapter.adapt(e.getWorld());
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(tw.getConfig().getLocatable().get(name)); ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(tw.getConfig().getLocatable().get(name));
if(config != null) { if(config != null) {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin().toVector()), tw.getWorld(), 0, 500, location -> { AsyncStructureFinder finder = new AsyncStructureFinder(w.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin().toVector()), tw.getWorld(), 0, 500, location -> {
if(location != null) if(location != null)
e.setResult(BukkitAdapter.adapt(location).toLocation(e.getWorld())); e.setResult(BukkitAdapter.adapt(location).toLocation(e.getWorld()));
main.getDebugLogger().info("Location: " + location); main.getDebugLogger().info("Location: " + location);

View File

@ -3,6 +3,7 @@ package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.api.TerraPlugin; import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.structure.configured.ConfiguredStructure; import com.dfsek.terra.api.structure.configured.ConfiguredStructure;
import com.dfsek.terra.api.world.TerraWorld; import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.locate.AsyncStructureFinder; import com.dfsek.terra.api.world.locate.AsyncStructureFinder;
import com.dfsek.terra.bukkit.world.BukkitAdapter; import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.world.population.items.TerraStructure; import com.dfsek.terra.world.population.items.TerraStructure;
@ -36,9 +37,9 @@ public class SpigotListener implements Listener {
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) { if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
main.getDebugLogger().info("Detected Ender Signal..."); main.getDebugLogger().info("Detected Ender Signal...");
if(!BukkitAdapter.adapt(e.getEntity().getWorld()).isTerraWorld()) return; if(!BukkitAdapter.adapt(e.getEntity().getWorld()).isTerraWorld()) return;
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getEntity().getWorld())); World w = BukkitAdapter.adapt(e.getEntity().getWorld());
EnderSignal signal = (EnderSignal) entity; EnderSignal signal = (EnderSignal) entity;
ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(tw.getConfig().getLocatable().get("STRONGHOLD")); ConfiguredStructure config = tw.getConfig().getRegistry(TerraStructure.class).get(w.getConfig().getLocatable().get("STRONGHOLD"));
if(config != null) { if(config != null) {
main.getDebugLogger().info("Overriding Ender Signal..."); main.getDebugLogger().info("Overriding Ender Signal...");
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation().toVector()), tw.getWorld(), 0, 500, location -> { AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation().toVector()), tw.getWorld(), 0, 500, location -> {