IrisPackWorld implements LiveWorld.Source: the engine's answers for a block, the platform's sky and loot tables, an object's loot and the saved spawner cooldowns, as values; the world manager no longer tidies cooldowns itself (the spawn module does)

This commit is contained in:
piexel committed 2026-10-10 18:21:37 +02:00
1 parent 540b4beaed
commit 2b49ffb759
5 files changed
+430 -8

No files matched your search

@@ -0,0 +1,58 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
import art.arcane.iris.engine.framework.Engine;
import java.util.function.ToLongFunction;
/** The cooldowns of an engine's spawners, in the data the engine saves with its world. */
final class EngineSpawnCooldowns implements SpawnCooldowns {
private final Engine engine;
EngineSpawnCooldowns(Engine engine) {
this.engine = engine;
}
@Override
public boolean canSpawn(String spawner, long intervalMilliseconds) {
return engine.getEngineData().getCooldown(spawner).canSpawn(intervalMilliseconds);
}
@Override
public void spawned(String spawner) {
engine.getEngineData().getCooldown(spawner).spawn();
}
@Override
public boolean canSpawnInChunk(int chunkX, int chunkZ, String spawner, long intervalMilliseconds) {
return engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(spawner).canSpawn(intervalMilliseconds);
}
@Override
public void spawnedInChunk(int chunkX, int chunkZ, String spawner) {
engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(spawner).spawn();
}
@Override
public void forgetExpired(ToLongFunction<String> intervalMilliseconds) {
engine.getEngineData().cleanup(intervalMilliseconds);
}
}
@@ -0,0 +1,155 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.LiveWorld;
import art.arcane.iris.builtin.spawn.SpawnCooldowns;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.value.IrisPosition;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.framework.PlacedObject;
import art.arcane.iris.engine.object.world.biome.InferredType;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformWorld;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
import com.volmit.IrisFeature;
import com.volmit.resource.ResourceId;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
* An engine as {@link LiveWorld} shows it to the built-in services: the engine's own answers for a block, turned into pack
* resource ids and values.
*/
final class IrisLiveWorld implements LiveWorld {
private final Engine engine;
private final IrisPackResources resources;
private final SpawnCooldowns cooldowns;
private volatile Set<String> platformLootTables;
IrisLiveWorld(Engine engine, IrisPackResources resources) {
this.engine = engine;
this.resources = resources;
this.cooldowns = new EngineSpawnCooldowns(engine);
}
@Override
public int bottomY() {
return engine.getMinHeight();
}
@Override
public ResourceId surfaceBiome(int x, int z) {
return idOf(engine.getSurfaceBiome(x, z));
}
@Override
public ResourceId caveBiome(int x, int y, int z) {
IrisBiome cave = engine.getCaveBiome(x, y, z);
return cave == null ? surfaceBiome(x, z) : idOf(cave);
}
@Override
public BiomeKind surfaceKind(int x, int z) {
InferredType type = engine.getSurfaceBiome(x, z).getInferredType();
return BiomeKind.valueOf(type.name());
}
@Override
public double terrainHeight(int x, int z) {
return engine.getComplex().getHeightStream().get(x, z);
}
@Override
public int highestBlock(int x, int z, boolean ignoreFluid) {
return engine.getHeight(x, z, ignoreFluid);
}
@Override
public <F extends IrisFeature> Optional<F> settings(Class<F> type, Level level, int x, int y, int z) {
IrisRegistrant owner = switch (level) {
case DIMENSION -> engine.getDimension();
case REGION -> engine.getRegion(x, z);
case SURFACE_BIOME -> engine.getSurfaceBiome(x, z);
case BIOME -> engine.getBiome(x, y, z);
case CAVE_BIOME -> engine.getCaveBiome(x, y, z);
};
return owner == null ? Optional.empty() : owner.getModuleSettings().find(type);
}
@Override
public Optional<Sky> sky() {
PlatformWorld world = engine.getWorld().platformWorld();
if (world == null) {
return Optional.empty();
}
return Optional.of(new Sky(world.getTime(), world.isStorming(), world.isThundering()));
}
@Override
public boolean studio() {
return engine.isStudio();
}
@Override
public Set<String> platformLootTables() {
Set<String> known = platformLootTables;
if (known == null) {
known = Set.copyOf(IrisPlatforms.get().registries().lootTableKeys());
platformLootTables = known;
}
return known;
}
@Override
public List<BlockPosition> caveFloors(int chunkX, int chunkZ) {
if (J.isFolia()) {
return List.of();
}
int bottom = engine.getMinHeight();
return engine.getMantle().findMarkers(chunkX, chunkZ, MarkerMatter.CAVE_FLOOR).stream()
.map(floor -> new BlockPosition(floor.getX(), floor.getY() - bottom, floor.getZ()))
.toList();
}
@Override
public Optional<ObjectLoots> objectLoots(int x, int y, int z) {
PlacedObject placed = engine.getObjectPlacement(x, y, z);
IrisObjectPlacement placement = placed == null ? null : placed.getPlacement();
if (placement == null) {
return Optional.empty();
}
return Optional.of(new ObjectLoots(placement.getLoot(), placement.getVanillaLoot(), placement.isOverrideGlobalLoot()));
}
@Override
public SpawnCooldowns spawnCooldowns() {
return cooldowns;
}
private ResourceId idOf(IrisBiome biome) {
return resources.idOf(biome.getLoadKey());
}
}
@@ -19,6 +19,7 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.IrisSeed;
import art.arcane.iris.builtin.LiveWorld;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
import com.volmit.ModuleLog;
@@ -35,12 +36,13 @@ import java.util.function.Function;
* pack's resources reload under it. Iris's built-in modules reach the engine through {@link #of(PackWorld)}, as built-in
* reaches do through {@link IrisPackSettings#of}.
*/
public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source {
private final Engine engine;
private final IrisPackResources resources;
private final WorldStates states;
private final ModuleLog log;
private final Map<ModuleLog, IrisPackWorld> viewsByLog;
private final LiveWorld liveWorld;
IrisPackWorld(Engine engine) {
this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
@@ -53,6 +55,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
this.states = states;
this.log = log;
this.viewsByLog = viewsByLog;
this.liveWorld = new IrisLiveWorld(engine, resources);
}
/** Iris's own view of {@code world}, which Iris hands to every stage, service and lifecycle hook. */
@@ -99,6 +102,11 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source {
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
}
@Override
public LiveWorld liveWorld() {
return liveWorld;
}
@Override
public long seed(IrisSeed seed) {
SeedManager seeds = engine.getSeedManager();
@@ -58,7 +58,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
private final KList<Runnable> updateQueue = new KList<>();
final ChronoLatch cl;
private final ChronoLatch clw;
private final ChronoLatch cln;
private final ChronoLatch chunkUpdater;
private final ChronoLatch chunkDiscovery;
private final KMap<Long, Future<?>> cleanup = new KMap<>();
@@ -89,7 +88,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
public IrisWorldManager() {
super(null);
cl = null;
cln = null;
clw = null;
looper = null;
chunkUpdater = null;
@@ -101,7 +99,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
super(engine);
chunkUpdater = new ChronoLatch(3000);
chunkDiscovery = new ChronoLatch(5000);
cln = new ChronoLatch(60000);
cl = new ChronoLatch(3000);
clw = new ChronoLatch(1000, true);
cleanupService = createCleanupExecutor(getTarget().getWorld().name());
@@ -157,10 +154,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
chunkMaintenance.discoverChunks();
}
if (cln.flip()) {
getEngine().getEngineData().cleanup(getEngine());
}
if (!IrisSettings.get().getWorld().isMarkerEntitySpawningSystem()
&& !IrisSettings.get().getWorld().isAmbientEntitySpawningSystem()) {
return 3000L;