mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 18:42:30 +00:00
Implement structure random selection
This commit is contained in:
parent
28ebd9c31d
commit
9d05aed065
@ -20,4 +20,8 @@ public class Debug {
|
|||||||
public static void error(String message) {
|
public static void error(String message) {
|
||||||
if(ConfigUtil.debug) main.getLogger().severe(message);
|
if(ConfigUtil.debug) main.getLogger().severe(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void stack(Exception e) {
|
||||||
|
if(ConfigUtil.debug) e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,9 @@ public class TerraWorld {
|
|||||||
} catch(NullPointerException e) {
|
} catch(NullPointerException e) {
|
||||||
if(ConfigUtil.debug) e.printStackTrace();
|
if(ConfigUtil.debug) e.printStackTrace();
|
||||||
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
|
Bukkit.getLogger().severe("No such BiomeGrid " + partName);
|
||||||
|
Bukkit.getLogger().severe("Please check configuration files for errors. Configuration errors will have been reported during initialization.");
|
||||||
|
Bukkit.getLogger().severe("ONLY report this to Terra if you are SURE your config is error-free.");
|
||||||
|
Bukkit.getLogger().severe("Terrain will NOT generate properly at this point. Correct your config before using your server!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zone = new BiomeZone(w, worldConfig, definedGrids);
|
zone = new BiomeZone(w, worldConfig, definedGrids);
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
package com.dfsek.terra.config.genconfig;
|
package com.dfsek.terra.config.genconfig;
|
||||||
|
|
||||||
|
import com.dfsek.terra.Debug;
|
||||||
import com.dfsek.terra.config.TerraConfig;
|
import com.dfsek.terra.config.TerraConfig;
|
||||||
|
import com.dfsek.terra.config.TerraConfigObject;
|
||||||
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
import com.dfsek.terra.config.exception.NotFoundException;
|
import com.dfsek.terra.config.exception.NotFoundException;
|
||||||
import org.polydev.gaea.math.Range;
|
|
||||||
import com.dfsek.terra.Terra;
|
|
||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
|
||||||
import com.dfsek.terra.config.TerraConfigObject;
|
|
||||||
import com.dfsek.terra.population.StructurePopulator;
|
import com.dfsek.terra.population.StructurePopulator;
|
||||||
import com.dfsek.terra.structure.GaeaStructure;
|
|
||||||
import com.dfsek.terra.procgen.GridSpawn;
|
import com.dfsek.terra.procgen.GridSpawn;
|
||||||
|
import com.dfsek.terra.structure.GaeaStructure;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.polydev.gaea.math.ProbabilityCollection;
|
||||||
|
import org.polydev.gaea.math.Range;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class StructureConfig extends TerraConfigObject {
|
public class StructureConfig extends TerraConfigObject {
|
||||||
private final GaeaStructure structure;
|
private final ProbabilityCollection<GaeaStructure> structure = new ProbabilityCollection<>();
|
||||||
private final GridSpawn spawn;
|
private final GridSpawn spawn;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final Range searchStart;
|
private final Range searchStart;
|
||||||
@ -29,9 +31,20 @@ public class StructureConfig extends TerraConfigObject {
|
|||||||
super(file, config);
|
super(file, config);
|
||||||
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||||
id = getString("id");
|
id = getString("id");
|
||||||
|
if(!contains("files")) throw new ConfigException("No files specified!", getID());
|
||||||
try {
|
try {
|
||||||
File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", Objects.requireNonNull(getString("file")));
|
for(Map.Entry<String, Object> e : Objects.requireNonNull(getConfigurationSection("files")).getValues(false).entrySet()) {
|
||||||
structure = GaeaStructure.load(structureFile);
|
try {
|
||||||
|
File structureFile = new File(config.getDataFolder() + File.separator + "structures" + File.separator + "data", e.getKey() + ".tstructure");
|
||||||
|
structure.add(GaeaStructure.load(structureFile), (Integer) e.getValue());
|
||||||
|
} catch(FileNotFoundException ex) {
|
||||||
|
Debug.stack(ex);
|
||||||
|
throw new NotFoundException("Structure File", e.getKey(), getID());
|
||||||
|
} catch(ClassCastException ex) {
|
||||||
|
Debug.stack(ex);
|
||||||
|
throw new ConfigException("Unable to parse Structure configuration! Check YAML syntax.", getID());
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch(IOException | NullPointerException e) {
|
} catch(IOException | NullPointerException e) {
|
||||||
if(ConfigUtil.debug) {
|
if(ConfigUtil.debug) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -54,8 +67,8 @@ public class StructureConfig extends TerraConfigObject {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GaeaStructure getStructure() {
|
public GaeaStructure getStructure(Random r) {
|
||||||
return structure;
|
return structure.get(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridSpawn getSpawn() {
|
public GridSpawn getSpawn() {
|
||||||
|
@ -34,9 +34,9 @@ public class StructurePopulator extends BlockPopulator {
|
|||||||
TerraConfig config = tw.getConfig();
|
TerraConfig config = tw.getConfig();
|
||||||
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE);
|
UserDefinedBiome b = (UserDefinedBiome) grid.getBiome(cx+ 8, cz + 8, GenerationPhase.POPULATE);
|
||||||
structure: for(StructureConfig conf : config.getBiome(b).getStructures()) {
|
structure: for(StructureConfig conf : config.getBiome(b).getStructures()) {
|
||||||
GaeaStructure struc = conf.getStructure();
|
|
||||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||||
Random r2 = new Random(spawn.hashCode());
|
Random r2 = new Random(spawn.hashCode());
|
||||||
|
GaeaStructure struc = conf.getStructure(r2);
|
||||||
main: for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
|
main: for(int y = conf.getSearchStart().get(r2); y > 0; y--) {
|
||||||
if(y > conf.getBound().getMax() || y < conf.getBound().getMin()) continue structure;
|
if(y > conf.getBound().getMax() || y < conf.getBound().getMin()) continue structure;
|
||||||
spawn.setY(y);
|
spawn.setY(y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user