Implement structure location

This commit is contained in:
dfsek 2020-10-08 21:14:35 -07:00
parent 1a7d49ab1e
commit 6ec7ab9c72
3 changed files with 30 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package com.dfsek.terra.async;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.genconfig.StructureConfig;
@ -12,6 +14,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.profiler.ProfileFuture;
import java.util.Random;
@ -83,14 +86,17 @@ public class AsyncStructureFinder implements Runnable {
} else if(p.isOnline()) p.sendMessage("Unable to locate structure. " + spawn);
}
private boolean isValidSpawn(int x, int z) {
Location spawn = new Location(world, x, 255, z); // Probably(tm) async safe
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(spawn, GenerationPhase.POPULATE);
Location spawn = target.getSpawn().getNearestSpawn(x, z, world.getSeed()).toLocation(world);
if(! TerraWorld.getWorld(world).getConfig().getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(target)) return false;
Random r2 = new Random(spawn.hashCode());
GaeaStructure struc = target.getStructure(r2);
main: for(int y = target.getSearchStart().get(r2); y > 0; y--) {
GaeaStructure.Rotation rotation = GaeaStructure.Rotation.fromDegrees(r2.nextInt(4) * 90);
for(int y = target.getSearchStart().get(r2); y > 0; y--) {
if(!target.getBound().isInRange(y)) return false;
spawn.setY(y);
if(y > target.getBound().getMax() || y < target.getBound().getMin()) return false;
if(! struc.checkSpawns(spawn, rotation)) continue;
return true;
}
return true;
return false;
}
}

View File

@ -24,8 +24,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
@ -43,6 +45,9 @@ public class ConfigPack extends YamlConfiguration {
private final Map<String, BiomeConfig> biomes;
private final Map<String, BiomeGridConfig> grids;
private final Map<String, TreeConfig> trees;
private final Set<StructureConfig> allStructures = new HashSet<>();
private final File dataFolder;
private final String id;
@ -106,6 +111,11 @@ public class ConfigPack extends YamlConfiguration {
biomeList = getStringList("grids");
configs.put(id, this);
for(BiomeConfig b : getBiomes().values()) {
allStructures.addAll(b.getStructures());
}
LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l)/1000000D));
}
@ -121,6 +131,10 @@ public class ConfigPack extends YamlConfiguration {
return carvers;
}
public Set<StructureConfig> getAllStructures() {
return allStructures;
}
public static synchronized void loadAll(JavaPlugin main) {
configs.clear();
List<Path> subfolder;

View File

@ -30,16 +30,16 @@ public class StructurePopulator extends BlockPopulator {
if(!tw.isSafe()) return;
TerraBiomeGrid grid = tw.getGrid();
ConfigPack config = tw.getConfig();
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE);
structure: for(StructureConfig conf : config.getBiome(b).getStructures()) {
structure: for(StructureConfig conf : config.getAllStructures()) {
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
if(!config.getBiome((UserDefinedBiome) grid.getBiome(spawn)).getStructures().contains(conf)) continue;
Random r2 = new Random(spawn.hashCode());
GaeaStructure struc = conf.getStructure(r2);
GaeaStructure.Rotation rotation = GaeaStructure.Rotation.fromDegrees(r2.nextInt(4) * 90);
main: for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
if(y > conf.getBound().getMax() || y < conf.getBound().getMin()) continue structure;
for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
if(!conf.getBound().isInRange(y)) continue structure;
spawn.setY(y);
if(!struc.checkSpawns(spawn, rotation)) continue;
if(! struc.checkSpawns(spawn, rotation)) continue;
double horizontal = struc.getStructureInfo().getMaxHorizontal();
if(Math.abs((cx + 8) - spawn.getBlockX()) <= horizontal && Math.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("StructurePasteTime")) {