Carving Biomes

This commit is contained in:
Daniel Mills 2020-09-12 00:17:12 -04:00
parent 30e1d9552c
commit 9272765f3c
8 changed files with 153 additions and 50 deletions

View File

@ -304,12 +304,12 @@ public abstract class ParallaxTerrainProvider extends TopographicTerrainProvider
private int placeObjects(RNG random, IrisRegion r, IrisBiome b, int i, int j, int g)
{
for(IrisObjectPlacement k : b.getObjects())
for(IrisObjectPlacement k : b.getSurfaceObjects())
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3566522));
}
for(IrisObjectPlacement k : r.getObjects())
for(IrisObjectPlacement k : r.getSurfaceObjects())
{
placeObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3569222));
}
@ -341,12 +341,12 @@ public abstract class ParallaxTerrainProvider extends TopographicTerrainProvider
private int placeCarveObjects(RNG random, IrisRegion r, IrisBiome b, int i, int j, int g, CarveResult c)
{
for(IrisObjectPlacement k : b.getObjects())
for(IrisObjectPlacement k : b.getCarvingObjects())
{
placeCarveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3569221 + g), c);
}
for(IrisObjectPlacement k : r.getObjects())
for(IrisObjectPlacement k : r.getCarvingObjects())
{
placeCarveObject(k, i, j, random.nextParallelRNG((34 * ((i * 30) + (j * 30) + g++) * i * j) + i - j + 3561222 + g), c);
}

View File

