From c4da8580954cbcde0cbb976778095c0949836a9c Mon Sep 17 00:00:00 2001 From: dfsek Date: Sat, 26 Dec 2020 22:22:17 -0700 Subject: [PATCH] reimplement structure probability collections --- .../dfsek/terra/config/templates/StructureTemplate.java | 7 ++++--- .../com/dfsek/terra/config/templates/TreeTemplate.java | 7 ++++--- .../com/dfsek/terra/generation/items/TerraStructure.java | 7 ++++--- .../com/dfsek/terra/generation/items/tree/TerraTree.java | 7 ++++--- .../com/dfsek/terra/population/StructurePopulator.java | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java index b4f241bb9..40dfa7be2 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/StructureTemplate.java @@ -6,6 +6,7 @@ import com.dfsek.tectonic.annotations.Value; import com.dfsek.tectonic.config.ValidatedConfigTemplate; import com.dfsek.tectonic.exception.ValidationException; import com.dfsek.terra.api.loot.LootTable; +import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.util.GlueList; @@ -19,9 +20,9 @@ public class StructureTemplate extends AbstractableTemplate implements Validated @Value("id") private String id; - @Value("script") + @Value("scripts") @Abstractable - private StructureScript structure; + private ProbabilityCollection structure; @Value("spawn.start") @Abstractable @@ -52,7 +53,7 @@ public class StructureTemplate extends AbstractableTemplate implements Validated return id; } - public StructureScript getStructures() { + public ProbabilityCollection getStructures() { return structure; } diff --git a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java index f872d5603..33702c5a4 100644 --- a/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java +++ b/common/src/main/java/com/dfsek/terra/config/templates/TreeTemplate.java @@ -3,14 +3,15 @@ package com.dfsek.terra.config.templates; import com.dfsek.tectonic.annotations.Abstractable; import com.dfsek.tectonic.annotations.Default; import com.dfsek.tectonic.annotations.Value; +import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.util.MaterialSet; @SuppressWarnings({"unused", "FieldMayBeFinal"}) public class TreeTemplate extends AbstractableTemplate { - @Value("script") + @Value("scripts") @Abstractable - private StructureScript structure; + private ProbabilityCollection structure; @Value("id") private String id; @@ -24,7 +25,7 @@ public class TreeTemplate extends AbstractableTemplate { @Abstractable private MaterialSet spawnable; - public StructureScript getStructures() { + public ProbabilityCollection getStructures() { return structure; } diff --git a/common/src/main/java/com/dfsek/terra/generation/items/TerraStructure.java b/common/src/main/java/com/dfsek/terra/generation/items/TerraStructure.java index 883490390..f1b5bbb93 100644 --- a/common/src/main/java/com/dfsek/terra/generation/items/TerraStructure.java +++ b/common/src/main/java/com/dfsek/terra/generation/items/TerraStructure.java @@ -1,6 +1,7 @@ package com.dfsek.terra.generation.items; import com.dfsek.terra.api.loot.LootTable; +import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.config.templates.StructureTemplate; @@ -10,14 +11,14 @@ import java.util.Map; // TODO: implementation public class TerraStructure { - private final StructureScript structure; + private final ProbabilityCollection structure; private final Range bound; private final Range spawnStart; private final GridSpawn spawn; private final Map loot; private final StructureTemplate template; - public TerraStructure(StructureScript structures, Range bound, Range spawnStart, GridSpawn spawn, Map loot, StructureTemplate template) { + public TerraStructure(ProbabilityCollection structures, Range bound, Range spawnStart, GridSpawn spawn, Map loot, StructureTemplate template) { this.structure = structures; this.bound = bound; this.spawnStart = spawnStart; @@ -30,7 +31,7 @@ public class TerraStructure { return template; } - public StructureScript getStructure() { + public ProbabilityCollection getStructure() { return structure; } diff --git a/common/src/main/java/com/dfsek/terra/generation/items/tree/TerraTree.java b/common/src/main/java/com/dfsek/terra/generation/items/tree/TerraTree.java index 90a124e9a..9fc9e09b0 100644 --- a/common/src/main/java/com/dfsek/terra/generation/items/tree/TerraTree.java +++ b/common/src/main/java/com/dfsek/terra/generation/items/tree/TerraTree.java @@ -1,5 +1,6 @@ package com.dfsek.terra.generation.items.tree; +import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.vector.Location; import com.dfsek.terra.api.structures.script.StructureScript; import com.dfsek.terra.api.structures.structure.Rotation; @@ -11,9 +12,9 @@ import java.util.Random; public class TerraTree implements Tree { private final MaterialSet spawnable; private final int yOffset; - private final StructureScript structure; + private final ProbabilityCollection structure; - public TerraTree(MaterialSet spawnable, int yOffset, StructureScript structure) { + public TerraTree(MaterialSet spawnable, int yOffset, ProbabilityCollection structure) { this.spawnable = spawnable; this.yOffset = yOffset; this.structure = structure; @@ -21,7 +22,7 @@ public class TerraTree implements Tree { @Override public synchronized boolean plant(Location location, Random random) { - structure.execute(location.clone().add(0, yOffset, 0), random, Rotation.fromDegrees(90 * random.nextInt(4))); + structure.get(random).execute(location.clone().add(0, yOffset, 0), random, Rotation.fromDegrees(90 * random.nextInt(4))); return true; } diff --git a/common/src/main/java/com/dfsek/terra/population/StructurePopulator.java b/common/src/main/java/com/dfsek/terra/population/StructurePopulator.java index 68c397f69..90c594a67 100644 --- a/common/src/main/java/com/dfsek/terra/population/StructurePopulator.java +++ b/common/src/main/java/com/dfsek/terra/population/StructurePopulator.java @@ -42,7 +42,7 @@ public class StructurePopulator implements TerraBlockPopulator { if(!((UserDefinedBiome) grid.getBiome(spawn)).getConfig().getStructures().contains(conf)) continue; Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed())); - conf.getStructure().execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4))); + conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4))); } } }