mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Added dimension stacking
- Dimension files define upright top-to-bottom terrain layers - Spacer values set exact air gaps between layers - Optional noise styles shape blended layer boundaries - Runtime queries resolve stacked terrain and biome ownership - Pack validation rejects invalid stack definitions - Project copy and hotload paths include stack dependencies - Superflat fixtures cover gaps, blending, clipping, and fluids - Platform tests cover stacked world generation contracts
This commit is contained in:
1 parent
366033a535
commit
6549b40797
119 files changed
+6874
-743
No files matched your search
+405
-58
@@ -4,6 +4,9 @@ import art.arcane.iris.platform.bukkit.BukkitWorldBinding;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.DimensionTerrainContext;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
@@ -16,6 +19,7 @@ import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.QuartPos;
|
||||
import net.minecraft.core.Registry;
|
||||
@@ -24,6 +28,8 @@ import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
@@ -80,27 +86,31 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
this.cacheRuntimeId = engine.getCacheID();
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getAllBiomes(Registry<Biome> customRegistry, Registry<Biome> registry, Engine engine) {
|
||||
private static List<Holder<Biome>> getAllBiomes(
|
||||
Registry<Biome> customRegistry,
|
||||
Registry<Biome> registry,
|
||||
Engine engine,
|
||||
boolean includeDimensionStack
|
||||
) {
|
||||
LinkedHashSet<Holder<Biome>> biomes = new LinkedHashSet<>();
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
for (OwnedBiome ownedBiome : getHostOwnedBiomes(engine)) {
|
||||
IrisBiome i = ownedBiome.biome();
|
||||
Holder<Biome> vanillaHolder = resolveBiomeHolder(registry, i.getStructureDerivativeKey());
|
||||
if (vanillaHolder == null) {
|
||||
throw new IllegalStateException("Iris structure biome derivative '"
|
||||
+ i.getStructureDerivativeKey() + "' is not registered for biome '" + i.getLoadKey() + "'");
|
||||
}
|
||||
biomes.add(vanillaHolder);
|
||||
}
|
||||
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
Holder<Biome> customHolder = resolveCustomBiomeHolder(customRegistry, engine, j.getId());
|
||||
if (customHolder == null) {
|
||||
throw new IllegalStateException("Iris custom structure biome '"
|
||||
+ engine.getDimension().getLoadKey() + ":" + j.getId() + "' is not registered");
|
||||
}
|
||||
biomes.add(customHolder);
|
||||
}
|
||||
}
|
||||
if (includeDimensionStack) {
|
||||
biomes.addAll(getVisibleBiomes(
|
||||
customRegistry,
|
||||
registry,
|
||||
engine,
|
||||
resolveFallbackBiome(registry, customRegistry)
|
||||
));
|
||||
}
|
||||
|
||||
if (biomes.isEmpty()) {
|
||||
@@ -110,6 +120,57 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return new ArrayList<>(biomes);
|
||||
}
|
||||
|
||||
private static List<Holder<Biome>> getVisibleBiomes(
|
||||
Registry<Biome> customRegistry,
|
||||
Registry<Biome> registry,
|
||||
Engine engine,
|
||||
Holder<Biome> fallback
|
||||
) {
|
||||
LinkedHashSet<Holder<Biome>> biomes = new LinkedHashSet<>();
|
||||
boolean fallbackPossible = false;
|
||||
for (OwnedBiome ownedBiome : getOwnedBiomes(engine)) {
|
||||
IrisBiome irisBiome = ownedBiome.biome();
|
||||
if (irisBiome.isCustom()) {
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
Holder<Biome> customHolder = resolveCustomBiomeHolder(
|
||||
customRegistry, ownedBiome.dimension(), customBiome.getId());
|
||||
if (customHolder == null) {
|
||||
throw new IllegalStateException("Iris custom visible biome '"
|
||||
+ customBiomeKey(ownedBiome.dimension(), customBiome.getId())
|
||||
+ "' is not registered");
|
||||
}
|
||||
biomes.add(customHolder);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
fallbackPossible |= !addVisibleBiomeHolder(
|
||||
biomes, registry, irisBiome.getDerivativeKey());
|
||||
for (String scatter : irisBiome.getBiomeScatter()) {
|
||||
fallbackPossible |= !addVisibleBiomeHolder(biomes, registry, scatter);
|
||||
}
|
||||
for (String scatter : irisBiome.getBiomeSkyScatter()) {
|
||||
fallbackPossible |= !addVisibleBiomeHolder(biomes, registry, scatter);
|
||||
}
|
||||
}
|
||||
if (fallbackPossible && fallback != null) {
|
||||
biomes.add(fallback);
|
||||
}
|
||||
return new ArrayList<>(biomes);
|
||||
}
|
||||
|
||||
private static boolean addVisibleBiomeHolder(
|
||||
Set<Holder<Biome>> biomes,
|
||||
Registry<Biome> registry,
|
||||
String biomeKey
|
||||
) {
|
||||
Holder<Biome> holder = resolveBiomeHolder(registry, biomeKey);
|
||||
if (holder == null) {
|
||||
return false;
|
||||
}
|
||||
biomes.add(holder);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Object getFor(Class<?> type, Object source) {
|
||||
Object o = fieldFor(type, source);
|
||||
|
||||
@@ -175,10 +236,19 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
|
||||
@Override
|
||||
protected Stream<Holder<Biome>> collectPossibleBiomes() {
|
||||
return possibleStructureBiomes().stream();
|
||||
return possibleBiomes(true).stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Holder<Biome>> possibleBiomes() {
|
||||
return possibleBiomes(true);
|
||||
}
|
||||
|
||||
Set<Holder<Biome>> possibleStructureBiomes() {
|
||||
return possibleBiomes(false);
|
||||
}
|
||||
|
||||
private Set<Holder<Biome>> possibleBiomes(boolean includeDimensionStack) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease("bukkit_possible_biomes");
|
||||
if (lease == null) {
|
||||
throw new IllegalStateException("Iris possible biome lookup was rejected during an engine transition");
|
||||
@@ -197,7 +267,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
.lookup(Registries.BIOME).orElse(null);
|
||||
Registry<Biome> worldRegistry = ((CraftWorld) world).getHandle().registryAccess()
|
||||
.lookup(Registries.BIOME).orElse(null);
|
||||
return Set.copyOf(getAllBiomes(customRegistry, worldRegistry, engine));
|
||||
return Set.copyOf(getAllBiomes(
|
||||
customRegistry, worldRegistry, engine, includeDimensionStack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,18 +278,22 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return m;
|
||||
}
|
||||
|
||||
for (IrisBiome i : engine.getAllBiomes()) {
|
||||
for (OwnedBiome ownedBiome : getOwnedBiomes(engine)) {
|
||||
IrisBiome i = ownedBiome.biome();
|
||||
if (i.isCustom()) {
|
||||
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
|
||||
Holder<Biome> holder = resolveCustomBiomeHolder(customRegistry, engine, j.getId());
|
||||
String key = customBiomeKey(ownedBiome.dimension(), j.getId());
|
||||
Holder<Biome> holder = resolveCustomBiomeHolder(
|
||||
customRegistry, ownedBiome.dimension(), j.getId());
|
||||
if (holder == null) {
|
||||
if (fallback != null) {
|
||||
m.put(j.getId(), fallback);
|
||||
m.put(key, fallback);
|
||||
}
|
||||
IrisLogging.error("Cannot find biome for IrisBiomeCustom " + j.getId() + " from engine " + engine.getName());
|
||||
IrisLogging.error("Cannot find biome for IrisBiomeCustom " + key
|
||||
+ " from engine " + engine.getName());
|
||||
continue;
|
||||
}
|
||||
m.put(j.getId(), holder);
|
||||
m.put(key, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,7 +307,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return Collections.unmodifiableMap(spawnBiomes);
|
||||
}
|
||||
|
||||
for (IrisBiome irisBiome : engine.getAllBiomes()) {
|
||||
for (OwnedBiome ownedBiome : getOwnedBiomes(engine)) {
|
||||
IrisBiome irisBiome = ownedBiome.biome();
|
||||
if (!irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
@@ -241,7 +317,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
Holder<Biome> customHolder = resolveCustomBiomeHolder(customRegistry, engine, customBiome.getId());
|
||||
Holder<Biome> customHolder = resolveCustomBiomeHolder(
|
||||
customRegistry, ownedBiome.dimension(), customBiome.getId());
|
||||
if (customHolder != null) {
|
||||
spawnBiomes.putIfAbsent(customHolder.value(), vanillaHolder);
|
||||
}
|
||||
@@ -268,6 +345,34 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
|
||||
Holder<Biome> getVisibleSurfaceBiome(int blockX, int blockZ) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease("bukkit_surface_spawn_biome");
|
||||
if (lease == null) {
|
||||
return null;
|
||||
}
|
||||
try (lease; IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
if (!isRuntimeAvailable()) {
|
||||
return null;
|
||||
}
|
||||
ensureCachesCurrent();
|
||||
int quartX = QuartPos.fromBlock(blockX);
|
||||
int quartZ = QuartPos.fromBlock(blockZ);
|
||||
int sampleX = QuartPos.toBlock(quartX);
|
||||
int sampleZ = QuartPos.toBlock(quartZ);
|
||||
boolean cacheable = isBiomeCacheable(engine, sampleX, sampleZ);
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
DimensionStackLayout.Layer layer = stackContext == null
|
||||
? null
|
||||
: stackContext.getLayout(sampleX, sampleZ).surfaceLayer();
|
||||
int internalY = layer == null
|
||||
? Engine.hostHeight(engine, sampleX, sampleZ, true)
|
||||
: layer.clippedSurfaceY();
|
||||
int quartY = QuartPos.fromBlock(internalY + engine.getWorld().minHeight());
|
||||
return getVisibleNoiseBiomeWithActiveGenerationLease(
|
||||
quartX, quartY, quartZ, null, null, cacheable);
|
||||
}
|
||||
}
|
||||
|
||||
private RegistryAccess registry() {
|
||||
RegistryAccess access = registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
|
||||
|
||||
@@ -294,28 +399,38 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
throw new IllegalStateException("Iris structure biome lookup has no active engine runtime");
|
||||
}
|
||||
ensureCachesCurrent();
|
||||
if (isGuaranteedSurfaceBiome(y)) {
|
||||
return getSurfaceStructureBiomeHolder(x, z);
|
||||
}
|
||||
return getStructureNoiseBiomeWithActiveGenerationLease(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
long cacheKey = packNoiseKey(x, y, z);
|
||||
private Holder<Biome> getStructureNoiseBiomeWithActiveGenerationLease(int x, int y, int z) {
|
||||
if (isGuaranteedSurfaceBiome(y)) {
|
||||
return getSurfaceStructureBiomeHolder(x, z);
|
||||
}
|
||||
|
||||
boolean cacheable = isBiomeCacheable(x, z);
|
||||
long cacheKey = packNoiseKey(x, y, z);
|
||||
if (cacheable) {
|
||||
Holder<Biome> cachedHolder = structureBiomeCache.get(cacheKey);
|
||||
if (cachedHolder != null) {
|
||||
return cachedHolder;
|
||||
}
|
||||
}
|
||||
|
||||
Holder<Biome> resolvedHolder = resolveStructureBiomeHolder(x, y, z);
|
||||
Holder<Biome> existingHolder = structureBiomeCache.putIfAbsent(cacheKey, resolvedHolder);
|
||||
if (existingHolder != null) {
|
||||
return existingHolder;
|
||||
}
|
||||
|
||||
if (structureBiomeCache.size() > NOISE_BIOME_CACHE_MAX) {
|
||||
structureBiomeCache.clear();
|
||||
}
|
||||
|
||||
Holder<Biome> resolvedHolder = resolveStructureBiomeHolder(x, y, z);
|
||||
if (!cacheable) {
|
||||
return resolvedHolder;
|
||||
}
|
||||
Holder<Biome> existingHolder = structureBiomeCache.putIfAbsent(cacheKey, resolvedHolder);
|
||||
if (existingHolder != null) {
|
||||
return existingHolder;
|
||||
}
|
||||
|
||||
if (structureBiomeCache.size() > NOISE_BIOME_CACHE_MAX) {
|
||||
structureBiomeCache.clear();
|
||||
}
|
||||
|
||||
return resolvedHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -346,6 +461,62 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<BlockPos, Holder<Biome>> findClosestBiome3d(
|
||||
BlockPos origin,
|
||||
int searchRadius,
|
||||
int sampleResolutionHorizontal,
|
||||
int sampleResolutionVertical,
|
||||
Predicate<Holder<Biome>> allowed,
|
||||
Climate.Sampler sampler,
|
||||
LevelReader level
|
||||
) {
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease("bukkit_locate_visible_biome");
|
||||
if (lease == null) {
|
||||
throw new IllegalStateException("Iris visible biome search was rejected during an engine transition");
|
||||
}
|
||||
try (lease; IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
prepareVisibleBiomeBatch();
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
if (stackContext == null) {
|
||||
return super.findClosestBiome3d(
|
||||
origin, searchRadius, sampleResolutionHorizontal, sampleResolutionVertical,
|
||||
allowed, sampler, level);
|
||||
}
|
||||
Set<Holder<Biome>> candidates = new HashSet<>();
|
||||
for (Holder<Biome> biome : getVisibleBiomes(
|
||||
biomeCustomRegistry, biomeRegistry, engine, fallbackBiome)) {
|
||||
if (allowed.test(biome)) {
|
||||
candidates.add(biome);
|
||||
}
|
||||
}
|
||||
if (candidates.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int sampleRadius = Math.floorDiv(searchRadius, sampleResolutionHorizontal);
|
||||
int[] sampleYs = Mth.outFromOrigin(
|
||||
origin.getY(), level.getMinY() + 1, level.getMaxY() + 1, sampleResolutionVertical).toArray();
|
||||
for (BlockPos.MutableBlockPos sampleColumn : BlockPos.spiralAround(
|
||||
BlockPos.ZERO, sampleRadius, Direction.EAST, Direction.SOUTH)) {
|
||||
int blockX = origin.getX() + sampleColumn.getX() * sampleResolutionHorizontal;
|
||||
int blockZ = origin.getZ() + sampleColumn.getZ() * sampleResolutionHorizontal;
|
||||
int quartX = QuartPos.fromBlock(blockX);
|
||||
int quartZ = QuartPos.fromBlock(blockZ);
|
||||
DimensionStackLayout stackLayout = stackContext.sample(
|
||||
QuartPos.toBlock(quartX), QuartPos.toBlock(quartZ));
|
||||
for (int blockY : sampleYs) {
|
||||
int quartY = QuartPos.fromBlock(blockY);
|
||||
Holder<Biome> visibleBiome = resolveVisibleBiomeHolder(
|
||||
quartX, quartY, quartZ, null, stackLayout);
|
||||
if (candidates.contains(visibleBiome)) {
|
||||
return Pair.of(new BlockPos(blockX, blockY, blockZ), visibleBiome);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static int horizontalBiomeSearchQuartStep(int blockY, int searchRadius) {
|
||||
return blockY == STRONGHOLD_RING_SEARCH_Y && searchRadius == STRONGHOLD_RING_SEARCH_RADIUS
|
||||
? STRONGHOLD_RING_SEARCH_QUART_STEP
|
||||
@@ -468,7 +639,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
private Holder<Biome> resolveSurfaceStructureBiomeHolder(int x, int z) {
|
||||
int blockX = x << 2;
|
||||
int blockZ = z << 2;
|
||||
IrisBiome irisBiome = engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
IrisBiome irisBiome = resolveSurfaceStructureBiome(engine, blockX, blockZ);
|
||||
if (irisBiome == null) {
|
||||
throw new IllegalStateException("Iris returned no surface structure biome at block "
|
||||
+ blockX + "," + blockZ);
|
||||
@@ -532,14 +703,32 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
int z,
|
||||
Climate.Sampler sampler,
|
||||
IrisDimensionCarvingResolver.State resolverState
|
||||
) {
|
||||
boolean cacheable = isBiomeCacheable(x, z);
|
||||
return getVisibleNoiseBiomeWithActiveGenerationLease(
|
||||
x, y, z, sampler, resolverState, cacheable);
|
||||
}
|
||||
|
||||
private Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
Climate.Sampler sampler,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
boolean cacheable
|
||||
) {
|
||||
long cacheKey = packNoiseKey(x, y, z);
|
||||
Holder<Biome> cachedHolder = noiseBiomeCache.get(cacheKey);
|
||||
if (cachedHolder != null) {
|
||||
return cachedHolder;
|
||||
if (cacheable) {
|
||||
Holder<Biome> cachedHolder = noiseBiomeCache.get(cacheKey);
|
||||
if (cachedHolder != null) {
|
||||
return cachedHolder;
|
||||
}
|
||||
}
|
||||
|
||||
Holder<Biome> resolvedHolder = resolveVisibleBiomeHolder(x, y, z, resolverState);
|
||||
if (!cacheable) {
|
||||
return resolvedHolder;
|
||||
}
|
||||
Holder<Biome> existingHolder = noiseBiomeCache.putIfAbsent(cacheKey, resolvedHolder);
|
||||
if (existingHolder != null) {
|
||||
return existingHolder;
|
||||
@@ -552,6 +741,18 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return resolvedHolder;
|
||||
}
|
||||
|
||||
private boolean isBiomeCacheable(int quartX, int quartZ) {
|
||||
return isBiomeCacheable(
|
||||
engine,
|
||||
QuartPos.toBlock(quartX),
|
||||
QuartPos.toBlock(quartZ)
|
||||
);
|
||||
}
|
||||
|
||||
static boolean isBiomeCacheable(Engine engine, int blockX, int blockZ) {
|
||||
return !engine.answersFromNaturalTerrain(blockX, blockZ);
|
||||
}
|
||||
|
||||
private GenerationSessionLease tryAcquireGenerationLease(String operation) {
|
||||
if (engine.isClosed()) {
|
||||
return null;
|
||||
@@ -597,7 +798,7 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveStructureBiomeHolder(int x, int y, int z) {
|
||||
BiomeResolution resolution = resolveBiomeResolution(x, y, z);
|
||||
BiomeResolution resolution = resolveStructureBiomeResolution(x, y, z);
|
||||
if (resolution == null) {
|
||||
throw new IllegalStateException("Iris returned no structure biome at quart "
|
||||
+ x + "," + y + "," + z);
|
||||
@@ -619,11 +820,26 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
int z,
|
||||
IrisDimensionCarvingResolver.State resolverState
|
||||
) {
|
||||
BiomeResolution resolution = resolveBiomeResolution(x, y, z, resolverState);
|
||||
return resolveVisibleBiomeHolder(x, y, z, resolverState, null);
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveVisibleBiomeHolder(
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
DimensionStackLayout stackLayout
|
||||
) {
|
||||
BiomeResolution resolution = resolveBiomeResolution(
|
||||
x, y, z, resolverState, true, stackLayout);
|
||||
if (resolution == null) {
|
||||
return getFallbackBiome();
|
||||
}
|
||||
|
||||
return resolveVisibleBiomeHolder(resolution);
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveVisibleBiomeHolder(BiomeResolution resolution) {
|
||||
if (resolution.irisBiome.isCustom()) {
|
||||
return resolveCustomHolder(resolution);
|
||||
}
|
||||
@@ -642,7 +858,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
private Holder<Biome> resolveCustomHolder(BiomeResolution resolution) {
|
||||
IrisBiomeCustom customBiome = resolution.irisBiome.getCustomBiome(resolution.rng, engine, resolution.blockX, resolution.blockY, resolution.blockZ);
|
||||
if (customBiome != null) {
|
||||
Holder<Biome> holder = customBiomes.get(customBiome.getId());
|
||||
Holder<Biome> holder = customBiomes.get(customBiomeKey(
|
||||
resolution.dimension, customBiome.getId()));
|
||||
if (holder != null) {
|
||||
return holder;
|
||||
}
|
||||
@@ -651,8 +868,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return getFallbackBiome();
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(int x, int y, int z) {
|
||||
return resolveBiomeResolution(x, y, z, null);
|
||||
private BiomeResolution resolveStructureBiomeResolution(int x, int y, int z) {
|
||||
return resolveBiomeResolution(x, y, z, null, false);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(
|
||||
@@ -660,6 +877,28 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
int y,
|
||||
int z,
|
||||
IrisDimensionCarvingResolver.State resolverState
|
||||
) {
|
||||
return resolveBiomeResolution(x, y, z, resolverState, true);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
boolean includeDimensionStack
|
||||
) {
|
||||
return resolveBiomeResolution(
|
||||
x, y, z, resolverState, includeDimensionStack, null);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
IrisDimensionCarvingResolver.State resolverState,
|
||||
boolean includeDimensionStack,
|
||||
DimensionStackLayout stackLayout
|
||||
) {
|
||||
if (engine == null || engine.isClosed()) {
|
||||
return null;
|
||||
@@ -675,31 +914,63 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
int worldMinHeight = engine.getWorld().minHeight();
|
||||
int internalY = blockY - worldMinHeight;
|
||||
int caveSwitchInternalY = Math.max(-8 - worldMinHeight, 40);
|
||||
DimensionStackLayout.Layer stackLayer = includeDimensionStack
|
||||
? stackLayout == null
|
||||
? resolveDimensionStackLayer(engine, blockX, internalY, blockZ)
|
||||
: stackLayout.layerAt(internalY)
|
||||
: null;
|
||||
IrisDimension owningDimension = stackLayer == null
|
||||
? engine.getDimension()
|
||||
: stackLayer.terrainContext().getDimension();
|
||||
if (stackLayer != null && !stackLayer.terrainContext().isSelfReferencing()) {
|
||||
IrisBiome stackedBiome = stackLayer.biome();
|
||||
return stackedBiome == null
|
||||
? null
|
||||
: createBiomeResolution(
|
||||
stackedBiome, false, owningDimension, blockX, blockY, blockZ);
|
||||
}
|
||||
boolean deepUnderground = internalY <= caveSwitchInternalY;
|
||||
boolean underground = false;
|
||||
IrisBiome irisBiome;
|
||||
if (deepUnderground) {
|
||||
int surfaceInternalY = engine.getComplex().getHeightStream().get(blockX, blockZ).intValue();
|
||||
if (stackLayer != null) {
|
||||
int surfaceInternalY = stackLayer.surfaceY();
|
||||
underground = internalY <= surfaceInternalY - 8;
|
||||
irisBiome = underground
|
||||
? engine.getCaveBiome(
|
||||
blockX,
|
||||
internalY,
|
||||
blockZ,
|
||||
resolverState,
|
||||
stackLayer.biome(),
|
||||
surfaceInternalY
|
||||
)
|
||||
: stackLayer.biome();
|
||||
} else if (deepUnderground) {
|
||||
int surfaceInternalY = Engine.hostHeight(engine, blockX, blockZ, true);
|
||||
underground = internalY <= surfaceInternalY - 8;
|
||||
irisBiome = underground
|
||||
? engine.getCaveBiome(blockX, internalY, blockZ, resolverState)
|
||||
: engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
: engine.getHostSurfaceBiome(blockX, blockZ);
|
||||
} else {
|
||||
irisBiome = engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
irisBiome = engine.getHostSurfaceBiome(blockX, blockZ);
|
||||
}
|
||||
if (irisBiome == null && underground) {
|
||||
irisBiome = engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
irisBiome = stackLayer == null
|
||||
? engine.getHostSurfaceBiome(blockX, blockZ)
|
||||
: stackLayer.biome();
|
||||
}
|
||||
if (irisBiome == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return createBiomeResolution(irisBiome, underground, blockX, blockY, blockZ);
|
||||
return createBiomeResolution(
|
||||
irisBiome, underground, owningDimension, blockX, blockY, blockZ);
|
||||
}
|
||||
|
||||
private BiomeResolution createBiomeResolution(
|
||||
IrisBiome irisBiome,
|
||||
boolean underground,
|
||||
IrisDimension dimension,
|
||||
int blockX,
|
||||
int blockY,
|
||||
int blockZ
|
||||
@@ -708,7 +979,8 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
^ (((long) blockX) * 341873128712L)
|
||||
^ (((long) blockY) * 132897987541L)
|
||||
^ (((long) blockZ) * 42317861L));
|
||||
return new BiomeResolution(irisBiome, underground, blockX, blockY, blockZ, noiseRng);
|
||||
return new BiomeResolution(
|
||||
irisBiome, underground, dimension, blockX, blockY, blockZ, noiseRng);
|
||||
}
|
||||
|
||||
private Holder<Biome> getFallbackBiome() {
|
||||
@@ -734,15 +1006,20 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return ((long) x << 32) ^ ((long) z & 4294967295L);
|
||||
}
|
||||
|
||||
private static Holder<Biome> resolveCustomBiomeHolder(Registry<Biome> customRegistry, Engine engine, String customBiomeId) {
|
||||
if (customRegistry == null || engine == null || customBiomeId == null || customBiomeId.isBlank()) {
|
||||
private static Holder<Biome> resolveCustomBiomeHolder(
|
||||
Registry<Biome> customRegistry,
|
||||
IrisDimension dimension,
|
||||
String customBiomeId
|
||||
) {
|
||||
if (customRegistry == null || dimension == null
|
||||
|| customBiomeId == null || customBiomeId.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Identifier resourceLocation = Identifier.fromNamespaceAndPath(
|
||||
engine.getDimension().getLoadKey().toLowerCase(java.util.Locale.ROOT),
|
||||
customBiomeId.toLowerCase(java.util.Locale.ROOT)
|
||||
);
|
||||
Identifier resourceLocation = Identifier.tryParse(customBiomeKey(dimension, customBiomeId));
|
||||
if (resourceLocation == null) {
|
||||
return null;
|
||||
}
|
||||
Biome biome = customRegistry.getValue(resourceLocation);
|
||||
if (biome == null) {
|
||||
return null;
|
||||
@@ -761,6 +1038,63 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
return optionalReferenceHolder.get();
|
||||
}
|
||||
|
||||
static String customBiomeKey(IrisDimension dimension, String customBiomeId) {
|
||||
return dimension.getCustomBiomeKey(customBiomeId);
|
||||
}
|
||||
|
||||
private static List<OwnedBiome> getOwnedBiomes(Engine engine) {
|
||||
ArrayList<OwnedBiome> biomes = new ArrayList<>(getHostOwnedBiomes(engine));
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
if (stackContext == null) {
|
||||
return biomes;
|
||||
}
|
||||
for (DimensionTerrainContext terrainContext : stackContext.getLayersBottomToTop()) {
|
||||
if (terrainContext.isSelfReferencing()) {
|
||||
continue;
|
||||
}
|
||||
IrisDimension dimension = terrainContext.getDimension();
|
||||
addOwnedBiomes(
|
||||
biomes,
|
||||
dimension,
|
||||
dimension.getReachableBiomes(terrainContext)
|
||||
);
|
||||
}
|
||||
return biomes;
|
||||
}
|
||||
|
||||
private static List<OwnedBiome> getHostOwnedBiomes(Engine engine) {
|
||||
IrisDimension hostDimension = engine.getDimension();
|
||||
ArrayList<OwnedBiome> biomes = new ArrayList<>();
|
||||
addOwnedBiomes(biomes, hostDimension, hostDimension.getReachableBiomes(engine));
|
||||
return biomes;
|
||||
}
|
||||
|
||||
private static void addOwnedBiomes(
|
||||
List<OwnedBiome> target,
|
||||
IrisDimension dimension,
|
||||
Iterable<IrisBiome> biomes
|
||||
) {
|
||||
for (IrisBiome biome : biomes) {
|
||||
if (biome != null) {
|
||||
target.add(new OwnedBiome(dimension, biome));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DimensionStackLayout.Layer resolveDimensionStackLayer(
|
||||
Engine engine,
|
||||
int blockX,
|
||||
int internalY,
|
||||
int blockZ
|
||||
) {
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
return stackContext == null ? null : stackContext.getLayerAt(blockX, internalY, blockZ);
|
||||
}
|
||||
|
||||
private static IrisBiome resolveSurfaceStructureBiome(Engine engine, int blockX, int blockZ) {
|
||||
return engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
}
|
||||
|
||||
private static Holder<Biome> resolveBiomeHolder(Registry<Biome> registry, String biomeKey) {
|
||||
if (registry == null || biomeKey == null || biomeKey.isBlank()) {
|
||||
return null;
|
||||
@@ -809,18 +1143,31 @@ public class CustomBiomeSource extends BiomeSource {
|
||||
private static final class BiomeResolution {
|
||||
private final IrisBiome irisBiome;
|
||||
private final boolean underground;
|
||||
private final IrisDimension dimension;
|
||||
private final int blockX;
|
||||
private final int blockY;
|
||||
private final int blockZ;
|
||||
private final RNG rng;
|
||||
|
||||
private BiomeResolution(IrisBiome irisBiome, boolean underground, int blockX, int blockY, int blockZ, RNG rng) {
|
||||
private BiomeResolution(
|
||||
IrisBiome irisBiome,
|
||||
boolean underground,
|
||||
IrisDimension dimension,
|
||||
int blockX,
|
||||
int blockY,
|
||||
int blockZ,
|
||||
RNG rng
|
||||
) {
|
||||
this.irisBiome = irisBiome;
|
||||
this.underground = underground;
|
||||
this.dimension = dimension;
|
||||
this.blockX = blockX;
|
||||
this.blockY = blockY;
|
||||
this.blockZ = blockZ;
|
||||
this.rng = rng;
|
||||
}
|
||||
}
|
||||
|
||||
private record OwnedBiome(IrisDimension dimension, IrisBiome biome) {
|
||||
}
|
||||
}
|
||||
+76
-14
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.core.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
import art.arcane.iris.engine.object.IrisBiome;
|
||||
@@ -40,6 +42,9 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Bukkit twin of the modded imported-feature stage. Same control, same semantics, same seeds: with
|
||||
@@ -198,8 +203,7 @@ final class ImportedFeatureStage {
|
||||
*/
|
||||
private Set<String> visibleBiomeKeys() {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
String namespace = engine.getDimension().getLoadKey().toLowerCase(Locale.ROOT);
|
||||
for (IrisBiome irisBiome : engine.getAllBiomes()) {
|
||||
for (IrisBiome irisBiome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
addKey(keys, irisBiome.getStructureDerivativeKey());
|
||||
addKey(keys, irisBiome.getDerivativeKey());
|
||||
addKey(keys, irisBiome.getVanillaDerivativeKey());
|
||||
@@ -213,7 +217,7 @@ final class ImportedFeatureStage {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
addKey(keys, namespace + ":" + customBiome.getId());
|
||||
addKey(keys, engine.getDimension().getCustomBiomeKey(customBiome.getId()));
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
@@ -226,8 +230,7 @@ final class ImportedFeatureStage {
|
||||
private Map<String, Holder<Biome>> customBiomeDerivatives(Registry<Biome> registry,
|
||||
Map<String, Holder<Biome>> byKey) {
|
||||
Map<String, Holder<Biome>> derivatives = new HashMap<>();
|
||||
String namespace = engine.getDimension().getLoadKey().toLowerCase(Locale.ROOT);
|
||||
for (IrisBiome irisBiome : engine.getAllBiomes()) {
|
||||
for (IrisBiome irisBiome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
if (!irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
@@ -246,7 +249,7 @@ final class ImportedFeatureStage {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
derivatives.put(namespace + ":" + customBiome.getId().toLowerCase(Locale.ROOT), derivative);
|
||||
derivatives.put(engine.getDimension().getCustomBiomeKey(customBiome.getId()), derivative);
|
||||
}
|
||||
}
|
||||
return derivatives;
|
||||
@@ -288,14 +291,24 @@ final class ImportedFeatureStage {
|
||||
List<FeatureSorter.StepFeatureData> steps = table.steps();
|
||||
WorldgenRandom random = new WorldgenRandom(new XoroshiroRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
long decorationSeed = random.setDecorationSeed(level.getSeed(), origin.getX(), origin.getZ());
|
||||
Set<Holder<Biome>> chunkBiomes = chunkBiomes(level, sectionPos, table);
|
||||
IrisStaticObjectLayer staticObjects = engine.getDimension().getStaticObjectLayer(engine.getData());
|
||||
int staticMinY = engine.getMinHeight();
|
||||
WorldGenLevel placementLevel = staticObjects.isEmpty() ? level : NativeStructureWorldgenAccess.create(
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
Set<Holder<Biome>> chunkBiomes = chunkBiomes(level, sectionPos, table, stackContext);
|
||||
IntBinaryOperator surfaceFirstFreeY = stackContext == null
|
||||
? (x, z) -> level.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z)
|
||||
: (x, z) -> Engine.hostHeight(engine, x, z, false) + staticMinY + 1;
|
||||
IntBinaryOperator floorFirstFreeY = stackContext == null
|
||||
? (x, z) -> level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z)
|
||||
: (x, z) -> Engine.hostHeight(engine, x, z, true) + staticMinY + 1;
|
||||
WorldGenLevel placementLevel = staticObjects.isEmpty() && stackContext == null
|
||||
? level
|
||||
: NativeStructureWorldgenAccess.create(
|
||||
level, centerPos,
|
||||
(x, z) -> level.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z),
|
||||
(x, z) -> level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z),
|
||||
position -> staticObjects.contains(position.getX(), position.getY() - staticMinY, position.getZ()));
|
||||
surfaceFirstFreeY,
|
||||
floorFirstFreeY,
|
||||
stackContext != null,
|
||||
importedFeatureProtection(staticObjects, stackContext, staticMinY));
|
||||
|
||||
try {
|
||||
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
|
||||
@@ -313,6 +326,30 @@ final class ImportedFeatureStage {
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<BlockPos> importedFeatureProtection(
|
||||
IrisStaticObjectLayer staticObjects,
|
||||
DimensionStackContext stackContext,
|
||||
int minimumY
|
||||
) {
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
private void placeStep(WorldGenLevel level, FeatureTable table, FeatureSorter.StepFeatureData stepData,
|
||||
Registry<PlacedFeature> featureRegistry, Set<Holder<Biome>> chunkBiomes,
|
||||
ChunkGenerator owner, WorldgenRandom random, long decorationSeed,
|
||||
@@ -353,12 +390,37 @@ final class ImportedFeatureStage {
|
||||
return id == null ? feature.toString() : id.toString();
|
||||
}
|
||||
|
||||
private Set<Holder<Biome>> chunkBiomes(WorldGenLevel level, SectionPos sectionPos, FeatureTable table) {
|
||||
private Set<Holder<Biome>> chunkBiomes(
|
||||
WorldGenLevel level,
|
||||
SectionPos sectionPos,
|
||||
FeatureTable table,
|
||||
DimensionStackContext stackContext
|
||||
) {
|
||||
List<Holder<Biome>> collected = new ArrayList<>();
|
||||
ChunkPos.rangeClosed(sectionPos.chunk(), 1).forEach((ChunkPos chunkPos) -> {
|
||||
ChunkAccess neighbour = level.getChunk(chunkPos.x(), chunkPos.z());
|
||||
for (LevelChunkSection section : neighbour.getSections()) {
|
||||
section.getBiomes().getAll(collected::add);
|
||||
LevelChunkSection[] sections = neighbour.getSections();
|
||||
for (int sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
||||
LevelChunkSection section = sections[sectionIndex];
|
||||
if (stackContext == null) {
|
||||
section.getBiomes().getAll(collected::add);
|
||||
continue;
|
||||
}
|
||||
int sectionMinimumY = neighbour.getSectionYFromSectionIndex(sectionIndex) << 4;
|
||||
for (int quartY = 0; quartY < 4; quartY++) {
|
||||
int internalY = sectionMinimumY + (quartY << 2) - level.getMinY();
|
||||
for (int quartX = 0; quartX < 4; quartX++) {
|
||||
int blockX = chunkPos.getMinBlockX() + (quartX << 2);
|
||||
for (int quartZ = 0; quartZ < 4; quartZ++) {
|
||||
int blockZ = chunkPos.getMinBlockZ() + (quartZ << 2);
|
||||
DimensionStackLayout.Layer layer = stackContext.getLayerAt(
|
||||
blockX, internalY, blockZ);
|
||||
if (layer.terrainContext().isSelfReferencing()) {
|
||||
collected.add(section.getBiomes().get(quartX, quartY, quartZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Set<Holder<Biome>> present = new LinkedHashSet<>();
|
||||
|
||||
+76
-14
@@ -1,5 +1,7 @@
|
||||
package art.arcane.iris.core.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
@@ -115,6 +117,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
private static final WrappedField<ChunkGenerator, BiomeSource> BIOME_SOURCE;
|
||||
@@ -429,7 +432,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
undergroundStep,
|
||||
decision.preserveSourceY(),
|
||||
decision.yBand(),
|
||||
(x, z) -> engine.getHeight(x, z, true) + engine.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(engine, x, z, true) + engine.getMinHeight());
|
||||
StructureStart wrapped = NativeStructureReferenceEnvelope.wrapForPublication(
|
||||
start, structure, start.getReferences(),
|
||||
NativeStructureTerrainIntegrator.resolveNativeTerrain(start, decision.terrain()),
|
||||
@@ -726,6 +729,14 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
return (x, z) -> engine.getHeight(x, z, true) + runtimeMinY + 1;
|
||||
}
|
||||
|
||||
private IntBinaryOperator hostWorldgenSurfaceHeight() {
|
||||
return (x, z) -> Engine.hostHeight(engine, x, z, false) + runtimeMinY + 1;
|
||||
}
|
||||
|
||||
private IntBinaryOperator hostWorldgenFloorHeight() {
|
||||
return (x, z) -> Engine.hostHeight(engine, x, z, true) + runtimeMinY + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeightedList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> holder, StructureManager structuremanager, MobCategory enumcreaturetype, BlockPos blockposition) {
|
||||
Holder<Biome> vanillaSpawnBiome = customBiomeSource.getVanillaSpawnBiome(holder);
|
||||
@@ -868,17 +879,22 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
}
|
||||
try {
|
||||
WorldgenTerrainHeightmaps.primeStructurePlacement(
|
||||
world, chunkPos, heightmapStarts, worldgenSurfaceHeight(), worldgenFloorHeight());
|
||||
world, chunkPos, heightmapStarts,
|
||||
hostWorldgenSurfaceHeight(), hostWorldgenFloorHeight());
|
||||
} catch (Throwable error) {
|
||||
throw NativeStructureGenerationException.failure(
|
||||
"heightmap priming", nativeStructureBatchContext(placementGroups),
|
||||
chunkPos.x(), chunkPos.z(), error);
|
||||
}
|
||||
IrisStaticObjectLayer staticObjects = engine.getDimension().getStaticObjectLayer(engine.getData());
|
||||
int staticMinY = engine.getMinHeight();
|
||||
WorldGenLevel boundedWorld = staticObjects.isEmpty() ? world : NativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, worldgenSurfaceHeight(), worldgenFloorHeight(),
|
||||
position -> staticObjects.contains(position.getX(), position.getY() - staticMinY, position.getZ()));
|
||||
Predicate<BlockPos> protectedPosition = nativeStructureProtection(staticObjects);
|
||||
WorldGenLevel boundedWorld = staticObjects.isEmpty()
|
||||
&& engine.getDimensionStackContext() == null
|
||||
? world
|
||||
: NativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, hostWorldgenSurfaceHeight(), hostWorldgenFloorHeight(),
|
||||
engine.getDimensionStackContext() != null,
|
||||
protectedPosition);
|
||||
try {
|
||||
NativeStructureVegetationClearer.clearIntersectingVegetation(
|
||||
boundedWorld, chunk, area, vegetationTargets);
|
||||
@@ -891,7 +907,7 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
try {
|
||||
vacuumFoundationPlan = NativeStructureSurfaceFitter.prepareSurfaceStructures(
|
||||
boundedWorld, area, terrainTargets,
|
||||
(x, z) -> engine.getHeight(x, z, true) + engine.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(engine, x, z, true) + engine.getMinHeight());
|
||||
} catch (Throwable error) {
|
||||
throw NativeStructureGenerationException.failure(
|
||||
"terrain integration", nativeStructureBatchContext(placementGroups),
|
||||
@@ -945,17 +961,45 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
BoundingBox area, ChunkPos chunkPos, String structureId, StructureStart start,
|
||||
IrisNativeStructureDecision decision) {
|
||||
WorldGenLevel boundedWorld = world instanceof NativeStructureWorldgenAccess ? world : NativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, worldgenSurfaceHeight(), worldgenFloorHeight(), position -> false);
|
||||
world,
|
||||
chunkPos,
|
||||
hostWorldgenSurfaceHeight(),
|
||||
hostWorldgenFloorHeight(),
|
||||
engine.getDimensionStackContext() != null,
|
||||
nativeStructureProtection(
|
||||
engine.getDimension().getStaticObjectLayer(engine.getData())));
|
||||
world.setCurrentlyGenerating(() -> "Iris native structure " + structureId);
|
||||
try {
|
||||
NativeStructurePostProcessor.place(boundedWorld, structureManager, this, random, area, chunkPos,
|
||||
structureId, start, decision, this::resolvePaletteBlock,
|
||||
(x, z) -> engine.getHeight(x, z, true) + engine.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(engine, x, z, true) + engine.getMinHeight());
|
||||
} finally {
|
||||
world.setCurrentlyGenerating(null);
|
||||
}
|
||||
}
|
||||
|
||||
private Predicate<BlockPos> nativeStructureProtection(IrisStaticObjectLayer staticObjects) {
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
int minimumY = engine.getMinHeight();
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
private List<List<Structure>> structuresByStep(Registry<Structure> registry) {
|
||||
StructureStepCache cached = structureStepCache;
|
||||
if (cached != null && cached.registry() == registry) {
|
||||
@@ -1041,7 +1085,17 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
@Override
|
||||
public void spawnOriginalMobs(WorldGenRegion region) {
|
||||
ChunkPos center = region.getCenter();
|
||||
Holder<Biome> visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
Holder<Biome> visibleBiome;
|
||||
if (engine.getDimensionStackContext() == null) {
|
||||
visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
} else {
|
||||
visibleBiome = customBiomeSource.getVisibleSurfaceBiome(
|
||||
center.getMinBlockX() + 8,
|
||||
center.getMinBlockZ() + 8);
|
||||
if (visibleBiome == null) {
|
||||
visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
}
|
||||
}
|
||||
Holder<Biome> vanillaBiome = customBiomeSource.getVanillaSpawnBiome(visibleBiome);
|
||||
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
random.setDecorationSeed(region.getSeed(), center.getMinBlockX(), center.getMinBlockZ());
|
||||
@@ -1081,9 +1135,12 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
public int getBaseHeight(int i, int j, Heightmap.Types heightmap_type, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease("bukkit_nms_base_height");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
boolean ignoreFluid = !heightmap_type.isOpaque().test(Blocks.WATER.defaultBlockState());
|
||||
int height = engine.getDimensionStackContext() == null
|
||||
? engine.getHeight(i, j, ignoreFluid)
|
||||
: Engine.hostHeight(engine, i, j, ignoreFluid);
|
||||
return levelheightaccessor.getMinY()
|
||||
+ engine.getHeight(i, j, !heightmap_type.isOpaque().test(Blocks.WATER.defaultBlockState()))
|
||||
+ 1;
|
||||
+ height + 1;
|
||||
} catch (GenerationSessionException e) {
|
||||
throw new IllegalStateException("Iris base height query could not acquire its engine runtime.", e);
|
||||
}
|
||||
@@ -1093,8 +1150,13 @@ public class IrisChunkGenerator extends CustomChunkGenerator {
|
||||
public NoiseColumn getBaseColumn(int i, int j, LevelHeightAccessor levelheightaccessor, RandomState randomstate) {
|
||||
try (GenerationSessionLease lease = engine.acquireGenerationLease("bukkit_nms_base_column");
|
||||
IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
int block = engine.getHeight(i, j, true);
|
||||
int water = engine.getHeight(i, j, false);
|
||||
boolean dimensionStack = engine.getDimensionStackContext() != null;
|
||||
int block = dimensionStack
|
||||
? Engine.hostHeight(engine, i, j, true)
|
||||
: engine.getHeight(i, j, true);
|
||||
int water = dimensionStack
|
||||
? Engine.hostHeight(engine, i, j, false)
|
||||
: engine.getHeight(i, j, false);
|
||||
BlockState[] column = new BlockState[levelheightaccessor.getHeight()];
|
||||
for (int k = 0; k < column.length; k++) {
|
||||
if (k <= block) {
|
||||
|
||||
+5
@@ -824,6 +824,11 @@ public class NMSBinding implements INMSBinding {
|
||||
return NativeStructureVolumeIndex.volumes(engine, minX, minZ, maxX, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateNativeStructureVolumeIndex(Engine engine) {
|
||||
NativeStructureVolumeIndex.invalidate(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeId(Biome biome) {
|
||||
for (World i : Bukkit.getWorlds()) {
|
||||
|
||||
+6
-2
@@ -64,6 +64,7 @@ final class NativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
private final ChunkPos generationCenter;
|
||||
private final IntBinaryOperator surfaceFirstFreeY;
|
||||
private final IntBinaryOperator floorFirstFreeY;
|
||||
private final boolean virtualizeHeights;
|
||||
private final Predicate<BlockPos> protectedPosition;
|
||||
private final Holder<Biome> fallbackBiome;
|
||||
private final BiomeManager biomeManager;
|
||||
@@ -81,6 +82,7 @@ final class NativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
boundary.surfaceFirstFreeY(), "Native structure world access requires a surface resolver");
|
||||
this.floorFirstFreeY = Objects.requireNonNull(
|
||||
boundary.floorFirstFreeY(), "Native structure world access requires an ocean-floor resolver");
|
||||
this.virtualizeHeights = boundary.virtualizeHeights();
|
||||
this.protectedPosition = Objects.requireNonNull(
|
||||
boundary.protectedPosition(), "World access requires a protected-position predicate");
|
||||
BlockPos biomeSample = generationCenter.getMiddleBlockPosition(delegate.getSeaLevel());
|
||||
@@ -103,9 +105,10 @@ final class NativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
static NativeStructureWorldgenAccess create(WorldGenLevel delegate, ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY,
|
||||
boolean virtualizeHeights,
|
||||
Predicate<BlockPos> protectedPosition) {
|
||||
return new NativeStructureWorldgenAccess(delegate, new Boundary(
|
||||
generationCenter, surfaceFirstFreeY, floorFirstFreeY, protectedPosition));
|
||||
generationCenter, surfaceFirstFreeY, floorFirstFreeY, virtualizeHeights, protectedPosition));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,7 +253,7 @@ final class NativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
|
||||
@Override
|
||||
public int getHeight(Heightmap.Types type, int x, int z) {
|
||||
if (isInsideGenerationRegion(x >> 4, z >> 4)) {
|
||||
if (!virtualizeHeights && isInsideGenerationRegion(x >> 4, z >> 4)) {
|
||||
return delegate.getHeight(type, x, z);
|
||||
}
|
||||
return height(type, x, z);
|
||||
@@ -549,6 +552,7 @@ final class NativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
private record Boundary(ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY,
|
||||
boolean virtualizeHeights,
|
||||
Predicate<BlockPos> protectedPosition) {
|
||||
}
|
||||
|
||||
|
||||
+176
-1
@@ -1,15 +1,29 @@
|
||||
package art.arcane.iris.core.nms.v26_2_R1;
|
||||
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CustomBiomeSourceStructureContractTest {
|
||||
@BeforeClass
|
||||
public static void bootstrapMinecraftRegistries() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeStructuresUseTerrainSafeDerivativeAtEveryBiomeBoundary() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
@@ -69,14 +83,53 @@ public class CustomBiomeSourceStructureContractTest {
|
||||
String realResolution = source.substring(realResolutionStart, naturalResolutionStart);
|
||||
String naturalResolution = source.substring(naturalResolutionStart, resolutionEnd);
|
||||
|
||||
assertTrue(realResolution.contains("engine.getComplex().getTrueBiomeStream().get(blockX, blockZ)"));
|
||||
assertTrue(realResolution.contains("resolveSurfaceStructureBiome(engine, blockX, blockZ)"));
|
||||
assertFalse(realResolution.contains("getNaturalTrueBiomeStream()"));
|
||||
assertTrue(naturalResolution.contains(
|
||||
"engine.getComplex().getNaturalTrueBiomeStream().get(blockX, blockZ)"));
|
||||
assertFalse(naturalResolution.contains("getTrueBiomeStream()"));
|
||||
int helperStart = source.indexOf("private static IrisBiome resolveSurfaceStructureBiome(");
|
||||
int helperEnd = source.indexOf("private static Holder<Biome> resolveBiomeHolder(", helperStart);
|
||||
String helper = source.substring(helperStart, helperEnd);
|
||||
assertTrue(helper.contains("engine.getComplex().getTrueBiomeStream().get(blockX, blockZ)"));
|
||||
assertFalse(helper.contains("getDimensionStackContext()"));
|
||||
assertFalse(helper.contains("getSurfaceBiome("));
|
||||
assertFalse(source.contains("studioBootstrapSurfaceStructureBiomeCache"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedCustomBiomesUseTheirOwningDimensionNamespace() {
|
||||
IrisDimension host = new IrisDimension();
|
||||
host.setLoadKey("Host");
|
||||
IrisDimension upper = new IrisDimension();
|
||||
upper.setLoadKey("Layers/Upper");
|
||||
|
||||
assertEquals("layers:upper/aurora", CustomBiomeSource.customBiomeKey(upper, "Aurora"));
|
||||
assertNotEquals(
|
||||
CustomBiomeSource.customBiomeKey(host, "Aurora"),
|
||||
CustomBiomeSource.customBiomeKey(upper, "Aurora")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visibleBiomeResolutionSelectsStackOwnershipBeforeHostCaves() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
int resolutionStart = source.indexOf("private BiomeResolution resolveBiomeResolution(");
|
||||
int resolutionEnd = source.indexOf("private BiomeResolution createBiomeResolution(", resolutionStart);
|
||||
|
||||
assertTrue(resolutionStart >= 0);
|
||||
assertTrue(resolutionEnd > resolutionStart);
|
||||
String resolution = source.substring(resolutionStart, resolutionEnd);
|
||||
|
||||
assertTrue(resolution.contains("resolveDimensionStackLayer("));
|
||||
assertTrue(resolution.contains("!stackLayer.terrainContext().isSelfReferencing()"));
|
||||
assertTrue(resolution.indexOf("resolveDimensionStackLayer(")
|
||||
< resolution.indexOf("boolean deepUnderground"));
|
||||
assertTrue(resolution.contains("includeDimensionStack"));
|
||||
assertTrue(source.contains("resolveBiomeResolution(x, y, z, null, false)"));
|
||||
assertTrue(source.contains("resolution.dimension, customBiome.getId()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visibleBiomeBatchReusesTheCallersGenerationLease() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
@@ -94,4 +147,126 @@ public class CustomBiomeSourceStructureContractTest {
|
||||
< lookup.indexOf("getVisibleNoiseBiomeWithActiveGenerationLease(x, y, z, sampler)"));
|
||||
assertFalse(source.contains("studioBootstrapNoiseBiomeCache"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackBiomesAreVisibleButExcludedFromStructureReachability() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
|
||||
assertTrue(source.contains("return possibleBiomes(true).stream()"));
|
||||
assertTrue(source.contains("public Set<Holder<Biome>> possibleBiomes()"));
|
||||
assertTrue(source.contains("irisBiome.getDerivativeKey()"));
|
||||
assertTrue(source.contains("irisBiome.getBiomeScatter()"));
|
||||
assertTrue(source.contains("irisBiome.getBiomeSkyScatter()"));
|
||||
assertTrue(source.contains("return possibleBiomes(false)"));
|
||||
assertTrue(source.contains("for (OwnedBiome ownedBiome : getHostOwnedBiomes(engine))"));
|
||||
assertTrue(source.contains("for (OwnedBiome ownedBiome : getOwnedBiomes(engine))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeLocatorSearchesTheVisibleStack() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
int start = source.indexOf("public Pair<BlockPos, Holder<Biome>> findClosestBiome3d(");
|
||||
int end = source.indexOf("static int horizontalBiomeSearchQuartStep", start);
|
||||
String method = source.substring(start, end);
|
||||
|
||||
assertTrue(method.contains("bukkit_locate_visible_biome"));
|
||||
assertTrue(method.contains("return super.findClosestBiome3d("));
|
||||
assertTrue(method.contains("getVisibleBiomes("));
|
||||
assertTrue(method.contains("QuartPos.toBlock(quartX), QuartPos.toBlock(quartZ)"));
|
||||
assertTrue(method.contains("resolveVisibleBiomeHolder("));
|
||||
assertFalse(method.contains("getStructureNoiseBiomeWithActiveGenerationLease("));
|
||||
assertTrue(method.indexOf("tryAcquireGenerationLease(\"bukkit_locate_visible_biome\")")
|
||||
< method.indexOf("engine.getDimensionStackContext()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surfaceSpawnBiomeUsesTheVisibleQuartCell() throws IOException {
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
int start = source.indexOf("Holder<Biome> getVisibleSurfaceBiome(");
|
||||
int end = source.indexOf("private RegistryAccess registry()", start);
|
||||
String method = source.substring(start, end);
|
||||
|
||||
assertTrue(method.contains("QuartPos.fromBlock(blockX)"));
|
||||
assertTrue(method.contains("QuartPos.toBlock(quartX)"));
|
||||
assertTrue(method.contains("QuartPos.fromBlock(internalY + engine.getWorld().minHeight())"));
|
||||
assertTrue(method.contains("stackContext.getLayout(sampleX, sampleZ).surfaceLayer()"));
|
||||
assertTrue(method.contains("getVisibleNoiseBiomeWithActiveGenerationLease("));
|
||||
assertTrue(method.contains("quartX, quartY, quartZ, null, null, cacheable"));
|
||||
assertTrue(method.indexOf("boolean cacheable = isBiomeCacheable(engine, sampleX, sampleZ)")
|
||||
< method.indexOf("Engine.hostHeight(engine, sampleX, sampleZ, true)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temporaryNaturalBiomeAnswersAreNotMemoized() throws IOException {
|
||||
Engine temporary = engineAnsweringNaturalFallback(true, 12, -8);
|
||||
Engine stable = engineAnsweringNaturalFallback(false, 12, -8);
|
||||
assertFalse(CustomBiomeSource.isBiomeCacheable(temporary, 12, -8));
|
||||
assertTrue(CustomBiomeSource.isBiomeCacheable(stable, 12, -8));
|
||||
|
||||
String source = Files.readString(Path.of(System.getProperty("iris.customBiomeSource")));
|
||||
int structureStart = source.indexOf(
|
||||
"private Holder<Biome> getStructureNoiseBiomeWithActiveGenerationLease(");
|
||||
int structureEnd = source.indexOf("@Override\n public Pair<BlockPos, Holder<Biome>> findBiomeHorizontal(",
|
||||
structureStart);
|
||||
assertCacheGuarded(source.substring(structureStart, structureEnd), "structureBiomeCache");
|
||||
|
||||
int firstVisible = source.indexOf(
|
||||
"Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(");
|
||||
int visibleStart = source.indexOf(
|
||||
"Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(", firstVisible + 1);
|
||||
int visibleEnd = source.indexOf("private boolean isBiomeCacheable(", visibleStart);
|
||||
assertCacheGuarded(source.substring(visibleStart, visibleEnd), "noiseBiomeCache");
|
||||
|
||||
String predicate = source.substring(
|
||||
visibleEnd,
|
||||
source.indexOf("private GenerationSessionLease tryAcquireGenerationLease(", visibleEnd)
|
||||
);
|
||||
assertTrue(predicate.contains("QuartPos.toBlock(quartX)"));
|
||||
assertTrue(predicate.contains("QuartPos.toBlock(quartZ)"));
|
||||
assertTrue(predicate.contains("return !engine.answersFromNaturalTerrain(blockX, blockZ)"));
|
||||
assertFalse(predicate.contains("getDimensionStackContext()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importedFeaturesCollectOnlyHostOwnedStackCells() throws IOException {
|
||||
Path biomeSource = Path.of(System.getProperty("iris.customBiomeSource"));
|
||||
String source = Files.readString(biomeSource.getParent().resolve("ImportedFeatureStage.java"));
|
||||
|
||||
assertTrue(source.contains("stackContext.getLayerAt("));
|
||||
assertTrue(source.contains("layer.terrainContext().isSelfReferencing()"));
|
||||
assertTrue(source.contains("section.getBiomes().get(quartX, quartY, quartZ)"));
|
||||
}
|
||||
|
||||
private static void assertCacheGuarded(String method, String cacheName) {
|
||||
int predicate = method.indexOf("boolean cacheable = isBiomeCacheable(");
|
||||
int read = method.indexOf(cacheName + ".get(", predicate);
|
||||
int readGuard = method.lastIndexOf("if (cacheable)", read);
|
||||
int bypass = method.indexOf("if (!cacheable)", read);
|
||||
int write = method.indexOf(cacheName + ".putIfAbsent(", bypass);
|
||||
|
||||
assertTrue(predicate >= 0);
|
||||
assertTrue(read > predicate);
|
||||
assertTrue(readGuard >= predicate);
|
||||
assertTrue(bypass > read);
|
||||
assertTrue(write > bypass);
|
||||
}
|
||||
|
||||
private static Engine engineAnsweringNaturalFallback(
|
||||
boolean naturalFallback,
|
||||
int expectedX,
|
||||
int expectedZ
|
||||
) {
|
||||
return (Engine) Proxy.newProxyInstance(
|
||||
Engine.class.getClassLoader(),
|
||||
new Class<?>[]{Engine.class},
|
||||
(proxy, method, arguments) -> {
|
||||
if (!method.getName().equals("answersFromNaturalTerrain")) {
|
||||
throw new UnsupportedOperationException(method.getName());
|
||||
}
|
||||
assertEquals(Integer.valueOf(expectedX), arguments[0]);
|
||||
assertEquals(Integer.valueOf(expectedZ), arguments[1]);
|
||||
return naturalFallback;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -78,6 +78,8 @@ public class IrisChunkGeneratorFailureContractTest {
|
||||
< placement.indexOf("for (NativePlacementGroup group"));
|
||||
assertTrue(placement.indexOf("repairVacuumFoundations")
|
||||
> placement.indexOf("for (NativePlacementGroup group"));
|
||||
assertTrue(placement.contains("nativeStructureProtection(staticObjects)"));
|
||||
assertTrue(placement.contains("Engine.hostHeight(engine, x, z, true)"));
|
||||
assertFalse(placement.contains("IrisLogging.reportError"));
|
||||
}
|
||||
|
||||
@@ -542,8 +544,8 @@ public class IrisChunkGeneratorFailureContractTest {
|
||||
String spawn = source.substring(spawnStart, spawnEnd);
|
||||
|
||||
assertTrue(spawn.contains("customBiomeSource.getVanillaSpawnBiome(visibleBiome)"));
|
||||
assertTrue(spawn.contains("customBiomeSource.getVisibleSurfaceBiome("));
|
||||
assertTrue(spawn.contains("NaturalSpawner.spawnMobsForChunkGeneration("));
|
||||
assertTrue(spawn.contains("region.getBiome(center.getWorldPosition().atY(region.getMaxY()))"));
|
||||
assertTrue(spawn.contains("new LegacyRandomSource(RandomSupport.generateUniqueSeed())"));
|
||||
assertTrue(spawn.contains("random.setDecorationSeed(region.getSeed()"));
|
||||
assertFalse(spawn.contains("delegate.spawnOriginalMobs"));
|
||||
|
||||
+24
-2
@@ -135,6 +135,24 @@ public class NativeStructureWorldgenAccessTest {
|
||||
assertEquals(1, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void virtualizedHeightsHideInRegionTerrainFromTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
NativeStructureWorldgenAccess access = NativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter,
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
true,
|
||||
position -> false);
|
||||
int x = generationCenter.getMiddleBlockX();
|
||||
int z = generationCenter.getMiddleBlockZ();
|
||||
|
||||
assertEquals(SURFACE_FIRST_FREE_Y, access.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z));
|
||||
assertEquals(FLOOR_FIRST_FREE_Y, access.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z));
|
||||
assertEquals(0, recording.heightReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protectedCellsRemainReadableButRejectWritesTilesAndTicks() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
@@ -142,7 +160,9 @@ public class NativeStructureWorldgenAccessTest {
|
||||
NativeStructureWorldgenAccess access = NativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y, position::equals);
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
false,
|
||||
position::equals);
|
||||
|
||||
assertSame(Blocks.DIRT, access.getBlockState(position).getBlock());
|
||||
assertFalse(access.ensureCanWrite(position));
|
||||
@@ -211,7 +231,9 @@ public class NativeStructureWorldgenAccessTest {
|
||||
return NativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y, position -> false);
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
false,
|
||||
position -> false);
|
||||
}
|
||||
|
||||
private static ChunkPos generationCenter() {
|
||||
|
||||
+12
@@ -332,6 +332,18 @@ public class NativeStructureFactoryTest {
|
||||
assertTrue(failureStart < source.indexOf("NativeStructureOwnershipStore.record("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manualNativeStructureGenerationUsesTheRootTerrainHeight() throws Exception {
|
||||
String source = Files.readString(
|
||||
Path.of(System.getProperty("iris.nativeStructureStartInjectorSource")),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
assertTrue(source.contains(
|
||||
"Engine.hostHeight(context.engine(), x, z, true)"));
|
||||
assertFalse(source.contains(
|
||||
"context.engine().getHeight(x, z, true)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failedManualStartPublicationClearsRecordedOwnershipAndPreservesTheFailure() throws Exception {
|
||||
String source = Files.readString(
|
||||
|
||||
+5
@@ -84,6 +84,11 @@ public final class BukkitEnginePlatformHooks implements EnginePlatformHooks {
|
||||
"iris");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareRuntimeHotload(Engine engine) {
|
||||
INMS.get().invalidateNativeStructureVolumeIndex(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyWorldBoundary(Engine engine) {
|
||||
IrisDimension expectedDimension = engine.getDimension();
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ public final class NativeStructureOwnershipRecovery {
|
||||
level,
|
||||
biome -> true,
|
||||
generator.getSeaLevel(),
|
||||
(x, z) -> engine.getHeight(x, z, true) + engine.getMinHeight()
|
||||
(x, z) -> Engine.hostHeight(engine, x, z, true) + engine.getMinHeight()
|
||||
);
|
||||
return NativeStructureFactory.generate(generationContext, holder, plan, references);
|
||||
}
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ public final class NativeStructureStartInjector {
|
||||
chunk,
|
||||
biome -> true,
|
||||
context.generator().getSeaLevel(),
|
||||
(x, z) -> context.engine().getHeight(x, z, true)
|
||||
(x, z) -> Engine.hostHeight(context.engine(), x, z, true)
|
||||
+ context.engine().getMinHeight()
|
||||
);
|
||||
StructureStart generated = NativeStructureFactory.generate(
|
||||
|
||||
+19
-1
@@ -89,6 +89,18 @@ public final class NativeStructureVolumeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
public static void invalidate(Engine engine) {
|
||||
if (engine == null) {
|
||||
return;
|
||||
}
|
||||
synchronized (INDEXES) {
|
||||
NativeStructureVolumeIndex current = INDEXES.get(engine);
|
||||
if (current != null) {
|
||||
INDEXES.put(engine, current.fresh());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static KList<NativeStructureVolume> volumes(Engine engine, int minX, int minZ, int maxX, int maxZ) {
|
||||
NativeStructureVolumeIndex index = engine == null ? null : INDEXES.get(engine);
|
||||
return index == null ? NativeStructureVolume.NONE : index.resolve(engine, minX, minZ, maxX, maxZ);
|
||||
@@ -102,6 +114,12 @@ public final class NativeStructureVolumeIndex {
|
||||
return ORIGIN_REACH_CHUNKS;
|
||||
}
|
||||
|
||||
private NativeStructureVolumeIndex fresh() {
|
||||
return context == null
|
||||
? new NativeStructureVolumeIndex(origins)
|
||||
: new NativeStructureVolumeIndex(context);
|
||||
}
|
||||
|
||||
KList<NativeStructureVolume> resolve(Engine engine, int minX, int minZ, int maxX, int maxZ) {
|
||||
int fromChunkX = Math.min(minX, maxX) >> 4;
|
||||
int toChunkX = Math.max(minX, maxX) >> 4;
|
||||
@@ -323,7 +341,7 @@ public final class NativeStructureVolumeIndex {
|
||||
}
|
||||
|
||||
private static IntBinaryOperator surfaceHeight(Engine engine) {
|
||||
return (x, z) -> engine.getHeight(x, z, true) + engine.getMinHeight();
|
||||
return (x, z) -> Engine.hostHeight(engine, x, z, true) + engine.getMinHeight();
|
||||
}
|
||||
|
||||
static KList<NativeStructureVolume> appendPieces(KList<NativeStructureVolume> volumes,
|
||||
|
||||
+491
-49
@@ -18,16 +18,22 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.DimensionTerrainContext;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionException;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.object.IrisBiome;
|
||||
import art.arcane.iris.engine.object.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.QuartPos;
|
||||
@@ -37,12 +43,15 @@ import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -196,11 +205,16 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
|
||||
private List<Holder<Biome>> collectPossibleBiomeHolders() {
|
||||
BiomeKeySets keys = biomeKeySets();
|
||||
Set<String> generatedBiomeKeys = requireConfiguredStructureBiomeKeys(keys.required());
|
||||
Set<String> visibleBiomeKeys = keys.visibleOnly();
|
||||
LinkedHashSet<String> generatedBiomeKeys = new LinkedHashSet<>(
|
||||
requireConfiguredStructureBiomeKeys(keys.structureRequired()));
|
||||
generatedBiomeKeys.addAll(keys.visibleRequired());
|
||||
LinkedHashSet<String> visibleBiomeKeys = new LinkedHashSet<>(keys.visibleOnly());
|
||||
Registry<Biome> registry = biomeRegistry();
|
||||
LinkedHashSet<Holder<Biome>> possible = new LinkedHashSet<>();
|
||||
if (registry == null) {
|
||||
if (keys.visibleFallbackPossible()) {
|
||||
visibleBiomeKeys.add("minecraft:plains");
|
||||
}
|
||||
for (Holder<Biome> biome : serializedSource.possibleBiomes()) {
|
||||
String key = holderKey(biome);
|
||||
if (isGeneratedBiomeKey(key, generatedBiomeKeys)
|
||||
@@ -215,6 +229,9 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
throw new IllegalStateException("Iris structure biomes are not registered: "
|
||||
+ missingBiomeKeys);
|
||||
}
|
||||
if (needsVisibleFallback(keys, registry)) {
|
||||
visibleBiomeKeys.add("minecraft:plains");
|
||||
}
|
||||
// Registry-ordered, never a hash-ordered walk: see possibleBiomes().
|
||||
registry.listElements().forEach((Holder.Reference<Biome> reference) -> {
|
||||
String key = holderKey(reference);
|
||||
@@ -223,7 +240,7 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
possible.add(reference);
|
||||
}
|
||||
});
|
||||
warnUnregisteredVisibleBiomes(registry, visibleBiomeKeys);
|
||||
warnUnregisteredVisibleBiomes(registry, keys.visibleOnly());
|
||||
}
|
||||
if (possible.isEmpty()) {
|
||||
String phase = registry == null ? "serialized biome bootstrap" : "biome registry";
|
||||
@@ -233,6 +250,36 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
return List.copyOf(possible);
|
||||
}
|
||||
|
||||
private List<Holder<Biome>> collectVisibleBiomeHolders() {
|
||||
BiomeKeySets keys = biomeKeySets();
|
||||
Set<String> visibleBiomeKeys = keys.visibleEmittable();
|
||||
Registry<Biome> registry = biomeRegistry();
|
||||
boolean includeFallback = registry == null
|
||||
? keys.visibleFallbackPossible()
|
||||
: needsVisibleFallback(keys, registry);
|
||||
ArrayList<Holder<Biome>> visible = new ArrayList<>();
|
||||
for (Holder<Biome> biome : resolvePossibleBiomes().ordered()) {
|
||||
String key = holderKey(biome);
|
||||
if (isGeneratedBiomeKey(key, visibleBiomeKeys)
|
||||
|| includeFallback && "minecraft:plains".equals(key)) {
|
||||
visible.add(biome);
|
||||
}
|
||||
}
|
||||
return List.copyOf(visible);
|
||||
}
|
||||
|
||||
private static boolean needsVisibleFallback(BiomeKeySets keys, Registry<Biome> registry) {
|
||||
if (keys.visibleFallbackPossible()) {
|
||||
return true;
|
||||
}
|
||||
for (String key : keys.visibleEmittable()) {
|
||||
if (resolveHolder(registry, key) == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scatter and derivative keys are advisory: a typo there must not stop a world from loading the way a
|
||||
* missing structure biome does, so they are reported once and skipped.
|
||||
@@ -273,19 +320,91 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<BlockPos, Holder<Biome>> findClosestBiome3d(
|
||||
BlockPos origin,
|
||||
int searchRadius,
|
||||
int sampleResolutionHorizontal,
|
||||
int sampleResolutionVertical,
|
||||
Predicate<Holder<Biome>> allowed,
|
||||
Climate.Sampler sampler,
|
||||
LevelReader level
|
||||
) {
|
||||
Engine engine = engineOrNull();
|
||||
if (engine == null) {
|
||||
return serializedSource.findClosestBiome3d(
|
||||
origin, searchRadius, sampleResolutionHorizontal, sampleResolutionVertical,
|
||||
allowed, sampler, level);
|
||||
}
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_locate_visible_biome");
|
||||
if (lease == null) {
|
||||
throw new IllegalStateException("Iris visible biome search was rejected during an engine transition");
|
||||
}
|
||||
try (lease; IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
if (!isReady(engine)) {
|
||||
throw new IllegalStateException("Iris visible biome search has no active engine runtime");
|
||||
}
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
if (stackContext == null) {
|
||||
return super.findClosestBiome3d(
|
||||
origin, searchRadius, sampleResolutionHorizontal, sampleResolutionVertical,
|
||||
allowed, sampler, level);
|
||||
}
|
||||
Set<Holder<Biome>> candidates = new HashSet<>();
|
||||
for (Holder<Biome> biome : collectVisibleBiomeHolders()) {
|
||||
if (allowed.test(biome)) {
|
||||
candidates.add(biome);
|
||||
}
|
||||
}
|
||||
if (candidates.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int sampleRadius = Math.floorDiv(searchRadius, sampleResolutionHorizontal);
|
||||
int[] sampleYs = Mth.outFromOrigin(
|
||||
origin.getY(), level.getMinY() + 1, level.getMaxY() + 1, sampleResolutionVertical).toArray();
|
||||
for (BlockPos.MutableBlockPos sampleColumn : BlockPos.spiralAround(
|
||||
BlockPos.ZERO, sampleRadius, Direction.EAST, Direction.SOUTH)) {
|
||||
int blockX = origin.getX() + sampleColumn.getX() * sampleResolutionHorizontal;
|
||||
int blockZ = origin.getZ() + sampleColumn.getZ() * sampleResolutionHorizontal;
|
||||
int quartX = QuartPos.fromBlock(blockX);
|
||||
int quartZ = QuartPos.fromBlock(blockZ);
|
||||
DimensionStackLayout stackLayout = stackContext.sample(
|
||||
QuartPos.toBlock(quartX), QuartPos.toBlock(quartZ));
|
||||
for (int blockY : sampleYs) {
|
||||
int quartY = QuartPos.fromBlock(blockY);
|
||||
Holder<Biome> visibleBiome = resolveVisibleBiome(
|
||||
engine, quartX, quartY, quartZ, sampler, stackLayout);
|
||||
if (candidates.contains(visibleBiome)) {
|
||||
return Pair.of(new BlockPos(blockX, blockY, blockZ), visibleBiome);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Holder<Biome> getNoiseBiome(Engine engine, int quartX, int quartY, int quartZ,
|
||||
Climate.Sampler sampler) {
|
||||
if (isGuaranteedSurfaceBiome(quartY, engine.getMinHeight())) {
|
||||
return getSurfaceStructureBiome(engine, quartX, quartZ, sampler);
|
||||
}
|
||||
boolean cacheable = isBiomeCacheable(
|
||||
engine,
|
||||
QuartPos.toBlock(quartX),
|
||||
QuartPos.toBlock(quartZ)
|
||||
);
|
||||
long key = packNoiseKey(quartX, quartY, quartZ);
|
||||
BiomeHolderTable cache = structureBiomeCache;
|
||||
Holder<Biome> cached = cache.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
if (cacheable) {
|
||||
Holder<Biome> cached = cache.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
Holder<Biome> resolved = resolveStructureBiome(engine, quartX, quartY, quartZ, sampler);
|
||||
cache.put(key, resolved);
|
||||
if (cacheable) {
|
||||
cache.put(key, resolved);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
@@ -302,14 +421,81 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
if (!isReady(engine)) {
|
||||
throw new IllegalStateException("Iris visible biome lookup has no active engine runtime");
|
||||
}
|
||||
long key = packNoiseKey(quartX, quartY, quartZ);
|
||||
BiomeHolderTable cache = visibleBiomeCache;
|
||||
return getVisibleNoiseBiomeWithActiveGenerationLease(
|
||||
engine, quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
}
|
||||
|
||||
private Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(
|
||||
Engine engine,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ,
|
||||
Climate.Sampler sampler
|
||||
) {
|
||||
boolean cacheable = isBiomeCacheable(
|
||||
engine,
|
||||
QuartPos.toBlock(quartX),
|
||||
QuartPos.toBlock(quartZ)
|
||||
);
|
||||
long key = packNoiseKey(quartX, quartY, quartZ);
|
||||
BiomeHolderTable cache = visibleBiomeCache;
|
||||
if (cacheable) {
|
||||
Holder<Biome> cached = cache.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
Holder<Biome> resolved = resolveVisibleBiome(engine, quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
Holder<Biome> resolved = resolveVisibleBiome(engine, quartX, quartY, quartZ, sampler);
|
||||
if (cacheable) {
|
||||
cache.put(key, resolved);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
Holder<Biome> getVisibleSurfaceBiome(int blockX, int blockZ) {
|
||||
Engine engine = engineOrNull();
|
||||
if (engine == null) {
|
||||
return null;
|
||||
}
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_surface_spawn_biome");
|
||||
if (lease == null) {
|
||||
return null;
|
||||
}
|
||||
try (lease; IrisContext.Scope ignored = IrisContext.open(engine, lease.sessionId(), null)) {
|
||||
if (!isReady(engine)) {
|
||||
return null;
|
||||
}
|
||||
Registry<Biome> registry = biomeRegistry();
|
||||
if (registry == null) {
|
||||
return null;
|
||||
}
|
||||
int quartX = QuartPos.fromBlock(blockX);
|
||||
int quartZ = QuartPos.fromBlock(blockZ);
|
||||
int sampleX = QuartPos.toBlock(quartX);
|
||||
int sampleZ = QuartPos.toBlock(quartZ);
|
||||
boolean cacheable = isBiomeCacheable(engine, sampleX, sampleZ);
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
DimensionStackLayout.Layer layer = stackContext == null
|
||||
? null
|
||||
: stackContext.getLayout(sampleX, sampleZ).surfaceLayer();
|
||||
int internalY = layer == null
|
||||
? Engine.hostHeight(engine, sampleX, sampleZ, true)
|
||||
: layer.clippedSurfaceY();
|
||||
int quartY = QuartPos.fromBlock(internalY + engine.getMinHeight());
|
||||
long key = packNoiseKey(quartX, quartY, quartZ);
|
||||
BiomeHolderTable cache = visibleBiomeCache;
|
||||
if (cacheable) {
|
||||
Holder<Biome> cached = cache.get(key);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
Holder<Biome> resolved = resolveVisibleBiome(
|
||||
engine, quartX, quartY, quartZ, null);
|
||||
if (cacheable) {
|
||||
cache.put(key, resolved);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
@@ -395,7 +581,9 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
if (registry == null) {
|
||||
throw new IllegalStateException("Iris structure biome lookup has no biome registry");
|
||||
}
|
||||
IrisBiome irisBiome = engine.getComplex().getTrueBiomeStream().get(quartX << 2, quartZ << 2);
|
||||
int blockX = quartX << 2;
|
||||
int blockZ = quartZ << 2;
|
||||
IrisBiome irisBiome = resolveSurfaceStructureBiome(engine, blockX, blockZ);
|
||||
if (irisBiome == null) {
|
||||
throw new IllegalStateException("Iris returned no surface structure biome at quart "
|
||||
+ quartX + "," + quartZ);
|
||||
@@ -412,7 +600,8 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
private Holder<Biome> resolveStructureBiome(Engine engine, int quartX, int quartY, int quartZ,
|
||||
Climate.Sampler sampler) {
|
||||
Registry<Biome> registry = biomeRegistry();
|
||||
BiomeResolution resolution = resolveBiomeResolution(engine, quartX, quartY, quartZ);
|
||||
BiomeResolution resolution = resolveStructureBiomeResolution(
|
||||
engine, quartX, quartY, quartZ);
|
||||
if (resolution == null) {
|
||||
throw new IllegalStateException("Iris returned no structure biome at quart "
|
||||
+ quartX + "," + quartY + "," + quartZ);
|
||||
@@ -431,11 +620,36 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
|
||||
private Holder<Biome> resolveVisibleBiome(Engine engine, int quartX, int quartY, int quartZ,
|
||||
Climate.Sampler sampler) {
|
||||
return resolveVisibleBiome(engine, quartX, quartY, quartZ, sampler, null);
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveVisibleBiome(
|
||||
Engine engine,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ,
|
||||
Climate.Sampler sampler,
|
||||
DimensionStackLayout stackLayout
|
||||
) {
|
||||
Registry<Biome> registry = biomeRegistry();
|
||||
BiomeResolution resolution = resolveBiomeResolution(engine, quartX, quartY, quartZ);
|
||||
BiomeResolution resolution = resolveBiomeResolution(
|
||||
engine, quartX, quartY, quartZ, true, stackLayout);
|
||||
if (resolution == null || registry == null) {
|
||||
return serializedSource.getNoiseBiome(quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
return resolveVisibleBiome(
|
||||
engine, registry, resolution, quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveVisibleBiome(
|
||||
Engine engine,
|
||||
Registry<Biome> registry,
|
||||
BiomeResolution resolution,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ,
|
||||
Climate.Sampler sampler
|
||||
) {
|
||||
String biomeKey;
|
||||
if (resolution.irisBiome().isCustom()) {
|
||||
IrisBiomeCustom customBiome = resolution.irisBiome().getCustomBiome(
|
||||
@@ -444,7 +658,8 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
return fallbackBiome(registry, "custom derivative of '"
|
||||
+ resolution.irisBiome().getLoadKey() + "'", quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
biomeKey = ModdedWorldgenIds.biomeRef(engine, customBiome.getId());
|
||||
biomeKey = customBiomeRef(
|
||||
resolution.packName(), resolution.dimension(), customBiome.getId());
|
||||
} else if (resolution.underground()) {
|
||||
biomeKey = resolution.irisBiome().getGroundBiomeKey(
|
||||
resolution.rng(), engine, resolution.blockX(), resolution.blockY(), resolution.blockZ());
|
||||
@@ -459,6 +674,37 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(Engine engine, int quartX, int quartY, int quartZ) {
|
||||
return resolveBiomeResolution(engine, quartX, quartY, quartZ, true);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveStructureBiomeResolution(
|
||||
Engine engine,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ
|
||||
) {
|
||||
return resolveBiomeResolution(engine, quartX, quartY, quartZ, false);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(
|
||||
Engine engine,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ,
|
||||
boolean includeDimensionStack
|
||||
) {
|
||||
return resolveBiomeResolution(
|
||||
engine, quartX, quartY, quartZ, includeDimensionStack, null);
|
||||
}
|
||||
|
||||
private BiomeResolution resolveBiomeResolution(
|
||||
Engine engine,
|
||||
int quartX,
|
||||
int quartY,
|
||||
int quartZ,
|
||||
boolean includeDimensionStack,
|
||||
DimensionStackLayout stackLayout
|
||||
) {
|
||||
if (!isReady(engine)) {
|
||||
return null;
|
||||
}
|
||||
@@ -467,27 +713,75 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
int blockZ = quartZ << 2;
|
||||
int internalY = blockY - engine.getMinHeight();
|
||||
int caveSwitchY = Math.max(-8 - engine.getMinHeight(), 40);
|
||||
DimensionStackLayout.Layer stackLayer = includeDimensionStack
|
||||
? stackLayout == null
|
||||
? resolveDimensionStackLayer(engine, blockX, internalY, blockZ)
|
||||
: stackLayout.layerAt(internalY)
|
||||
: null;
|
||||
IrisDimension owningDimension = stackLayer == null
|
||||
? engine.getDimension()
|
||||
: stackLayer.terrainContext().getDimension();
|
||||
IrisData owningData = stackLayer == null
|
||||
? engine.getData()
|
||||
: stackLayer.terrainContext().getData();
|
||||
if (stackLayer != null && !stackLayer.terrainContext().isSelfReferencing()) {
|
||||
IrisBiome stackedBiome = stackLayer.biome();
|
||||
if (stackedBiome == null) {
|
||||
return null;
|
||||
}
|
||||
return createBiomeResolution(
|
||||
engine,
|
||||
stackedBiome,
|
||||
false,
|
||||
owningDimension,
|
||||
owningData,
|
||||
blockX,
|
||||
blockY,
|
||||
blockZ
|
||||
);
|
||||
}
|
||||
boolean underground = false;
|
||||
IrisBiome irisBiome;
|
||||
if (internalY <= caveSwitchY) {
|
||||
int surfaceY = engine.getComplex().getHeightStream().get(blockX, blockZ).intValue();
|
||||
if (stackLayer != null) {
|
||||
int surfaceY = stackLayer.surfaceY();
|
||||
underground = isUnderground(internalY, surfaceY);
|
||||
irisBiome = underground
|
||||
? engine.getCaveBiome(
|
||||
blockX,
|
||||
internalY,
|
||||
blockZ,
|
||||
null,
|
||||
stackLayer.biome(),
|
||||
surfaceY
|
||||
)
|
||||
: stackLayer.biome();
|
||||
} else if (internalY <= caveSwitchY) {
|
||||
int surfaceY = Engine.hostHeight(engine, blockX, blockZ, true);
|
||||
underground = isUnderground(internalY, surfaceY);
|
||||
irisBiome = underground
|
||||
? engine.getCaveBiome(blockX, internalY, blockZ)
|
||||
: engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
: engine.getHostSurfaceBiome(blockX, blockZ);
|
||||
} else {
|
||||
irisBiome = engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
irisBiome = engine.getHostSurfaceBiome(blockX, blockZ);
|
||||
}
|
||||
if (irisBiome == null && underground) {
|
||||
irisBiome = engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
irisBiome = stackLayer == null
|
||||
? engine.getHostSurfaceBiome(blockX, blockZ)
|
||||
: stackLayer.biome();
|
||||
}
|
||||
if (irisBiome == null) {
|
||||
return null;
|
||||
}
|
||||
IrisModdedChunkGenerator current = generator;
|
||||
long worldSeed = current == null ? engine.getWorld().getRawWorldSeed() : current.visibleBiomeSeed();
|
||||
long seed = biomeResolutionSeed(worldSeed, blockX, blockY, blockZ);
|
||||
return new BiomeResolution(irisBiome, underground, blockX, blockY, blockZ, new RNG(seed));
|
||||
return createBiomeResolution(
|
||||
engine,
|
||||
irisBiome,
|
||||
underground,
|
||||
owningDimension,
|
||||
owningData,
|
||||
blockX,
|
||||
blockY,
|
||||
blockZ
|
||||
);
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveRequiredStructureBiome(int quartX, int quartY, int quartZ) {
|
||||
@@ -510,9 +804,10 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
}
|
||||
IrisBiome irisBiome;
|
||||
if (isGuaranteedSurfaceBiome(quartY, engine.getMinHeight())) {
|
||||
irisBiome = engine.getComplex().getTrueBiomeStream().get(quartX << 2, quartZ << 2);
|
||||
irisBiome = resolveSurfaceStructureBiome(engine, quartX << 2, quartZ << 2);
|
||||
} else {
|
||||
BiomeResolution resolution = resolveBiomeResolution(engine, quartX, quartY, quartZ);
|
||||
BiomeResolution resolution = resolveStructureBiomeResolution(
|
||||
engine, quartX, quartY, quartZ);
|
||||
irisBiome = resolution == null ? null : resolution.irisBiome();
|
||||
}
|
||||
if (irisBiome == null) {
|
||||
@@ -557,6 +852,10 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
return internalY <= surfaceY - 8;
|
||||
}
|
||||
|
||||
static boolean isBiomeCacheable(Engine engine, int blockX, int blockZ) {
|
||||
return !engine.answersFromNaturalTerrain(blockX, blockZ);
|
||||
}
|
||||
|
||||
static boolean isMonumentSurfaceBiomeQuery(int blockY, int radius, int minHeight, int fluidHeight) {
|
||||
return radius == 29 && blockY == minHeight + fluidHeight;
|
||||
}
|
||||
@@ -612,7 +911,7 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
}
|
||||
|
||||
private Set<String> exactStructureBiomeKeys() {
|
||||
return biomeKeySets().required();
|
||||
return biomeKeySets().structureRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,11 +935,12 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
private BiomeKeySets collectBiomeKeySets(long generation) {
|
||||
IrisModdedChunkGenerator current = generator;
|
||||
if (current == null) {
|
||||
return new BiomeKeySets(generation, Set.of(), Set.of());
|
||||
return new BiomeKeySets(generation, Set.of(), Set.of(), Set.of(), Set.of(), false);
|
||||
}
|
||||
Engine engine = current.structureEngineOrNull();
|
||||
if (engine == null) {
|
||||
return new BiomeKeySets(generation, current.configuredStructureBiomeKeys(), Set.of());
|
||||
return new BiomeKeySets(
|
||||
generation, current.configuredStructureBiomeKeys(), Set.of(), Set.of(), Set.of(), false);
|
||||
}
|
||||
GenerationSessionLease lease = tryAcquireGenerationLease(engine, "modded_structure_biome_keys");
|
||||
if (lease == null) {
|
||||
@@ -650,36 +950,154 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
if (!isReady(engine)) {
|
||||
throw new IllegalStateException("Iris structure biome key lookup has no active engine runtime");
|
||||
}
|
||||
LinkedHashSet<String> required = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> visible = new LinkedHashSet<>();
|
||||
for (IrisBiome irisBiome : engine.getAllBiomes()) {
|
||||
String derivative = normalizeKey(irisBiome.getStructureDerivativeKey());
|
||||
if (derivative != null) {
|
||||
required.add(derivative);
|
||||
}
|
||||
Set<String> structureRequired = collectStructureBiomeKeys(
|
||||
engine.getDimension(), engine.getData());
|
||||
LinkedHashSet<String> visibleRequired = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> visibleEmittable = new LinkedHashSet<>();
|
||||
boolean visibleFallbackPossible = false;
|
||||
for (OwnedBiome ownedBiome : getOwnedBiomes(engine)) {
|
||||
IrisBiome irisBiome = ownedBiome.biome();
|
||||
if (irisBiome.isCustom()) {
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
required.add(ModdedWorldgenIds.biomeRef(engine, customBiome.getId()));
|
||||
String customKey = customBiomeRef(
|
||||
ownedBiome.data().getDataFolder().getName(),
|
||||
ownedBiome.dimension(),
|
||||
customBiome.getId()
|
||||
);
|
||||
visibleRequired.add(customKey);
|
||||
visibleEmittable.add(customKey);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
addVisibleBiomeKey(visible, irisBiome.getDerivativeKey());
|
||||
visibleFallbackPossible |= !addVisibleBiomeKey(
|
||||
visibleEmittable, irisBiome.getDerivativeKey());
|
||||
for (String scatter : irisBiome.getBiomeScatter()) {
|
||||
addVisibleBiomeKey(visible, scatter);
|
||||
visibleFallbackPossible |= !addVisibleBiomeKey(visibleEmittable, scatter);
|
||||
}
|
||||
for (String scatter : irisBiome.getBiomeSkyScatter()) {
|
||||
addVisibleBiomeKey(visible, scatter);
|
||||
visibleFallbackPossible |= !addVisibleBiomeKey(visibleEmittable, scatter);
|
||||
}
|
||||
}
|
||||
visible.removeAll(required);
|
||||
return new BiomeKeySets(generation, Set.copyOf(required), Set.copyOf(visible));
|
||||
LinkedHashSet<String> visible = new LinkedHashSet<>(visibleEmittable);
|
||||
visible.removeAll(structureRequired);
|
||||
visible.removeAll(visibleRequired);
|
||||
return new BiomeKeySets(
|
||||
generation,
|
||||
Set.copyOf(structureRequired),
|
||||
Set.copyOf(visibleRequired),
|
||||
Set.copyOf(visible),
|
||||
Set.copyOf(visibleEmittable),
|
||||
visibleFallbackPossible
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addVisibleBiomeKey(Set<String> target, String key) {
|
||||
String normalized = normalizeKey(key);
|
||||
if (normalized != null) {
|
||||
target.add(normalized);
|
||||
static Set<String> collectStructureBiomeKeys(IrisDimension dimension, IrisData data) {
|
||||
LinkedHashSet<String> keys = new LinkedHashSet<>();
|
||||
for (IrisBiome irisBiome : dimension.getReachableBiomes(() -> data)) {
|
||||
String derivative = normalizeKey(irisBiome.getStructureDerivativeKey());
|
||||
if (derivative != null) {
|
||||
keys.add(derivative);
|
||||
}
|
||||
}
|
||||
return Set.copyOf(keys);
|
||||
}
|
||||
|
||||
private static boolean addVisibleBiomeKey(Set<String> target, String key) {
|
||||
String normalized = normalizeKey(key);
|
||||
if (normalized == null) {
|
||||
return false;
|
||||
}
|
||||
target.add(normalized);
|
||||
return true;
|
||||
}
|
||||
|
||||
static String customBiomeRef(String packName, IrisDimension dimension, String customBiomeId) {
|
||||
return ModdedWorldgenIds.biomeRef(packName, dimension.getLoadKey(), customBiomeId);
|
||||
}
|
||||
|
||||
private BiomeResolution createBiomeResolution(
|
||||
Engine engine,
|
||||
IrisBiome irisBiome,
|
||||
boolean underground,
|
||||
IrisDimension dimension,
|
||||
IrisData data,
|
||||
int blockX,
|
||||
int blockY,
|
||||
int blockZ
|
||||
) {
|
||||
IrisModdedChunkGenerator current = generator;
|
||||
long worldSeed = current == null
|
||||
? engine.getWorld().getRawWorldSeed()
|
||||
: current.visibleBiomeSeed();
|
||||
long seed = biomeResolutionSeed(worldSeed, blockX, blockY, blockZ);
|
||||
return new BiomeResolution(
|
||||
irisBiome,
|
||||
underground,
|
||||
dimension,
|
||||
data.getDataFolder().getName(),
|
||||
blockX,
|
||||
blockY,
|
||||
blockZ,
|
||||
new RNG(seed)
|
||||
);
|
||||
}
|
||||
|
||||
private static List<OwnedBiome> getOwnedBiomes(Engine engine) {
|
||||
ArrayList<OwnedBiome> biomes = new ArrayList<>();
|
||||
IrisDimension hostDimension = engine.getDimension();
|
||||
IrisData hostData = engine.getData();
|
||||
addOwnedBiomes(
|
||||
biomes,
|
||||
hostDimension,
|
||||
hostData,
|
||||
hostDimension.getReachableBiomes(engine)
|
||||
);
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
if (stackContext == null) {
|
||||
return biomes;
|
||||
}
|
||||
for (DimensionTerrainContext terrainContext : stackContext.getLayersBottomToTop()) {
|
||||
if (terrainContext.isSelfReferencing()) {
|
||||
continue;
|
||||
}
|
||||
IrisDimension dimension = terrainContext.getDimension();
|
||||
IrisData data = terrainContext.getData();
|
||||
addOwnedBiomes(
|
||||
biomes,
|
||||
dimension,
|
||||
data,
|
||||
dimension.getReachableBiomes(terrainContext)
|
||||
);
|
||||
}
|
||||
return biomes;
|
||||
}
|
||||
|
||||
private static void addOwnedBiomes(
|
||||
List<OwnedBiome> target,
|
||||
IrisDimension dimension,
|
||||
IrisData data,
|
||||
Iterable<IrisBiome> biomes
|
||||
) {
|
||||
for (IrisBiome biome : biomes) {
|
||||
if (biome != null) {
|
||||
target.add(new OwnedBiome(dimension, data, biome));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DimensionStackLayout.Layer resolveDimensionStackLayer(
|
||||
Engine engine,
|
||||
int blockX,
|
||||
int internalY,
|
||||
int blockZ
|
||||
) {
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
return stackContext == null ? null : stackContext.getLayerAt(blockX, internalY, blockZ);
|
||||
}
|
||||
|
||||
private static IrisBiome resolveSurfaceStructureBiome(Engine engine, int blockX, int blockZ) {
|
||||
return engine.getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
}
|
||||
|
||||
private static Set<String> registeredBiomeKeys(Registry<Biome> registry) {
|
||||
@@ -726,7 +1144,13 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
Holder<Biome> plains = resolveHolder(registry, "minecraft:plains");
|
||||
warnUnresolvedBiome(unresolvedKey, plains == null ? "the serialized biome source" : "minecraft:plains",
|
||||
quartX, quartY, quartZ);
|
||||
return plains == null ? serializedSource.getNoiseBiome(quartX, quartY, quartZ, sampler) : plains;
|
||||
if (plains != null) {
|
||||
return plains;
|
||||
}
|
||||
if (sampler == null) {
|
||||
throw new IllegalStateException("Iris cannot resolve a registered fallback biome");
|
||||
}
|
||||
return serializedSource.getNoiseBiome(quartX, quartY, quartZ, sampler);
|
||||
}
|
||||
|
||||
private void warnUnresolvedBiome(String unresolvedKey, String fallback,
|
||||
@@ -753,11 +1177,29 @@ final class IrisModdedBiomeSource extends BiomeSource {
|
||||
return ((long) x << 32) ^ ((long) z & 4294967295L);
|
||||
}
|
||||
|
||||
private record BiomeResolution(IrisBiome irisBiome, boolean underground, int blockX, int blockY,
|
||||
int blockZ, RNG rng) {
|
||||
private record BiomeResolution(
|
||||
IrisBiome irisBiome,
|
||||
boolean underground,
|
||||
IrisDimension dimension,
|
||||
String packName,
|
||||
int blockX,
|
||||
int blockY,
|
||||
int blockZ,
|
||||
RNG rng
|
||||
) {
|
||||
}
|
||||
|
||||
private record BiomeKeySets(long generation, Set<String> required, Set<String> visibleOnly) {
|
||||
private record OwnedBiome(IrisDimension dimension, IrisData data, IrisBiome biome) {
|
||||
}
|
||||
|
||||
private record BiomeKeySets(
|
||||
long generation,
|
||||
Set<String> structureRequired,
|
||||
Set<String> visibleRequired,
|
||||
Set<String> visibleOnly,
|
||||
Set<String> visibleEmittable,
|
||||
boolean visibleFallbackPossible
|
||||
) {
|
||||
}
|
||||
|
||||
private record PossibleBiomes(long generation, List<Holder<Biome>> ordered, Set<Holder<Biome>> set) {
|
||||
|
||||
+67
-11
@@ -30,6 +30,7 @@ import art.arcane.iris.engine.object.IrisImportedStructureControl;
|
||||
import art.arcane.iris.nativegen.NativeStructureStartInjector;
|
||||
import art.arcane.iris.nativegen.NativeStructureReferenceRepair;
|
||||
import art.arcane.iris.nativegen.NativeStructureVanillaLocator;
|
||||
import art.arcane.iris.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -89,7 +90,9 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -181,11 +184,18 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
}
|
||||
requireGlobalStructureGeneration(
|
||||
level.getServer().getWorldGenSettings().options().generateStructures(), dimensionKey);
|
||||
Engine activeEngine = engineIfBound();
|
||||
Engine replacement = ModdedWorldEngines.prepareReplacement(level, pack, packDimensionKey, seed);
|
||||
try {
|
||||
if (activeEngine != null) {
|
||||
requireStructureBiomeUniverseCompatible(
|
||||
activeEngine.getDimension(), replacement.getDimension());
|
||||
}
|
||||
nativeStructures.installVolumeIndex(level, replacement);
|
||||
ModdedWorldEngines.installReplacement(level, replacement);
|
||||
replacement.getPlatformHooks().applyWorldBoundary(replacement);
|
||||
} catch (Throwable error) {
|
||||
NativeStructureVolumeIndex.uninstall(replacement);
|
||||
try {
|
||||
ModdedWorldEngines.closeUnregistered(replacement);
|
||||
} catch (Throwable cleanupError) {
|
||||
@@ -203,17 +213,14 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
this.activePack = pack;
|
||||
this.activeDimensionKey = packDimensionKey;
|
||||
this.seedOverride = seed;
|
||||
this.engine = replacement;
|
||||
this.configuredStructureBiomeKeys = null;
|
||||
this.configuredPack = null;
|
||||
this.heightMetadata = engineHeights(replacement);
|
||||
this.engineBinding.reset();
|
||||
this.engineBinding.complete(replacement);
|
||||
this.announced.set(false);
|
||||
this.structureBiomeSource.clearCaches();
|
||||
this.importedFeatures.invalidate();
|
||||
this.nativeStructures.clearWorldCheckStructureShifts();
|
||||
this.spawnTables.resetVanillaSpawnBiomes();
|
||||
resetRuntimeCaches();
|
||||
this.engine = replacement;
|
||||
this.engineBinding.complete(replacement);
|
||||
// Bind time: a feature-order cycle in the new pack is reported here, once, and degrades to features-off.
|
||||
// Never waits on a build owned by another thread: this method owns the generator monitor and the build
|
||||
// path can need it.
|
||||
@@ -751,7 +758,38 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
return lastChunkGenAt;
|
||||
}
|
||||
|
||||
public void onHotload() {
|
||||
public void prepareRuntimeHotload(ServerLevel level, Engine current) {
|
||||
if (this.engine != current || level.getChunkSource().getGenerator() != this) {
|
||||
throw new IllegalStateException("Iris generator '" + dimensionKey
|
||||
+ "' cannot prepare caches for an unrelated engine hotload");
|
||||
}
|
||||
resetRuntimeCaches();
|
||||
nativeStructures.installVolumeIndex(level, current);
|
||||
}
|
||||
|
||||
public static void requireStructureBiomeUniverseCompatible(
|
||||
IrisDimension active,
|
||||
IrisDimension replacement
|
||||
) {
|
||||
IrisData activeData = Objects.requireNonNull(active.getLoader(),
|
||||
"Active Iris dimension has no pack loader");
|
||||
IrisData replacementData = Objects.requireNonNull(replacement.getLoader(),
|
||||
"Replacement Iris dimension has no pack loader");
|
||||
requireStructureBiomeUniverseCompatible(
|
||||
IrisModdedBiomeSource.collectStructureBiomeKeys(active, activeData),
|
||||
IrisModdedBiomeSource.collectStructureBiomeKeys(replacement, replacementData));
|
||||
}
|
||||
|
||||
static void requireStructureBiomeUniverseCompatible(Set<String> active, Set<String> replacement) {
|
||||
if (active.equals(replacement)) {
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("Iris cannot hotload a changed host structure-biome derivative set "
|
||||
+ "from " + new TreeSet<>(active) + " to " + new TreeSet<>(replacement)
|
||||
+ ". Restart the server so Minecraft can rebuild its immutable structure state.");
|
||||
}
|
||||
|
||||
private void resetRuntimeCaches() {
|
||||
configuredStructureBiomeKeys = null;
|
||||
structureBiomeSource.clearCaches();
|
||||
importedFeatures.invalidate();
|
||||
@@ -986,7 +1024,17 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
Registry<Biome> registry = region.registryAccess().lookupOrThrow(Registries.BIOME);
|
||||
spawnTables.initializeVanillaSpawnBiomes(registry);
|
||||
ChunkPos center = region.getCenter();
|
||||
Holder<Biome> visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
Holder<Biome> visibleBiome;
|
||||
if (engine == null || engine.getDimensionStackContext() == null) {
|
||||
visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
} else {
|
||||
visibleBiome = structureBiomeSource.getVisibleSurfaceBiome(
|
||||
center.getMinBlockX() + 8,
|
||||
center.getMinBlockZ() + 8);
|
||||
if (visibleBiome == null) {
|
||||
visibleBiome = region.getBiome(center.getWorldPosition().atY(region.getMaxY()));
|
||||
}
|
||||
}
|
||||
Holder<Biome> vanillaBiome = spawnTables.vanillaSpawnBiome(visibleBiome.value());
|
||||
WorldgenRandom random = new WorldgenRandom(new LegacyRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
random.setDecorationSeed(region.getSeed(), center.getMinBlockX(), center.getMinBlockZ());
|
||||
@@ -1029,7 +1077,10 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
boolean ignoreFluid = !type.isOpaque().test(Blocks.WATER.defaultBlockState());
|
||||
try (GenerationSessionLease lease = current.acquireGenerationLease("modded_base_height");
|
||||
IrisContext.Scope ignored = IrisContext.open(current, lease.sessionId(), null)) {
|
||||
return heightAccessor.getMinY() + current.getHeight(x, z, ignoreFluid) + 1;
|
||||
int height = current.getDimensionStackContext() == null
|
||||
? current.getHeight(x, z, ignoreFluid)
|
||||
: Engine.hostHeight(current, x, z, ignoreFluid);
|
||||
return heightAccessor.getMinY() + height + 1;
|
||||
} catch (GenerationSessionException e) {
|
||||
throw new IllegalStateException("Iris base height query could not acquire its engine runtime.", e);
|
||||
}
|
||||
@@ -1043,8 +1094,13 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
|
||||
try (GenerationSessionLease lease = current.acquireGenerationLease("modded_base_column");
|
||||
IrisContext.Scope ignored = IrisContext.open(current, lease.sessionId(), null)) {
|
||||
BlockState airState = Blocks.AIR.defaultBlockState();
|
||||
int surface = current.getHeight(x, z, true);
|
||||
int fluid = current.getHeight(x, z, false);
|
||||
boolean dimensionStack = current.getDimensionStackContext() != null;
|
||||
int surface = dimensionStack
|
||||
? Engine.hostHeight(current, x, z, true)
|
||||
: current.getHeight(x, z, true);
|
||||
int fluid = dimensionStack
|
||||
? Engine.hostHeight(current, x, z, false)
|
||||
: current.getHeight(x, z, false);
|
||||
BlockState stone = Blocks.STONE.defaultBlockState();
|
||||
BlockState water = Blocks.WATER.defaultBlockState();
|
||||
int solidEnd = Math.max(0, Math.min(states.length, surface + 1));
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.modded;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.IrisBiome;
|
||||
import art.arcane.iris.engine.object.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.spi.PlatformBiome;
|
||||
import art.arcane.iris.spi.PlatformBiomeWriter;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
@@ -97,7 +98,7 @@ public final class ModdedBiomeWriter implements PlatformBiomeWriter {
|
||||
return key;
|
||||
}
|
||||
Engine engine = context.getEngine();
|
||||
String prefix = engine.getDimension().getLoadKey() + ":";
|
||||
String prefix = engine.getDimension().getCustomBiomeKeyPrefix();
|
||||
if (!key.regionMatches(true, 0, prefix, 0, prefix.length())) {
|
||||
return key;
|
||||
}
|
||||
@@ -138,13 +139,7 @@ public final class ModdedBiomeWriter implements PlatformBiomeWriter {
|
||||
}
|
||||
|
||||
private int idForDerivative(Registry<Biome> registry, String key) {
|
||||
int colon = key.indexOf(':');
|
||||
if (colon <= 0 || colon >= key.length() - 1) {
|
||||
return -1;
|
||||
}
|
||||
String dimensionLoadKey = key.substring(0, colon);
|
||||
String customBiomeId = key.substring(colon + 1);
|
||||
IrisBiome owner = findCustomBiomeOwner(dimensionLoadKey, customBiomeId);
|
||||
IrisBiome owner = findCustomBiomeOwner(key);
|
||||
if (owner == null) {
|
||||
return -1;
|
||||
}
|
||||
@@ -155,20 +150,18 @@ public final class ModdedBiomeWriter implements PlatformBiomeWriter {
|
||||
return idForKey(registry, derivativeKey);
|
||||
}
|
||||
|
||||
private IrisBiome findCustomBiomeOwner(String dimensionLoadKey, String customBiomeId) {
|
||||
private IrisBiome findCustomBiomeOwner(String key) {
|
||||
for (Engine engine : ModdedWorldEngines.activeEngines()) {
|
||||
if (engine == null || engine.isClosed()) {
|
||||
continue;
|
||||
}
|
||||
if (!dimensionLoadKey.equalsIgnoreCase(engine.getDimension().getLoadKey())) {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiome biome : engine.getDimension().getAllBiomes(engine)) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
for (IrisBiome biome : dimension.getAllBiomes(engine)) {
|
||||
if (!biome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom custom : biome.getCustomDerivitives()) {
|
||||
if (customBiomeId.equals(custom.getId())) {
|
||||
if (key.equalsIgnoreCase(dimension.getCustomBiomeKey(custom.getId()))) {
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ public final class ModdedBlockBreakHandler {
|
||||
if (skipsParents(providers)) {
|
||||
return providers;
|
||||
}
|
||||
IrisRegion region = engine.getRegion(position.getX(), position.getZ());
|
||||
IrisRegion region = engine.getRegion(position.getX(), relativeY, position.getZ());
|
||||
if (region != null) {
|
||||
addMatching(providers, region.getBlockDrops(), brokenState, data);
|
||||
}
|
||||
|
||||
+1
-2
@@ -62,7 +62,6 @@ final class ModdedDimensionMetadata {
|
||||
|
||||
static Set<String> collectConfiguredBiomeKeys(Iterable<IrisBiome> biomes, String dimensionLoadKey) {
|
||||
LinkedHashSet<String> keys = new LinkedHashSet<>();
|
||||
String namespace = dimensionLoadKey.toLowerCase(Locale.ROOT);
|
||||
for (IrisBiome irisBiome : biomes) {
|
||||
if (irisBiome == null) {
|
||||
continue;
|
||||
@@ -75,7 +74,7 @@ final class ModdedDimensionMetadata {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
keys.add(namespace + ":" + customBiome.getId().toLowerCase(Locale.ROOT));
|
||||
keys.add(IrisDimension.customBiomeKey(dimensionLoadKey, customBiome.getId()));
|
||||
}
|
||||
}
|
||||
return Set.copyOf(keys);
|
||||
|
||||
+1
-1
@@ -226,7 +226,7 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
||||
int blockY = floor(player.getY()) - getEngine().getWorld().minHeight();
|
||||
int blockZ = floor(player.getZ());
|
||||
state.biome(getEngine().getBiome(blockX, blockY, blockZ));
|
||||
state.region(getEngine().getRegion(blockX, blockZ));
|
||||
state.region(getEngine().getRegion(blockX, blockY, blockZ));
|
||||
}
|
||||
|
||||
private void applyEffects(ServerLevel level, ServerPlayer player, Iterable<IrisEffect> effects) {
|
||||
|
||||
+5
-11
@@ -52,7 +52,6 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HexFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -514,18 +513,13 @@ public final class ModdedForcedDatapack {
|
||||
if (!dimensionsDirectory.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
File[] dimensionFiles = dimensionsDirectory.listFiles(
|
||||
(File file) -> file.isFile() && file.getName().endsWith(".json"));
|
||||
if (dimensionFiles == null) {
|
||||
throw new IOException("Iris could not read dimensions for pack '" + packName + "'");
|
||||
}
|
||||
if (dimensionFiles.length == 0) {
|
||||
IrisData data = IrisData.get(packFolder);
|
||||
String[] dimensionKeys = data.getDimensionLoader().getPossibleKeys();
|
||||
if (dimensionKeys == null || dimensionKeys.length == 0) {
|
||||
return false;
|
||||
}
|
||||
Arrays.sort(dimensionFiles, Comparator.comparing(File::getName));
|
||||
IrisData data = IrisData.get(packFolder);
|
||||
for (File dimensionFile : dimensionFiles) {
|
||||
String dimensionKey = dimensionFile.getName().substring(0, dimensionFile.getName().length() - ".json".length());
|
||||
List<String> sortedDimensionKeys = Stream.of(dimensionKeys).sorted().toList();
|
||||
for (String dimensionKey : sortedDimensionKeys) {
|
||||
IrisDimension dimension = data.getDimensionLoader().load(dimensionKey);
|
||||
if (dimension == null) {
|
||||
throw new IllegalStateException("Iris pack '" + packName + "' dimension '"
|
||||
|
||||
+109
-10
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.NativeFeatureGenerationPolicy;
|
||||
@@ -57,7 +59,10 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Native placed-feature passthrough for one Iris dimension, gated on {@code importedFeatures.enabled}.
|
||||
@@ -219,7 +224,14 @@ final class ModdedImportedFeatureStage {
|
||||
private FeatureTable buildTable(Engine engine, IrisImportedFeatureControl control, long generation) {
|
||||
// Registry-ordered biome list. FeatureSorter's cycle detection walks it, so an unordered list makes
|
||||
// detection depend on JVM hash order and turns a real cycle into an intermittent one.
|
||||
List<Holder<Biome>> biomes = biomeSource.orderedPossibleBiomes();
|
||||
Set<String> hostBiomeKeys = hostBiomeKeys(engine);
|
||||
List<Holder<Biome>> biomes = new ArrayList<>();
|
||||
for (Holder<Biome> biome : biomeSource.orderedPossibleBiomes()) {
|
||||
String key = holderKey(biome);
|
||||
if (key != null && hostBiomeKeys.contains(key)) {
|
||||
biomes.add(biome);
|
||||
}
|
||||
}
|
||||
if (biomes.isEmpty()) {
|
||||
ModdedIrisLog.error("Iris importedFeatures is on but {} exposes no biomes; features off",
|
||||
dimensionKey(engine));
|
||||
@@ -262,7 +274,7 @@ final class ModdedImportedFeatureStage {
|
||||
*/
|
||||
private Map<String, Holder<Biome>> customBiomeDerivatives(Engine engine, Map<String, Holder<Biome>> byKey) {
|
||||
Map<String, Holder<Biome>> derivatives = new HashMap<>();
|
||||
for (IrisBiome irisBiome : engine.getAllBiomes()) {
|
||||
for (IrisBiome irisBiome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
if (!irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
@@ -322,14 +334,24 @@ final class ModdedImportedFeatureStage {
|
||||
List<FeatureSorter.StepFeatureData> steps = table.steps();
|
||||
WorldgenRandom random = new WorldgenRandom(new XoroshiroRandomSource(RandomSupport.generateUniqueSeed()));
|
||||
long decorationSeed = random.setDecorationSeed(level.getSeed(), origin.getX(), origin.getZ());
|
||||
Set<Holder<Biome>> chunkBiomes = chunkBiomes(level, sectionPos, table);
|
||||
IrisStaticObjectLayer staticObjects = engine.getDimension().getStaticObjectLayer(engine.getData());
|
||||
int staticMinY = engine.getMinHeight();
|
||||
WorldGenLevel placementLevel = staticObjects.isEmpty() ? level : ModdedNativeStructureWorldgenAccess.create(
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
Set<Holder<Biome>> chunkBiomes = chunkBiomes(level, sectionPos, table, stackContext);
|
||||
IntBinaryOperator surfaceFirstFreeY = stackContext == null
|
||||
? (x, z) -> level.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z)
|
||||
: (x, z) -> Engine.hostHeight(engine, x, z, false) + staticMinY + 1;
|
||||
IntBinaryOperator floorFirstFreeY = stackContext == null
|
||||
? (x, z) -> level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z)
|
||||
: (x, z) -> Engine.hostHeight(engine, x, z, true) + staticMinY + 1;
|
||||
WorldGenLevel placementLevel = staticObjects.isEmpty() && stackContext == null
|
||||
? level
|
||||
: ModdedNativeStructureWorldgenAccess.create(
|
||||
level, centerPos,
|
||||
(x, z) -> level.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z),
|
||||
(x, z) -> level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z),
|
||||
position -> staticObjects.contains(position.getX(), position.getY() - staticMinY, position.getZ()));
|
||||
surfaceFirstFreeY,
|
||||
floorFirstFreeY,
|
||||
stackContext != null,
|
||||
importedFeatureProtection(staticObjects, stackContext, staticMinY));
|
||||
|
||||
try {
|
||||
for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
|
||||
@@ -349,6 +371,58 @@ final class ModdedImportedFeatureStage {
|
||||
WorldCheckFeaturePlacement.recordPlacementPass();
|
||||
}
|
||||
|
||||
private static Set<String> hostBiomeKeys(Engine engine) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (IrisBiome irisBiome : engine.getDimension().getReachableBiomes(engine)) {
|
||||
addKey(keys, irisBiome.getStructureDerivativeKey());
|
||||
addKey(keys, irisBiome.getDerivativeKey());
|
||||
for (String scatter : irisBiome.getBiomeScatter()) {
|
||||
addKey(keys, scatter);
|
||||
}
|
||||
for (String scatter : irisBiome.getBiomeSkyScatter()) {
|
||||
addKey(keys, scatter);
|
||||
}
|
||||
if (!irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
addKey(keys, ModdedWorldgenIds.biomeRef(engine, customBiome.getId()));
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static void addKey(Set<String> keys, String key) {
|
||||
String normalized = normalizeKey(key);
|
||||
if (normalized != null) {
|
||||
keys.add(normalized);
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<BlockPos> importedFeatureProtection(
|
||||
IrisStaticObjectLayer staticObjects,
|
||||
DimensionStackContext stackContext,
|
||||
int minimumY
|
||||
) {
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
private void placeStep(WorldGenLevel level, FeatureTable table, FeatureSorter.StepFeatureData stepData,
|
||||
Registry<PlacedFeature> featureRegistry, Set<Holder<Biome>> chunkBiomes,
|
||||
IrisModdedChunkGenerator owner, WorldgenRandom random, long decorationSeed,
|
||||
@@ -394,12 +468,37 @@ final class ModdedImportedFeatureStage {
|
||||
* shape as vanilla, which drops any section biome its biome source does not claim. Holders are canonicalised
|
||||
* back onto the table's own holders so the index mapping cannot be handed a holder it never saw.
|
||||
*/
|
||||
private Set<Holder<Biome>> chunkBiomes(WorldGenLevel level, SectionPos sectionPos, FeatureTable table) {
|
||||
private Set<Holder<Biome>> chunkBiomes(
|
||||
WorldGenLevel level,
|
||||
SectionPos sectionPos,
|
||||
FeatureTable table,
|
||||
DimensionStackContext stackContext
|
||||
) {
|
||||
List<Holder<Biome>> collected = new ArrayList<>();
|
||||
ChunkPos.rangeClosed(sectionPos.chunk(), 1).forEach((ChunkPos chunkPos) -> {
|
||||
ChunkAccess neighbour = level.getChunk(chunkPos.x(), chunkPos.z());
|
||||
for (LevelChunkSection section : neighbour.getSections()) {
|
||||
section.getBiomes().getAll(collected::add);
|
||||
LevelChunkSection[] sections = neighbour.getSections();
|
||||
for (int sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
|
||||
LevelChunkSection section = sections[sectionIndex];
|
||||
if (stackContext == null) {
|
||||
section.getBiomes().getAll(collected::add);
|
||||
continue;
|
||||
}
|
||||
int sectionMinimumY = neighbour.getSectionYFromSectionIndex(sectionIndex) << 4;
|
||||
for (int quartY = 0; quartY < 4; quartY++) {
|
||||
int internalY = sectionMinimumY + (quartY << 2) - level.getMinY();
|
||||
for (int quartX = 0; quartX < 4; quartX++) {
|
||||
int blockX = chunkPos.getMinBlockX() + (quartX << 2);
|
||||
for (int quartZ = 0; quartZ < 4; quartZ++) {
|
||||
int blockZ = chunkPos.getMinBlockZ() + (quartZ << 2);
|
||||
DimensionStackLayout.Layer layer = stackContext.getLayerAt(
|
||||
blockX, internalY, blockZ);
|
||||
if (layer.terrainContext().isSelfReferencing()) {
|
||||
collected.add(section.getBiomes().get(quartX, quartY, quartZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Set<Holder<Biome>> present = new LinkedHashSet<>();
|
||||
|
||||
+48
-9
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionStackLayout;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.NativeStructureGenerationPolicy;
|
||||
@@ -78,6 +80,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Native (vanilla registry) structure stage for {@link IrisModdedChunkGenerator}. The generator keeps the
|
||||
@@ -266,7 +269,7 @@ final class ModdedNativeStructureStage {
|
||||
undergroundStep,
|
||||
decision.preserveSourceY(),
|
||||
decision.yBand(),
|
||||
(x, z) -> current.getHeight(x, z, true) + current.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(current, x, z, true) + current.getMinHeight());
|
||||
StructureStart wrapped = NativeStructureReferenceEnvelope.wrapForPublication(
|
||||
start, structure, start.getReferences(),
|
||||
NativeStructureTerrainIntegrator.resolveNativeTerrain(start, decision.terrain()),
|
||||
@@ -367,10 +370,14 @@ final class ModdedNativeStructureStage {
|
||||
chunkPos.x(), chunkPos.z(), error);
|
||||
}
|
||||
IrisStaticObjectLayer staticObjects = current.getDimension().getStaticObjectLayer(current.getData());
|
||||
int staticMinY = current.getMinHeight();
|
||||
WorldGenLevel boundedWorld = staticObjects.isEmpty() ? world : ModdedNativeStructureWorldgenAccess.create(
|
||||
Predicate<BlockPos> protectedPosition = nativeStructureProtection(current, staticObjects);
|
||||
WorldGenLevel boundedWorld = staticObjects.isEmpty()
|
||||
&& current.getDimensionStackContext() == null
|
||||
? world
|
||||
: ModdedNativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, worldgenSurfaceHeight(current, world.getMinY()), worldgenFloorHeight(current, world.getMinY()),
|
||||
position -> staticObjects.contains(position.getX(), position.getY() - staticMinY, position.getZ()));
|
||||
current.getDimensionStackContext() != null,
|
||||
protectedPosition);
|
||||
try {
|
||||
NativeStructureVegetationClearer.clearIntersectingVegetation(
|
||||
boundedWorld, chunk, area, vegetationTargets);
|
||||
@@ -383,7 +390,7 @@ final class ModdedNativeStructureStage {
|
||||
try {
|
||||
vacuumFoundationPlan = NativeStructureSurfaceFitter.prepareSurfaceStructures(
|
||||
boundedWorld, area, terrainTargets,
|
||||
(x, z) -> current.getHeight(x, z, true) + current.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(current, x, z, true) + current.getMinHeight());
|
||||
} catch (Throwable error) {
|
||||
throw NativeStructureGenerationException.failure(
|
||||
"terrain integration", nativeStructureBatchContext(placementGroups),
|
||||
@@ -443,18 +450,50 @@ final class ModdedNativeStructureStage {
|
||||
IrisNativeStructureDecision decision) {
|
||||
Engine current = generator.engine();
|
||||
WorldGenLevel boundedWorld = world instanceof ModdedNativeStructureWorldgenAccess ? world : ModdedNativeStructureWorldgenAccess.create(
|
||||
world, chunkPos, worldgenSurfaceHeight(current, world.getMinY()), worldgenFloorHeight(current, world.getMinY()), position -> false);
|
||||
world,
|
||||
chunkPos,
|
||||
worldgenSurfaceHeight(current, world.getMinY()),
|
||||
worldgenFloorHeight(current, world.getMinY()),
|
||||
current.getDimensionStackContext() != null,
|
||||
nativeStructureProtection(
|
||||
current,
|
||||
current.getDimension().getStaticObjectLayer(current.getData())));
|
||||
world.setCurrentlyGenerating(() -> "Iris native structure " + structureId);
|
||||
try {
|
||||
NativeStructurePostProcessor.place(
|
||||
boundedWorld, structureManager, generator, random, area, chunkPos,
|
||||
structureId, start, decision, this::resolvePaletteBlock,
|
||||
(x, z) -> current.getHeight(x, z, true) + current.getMinHeight());
|
||||
(x, z) -> Engine.hostHeight(current, x, z, true) + current.getMinHeight());
|
||||
} finally {
|
||||
world.setCurrentlyGenerating(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static Predicate<BlockPos> nativeStructureProtection(
|
||||
Engine engine,
|
||||
IrisStaticObjectLayer staticObjects
|
||||
) {
|
||||
DimensionStackContext stackContext = engine.getDimensionStackContext();
|
||||
int minimumY = engine.getMinHeight();
|
||||
Map<Long, DimensionStackLayout> layouts = new ConcurrentHashMap<>();
|
||||
return position -> {
|
||||
if (!staticObjects.isEmpty() && staticObjects.contains(
|
||||
position.getX(), position.getY() - minimumY, position.getZ())) {
|
||||
return true;
|
||||
}
|
||||
if (stackContext == null) {
|
||||
return false;
|
||||
}
|
||||
long columnKey = ((long) position.getX() << 32)
|
||||
^ (position.getZ() & 0xFFFFFFFFL);
|
||||
DimensionStackLayout layout = layouts.computeIfAbsent(
|
||||
columnKey,
|
||||
ignored -> stackContext.sample(position.getX(), position.getZ())
|
||||
);
|
||||
return layout.isHostFeatureProtectedY(position.getY() - minimumY);
|
||||
};
|
||||
}
|
||||
|
||||
private List<List<Structure>> structuresByStep(Registry<Structure> registry) {
|
||||
StructureStepCache cached = structureStepCache;
|
||||
if (cached != null && cached.registry() == registry) {
|
||||
@@ -523,11 +562,11 @@ final class ModdedNativeStructureStage {
|
||||
}
|
||||
|
||||
private IntBinaryOperator worldgenSurfaceHeight(Engine generationEngine, int runtimeMinY) {
|
||||
return (x, z) -> generationEngine.getHeight(x, z, false) + runtimeMinY + 1;
|
||||
return (x, z) -> Engine.hostHeight(generationEngine, x, z, false) + runtimeMinY + 1;
|
||||
}
|
||||
|
||||
private IntBinaryOperator worldgenFloorHeight(Engine generationEngine, int runtimeMinY) {
|
||||
return (x, z) -> generationEngine.getHeight(x, z, true) + runtimeMinY + 1;
|
||||
return (x, z) -> Engine.hostHeight(generationEngine, x, z, true) + runtimeMinY + 1;
|
||||
}
|
||||
|
||||
private record NativeStructureStartKey(String structureId, long chunkPosition) {
|
||||
|
||||
+6
-2
@@ -63,6 +63,7 @@ final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
private final ChunkPos generationCenter;
|
||||
private final IntBinaryOperator surfaceFirstFreeY;
|
||||
private final IntBinaryOperator floorFirstFreeY;
|
||||
private final boolean virtualizeHeights;
|
||||
private final Predicate<BlockPos> protectedPosition;
|
||||
private final Holder<Biome> fallbackBiome;
|
||||
private final BiomeManager biomeManager;
|
||||
@@ -80,6 +81,7 @@ final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
boundary.surfaceFirstFreeY(), "Native structure world access requires a surface resolver");
|
||||
this.floorFirstFreeY = Objects.requireNonNull(
|
||||
boundary.floorFirstFreeY(), "Native structure world access requires an ocean-floor resolver");
|
||||
this.virtualizeHeights = boundary.virtualizeHeights();
|
||||
this.protectedPosition = Objects.requireNonNull(
|
||||
boundary.protectedPosition(), "World access requires a protected-position predicate");
|
||||
BlockPos biomeSample = generationCenter.getMiddleBlockPosition(delegate.getSeaLevel());
|
||||
@@ -102,9 +104,10 @@ final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
static ModdedNativeStructureWorldgenAccess create(WorldGenLevel delegate, ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY,
|
||||
boolean virtualizeHeights,
|
||||
Predicate<BlockPos> protectedPosition) {
|
||||
return new ModdedNativeStructureWorldgenAccess(delegate, new Boundary(
|
||||
generationCenter, surfaceFirstFreeY, floorFirstFreeY, protectedPosition));
|
||||
generationCenter, surfaceFirstFreeY, floorFirstFreeY, virtualizeHeights, protectedPosition));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,7 +244,7 @@ final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
|
||||
@Override
|
||||
public int getHeight(Heightmap.Types type, int x, int z) {
|
||||
if (isInsideGenerationRegion(x >> 4, z >> 4)) {
|
||||
if (!virtualizeHeights && isInsideGenerationRegion(x >> 4, z >> 4)) {
|
||||
return delegate.getHeight(type, x, z);
|
||||
}
|
||||
return height(type, x, z);
|
||||
@@ -526,6 +529,7 @@ final class ModdedNativeStructureWorldgenAccess implements WorldGenLevel {
|
||||
private record Boundary(ChunkPos generationCenter,
|
||||
IntBinaryOperator surfaceFirstFreeY,
|
||||
IntBinaryOperator floorFirstFreeY,
|
||||
boolean virtualizeHeights,
|
||||
Predicate<BlockPos> protectedPosition) {
|
||||
}
|
||||
|
||||
|
||||
@@ -108,12 +108,17 @@ public final class ModdedScheduler implements PlatformScheduler {
|
||||
scheduler.drain();
|
||||
}
|
||||
|
||||
public static boolean isMainThread() {
|
||||
Thread running = mainThread;
|
||||
return running != null && Thread.currentThread() == running;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void global(Runnable task) {
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
if (onMainThread()) {
|
||||
if (isMainThread()) {
|
||||
runGuarded(task);
|
||||
return;
|
||||
}
|
||||
@@ -250,11 +255,6 @@ public final class ModdedScheduler implements PlatformScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean onMainThread() {
|
||||
Thread main = mainThread;
|
||||
return main != null && Thread.currentThread() == main;
|
||||
}
|
||||
|
||||
private void runGuarded(Runnable task) {
|
||||
try {
|
||||
task.run();
|
||||
|
||||
+75
-34
@@ -18,10 +18,14 @@
|
||||
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.DimensionStackContext;
|
||||
import art.arcane.iris.engine.DimensionTerrainContext;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.object.IrisBiome;
|
||||
import art.arcane.iris.engine.object.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.util.project.context.IrisContext;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
@@ -31,32 +35,24 @@ import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Vanilla-derivative spawn table state for {@link IrisModdedChunkGenerator}. Every mutator locks the
|
||||
* generator monitor because the repoint/bind/reset paths already hold it while resetting this state.
|
||||
*/
|
||||
final class ModdedSpawnTableMerger {
|
||||
private final IrisModdedChunkGenerator generator;
|
||||
private final ConcurrentHashMap<Biome, Holder<Biome>> vanillaSpawnBiomes = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<SpawnTableKey, WeightedList<MobSpawnSettings.SpawnerData>> mergedSpawnTables = new ConcurrentHashMap<>();
|
||||
private volatile boolean vanillaSpawnBiomesInitialized;
|
||||
private volatile SpawnTableState state = new SpawnTableState();
|
||||
|
||||
ModdedSpawnTableMerger(IrisModdedChunkGenerator generator) {
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
void initializeVanillaSpawnBiomes(Registry<Biome> registry) {
|
||||
// Volatile fast path BEFORE the monitor: this runs per mob category per spawn attempt
|
||||
// on the server thread, and the generator monitor is contended by binds/hotloads.
|
||||
if (vanillaSpawnBiomesInitialized) {
|
||||
SpawnTableState active = state;
|
||||
if (active.initialized) {
|
||||
return;
|
||||
}
|
||||
synchronized (generator) {
|
||||
if (vanillaSpawnBiomesInitialized) {
|
||||
synchronized (active) {
|
||||
if (active != state || active.initialized) {
|
||||
return;
|
||||
}
|
||||
Engine current = generator.engineOrNull();
|
||||
@@ -66,29 +62,70 @@ final class ModdedSpawnTableMerger {
|
||||
|
||||
try (GenerationSessionLease lease = generator.requireGenerationLease(current, "modded_spawn_biomes");
|
||||
IrisContext.Scope ignored = IrisContext.open(current, lease.sessionId(), null)) {
|
||||
String namespace = current.getDimension().getLoadKey().toLowerCase(Locale.ROOT);
|
||||
for (IrisBiome irisBiome : current.getDimension().getReachableBiomes(current)) {
|
||||
if (irisBiome == null || !irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
Holder<Biome> vanillaHolder = resolveBiomeHolder(registry, irisBiome.getVanillaDerivativeKey());
|
||||
if (vanillaHolder == null) {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
Holder<Biome> customHolder = resolveBiomeHolder(registry, namespace + ":" + customBiome.getId());
|
||||
if (customHolder != null) {
|
||||
vanillaSpawnBiomes.putIfAbsent(customHolder.value(), vanillaHolder);
|
||||
IrisDimension hostDimension = current.getDimension();
|
||||
addVanillaSpawnBiomes(
|
||||
registry,
|
||||
hostDimension,
|
||||
current.getData(),
|
||||
hostDimension.getReachableBiomes(current),
|
||||
active
|
||||
);
|
||||
DimensionStackContext stackContext = current.getDimensionStackContext();
|
||||
if (stackContext != null) {
|
||||
for (DimensionTerrainContext terrainContext : stackContext.getLayersBottomToTop()) {
|
||||
if (terrainContext.isSelfReferencing()) {
|
||||
continue;
|
||||
}
|
||||
IrisDimension dimension = terrainContext.getDimension();
|
||||
addVanillaSpawnBiomes(
|
||||
registry,
|
||||
dimension,
|
||||
terrainContext.getData(),
|
||||
dimension.getReachableBiomes(terrainContext),
|
||||
active
|
||||
);
|
||||
}
|
||||
}
|
||||
vanillaSpawnBiomesInitialized = true;
|
||||
active.initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addVanillaSpawnBiomes(
|
||||
Registry<Biome> registry,
|
||||
IrisDimension dimension,
|
||||
IrisData data,
|
||||
Iterable<IrisBiome> biomes,
|
||||
SpawnTableState state
|
||||
) {
|
||||
for (IrisBiome irisBiome : biomes) {
|
||||
if (irisBiome == null || !irisBiome.isCustom()) {
|
||||
continue;
|
||||
}
|
||||
Holder<Biome> vanillaHolder = resolveBiomeHolder(
|
||||
registry, irisBiome.getVanillaDerivativeKey());
|
||||
if (vanillaHolder == null) {
|
||||
continue;
|
||||
}
|
||||
for (IrisBiomeCustom customBiome : irisBiome.getCustomDerivitives()) {
|
||||
Holder<Biome> customHolder = resolveBiomeHolder(
|
||||
registry,
|
||||
ModdedWorldgenIds.biomeRef(
|
||||
data.getDataFolder().getName(),
|
||||
dimension.getLoadKey(),
|
||||
customBiome.getId()
|
||||
)
|
||||
);
|
||||
if (customHolder == null) {
|
||||
continue;
|
||||
}
|
||||
state.vanillaSpawnBiomes.putIfAbsent(customHolder.value(), vanillaHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Holder<Biome> vanillaSpawnBiome(Biome biome) {
|
||||
return vanillaSpawnBiomes.get(biome);
|
||||
return state.vanillaSpawnBiomes.get(biome);
|
||||
}
|
||||
|
||||
WeightedList<MobSpawnSettings.SpawnerData> mergedSpawnTable(
|
||||
@@ -96,7 +133,8 @@ final class ModdedSpawnTableMerger {
|
||||
WeightedList<MobSpawnSettings.SpawnerData> vanillaSpawns,
|
||||
WeightedList<MobSpawnSettings.SpawnerData> explicitSpawns) {
|
||||
SpawnTableKey key = new SpawnTableKey(biome, category);
|
||||
return mergedSpawnTables.computeIfAbsent(key, ignored -> NativeSpawnTableMerger.merge(vanillaSpawns, explicitSpawns));
|
||||
return state.mergedSpawnTables.computeIfAbsent(
|
||||
key, ignored -> NativeSpawnTableMerger.merge(vanillaSpawns, explicitSpawns));
|
||||
}
|
||||
|
||||
private Holder<Biome> resolveBiomeHolder(Registry<Biome> registry, String key) {
|
||||
@@ -112,13 +150,16 @@ final class ModdedSpawnTableMerger {
|
||||
}
|
||||
|
||||
void resetVanillaSpawnBiomes() {
|
||||
synchronized (generator) {
|
||||
vanillaSpawnBiomes.clear();
|
||||
mergedSpawnTables.clear();
|
||||
vanillaSpawnBiomesInitialized = false;
|
||||
}
|
||||
state = new SpawnTableState();
|
||||
}
|
||||
|
||||
private record SpawnTableKey(Biome biome, MobCategory category) {
|
||||
}
|
||||
|
||||
private static final class SpawnTableState {
|
||||
private final ConcurrentHashMap<Biome, Holder<Biome>> vanillaSpawnBiomes = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<SpawnTableKey, WeightedList<MobSpawnSettings.SpawnerData>> mergedSpawnTables =
|
||||
new ConcurrentHashMap<>();
|
||||
private volatile boolean initialized;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -84,7 +84,8 @@ final class ModdedEditCommands {
|
||||
}
|
||||
BlockPos pos = player.blockPosition();
|
||||
try {
|
||||
region = engine.getRegion(pos.getX(), pos.getZ());
|
||||
region = engine.getRegion(
|
||||
pos.getX(), pos.getY() - engine.getMinHeight(), pos.getZ());
|
||||
} catch (Throwable e) {
|
||||
IrisModdedCommands.fail(source, IrisLanguage.plain(ModdedCommandMessages.IRIS_MODDED_COMMANDS_REGION_LOOKUP_FAILED, MessageArgument.untrusted("value", e.getClass().getSimpleName())));
|
||||
return 0;
|
||||
|
||||
+52
-14
@@ -73,6 +73,8 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -85,6 +87,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import art.arcane.iris.core.localization.IrisLanguage;
|
||||
import art.arcane.iris.core.localization.ModdedCommandMessages;
|
||||
@@ -891,21 +894,30 @@ public final class ModdedStudioCommands {
|
||||
LinkedHashSet<String> objectKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> markerKeys = new LinkedHashSet<>();
|
||||
LinkedHashSet<String> structureKeys = new LinkedHashSet<>();
|
||||
List<IrisDimension> dimensions = new ArrayList<>();
|
||||
|
||||
dimension.getAllRegions(() -> dm).forEach((IrisRegion region) -> {
|
||||
if (region != null && region.getLoadKey() != null) {
|
||||
regionKeys.add(region.getLoadKey());
|
||||
for (String dimensionKey : PackExportClosure.collectDimensionKeys(dimension).stream().sorted().toList()) {
|
||||
IrisDimension exportedDimension = dm.getDimensionLoader().load(dimensionKey);
|
||||
if (exportedDimension != null) {
|
||||
dimensions.add(exportedDimension);
|
||||
}
|
||||
});
|
||||
dimension.getReachableBiomes(() -> dm).forEach((IrisBiome biome) -> {
|
||||
if (biome != null && biome.getLoadKey() != null) {
|
||||
biomeKeys.add(biome.getLoadKey());
|
||||
}
|
||||
});
|
||||
lootKeys.addAll(dimension.getLoot().getTables());
|
||||
spawnerKeys.addAll(dimension.getEntitySpawners());
|
||||
collectStructureKeys(structureKeys, dimension.getStructures());
|
||||
objectKeys.addAll(PackExportClosure.collectStaticObjectKeys(dimension.getStaticObjects()));
|
||||
}
|
||||
for (IrisDimension exportedDimension : dimensions) {
|
||||
exportedDimension.getAllRegions(() -> dm).forEach((IrisRegion region) -> {
|
||||
if (region != null && region.getLoadKey() != null) {
|
||||
regionKeys.add(region.getLoadKey());
|
||||
}
|
||||
});
|
||||
exportedDimension.getReachableBiomes(() -> dm).forEach((IrisBiome biome) -> {
|
||||
if (biome != null && biome.getLoadKey() != null) {
|
||||
biomeKeys.add(biome.getLoadKey());
|
||||
}
|
||||
});
|
||||
lootKeys.addAll(exportedDimension.getLoot().getTables());
|
||||
spawnerKeys.addAll(exportedDimension.getEntitySpawners());
|
||||
collectStructureKeys(structureKeys, exportedDimension.getStructures());
|
||||
objectKeys.addAll(PackExportClosure.collectStaticObjectKeys(exportedDimension.getStaticObjects()));
|
||||
}
|
||||
|
||||
for (String regionKey : regionKeys) {
|
||||
IrisRegion region = dm.getRegionLoader().load(regionKey);
|
||||
@@ -975,10 +987,17 @@ public final class ModdedStudioCommands {
|
||||
}
|
||||
}
|
||||
|
||||
hashes.append(copyJson(folder, "dimensions", dimension.getLoadKey(), dm.getDimensionLoader().findFile(dimension.getLoadKey())));
|
||||
for (IrisDimension exportedDimension : dimensions) {
|
||||
String key = exportedDimension.getLoadKey();
|
||||
hashes.append(copyJson(folder, "dimensions", key, dm.getDimensionLoader().findFile(key)));
|
||||
}
|
||||
for (String key : generatorKeys) {
|
||||
hashes.append(copyJson(folder, "generators", key, dm.getGeneratorLoader().findFile(key)));
|
||||
}
|
||||
for (String key : Stream.of(dm.getExpressionLoader().getPossibleKeys()).sorted().toList()) {
|
||||
hashes.append(copyJson(folder, "expressions", key, dm.getExpressionLoader().findFile(key)));
|
||||
}
|
||||
hashes.append(copyStyleSnippets(packFolder, folder));
|
||||
for (String key : regionKeys) {
|
||||
hashes.append(copyJson(folder, "regions", key, dm.getRegionLoader().findFile(key)));
|
||||
}
|
||||
@@ -1041,6 +1060,25 @@ public final class ModdedStudioCommands {
|
||||
}
|
||||
}
|
||||
|
||||
private static String copyStyleSnippets(File packFolder, File folder) throws IOException {
|
||||
Path sourceRoot = new File(packFolder, "snippet/style").toPath();
|
||||
if (!Files.isDirectory(sourceRoot)) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder hashes = new StringBuilder();
|
||||
try (Stream<Path> files = Files.walk(sourceRoot)) {
|
||||
for (Path source : files.filter(Files::isRegularFile)
|
||||
.filter(path -> path.getFileName().toString().endsWith(".json"))
|
||||
.sorted()
|
||||
.toList()) {
|
||||
String relative = sourceRoot.relativize(source).toString().replace(File.separatorChar, '/');
|
||||
String key = relative.substring(0, relative.length() - ".json".length());
|
||||
hashes.append(copyJson(folder, "snippet/style", key, source.toFile()));
|
||||
}
|
||||
}
|
||||
return hashes.toString();
|
||||
}
|
||||
|
||||
private static int regions(CommandSourceStack source, int radius) {
|
||||
ServerPlayer player = source.getPlayer();
|
||||
if (player == null) {
|
||||
|
||||
+2
-1
@@ -216,7 +216,8 @@ public final class ModdedWhatCommands {
|
||||
int centerX = (pos.getX() & ~15) + 8;
|
||||
int centerZ = (pos.getZ() & ~15) + 8;
|
||||
try {
|
||||
IrisRegion region = engine.getRegion(centerX, centerZ);
|
||||
IrisRegion region = engine.getRegion(
|
||||
centerX, pos.getY() - engine.getMinHeight(), centerZ);
|
||||
IrisModdedCommands.ok(source, IrisLanguage.plain(
|
||||
RuntimeUiMessages.WHAT_IRIS_REGION,
|
||||
MessageArgument.untrusted("region", region.getLoadKey()),
|
||||
|
||||
+20
-1
@@ -32,6 +32,7 @@ import art.arcane.iris.engine.object.IrisWorldBoundary;
|
||||
import art.arcane.iris.modded.IrisModdedChunkGenerator;
|
||||
import art.arcane.iris.modded.ModdedDimensionManager;
|
||||
import art.arcane.iris.modded.ModdedForcedDatapack;
|
||||
import art.arcane.iris.modded.ModdedScheduler;
|
||||
import art.arcane.iris.modded.ModdedWorkspaceGenerator;
|
||||
import art.arcane.iris.nativegen.NativeStructureVolumeIndex;
|
||||
import art.arcane.iris.modded.command.ModdedPregenJob;
|
||||
@@ -100,6 +101,11 @@ public final class ModdedStudioHotloadService implements ModdedTickableService,
|
||||
return NativeStructureVolumeIndex.volumes(engine, minX, minZ, maxX, maxZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMainThread() {
|
||||
return ModdedScheduler.isMainThread();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshDatapackWorkspace(Engine engine) {
|
||||
IrisData data = engine.getData();
|
||||
@@ -121,6 +127,20 @@ public final class ModdedStudioHotloadService implements ModdedTickableService,
|
||||
engine.getDimension(),
|
||||
replacement,
|
||||
"irisworldgen");
|
||||
IrisModdedChunkGenerator.requireStructureBiomeUniverseCompatible(
|
||||
engine.getDimension(), replacement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareRuntimeHotload(Engine engine) {
|
||||
IrisWorld world = engine.getWorld();
|
||||
if (world == null || !world.hasPlatformWorld()
|
||||
|| !(world.platformWorld().nativeHandle() instanceof ServerLevel level)
|
||||
|| !(level.getChunkSource().getGenerator() instanceof IrisModdedChunkGenerator generator)) {
|
||||
NativeStructureVolumeIndex.invalidate(engine);
|
||||
return;
|
||||
}
|
||||
generator.prepareRuntimeHotload(level, engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,7 +305,6 @@ public final class ModdedStudioHotloadService implements ModdedTickableService,
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
engine.hotloadSilently();
|
||||
generator.onHotload();
|
||||
ModdedIrisLog.info("Iris studio hotload {} pack={} {}ms", dimensionId, engine.getDimension().getLoadKey(), System.currentTimeMillis() - start);
|
||||
} catch (Throwable e) {
|
||||
ModdedIrisLog.error("Iris studio hotload failed for {}", dimensionId, e);
|
||||
|
||||
+1
@@ -59,6 +59,7 @@ public class IrisModdedChunkGeneratorSpawnTest {
|
||||
String spawn = source.substring(spawnStart, spawnEnd);
|
||||
|
||||
assertTrue(spawn.contains("spawnTables.initializeVanillaSpawnBiomes(registry)"));
|
||||
assertTrue(spawn.contains("structureBiomeSource.getVisibleSurfaceBiome("));
|
||||
assertTrue(spawn.contains("spawnTables.vanillaSpawnBiome(visibleBiome.value())"));
|
||||
assertTrue(spawn.contains("NaturalSpawner.spawnMobsForChunkGeneration("));
|
||||
assertTrue(spawn.contains("new LegacyRandomSource(RandomSupport.generateUniqueSeed())"));
|
||||
|
||||
+185
@@ -5,6 +5,7 @@ import art.arcane.iris.engine.object.IrisBiomeCustom;
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.engine.object.IrisRange;
|
||||
import art.arcane.iris.engine.object.InferredType;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import net.minecraft.SharedConstants;
|
||||
@@ -29,6 +30,8 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisModdedStructureParityTest {
|
||||
@BeforeClass
|
||||
@@ -110,6 +113,144 @@ public class IrisModdedStructureParityTest {
|
||||
assertEquals(expected, IrisModdedBiomeSource.biomeResolutionSeed(worldSeed, blockX, blockY, blockZ));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedCustomBiomesUseTheirOwningDimensionNamespace() {
|
||||
IrisDimension host = new IrisDimension();
|
||||
host.setLoadKey("Host");
|
||||
IrisDimension upper = new IrisDimension();
|
||||
upper.setLoadKey("Upper");
|
||||
|
||||
assertEquals(
|
||||
ModdedWorldgenIds.biomeRef("pack", "Upper", "Aurora"),
|
||||
IrisModdedBiomeSource.customBiomeRef("pack", upper, "Aurora")
|
||||
);
|
||||
assertFalse(IrisModdedBiomeSource.customBiomeRef("pack", host, "Aurora")
|
||||
.equals(IrisModdedBiomeSource.customBiomeRef("pack", upper, "Aurora")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visibleBiomeResolutionSelectsStackOwnershipBeforeHostCaves() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
|
||||
int resolutionStart = source.indexOf("private BiomeResolution resolveBiomeResolution(");
|
||||
int resolutionEnd = source.indexOf("private Holder<Biome> resolveRequiredStructureBiome(", resolutionStart);
|
||||
|
||||
assertTrue(resolutionStart >= 0);
|
||||
assertTrue(resolutionEnd > resolutionStart);
|
||||
String resolution = source.substring(resolutionStart, resolutionEnd);
|
||||
|
||||
assertTrue(resolution.contains("resolveDimensionStackLayer("));
|
||||
assertTrue(resolution.contains("!stackLayer.terrainContext().isSelfReferencing()"));
|
||||
assertTrue(resolution.indexOf("resolveDimensionStackLayer(")
|
||||
< resolution.indexOf("boolean underground"));
|
||||
assertTrue(resolution.contains("includeDimensionStack"));
|
||||
assertTrue(resolution.contains(
|
||||
"return resolveBiomeResolution(engine, quartX, quartY, quartZ, false)"));
|
||||
assertTrue(source.contains("resolution.packName(), resolution.dimension(), customBiome.getId()"));
|
||||
int helperStart = source.indexOf("private static IrisBiome resolveSurfaceStructureBiome(");
|
||||
int helperEnd = source.indexOf("private static Set<String> registeredBiomeKeys(", helperStart);
|
||||
String helper = source.substring(helperStart, helperEnd);
|
||||
assertTrue(helper.contains("engine.getComplex().getTrueBiomeStream().get(blockX, blockZ)"));
|
||||
assertFalse(helper.contains("getDimensionStackContext()"));
|
||||
assertFalse(helper.contains("getSurfaceBiome("));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackBiomesAreVisibleButExcludedFromStructureReachability() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
|
||||
|
||||
assertTrue(source.contains("return biomeKeySets().structureRequired()"));
|
||||
assertTrue(source.contains("generatedBiomeKeys.addAll(keys.visibleRequired())"));
|
||||
assertTrue(source.contains("collectStructureBiomeKeys("));
|
||||
assertTrue(source.contains("dimension.getReachableBiomes(() -> data)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeLocatorSearchesTheVisibleStack() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
|
||||
int start = source.indexOf("public Pair<BlockPos, Holder<Biome>> findClosestBiome3d(");
|
||||
int end = source.indexOf("private Holder<Biome> getNoiseBiome(", start);
|
||||
String method = source.substring(start, end);
|
||||
|
||||
assertTrue(method.contains("modded_locate_visible_biome"));
|
||||
assertTrue(method.contains("return super.findClosestBiome3d("));
|
||||
assertTrue(method.contains("collectVisibleBiomeHolders()"));
|
||||
assertTrue(method.contains("QuartPos.toBlock(quartX), QuartPos.toBlock(quartZ)"));
|
||||
assertTrue(method.contains("resolveVisibleBiome("));
|
||||
assertFalse(method.contains("Holder<Biome> structureBiome = getNoiseBiome("));
|
||||
assertTrue(method.indexOf("tryAcquireGenerationLease(engine, \"modded_locate_visible_biome\")")
|
||||
< method.indexOf("engine.getDimensionStackContext()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void surfaceSpawnBiomeUsesTheVisibleQuartCell() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
|
||||
int start = source.indexOf("Holder<Biome> getVisibleSurfaceBiome(");
|
||||
int end = source.indexOf("boolean isStructureReachable(", start);
|
||||
String method = source.substring(start, end);
|
||||
|
||||
assertTrue(method.contains("QuartPos.fromBlock(blockX)"));
|
||||
assertTrue(method.contains("QuartPos.toBlock(quartX)"));
|
||||
assertTrue(method.contains("QuartPos.fromBlock(internalY + engine.getMinHeight())"));
|
||||
assertTrue(method.contains("stackContext.getLayout(sampleX, sampleZ).surfaceLayer()"));
|
||||
assertTrue(method.contains("visibleBiomeCache"));
|
||||
assertTrue(method.contains("isBiomeCacheable(engine, sampleX, sampleZ)"));
|
||||
assertTrue(method.indexOf("boolean cacheable = isBiomeCacheable(engine, sampleX, sampleZ)")
|
||||
< method.indexOf("Engine.hostHeight(engine, sampleX, sampleZ, true)"));
|
||||
assertCacheGuarded(method, "visibleBiomeCache");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void temporaryNaturalBiomeAnswersAreNotMemoized() throws IOException {
|
||||
Engine engine = mock(Engine.class);
|
||||
when(engine.answersFromNaturalTerrain(12, -8)).thenReturn(true);
|
||||
assertFalse(IrisModdedBiomeSource.isBiomeCacheable(engine, 12, -8));
|
||||
when(engine.answersFromNaturalTerrain(12, -8)).thenReturn(false);
|
||||
assertTrue(IrisModdedBiomeSource.isBiomeCacheable(engine, 12, -8));
|
||||
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/IrisModdedBiomeSource.java"));
|
||||
int structureStart = source.indexOf("private Holder<Biome> getNoiseBiome(Engine engine");
|
||||
int structureEnd = source.indexOf("Holder<Biome> getVisibleNoiseBiome(", structureStart);
|
||||
String structure = source.substring(structureStart, structureEnd);
|
||||
assertTrue(structure.contains("QuartPos.toBlock(quartX)"));
|
||||
assertTrue(structure.contains("QuartPos.toBlock(quartZ)"));
|
||||
assertCacheGuarded(structure, "structureBiomeCache");
|
||||
|
||||
int visibleStart = source.indexOf(
|
||||
"private Holder<Biome> getVisibleNoiseBiomeWithActiveGenerationLease(");
|
||||
int visibleEnd = source.indexOf("Holder<Biome> getVisibleSurfaceBiome(", visibleStart);
|
||||
String visible = source.substring(visibleStart, visibleEnd);
|
||||
assertTrue(visible.contains("QuartPos.toBlock(quartX)"));
|
||||
assertTrue(visible.contains("QuartPos.toBlock(quartZ)"));
|
||||
assertCacheGuarded(visible, "visibleBiomeCache");
|
||||
|
||||
int predicateStart = source.indexOf("static boolean isBiomeCacheable(");
|
||||
int predicateEnd = source.indexOf("static boolean isMonumentSurfaceBiomeQuery(", predicateStart);
|
||||
String predicate = source.substring(predicateStart, predicateEnd);
|
||||
assertTrue(predicate.contains("return !engine.answersFromNaturalTerrain(blockX, blockZ)"));
|
||||
assertFalse(predicate.contains("getDimensionStackContext()"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importedFeaturesCollectOnlyHostOwnedStackCells() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/ModdedImportedFeatureStage.java"));
|
||||
|
||||
assertTrue(source.contains("stackContext.getLayerAt("));
|
||||
assertTrue(source.contains("layer.terrainContext().isSelfReferencing()"));
|
||||
assertTrue(source.contains("section.getBiomes().get(quartX, quartY, quartZ)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredBiomeKeysContainOnlyPackDerivativesAndCustomBiomes() {
|
||||
IrisBiome ocean = new IrisBiome()
|
||||
@@ -132,6 +273,21 @@ public class IrisModdedStructureParityTest {
|
||||
"minecraft:the_void", "overworld:aurora"), keys);
|
||||
assertFalse(keys.contains("minecraft:desert"));
|
||||
assertFalse(keys.contains("minecraft:plains"));
|
||||
|
||||
Set<String> recursiveKeys = ModdedDimensionMetadata.collectConfiguredBiomeKeys(
|
||||
List.of(custom), "Layers/Sky");
|
||||
assertTrue(recursiveKeys.contains("layers:sky/aurora"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void biomeWriterDerivativeFallbackMatchesCanonicalRecursiveKeys() throws IOException {
|
||||
String source = Files.readString(Path.of(
|
||||
System.getProperty("iris.moddedCommonSources"),
|
||||
"art/arcane/iris/modded/ModdedBiomeWriter.java"));
|
||||
|
||||
assertTrue(source.contains(
|
||||
"key.equalsIgnoreCase(dimension.getCustomBiomeKey(custom.getId()))"));
|
||||
assertFalse(source.contains("String dimensionLoadKey = key.substring(0, colon)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,6 +315,19 @@ public class IrisModdedStructureParityTest {
|
||||
assertSame(configured, IrisModdedBiomeSource.requireConfiguredStructureBiomeKeys(configured));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liveReplacementRequiresTheSameStructureBiomeUniverse() {
|
||||
IrisModdedChunkGenerator.requireStructureBiomeUniverseCompatible(
|
||||
Set.of("minecraft:plains", "minecraft:beach"),
|
||||
Set.of("minecraft:beach", "minecraft:plains"));
|
||||
|
||||
IllegalArgumentException error = assertThrows(IllegalArgumentException.class,
|
||||
() -> IrisModdedChunkGenerator.requireStructureBiomeUniverseCompatible(
|
||||
Set.of("minecraft:plains"), Set.of("minecraft:desert")));
|
||||
|
||||
assertTrue(error.getMessage().contains("Restart the server"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configuredDimensionMetadataIsExactBeforeEngineBinding() {
|
||||
IrisDimension dimension = new IrisDimension()
|
||||
@@ -240,4 +409,20 @@ public class IrisModdedStructureParityTest {
|
||||
assertSame(MantleFlag.INITIAL_SPAWNED_MARKER, ModdedWorldManager.INITIAL_SPAWN_COMPLETION_FLAG);
|
||||
}
|
||||
|
||||
private static void assertCacheGuarded(String method, String cacheName) {
|
||||
int predicate = method.indexOf("boolean cacheable = isBiomeCacheable(");
|
||||
int cache = method.indexOf("BiomeHolderTable cache = " + cacheName, predicate);
|
||||
int read = method.indexOf("cache.get(", predicate);
|
||||
int readGuard = method.lastIndexOf("if (cacheable)", read);
|
||||
int write = method.indexOf("cache.put(", read);
|
||||
int writeGuard = method.lastIndexOf("if (cacheable)", write);
|
||||
|
||||
assertTrue(predicate >= 0);
|
||||
assertTrue(cache >= 0);
|
||||
assertTrue(read > predicate);
|
||||
assertTrue(readGuard >= predicate);
|
||||
assertTrue(write > read);
|
||||
assertTrue(writeGuard > read);
|
||||
}
|
||||
|
||||
}
|
||||
+24
-2
@@ -135,6 +135,24 @@ public class ModdedNativeStructureWorldgenAccessTest {
|
||||
assertEquals(1, recording.blockTicks.count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void virtualizedHeightsHideInRegionTerrainFromTheDelegate() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
ChunkPos generationCenter = generationCenter();
|
||||
ModdedNativeStructureWorldgenAccess access = ModdedNativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter,
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
true,
|
||||
position -> false);
|
||||
int x = generationCenter.getMiddleBlockX();
|
||||
int z = generationCenter.getMiddleBlockZ();
|
||||
|
||||
assertEquals(SURFACE_FIRST_FREE_Y, access.getHeight(Heightmap.Types.WORLD_SURFACE_WG, x, z));
|
||||
assertEquals(FLOOR_FIRST_FREE_Y, access.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, x, z));
|
||||
assertEquals(0, recording.heightReads);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void protectedCellsRemainReadableButRejectWritesTilesAndTicks() {
|
||||
RecordingDelegate recording = new RecordingDelegate();
|
||||
@@ -142,7 +160,9 @@ public class ModdedNativeStructureWorldgenAccessTest {
|
||||
ModdedNativeStructureWorldgenAccess access = ModdedNativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y, position::equals);
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
false,
|
||||
position::equals);
|
||||
|
||||
assertSame(Blocks.DIRT, access.getBlockState(position).getBlock());
|
||||
assertFalse(access.ensureCanWrite(position));
|
||||
@@ -211,7 +231,9 @@ public class ModdedNativeStructureWorldgenAccessTest {
|
||||
return ModdedNativeStructureWorldgenAccess.create(
|
||||
recording.world(), generationCenter(),
|
||||
(x, z) -> SURFACE_FIRST_FREE_Y,
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y, position -> false);
|
||||
(x, z) -> FLOOR_FIRST_FREE_Y,
|
||||
false,
|
||||
position -> false);
|
||||
}
|
||||
|
||||
private static ChunkPos generationCenter() {
|
||||
|
||||
+5
-2
@@ -95,8 +95,9 @@ public class NativeStructureFailureContractTest {
|
||||
assertTrue(placement.contains("heightmapStarts.add(start);"));
|
||||
assertTrue(placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement(")
|
||||
< placement.indexOf("prepareSurfaceStructures"));
|
||||
assertTrue(source.contains("generationEngine.getHeight(x, z, false) + runtimeMinY + 1"));
|
||||
assertTrue(source.contains("generationEngine.getHeight(x, z, true) + runtimeMinY + 1"));
|
||||
assertTrue(source.contains("Engine.hostHeight(generationEngine, x, z, false) + runtimeMinY + 1"));
|
||||
assertTrue(source.contains("Engine.hostHeight(generationEngine, x, z, true) + runtimeMinY + 1"));
|
||||
assertTrue(placement.contains("current.getDimensionStackContext() != null"));
|
||||
assertTrue(source.contains("int minY = chunk.getMinY() + 1;"));
|
||||
}
|
||||
|
||||
@@ -108,6 +109,8 @@ public class NativeStructureFailureContractTest {
|
||||
String placement = source.substring(placementStart, placementEnd);
|
||||
|
||||
assertTrue(placement.contains("ModdedNativeStructureWorldgenAccess.create("));
|
||||
assertTrue(placement.contains("nativeStructureProtection(current, staticObjects)"));
|
||||
assertTrue(placement.contains("Engine.hostHeight(current, x, z, true)"));
|
||||
assertTrue(placement.contains("placeVanillaStructure(boundedWorld, structureManager"));
|
||||
assertFalse(placement.contains("NativeStructurePostProcessor.place(world,"));
|
||||
assertTrue(placement.contains("world.setCurrentlyGenerating(null);"));
|
||||
|
||||
+19
@@ -1,10 +1,12 @@
|
||||
package art.arcane.iris.modded.service;
|
||||
|
||||
import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.modded.ModdedScheduler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -26,4 +28,21 @@ public class ModdedStudioHotloadServiceTest {
|
||||
assertFalse(ModdedStudioHotloadService.hasDatapackImports(null));
|
||||
assertFalse(ModdedStudioHotloadService.hasDatapackImports(List.of(empty)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportsTheCapturedServerThread() throws InterruptedException {
|
||||
ModdedScheduler scheduler = new ModdedScheduler();
|
||||
scheduler.reset();
|
||||
try {
|
||||
ModdedStudioHotloadService service = new ModdedStudioHotloadService();
|
||||
assertTrue(service.isMainThread());
|
||||
AtomicBoolean offThread = new AtomicBoolean(true);
|
||||
Thread worker = new Thread(() -> offThread.set(service.isMainThread()));
|
||||
worker.start();
|
||||
worker.join();
|
||||
assertFalse(offThread.get());
|
||||
} finally {
|
||||
scheduler.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user