Support decoration tops for stack decorations

This commit is contained in:
Daniel Mills 2020-10-23 10:21:39 -04:00
parent 75e508bfd0
commit 6d917b31e0
2 changed files with 54 additions and 1 deletions

View File

@ -419,6 +419,12 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
else else
{ {
int stack = i.getHeight(rng.nextParallelRNG((int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())), rx, rz, getData()); int stack = i.getHeight(rng.nextParallelRNG((int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())), rx, rz, getData());
FastBlockData top = null;
if(stack > 1 && i.getTopPalette().hasElements())
{
top = i.getBlockData(biome, rng.nextParallelRNG(38887 + biome.getRarity() + biome.getName().length() + j++), rx, rz, getData());
}
if(stack == 1) if(stack == 1)
{ {
@ -429,7 +435,7 @@ public abstract class TopographicTerrainProvider extends ParallelTerrainProvider
{ {
for(int l = 0; l < stack; l++) for(int l = 0; l < stack; l++)
{ {
sliver.set(k + l + 1, d); sliver.set(k + l + 1, l == stack - 1 && top != null ? top : d);
} }
} }
} }

View File

@ -87,10 +87,16 @@ public class IrisBiomeDecorator
@Desc("The palette of blocks to pick from when this decorator needs to place.") @Desc("The palette of blocks to pick from when this decorator needs to place.")
private KList<IrisBlockData> palette = new KList<IrisBlockData>().qadd(new IrisBlockData("grass")); private KList<IrisBlockData> palette = new KList<IrisBlockData>().qadd(new IrisBlockData("grass"));
@ArrayType(min = 1, type = IrisBlockData.class)
@DontObfuscate
@Desc("The palette of blocks used at the very top of a 'stackMax' of higher than 1. For example, bamboo tops.")
private KList<IrisBlockData> topPalette = new KList<IrisBlockData>();
private final transient AtomicCache<CNG> layerGenerator = new AtomicCache<>(); private final transient AtomicCache<CNG> layerGenerator = new AtomicCache<>();
private final transient AtomicCache<CNG> varianceGenerator = new AtomicCache<>(); private final transient AtomicCache<CNG> varianceGenerator = new AtomicCache<>();
private final transient AtomicCache<CNG> heightGenerator = new AtomicCache<>(); private final transient AtomicCache<CNG> heightGenerator = new AtomicCache<>();
private final transient AtomicCache<KList<FastBlockData>> blockData = new AtomicCache<>(); private final transient AtomicCache<KList<FastBlockData>> blockData = new AtomicCache<>();
private final transient AtomicCache<KList<FastBlockData>> blockDataTops = new AtomicCache<>();
public int getHeight(RNG rng, double x, double z, IrisDataManager data) public int getHeight(RNG rng, double x, double z, IrisDataManager data)
{ {
@ -150,6 +156,29 @@ public class IrisBiomeDecorator
return null; return null;
} }
public FastBlockData getBlockDataForTop(IrisBiome b, RNG rng, double x, double z, IrisDataManager data)
{
if(getBlockDataTops(data).isEmpty())
{
return null;
}
double xx = x / getZoom();
double zz = z / getZoom();
if(getGenerator(rng, data).fitDouble(0D, 1D, xx, zz) <= chance)
{
if(getBlockData(data).size() == 1)
{
return getBlockDataTops(data).get(0);
}
return getVarianceGenerator(rng, data).fit(getBlockDataTops(data), xx, zz);
}
return null;
}
public KList<FastBlockData> getBlockData(IrisDataManager data) public KList<FastBlockData> getBlockData(IrisDataManager data)
{ {
return blockData.aquire(() -> return blockData.aquire(() ->
@ -167,4 +196,22 @@ public class IrisBiomeDecorator
return blockData; return blockData;
}); });
} }
public KList<FastBlockData> getBlockDataTops(IrisDataManager data)
{
return blockDataTops.aquire(() ->
{
KList<FastBlockData> blockDataTops = new KList<>();
for(IrisBlockData i : topPalette)
{
FastBlockData bx = i.getBlockData(data);
if(bx != null)
{
blockDataTops.add(bx);
}
}
return blockDataTops;
});
}
} }