@ -141,7 +141,7 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
boolean carvable = getGlCarve().couldCarveBelow(rx, height, rz);
IrisRegion region = sampleRegion(rx, rz);
IrisBiome biome = sampleTrueBiome(rx, rz, noise);
IrisBiome landBiome = null;
IrisBiome carveBiome = null;
Biome onlyBiome = Iris.biome3d ? null : biome.getGroundBiome(getMasterRandom(), rz, getDimension().getFluidHeight(), rx);
if(biome == null)
@ -185,12 +185,12 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
{
if(biomeMap != null)
{
if(landBiome == null)
if(carveBiome == null)
{
landBiome = getGlBiome().generateData(InferredType.LAND, wx, wz, rx, rz, region);
carveBiome = biome.getRealCarvingBiome(getData());
}
sliver.set(k, landBiome.getDerivative());
sliver.set(k, carveBiome.getDerivative());
}
sliver.set(k, CAVE_AIR);
@ -245,14 +245,14 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
// Set Surface Material for cavern layer surfaces
else if(carvable && cavernHeights.isNotEmpty() && lastCavernHeight - k >= 0 && lastCavernHeight - k < 5)
{
if(landBiome == null)
if(carveBiome == null)
{
landBiome = getGlBiome().generateData(InferredType.LAND, wx, wz, rx, rz, region);
carveBiome = biome.getRealCarvingBiome(getData());
}
if(cavernLayers == null)
{
cavernLayers = landBiome.generateLayers(rx, rz, getMasterRandom(), 5, height - getFluidHeight());
cavernLayers = carveBiome.generateLayers(rx, rz, getMasterRandom(), 5, height - getFluidHeight());
}
block = cavernLayers.hasIndex(lastCavernHeight - k) ? cavernLayers.get(lastCavernHeight - k) : cavernLayers.get(0);
@ -277,12 +277,12 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
// Decorate Cavern surfaces, but not the true surface
if((carvable && cavernSurface) && !(k == Math.max(height, fluidHeight) && block.getMaterial().isSolid() && k < 255 && k >= fluidHeight))
{
if(landBiome == null)
if(carveBiome == null)
{
landBiome = getGlBiome().generateData(InferredType.LAND, wx, wz, rx, rz, region);
carveBiome = biome.getRealCarvingBiome(getData());
}
decorateLand(landBiome, sliver, wx, k, wz, rx, rz, block);
decorateLand(carveBiome, sliver, wx, k, wz, rx, rz, block);
}
}

View File

@ -30,6 +30,7 @@ public class GenLayerBiome extends GenLayer
private BiomeDataProvider landProvider;
private BiomeDataProvider shoreProvider;
private BiomeDataProvider caveProvider;
private BiomeDataProvider carveProvider;
private BiomeDataProvider riverProvider;
private BiomeDataProvider lakeProvider;
private DimensionalTerrainProvider iris;

View File

@ -0,0 +1,25 @@
package com.volmit.iris.object;
import com.volmit.iris.util.DontObfuscate;
public enum CarvingMode
{
@DontObfuscate
SURFACE_ONLY,
@DontObfuscate
CARVING_ONLY,
@DontObfuscate
ANYWHERE;
public boolean supportsCarving()
{
return this.equals(ANYWHERE) || this.equals(CARVING_ONLY);
}
public boolean supportsSurface()
{
return this.equals(ANYWHERE) || this.equals(SURFACE_ONLY);
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.ContextualTerrainProvider;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.util.ArrayType;
import com.volmit.iris.util.DependsOn;
@ -39,187 +40,217 @@ public class IrisBiome extends IrisRegistrant implements IRare
{
@MinNumber(2)
@Required
@DontObfuscate
@Desc("This is the human readable name for this biome. This can and should be different than the file name. This is not used for loading biomes in other objects.")
private String name = "A Biome";
@DontObfuscate
@Desc("Place text on terrain. Iris will render text into block schematics and randomly place them in this biome.")
@ArrayType(min = 1, type = IrisTextPlacement.class)
private KList<IrisTextPlacement> text = new KList<>();
@DontObfuscate
@Desc("The type of fluid if this biome is underwater. To 'defer' this value to whatever the parent dimension fluid type is, use an emtpy string.")
private String fluidType = "";
@DontObfuscate
@Desc("Entity spawns to override or add to this biome. Anytime an entity spawns, it has a chance to be replaced as one of these overrides.")
@ArrayType(min = 1, type = IrisEntitySpawnOverride.class)
private KList<IrisEntitySpawnOverride> entitySpawnOverrides = new KList<>();
@DontObfuscate
@Desc("Entity spawns during generation")
@ArrayType(min = 1, type = IrisEntityInitialSpawn.class)
private KList<IrisEntityInitialSpawn> entityInitialSpawns = new KList<>();
@ArrayType(min = 1, type = IrisEffect.class)
@DontObfuscate
@Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.")
private KList<IrisEffect> effects = new KList<>();
@DontObfuscate
@DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"})
@Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.")
private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style();
@ArrayType(min = 1, type = IrisBlockDrops.class)
@DontObfuscate
@Desc("Define custom block drops for this biome")
private KList<IrisBlockDrops> blockDrops = new KList<>();
@DontObfuscate
@Desc("Reference loot tables in this area")
private IrisLootReference loot = new IrisLootReference();
@MinNumber(0.0001)
@DontObfuscate
@DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"})
@Desc("This zooms in the biome colors if multiple derivatives are chosen")
private double biomeZoom = 1;
@DontObfuscate
@Desc("Layers no longer descend from the surface block, they descend from the max possible height the biome can produce (constant) creating mesa like layers.")
private boolean lockLayers = false;
@DontObfuscate
@Desc("The max layers to iterate below the surface for locked layer biomes (mesa).")
private int lockLayersMax = 7;
@MinNumber(1)
@MaxNumber(512)
@DontObfuscate
@Desc("The rarity of this biome (integer)")
private int rarity = 1;
@DontObfuscate
@Desc("A debug color for visualizing this biome with a color. I.e. #F13AF5")
private String debugColor = "";
@Required
@DontObfuscate
@Desc("The raw derivative of this biome. This is required or the terrain will not properly generate. Use any vanilla biome type. Look in examples/biome-list.txt")
private Biome derivative = Biome.THE_VOID;
@ArrayType(min = 1, type = Biome.class)
@DontObfuscate
@Desc("You can instead specify multiple biome derivatives to randomly scatter colors in this biome")
private KList<Biome> biomeScatter = new KList<>();
@ArrayType(min = 1, type = Biome.class)
@DontObfuscate
@Desc("Since 1.13 supports 3D biomes, you can add different derivative colors for anything above the terrain. (Think swampy tree leaves with a desert looking grass surface)")
private KList<Biome> biomeSkyScatter = new KList<>();
@DontObfuscate
@DependsOn({"children"})
@Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, how much smaller will it be (inside of this biome). Higher values means a smaller biome relative to this biome's size. Set higher than 1.0 and below 3.0 for best results.")
private double childShrinkFactor = 1.5;
@DontObfuscate
@DependsOn({"children"})
@Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?")
private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style();
@RegistryListBiome
@ArrayType(min = 1, type = String.class)
@DontObfuscate
@Desc("List any biome names (file names without.json) here as children. Portions of this biome can sometimes morph into their children. Iris supports cyclic relationships such as A > B > A > B. Iris will stop checking 9 biomes down the tree.")
private KList<String> children = new KList<>();
@RegistryListBiome
@DontObfuscate
@Desc("The carving biome. If specified the biome will be used when under a carving instead of this current biome.")
private String carvingBiome = "";
@DontObfuscate
@Desc("The default slab if iris decides to place a slab in this biome. Default is no slab.")
private IrisBiomePaletteLayer slab = new IrisBiomePaletteLayer().zero();
@DontObfuscate
@Desc("The default wall if iris decides to place a wall higher than 2 blocks (steep hills or possibly cliffs)")
private IrisBiomePaletteLayer wall = new IrisBiomePaletteLayer().zero();
@Required
@ArrayType(min = 1, type = IrisBiomePaletteLayer.class)
@DontObfuscate
@Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.")
private KList<IrisBiomePaletteLayer> layers = new KList<IrisBiomePaletteLayer>().qadd(new IrisBiomePaletteLayer());
@ArrayType(min = 1, type = IrisBiomePaletteLayer.class)
@DontObfuscate
@Desc("This defines the layers of materials in this biome. Each layer has a palette and min/max height and some other properties. Usually a grassy/sandy layer then a dirt layer then a stone layer. Iris will fill in the remaining blocks below your layers with stone.")
private KList<IrisBiomePaletteLayer> seaLayers = new KList<IrisBiomePaletteLayer>();
@ArrayType(min = 1, type = IrisBiomeDecorator.class)
@DontObfuscate
@Desc("Decorators are used for things like tall grass, bisected flowers, and even kelp or cactus (random heights)")
private KList<IrisBiomeDecorator> decorators = new KList<IrisBiomeDecorator>();
@ArrayType(min = 1, type = IrisObjectPlacement.class)
@DontObfuscate
@Desc("Objects define what schematics (iob files) iris will place in this biome")
private KList<IrisObjectPlacement> objects = new KList<IrisObjectPlacement>();
@Required
@ArrayType(min = 1, type = IrisBiomeGeneratorLink.class)
@DontObfuscate
@Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.")
private KList<IrisBiomeGeneratorLink> generators = new KList<IrisBiomeGeneratorLink>().qadd(new IrisBiomeGeneratorLink());
@ArrayType(min = 1, type = IrisStructurePlacement.class)
@DontObfuscate
@Desc("A list of structure tilesets")
private KList<IrisStructurePlacement> structures = new KList<>();
@ArrayType(min = 1, type = IrisDepositGenerator.class)
@DontObfuscate
@Desc("Define biome deposit generators that add onto the existing regional and global deposit generators")
private KList<IrisDepositGenerator> deposits = new KList<>();
private transient InferredType inferredType;
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>(false);
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>(false);
private final transient AtomicCache<Color> cacheColor = new AtomicCache<>(true);
private final transient AtomicCache<CNG> childrenCell = new AtomicCache<>();
private final transient AtomicCache<CNG> biomeGenerator = new AtomicCache<>();
private final transient AtomicCache<Integer> maxHeight = new AtomicCache<>();
private final transient AtomicCache<IrisBiome> realCarveBiome = new AtomicCache<>();
private final transient AtomicCache<KList<IrisBiome>> realChildren = new AtomicCache<>();
private final transient AtomicCache<KList<CNG>> layerHeightGenerators = new AtomicCache<>();
private final transient AtomicCache<KList<CNG>> layerSeaHeightGenerators = new AtomicCache<>();
public IrisBiome getRealCarvingBiome(IrisDataManager data)
{
return realCarveBiome.aquire(() ->
{
IrisBiome biome = data.getBiomeLoader().load(getCarvingBiome());
if(biome == null)
{
biome = this;
}
return biome;
});
}
public KList<IrisObjectPlacement> getSurfaceObjects()
{
return getSurfaceObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for(IrisObjectPlacement i : o.copy())
{
if(!i.getCarvingSupport().supportsSurface())
{
o.remove(i);
}
}
return o;
});
}
public KList<IrisObjectPlacement> getCarvingObjects()
{
return getCarveObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for(IrisObjectPlacement i : o.copy())
{
if(!i.getCarvingSupport().supportsCarving())
{
o.remove(i);
}
}
return o;
});
}
public Color getCachedColor()
{
return cacheColor.aquire(() ->

View File

@ -100,11 +100,7 @@ public class IrisObjectPlacement
@DontObfuscate
@Desc("If set to true, objects will place in carvings (such as underground) or under an overhang.")
private boolean allowInCarvings = true;
@DontObfuscate
@Desc("If set to true, objects will place on carving ceilings instead of the floors. Make sure to rotate it upside down with rotate if need be as this option does NOT flip your object upside down.")
private boolean carvingCeiling = false;
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
@DontObfuscate
@Desc("If set to true, Iris will try to fill the insides of 'rooms' and 'pockets' where air should fit based off of raytrace checks. This prevents a village house placing in an area where a tree already exists, and instead replaces the parts of the tree where the interior of the structure is. \n\nThis operation does not affect warmed-up generation speed however it does slow down loading objects.")

View File

@ -229,6 +229,8 @@ public class IrisRegion extends IrisRegistrant implements IRare
@Desc("Generate rivers in this region")
private double riverThickness = 0.1;
private final transient AtomicCache<KList<IrisObjectPlacement>> surfaceObjectsCache = new AtomicCache<>(true);
private final transient AtomicCache<KList<IrisObjectPlacement>> carveObjectsCache = new AtomicCache<>(true);
private final transient AtomicCache<KList<String>> cacheRidge = new AtomicCache<>();
private final transient AtomicCache<KList<String>> cacheSpot = new AtomicCache<>();
private final transient AtomicCache<CNG> shoreHeightGenerator = new AtomicCache<>();
@ -242,6 +244,42 @@ public class IrisRegion extends IrisRegistrant implements IRare
private final transient AtomicCache<CNG> riverGen = new AtomicCache<>();
private final transient AtomicCache<CNG> riverChanceGen = new AtomicCache<>();
public KList<IrisObjectPlacement> getSurfaceObjects()
{
return getSurfaceObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for(IrisObjectPlacement i : o.copy())
{
if(!i.getCarvingSupport().supportsSurface())
{
o.remove(i);
}
}
return o;
});
}
public KList<IrisObjectPlacement> getCarvingObjects()
{
return getCarveObjectsCache().aquire(() ->
{
KList<IrisObjectPlacement> o = getObjects().copy();
for(IrisObjectPlacement i : o.copy())
{
if(!i.getCarvingSupport().supportsCarving())
{
o.remove(i);
}
}
return o;
});
}
public boolean isRiver(RNG rng, double x, double z)
{
if(!isRivers())
@ -368,8 +406,15 @@ public class IrisRegion extends IrisRegistrant implements IRare
}
IrisBiome biome = (g == null ? Iris.globaldata : g.getData()).getBiomeLoader().load(i);
b.put(biome.getLoadKey(), biome);
names.remove(i);
if(biome == null)
{
continue;
}
names.add(biome.getCarvingBiome());
b.put(biome.getLoadKey(), biome);
names.addAll(biome.getChildren());
}
}

View File

@ -100,6 +100,11 @@ public class ResourceLoader<T extends IrisRegistrant>
public T load(String name)
{
if(name.trim().isEmpty())
{
return null;
}
String key = name + "-" + cname;
if(loadCache.containsKey(key))