Skip to content

Commit

Permalink
templates can specify dimensions to spawn in (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuarterAnimal authored and AtomicStryker committed Jan 16, 2019
1 parent 5e95d43 commit 937650a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Ruins/src/main/java/atomicstryker/ruins/common/FileHandler.java
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.DimensionType;
import net.minecraft.world.biome.Biome;

class FileHandler
Expand Down Expand Up @@ -234,7 +235,7 @@ private void recalcBiomeWeight(String biomeName)
vars.put(biomeName, val);
}

private static final Pattern patternSpecificBiome = Pattern.compile("\\s*+specific_([^\\s=]++)\\s*+=\\s*+([^\\s#]++)");
private static final Pattern patternSpecificBiome = Pattern.compile("specific_([^=]++)=(.++)");

private void readPerWorldOptions(File dir, PrintWriter ruinsLog) throws Exception
{
Expand Down Expand Up @@ -323,7 +324,7 @@ else if (check[0].equals("teblocks") && check.length > 1)
}
}
}
else if ((matcher = patternSpecificBiome.matcher(read)).lookingAt())
else if ((matcher = patternSpecificBiome.matcher(read)).matches())
{
boolean found = false;
Biome bgb;
Expand Down Expand Up @@ -359,13 +360,18 @@ private void addRuins(PrintWriter pw, File path, String name, HashSet<RuinTempla
RuinTemplate r;
Biome bgb;
File[] listFiles = path.listFiles();
final String dimensionName = DimensionType.getById(dimension).getName();
if (listFiles != null)
{
for (File f : listFiles)
{
try
{
r = new RuinTemplate(pw, f.getCanonicalPath(), f.getName());
if (!r.acceptsDimension(dimensionName))
{
continue;
}
targetList.add(r);
for (String biomeName : r.getBiomesToSpawnIn())
{
Expand Down
14 changes: 14 additions & 0 deletions Ruins/src/main/java/atomicstryker/ruins/common/RuinTemplate.java
Expand Up @@ -48,6 +48,7 @@ public class RuinTemplate
private boolean preventRotation = false;
private final ArrayList<Integer> bonemealMarkers;
private final ArrayList<AdjoiningTemplateData> adjoiningTemplates;
private final Set<String> acceptedDimensions = new HashSet<>();

private class AdjoiningTemplateData
{
Expand Down Expand Up @@ -855,6 +856,14 @@ else if (line.startsWith("unacceptable_target_blocks"))
deniedSurfaces = inacceptables.toArray(deniedSurfaces);
}
}
else if (line.startsWith("dimensionsToSpawnIn"))
{
String[] check = line.split("=");
if (check.length > 1)
{
Collections.addAll(acceptedDimensions, check[1].split(","));
}
}
else if (line.startsWith("dimensions"))
{
String[] check = line.split("=");
Expand Down Expand Up @@ -1131,6 +1140,11 @@ public Block getAirBlock()
return Blocks.AIR;
}

public boolean acceptsDimension(final String dimension)
{
return acceptedDimensions.isEmpty() || dimension != null && !dimension.isEmpty() && acceptedDimensions.contains(dimension);
}

// A VariantRuleset is a list of template rules, some of which may have a number of variant versions from which the
// actual rule definitions for a particular structure are randomly drawn. This allows per-structure randomization
// (in addition to regular per-block randomization) without the need to create separate templates.
Expand Down
Expand Up @@ -472,6 +472,10 @@ private void toFile(File file)
pw.println("# e.g., a weight=6 template is chosen 3X as often as one with weight=2");
pw.println("weight=1");
pw.println("#");
pw.println("# list of dimensions in which this template may spawn, even if generic");
pw.println("# one or more dimension names, separated by commas (blank = all)");
pw.println("dimensionsToSpawnIn=");
pw.println("#");
pw.println("# list of other biomes in which this template may spawn");
pw.println("# biome corresponding to directory is always assumed, listed or not");
pw.println("# generic templates should leave this list empty");
Expand Down
2 changes: 2 additions & 0 deletions Ruins/src/main/resources/changelog.txt
Expand Up @@ -545,3 +545,5 @@ a: setAccessible now true
+ consider dimension in "recursive generator" check, bugfix
+ allow floating point block and template weights, rule and specific_biome chance values
+ remove extra +1% generic spawn chance, bugfix
+ support biome names containing spaces
+ templates can now specify dimensions to spawn in
6 changes: 6 additions & 0 deletions Ruins/src/main/resources/examplesAndDocs/template_rules.txt
Expand Up @@ -187,6 +187,12 @@
# and is of lower precedence than + and -; parentheses may be used to further control the
# order of evaluation.
#
# Ruins 17.3 adds optional variable "dimensionsToSpawnIn" to specify in which
# dimensions the template's structures may appear. Note this applies to generic
# spawning as well. List one or more dimensions by name, separated by commas,
# or leave blank (default) to allow all dimensions.
# example: dimensionsToSpawnIn=overworld,twilight_forest
#

weight=5
embed_into_distance=1
Expand Down

0 comments on commit 937650a

Please sign in to comment.