mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Merge branch 'wave3b/p' into feat/irisapi-host
# Conflicts: # core/src/main/java/art/arcane/iris/core/modules/ModuleServices.java
This commit is contained in:
commit
80d50b5cff
8 files changed
+230
-18
No files matched your search
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import com.volmit.service.CaveBiomes;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* What the world's {@link CaveBiomes} provider says, kept for the world. The host asks it for every cave block it gives a
|
||||
* biome, so the provider is found once per world, each biome's minimum depth asked once and each overriding biome
|
||||
* loaded once.
|
||||
*/
|
||||
public final class CaveBiomeAnswers {
|
||||
private static final CaveBiomes NO_PROVIDER = new CaveBiomes() {
|
||||
@Override
|
||||
public Optional<String> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
private final PackWorld world;
|
||||
private final IrisData data;
|
||||
private final CaveBiomes provider;
|
||||
private final Map<String, IrisBiome> overridingBiomes = new ConcurrentHashMap<>();
|
||||
private final Map<String, Integer> minDepths = new ConcurrentHashMap<>();
|
||||
|
||||
CaveBiomeAnswers(Engine engine, CaveBiomes provider, PackWorld world) {
|
||||
this.world = world;
|
||||
this.data = engine.getData();
|
||||
this.provider = provider == null ? NO_PROVIDER : provider;
|
||||
}
|
||||
|
||||
/** The pack biome the module puts at the position whatever the regions say; null where it overrides nothing or names a biome the pack lacks. {@code y} is the height above the dimension's bottom. */
|
||||
public IrisBiome overriddenBiome(int x, int y, int z) {
|
||||
Optional<String> key = provider.overriddenBiome(world, x, y, z);
|
||||
return key.isEmpty() ? null : overridingBiome(key.get());
|
||||
}
|
||||
|
||||
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
|
||||
public int minDepthBelowSurface(String biomeKey) {
|
||||
Integer depth = minDepths.get(biomeKey);
|
||||
if (depth != null) {
|
||||
return depth;
|
||||
}
|
||||
return minDepths.computeIfAbsent(biomeKey, key -> provider.minDepthBelowSurface(world, key));
|
||||
}
|
||||
|
||||
private IrisBiome overridingBiome(String key) {
|
||||
IrisBiome biome = overridingBiomes.get(key);
|
||||
if (biome != null) {
|
||||
return biome;
|
||||
}
|
||||
biome = data.getBiomeLoader().load(key);
|
||||
if (biome != null) {
|
||||
overridingBiomes.putIfAbsent(key, biome);
|
||||
}
|
||||
return biome;
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,12 @@ final class IrisTerrainSampler implements TerrainSampler {
|
||||
return new TerrainSample(surfaceY, fluidY, slope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double surfaceY(int worldX, int worldZ) {
|
||||
requireInside(worldX, bounds.minY(), worldZ);
|
||||
return engine.getComplex().getHeightStream().get(worldX, worldZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeSample biome(int worldX, int y, int worldZ) {
|
||||
requireInside(worldX, y, worldZ);
|
||||
|
||||
@@ -77,17 +77,11 @@ public final class ModuleServices {
|
||||
return Optional.of(new Provider<>(service.cast(first.provider()), first.scope(engine.getGeneration().world())));
|
||||
}
|
||||
|
||||
/** The pack biome key the module that decides cave biomes puts at the position, whatever the regions say; empty where it overrides nothing. {@code y} is the height above the dimension's bottom. */
|
||||
public static Optional<String> overriddenCaveBiome(Engine engine, int x, int y, int z) {
|
||||
return firstProvider(engine, CaveBiomes.class)
|
||||
.flatMap(provider -> provider.service().overriddenBiome(provider.world(), x, y, z));
|
||||
}
|
||||
|
||||
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
|
||||
public static int caveMinDepthBelowSurface(Engine engine, String biomeKey) {
|
||||
return firstProvider(engine, CaveBiomes.class)
|
||||
.map(provider -> provider.service().minDepthBelowSurface(provider.world(), biomeKey))
|
||||
.orElse(0);
|
||||
/** What the module that decides cave biomes says for the engine's world, kept for the world, its log the module's own. */
|
||||
public static CaveBiomeAnswers caveBiomes(Engine engine) {
|
||||
return engine.getGeneration().state(CaveBiomeAnswers.class, owner -> firstProvider(owner, CaveBiomes.class)
|
||||
.map(provider -> new CaveBiomeAnswers(owner, provider.service(), provider.world()))
|
||||
.orElseGet(() -> new CaveBiomeAnswers(owner, null, owner.getGeneration().world())));
|
||||
}
|
||||
|
||||
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
|
||||
|
||||
@@ -44,7 +44,8 @@ public final class PackModuleSet implements AutoCloseable {
|
||||
private final File packFolder;
|
||||
private final Supplier<Gson> irisGson;
|
||||
private State state = State.NOT_LOADED;
|
||||
private LoadedPack pack;
|
||||
/** Set only while loaded; volatile so {@link #pack()}, asked on the generation hot path, needs no lock then. */
|
||||
private volatile LoadedPack pack;
|
||||
private ModuleSettingsDecoder settings;
|
||||
private PackModulesException failure;
|
||||
private List<String> loadedJars = List.of();
|
||||
@@ -56,7 +57,15 @@ public final class PackModuleSet implements AutoCloseable {
|
||||
}
|
||||
|
||||
/** The loaded pack, its built-in modules included. */
|
||||
public synchronized LoadedPack pack() {
|
||||
public LoadedPack pack() {
|
||||
LoadedPack loaded = pack;
|
||||
if (loaded != null) {
|
||||
return loaded;
|
||||
}
|
||||
return loadedPack();
|
||||
}
|
||||
|
||||
private synchronized LoadedPack loadedPack() {
|
||||
requireLoaded();
|
||||
return pack;
|
||||
}
|
||||
@@ -111,8 +120,8 @@ public final class PackModuleSet implements AutoCloseable {
|
||||
loadedJars = jarFingerprint();
|
||||
try {
|
||||
LoadedPack loaded = LoadedPack.load(packFolder.toPath(), IrisModuleHost.get());
|
||||
pack = loaded;
|
||||
settings = new ModuleSettingsDecoder(loaded.catalog(), packFolder.toPath(), irisGson);
|
||||
pack = loaded;
|
||||
state = State.LOADED;
|
||||
warnWhenBuiltInModulesAreMissing(loaded);
|
||||
} catch (RuntimeException loadFailure) {
|
||||
|
||||
@@ -46,6 +46,9 @@ public final class PlatformBlockStates {
|
||||
private final Map<PlatformBlockState, BlockState> read = new HashMap<>();
|
||||
private final Map<BlockState, PlatformBlockState> written = new HashMap<>();
|
||||
private final Map<BlockState, PlatformBlockState> origins = new IdentityHashMap<>();
|
||||
/** The state read last: scans over a chunk read long runs of one state, such as stone or air, so most reads hit it. */
|
||||
private PlatformBlockState lastRead;
|
||||
private BlockState lastReadAsApi;
|
||||
|
||||
/** {@code platformStates} turns a block state key into the platform's state, such as {@code B::getState}. */
|
||||
public PlatformBlockStates(Function<String, PlatformBlockState> platformStates) {
|
||||
@@ -60,6 +63,14 @@ public final class PlatformBlockStates {
|
||||
if (state == null) {
|
||||
return AIR;
|
||||
}
|
||||
if (state != lastRead) {
|
||||
lastReadAsApi = convertRead(state);
|
||||
lastRead = state;
|
||||
}
|
||||
return lastReadAsApi;
|
||||
}
|
||||
|
||||
private BlockState convertRead(PlatformBlockState state) {
|
||||
BlockState known = read.get(state);
|
||||
if (known != null) {
|
||||
return known;
|
||||
|
||||
@@ -28,6 +28,7 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.nms.container.BlockPos;
|
||||
import art.arcane.iris.core.nms.container.Pair;
|
||||
import art.arcane.iris.core.modules.CaveBiomeAnswers;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.IrisComplex;
|
||||
import art.arcane.iris.engine.UpperDimensionContext;
|
||||
@@ -71,7 +72,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -275,8 +275,8 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
@BlockCoordinates
|
||||
default IrisBiome getCaveBiome(int x, int y, int z) {
|
||||
IrisBiome surfaceBiome = getSurfaceBiome(x, z);
|
||||
Optional<String> overriddenKey = ModuleServices.overriddenCaveBiome(this, x, y, z);
|
||||
IrisBiome overriddenBiome = overriddenKey.map(key -> getData().getBiomeLoader().load(key)).orElse(null);
|
||||
CaveBiomeAnswers caves = ModuleServices.caveBiomes(this);
|
||||
IrisBiome overriddenBiome = caves.overriddenBiome(x, y, z);
|
||||
if (overriddenBiome != null) {
|
||||
return overriddenBiome;
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
return surfaceBiome;
|
||||
}
|
||||
|
||||
int minDepth = Math.max(0, ModuleServices.caveMinDepthBelowSurface(this, caveBiome.getLoadKey()));
|
||||
int minDepth = Math.max(0, caves.minDepthBelowSurface(caveBiome.getLoadKey()));
|
||||
if (depthBelowSurface < minDepth) {
|
||||
return surfaceBiome;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user