mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 09:15:27 +00:00
Batch 3 of the API review: Iris offers its facades as extensions
- IrisPackWorld offers IrisSeeds, LiveWorld, ObjectHost, FloatingHost, StructureHost (and the engine to the structure built-ins) through extension(); IrisPackSettings the facades a reach needs. withLog, the Source interfaces and the of(...) casts are gone (HostExtensions). - The invocation inputs offer IrisChunk / IrisMantleChunk, MatterMantle and ObjectPlacement; IrisChunk.current(), IrisMantleChunk.current() and IrisPlacement.runBound are gone. A chunk stage's MatterMantle is its own chunk plus the loaded neighbours (OwnChunkMatter). - IrisPackResources serves find(kind, id) / ids(kind) and maps ids back to pack keys at the host's edge (keyOf); ModuleServices, ContentServices, the settings decoder (a bare ResourceId is the pack's id), ModuleSettings and CaveBiomeAnswers convert there. - MantleCaverns, IrisModuleMantle and PlacementMantle answer isCarved. - Starts get a StartKey per platform start (weakly held). - Bukkit adapters read the Optional-valued items, entities and effects. - Tests follow; the loot and entity pins are retaken after checking that the old printing of the new values gives the old hashes.
This commit is contained in:
1 parent
7fc4445ab7
commit
4bacc306e9
82 files changed
+783
-693
No files matched your search
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.content;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
@@ -26,6 +27,7 @@ import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.item.ItemEnchantment;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
@@ -51,12 +53,14 @@ public final class ContentServices {
|
||||
* @param containerKey the platform's key for the block when it is a storage chest an object may have given loot, else null
|
||||
*/
|
||||
public static List<ContentLoot.Part> containerLoot(Engine engine, int x, int worldY, int z, String containerKey, boolean nativeLootDefined) {
|
||||
BlockState container = containerKey == null ? null : BlockState.parse(PlatformBlockStates.namespaced(containerKey));
|
||||
Optional<BlockState> container = containerKey == null
|
||||
? Optional.empty()
|
||||
: Optional.of(BlockState.parse(PlatformBlockStates.namespaced(containerKey)));
|
||||
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), container, nativeLootDefined, false);
|
||||
List<ContentLoot.Part> parts = new ArrayList<>();
|
||||
for (Loot.Source source : ModuleServices.lootTables(engine, site)) {
|
||||
switch (source) {
|
||||
case Loot.Table table -> parts.add(new ContentLoot.Items(tableItems(engine, x, worldY, z, table.key())));
|
||||
case Loot.Table table -> parts.add(new ContentLoot.Items(tableItems(engine, x, worldY, z, table.id())));
|
||||
case Loot.PlatformTable table -> parts.add(new ContentLoot.PlatformTable(table.key(), table.seed()));
|
||||
}
|
||||
}
|
||||
@@ -65,8 +69,12 @@ public final class ContentServices {
|
||||
|
||||
/** The items the pack's loot table {@code tableKey} gives at the spot. */
|
||||
public static List<ContentItem> tableItems(Engine engine, int x, int worldY, int z, String tableKey) {
|
||||
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), null, false, false);
|
||||
return ModuleServices.lootItems(engine, site, tableKey).stream().map(ContentServices::itemOf).toList();
|
||||
return tableItems(engine, x, worldY, z, engine.getData().getPackResources().idOf(tableKey));
|
||||
}
|
||||
|
||||
private static List<ContentItem> tableItems(Engine engine, int x, int worldY, int z, ResourceId table) {
|
||||
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), Optional.empty(), false, false);
|
||||
return ModuleServices.lootItems(engine, site, table).stream().map(ContentServices::itemOf).toList();
|
||||
}
|
||||
|
||||
/** What the modules drop for the block with the platform's key {@code blockKey} broken at the spot. */
|
||||
@@ -83,13 +91,16 @@ public final class ContentServices {
|
||||
|
||||
/** What the first module that knows the spawner plans at the marker block. */
|
||||
public static Optional<ContentSpawns.Plan> planMarkerSpawn(Engine engine, int x, int worldY, int z, String marker, String spawner, boolean initial) {
|
||||
return planned(engine, new EntitySpawns.Marker(position(engine, x, worldY, z), marker, spawner, initial));
|
||||
ResourceId spawnerId = engine.getData().getPackResources().idOf(spawner);
|
||||
return planned(engine, new EntitySpawns.Marker(position(engine, x, worldY, z), marker, spawnerId, initial));
|
||||
}
|
||||
|
||||
/** What the marker with the tag {@code tag} does; empty for a tag no module knows. */
|
||||
public static Optional<ContentSpawns.MarkerRule> markerRule(Engine engine, String tag) {
|
||||
IrisPackResources resources = engine.getData().getPackResources();
|
||||
return ModuleServices.markerRule(engine, tag)
|
||||
.map(rule -> new ContentSpawns.MarkerRule(rule.spawners(), rule.emptyAbove(), rule.removeOnChange()));
|
||||
.map(rule -> new ContentSpawns.MarkerRule(rule.spawners().stream().map(resources::keyOf).toList(),
|
||||
rule.emptyAbove(), rule.removeOnChange()));
|
||||
}
|
||||
|
||||
/** The entity of the pack named {@code key} as a module would spawn it; empty for an unknown key. */
|
||||
@@ -121,10 +132,12 @@ public final class ContentServices {
|
||||
}
|
||||
|
||||
private static ContentItem itemOf(ItemDrop drop) {
|
||||
return new ContentItem(drop.item(), drop.amount(), drop.displayName(), drop.lore(),
|
||||
return new ContentItem(drop.item(), drop.amount(), drop.displayName().orElse(null), drop.lore(),
|
||||
drop.enchantments().stream().map(ContentServices::enchantmentOf).toList(),
|
||||
drop.attributes().stream().map(ContentServices::attributeOf).toList(), drop.unbreakable(), drop.flags(),
|
||||
drop.customModel(), drop.damage(), drop.leatherColor(), drop.dyeColor(), drop.customNbt());
|
||||
drop.customModel().isPresent() ? drop.customModel().getAsInt() : null,
|
||||
drop.damage().isPresent() ? drop.damage().getAsDouble() : null,
|
||||
drop.leatherColor().orElse(null), drop.dyeColor().orElse(null), drop.customNbt());
|
||||
}
|
||||
|
||||
private static ContentItem.Enchantment enchantmentOf(ItemEnchantment enchantment) {
|
||||
@@ -135,12 +148,19 @@ public final class ContentServices {
|
||||
return new ContentItem.Attribute(attribute.attribute(), attribute.name(), attribute.operation(), attribute.amount());
|
||||
}
|
||||
|
||||
/**
|
||||
* The adapters' entity keeps their conventions: a missing type, special type or name is empty text, anything else
|
||||
* missing is {@code null}. Loot tables are named by their ids' paths, which is how the adapters ask
|
||||
* {@link #tableItems} for them again.
|
||||
*/
|
||||
private static ContentEntity entityOf(EntitySpec spec) {
|
||||
return new ContentEntity(spec.type(), spec.specialType(), spec.reason(), spec.customName(), flagsOf(spec.flags()),
|
||||
return new ContentEntity(spec.type().orElse(""), spec.specialType().orElse(""), spec.reason().orElse(null),
|
||||
spec.customName().orElse(""), flagsOf(spec.flags()),
|
||||
equipmentOf(spec.equipment()), spec.passengers().stream().map(ContentServices::entityOf).toList(),
|
||||
spec.attributes().stream().map(ContentServices::attributeOf).toList(), spec.lootTables(), spec.lootShuffleSeed(),
|
||||
spec.leashHolder() == null ? null : entityOf(spec.leashHolder()), spawnEffectOf(spec.spawnEffect()),
|
||||
spec.riseOutOfGround(), spec.pandaMainGene(), spec.pandaHiddenGene(), spec.applySettingsToSpecial(),
|
||||
spec.attributes().stream().map(ContentServices::attributeOf).toList(),
|
||||
spec.lootTables().stream().map(ResourceId::path).toList(), spec.lootShuffleSeed(),
|
||||
spec.leashHolder().map(ContentServices::entityOf).orElse(null), spec.spawnEffect().map(ContentServices::spawnEffectOf).orElse(null),
|
||||
spec.riseOutOfGround(), spec.pandaMainGene().orElse(null), spec.pandaHiddenGene().orElse(null), spec.applySettingsToSpecial(),
|
||||
spec.commands().stream().map(ContentServices::commandOf).toList());
|
||||
}
|
||||
|
||||
@@ -155,16 +175,13 @@ public final class ContentServices {
|
||||
optionalItem(equipment.offHand()));
|
||||
}
|
||||
|
||||
private static ContentItem optionalItem(ItemDrop drop) {
|
||||
return drop == null ? null : itemOf(drop);
|
||||
private static ContentItem optionalItem(Optional<ItemDrop> drop) {
|
||||
return drop.map(ContentServices::itemOf).orElse(null);
|
||||
}
|
||||
|
||||
private static ContentEntity.SpawnEffect spawnEffectOf(EntitySpec.SpawnEffect effect) {
|
||||
if (effect == null) {
|
||||
return null;
|
||||
}
|
||||
return new ContentEntity.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(), effect.maxPitch(),
|
||||
effect.volume(), effect.particle(), effect.particleOffset(), effect.particleCount(), effect.altX(), effect.altY(),
|
||||
return new ContentEntity.SpawnEffect(effect.sound().orElse(null), effect.soundDistance(), effect.minPitch(), effect.maxPitch(),
|
||||
effect.volume(), effect.particle().orElse(null), effect.particleOffset(), effect.particleCount(), effect.altX(), effect.altY(),
|
||||
effect.altZ(), effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra());
|
||||
}
|
||||
|
||||
@@ -173,19 +190,20 @@ public final class ContentServices {
|
||||
}
|
||||
|
||||
private static ContentEffect effectOf(AmbientEffects.Effect effect) {
|
||||
return new ContentEffect(soundOf(effect.sound()), particlesOf(effect.particles()),
|
||||
return new ContentEffect(effect.sound().map(ContentServices::soundOf).orElse(null),
|
||||
effect.particles().map(ContentServices::particlesOf).orElse(null),
|
||||
effect.commands().stream().map(command -> new ContentEffect.Command(commandOf(command.command()),
|
||||
command.offsetX(), command.offsetY(), command.offsetZ())).toList(),
|
||||
effect.potion() == null ? null : new ContentEffect.Potion(effect.potion().key(), effect.potion().strength(), effect.potion().ticks()));
|
||||
effect.potion().map(potion -> new ContentEffect.Potion(potion.key(), potion.strength(), potion.ticks())).orElse(null));
|
||||
}
|
||||
|
||||
private static ContentEffect.Sound soundOf(AmbientEffects.Sound sound) {
|
||||
return sound == null ? null : new ContentEffect.Sound(sound.key(), sound.offsetX(), sound.offsetY(), sound.offsetZ(),
|
||||
return new ContentEffect.Sound(sound.key(), sound.offsetX(), sound.offsetY(), sound.offsetZ(),
|
||||
sound.volume(), sound.pitch());
|
||||
}
|
||||
|
||||
private static ContentEffect.Particles particlesOf(AmbientEffects.Particles particles) {
|
||||
return particles == null ? null : new ContentEffect.Particles(particles.key(), particles.forward(), particles.sideways(),
|
||||
return new ContentEffect.Particles(particles.key(), particles.forward(), particles.sideways(),
|
||||
particles.jitterX(), particles.jitterZ(), particles.lift(), particles.count(), particles.altX(), particles.altY(),
|
||||
particles.altZ(), particles.extra());
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class BiomeModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void write(ChunkStageContext context) {
|
||||
IrisChunk chunk = IrisChunk.current();
|
||||
IrisChunk chunk = context.extension(IrisChunk.class).orElseThrow();
|
||||
chunk.state(BiomeWriter.class, BiomeWriter::new).write(chunk.originX(), chunk.originZ(), chunk.biomes(), chunk.context());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.CaveBiomes;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
@@ -36,12 +38,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
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) {
|
||||
public Optional<ResourceId> overriddenBiome(PackWorld world, int x, int y, int z) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
||||
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -60,8 +62,8 @@ public final class CaveBiomeAnswers {
|
||||
|
||||
/** 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());
|
||||
Optional<ResourceId> biome = provider.overriddenBiome(world, x, y, z);
|
||||
return biome.isEmpty() ? null : overridingBiome(data.getPackResources().keyOf(PackResources.BIOMES, biome.get()));
|
||||
}
|
||||
|
||||
/** How many blocks below the surface the caves of the pack biome {@code biomeKey} begin; 0 where nothing limits them. */
|
||||
@@ -70,7 +72,7 @@ public final class CaveBiomeAnswers {
|
||||
if (depth != null) {
|
||||
return depth;
|
||||
}
|
||||
return minDepths.computeIfAbsent(biomeKey, key -> provider.minDepthBelowSurface(world, key));
|
||||
return minDepths.computeIfAbsent(biomeKey, key -> provider.minDepthBelowSurface(world, world.resources().idOf(key)));
|
||||
}
|
||||
|
||||
private IrisBiome overridingBiome(String key) {
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class CustomModule implements IrisModule {
|
||||
}
|
||||
|
||||
private static void record(ChunkStageContext context) {
|
||||
IrisChunk chunk = IrisChunk.current();
|
||||
IrisChunk chunk = context.extension(IrisChunk.class).orElseThrow();
|
||||
if (chunk.bypassesMantleStages()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 java.util.Optional;
|
||||
|
||||
/** How Iris answers IrisApi's {@code extension(type)}: what it offers for a type, when it is of that type. */
|
||||
final class HostExtensions {
|
||||
private HostExtensions() {
|
||||
}
|
||||
|
||||
/** {@code offered} as a {@code type}; empty when Iris offers nothing for the type (null) or something else. */
|
||||
static <T> Optional<T> as(Class<T> type, Object offered) {
|
||||
return type.isInstance(offered) ? Optional.of(type.cast(offered)) : Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,11 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose module stages are running: the engine, Iris's block and biome hunks and
|
||||
* the chunk's sampled context. Iris's built-in chunk stages read them through {@link #current()}, bound on the
|
||||
* generating thread while the chunk graph runs, and work on Iris's types directly; pack modules cannot see
|
||||
* the chunk's sampled context. Iris offers it as an extension of the chunk invocation, so its built-in chunk stages
|
||||
* read it with {@code context.extension(IrisChunk.class)} and work on Iris's types directly; pack modules cannot see
|
||||
* this class.
|
||||
*/
|
||||
public final class IrisChunk {
|
||||
private static final ScopedValue<IrisChunk> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private final Engine engine;
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
@@ -54,18 +52,6 @@ public final class IrisChunk {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/** The chunk generating on this thread. */
|
||||
public static IrisChunk current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris chunk is generating on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
void runBound(Runnable generation) {
|
||||
ScopedValue.where(CURRENT, this).run(generation);
|
||||
}
|
||||
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterBiomeInject;
|
||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -128,11 +129,12 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeFloating(PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement, RNG random) {
|
||||
public void placeFloating(InvocationContext context, PlaceableObject object, int worldX, int worldZ, ObjectPlacement placement,
|
||||
RNG random) {
|
||||
IrisObject placed = (IrisObject) object;
|
||||
IrisData data = engine.getData();
|
||||
IrisObjectPlacement floating = ObjectPlacements.host(placement, data).toPlacement(placed.getLoadKey());
|
||||
MantleWriter writer = IrisMantleChunk.current().writer();
|
||||
MantleWriter writer = writerOf(context);
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
placed.place(worldX, FLOATING_OBJECT_Y, worldZ, writer, floating, random, (block, state) -> writeMarker(writer, placed, id, block.getX(),
|
||||
@@ -143,20 +145,25 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeOnTop(PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
|
||||
public void placeOnTop(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||
IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeUnder(PlaceableObject object, int worldX, int y, int worldZ, int yRotation, ObjectPlacement placement,
|
||||
IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation), anchor, random,
|
||||
"inverted");
|
||||
public void placeUnder(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, int yRotation,
|
||||
ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation),
|
||||
anchor, random, "inverted");
|
||||
}
|
||||
|
||||
private static MantleWriter writerOf(InvocationContext context) {
|
||||
return context.extension(IrisMantleChunk.class).orElseThrow().writer();
|
||||
}
|
||||
|
||||
/** Places the object through a transaction that writes nothing unless every block lands where the anchor allows. */
|
||||
private void placeAgainstIsland(IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IrisObjectRotation rotation,
|
||||
IslandAnchor anchor, RNG random, String kind) {
|
||||
private void placeAgainstIsland(MantleWriter writer, IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||
IrisObjectRotation rotation, IslandAnchor anchor, RNG random, String kind) {
|
||||
IrisData data = engine.getData();
|
||||
IrisObjectPlacement anchored = ObjectPlacements.host(placement, data).toPlacement(object.getLoadKey());
|
||||
anchored.setMode(anchored.getMode().onFloatingIsland());
|
||||
@@ -166,7 +173,7 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
anchored.setBottom(false);
|
||||
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
new IslandAnchorPlacer(IrisMantleChunk.current().writer(), anchor));
|
||||
new IslandAnchorPlacer(writer, anchor));
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
int resultY = object.place(worldX, y, worldZ, transaction, anchored, random, (block, state) -> writeMarker(transaction, object, id,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockState;
|
||||
@@ -30,10 +31,11 @@ import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* One chunk of an Iris engine as an IrisApi chunk invocation: the chunk's block hunk, Iris's terrain
|
||||
* streams, the pack's module settings and the chunk's mantle, which IrisApi gives chunk stages read-only.
|
||||
* streams, the pack's module settings and the chunk's mantle, which IrisApi lets chunk stages write in their own chunk only.
|
||||
* Pack resources are the pack snapshot's, shared by every invocation of it.
|
||||
*/
|
||||
final class IrisGenerationContext implements GenerationContext {
|
||||
@@ -42,6 +44,7 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
/** The mantle too reaches this far around the chunk; chunks beyond its own are pinned when a stage first reads them. */
|
||||
private static final int MANTLE_MARGIN_BLOCKS = 16;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
|
||||
private final Engine engine;
|
||||
private final int originX;
|
||||
@@ -50,13 +53,19 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
private final IrisTerrainSampler terrain;
|
||||
private final ChunkModuleSettings settings;
|
||||
private final IrisModuleMantle mantle;
|
||||
private final IrisChunk irisChunk;
|
||||
private PackWorld world;
|
||||
|
||||
/** {@code states} convert the chunk's blocks, in the hunk and in the planned blocks of its mantle alike. */
|
||||
/**
|
||||
* {@code states} convert the chunk's blocks, in the hunk and in the planned blocks of its mantle alike;
|
||||
* {@code irisChunk} is what Iris's built-in chunk stages see of the chunk as an extension.
|
||||
*/
|
||||
IrisGenerationContext(Engine engine, int originX, int originZ, art.arcane.iris.util.project.hunk.Hunk<PlatformBlockState> blocks,
|
||||
PlatformBlockStates states, IrisModuleMantle.Chunks mantleChunks, Collection<MantleRegistration<?>> mantleLayers) {
|
||||
PlatformBlockStates states, IrisModuleMantle.Chunks mantleChunks, Collection<MantleRegistration<?>> mantleLayers,
|
||||
IrisChunk irisChunk) {
|
||||
PackResourceIds ids = new PackResourceIds(engine.getData().getDataFolder());
|
||||
this.engine = engine;
|
||||
this.irisChunk = irisChunk;
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = new BlockStateHunk(blocks, states);
|
||||
@@ -101,6 +110,17 @@ final class IrisGenerationContext implements GenerationContext {
|
||||
return (com.volmit.hunk.Hunk<T>) blocks;
|
||||
}
|
||||
|
||||
/** Iris's own view of the chunk, and the matter of its own chunk with loaded-only reads of its neighbours. */
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
if (type == IrisChunk.class) {
|
||||
return HostExtensions.as(type, irisChunk);
|
||||
}
|
||||
if (type == MatterMantle.class) {
|
||||
return HostExtensions.as(type, new OwnChunkMatter(mantle, originX >> CHUNK_SHIFT, originZ >> CHUNK_SHIFT));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
|
||||
@@ -26,13 +26,11 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Iris's own view of the chunk whose mantle stages are running: the engine, the mantle writer prepared around
|
||||
* the chunk and the generating chunk's sampled context. Iris's built-in mantle stages read them through
|
||||
* {@link #current()}, bound on the thread running the mantle graph, and write Iris's own mantle data; pack
|
||||
* modules cannot see this class.
|
||||
* the chunk and the generating chunk's sampled context. Iris offers it as an extension of the mantle invocation, so
|
||||
* its built-in mantle stages and the hosts they call read it with {@code context.extension(IrisMantleChunk.class)} and
|
||||
* write Iris's own mantle data; pack modules cannot see this class.
|
||||
*/
|
||||
public final class IrisMantleChunk {
|
||||
private static final ScopedValue<IrisMantleChunk> CURRENT = ScopedValue.newInstance();
|
||||
|
||||
private final Engine engine;
|
||||
private final MantleWriter writer;
|
||||
private final int chunkX;
|
||||
@@ -47,18 +45,6 @@ public final class IrisMantleChunk {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/** The mantle chunk whose stages run on this thread. */
|
||||
public static IrisMantleChunk current() {
|
||||
if (!CURRENT.isBound()) {
|
||||
throw new IllegalStateException("No Iris mantle chunk is generating on this thread");
|
||||
}
|
||||
return CURRENT.get();
|
||||
}
|
||||
|
||||
void runBound(Runnable generation) {
|
||||
ScopedValue.where(CURRENT, this).run(generation);
|
||||
}
|
||||
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
@@ -29,6 +30,7 @@ import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* One chunk of an Iris engine as an IrisApi mantle invocation: the mantle around the chunk as far as the
|
||||
@@ -47,12 +49,15 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
private final IrisTerrainSampler terrain;
|
||||
private final ChunkModuleSettings settings;
|
||||
private final IrisModuleMantle mantle;
|
||||
private final IrisMantleChunk irisChunk;
|
||||
private PackWorld world;
|
||||
|
||||
/** {@code irisChunk} is what Iris's built-in mantle stages see of the chunk as an extension. */
|
||||
IrisMantleGenerationContext(Engine engine, int chunkX, int chunkZ, int reachBlocks, IrisModuleMantle.Chunks chunks,
|
||||
Collection<MantleRegistration<?>> layers) {
|
||||
Collection<MantleRegistration<?>> layers, IrisMantleChunk irisChunk) {
|
||||
PackResourceIds ids = new PackResourceIds(engine.getData().getDataFolder());
|
||||
this.engine = engine;
|
||||
this.irisChunk = irisChunk;
|
||||
this.originX = chunkX << CHUNK_SHIFT;
|
||||
this.originZ = chunkZ << CHUNK_SHIFT;
|
||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, Math.max(reachBlocks, TERRAIN_MARGIN_BLOCKS));
|
||||
@@ -88,6 +93,18 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
|
||||
return mantle;
|
||||
}
|
||||
|
||||
/** Iris's own view of the chunk, and the matter of the mantle as far as the stage reaches. */
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
if (type == IrisMantleChunk.class) {
|
||||
return HostExtensions.as(type, irisChunk);
|
||||
}
|
||||
if (type == MatterMantle.class) {
|
||||
return HostExtensions.as(type, mantle);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||
@Override
|
||||
|
||||
@@ -112,8 +112,8 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new MantleCaverns(bounds, chunks);
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -262,9 +262,9 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
requireOpen();
|
||||
return new MantleCaverns(bounds, chunks);
|
||||
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,6 +45,7 @@ import art.arcane.iris.util.project.noise.NoiseType;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
@@ -117,8 +118,8 @@ final class IrisObjectHost implements ObjectHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectChunk chunk() {
|
||||
IrisMantleChunk chunk = IrisMantleChunk.current();
|
||||
public ObjectChunk chunk(InvocationContext context) {
|
||||
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||
return new IrisObjectChunk(chunk.engine(), chunk.writer(), log, this::options);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKey;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.world.PackRegion;
|
||||
@@ -52,11 +51,11 @@ import java.util.function.Supplier;
|
||||
* snapshot shares. Each load or hotload of the pack's data makes a new one, with a new {@link #snapshotId()}, and so
|
||||
* does every reload of its module resources ({@link IrisData#dump()}, {@link IrisData#invalidateStructureResources()}).
|
||||
* <p>
|
||||
* Served by the type the key asks for: {@link GeneratedObject} (a pack object, as its geometry), {@link PackBiome},
|
||||
* {@link PackRegion}, and the type of every {@link ResourceKind} the pack's modules register, read from the kind's
|
||||
* folder ({@link ModuleResourceFiles}). All use the id {@code <pack namespace>:<key>} that {@link PackResourceIds}
|
||||
* Served by kind: the host kinds {@link #OBJECTS} (a pack object, as its geometry), {@link #BIOMES} and
|
||||
* {@link #REGIONS}, and every {@link ResourceKind} the pack's modules register, read from the kind's folder
|
||||
* ({@link ModuleResourceFiles}). All use the id {@code <pack namespace>:<key>} that {@link PackResourceIds}
|
||||
* gives the pack's biomes in a biome sample, so one id can name a biome and a region. An id the pack lacks, or of
|
||||
* another namespace, is absent; any other type fails with {@link IllegalArgumentException}. A resource that exists
|
||||
* another namespace, is absent; any other kind fails with {@link IllegalArgumentException}. A resource that exists
|
||||
* but cannot be loaded fails with {@link IllegalStateException}. Each resource is built once and kept for the
|
||||
* snapshot. The module kinds are looked up the first time one is asked for, which loads the pack's modules.
|
||||
* <p>
|
||||
@@ -64,7 +63,7 @@ import java.util.function.Supplier;
|
||||
* styles through Iris's generators, expressions and image maps ({@link IrisNoiseFactory}), both kept per snapshot.
|
||||
*/
|
||||
public final class IrisPackResources implements PackResources {
|
||||
private static final String SERVED_TYPES = "GeneratedObject, PackBiome, PackRegion and the types of the pack's module resource kinds";
|
||||
private static final String SERVED_TYPES = "the host kinds (objects, biomes, regions) and the pack's module resource kinds";
|
||||
|
||||
private final IrisData data;
|
||||
private final PackResourceIds ids;
|
||||
@@ -73,9 +72,9 @@ public final class IrisPackResources implements PackResources {
|
||||
private final BlockRegistry blocks;
|
||||
private final ItemRegistry items = new IrisItemRegistry();
|
||||
private final NoiseFactory noise;
|
||||
private final Map<Class<?>, Kind<?>> irisKinds;
|
||||
private final Map<ResourceId, Kind<?>> irisKinds;
|
||||
private final Supplier<List<ResourceKind<?>>> moduleKindList;
|
||||
private volatile Map<Class<?>, Kind<?>> moduleKinds;
|
||||
private volatile Map<ResourceId, Kind<?>> moduleKinds;
|
||||
private volatile List<String> moduleFolders;
|
||||
private boolean announcedToModules;
|
||||
|
||||
@@ -93,9 +92,9 @@ public final class IrisPackResources implements PackResources {
|
||||
this.blocks = new IrisBlockRegistry(data);
|
||||
this.noise = new IrisNoiseFactory(data);
|
||||
this.irisKinds = Map.of(
|
||||
GeneratedObject.class, Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
||||
PackBiome.class, Kind.<IrisBiome, PackBiome>ofLoader(ids, data::getBiomeLoader, this::biomeOf),
|
||||
PackRegion.class, Kind.<IrisRegion, PackRegion>ofLoader(ids, data::getRegionLoader, this::regionOf));
|
||||
OBJECTS.id(), Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
||||
BIOMES.id(), Kind.<IrisBiome, PackBiome>ofLoader(ids, data::getBiomeLoader, this::biomeOf),
|
||||
REGIONS.id(), Kind.<IrisRegion, PackRegion>ofLoader(ids, data::getRegionLoader, this::regionOf));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,14 +140,14 @@ public final class IrisPackResources implements PackResources {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // The kinds are keyed by the type they serve.
|
||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
||||
return ((Kind<T>) kindOf(key.type())).find(key.id());
|
||||
@SuppressWarnings("unchecked") // A kind's id names the one kind registered under it, which serves the kind's type.
|
||||
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||
return ((Kind<T>) kindOf(kind)).find(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceId> ids(Class<?> type) {
|
||||
return kindOf(type).ids();
|
||||
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||
return kindOf(kind).ids();
|
||||
}
|
||||
|
||||
/** The id of the resource the pack names by {@code packKey}, such as {@code overworld:castle/keep} for {@code castle/keep}. */
|
||||
@@ -167,27 +166,27 @@ public final class IrisPackResources implements PackResources {
|
||||
return folders;
|
||||
}
|
||||
|
||||
private Kind<?> kindOf(Class<?> type) {
|
||||
Kind<?> iris = irisKinds.get(type);
|
||||
private Kind<?> kindOf(ResourceKind<?> kind) {
|
||||
Kind<?> iris = irisKinds.get(kind.id());
|
||||
if (iris != null) {
|
||||
return iris;
|
||||
}
|
||||
Kind<?> module = moduleKinds().get(type);
|
||||
Kind<?> module = moduleKinds().get(kind.id());
|
||||
if (module == null) {
|
||||
throw new IllegalArgumentException("Iris serves pack resources of " + SERVED_TYPES + ", not " + type.getName());
|
||||
throw new IllegalArgumentException("Iris serves pack resources of " + SERVED_TYPES + ", not " + kind.id());
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
private Map<Class<?>, Kind<?>> moduleKinds() {
|
||||
Map<Class<?>, Kind<?>> kinds = moduleKinds;
|
||||
private Map<ResourceId, Kind<?>> moduleKinds() {
|
||||
Map<ResourceId, Kind<?>> kinds = moduleKinds;
|
||||
if (kinds != null) {
|
||||
return kinds;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (moduleKinds == null) {
|
||||
Map<Class<?>, Kind<?>> found = new HashMap<>();
|
||||
moduleKindList.get().forEach(kind -> found.put(kind.type(), moduleKind(kind)));
|
||||
Map<ResourceId, Kind<?>> found = new HashMap<>();
|
||||
moduleKindList.get().forEach(kind -> found.put(kind.id(), moduleKind(kind)));
|
||||
moduleKinds = Map.copyOf(found);
|
||||
}
|
||||
return moduleKinds;
|
||||
@@ -201,10 +200,24 @@ public final class IrisPackResources implements PackResources {
|
||||
|
||||
/** Iris's own biome that {@code id}, as a {@code BiomeSample} gives it, names; for host code that reads what the biome declares. */
|
||||
Optional<IrisBiome> irisBiome(ResourceId id) {
|
||||
String key = irisKinds.get(PackBiome.class).keyOf(id);
|
||||
String key = irisKinds.get(BIOMES.id()).keyOf(id);
|
||||
return key == null ? Optional.empty() : Optional.ofNullable(data.getBiomeLoader().load(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* The key Iris's own code names {@code id} by, a resource of {@code kind}: the pack key that has the id, else the
|
||||
* id's path when it is of the pack's namespace, else the id as written ({@code minecraft:village}).
|
||||
*/
|
||||
public String keyOf(ResourceKind<?> kind, ResourceId id) {
|
||||
String key = kindOf(kind).keyOf(id);
|
||||
return key == null ? keyOf(id) : key;
|
||||
}
|
||||
|
||||
/** The key Iris's own code names {@code id} by when no index of keys is at hand: its path in the pack's namespace, else the id as written. */
|
||||
public String keyOf(ResourceId id) {
|
||||
return id.namespace().equals(ids.namespace()) ? id.path() : id.toString();
|
||||
}
|
||||
|
||||
private PackBiome biomeOf(ResourceId id, IrisBiome biome) {
|
||||
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
|
||||
biome.getRarity(), idsOf(biome.getChildren()));
|
||||
|
||||
@@ -36,13 +36,15 @@ import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The settings an engine's pack declares, for working out mantle stage reaches when the pack loads and for vanilla
|
||||
* structure hooks: the engine's dimension, then every region it can reach, then every biome. Iris's built-in modules
|
||||
* decide from Iris's own pack data instead of module settings; they reach the engine through {@link #of(PackSettings)}.
|
||||
* decide from Iris's own pack data instead of module settings; they reach it through the object, floating and structure
|
||||
* hosts the settings offer as {@linkplain #extension extensions}.
|
||||
*/
|
||||
public final class IrisPackSettings implements PackSettings, ObjectHost.Source, FloatingHost.Source, StructureHost.Source {
|
||||
public final class IrisPackSettings implements PackSettings {
|
||||
static final String DIMENSION = "dimension";
|
||||
static final String REGION = "region";
|
||||
static final String BIOME = "biome";
|
||||
@@ -55,32 +57,31 @@ public final class IrisPackSettings implements PackSettings, ObjectHost.Source,
|
||||
this.ids = new PackResourceIds(engine.getData().getDataFolder());
|
||||
}
|
||||
|
||||
/** Iris's own view of {@code settings}, which Iris hands to every reach it works out. */
|
||||
public static IrisPackSettings of(PackSettings settings) {
|
||||
if (!(settings instanceof IrisPackSettings irisSettings)) {
|
||||
throw new IllegalArgumentException("Built-in modules read an Iris engine's pack, not " + settings);
|
||||
}
|
||||
return irisSettings;
|
||||
}
|
||||
|
||||
/** The engine whose pack is loading. */
|
||||
public Engine engine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHost objects() {
|
||||
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return HostExtensions.as(type, offered(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureHost structures() {
|
||||
return new IrisStructureHost(engine, IrisApiLogger.hostLog());
|
||||
/** The engine is offered only for the structure built-ins, which drive Iris's structure locator themselves. */
|
||||
private Object offered(Class<?> type) {
|
||||
if (type == Engine.class) {
|
||||
return engine;
|
||||
}
|
||||
if (type == ObjectHost.class) {
|
||||
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
if (type == FloatingHost.class) {
|
||||
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
if (type == StructureHost.class) {
|
||||
return new IrisStructureHost(engine, IrisApiLogger.hostLog());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeed;
|
||||
import art.arcane.iris.builtin.IrisSeeds;
|
||||
import art.arcane.iris.builtin.LiveWorld;
|
||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||
import art.arcane.iris.builtin.structure.StructureHost;
|
||||
@@ -29,47 +30,33 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.world.PackWorld;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* One Iris world as modules see it: an engine runtime generating with one snapshot of its pack's resources, and the
|
||||
* state modules keep for it. {@link ModuleWorlds} makes one when the runtime is built and a new one whenever the
|
||||
* 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}.
|
||||
* pack's resources reload under it. Iris's built-in modules reach what they need of Iris through its
|
||||
* {@linkplain #extension extensions}: the world's seeds, its live view and the object, floating and structure hosts.
|
||||
*/
|
||||
public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorld.Source, ObjectHost.Source, FloatingHost.Source, StructureHost.Source {
|
||||
public final class IrisPackWorld implements PackWorld {
|
||||
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;
|
||||
private final IrisSeeds seeds;
|
||||
private volatile IrisObjectHost objectHost;
|
||||
private volatile IrisFloatingHost floatingHost;
|
||||
private volatile IrisStructureHost structureHost;
|
||||
|
||||
IrisPackWorld(Engine engine) {
|
||||
this(engine, engine.getData().getPackResources(), new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private IrisPackWorld(Engine engine, IrisPackResources resources, WorldStates states, ModuleLog log,
|
||||
Map<ModuleLog, IrisPackWorld> viewsByLog) {
|
||||
this.engine = engine;
|
||||
this.resources = resources;
|
||||
this.states = states;
|
||||
this.log = log;
|
||||
this.viewsByLog = viewsByLog;
|
||||
this.resources = engine.getData().getPackResources();
|
||||
this.states = new WorldStates();
|
||||
this.log = IrisApiLogger.hostLog();
|
||||
this.liveWorld = new IrisLiveWorld(engine, resources);
|
||||
}
|
||||
|
||||
/** Iris's own view of {@code world}, which Iris hands to every stage, service and lifecycle hook. */
|
||||
public static IrisPackWorld of(PackWorld world) {
|
||||
if (!(world instanceof IrisPackWorld irisWorld)) {
|
||||
throw new IllegalArgumentException("Built-in modules work in worlds Iris generates, not " + world);
|
||||
}
|
||||
return irisWorld;
|
||||
this.seeds = this::seedOf;
|
||||
}
|
||||
|
||||
/** The engine generating this world. */
|
||||
@@ -107,19 +94,35 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
||||
return log;
|
||||
}
|
||||
|
||||
/** One view per log, since the services ask for a module's view on every call. */
|
||||
@Override
|
||||
public IrisPackWorld withLog(ModuleLog log) {
|
||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return HostExtensions.as(type, offered(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveWorld liveWorld() {
|
||||
return liveWorld;
|
||||
/** The engine is offered only for the structure built-ins, which drive Iris's structure locator themselves. */
|
||||
private Object offered(Class<?> type) {
|
||||
if (type == Engine.class) {
|
||||
return engine;
|
||||
}
|
||||
if (type == IrisSeeds.class) {
|
||||
return seeds;
|
||||
}
|
||||
if (type == LiveWorld.class) {
|
||||
return liveWorld;
|
||||
}
|
||||
if (type == ObjectHost.class) {
|
||||
return objects();
|
||||
}
|
||||
if (type == FloatingHost.class) {
|
||||
return floating();
|
||||
}
|
||||
if (type == StructureHost.class) {
|
||||
return structures();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long seed(IrisSeed seed) {
|
||||
private long seedOf(IrisSeed seed) {
|
||||
SeedManager seeds = engine.getSeedManager();
|
||||
return switch (seed) {
|
||||
case BIOME -> seeds.getBiome();
|
||||
@@ -136,8 +139,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHost objects() {
|
||||
private ObjectHost objects() {
|
||||
IrisObjectHost host = objectHost;
|
||||
if (host == null) {
|
||||
host = new IrisObjectHost(engine, log);
|
||||
@@ -146,8 +148,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloatingHost floating() {
|
||||
private FloatingHost floating() {
|
||||
IrisFloatingHost host = floatingHost;
|
||||
if (host == null) {
|
||||
host = new IrisFloatingHost(engine, log);
|
||||
@@ -156,8 +157,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureHost structures() {
|
||||
private StructureHost structures() {
|
||||
IrisStructureHost host = structureHost;
|
||||
if (host == null) {
|
||||
host = new IrisStructureHost(engine, log);
|
||||
|
||||
@@ -43,12 +43,11 @@ import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.BlockPosition;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Iris's own inputs of the object placement being run: the placement settings, object, placer and cave that IrisApi
|
||||
* does not describe, answered to Iris's built-in placement stages as an {@link ObjectPlacement}, bound on the placing
|
||||
* thread while the placement graph runs. Pack modules cannot see this class.
|
||||
* does not describe, answered to Iris's built-in placement stages as an {@link ObjectPlacement}, the extension of the
|
||||
* placement invocation. Pack modules cannot see this class.
|
||||
*/
|
||||
public final class IrisPlacement implements ObjectPlacement {
|
||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
||||
@@ -87,9 +86,6 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
this.terrain = new IrisPlacementTerrain(placer, object.getLoader(), data, states);
|
||||
}
|
||||
|
||||
<T> T runBound(Supplier<T> placement) {
|
||||
return ObjectPlacement.runBound(this, placement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectShape object() {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
@@ -30,6 +31,7 @@ import com.volmit.world.TerrainSample;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -40,14 +42,25 @@ final class IrisPlacementInputs implements PlacementContext {
|
||||
private final FeatureSettings settings;
|
||||
private final BlockView blocks;
|
||||
private final Supplier<PackWorld> worldSource;
|
||||
private final ObjectPlacement placement;
|
||||
private PackWorld world;
|
||||
|
||||
/** @param worldSource the world the placement generates in, asked for the first time a stage needs it */
|
||||
IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, BlockView blocks, Supplier<PackWorld> worldSource) {
|
||||
/**
|
||||
* @param worldSource the world the placement generates in, asked for the first time a stage needs it
|
||||
* @param placement what Iris's built-in placement stages see of the placement as an extension
|
||||
*/
|
||||
IrisPlacementInputs(TerrainSampler terrain, FeatureSettings settings, BlockView blocks, Supplier<PackWorld> worldSource,
|
||||
ObjectPlacement placement) {
|
||||
this.terrain = terrain;
|
||||
this.settings = settings;
|
||||
this.blocks = blocks;
|
||||
this.worldSource = worldSource;
|
||||
this.placement = placement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> extension(Class<T> type) {
|
||||
return type == ObjectPlacement.class ? HostExtensions.as(type, placement) : Optional.empty();
|
||||
}
|
||||
|
||||
/** The world of the engine's runtime, as it is when the placement first asks. */
|
||||
|
||||
@@ -22,6 +22,7 @@ import art.arcane.iris.builtin.structure.StructureHost;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
|
||||
/** Iris's {@link StructureHost}: the engine's {@link StructurePlacing}, one per engine runtime, places and sizes its structures. */
|
||||
final class IrisStructureHost implements StructureHost {
|
||||
@@ -34,8 +35,8 @@ final class IrisStructureHost implements StructureHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void placeChunk() {
|
||||
IrisMantleChunk chunk = IrisMantleChunk.current();
|
||||
public void placeChunk(InvocationContext context) {
|
||||
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||
placing().place(chunk.writer(), chunk.chunkX(), chunk.chunkZ(), chunk.context());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,31 +15,22 @@
|
||||
* 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.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.BlockBox;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.mantle.MantleVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#caverns()}: where the cave
|
||||
* planner marked a cavern in the mantle's cavern slice, whatever the cavern holds (air, fluid, lava). Stages only read them.
|
||||
* The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#isCarved}: where the
|
||||
* cave planner marked a cavern in the mantle's cavern slice, whatever the cavern holds (air, fluid, lava).
|
||||
*/
|
||||
final class MantleCaverns implements MantleLayer<Boolean> {
|
||||
final class MantleCaverns {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int SECTION_SHIFT = 4;
|
||||
private static final int LOCAL_MASK = 15;
|
||||
private static final String READ_ONLY = "Stages read the caverns; the cave planner writes them";
|
||||
private static final Comparator<Position> VISIT_ORDER = Comparator.comparingInt(Position::x)
|
||||
.thenComparingInt(Position::y).thenComparingInt(Position::z);
|
||||
|
||||
private final BlockBox bounds;
|
||||
private final IrisModuleMantle.Chunks chunks;
|
||||
@@ -49,58 +40,9 @@ final class MantleCaverns implements MantleLayer<Boolean> {
|
||||
this.chunks = chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean get(int x, int y, int z) {
|
||||
boolean isCarved(int x, int y, int z) {
|
||||
requireInside(x, y, z);
|
||||
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z) ? Boolean.TRUE : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
|
||||
Objects.requireNonNull(visitor, "visitor");
|
||||
requireInside(area);
|
||||
for (Position carved : carvedIn(area)) {
|
||||
visitor.accept(carved.x(), carved.y(), carved.z(), Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, Boolean value) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(int x, int y, int z) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(BlockBox area) {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
}
|
||||
|
||||
/** The carved positions in {@code area}, ordered by x, then y, then z, as {@link MantleLayer#visit} promises. */
|
||||
private List<Position> carvedIn(BlockBox area) {
|
||||
List<Position> carved = new ArrayList<>();
|
||||
for (int chunkX = area.minX() >> CHUNK_SHIFT; chunkX <= (area.maxX() - 1) >> CHUNK_SHIFT; chunkX++) {
|
||||
for (int chunkZ = area.minZ() >> CHUNK_SHIFT; chunkZ <= (area.maxZ() - 1) >> CHUNK_SHIFT; chunkZ++) {
|
||||
collect(chunkX, chunkZ, area, carved);
|
||||
}
|
||||
}
|
||||
carved.sort(VISIT_ORDER);
|
||||
return carved;
|
||||
}
|
||||
|
||||
private void collect(int chunkX, int chunkZ, BlockBox area, List<Position> carved) {
|
||||
int originX = chunkX << CHUNK_SHIFT;
|
||||
int originZ = chunkZ << CHUNK_SHIFT;
|
||||
requireChunk(chunkX, chunkZ).iterate(MatterCavern.class, (localX, y, localZ, cavern) -> {
|
||||
int x = originX + localX;
|
||||
int z = originZ + localZ;
|
||||
if (cavern != null && area.contains(x, y, z)) {
|
||||
carved.add(new Position(x, y, z));
|
||||
}
|
||||
});
|
||||
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z);
|
||||
}
|
||||
|
||||
private static boolean cavernAt(MantleChunk<Matter> chunk, int x, int y, int z) {
|
||||
@@ -128,14 +70,4 @@ final class MantleCaverns implements MantleLayer<Boolean> {
|
||||
throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the mantle this invocation prepared, " + bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private void requireInside(BlockBox area) {
|
||||
Objects.requireNonNull(area, "area");
|
||||
if (!bounds.contains(area)) {
|
||||
throw new IndexOutOfBoundsException("Area " + area + " is not inside the mantle this invocation prepared, " + bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private record Position(int x, int y, int z) {
|
||||
}
|
||||
}
|
||||
@@ -61,10 +61,10 @@ public final class ModuleChunkGeneration {
|
||||
int chunkZ = z >> CHUNK_SHIFT;
|
||||
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), chunkX, chunkZ);
|
||||
try (PinnedMantleChunks mantle = new PinnedMantleChunks(engine)) {
|
||||
IrisChunk irisChunk = new IrisChunk(engine, x, z, blocks, biomes, multicore, context);
|
||||
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z, blocks, new PlatformBlockStates(platformStates), mantle,
|
||||
pack.catalog().mantle());
|
||||
StageMetrics metrics = new StageMetrics(engine.getMetrics());
|
||||
new IrisChunk(engine, x, z, blocks, biomes, multicore, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed, metrics));
|
||||
pack.catalog().mantle(), irisChunk);
|
||||
new ChunkRunner(chunk).generate(inputs, seed, new StageMetrics(engine.getMetrics()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,12 +112,16 @@ public final class ModuleMantleComponent implements MantleComponent {
|
||||
|
||||
@Override
|
||||
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||
new IrisMantleChunk(engine, writer, x, z, context).runBound(() -> generate(x, z, writer::acquireChunk));
|
||||
generate(x, z, writer::acquireChunk, new IrisMantleChunk(engine, writer, x, z, context));
|
||||
}
|
||||
|
||||
/** Runs the stage for chunk {@code x}, {@code z}, with the mantle chunks within the stage's reach of it. */
|
||||
void generate(int x, int z, IrisModuleMantle.Chunks chunks) {
|
||||
IrisMantleGenerationContext inputs = new IrisMantleGenerationContext(engine, x, z, reachBlocks, chunks, pack.catalog().mantle());
|
||||
/**
|
||||
* Runs the stage for chunk {@code x}, {@code z}, with the mantle chunks within the stage's reach of it and
|
||||
* {@code irisChunk} as Iris's own view of the chunk.
|
||||
*/
|
||||
void generate(int x, int z, IrisModuleMantle.Chunks chunks, IrisMantleChunk irisChunk) {
|
||||
IrisMantleGenerationContext inputs = new IrisMantleGenerationContext(engine, x, z, reachBlocks, chunks, pack.catalog().mantle(),
|
||||
irisChunk);
|
||||
runner.generate(stage.stage(), inputs, ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x, z),
|
||||
new StageMetrics(engine.getMetrics()));
|
||||
}
|
||||
|
||||
@@ -90,9 +90,10 @@ public final class ModuleObjectPlacement {
|
||||
try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) {
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area),
|
||||
new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source),
|
||||
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld);
|
||||
PlacementOutcome outcome = placement.runBound(() -> new PlacementRunner(graph)
|
||||
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics));
|
||||
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld,
|
||||
placement);
|
||||
PlacementOutcome outcome = new PlacementRunner(graph)
|
||||
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics);
|
||||
return outcome.isPlaced()
|
||||
? ObjectPlacementResult.placed(placement.anchorY())
|
||||
: ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.ServiceRegistration;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.service.BlockDrops;
|
||||
@@ -98,23 +99,30 @@ public final class ModuleServices {
|
||||
|
||||
/** The objects every module would place in the chunk at {@code chunkX}, {@code chunkZ}, guessed without generating it. */
|
||||
public static Set<String> objectsAt(Engine engine, int chunkX, int chunkZ) {
|
||||
IrisPackResources resources = engine.getData().getPackResources();
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
|
||||
keys.addAll(provider.service().objectsAt(provider.world(), chunkX, chunkZ));
|
||||
provider.service().objectsAt(provider.world(), chunkX, chunkZ).forEach(id -> keys.add(resources.keyOf(PackResources.OBJECTS, id)));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** The biomes and regions of the engine's layout that every module says place the object {@code objectKey}. */
|
||||
public static ObjectsAt.PlacedBy objectPlacers(Engine engine, String objectKey) {
|
||||
/** The keys of the biomes and regions of the engine's layout that every module says place the object {@code objectKey}. */
|
||||
public static ObjectPlacers objectPlacers(Engine engine, String objectKey) {
|
||||
IrisPackResources resources = engine.getData().getPackResources();
|
||||
ResourceId object = resources.idOf(objectKey);
|
||||
Set<String> biomes = new LinkedHashSet<>();
|
||||
Set<String> regions = new LinkedHashSet<>();
|
||||
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
|
||||
ObjectsAt.PlacedBy placedBy = provider.service().placedBy(provider.world(), objectKey);
|
||||
biomes.addAll(placedBy.biomes());
|
||||
regions.addAll(placedBy.regions());
|
||||
ObjectsAt.PlacedBy placedBy = provider.service().placedBy(provider.world(), object);
|
||||
placedBy.biomes().forEach(id -> biomes.add(resources.keyOf(PackResources.BIOMES, id)));
|
||||
placedBy.regions().forEach(id -> regions.add(resources.keyOf(PackResources.REGIONS, id)));
|
||||
}
|
||||
return new ObjectsAt.PlacedBy(biomes, regions);
|
||||
return new ObjectPlacers(biomes, regions);
|
||||
}
|
||||
|
||||
/** The keys of the biomes and regions that place an object. */
|
||||
public record ObjectPlacers(Set<String> biomes, Set<String> regions) {
|
||||
}
|
||||
|
||||
/** The loot tables the modules say the container at {@code site} draws from, in module order. */
|
||||
@@ -126,11 +134,11 @@ public final class ModuleServices {
|
||||
return tables;
|
||||
}
|
||||
|
||||
/** The items loot table {@code key} gives at {@code site}, from the module that knows the table. */
|
||||
public static List<ItemDrop> lootItems(Engine engine, Loot.Site site, String key) {
|
||||
/** The items loot table {@code table} gives at {@code site}, from the module that knows the table. */
|
||||
public static List<ItemDrop> lootItems(Engine engine, Loot.Site site, ResourceId table) {
|
||||
List<ItemDrop> items = new ArrayList<>();
|
||||
for (Provider<Loot> provider : providers(engine, Loot.class)) {
|
||||
items.addAll(provider.service().items(provider.world(), site, key));
|
||||
items.addAll(provider.service().items(provider.world(), site, table));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
@@ -160,8 +168,8 @@ public final class ModuleServices {
|
||||
|
||||
/** The objects every module places as trees. */
|
||||
public static SaplingGrowth.TreeObjects treeObjects(Engine engine) {
|
||||
Set<String> objects = new LinkedHashSet<>();
|
||||
Set<String> procedural = new LinkedHashSet<>();
|
||||
Set<ResourceId> objects = new LinkedHashSet<>();
|
||||
Set<ResourceId> procedural = new LinkedHashSet<>();
|
||||
for (Provider<SaplingGrowth> provider : providers(engine, SaplingGrowth.class)) {
|
||||
SaplingGrowth.TreeObjects trees = provider.service().treeObjects(provider.world());
|
||||
objects.addAll(trees.objects());
|
||||
@@ -181,10 +189,11 @@ public final class ModuleServices {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/** The entity {@code key} as the first module that knows it would spawn it. */
|
||||
/** The entity the pack names {@code key} as the first module that knows it would spawn it. */
|
||||
public static Optional<EntitySpec> entity(Engine engine, String key) {
|
||||
ResourceId id = engine.getData().getPackResources().idOf(key);
|
||||
for (Provider<EntitySpawns> provider : providers(engine, EntitySpawns.class)) {
|
||||
Optional<EntitySpec> entity = provider.service().entity(provider.world(), key);
|
||||
Optional<EntitySpec> entity = provider.service().entity(provider.world(), id);
|
||||
if (entity.isPresent()) {
|
||||
return entity;
|
||||
}
|
||||
@@ -223,7 +232,7 @@ public final class ModuleServices {
|
||||
public static Set<String> structureKeys(IrisData data) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (StructureLocator provider : catalog(data).services(StructureLocator.class)) {
|
||||
keys.addAll(provider.structures(data.getPackResources()));
|
||||
keys.addAll(structureKeysOf(data, provider.structures(data.getPackResources())));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
@@ -232,7 +241,7 @@ public final class ModuleServices {
|
||||
public static Set<String> locatableStructures(Engine engine) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
keys.addAll(provider.service().locatable(provider.world()));
|
||||
keys.addAll(structureKeysOf(engine.getData(), provider.service().locatable(provider.world())));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
@@ -249,7 +258,7 @@ public final class ModuleServices {
|
||||
public static Set<String> placedStructures(Engine engine) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
keys.addAll(provider.service().placed(provider.world()));
|
||||
keys.addAll(structureKeysOf(engine.getData(), provider.service().placed(provider.world())));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
@@ -265,7 +274,8 @@ public final class ModuleServices {
|
||||
*/
|
||||
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||
LocateResult result = structureLocatorOf(engine, key, StructureLocator::placed)
|
||||
.map(provider -> provider.service().locate(provider.world(), key, fromX, fromZ, maxRadiusChunks))
|
||||
.map(provider -> provider.service().locate(provider.world(), structureIdOf(engine.getData(), key), fromX, fromZ,
|
||||
maxRadiusChunks))
|
||||
.orElse(LocateResult.NOT_FOUND);
|
||||
return StructureSearch.of(result, engine);
|
||||
}
|
||||
@@ -339,21 +349,41 @@ public final class ModuleServices {
|
||||
}
|
||||
}
|
||||
|
||||
/** The first provider, in the catalog's order, whose structures of the kind {@code keys} lists hold {@code key}. */
|
||||
/** The first provider, in the catalog's order, whose structures of the kind {@code structures} lists hold {@code key}. */
|
||||
private static Optional<Provider<StructureLocator>> structureLocatorOf(Engine engine, String key,
|
||||
BiFunction<StructureLocator, PackWorld, Set<String>> keys) {
|
||||
BiFunction<StructureLocator, PackWorld, Set<ResourceId>> structures) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String wanted = normalized(key);
|
||||
ResourceId wanted = structureIdOf(engine.getData(), key);
|
||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
||||
if (keys.apply(provider.service(), provider.world()).stream().map(ModuleServices::normalized).anyMatch(wanted::equals)) {
|
||||
if (structures.apply(provider.service(), provider.world()).contains(wanted)) {
|
||||
return Optional.of(provider);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The id of the structure Iris's commands name {@code key}: a key with a namespace is that id
|
||||
* ({@code minecraft:village}), any other a structure of the pack. Ids are lower case, so keys match without regard
|
||||
* to case.
|
||||
*/
|
||||
private static ResourceId structureIdOf(IrisData data, String key) {
|
||||
String trimmed = key.trim();
|
||||
return trimmed.indexOf(':') >= 0 ? ResourceId.parse(normalized(trimmed)) : data.getPackResources().idOf(trimmed);
|
||||
}
|
||||
|
||||
/** The keys Iris's commands show for {@code structures}: a pack structure by its path, any other by its id. */
|
||||
private static Set<String> structureKeysOf(IrisData data, Set<ResourceId> structures) {
|
||||
IrisPackResources resources = data.getPackResources();
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (ResourceId structure : structures) {
|
||||
keys.add(resources.keyOf(structure));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/** The platform structures every provider lists with {@code structures}, as lower-case registry keys. */
|
||||
private static Set<String> platformStructures(Engine engine, BiFunction<VanillaStructures, PackWorld, Set<ResourceId>> structures) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.host.ConfiguredSettings;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -60,21 +61,24 @@ public final class ModuleSettings {
|
||||
return values.isEmpty();
|
||||
}
|
||||
|
||||
/** The biomes these settings add to the biome tree of the owner's regions ({@link LinkedBiomes#treeBiomes}), in a fixed order. */
|
||||
public Set<String> treeBiomes() {
|
||||
return linkedBiomes(LinkedBiomes::treeBiomes);
|
||||
/**
|
||||
* The keys of the biomes these settings add to the biome tree of the owner's regions ({@link LinkedBiomes#treeBiomes}),
|
||||
* in a fixed order.
|
||||
*/
|
||||
public Set<String> treeBiomes(IrisPackResources resources) {
|
||||
return linkedBiomes(resources, linked -> linked.treeBiomes(resources));
|
||||
}
|
||||
|
||||
/**
|
||||
* The biomes these settings use besides ({@link LinkedBiomes#usedBiomes}), in a fixed order.
|
||||
* The keys of the biomes these settings use besides ({@link LinkedBiomes#usedBiomes}), in a fixed order.
|
||||
*
|
||||
* @param dimension the settings of the dimension the owner is part of
|
||||
*/
|
||||
public Set<String> usedBiomes(ModuleSettings dimension) {
|
||||
return linkedBiomes(linked -> linked.usedBiomes(dimension.values()));
|
||||
public Set<String> usedBiomes(IrisPackResources resources, ModuleSettings dimension) {
|
||||
return linkedBiomes(resources, linked -> linked.usedBiomes(resources, dimension.values()));
|
||||
}
|
||||
|
||||
private Set<String> linkedBiomes(Function<LinkedBiomes, Set<String>> pick) {
|
||||
private Set<String> linkedBiomes(IrisPackResources resources, Function<LinkedBiomes, Set<ResourceId>> pick) {
|
||||
if (values.isEmpty()) {
|
||||
return Set.of();
|
||||
}
|
||||
@@ -82,7 +86,7 @@ public final class ModuleSettings {
|
||||
values.values().stream()
|
||||
.filter(LinkedBiomes.class::isInstance)
|
||||
.sorted(Comparator.comparing(value -> value.getClass().getName()))
|
||||
.forEach(value -> biomes.addAll(pick.apply((LinkedBiomes) value)));
|
||||
.forEach(value -> pick.apply((LinkedBiomes) value).forEach(id -> biomes.add(resources.keyOf(PackResources.BIOMES, id))));
|
||||
return biomes;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,11 +34,11 @@ import com.google.gson.stream.JsonWriter;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.config.OptionsMetadata;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.FeatureDescriptor;
|
||||
import com.volmit.host.ObjectRegistration;
|
||||
import com.volmit.host.OptionsMetadata;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -83,9 +83,10 @@ public final class ModuleSettingsDecoder {
|
||||
ModuleSettingsDecoder(FeatureCatalog catalog, Path packFolder, Supplier<Gson> irisGson) {
|
||||
this.packFolder = packFolder;
|
||||
this.irisGson = irisGson;
|
||||
PackResourceIds packIds = new PackResourceIds(packFolder.toFile());
|
||||
this.gson = new GsonBuilder()
|
||||
.registerTypeAdapter(BlockState.class, textAdapter(BlockState::parse, BlockState::key))
|
||||
.registerTypeAdapter(ResourceId.class, textAdapter(ResourceId::parse, ResourceId::toString))
|
||||
.registerTypeAdapter(ResourceId.class, textAdapter(text -> resourceIdOf(packIds, text), ResourceId::toString))
|
||||
.registerTypeAdapterFactory(new HostTypes())
|
||||
.registerTypeAdapterFactory(new SnippetReferences())
|
||||
.create();
|
||||
@@ -95,6 +96,11 @@ public final class ModuleSettingsDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
/** A resource id as written: {@code namespace:path}, or a pack key such as {@code desert/dunes}, which names a resource of the pack. */
|
||||
private static ResourceId resourceIdOf(PackResourceIds packIds, String text) {
|
||||
return text.indexOf(':') >= 0 ? ResourceId.parse(text) : packIds.of(text);
|
||||
}
|
||||
|
||||
/** Every JSON key the pack's modules read at {@code target}: the keys of their features, object generators' included. */
|
||||
public Set<String> keys(Level target) {
|
||||
return keys.get(target);
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.VanillaStructures;
|
||||
import com.volmit.vanilla.DecorationStep;
|
||||
import com.volmit.vanilla.PieceKind;
|
||||
import com.volmit.vanilla.StartKey;
|
||||
import com.volmit.vanilla.StartMemo;
|
||||
import com.volmit.vanilla.StructureFit;
|
||||
import com.volmit.vanilla.TemplateCells;
|
||||
@@ -51,12 +52,14 @@ import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -66,6 +69,8 @@ import java.util.function.Supplier;
|
||||
* states and back through caches, so a provider can read and write blocks without allocating per block.
|
||||
*/
|
||||
public final class ModuleStructureFitting implements NativeStructureFitting {
|
||||
/** One key per platform start for as long as the platform keeps the start, so a start fitted in many chunks is known again. */
|
||||
private static final Map<Object, StartKey> START_KEYS = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
private static final Map<Object, BlockState> API_STATES = new ConcurrentHashMap<>();
|
||||
private static final Map<BlockState, Object> NATIVE_STATES = new ConcurrentHashMap<>();
|
||||
private static final Map<Object, Integer> NATIVE_TRAITS = new ConcurrentHashMap<>();
|
||||
@@ -360,8 +365,8 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object key() {
|
||||
return start.key();
|
||||
public StartKey key() {
|
||||
return START_KEYS.computeIfAbsent(start.key(), ignored -> StartKey.create());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.MatterMantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
/**
|
||||
* The matter mantle of a chunk invocation: its own chunk, which a chunk stage writes as it writes the mantle layers of
|
||||
* its own chunk, and its neighbours only as far as the world already holds them in memory.
|
||||
*/
|
||||
final class OwnChunkMatter implements MatterMantle {
|
||||
private final MatterMantle mantle;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
|
||||
OwnChunkMatter(MatterMantle mantle, int chunkX, int chunkZ) {
|
||||
this.mantle = mantle;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> chunk(int chunkX, int chunkZ) {
|
||||
if (chunkX != this.chunkX || chunkZ != this.chunkZ) {
|
||||
return null;
|
||||
}
|
||||
return mantle.chunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
|
||||
return mantle.loadedChunk(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
@@ -71,8 +71,11 @@ final class PlacementMantle implements Mantle, AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new StoredRange<>(placement.caverns());
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
if (!bounds.contains(x, y, z)) {
|
||||
throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the placement area " + bounds);
|
||||
}
|
||||
return y >= storedBounds.minY() && y < storedBounds.maxY() && placement.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,8 +24,6 @@ import com.volmit.host.WorldStates;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -39,20 +37,13 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
private final PackSettings settings;
|
||||
private final WorldStates states;
|
||||
private final ModuleLog log;
|
||||
private final Map<ModuleLog, ToolWorld> viewsByLog;
|
||||
|
||||
ToolWorld(long seed, PackResources resources, PackSettings settings) {
|
||||
this(seed, resources, settings, new WorldStates(), IrisApiLogger.hostLog(), new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private ToolWorld(long seed, PackResources resources, PackSettings settings, WorldStates states, ModuleLog log,
|
||||
Map<ModuleLog, ToolWorld> viewsByLog) {
|
||||
this.seed = seed;
|
||||
this.resources = resources;
|
||||
this.settings = settings;
|
||||
this.states = states;
|
||||
this.log = log;
|
||||
this.viewsByLog = viewsByLog;
|
||||
this.states = new WorldStates();
|
||||
this.log = IrisApiLogger.hostLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,11 +71,6 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
||||
return log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld withLog(ModuleLog log) {
|
||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new ToolWorld(seed, resources, settings, states, moduleLog, viewsByLog));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
states.close();
|
||||
|
||||
@@ -217,7 +217,7 @@ public final class ModuleResourceClosure {
|
||||
private Object lookup(ResourceKind<?> kind, String key) {
|
||||
IrisPackResources resources = data.getPackResources();
|
||||
try {
|
||||
return resources.find(kind.key(resources.idOf(key))).orElse(null);
|
||||
return resources.find(kind, resources.idOf(key)).orElse(null);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ public class SchemaBuilder {
|
||||
}
|
||||
|
||||
private PackResourceList putModuleResourceRef(JSONObject property, ResourceKind<?> kind) {
|
||||
List<String> keys = data.getPackResources().ids(kind.type()).stream().map(ResourceId::path).toList();
|
||||
List<String> keys = data.getPackResources().ids(kind).stream().map(ResourceId::path).toList();
|
||||
return putResourceKeys(property, new PackResourceList(kind.folder(), ModuleResourceFiles.typeName(kind)), keys);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package art.arcane.iris.core.service.tree;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -10,17 +12,19 @@ import java.util.Set;
|
||||
public final class TreeDefinitionIndex {
|
||||
private static final String PROCEDURAL_TREE_PREFIX = "procedural/tree/";
|
||||
|
||||
private final Set<String> explicitObjectKeys;
|
||||
private final Set<String> proceduralTreeKeys;
|
||||
private final PackResources resources;
|
||||
private final Set<ResourceId> explicitObjects;
|
||||
private final Set<ResourceId> proceduralTrees;
|
||||
|
||||
private TreeDefinitionIndex(Set<String> explicitObjectKeys, Set<String> proceduralTreeKeys) {
|
||||
this.explicitObjectKeys = Set.copyOf(explicitObjectKeys);
|
||||
this.proceduralTreeKeys = Set.copyOf(proceduralTreeKeys);
|
||||
private TreeDefinitionIndex(PackResources resources, Set<ResourceId> explicitObjects, Set<ResourceId> proceduralTrees) {
|
||||
this.resources = resources;
|
||||
this.explicitObjects = Set.copyOf(explicitObjects);
|
||||
this.proceduralTrees = Set.copyOf(proceduralTrees);
|
||||
}
|
||||
|
||||
public static TreeDefinitionIndex build(Engine engine) {
|
||||
SaplingGrowth.TreeObjects trees = ModuleServices.treeObjects(engine);
|
||||
return new TreeDefinitionIndex(trees.objects(), trees.procedural());
|
||||
return new TreeDefinitionIndex(engine.getData().getPackResources(), trees.objects(), trees.procedural());
|
||||
}
|
||||
|
||||
public boolean isTreeMarker(String marker) {
|
||||
@@ -31,11 +35,11 @@ public final class TreeDefinitionIndex {
|
||||
|
||||
String objectKey = decoded.objectKey();
|
||||
if (objectKey.startsWith(PROCEDURAL_TREE_PREFIX)) {
|
||||
return proceduralTreeKeys.contains(objectKey);
|
||||
return proceduralTrees.contains(resources.idOf(objectKey));
|
||||
}
|
||||
if (objectKey.startsWith("procedural/")) {
|
||||
return false;
|
||||
}
|
||||
return objectKey.startsWith("trees/") || explicitObjectKeys.contains(objectKey);
|
||||
return objectKey.startsWith("trees/") || explicitObjects.contains(resources.idOf(objectKey));
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import art.arcane.iris.util.common.plugin.Chunks;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.collection.KSet;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -53,7 +54,7 @@ final class MarkerSpawnScanner {
|
||||
}
|
||||
|
||||
/** A spawner a marker names, and the marker. */
|
||||
record MarkerSpawner(String marker, String spawner) {
|
||||
record MarkerSpawner(String marker, ResourceId spawner) {
|
||||
}
|
||||
|
||||
Map<IrisPosition, List<MarkerSpawner>> getSpawnersFromMarkers(Chunk c) {
|
||||
@@ -80,7 +81,7 @@ final class MarkerSpawnScanner {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String spawner : rule.get().spawners()) {
|
||||
for (ResourceId spawner : rule.get().spawners()) {
|
||||
addOnce(p.computeIfAbsent(pos, (k) -> new ArrayList<>()), new MarkerSpawner(t.getTag(), spawner));
|
||||
}
|
||||
});
|
||||
@@ -178,7 +179,7 @@ final class MarkerSpawnScanner {
|
||||
MarkerSpawnData data = markerData.computeIfAbsent(position, k -> new MarkerSpawnData());
|
||||
data.requiresEmptyAbove = data.requiresEmptyAbove || rule.get().emptyAbove();
|
||||
|
||||
for (String spawner : rule.get().spawners()) {
|
||||
for (ResourceId spawner : rule.get().spawners()) {
|
||||
addOnce(data.spawners, new MarkerSpawner(t.getTag(), spawner));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -391,7 +391,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
||||
}
|
||||
|
||||
IrisComplex complex = engine.getComplex();
|
||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, objectKey);
|
||||
ModuleServices.ObjectPlacers placers = ModuleServices.objectPlacers(engine, objectKey);
|
||||
BiomeSource source = new BiomeSource(engine);
|
||||
KSet<String> landHosts = new KSet<>();
|
||||
KSet<String> seaHosts = new KSet<>();
|
||||
|
||||
@@ -40,6 +40,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -67,6 +68,7 @@ import org.bukkit.util.Vector;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -141,8 +143,8 @@ public final class BukkitEntitySpawner {
|
||||
}
|
||||
|
||||
if (e instanceof Panda panda) {
|
||||
panda.setMainGene(resolveGene(spec.pandaMainGene()));
|
||||
panda.setHiddenGene(resolveGene(spec.pandaHiddenGene()));
|
||||
panda.setMainGene(resolveGene(spec.pandaMainGene().orElse(null)));
|
||||
panda.setHiddenGene(resolveGene(spec.pandaHiddenGene().orElse(null)));
|
||||
}
|
||||
|
||||
if (e instanceof Villager villager) {
|
||||
@@ -154,9 +156,7 @@ public final class BukkitEntitySpawner {
|
||||
mob.setAware(spec.flags().aware());
|
||||
}
|
||||
|
||||
if (spec.spawnEffect() != null) {
|
||||
showSpawnEffect(e, spec.spawnEffect());
|
||||
}
|
||||
spec.spawnEffect().ifPresent(effect -> showSpawnEffect(e, effect));
|
||||
|
||||
runCommands(spec, at);
|
||||
|
||||
@@ -191,7 +191,7 @@ public final class BukkitEntitySpawner {
|
||||
|
||||
private static void applyFlags(Entity e, EntitySpec spec) {
|
||||
EntitySpec.Flags flags = spec.flags();
|
||||
e.setCustomName(spec.customName() != null ? C.translateAlternateColorCodes('&', spec.customName()) : null);
|
||||
e.setCustomName(spec.customName().map(name -> C.translateAlternateColorCodes('&', name)).orElse(null));
|
||||
e.setCustomNameVisible(flags.customNameVisible());
|
||||
e.setGlowing(flags.glowing());
|
||||
e.setGravity(flags.gravity());
|
||||
@@ -219,31 +219,17 @@ public final class BukkitEntitySpawner {
|
||||
l.setAI(spec.flags().ai());
|
||||
l.setCanPickupItems(spec.flags().pickupItems());
|
||||
|
||||
if (spec.leashHolder() != null) {
|
||||
l.setLeashHolder(spawn(gen, spec.leashHolder(), at));
|
||||
}
|
||||
spec.leashHolder().ifPresent(holder -> l.setLeashHolder(spawn(gen, holder, at)));
|
||||
|
||||
l.setRemoveWhenFarAway(spec.flags().removable());
|
||||
|
||||
EntitySpec.Equipment equipment = spec.equipment();
|
||||
if (equipment.helmet() != null) {
|
||||
l.getEquipment().setHelmet(BukkitItemStacks.create(equipment.helmet()));
|
||||
}
|
||||
if (equipment.chestplate() != null) {
|
||||
l.getEquipment().setChestplate(BukkitItemStacks.create(equipment.chestplate()));
|
||||
}
|
||||
if (equipment.leggings() != null) {
|
||||
l.getEquipment().setLeggings(BukkitItemStacks.create(equipment.leggings()));
|
||||
}
|
||||
if (equipment.boots() != null) {
|
||||
l.getEquipment().setBoots(BukkitItemStacks.create(equipment.boots()));
|
||||
}
|
||||
if (equipment.mainHand() != null) {
|
||||
l.getEquipment().setItemInMainHand(BukkitItemStacks.create(equipment.mainHand()));
|
||||
}
|
||||
if (equipment.offHand() != null) {
|
||||
l.getEquipment().setItemInOffHand(BukkitItemStacks.create(equipment.offHand()));
|
||||
}
|
||||
equipment.helmet().ifPresent(item -> l.getEquipment().setHelmet(BukkitItemStacks.create(item)));
|
||||
equipment.chestplate().ifPresent(item -> l.getEquipment().setChestplate(BukkitItemStacks.create(item)));
|
||||
equipment.leggings().ifPresent(item -> l.getEquipment().setLeggings(BukkitItemStacks.create(item)));
|
||||
equipment.boots().ifPresent(item -> l.getEquipment().setBoots(BukkitItemStacks.create(item)));
|
||||
equipment.mainHand().ifPresent(item -> l.getEquipment().setItemInMainHand(BukkitItemStacks.create(item)));
|
||||
equipment.offHand().ifPresent(item -> l.getEquipment().setItemInOffHand(BukkitItemStacks.create(item)));
|
||||
}
|
||||
|
||||
private static void runCommands(EntitySpec spec, Location at) {
|
||||
@@ -338,7 +324,7 @@ public final class BukkitEntitySpawner {
|
||||
}
|
||||
|
||||
if (spec.isSpecial()) {
|
||||
return IrisServices.get(ExternalDataSVC.class).spawnMob(at, Identifier.fromString(spec.specialType()));
|
||||
return IrisServices.get(ExternalDataSVC.class).spawnMob(at, Identifier.fromString(spec.specialType().orElseThrow()));
|
||||
}
|
||||
|
||||
return BukkitPlatform.spawnEntity(at, bukkitType(spec), bukkitReason(spec));
|
||||
@@ -346,11 +332,12 @@ public final class BukkitEntitySpawner {
|
||||
|
||||
/** The platform's entity type of the spec, unknown when it names none. */
|
||||
public static EntityType bukkitType(EntitySpec spec) {
|
||||
if (spec.type().isBlank()) {
|
||||
String type = spec.type().orElse("");
|
||||
if (type.isBlank()) {
|
||||
return EntityType.UNKNOWN;
|
||||
}
|
||||
|
||||
NamespacedKey key = NamespacedKey.fromString(spec.type().trim().toLowerCase(Locale.ROOT));
|
||||
NamespacedKey key = NamespacedKey.fromString(type.trim().toLowerCase(Locale.ROOT));
|
||||
if (key == null) {
|
||||
return EntityType.UNKNOWN;
|
||||
}
|
||||
@@ -360,12 +347,13 @@ public final class BukkitEntitySpawner {
|
||||
}
|
||||
|
||||
private static CreatureSpawnEvent.SpawnReason bukkitReason(EntitySpec spec) {
|
||||
if (spec.reason() == null || spec.reason().isBlank()) {
|
||||
String reason = spec.reason().orElse("");
|
||||
if (reason.isBlank()) {
|
||||
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
||||
}
|
||||
|
||||
try {
|
||||
return CreatureSpawnEvent.SpawnReason.valueOf(spec.reason().trim().toUpperCase(Locale.ROOT));
|
||||
return CreatureSpawnEvent.SpawnReason.valueOf(reason.trim().toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
||||
}
|
||||
@@ -385,8 +373,8 @@ public final class BukkitEntitySpawner {
|
||||
|
||||
private static void showSpawnEffect(Entity p, EntitySpec.SpawnEffect fx) {
|
||||
J.runEntity(p, () -> {
|
||||
Sound soundType = fx.sound() == null ? null : resolveKeyed(Sound.class, fx.sound());
|
||||
Particle particleType = fx.particle() == null ? null : resolveKeyed(Particle.class, fx.particle());
|
||||
Sound soundType = fx.sound().map(sound -> resolveKeyed(Sound.class, sound)).orElse(null);
|
||||
Particle particleType = fx.particle().map(particle -> resolveKeyed(Particle.class, particle)).orElse(null);
|
||||
if (soundType != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-fx.soundDistance(), fx.soundDistance()), RNG.r.i(-fx.soundDistance(), fx.soundDistance()), RNG.r.i(-fx.soundDistance(), fx.soundDistance()));
|
||||
p.getWorld().playSound(part, soundType, (float) fx.volume(), (float) RNG.r.d(fx.minPitch(), fx.maxPitch()));
|
||||
@@ -424,10 +412,10 @@ public final class BukkitEntitySpawner {
|
||||
@Override
|
||||
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
|
||||
BlockPosition position = new BlockPosition(finalAt.getBlockX(), finalAt.getBlockY() - gen.getMinHeight(), finalAt.getBlockZ());
|
||||
Loot.Site site = new Loot.Site(position, null, false, gen.isStudio());
|
||||
Loot.Site site = new Loot.Site(position, Optional.empty(), false, gen.isStudio());
|
||||
KList<ItemStack> items = new KList<>();
|
||||
|
||||
for (String table : spec.lootTables()) {
|
||||
for (ResourceId table : spec.lootTables()) {
|
||||
items.addAll(BukkitItemStacks.createAll(ModuleServices.lootItems(gen, site, table)));
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ import org.bukkit.loot.Lootable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -420,9 +421,9 @@ public final class EngineBukkitOps {
|
||||
private static Loot.Site lootSite(Engine engine, Block b, boolean nativeLootDefined) {
|
||||
BlockPosition position = new BlockPosition(b.getX(), b.getY() - engine.getMinHeight(), b.getZ());
|
||||
BlockData data = b.getBlockData();
|
||||
com.volmit.block.BlockState container = BukkitBlockResolution.isStorageChest(data)
|
||||
? com.volmit.block.BlockState.parse(PlatformBlockStates.namespaced(BukkitBlockState.of(data).key()))
|
||||
: null;
|
||||
Optional<com.volmit.block.BlockState> container = BukkitBlockResolution.isStorageChest(data)
|
||||
? Optional.of(com.volmit.block.BlockState.parse(PlatformBlockStates.namespaced(BukkitBlockState.of(data).key())))
|
||||
: Optional.empty();
|
||||
return new Loot.Site(position, container, nativeLootDefined, false);
|
||||
}
|
||||
|
||||
@@ -473,11 +474,11 @@ public final class EngineBukkitOps {
|
||||
|
||||
/** The items of {@code tables} at the spot, in the tables' order: the modules' for pack tables, the platform's own for platform tables. */
|
||||
private static List<ItemStack> lootItems(Engine engine, boolean debug, List<Loot.Source> tables, World world, int x, int y, int z) {
|
||||
Loot.Site site = new Loot.Site(new BlockPosition(x, y - engine.getMinHeight(), z), null, false, debug);
|
||||
Loot.Site site = new Loot.Site(new BlockPosition(x, y - engine.getMinHeight(), z), Optional.empty(), false, debug);
|
||||
List<ItemStack> items = new KList<>();
|
||||
for (Loot.Source source : tables) {
|
||||
switch (source) {
|
||||
case Loot.Table table -> items.addAll(BukkitItemStacks.createAll(ModuleServices.lootItems(engine, site, table.key())));
|
||||
case Loot.Table table -> items.addAll(BukkitItemStacks.createAll(ModuleServices.lootItems(engine, site, table.id())));
|
||||
case Loot.PlatformTable table -> items.addAll(platformLoot(table, world, x, y, z));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,16 +54,10 @@ public final class BukkitAmbientEffects {
|
||||
}
|
||||
|
||||
private static void playOnEntityThread(Player player, Engine engine, AmbientEffects.Effect effect) {
|
||||
if (effect.sound() != null) {
|
||||
playSound(player, effect.sound());
|
||||
}
|
||||
if (effect.particles() != null) {
|
||||
showParticles(player, engine, effect.particles());
|
||||
}
|
||||
effect.sound().ifPresent(sound -> playSound(player, sound));
|
||||
effect.particles().ifPresent(particles -> showParticles(player, engine, particles));
|
||||
effect.commands().forEach(command -> runCommand(player, command));
|
||||
if (effect.potion() != null) {
|
||||
givePotion(player, effect.potion());
|
||||
}
|
||||
effect.potion().ifPresent(potion -> givePotion(player, potion));
|
||||
}
|
||||
|
||||
private static void playSound(Player player, AmbientEffects.Sound sound) {
|
||||
|
||||
@@ -114,19 +114,19 @@ public final class BukkitItemStacks {
|
||||
meta.setUnbreakable(drop.unbreakable());
|
||||
flags(drop).forEach(meta::addItemFlags);
|
||||
|
||||
if (drop.customModel() != null) {
|
||||
if (drop.customModel().isPresent()) {
|
||||
CustomModelDataComponent customModelData = meta.getCustomModelDataComponent();
|
||||
customModelData.setFloats(List.of(drop.customModel().floatValue()));
|
||||
customModelData.setFloats(List.of((float) drop.customModel().getAsInt()));
|
||||
meta.setCustomModelDataComponent(customModelData);
|
||||
}
|
||||
|
||||
int maxDurability = stack.getType().getMaxDurability();
|
||||
if (drop.damage() != null && maxDurability > 0 && meta instanceof Damageable damageable) {
|
||||
damageable.setDamage((int) Math.round(Math.max(0, Math.min(maxDurability, drop.damage() * maxDurability))));
|
||||
if (drop.damage().isPresent() && maxDurability > 0 && meta instanceof Damageable damageable) {
|
||||
damageable.setDamage((int) Math.round(Math.max(0, Math.min(maxDurability, drop.damage().getAsDouble() * maxDurability))));
|
||||
}
|
||||
|
||||
if (drop.leatherColor() != null && meta instanceof LeatherArmorMeta leather) {
|
||||
Color c = Color.decode(drop.leatherColor());
|
||||
if (drop.leatherColor().isPresent() && meta instanceof LeatherArmorMeta leather) {
|
||||
Color c = Color.decode(drop.leatherColor().get());
|
||||
leather.setColor(org.bukkit.Color.fromRGB(c.getRed(), c.getGreen(), c.getBlue()));
|
||||
}
|
||||
|
||||
@@ -135,9 +135,7 @@ public final class BukkitItemStacks {
|
||||
colorable.setColor(dye);
|
||||
}
|
||||
|
||||
if (drop.displayName() != null) {
|
||||
meta.setDisplayName(C.translateAlternateColorCodes('&', drop.displayName()));
|
||||
}
|
||||
drop.displayName().ifPresent(name -> meta.setDisplayName(C.translateAlternateColorCodes('&', name)));
|
||||
|
||||
meta.setLore(lore(drop));
|
||||
return meta;
|
||||
@@ -185,11 +183,11 @@ public final class BukkitItemStacks {
|
||||
}
|
||||
|
||||
private static DyeColor dyeColor(ItemDrop drop) {
|
||||
if (drop.dyeColor() == null) {
|
||||
if (drop.dyeColor().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return DyeColor.valueOf(drop.dyeColor());
|
||||
return DyeColor.valueOf(drop.dyeColor().get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
@@ -207,9 +205,7 @@ public final class BukkitItemStacks {
|
||||
lore.add(colored);
|
||||
}
|
||||
}
|
||||
if (drop.source() != null) {
|
||||
addSourceLore(lore, drop.source());
|
||||
}
|
||||
drop.source().ifPresent(source -> addSourceLore(lore, source));
|
||||
return lore;
|
||||
}
|
||||
|
||||
@@ -217,12 +213,12 @@ public final class BukkitItemStacks {
|
||||
if (lore.isNotEmpty()) {
|
||||
lore.add(LORE_RULE);
|
||||
}
|
||||
if (source.table() == null) {
|
||||
if (source.table().isEmpty()) {
|
||||
lore.add(C.GRAY + "1 in " + source.entryRarity() + " Chance (" + Form.pc(1D / source.entryRarity(), CHANCE_DIGITS) + ")");
|
||||
return;
|
||||
}
|
||||
long combined = (long) source.tableRarity() * source.entryRarity();
|
||||
lore.add(C.GRAY + "From: " + source.table() + " (" + Form.pc(1D / source.tableRarity(), CHANCE_DIGITS) + ")");
|
||||
lore.add(C.GRAY + "From: " + source.table().get() + " (" + Form.pc(1D / source.tableRarity(), CHANCE_DIGITS) + ")");
|
||||
lore.add(C.GRAY + "1 in " + combined + " Chance (" + Form.pc(1D / combined, CHANCE_DIGITS) + ")");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -21,7 +21,7 @@ package art.arcane.iris.util.common.director.specialhandlers;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -70,7 +70,7 @@ public final class EntityKeyHandler implements DirectorParameterHandler<String>
|
||||
/** A pack whose modules fail to load has no entities to offer; its failure was reported when it loaded. */
|
||||
private static void addEntityKeys(Set<String> keys, IrisData data) {
|
||||
try {
|
||||
data.getPackResources().ids(EntityDefinition.class).forEach(id -> keys.add(id.path()));
|
||||
data.getPackResources().ids(SpawnResources.ENTITIES).forEach(id -> keys.add(id.path()));
|
||||
} catch (PackModulesException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user