mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Structures!
This commit is contained in:
@@ -2,7 +2,7 @@ package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.Location;
|
||||
@@ -17,8 +17,8 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* Runnable to locate structures asynchronously
|
||||
*/
|
||||
public class AsyncStructureFinder extends AsyncFeatureFinder<StructureTemplate> {
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, StructureTemplate target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) {
|
||||
public class AsyncStructureFinder extends AsyncFeatureFinder<TerraStructure> {
|
||||
public AsyncStructureFinder(TerraBiomeGrid grid, TerraStructure target, @NotNull Location origin, int startRadius, int maxRadius, Consumer<Vector> callback) {
|
||||
super(grid, target, origin, startRadius, maxRadius, callback);
|
||||
setSearchSize(target.getSpawn().getWidth() + 2 * target.getSpawn().getSeparation());
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<StructureTemplate>
|
||||
* @param z Z coordinate
|
||||
* @return Whether location is a valid spawn for StructureConfig
|
||||
*/
|
||||
public boolean isValid(int x, int z, StructureTemplate target) {
|
||||
public boolean isValid(int x, int z, TerraStructure target) {
|
||||
World world = getWorld();
|
||||
Location spawn = target.getSpawn().getChunkSpawn(x, z, world.getSeed()).toLocation(world);
|
||||
if(!((UserDefinedBiome) getGrid().getBiome(spawn)).getConfig().getStructures().contains(target))
|
||||
@@ -38,7 +38,7 @@ public class AsyncStructureFinder extends AsyncFeatureFinder<StructureTemplate>
|
||||
Random r2 = new FastRandom(spawn.hashCode());
|
||||
Structure struc = target.getStructures().get(r2);
|
||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = target.getY().get(r2); y > 0; y--) {
|
||||
for(int y = target.getSpawnStart().get(r2); y > 0; y--) {
|
||||
if(!target.getBound().isInRange(y)) return false;
|
||||
spawn.setY(y);
|
||||
if(!struc.checkSpawns(spawn, rotation)) continue;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
public class OreEntry {
|
||||
}
|
||||
@@ -16,7 +16,7 @@ public class PaletteHolderBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes", "RedundantSuppression"})
|
||||
public PaletteHolder build() {
|
||||
Palette<BlockData>[] palettes = new Palette[paletteMap.lastKey() + 1];
|
||||
for(int y = 0; y <= FastMath.max(paletteMap.lastKey(), 255); y++) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.structure.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -46,7 +46,7 @@ public class BiomeInfoCommand extends WorldCommand {
|
||||
else {
|
||||
sender.sendMessage("-------Structures-------");
|
||||
for(TerraStructure c : structureConfigs) {
|
||||
sender.sendMessage(" - " + c.getID());
|
||||
sender.sendMessage(" - " + c.getTemplate().getID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@@ -38,7 +38,7 @@ public class LocateCommand extends WorldCommand {
|
||||
LangUtil.send("command.structure.invalid-radius", sender, args[1]);
|
||||
return true;
|
||||
}
|
||||
StructureTemplate s;
|
||||
TerraStructure s;
|
||||
try {
|
||||
s = Objects.requireNonNull(TerraWorld.getWorld(world).getConfig().getStructure(id));
|
||||
} catch(IllegalArgumentException | NullPointerException e) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.dfsek.terra.config.factories.CarverFactory;
|
||||
import com.dfsek.terra.config.factories.FloraFactory;
|
||||
import com.dfsek.terra.config.factories.OreFactory;
|
||||
import com.dfsek.terra.config.factories.PaletteFactory;
|
||||
import com.dfsek.terra.config.factories.StructureFactory;
|
||||
import com.dfsek.terra.config.factories.TerraFactory;
|
||||
import com.dfsek.terra.config.factories.TreeFactory;
|
||||
import com.dfsek.terra.config.files.FolderLoader;
|
||||
@@ -30,6 +31,7 @@ import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.registry.BiomeGridRegistry;
|
||||
import com.dfsek.terra.registry.BiomeRegistry;
|
||||
@@ -89,7 +91,8 @@ public class ConfigPack {
|
||||
.registerLoader(UserDefinedCarver.class, carverRegistry)
|
||||
.registerLoader(Flora.class, floraRegistry)
|
||||
.registerLoader(Ore.class, oreRegistry)
|
||||
.registerLoader(Tree.class, treeRegistry);
|
||||
.registerLoader(Tree.class, treeRegistry)
|
||||
.registerLoader(TerraStructure.class, structureRegistry);
|
||||
ConfigUtil.registerAllLoaders(abstractConfigLoader);
|
||||
ConfigUtil.registerAllLoaders(selfLoader);
|
||||
}
|
||||
@@ -143,6 +146,7 @@ public class ConfigPack {
|
||||
.open("flora").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new))).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new))).close()
|
||||
.open("structures/trees").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new))).close()
|
||||
.open("structures/single").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new))).close()
|
||||
.open("biomes").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this)))).close()
|
||||
.open("grids").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new))).close();
|
||||
for(UserDefinedBiome b : biomeRegistry.entries()) {
|
||||
@@ -172,11 +176,11 @@ public class ConfigPack {
|
||||
return biomeIDs;
|
||||
}
|
||||
|
||||
public StructureTemplate getStructure(String id) {
|
||||
public TerraStructure getStructure(String id) {
|
||||
return structureRegistry.get(id);
|
||||
}
|
||||
|
||||
public Set<StructureTemplate> getStructures() {
|
||||
public Set<TerraStructure> getStructures() {
|
||||
return structureRegistry.entries();
|
||||
}
|
||||
|
||||
@@ -190,7 +194,7 @@ public class ConfigPack {
|
||||
|
||||
public List<String> getStructureIDs() {
|
||||
List<String> ids = new ArrayList<>();
|
||||
structureRegistry.forEach(structure -> ids.add(structure.getID()));
|
||||
structureRegistry.forEach(structure -> ids.add(structure.getTemplate().getID()));
|
||||
return ids;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
|
||||
public class StructureFactory implements TerraFactory<StructureTemplate, TerraStructure> {
|
||||
@Override
|
||||
public TerraStructure build(StructureTemplate config) throws LoadException {
|
||||
return new TerraStructure(config.getStructures(), config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,12 @@ import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.SinglePalette;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.flora.FloraLayer;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.generation.items.ores.OreConfig;
|
||||
import com.dfsek.terra.generation.items.tree.TreeLayer;
|
||||
import com.dfsek.terra.math.BlankFunction;
|
||||
import com.dfsek.terra.structure.TerraStructure;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@@ -27,13 +27,6 @@ public class StructureTemplate extends AbstractableTemplate {
|
||||
@Abstractable
|
||||
private Range bound;
|
||||
|
||||
@Value("spawn.width")
|
||||
@Abstractable
|
||||
private int width;
|
||||
|
||||
@Value("spawn.padding")
|
||||
@Abstractable
|
||||
private int padding;
|
||||
|
||||
@Value("spawn")
|
||||
@Abstractable
|
||||
@@ -63,13 +56,6 @@ public class StructureTemplate extends AbstractableTemplate {
|
||||
return bound;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
public GridSpawn getSpawn() {
|
||||
return spawn;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.dfsek.terra.generation.items;
|
||||
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.procgen.GridSpawn;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.structures.loot.LootTable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
// TODO: implementation
|
||||
public class TerraStructure {
|
||||
private final ProbabilityCollection<Structure> structures;
|
||||
private final Range bound;
|
||||
private final Range spawnStart;
|
||||
private final GridSpawn spawn;
|
||||
private final Map<Integer, LootTable> loot;
|
||||
private final StructureTemplate template;
|
||||
|
||||
public TerraStructure(ProbabilityCollection<Structure> structures, Range bound, Range spawnStart, GridSpawn spawn, Map<Integer, LootTable> loot, StructureTemplate template) {
|
||||
this.structures = structures;
|
||||
this.bound = bound;
|
||||
this.spawnStart = spawnStart;
|
||||
this.spawn = spawn;
|
||||
this.loot = loot;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public StructureTemplate getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Structure> getStructures() {
|
||||
return structures;
|
||||
}
|
||||
|
||||
public Range getBound() {
|
||||
return bound;
|
||||
}
|
||||
|
||||
public Range getSpawnStart() {
|
||||
return spawnStart;
|
||||
}
|
||||
|
||||
public GridSpawn getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
public Map<Integer, LootTable> getLoot() {
|
||||
return loot;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
@@ -40,13 +40,13 @@ public class StructurePopulator extends BlockPopulator {
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
ConfigPack config = tw.getConfig();
|
||||
structure:
|
||||
for(StructureTemplate conf : config.getStructures()) {
|
||||
for(TerraStructure conf : config.getStructures()) {
|
||||
Location spawn = conf.getSpawn().getNearestSpawn(cx + 8, cz + 8, world.getSeed()).toLocation(world);
|
||||
if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue;
|
||||
Random r2 = new FastRandom(spawn.hashCode());
|
||||
Structure struc = conf.getStructures().get(r2);
|
||||
Rotation rotation = Rotation.fromDegrees(r2.nextInt(4) * 90);
|
||||
for(int y = conf.getY().get(r2); y > 0; y--) {
|
||||
for(int y = conf.getSpawnStart().get(r2); y > 0; y--) {
|
||||
if(!conf.getBound().isInRange(y)) continue structure;
|
||||
spawn.setY(y);
|
||||
if(!struc.checkSpawns(spawn, rotation)) continue;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.registry;
|
||||
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
|
||||
public class StructureRegistry extends TerraRegistry<StructureTemplate> {
|
||||
public class StructureRegistry extends TerraRegistry<TerraStructure> {
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
// TODO: implementation
|
||||
public class TerraStructure {
|
||||
public String getID() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user