mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Merged pack authoring features
- Rivers take the hydrology policy fluid of the area where each reach starts - Policy fluid lookups for reach starts run in a sparse bake scope - Effects, vine faces, inland water biomes and fluid seams come from the contributed branch
This commit is contained in:
commit
64dc22025e
7 files changed
+183
-40
No files matched your search
@@ -457,40 +457,21 @@ final class DecoratorCore {
|
||||
BlockData rawB = (BlockData) b.nativeHandle();
|
||||
BlockData cloned = rawB.clone();
|
||||
MultipleFacing data = (MultipleFacing) cloned;
|
||||
if (data.getFaces().stream().anyMatch(f -> f != BlockFace.UP && f != BlockFace.DOWN)) {
|
||||
// The pack chose which side a hanging strand faces: keep it (the vine above holds it up), and tie the
|
||||
// block under a solid ceiling to it, so ceiling decorators hang curtains instead of flat ceiling sheets.
|
||||
if (data.getAllowedFaces().contains(BlockFace.UP) && sturdy(BlockFace.UP, hunk, rX, rZ, x, y, z, mantle)) {
|
||||
data.setFace(BlockFace.UP, true);
|
||||
}
|
||||
return BukkitBlockState.of(cloned);
|
||||
}
|
||||
data.getFaces().forEach(f -> data.setFace(f, false));
|
||||
|
||||
boolean found = false;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
if (!f.isCartesian()) {
|
||||
continue;
|
||||
}
|
||||
int yy = y + f.getModY();
|
||||
|
||||
NativeBlockState rs = null;
|
||||
if (mantle != null) {
|
||||
rs = mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class);
|
||||
}
|
||||
BlockData r = rs == null ? (BlockData) EngineMantle.AIR.get().nativeHandle() : (BlockData) rs.nativeHandle();
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
if (data.getAllowedFaces().contains(f)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int xx = rX + f.getModX();
|
||||
int zz = rZ + f.getModZ();
|
||||
if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy >= hunk.getHeight()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = (BlockData) hunk.get(xx, yy, zz).nativeHandle();
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
if (data.getAllowedFaces().contains(f)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
if (f.isCartesian() && sturdy(f, hunk, rX, rZ, x, y, z, mantle) && data.getAllowedFaces().contains(f)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
@@ -502,6 +483,22 @@ final class DecoratorCore {
|
||||
return BukkitBlockState.of(cloned);
|
||||
}
|
||||
|
||||
/** Whether the neighbour on that face (mantle first, then this chunk's hunk) offers a full sturdy face to attach to. */
|
||||
private static boolean sturdy(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
||||
int yy = y + f.getModY();
|
||||
NativeBlockState rs = mantle == null ? null : mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class);
|
||||
BlockData r = rs == null ? (BlockData) EngineMantle.AIR.get().nativeHandle() : (BlockData) rs.nativeHandle();
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
return true;
|
||||
}
|
||||
int xx = rX + f.getModX();
|
||||
int zz = rZ + f.getModZ();
|
||||
if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy >= hunk.getHeight()) {
|
||||
return false;
|
||||
}
|
||||
return ((BlockData) hunk.get(xx, yy, zz).nativeHandle()).isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL);
|
||||
}
|
||||
|
||||
static boolean canGoOn(NativeBlockState decorator, NativeBlockState surface) {
|
||||
if (!B.canPlaceOnto(decorator, surface)) {
|
||||
return false;
|
||||
|
||||
@@ -19,4 +19,6 @@ public class IrisFluidProfile {
|
||||
@Required
|
||||
@Description("Blocks that fill the water feature.")
|
||||
private IrisMaterialPalette palette = new IrisMaterialPalette().qclear().qadd("minecraft:water");
|
||||
@Description("Name of another fluid profile that fills this fluid's edge where it touches a different fluid, such as obsidian where lava meets water. Worldgen places fluids without updates, so unset leaves the two fluids side by side.")
|
||||
private String seam = null;
|
||||
}
|
||||
+6
-1
@@ -86,7 +86,12 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
|
||||
|
||||
@Override
|
||||
public String channelFluid(int x, int z) {
|
||||
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
|
||||
ChunkBakeCache.enterSparse();
|
||||
try {
|
||||
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
|
||||
} finally {
|
||||
ChunkBakeCache.exitSparse();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -61,6 +61,7 @@ public final class HydrologySettings {
|
||||
private final Deformation deformation;
|
||||
private final Underground underground;
|
||||
private final Map<String, IrisMaterialPalette> fluids;
|
||||
private final Map<String, String> seams;
|
||||
private final int prefetchRings;
|
||||
private final boolean persist;
|
||||
private final long fingerprint;
|
||||
@@ -83,6 +84,7 @@ public final class HydrologySettings {
|
||||
this.deformation = deformation(config.getDeformation());
|
||||
this.underground = underground(config.getUnderground());
|
||||
this.fluids = fluids(config.getFluids());
|
||||
this.seams = seams(config.getFluids());
|
||||
this.prefetchRings = config.getPrefetchRings();
|
||||
this.persist = config.isPersist();
|
||||
requireFluidReferences();
|
||||
@@ -167,6 +169,11 @@ public final class HydrologySettings {
|
||||
return fluids;
|
||||
}
|
||||
|
||||
/** Fluid name -> the fluid profile that fills its edge where it touches a different fluid. */
|
||||
public Map<String, String> seams() {
|
||||
return seams;
|
||||
}
|
||||
|
||||
public int prefetchRings() {
|
||||
return prefetchRings;
|
||||
}
|
||||
@@ -340,6 +347,16 @@ public final class HydrologySettings {
|
||||
return Collections.unmodifiableMap(compiled);
|
||||
}
|
||||
|
||||
private static Map<String, String> seams(List<IrisFluidProfile> profiles) {
|
||||
Map<String, String> seams = new LinkedHashMap<>();
|
||||
for (IrisFluidProfile profile : profiles) {
|
||||
if (profile.getSeam() != null && !profile.getSeam().isBlank()) {
|
||||
seams.put(profile.getName(), profile.getSeam());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(seams);
|
||||
}
|
||||
|
||||
private static IrisMaterialPalette requirePalette(IrisFluidProfile profile, String field) {
|
||||
IrisMaterialPalette palette = profile.getPalette();
|
||||
if (palette == null || unwritten(palette)) {
|
||||
@@ -481,6 +498,9 @@ public final class HydrologySettings {
|
||||
}
|
||||
requireFluid(ponds.fluid(), "ponds.fluid");
|
||||
requireFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
|
||||
for (Map.Entry<String, String> seam : seams.entrySet()) {
|
||||
requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private void requireFluid(String name, String field) {
|
||||
@@ -558,6 +578,10 @@ public final class HydrologySettings {
|
||||
for (Map.Entry<String, IrisMaterialPalette> fluid : fluids.entrySet()) {
|
||||
hash.add(fluid.getKey()).add(fluid.getValue());
|
||||
}
|
||||
hash.add(seams.size());
|
||||
for (Map.Entry<String, String> seam : seams.entrySet()) {
|
||||
hash.add(seam.getKey()).add(seam.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public record FloatRange(float min, float max) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.grid.CellHash;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
@@ -10,6 +11,8 @@ import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class RasterComposer {
|
||||
private static final int CHUNK = 16;
|
||||
@@ -22,6 +25,8 @@ final class RasterComposer {
|
||||
private static final double ROUNDING = 1e-6D;
|
||||
private static final int SLOPE_REACH = 2;
|
||||
private static final int RAY_STEP = 4;
|
||||
private static final long SALT_SEAM = 0x5345414d4c4eL;
|
||||
private static final double SEAM_SPREAD = 0.6D;
|
||||
|
||||
private final HydrologySettings settings;
|
||||
private final ChunkFeatures features;
|
||||
@@ -42,6 +47,7 @@ final class RasterComposer {
|
||||
private final HydrologyTier[] nearTier = new HydrologyTier[CELLS];
|
||||
private final ReachCursor cursor = new ReachCursor();
|
||||
private final int[] inletColumn = new int[2];
|
||||
private final Map<Long, String> reachFluids = new HashMap<>();
|
||||
private NaturalHeights naturalHeight;
|
||||
|
||||
RasterComposer(HydrologySettings settings, ChunkFeatures features, ChannelFluids channelFluids, int chunkX, int chunkZ) {
|
||||
@@ -75,6 +81,7 @@ final class RasterComposer {
|
||||
bermEdges();
|
||||
measureLakeShores();
|
||||
nameShores();
|
||||
sealSeams();
|
||||
return pack();
|
||||
}
|
||||
|
||||
@@ -116,6 +123,76 @@ final class RasterComposer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a fluid with a seam touches a different fluid (or the sea), fill its edge with the seam, e.g. a cooled-lava
|
||||
* crust where lava meets water. Every touching cell seals, and about SEAM_SPREAD of the cells next to those, picked
|
||||
* by a world-position hash, so the crust is a ragged band instead of a one-block line.
|
||||
*/
|
||||
private void sealSeams() {
|
||||
Map<String, String> seams = settings.seams();
|
||||
if (seams.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
boolean[] contact = new boolean[CELLS];
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
if (!sealable(cell, seams)) {
|
||||
continue;
|
||||
}
|
||||
String seam = seams.get(fluid[cell]);
|
||||
for (int dz = -1; dz <= 1 && !contact[cell]; dz++) {
|
||||
for (int dx = -1; dx <= 1 && !contact[cell]; dx++) {
|
||||
int next = neighbour(cell, dx, dz);
|
||||
contact[cell] = next >= 0 && meetsOther(cell, next, seam);
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean[] sealed = contact.clone();
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
if (contact[cell] || !sealable(cell, seams)) {
|
||||
continue;
|
||||
}
|
||||
int x = originX + cell % GRID;
|
||||
int z = originZ + cell / GRID;
|
||||
if (CellHash.unit(CellHash.mix(settings.seed(), SALT_SEAM, x, z)) >= SEAM_SPREAD) {
|
||||
continue;
|
||||
}
|
||||
for (int dz = -1; dz <= 1 && !sealed[cell]; dz++) {
|
||||
for (int dx = -1; dx <= 1 && !sealed[cell]; dx++) {
|
||||
int next = neighbour(cell, dx, dz);
|
||||
sealed[cell] = next >= 0 && contact[next];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
if (sealed[cell]) {
|
||||
fluid[cell] = seams.get(fluid[cell]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sealable(int cell, Map<String, String> seams) {
|
||||
return !corner(cell) && fluid[cell] != null && role[cell].wet() && seams.containsKey(fluid[cell]);
|
||||
}
|
||||
|
||||
/** Whether the neighbour holds a different fluid: other hydrology water, or the sea (dry here, ground below sea level). */
|
||||
private boolean meetsOther(int cell, int next, String seam) {
|
||||
if (corner(next) || next == cell) {
|
||||
return false;
|
||||
}
|
||||
if (role[next].wet()) {
|
||||
String other = fluid[next];
|
||||
return other != null && !other.equals(fluid[cell]) && !other.equals(seam);
|
||||
}
|
||||
return terrain[next] < settings.seaLevel();
|
||||
}
|
||||
|
||||
/** The grid cell dx,dz away, or -1 outside the grid. */
|
||||
private static int neighbour(int cell, int dx, int dz) {
|
||||
int x = cell % GRID + dx;
|
||||
int z = cell / GRID + dz;
|
||||
return x < 0 || x >= GRID || z < 0 || z >= GRID ? -1 : z * GRID + x;
|
||||
}
|
||||
|
||||
private void standing(int cell, Pond water, int floor) {
|
||||
head[cell] = level(water.level());
|
||||
terrain[cell] = Math.min(floor, head[cell] - 1);
|
||||
@@ -136,13 +213,19 @@ final class RasterComposer {
|
||||
ReachCursor.Choice hit = cursor.channel;
|
||||
Reach reach = hit.reach;
|
||||
int point = hit.point();
|
||||
String area = channelFluids.channelFluid(x, z);
|
||||
head[cell] = level(reach.grade()[point]);
|
||||
terrain[cell] = bed(hit, head[cell], ground, variation, BedProfile.detail(settings.seed(), x, z));
|
||||
role[cell] = role(reach.style()[point]);
|
||||
feature[cell] = reach.id();
|
||||
tier[cell] = reach.tier();
|
||||
fluid[cell] = area != null ? area : reach.tier().fluid();
|
||||
fluid[cell] = reachFluid(reach);
|
||||
}
|
||||
|
||||
private String reachFluid(Reach reach) {
|
||||
return reachFluids.computeIfAbsent(reach.id(), id -> {
|
||||
String area = channelFluids.channelFluid((int) Math.floor(reach.xs()[0]), (int) Math.floor(reach.zs()[0]));
|
||||
return area != null ? area : reach.tier().fluid();
|
||||
});
|
||||
}
|
||||
|
||||
private static int bed(ReachCursor.Choice hit, int surface, int ground, double variation, double detail) {
|
||||
|
||||
@@ -493,7 +493,7 @@ public class IrisComplex implements DataProvider {
|
||||
naturalTrueBiomeStream = new BakedStream<>(bakeCache, BakePlane.NATURAL_TRUE_BIOME, naturalTrueBiomeSource);
|
||||
shoreBiomes = new HydrologyShoreBiomes(engine.getDimension(), data, engine.getSeedManager().getBodies());
|
||||
hydrologyRuntime = HydrologyRuntime.create(engine, this);
|
||||
waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids()) : Map.of();
|
||||
waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids(), hydrologyRuntime.settings().seams().values()) : Map.of();
|
||||
pondMaterials = hydrologyRuntime.enabled() ? hydrologyRuntime.settings().ponds().materials() : null;
|
||||
waterVegetation = hydrologyRuntime.enabled() ? HydrologyVegetationSource.create(engine.getDimension(), hydrologyRuntime.settings(), data,
|
||||
engine.getDimension().getAllRegions(engine), engine.getDimension().getReachableBiomes(engine)) : HydrologyVegetationSource.NONE;
|
||||
@@ -1242,12 +1242,14 @@ public class IrisComplex implements DataProvider {
|
||||
public record BiomePick(IrisBiome biome, InferredType type) {
|
||||
}
|
||||
|
||||
private Map<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids) {
|
||||
private Map<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids,
|
||||
Collection<String> seams) {
|
||||
Map<String, ProceduralStream<NativeBlockState>> streams = new HashMap<>();
|
||||
int index = 0;
|
||||
for (Map.Entry<String, IrisMaterialPalette> fluid : fluids.entrySet()) {
|
||||
// a seam (obsidian where lava meets water) is the solid result of two fluids meeting, not a fluid itself
|
||||
streams.put(fluid.getKey(), configuredFluidStream(fluid.getValue(), rng.nextParallelRNG(10900 + index),
|
||||
"hydrology fluid " + fluid.getKey()));
|
||||
"hydrology fluid " + fluid.getKey(), !seams.contains(fluid.getKey())));
|
||||
index++;
|
||||
}
|
||||
return Map.copyOf(streams);
|
||||
@@ -1257,6 +1259,15 @@ public class IrisComplex implements DataProvider {
|
||||
IrisMaterialPalette palette,
|
||||
RNG fluidRng,
|
||||
String configurationName
|
||||
) {
|
||||
return configuredFluidStream(palette, fluidRng, configurationName, true);
|
||||
}
|
||||
|
||||
private ProceduralStream<NativeBlockState> configuredFluidStream(
|
||||
IrisMaterialPalette palette,
|
||||
RNG fluidRng,
|
||||
String configurationName,
|
||||
boolean fluidOnly
|
||||
) {
|
||||
Objects.requireNonNull(palette, configurationName + " fluidPalette must be configured");
|
||||
KList<NativeBlockState> blocks = palette.getBlockData(data);
|
||||
@@ -1265,7 +1276,7 @@ public class IrisComplex implements DataProvider {
|
||||
configurationName + " fluidPalette must resolve at least one fluid block");
|
||||
}
|
||||
for (NativeBlockState block : blocks) {
|
||||
if (block == null || !block.isFluid()) {
|
||||
if (block == null || fluidOnly && !block.isFluid()) {
|
||||
throw new IllegalArgumentException(
|
||||
configurationName + " fluidPalette may contain only fluid blocks");
|
||||
}
|
||||
@@ -1743,9 +1754,14 @@ public class IrisComplex implements DataProvider {
|
||||
if (mapped != null) {
|
||||
return mapped;
|
||||
}
|
||||
IrisBiome base = baseBiomeStream.get(x, z);
|
||||
if (base.getInferredType() == InferredType.LAND && inlandWater(x, z)) {
|
||||
// a pond or stream above sea level keeps the land around it, even where its floor dips below sea level
|
||||
return base;
|
||||
}
|
||||
return fixBiomeType(
|
||||
terrainHeight,
|
||||
baseBiomeStream.get(x, z),
|
||||
base,
|
||||
regionStream.get(x, z),
|
||||
x,
|
||||
z,
|
||||
@@ -1753,6 +1769,18 @@ public class IrisComplex implements DataProvider {
|
||||
);
|
||||
}
|
||||
|
||||
private boolean inlandWater(double x, double z) {
|
||||
int blockX = blockCoordinate(x);
|
||||
int blockZ = blockCoordinate(z);
|
||||
ChunkWaterRaster raster = hydrologyRasterAt(blockX, blockZ);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(blockX & 15, blockZ & 15);
|
||||
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET
|
||||
&& raster.waterHead(blockX & 15, blockZ & 15) > transitionFluidHeight(x, z, fluidHeight);
|
||||
}
|
||||
|
||||
private IrisBiome hydrologyShoreBiome(double terrainHeight, double x, double z) {
|
||||
int blockX = blockCoordinate(x);
|
||||
int blockZ = blockCoordinate(z);
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@@ -117,6 +118,9 @@ public class IrisEffect {
|
||||
@MaxNumber(512)
|
||||
@Description("The sound volume.")
|
||||
private double volume = 1.5D;
|
||||
@DependsOn({"sound"})
|
||||
@Description("The sound category the sound plays in, which picks the client volume slider that controls it (for example MUSIC, AMBIENT or HOSTILE).")
|
||||
private SoundCategory soundCategory = SoundCategory.MASTER;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(512)
|
||||
@@ -240,7 +244,7 @@ public class IrisEffect {
|
||||
Particle particleType = getParticleEffect();
|
||||
if (soundType != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||
p.playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
p.playSound(part, soundType, soundCategory, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
@@ -317,7 +321,7 @@ public class IrisEffect {
|
||||
Particle particleType = getParticleEffect();
|
||||
if (soundType != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||
p.getWorld().playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
p.getWorld().playSound(part, soundType, soundCategory, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
|
||||
Reference in new issue
Block a user