mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-02 19:22:08 +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;
|
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.ModuleServices;
|
||||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
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.ItemAttribute;
|
||||||
import com.volmit.item.ItemDrop;
|
import com.volmit.item.ItemDrop;
|
||||||
import com.volmit.item.ItemEnchantment;
|
import com.volmit.item.ItemEnchantment;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.AmbientEffects;
|
import com.volmit.service.AmbientEffects;
|
||||||
import com.volmit.service.BlockDrops;
|
import com.volmit.service.BlockDrops;
|
||||||
import com.volmit.service.EntitySpawns;
|
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
|
* @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) {
|
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);
|
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), container, nativeLootDefined, false);
|
||||||
List<ContentLoot.Part> parts = new ArrayList<>();
|
List<ContentLoot.Part> parts = new ArrayList<>();
|
||||||
for (Loot.Source source : ModuleServices.lootTables(engine, site)) {
|
for (Loot.Source source : ModuleServices.lootTables(engine, site)) {
|
||||||
switch (source) {
|
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()));
|
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. */
|
/** 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) {
|
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 tableItems(engine, x, worldY, z, engine.getData().getPackResources().idOf(tableKey));
|
||||||
return ModuleServices.lootItems(engine, site, tableKey).stream().map(ContentServices::itemOf).toList();
|
}
|
||||||
|
|
||||||
|
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. */
|
/** 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. */
|
/** 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) {
|
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. */
|
/** 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) {
|
public static Optional<ContentSpawns.MarkerRule> markerRule(Engine engine, String tag) {
|
||||||
|
IrisPackResources resources = engine.getData().getPackResources();
|
||||||
return ModuleServices.markerRule(engine, tag)
|
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. */
|
/** 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) {
|
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.enchantments().stream().map(ContentServices::enchantmentOf).toList(),
|
||||||
drop.attributes().stream().map(ContentServices::attributeOf).toList(), drop.unbreakable(), drop.flags(),
|
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) {
|
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());
|
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) {
|
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(),
|
equipmentOf(spec.equipment()), spec.passengers().stream().map(ContentServices::entityOf).toList(),
|
||||||
spec.attributes().stream().map(ContentServices::attributeOf).toList(), spec.lootTables(), spec.lootShuffleSeed(),
|
spec.attributes().stream().map(ContentServices::attributeOf).toList(),
|
||||||
spec.leashHolder() == null ? null : entityOf(spec.leashHolder()), spawnEffectOf(spec.spawnEffect()),
|
spec.lootTables().stream().map(ResourceId::path).toList(), spec.lootShuffleSeed(),
|
||||||
spec.riseOutOfGround(), spec.pandaMainGene(), spec.pandaHiddenGene(), spec.applySettingsToSpecial(),
|
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());
|
spec.commands().stream().map(ContentServices::commandOf).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,16 +175,13 @@ public final class ContentServices {
|
|||||||
optionalItem(equipment.offHand()));
|
optionalItem(equipment.offHand()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentItem optionalItem(ItemDrop drop) {
|
private static ContentItem optionalItem(Optional<ItemDrop> drop) {
|
||||||
return drop == null ? null : itemOf(drop);
|
return drop.map(ContentServices::itemOf).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentEntity.SpawnEffect spawnEffectOf(EntitySpec.SpawnEffect effect) {
|
private static ContentEntity.SpawnEffect spawnEffectOf(EntitySpec.SpawnEffect effect) {
|
||||||
if (effect == null) {
|
return new ContentEntity.SpawnEffect(effect.sound().orElse(null), effect.soundDistance(), effect.minPitch(), effect.maxPitch(),
|
||||||
return null;
|
effect.volume(), effect.particle().orElse(null), effect.particleOffset(), effect.particleCount(), effect.altX(), effect.altY(),
|
||||||
}
|
|
||||||
return new ContentEntity.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(), effect.maxPitch(),
|
|
||||||
effect.volume(), effect.particle(), effect.particleOffset(), effect.particleCount(), effect.altX(), effect.altY(),
|
|
||||||
effect.altZ(), effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra());
|
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) {
|
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()),
|
effect.commands().stream().map(command -> new ContentEffect.Command(commandOf(command.command()),
|
||||||
command.offsetX(), command.offsetY(), command.offsetZ())).toList(),
|
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) {
|
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());
|
sound.volume(), sound.pitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentEffect.Particles particlesOf(AmbientEffects.Particles particles) {
|
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.jitterX(), particles.jitterZ(), particles.lift(), particles.count(), particles.altX(), particles.altY(),
|
||||||
particles.altZ(), particles.extra());
|
particles.altZ(), particles.extra());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public final class BiomeModule implements IrisModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void write(ChunkStageContext context) {
|
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());
|
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.core.loader.IrisData;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
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.service.CaveBiomes;
|
||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
|
|
||||||
@@ -36,12 +38,12 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public final class CaveBiomeAnswers {
|
public final class CaveBiomeAnswers {
|
||||||
private static final CaveBiomes NO_PROVIDER = new CaveBiomes() {
|
private static final CaveBiomes NO_PROVIDER = new CaveBiomes() {
|
||||||
@Override
|
@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();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||||
return 0;
|
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. */
|
/** 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) {
|
public IrisBiome overriddenBiome(int x, int y, int z) {
|
||||||
Optional<String> key = provider.overriddenBiome(world, x, y, z);
|
Optional<ResourceId> biome = provider.overriddenBiome(world, x, y, z);
|
||||||
return key.isEmpty() ? null : overridingBiome(key.get());
|
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. */
|
/** 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) {
|
if (depth != null) {
|
||||||
return depth;
|
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) {
|
private IrisBiome overridingBiome(String key) {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public final class CustomModule implements IrisModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void record(ChunkStageContext context) {
|
private static void record(ChunkStageContext context) {
|
||||||
IrisChunk chunk = IrisChunk.current();
|
IrisChunk chunk = context.extension(IrisChunk.class).orElseThrow();
|
||||||
if (chunk.bypassesMantleStages()) {
|
if (chunk.bypassesMantleStages()) {
|
||||||
return;
|
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
|
* 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
|
* the chunk's sampled context. Iris offers it as an extension of the chunk invocation, so its built-in chunk stages
|
||||||
* generating thread while the chunk graph runs, and work on Iris's types directly; pack modules cannot see
|
* read it with {@code context.extension(IrisChunk.class)} and work on Iris's types directly; pack modules cannot see
|
||||||
* this class.
|
* this class.
|
||||||
*/
|
*/
|
||||||
public final class IrisChunk {
|
public final class IrisChunk {
|
||||||
private static final ScopedValue<IrisChunk> CURRENT = ScopedValue.newInstance();
|
|
||||||
|
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final int originX;
|
private final int originX;
|
||||||
private final int originZ;
|
private final int originZ;
|
||||||
@@ -54,18 +52,6 @@ public final class IrisChunk {
|
|||||||
this.context = context;
|
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() {
|
public Engine engine() {
|
||||||
return 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.MatterBiomeInject;
|
||||||
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
|
||||||
import com.volmit.ModuleLog;
|
import com.volmit.ModuleLog;
|
||||||
|
import com.volmit.generation.InvocationContext;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -128,11 +129,12 @@ final class IrisFloatingHost implements FloatingHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
IrisObject placed = (IrisObject) object;
|
||||||
IrisData data = engine.getData();
|
IrisData data = engine.getData();
|
||||||
IrisObjectPlacement floating = ObjectPlacements.host(placement, data).toPlacement(placed.getLoadKey());
|
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);
|
int id = random.i(0, Integer.MAX_VALUE);
|
||||||
try {
|
try {
|
||||||
placed.place(worldX, FLOATING_OBJECT_Y, worldZ, writer, floating, random, (block, state) -> writeMarker(writer, placed, id, block.getX(),
|
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
|
@Override
|
||||||
public void placeOnTop(PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
public void placeOnTop(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||||
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
|
IslandAnchor anchor, RNG random) {
|
||||||
|
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, NO_ROTATION, anchor, random, "anchored");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void placeUnder(PlaceableObject object, int worldX, int y, int worldZ, int yRotation, ObjectPlacement placement,
|
public void placeUnder(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, int yRotation,
|
||||||
IslandAnchor anchor, RNG random) {
|
ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
||||||
placeAgainstIsland((IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation), anchor, random,
|
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation),
|
||||||
"inverted");
|
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. */
|
/** 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,
|
private void placeAgainstIsland(MantleWriter writer, IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||||
IslandAnchor anchor, RNG random, String kind) {
|
IrisObjectRotation rotation, IslandAnchor anchor, RNG random, String kind) {
|
||||||
IrisData data = engine.getData();
|
IrisData data = engine.getData();
|
||||||
IrisObjectPlacement anchored = ObjectPlacements.host(placement, data).toPlacement(object.getLoadKey());
|
IrisObjectPlacement anchored = ObjectPlacements.host(placement, data).toPlacement(object.getLoadKey());
|
||||||
anchored.setMode(anchored.getMode().onFloatingIsland());
|
anchored.setMode(anchored.getMode().onFloatingIsland());
|
||||||
@@ -166,7 +173,7 @@ final class IrisFloatingHost implements FloatingHost {
|
|||||||
anchored.setBottom(false);
|
anchored.setBottom(false);
|
||||||
|
|
||||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||||
new IslandAnchorPlacer(IrisMantleChunk.current().writer(), anchor));
|
new IslandAnchorPlacer(writer, anchor));
|
||||||
int id = random.i(0, Integer.MAX_VALUE);
|
int id = random.i(0, Integer.MAX_VALUE);
|
||||||
try {
|
try {
|
||||||
int resultY = object.place(worldX, y, worldZ, transaction, anchored, random, (block, state) -> writeMarker(transaction, object, id,
|
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;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
|
import art.arcane.iris.builtin.MatterMantle;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.spi.PlatformBlockState;
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
import com.volmit.block.BlockState;
|
import com.volmit.block.BlockState;
|
||||||
@@ -30,10 +31,11 @@ import com.volmit.world.PackWorld;
|
|||||||
import com.volmit.world.TerrainSampler;
|
import com.volmit.world.TerrainSampler;
|
||||||
|
|
||||||
import java.util.Collection;
|
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
|
* 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.
|
* Pack resources are the pack snapshot's, shared by every invocation of it.
|
||||||
*/
|
*/
|
||||||
final class IrisGenerationContext implements GenerationContext {
|
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. */
|
/** 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 MANTLE_MARGIN_BLOCKS = 16;
|
||||||
private static final int CHUNK_WIDTH = 16;
|
private static final int CHUNK_WIDTH = 16;
|
||||||
|
private static final int CHUNK_SHIFT = 4;
|
||||||
|
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final int originX;
|
private final int originX;
|
||||||
@@ -50,13 +53,19 @@ final class IrisGenerationContext implements GenerationContext {
|
|||||||
private final IrisTerrainSampler terrain;
|
private final IrisTerrainSampler terrain;
|
||||||
private final ChunkModuleSettings settings;
|
private final ChunkModuleSettings settings;
|
||||||
private final IrisModuleMantle mantle;
|
private final IrisModuleMantle mantle;
|
||||||
|
private final IrisChunk irisChunk;
|
||||||
private PackWorld world;
|
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,
|
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());
|
PackResourceIds ids = new PackResourceIds(engine.getData().getDataFolder());
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
|
this.irisChunk = irisChunk;
|
||||||
this.originX = originX;
|
this.originX = originX;
|
||||||
this.originZ = originZ;
|
this.originZ = originZ;
|
||||||
this.blocks = new BlockStateHunk(blocks, states);
|
this.blocks = new BlockStateHunk(blocks, states);
|
||||||
@@ -101,6 +110,17 @@ final class IrisGenerationContext implements GenerationContext {
|
|||||||
return (com.volmit.hunk.Hunk<T>) blocks;
|
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. */
|
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||||
@Override
|
@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
|
* 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
|
* the chunk and the generating chunk's sampled context. Iris offers it as an extension of the mantle invocation, so
|
||||||
* {@link #current()}, bound on the thread running the mantle graph, and write Iris's own mantle data; pack
|
* its built-in mantle stages and the hosts they call read it with {@code context.extension(IrisMantleChunk.class)} and
|
||||||
* modules cannot see this class.
|
* write Iris's own mantle data; pack modules cannot see this class.
|
||||||
*/
|
*/
|
||||||
public final class IrisMantleChunk {
|
public final class IrisMantleChunk {
|
||||||
private static final ScopedValue<IrisMantleChunk> CURRENT = ScopedValue.newInstance();
|
|
||||||
|
|
||||||
private final Engine engine;
|
private final Engine engine;
|
||||||
private final MantleWriter writer;
|
private final MantleWriter writer;
|
||||||
private final int chunkX;
|
private final int chunkX;
|
||||||
@@ -47,18 +45,6 @@ public final class IrisMantleChunk {
|
|||||||
this.context = context;
|
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() {
|
public Engine engine() {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
|
import art.arcane.iris.builtin.MatterMantle;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.util.common.data.B;
|
import art.arcane.iris.util.common.data.B;
|
||||||
import com.volmit.config.FeatureSettings;
|
import com.volmit.config.FeatureSettings;
|
||||||
@@ -29,6 +30,7 @@ import com.volmit.world.PackWorld;
|
|||||||
import com.volmit.world.TerrainSampler;
|
import com.volmit.world.TerrainSampler;
|
||||||
|
|
||||||
import java.util.Collection;
|
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
|
* 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 IrisTerrainSampler terrain;
|
||||||
private final ChunkModuleSettings settings;
|
private final ChunkModuleSettings settings;
|
||||||
private final IrisModuleMantle mantle;
|
private final IrisModuleMantle mantle;
|
||||||
|
private final IrisMantleChunk irisChunk;
|
||||||
private PackWorld world;
|
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,
|
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());
|
PackResourceIds ids = new PackResourceIds(engine.getData().getDataFolder());
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
|
this.irisChunk = irisChunk;
|
||||||
this.originX = chunkX << CHUNK_SHIFT;
|
this.originX = chunkX << CHUNK_SHIFT;
|
||||||
this.originZ = chunkZ << CHUNK_SHIFT;
|
this.originZ = chunkZ << CHUNK_SHIFT;
|
||||||
this.terrain = new IrisTerrainSampler(engine, ids, originX, originZ, Math.max(reachBlocks, TERRAIN_MARGIN_BLOCKS));
|
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;
|
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. */
|
/** The world this invocation first asked for; it keeps it if the world restarts meanwhile. */
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MantleLayer<Boolean> caverns() {
|
public boolean isCarved(int x, int y, int z) {
|
||||||
return new MantleCaverns(bounds, chunks);
|
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -262,9 +262,9 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MantleLayer<Boolean> caverns() {
|
public boolean isCarved(int x, int y, int z) {
|
||||||
requireOpen();
|
requireOpen();
|
||||||
return new MantleCaverns(bounds, chunks);
|
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.cache.CacheKey;
|
||||||
import art.arcane.volmlib.util.math.RNG;
|
import art.arcane.volmlib.util.math.RNG;
|
||||||
import com.volmit.config.Level;
|
import com.volmit.config.Level;
|
||||||
|
import com.volmit.generation.InvocationContext;
|
||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
import com.volmit.ModuleLog;
|
import com.volmit.ModuleLog;
|
||||||
import com.volmit.config.FeatureSettings;
|
import com.volmit.config.FeatureSettings;
|
||||||
@@ -117,8 +118,8 @@ final class IrisObjectHost implements ObjectHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectChunk chunk() {
|
public ObjectChunk chunk(InvocationContext context) {
|
||||||
IrisMantleChunk chunk = IrisMantleChunk.current();
|
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||||
return new IrisObjectChunk(chunk.engine(), chunk.writer(), log, this::options);
|
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.object.GeneratedObject;
|
||||||
import com.volmit.resource.PackResources;
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.resource.ResourceKey;
|
|
||||||
import com.volmit.resource.ResourceKind;
|
import com.volmit.resource.ResourceKind;
|
||||||
import com.volmit.world.PackBiome;
|
import com.volmit.world.PackBiome;
|
||||||
import com.volmit.world.PackRegion;
|
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
|
* 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()}).
|
* does every reload of its module resources ({@link IrisData#dump()}, {@link IrisData#invalidateStructureResources()}).
|
||||||
* <p>
|
* <p>
|
||||||
* Served by the type the key asks for: {@link GeneratedObject} (a pack object, as its geometry), {@link PackBiome},
|
* Served by kind: the host kinds {@link #OBJECTS} (a pack object, as its geometry), {@link #BIOMES} and
|
||||||
* {@link PackRegion}, and the type of every {@link ResourceKind} the pack's modules register, read from the kind's
|
* {@link #REGIONS}, and every {@link ResourceKind} the pack's modules register, read from the kind's folder
|
||||||
* folder ({@link ModuleResourceFiles}). All use the id {@code <pack namespace>:<key>} that {@link PackResourceIds}
|
* ({@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
|
* 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
|
* 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.
|
* snapshot. The module kinds are looked up the first time one is asked for, which loads the pack's modules.
|
||||||
* <p>
|
* <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.
|
* styles through Iris's generators, expressions and image maps ({@link IrisNoiseFactory}), both kept per snapshot.
|
||||||
*/
|
*/
|
||||||
public final class IrisPackResources implements PackResources {
|
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 IrisData data;
|
||||||
private final PackResourceIds ids;
|
private final PackResourceIds ids;
|
||||||
@@ -73,9 +72,9 @@ public final class IrisPackResources implements PackResources {
|
|||||||
private final BlockRegistry blocks;
|
private final BlockRegistry blocks;
|
||||||
private final ItemRegistry items = new IrisItemRegistry();
|
private final ItemRegistry items = new IrisItemRegistry();
|
||||||
private final NoiseFactory noise;
|
private final NoiseFactory noise;
|
||||||
private final Map<Class<?>, Kind<?>> irisKinds;
|
private final Map<ResourceId, Kind<?>> irisKinds;
|
||||||
private final Supplier<List<ResourceKind<?>>> moduleKindList;
|
private final Supplier<List<ResourceKind<?>>> moduleKindList;
|
||||||
private volatile Map<Class<?>, Kind<?>> moduleKinds;
|
private volatile Map<ResourceId, Kind<?>> moduleKinds;
|
||||||
private volatile List<String> moduleFolders;
|
private volatile List<String> moduleFolders;
|
||||||
private boolean announcedToModules;
|
private boolean announcedToModules;
|
||||||
|
|
||||||
@@ -93,9 +92,9 @@ public final class IrisPackResources implements PackResources {
|
|||||||
this.blocks = new IrisBlockRegistry(data);
|
this.blocks = new IrisBlockRegistry(data);
|
||||||
this.noise = new IrisNoiseFactory(data);
|
this.noise = new IrisNoiseFactory(data);
|
||||||
this.irisKinds = Map.of(
|
this.irisKinds = Map.of(
|
||||||
GeneratedObject.class, Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
OBJECTS.id(), Kind.<IrisObject, GeneratedObject>ofLoader(ids, data::getObjectLoader, (id, object) -> object.getGeometry()),
|
||||||
PackBiome.class, Kind.<IrisBiome, PackBiome>ofLoader(ids, data::getBiomeLoader, this::biomeOf),
|
BIOMES.id(), Kind.<IrisBiome, PackBiome>ofLoader(ids, data::getBiomeLoader, this::biomeOf),
|
||||||
PackRegion.class, Kind.<IrisRegion, PackRegion>ofLoader(ids, data::getRegionLoader, this::regionOf));
|
REGIONS.id(), Kind.<IrisRegion, PackRegion>ofLoader(ids, data::getRegionLoader, this::regionOf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,14 +140,14 @@ public final class IrisPackResources implements PackResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked") // The kinds are keyed by the type they serve.
|
@SuppressWarnings("unchecked") // A kind's id names the one kind registered under it, which serves the kind's type.
|
||||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||||
return ((Kind<T>) kindOf(key.type())).find(key.id());
|
return ((Kind<T>) kindOf(kind)).find(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourceId> ids(Class<?> type) {
|
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||||
return kindOf(type).ids();
|
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}. */
|
/** 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;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Kind<?> kindOf(Class<?> type) {
|
private Kind<?> kindOf(ResourceKind<?> kind) {
|
||||||
Kind<?> iris = irisKinds.get(type);
|
Kind<?> iris = irisKinds.get(kind.id());
|
||||||
if (iris != null) {
|
if (iris != null) {
|
||||||
return iris;
|
return iris;
|
||||||
}
|
}
|
||||||
Kind<?> module = moduleKinds().get(type);
|
Kind<?> module = moduleKinds().get(kind.id());
|
||||||
if (module == null) {
|
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;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Class<?>, Kind<?>> moduleKinds() {
|
private Map<ResourceId, Kind<?>> moduleKinds() {
|
||||||
Map<Class<?>, Kind<?>> kinds = moduleKinds;
|
Map<ResourceId, Kind<?>> kinds = moduleKinds;
|
||||||
if (kinds != null) {
|
if (kinds != null) {
|
||||||
return kinds;
|
return kinds;
|
||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (moduleKinds == null) {
|
if (moduleKinds == null) {
|
||||||
Map<Class<?>, Kind<?>> found = new HashMap<>();
|
Map<ResourceId, Kind<?>> found = new HashMap<>();
|
||||||
moduleKindList.get().forEach(kind -> found.put(kind.type(), moduleKind(kind)));
|
moduleKindList.get().forEach(kind -> found.put(kind.id(), moduleKind(kind)));
|
||||||
moduleKinds = Map.copyOf(found);
|
moduleKinds = Map.copyOf(found);
|
||||||
}
|
}
|
||||||
return moduleKinds;
|
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. */
|
/** 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) {
|
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));
|
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) {
|
private PackBiome biomeOf(ResourceId id, IrisBiome biome) {
|
||||||
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
|
return new PackBiome(id, biome.getName(), ResourceId.parse(biome.getDerivativeKey()), ResourceId.parse(biome.getVanillaDerivativeKey()),
|
||||||
biome.getRarity(), idsOf(biome.getChildren()));
|
biome.getRarity(), idsOf(biome.getChildren()));
|
||||||
|
|||||||
@@ -36,13 +36,15 @@ import com.volmit.resource.ResourceId;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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
|
* 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
|
* 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 DIMENSION = "dimension";
|
||||||
static final String REGION = "region";
|
static final String REGION = "region";
|
||||||
static final String BIOME = "biome";
|
static final String BIOME = "biome";
|
||||||
@@ -55,32 +57,31 @@ public final class IrisPackSettings implements PackSettings, ObjectHost.Source,
|
|||||||
this.ids = new PackResourceIds(engine.getData().getDataFolder());
|
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. */
|
/** The engine whose pack is loading. */
|
||||||
public Engine engine() {
|
public Engine engine() {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectHost objects() {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
return HostExtensions.as(type, offered(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** The engine is offered only for the structure built-ins, which drive Iris's structure locator themselves. */
|
||||||
public FloatingHost floating() {
|
private Object offered(Class<?> type) {
|
||||||
return new IrisFloatingHost(engine, IrisApiLogger.hostLog());
|
if (type == Engine.class) {
|
||||||
}
|
return engine;
|
||||||
|
}
|
||||||
@Override
|
if (type == ObjectHost.class) {
|
||||||
public StructureHost structures() {
|
return new IrisObjectHost(engine, IrisApiLogger.hostLog());
|
||||||
return new IrisStructureHost(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
|
@Override
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.LiveWorld;
|
import art.arcane.iris.builtin.LiveWorld;
|
||||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||||
import art.arcane.iris.builtin.structure.StructureHost;
|
import art.arcane.iris.builtin.structure.StructureHost;
|
||||||
@@ -29,47 +30,33 @@ import com.volmit.ModuleLog;
|
|||||||
import com.volmit.config.PackSettings;
|
import com.volmit.config.PackSettings;
|
||||||
import com.volmit.host.WorldStates;
|
import com.volmit.host.WorldStates;
|
||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
import java.util.Map;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.function.Function;
|
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
|
* 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
|
* 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
|
* pack's resources reload under it. Iris's built-in modules reach what they need of Iris through its
|
||||||
* reaches do through {@link IrisPackSettings#of}.
|
* {@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 Engine engine;
|
||||||
private final IrisPackResources resources;
|
private final IrisPackResources resources;
|
||||||
private final WorldStates states;
|
private final WorldStates states;
|
||||||
private final ModuleLog log;
|
private final ModuleLog log;
|
||||||
private final Map<ModuleLog, IrisPackWorld> viewsByLog;
|
|
||||||
private final LiveWorld liveWorld;
|
private final LiveWorld liveWorld;
|
||||||
|
private final IrisSeeds seeds;
|
||||||
private volatile IrisObjectHost objectHost;
|
private volatile IrisObjectHost objectHost;
|
||||||
private volatile IrisFloatingHost floatingHost;
|
private volatile IrisFloatingHost floatingHost;
|
||||||
private volatile IrisStructureHost structureHost;
|
private volatile IrisStructureHost structureHost;
|
||||||
|
|
||||||
IrisPackWorld(Engine engine) {
|
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.engine = engine;
|
||||||
this.resources = resources;
|
this.resources = engine.getData().getPackResources();
|
||||||
this.states = states;
|
this.states = new WorldStates();
|
||||||
this.log = log;
|
this.log = IrisApiLogger.hostLog();
|
||||||
this.viewsByLog = viewsByLog;
|
|
||||||
this.liveWorld = new IrisLiveWorld(engine, resources);
|
this.liveWorld = new IrisLiveWorld(engine, resources);
|
||||||
}
|
this.seeds = this::seedOf;
|
||||||
|
|
||||||
/** 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The engine generating this world. */
|
/** The engine generating this world. */
|
||||||
@@ -107,19 +94,35 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
|||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One view per log, since the services ask for a module's view on every call. */
|
|
||||||
@Override
|
@Override
|
||||||
public IrisPackWorld withLog(ModuleLog log) {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new IrisPackWorld(engine, resources, states, moduleLog, viewsByLog));
|
return HostExtensions.as(type, offered(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** The engine is offered only for the structure built-ins, which drive Iris's structure locator themselves. */
|
||||||
public LiveWorld liveWorld() {
|
private Object offered(Class<?> type) {
|
||||||
return liveWorld;
|
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
|
private long seedOf(IrisSeed seed) {
|
||||||
public long seed(IrisSeed seed) {
|
|
||||||
SeedManager seeds = engine.getSeedManager();
|
SeedManager seeds = engine.getSeedManager();
|
||||||
return switch (seed) {
|
return switch (seed) {
|
||||||
case BIOME -> seeds.getBiome();
|
case BIOME -> seeds.getBiome();
|
||||||
@@ -136,8 +139,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private ObjectHost objects() {
|
||||||
public ObjectHost objects() {
|
|
||||||
IrisObjectHost host = objectHost;
|
IrisObjectHost host = objectHost;
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = new IrisObjectHost(engine, log);
|
host = new IrisObjectHost(engine, log);
|
||||||
@@ -146,8 +148,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
|||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private FloatingHost floating() {
|
||||||
public FloatingHost floating() {
|
|
||||||
IrisFloatingHost host = floatingHost;
|
IrisFloatingHost host = floatingHost;
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = new IrisFloatingHost(engine, log);
|
host = new IrisFloatingHost(engine, log);
|
||||||
@@ -156,8 +157,7 @@ public final class IrisPackWorld implements PackWorld, IrisSeed.Source, LiveWorl
|
|||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private StructureHost structures() {
|
||||||
public StructureHost structures() {
|
|
||||||
IrisStructureHost host = structureHost;
|
IrisStructureHost host = structureHost;
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = new IrisStructureHost(engine, log);
|
host = new IrisStructureHost(engine, log);
|
||||||
|
|||||||
@@ -43,12 +43,11 @@ import com.volmit.resource.PackResources;
|
|||||||
import com.volmit.world.BlockPosition;
|
import com.volmit.world.BlockPosition;
|
||||||
|
|
||||||
import java.util.Optional;
|
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
|
* 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
|
* does not describe, answered to Iris's built-in placement stages as an {@link ObjectPlacement}, the extension of the
|
||||||
* thread while the placement graph runs. Pack modules cannot see this class.
|
* placement invocation. Pack modules cannot see this class.
|
||||||
*/
|
*/
|
||||||
public final class IrisPlacement implements ObjectPlacement {
|
public final class IrisPlacement implements ObjectPlacement {
|
||||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
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);
|
this.terrain = new IrisPlacementTerrain(placer, object.getLoader(), data, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> T runBound(Supplier<T> placement) {
|
|
||||||
return ObjectPlacement.runBound(this, placement);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectShape object() {
|
public ObjectShape object() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
|
import art.arcane.iris.builtin.placement.ObjectPlacement;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import com.volmit.config.FeatureSettings;
|
import com.volmit.config.FeatureSettings;
|
||||||
import com.volmit.mantle.BlockBox;
|
import com.volmit.mantle.BlockBox;
|
||||||
@@ -30,6 +31,7 @@ import com.volmit.world.TerrainSample;
|
|||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
import com.volmit.world.TerrainSampler;
|
import com.volmit.world.TerrainSampler;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -40,14 +42,25 @@ final class IrisPlacementInputs implements PlacementContext {
|
|||||||
private final FeatureSettings settings;
|
private final FeatureSettings settings;
|
||||||
private final BlockView blocks;
|
private final BlockView blocks;
|
||||||
private final Supplier<PackWorld> worldSource;
|
private final Supplier<PackWorld> worldSource;
|
||||||
|
private final ObjectPlacement placement;
|
||||||
private PackWorld world;
|
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.terrain = terrain;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.worldSource = worldSource;
|
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. */
|
/** 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.framework.Engine;
|
||||||
import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
||||||
import com.volmit.ModuleLog;
|
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. */
|
/** Iris's {@link StructureHost}: the engine's {@link StructurePlacing}, one per engine runtime, places and sizes its structures. */
|
||||||
final class IrisStructureHost implements StructureHost {
|
final class IrisStructureHost implements StructureHost {
|
||||||
@@ -34,8 +35,8 @@ final class IrisStructureHost implements StructureHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void placeChunk() {
|
public void placeChunk(InvocationContext context) {
|
||||||
IrisMantleChunk chunk = IrisMantleChunk.current();
|
IrisMantleChunk chunk = context.extension(IrisMantleChunk.class).orElseThrow();
|
||||||
placing().place(chunk.writer(), chunk.chunkX(), chunk.chunkZ(), chunk.context());
|
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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||||
import art.arcane.volmlib.util.matter.Matter;
|
import art.arcane.volmlib.util.matter.Matter;
|
||||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||||
import com.volmit.mantle.BlockBox;
|
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
|
* The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#isCarved}: where the
|
||||||
* planner marked a cavern in the mantle's cavern slice, whatever the cavern holds (air, fluid, lava). Stages only read them.
|
* 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 CHUNK_SHIFT = 4;
|
||||||
private static final int SECTION_SHIFT = 4;
|
private static final int SECTION_SHIFT = 4;
|
||||||
private static final int LOCAL_MASK = 15;
|
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 BlockBox bounds;
|
||||||
private final IrisModuleMantle.Chunks chunks;
|
private final IrisModuleMantle.Chunks chunks;
|
||||||
@@ -49,58 +40,9 @@ final class MantleCaverns implements MantleLayer<Boolean> {
|
|||||||
this.chunks = chunks;
|
this.chunks = chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
boolean isCarved(int x, int y, int z) {
|
||||||
public Boolean get(int x, int y, int z) {
|
|
||||||
requireInside(x, y, z);
|
requireInside(x, y, z);
|
||||||
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z) ? Boolean.TRUE : null;
|
return cavernAt(requireChunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT), x, y, z);
|
||||||
}
|
|
||||||
|
|
||||||
@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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean cavernAt(MantleChunk<Matter> chunk, int x, int y, int 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);
|
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;
|
int chunkZ = z >> CHUNK_SHIFT;
|
||||||
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), chunkX, chunkZ);
|
long seed = ModuleSeeds.chunk(engine.getSeedManager().getSeed(), chunkX, chunkZ);
|
||||||
try (PinnedMantleChunks mantle = new PinnedMantleChunks(engine)) {
|
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,
|
IrisGenerationContext inputs = new IrisGenerationContext(engine, x, z, blocks, new PlatformBlockStates(platformStates), mantle,
|
||||||
pack.catalog().mantle());
|
pack.catalog().mantle(), irisChunk);
|
||||||
StageMetrics metrics = new StageMetrics(engine.getMetrics());
|
new ChunkRunner(chunk).generate(inputs, seed, new StageMetrics(engine.getMetrics()));
|
||||||
new IrisChunk(engine, x, z, blocks, biomes, multicore, context).runBound(() -> new ChunkRunner(chunk).generate(inputs, seed, metrics));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,12 +112,16 @@ public final class ModuleMantleComponent implements MantleComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
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) {
|
* Runs the stage for chunk {@code x}, {@code z}, with the mantle chunks within the stage's reach of it and
|
||||||
IrisMantleGenerationContext inputs = new IrisMantleGenerationContext(engine, x, z, reachBlocks, chunks, pack.catalog().mantle());
|
* {@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),
|
runner.generate(stage.stage(), inputs, ModuleSeeds.chunk(engine.getSeedManager().getSeed(), x, z),
|
||||||
new StageMetrics(engine.getMetrics()));
|
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) {
|
try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) {
|
||||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area),
|
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area),
|
||||||
new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source),
|
new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source),
|
||||||
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld);
|
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld,
|
||||||
PlacementOutcome outcome = placement.runBound(() -> new PlacementRunner(graph)
|
placement);
|
||||||
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics));
|
PlacementOutcome outcome = new PlacementRunner(graph)
|
||||||
|
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics);
|
||||||
return outcome.isPlaced()
|
return outcome.isPlaced()
|
||||||
? ObjectPlacementResult.placed(placement.anchorY())
|
? ObjectPlacementResult.placed(placement.anchorY())
|
||||||
: ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
: ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.volmit.host.FeatureCatalog;
|
|||||||
import com.volmit.host.ServiceRegistration;
|
import com.volmit.host.ServiceRegistration;
|
||||||
import com.volmit.entity.EntitySpec;
|
import com.volmit.entity.EntitySpec;
|
||||||
import com.volmit.item.ItemDrop;
|
import com.volmit.item.ItemDrop;
|
||||||
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.AmbientEffects;
|
import com.volmit.service.AmbientEffects;
|
||||||
import com.volmit.service.BlockDrops;
|
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. */
|
/** 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) {
|
public static Set<String> objectsAt(Engine engine, int chunkX, int chunkZ) {
|
||||||
|
IrisPackResources resources = engine.getData().getPackResources();
|
||||||
Set<String> keys = new LinkedHashSet<>();
|
Set<String> keys = new LinkedHashSet<>();
|
||||||
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
|
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;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The biomes and regions of the engine's layout that every module says place the object {@code objectKey}. */
|
/** The keys of 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) {
|
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> biomes = new LinkedHashSet<>();
|
||||||
Set<String> regions = new LinkedHashSet<>();
|
Set<String> regions = new LinkedHashSet<>();
|
||||||
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
|
for (Provider<ObjectsAt> provider : providers(engine, ObjectsAt.class)) {
|
||||||
ObjectsAt.PlacedBy placedBy = provider.service().placedBy(provider.world(), objectKey);
|
ObjectsAt.PlacedBy placedBy = provider.service().placedBy(provider.world(), object);
|
||||||
biomes.addAll(placedBy.biomes());
|
placedBy.biomes().forEach(id -> biomes.add(resources.keyOf(PackResources.BIOMES, id)));
|
||||||
regions.addAll(placedBy.regions());
|
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. */
|
/** 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;
|
return tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The items loot table {@code key} gives at {@code site}, from the module that knows the table. */
|
/** 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, String key) {
|
public static List<ItemDrop> lootItems(Engine engine, Loot.Site site, ResourceId table) {
|
||||||
List<ItemDrop> items = new ArrayList<>();
|
List<ItemDrop> items = new ArrayList<>();
|
||||||
for (Provider<Loot> provider : providers(engine, Loot.class)) {
|
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;
|
return items;
|
||||||
}
|
}
|
||||||
@@ -160,8 +168,8 @@ public final class ModuleServices {
|
|||||||
|
|
||||||
/** The objects every module places as trees. */
|
/** The objects every module places as trees. */
|
||||||
public static SaplingGrowth.TreeObjects treeObjects(Engine engine) {
|
public static SaplingGrowth.TreeObjects treeObjects(Engine engine) {
|
||||||
Set<String> objects = new LinkedHashSet<>();
|
Set<ResourceId> objects = new LinkedHashSet<>();
|
||||||
Set<String> procedural = new LinkedHashSet<>();
|
Set<ResourceId> procedural = new LinkedHashSet<>();
|
||||||
for (Provider<SaplingGrowth> provider : providers(engine, SaplingGrowth.class)) {
|
for (Provider<SaplingGrowth> provider : providers(engine, SaplingGrowth.class)) {
|
||||||
SaplingGrowth.TreeObjects trees = provider.service().treeObjects(provider.world());
|
SaplingGrowth.TreeObjects trees = provider.service().treeObjects(provider.world());
|
||||||
objects.addAll(trees.objects());
|
objects.addAll(trees.objects());
|
||||||
@@ -181,10 +189,11 @@ public final class ModuleServices {
|
|||||||
return Optional.empty();
|
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) {
|
public static Optional<EntitySpec> entity(Engine engine, String key) {
|
||||||
|
ResourceId id = engine.getData().getPackResources().idOf(key);
|
||||||
for (Provider<EntitySpawns> provider : providers(engine, EntitySpawns.class)) {
|
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()) {
|
if (entity.isPresent()) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
@@ -223,7 +232,7 @@ public final class ModuleServices {
|
|||||||
public static Set<String> structureKeys(IrisData data) {
|
public static Set<String> structureKeys(IrisData data) {
|
||||||
Set<String> keys = new LinkedHashSet<>();
|
Set<String> keys = new LinkedHashSet<>();
|
||||||
for (StructureLocator provider : catalog(data).services(StructureLocator.class)) {
|
for (StructureLocator provider : catalog(data).services(StructureLocator.class)) {
|
||||||
keys.addAll(provider.structures(data.getPackResources()));
|
keys.addAll(structureKeysOf(data, provider.structures(data.getPackResources())));
|
||||||
}
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
@@ -232,7 +241,7 @@ public final class ModuleServices {
|
|||||||
public static Set<String> locatableStructures(Engine engine) {
|
public static Set<String> locatableStructures(Engine engine) {
|
||||||
Set<String> keys = new LinkedHashSet<>();
|
Set<String> keys = new LinkedHashSet<>();
|
||||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
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;
|
return keys;
|
||||||
}
|
}
|
||||||
@@ -249,7 +258,7 @@ public final class ModuleServices {
|
|||||||
public static Set<String> placedStructures(Engine engine) {
|
public static Set<String> placedStructures(Engine engine) {
|
||||||
Set<String> keys = new LinkedHashSet<>();
|
Set<String> keys = new LinkedHashSet<>();
|
||||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
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;
|
return keys;
|
||||||
}
|
}
|
||||||
@@ -265,7 +274,8 @@ public final class ModuleServices {
|
|||||||
*/
|
*/
|
||||||
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
public static StructureSearch locateStructure(Engine engine, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
||||||
LocateResult result = structureLocatorOf(engine, key, StructureLocator::placed)
|
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);
|
.orElse(LocateResult.NOT_FOUND);
|
||||||
return StructureSearch.of(result, engine);
|
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,
|
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()) {
|
if (key == null || key.isBlank()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
String wanted = normalized(key);
|
ResourceId wanted = structureIdOf(engine.getData(), key);
|
||||||
for (Provider<StructureLocator> provider : providers(engine, StructureLocator.class)) {
|
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.of(provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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. */
|
/** 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) {
|
private static Set<String> platformStructures(Engine engine, BiFunction<VanillaStructures, PackWorld, Set<ResourceId>> structures) {
|
||||||
Set<String> keys = new LinkedHashSet<>();
|
Set<String> keys = new LinkedHashSet<>();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
|||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
import com.volmit.config.LinkedBiomes;
|
import com.volmit.config.LinkedBiomes;
|
||||||
import com.volmit.host.ConfiguredSettings;
|
import com.volmit.host.ConfiguredSettings;
|
||||||
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -60,21 +61,24 @@ public final class ModuleSettings {
|
|||||||
return values.isEmpty();
|
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() {
|
* The keys of the biomes these settings add to the biome tree of the owner's regions ({@link LinkedBiomes#treeBiomes}),
|
||||||
return linkedBiomes(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
|
* @param dimension the settings of the dimension the owner is part of
|
||||||
*/
|
*/
|
||||||
public Set<String> usedBiomes(ModuleSettings dimension) {
|
public Set<String> usedBiomes(IrisPackResources resources, ModuleSettings dimension) {
|
||||||
return linkedBiomes(linked -> linked.usedBiomes(dimension.values()));
|
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()) {
|
if (values.isEmpty()) {
|
||||||
return Set.of();
|
return Set.of();
|
||||||
}
|
}
|
||||||
@@ -82,7 +86,7 @@ public final class ModuleSettings {
|
|||||||
values.values().stream()
|
values.values().stream()
|
||||||
.filter(LinkedBiomes.class::isInstance)
|
.filter(LinkedBiomes.class::isInstance)
|
||||||
.sorted(Comparator.comparing(value -> value.getClass().getName()))
|
.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;
|
return biomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
import com.volmit.config.Level;
|
import com.volmit.config.Level;
|
||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
import com.volmit.block.BlockState;
|
import com.volmit.block.BlockState;
|
||||||
import com.volmit.config.OptionsMetadata;
|
|
||||||
import com.volmit.config.Snippet;
|
import com.volmit.config.Snippet;
|
||||||
import com.volmit.host.FeatureCatalog;
|
import com.volmit.host.FeatureCatalog;
|
||||||
import com.volmit.host.FeatureDescriptor;
|
import com.volmit.host.FeatureDescriptor;
|
||||||
import com.volmit.host.ObjectRegistration;
|
import com.volmit.host.ObjectRegistration;
|
||||||
|
import com.volmit.host.OptionsMetadata;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -83,9 +83,10 @@ public final class ModuleSettingsDecoder {
|
|||||||
ModuleSettingsDecoder(FeatureCatalog catalog, Path packFolder, Supplier<Gson> irisGson) {
|
ModuleSettingsDecoder(FeatureCatalog catalog, Path packFolder, Supplier<Gson> irisGson) {
|
||||||
this.packFolder = packFolder;
|
this.packFolder = packFolder;
|
||||||
this.irisGson = irisGson;
|
this.irisGson = irisGson;
|
||||||
|
PackResourceIds packIds = new PackResourceIds(packFolder.toFile());
|
||||||
this.gson = new GsonBuilder()
|
this.gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(BlockState.class, textAdapter(BlockState::parse, BlockState::key))
|
.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 HostTypes())
|
||||||
.registerTypeAdapterFactory(new SnippetReferences())
|
.registerTypeAdapterFactory(new SnippetReferences())
|
||||||
.create();
|
.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. */
|
/** 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) {
|
public Set<String> keys(Level target) {
|
||||||
return keys.get(target);
|
return keys.get(target);
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import com.volmit.resource.ResourceId;
|
|||||||
import com.volmit.service.VanillaStructures;
|
import com.volmit.service.VanillaStructures;
|
||||||
import com.volmit.vanilla.DecorationStep;
|
import com.volmit.vanilla.DecorationStep;
|
||||||
import com.volmit.vanilla.PieceKind;
|
import com.volmit.vanilla.PieceKind;
|
||||||
|
import com.volmit.vanilla.StartKey;
|
||||||
import com.volmit.vanilla.StartMemo;
|
import com.volmit.vanilla.StartMemo;
|
||||||
import com.volmit.vanilla.StructureFit;
|
import com.volmit.vanilla.StructureFit;
|
||||||
import com.volmit.vanilla.TemplateCells;
|
import com.volmit.vanilla.TemplateCells;
|
||||||
@@ -51,12 +52,14 @@ import com.volmit.world.BlockPosition;
|
|||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Supplier;
|
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.
|
* states and back through caches, so a provider can read and write blocks without allocating per block.
|
||||||
*/
|
*/
|
||||||
public final class ModuleStructureFitting implements NativeStructureFitting {
|
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<Object, BlockState> API_STATES = new ConcurrentHashMap<>();
|
||||||
private static final Map<BlockState, Object> NATIVE_STATES = new ConcurrentHashMap<>();
|
private static final Map<BlockState, Object> NATIVE_STATES = new ConcurrentHashMap<>();
|
||||||
private static final Map<Object, Integer> NATIVE_TRAITS = new ConcurrentHashMap<>();
|
private static final Map<Object, Integer> NATIVE_TRAITS = new ConcurrentHashMap<>();
|
||||||
@@ -360,8 +365,8 @@ public final class ModuleStructureFitting implements NativeStructureFitting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object key() {
|
public StartKey key() {
|
||||||
return start.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
|
@Override
|
||||||
public MantleLayer<Boolean> caverns() {
|
public boolean isCarved(int x, int y, int z) {
|
||||||
return new StoredRange<>(placement.caverns());
|
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
|
@Override
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import com.volmit.host.WorldStates;
|
|||||||
import com.volmit.resource.PackResources;
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,20 +37,13 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
|||||||
private final PackSettings settings;
|
private final PackSettings settings;
|
||||||
private final WorldStates states;
|
private final WorldStates states;
|
||||||
private final ModuleLog log;
|
private final ModuleLog log;
|
||||||
private final Map<ModuleLog, ToolWorld> viewsByLog;
|
|
||||||
|
|
||||||
ToolWorld(long seed, PackResources resources, PackSettings settings) {
|
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.seed = seed;
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.states = states;
|
this.states = new WorldStates();
|
||||||
this.log = log;
|
this.log = IrisApiLogger.hostLog();
|
||||||
this.viewsByLog = viewsByLog;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,11 +71,6 @@ final class ToolWorld implements PackWorld, AutoCloseable {
|
|||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackWorld withLog(ModuleLog log) {
|
|
||||||
return viewsByLog.computeIfAbsent(log, moduleLog -> new ToolWorld(seed, resources, settings, states, moduleLog, viewsByLog));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
states.close();
|
states.close();
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ public final class ModuleResourceClosure {
|
|||||||
private Object lookup(ResourceKind<?> kind, String key) {
|
private Object lookup(ResourceKind<?> kind, String key) {
|
||||||
IrisPackResources resources = data.getPackResources();
|
IrisPackResources resources = data.getPackResources();
|
||||||
try {
|
try {
|
||||||
return resources.find(kind.key(resources.idOf(key))).orElse(null);
|
return resources.find(kind, resources.idOf(key)).orElse(null);
|
||||||
} catch (IllegalStateException failedToLoad) {
|
} catch (IllegalStateException failedToLoad) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ public class SchemaBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PackResourceList putModuleResourceRef(JSONObject property, ResourceKind<?> kind) {
|
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);
|
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.core.modules.ModuleServices;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||||
|
import com.volmit.resource.PackResources;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.SaplingGrowth;
|
import com.volmit.service.SaplingGrowth;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -10,17 +12,19 @@ import java.util.Set;
|
|||||||
public final class TreeDefinitionIndex {
|
public final class TreeDefinitionIndex {
|
||||||
private static final String PROCEDURAL_TREE_PREFIX = "procedural/tree/";
|
private static final String PROCEDURAL_TREE_PREFIX = "procedural/tree/";
|
||||||
|
|
||||||
private final Set<String> explicitObjectKeys;
|
private final PackResources resources;
|
||||||
private final Set<String> proceduralTreeKeys;
|
private final Set<ResourceId> explicitObjects;
|
||||||
|
private final Set<ResourceId> proceduralTrees;
|
||||||
|
|
||||||
private TreeDefinitionIndex(Set<String> explicitObjectKeys, Set<String> proceduralTreeKeys) {
|
private TreeDefinitionIndex(PackResources resources, Set<ResourceId> explicitObjects, Set<ResourceId> proceduralTrees) {
|
||||||
this.explicitObjectKeys = Set.copyOf(explicitObjectKeys);
|
this.resources = resources;
|
||||||
this.proceduralTreeKeys = Set.copyOf(proceduralTreeKeys);
|
this.explicitObjects = Set.copyOf(explicitObjects);
|
||||||
|
this.proceduralTrees = Set.copyOf(proceduralTrees);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeDefinitionIndex build(Engine engine) {
|
public static TreeDefinitionIndex build(Engine engine) {
|
||||||
SaplingGrowth.TreeObjects trees = ModuleServices.treeObjects(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) {
|
public boolean isTreeMarker(String marker) {
|
||||||
@@ -31,11 +35,11 @@ public final class TreeDefinitionIndex {
|
|||||||
|
|
||||||
String objectKey = decoded.objectKey();
|
String objectKey = decoded.objectKey();
|
||||||
if (objectKey.startsWith(PROCEDURAL_TREE_PREFIX)) {
|
if (objectKey.startsWith(PROCEDURAL_TREE_PREFIX)) {
|
||||||
return proceduralTreeKeys.contains(objectKey);
|
return proceduralTrees.contains(resources.idOf(objectKey));
|
||||||
}
|
}
|
||||||
if (objectKey.startsWith("procedural/")) {
|
if (objectKey.startsWith("procedural/")) {
|
||||||
return false;
|
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.iris.util.common.scheduling.J;
|
||||||
import art.arcane.volmlib.util.collection.KMap;
|
import art.arcane.volmlib.util.collection.KMap;
|
||||||
import art.arcane.volmlib.util.collection.KSet;
|
import art.arcane.volmlib.util.collection.KSet;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.EntitySpawns;
|
import com.volmit.service.EntitySpawns;
|
||||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@@ -53,7 +54,7 @@ final class MarkerSpawnScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A spawner a marker names, and the marker. */
|
/** 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) {
|
Map<IrisPosition, List<MarkerSpawner>> getSpawnersFromMarkers(Chunk c) {
|
||||||
@@ -80,7 +81,7 @@ final class MarkerSpawnScanner {
|
|||||||
return;
|
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));
|
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());
|
MarkerSpawnData data = markerData.computeIfAbsent(position, k -> new MarkerSpawnData());
|
||||||
data.requiresEmptyAbove = data.requiresEmptyAbove || rule.get().emptyAbove();
|
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));
|
addOnce(data.spawners, new MarkerSpawner(t.getTag(), spawner));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ public final class HintedLocator<T> implements Locator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IrisComplex complex = engine.getComplex();
|
IrisComplex complex = engine.getComplex();
|
||||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, objectKey);
|
ModuleServices.ObjectPlacers placers = ModuleServices.objectPlacers(engine, objectKey);
|
||||||
BiomeSource source = new BiomeSource(engine);
|
BiomeSource source = new BiomeSource(engine);
|
||||||
KSet<String> landHosts = new KSet<>();
|
KSet<String> landHosts = new KSet<>();
|
||||||
KSet<String> seaHosts = 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 art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||||
import com.volmit.entity.EntitySpec;
|
import com.volmit.entity.EntitySpec;
|
||||||
import com.volmit.item.ItemAttribute;
|
import com.volmit.item.ItemAttribute;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.Loot;
|
import com.volmit.service.Loot;
|
||||||
import com.volmit.world.BlockPosition;
|
import com.volmit.world.BlockPosition;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -67,6 +68,7 @@ import org.bukkit.util.Vector;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@@ -141,8 +143,8 @@ public final class BukkitEntitySpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e instanceof Panda panda) {
|
if (e instanceof Panda panda) {
|
||||||
panda.setMainGene(resolveGene(spec.pandaMainGene()));
|
panda.setMainGene(resolveGene(spec.pandaMainGene().orElse(null)));
|
||||||
panda.setHiddenGene(resolveGene(spec.pandaHiddenGene()));
|
panda.setHiddenGene(resolveGene(spec.pandaHiddenGene().orElse(null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e instanceof Villager villager) {
|
if (e instanceof Villager villager) {
|
||||||
@@ -154,9 +156,7 @@ public final class BukkitEntitySpawner {
|
|||||||
mob.setAware(spec.flags().aware());
|
mob.setAware(spec.flags().aware());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spec.spawnEffect() != null) {
|
spec.spawnEffect().ifPresent(effect -> showSpawnEffect(e, effect));
|
||||||
showSpawnEffect(e, spec.spawnEffect());
|
|
||||||
}
|
|
||||||
|
|
||||||
runCommands(spec, at);
|
runCommands(spec, at);
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ public final class BukkitEntitySpawner {
|
|||||||
|
|
||||||
private static void applyFlags(Entity e, EntitySpec spec) {
|
private static void applyFlags(Entity e, EntitySpec spec) {
|
||||||
EntitySpec.Flags flags = spec.flags();
|
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.setCustomNameVisible(flags.customNameVisible());
|
||||||
e.setGlowing(flags.glowing());
|
e.setGlowing(flags.glowing());
|
||||||
e.setGravity(flags.gravity());
|
e.setGravity(flags.gravity());
|
||||||
@@ -219,31 +219,17 @@ public final class BukkitEntitySpawner {
|
|||||||
l.setAI(spec.flags().ai());
|
l.setAI(spec.flags().ai());
|
||||||
l.setCanPickupItems(spec.flags().pickupItems());
|
l.setCanPickupItems(spec.flags().pickupItems());
|
||||||
|
|
||||||
if (spec.leashHolder() != null) {
|
spec.leashHolder().ifPresent(holder -> l.setLeashHolder(spawn(gen, holder, at)));
|
||||||
l.setLeashHolder(spawn(gen, spec.leashHolder(), at));
|
|
||||||
}
|
|
||||||
|
|
||||||
l.setRemoveWhenFarAway(spec.flags().removable());
|
l.setRemoveWhenFarAway(spec.flags().removable());
|
||||||
|
|
||||||
EntitySpec.Equipment equipment = spec.equipment();
|
EntitySpec.Equipment equipment = spec.equipment();
|
||||||
if (equipment.helmet() != null) {
|
equipment.helmet().ifPresent(item -> l.getEquipment().setHelmet(BukkitItemStacks.create(item)));
|
||||||
l.getEquipment().setHelmet(BukkitItemStacks.create(equipment.helmet()));
|
equipment.chestplate().ifPresent(item -> l.getEquipment().setChestplate(BukkitItemStacks.create(item)));
|
||||||
}
|
equipment.leggings().ifPresent(item -> l.getEquipment().setLeggings(BukkitItemStacks.create(item)));
|
||||||
if (equipment.chestplate() != null) {
|
equipment.boots().ifPresent(item -> l.getEquipment().setBoots(BukkitItemStacks.create(item)));
|
||||||
l.getEquipment().setChestplate(BukkitItemStacks.create(equipment.chestplate()));
|
equipment.mainHand().ifPresent(item -> l.getEquipment().setItemInMainHand(BukkitItemStacks.create(item)));
|
||||||
}
|
equipment.offHand().ifPresent(item -> l.getEquipment().setItemInOffHand(BukkitItemStacks.create(item)));
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void runCommands(EntitySpec spec, Location at) {
|
private static void runCommands(EntitySpec spec, Location at) {
|
||||||
@@ -338,7 +324,7 @@ public final class BukkitEntitySpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (spec.isSpecial()) {
|
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));
|
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. */
|
/** The platform's entity type of the spec, unknown when it names none. */
|
||||||
public static EntityType bukkitType(EntitySpec spec) {
|
public static EntityType bukkitType(EntitySpec spec) {
|
||||||
if (spec.type().isBlank()) {
|
String type = spec.type().orElse("");
|
||||||
|
if (type.isBlank()) {
|
||||||
return EntityType.UNKNOWN;
|
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) {
|
if (key == null) {
|
||||||
return EntityType.UNKNOWN;
|
return EntityType.UNKNOWN;
|
||||||
}
|
}
|
||||||
@@ -360,12 +347,13 @@ public final class BukkitEntitySpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static CreatureSpawnEvent.SpawnReason bukkitReason(EntitySpec spec) {
|
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;
|
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return CreatureSpawnEvent.SpawnReason.valueOf(spec.reason().trim().toUpperCase(Locale.ROOT));
|
return CreatureSpawnEvent.SpawnReason.valueOf(reason.trim().toUpperCase(Locale.ROOT));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
||||||
}
|
}
|
||||||
@@ -385,8 +373,8 @@ public final class BukkitEntitySpawner {
|
|||||||
|
|
||||||
private static void showSpawnEffect(Entity p, EntitySpec.SpawnEffect fx) {
|
private static void showSpawnEffect(Entity p, EntitySpec.SpawnEffect fx) {
|
||||||
J.runEntity(p, () -> {
|
J.runEntity(p, () -> {
|
||||||
Sound soundType = fx.sound() == null ? null : resolveKeyed(Sound.class, fx.sound());
|
Sound soundType = fx.sound().map(sound -> resolveKeyed(Sound.class, sound)).orElse(null);
|
||||||
Particle particleType = fx.particle() == null ? null : resolveKeyed(Particle.class, fx.particle());
|
Particle particleType = fx.particle().map(particle -> resolveKeyed(Particle.class, particle)).orElse(null);
|
||||||
if (soundType != 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()));
|
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()));
|
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
|
@Override
|
||||||
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
|
public Collection<ItemStack> populateLoot(Random random, LootContext context) {
|
||||||
BlockPosition position = new BlockPosition(finalAt.getBlockX(), finalAt.getBlockY() - gen.getMinHeight(), finalAt.getBlockZ());
|
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<>();
|
KList<ItemStack> items = new KList<>();
|
||||||
|
|
||||||
for (String table : spec.lootTables()) {
|
for (ResourceId table : spec.lootTables()) {
|
||||||
items.addAll(BukkitItemStacks.createAll(ModuleServices.lootItems(gen, site, table)));
|
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.lang.reflect.Method;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -420,9 +421,9 @@ public final class EngineBukkitOps {
|
|||||||
private static Loot.Site lootSite(Engine engine, Block b, boolean nativeLootDefined) {
|
private static Loot.Site lootSite(Engine engine, Block b, boolean nativeLootDefined) {
|
||||||
BlockPosition position = new BlockPosition(b.getX(), b.getY() - engine.getMinHeight(), b.getZ());
|
BlockPosition position = new BlockPosition(b.getX(), b.getY() - engine.getMinHeight(), b.getZ());
|
||||||
BlockData data = b.getBlockData();
|
BlockData data = b.getBlockData();
|
||||||
com.volmit.block.BlockState container = BukkitBlockResolution.isStorageChest(data)
|
Optional<com.volmit.block.BlockState> container = BukkitBlockResolution.isStorageChest(data)
|
||||||
? com.volmit.block.BlockState.parse(PlatformBlockStates.namespaced(BukkitBlockState.of(data).key()))
|
? Optional.of(com.volmit.block.BlockState.parse(PlatformBlockStates.namespaced(BukkitBlockState.of(data).key())))
|
||||||
: null;
|
: Optional.empty();
|
||||||
return new Loot.Site(position, container, nativeLootDefined, false);
|
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. */
|
/** 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) {
|
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<>();
|
List<ItemStack> items = new KList<>();
|
||||||
for (Loot.Source source : tables) {
|
for (Loot.Source source : tables) {
|
||||||
switch (source) {
|
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));
|
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) {
|
private static void playOnEntityThread(Player player, Engine engine, AmbientEffects.Effect effect) {
|
||||||
if (effect.sound() != null) {
|
effect.sound().ifPresent(sound -> playSound(player, sound));
|
||||||
playSound(player, effect.sound());
|
effect.particles().ifPresent(particles -> showParticles(player, engine, particles));
|
||||||
}
|
|
||||||
if (effect.particles() != null) {
|
|
||||||
showParticles(player, engine, effect.particles());
|
|
||||||
}
|
|
||||||
effect.commands().forEach(command -> runCommand(player, command));
|
effect.commands().forEach(command -> runCommand(player, command));
|
||||||
if (effect.potion() != null) {
|
effect.potion().ifPresent(potion -> givePotion(player, potion));
|
||||||
givePotion(player, effect.potion());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void playSound(Player player, AmbientEffects.Sound sound) {
|
private static void playSound(Player player, AmbientEffects.Sound sound) {
|
||||||
|
|||||||
@@ -114,19 +114,19 @@ public final class BukkitItemStacks {
|
|||||||
meta.setUnbreakable(drop.unbreakable());
|
meta.setUnbreakable(drop.unbreakable());
|
||||||
flags(drop).forEach(meta::addItemFlags);
|
flags(drop).forEach(meta::addItemFlags);
|
||||||
|
|
||||||
if (drop.customModel() != null) {
|
if (drop.customModel().isPresent()) {
|
||||||
CustomModelDataComponent customModelData = meta.getCustomModelDataComponent();
|
CustomModelDataComponent customModelData = meta.getCustomModelDataComponent();
|
||||||
customModelData.setFloats(List.of(drop.customModel().floatValue()));
|
customModelData.setFloats(List.of((float) drop.customModel().getAsInt()));
|
||||||
meta.setCustomModelDataComponent(customModelData);
|
meta.setCustomModelDataComponent(customModelData);
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxDurability = stack.getType().getMaxDurability();
|
int maxDurability = stack.getType().getMaxDurability();
|
||||||
if (drop.damage() != null && maxDurability > 0 && meta instanceof Damageable damageable) {
|
if (drop.damage().isPresent() && maxDurability > 0 && meta instanceof Damageable damageable) {
|
||||||
damageable.setDamage((int) Math.round(Math.max(0, Math.min(maxDurability, drop.damage() * maxDurability))));
|
damageable.setDamage((int) Math.round(Math.max(0, Math.min(maxDurability, drop.damage().getAsDouble() * maxDurability))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drop.leatherColor() != null && meta instanceof LeatherArmorMeta leather) {
|
if (drop.leatherColor().isPresent() && meta instanceof LeatherArmorMeta leather) {
|
||||||
Color c = Color.decode(drop.leatherColor());
|
Color c = Color.decode(drop.leatherColor().get());
|
||||||
leather.setColor(org.bukkit.Color.fromRGB(c.getRed(), c.getGreen(), c.getBlue()));
|
leather.setColor(org.bukkit.Color.fromRGB(c.getRed(), c.getGreen(), c.getBlue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,9 +135,7 @@ public final class BukkitItemStacks {
|
|||||||
colorable.setColor(dye);
|
colorable.setColor(dye);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drop.displayName() != null) {
|
drop.displayName().ifPresent(name -> meta.setDisplayName(C.translateAlternateColorCodes('&', name)));
|
||||||
meta.setDisplayName(C.translateAlternateColorCodes('&', drop.displayName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.setLore(lore(drop));
|
meta.setLore(lore(drop));
|
||||||
return meta;
|
return meta;
|
||||||
@@ -185,11 +183,11 @@ public final class BukkitItemStacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static DyeColor dyeColor(ItemDrop drop) {
|
private static DyeColor dyeColor(ItemDrop drop) {
|
||||||
if (drop.dyeColor() == null) {
|
if (drop.dyeColor().isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return DyeColor.valueOf(drop.dyeColor());
|
return DyeColor.valueOf(drop.dyeColor().get());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -207,9 +205,7 @@ public final class BukkitItemStacks {
|
|||||||
lore.add(colored);
|
lore.add(colored);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (drop.source() != null) {
|
drop.source().ifPresent(source -> addSourceLore(lore, source));
|
||||||
addSourceLore(lore, drop.source());
|
|
||||||
}
|
|
||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,12 +213,12 @@ public final class BukkitItemStacks {
|
|||||||
if (lore.isNotEmpty()) {
|
if (lore.isNotEmpty()) {
|
||||||
lore.add(LORE_RULE);
|
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) + ")");
|
lore.add(C.GRAY + "1 in " + source.entryRarity() + " Chance (" + Form.pc(1D / source.entryRarity(), CHANCE_DIGITS) + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long combined = (long) source.tableRarity() * source.entryRarity();
|
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) + ")");
|
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.loader.IrisData;
|
||||||
import art.arcane.iris.core.modules.PackModulesException;
|
import art.arcane.iris.core.modules.PackModulesException;
|
||||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
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.spi.IrisPlatforms;
|
||||||
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
||||||
import art.arcane.volmlib.util.collection.KList;
|
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. */
|
/** 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) {
|
private static void addEntityKeys(Set<String> keys, IrisData data) {
|
||||||
try {
|
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) {
|
} catch (PackModulesException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import org.junit.rules.TemporaryFolder;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -133,9 +134,9 @@ public class BuiltInModulesJarServicesTest {
|
|||||||
try (LoadedPack loaded = load()) {
|
try (LoadedPack loaded = load()) {
|
||||||
Loot loot = loaded.catalog().services(Loot.class).getFirst();
|
Loot loot = loaded.catalog().services(Loot.class).getFirst();
|
||||||
|
|
||||||
List<Loot.Source> tables = loot.tables(world, new Loot.Site(AT, null, false, false));
|
List<Loot.Source> tables = loot.tables(world, new Loot.Site(AT, Optional.empty(), false, false));
|
||||||
|
|
||||||
assertEquals(List.of(new Loot.Table("dungeon/chest")), tables);
|
assertEquals(List.of(new Loot.Table(world.resources().idOf("dungeon/chest"))), tables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,8 +186,9 @@ public class CarveSettingsDecodingTest {
|
|||||||
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"carvingBiome\": \"carving/mushroom\"}"), "biome test");
|
ModuleSettings settings = decoder.decode(Level.BIOME, new JSONObject("{\"carvingBiome\": \"carving/mushroom\"}"), "biome test");
|
||||||
|
|
||||||
assertEquals("carving/mushroom", settings.find(CarvingBiomeSettings.class).orElseThrow().biome());
|
assertEquals("carving/mushroom", settings.find(CarvingBiomeSettings.class).orElseThrow().biome());
|
||||||
assertEquals(Set.of("carving/mushroom"), settings.treeBiomes());
|
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||||
assertEquals(Set.of(), settings.usedBiomes(ModuleSettings.NONE));
|
assertEquals(Set.of("carving/mushroom"), settings.treeBiomes(resources));
|
||||||
|
assertEquals(Set.of(), settings.usedBiomes(resources, ModuleSettings.NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
import art.arcane.iris.core.loader.ResourceLoader;
|
import art.arcane.iris.core.loader.ResourceLoader;
|
||||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||||
@@ -40,7 +41,7 @@ import com.volmit.item.ItemRegistry;
|
|||||||
import com.volmit.noise.NoiseFactory;
|
import com.volmit.noise.NoiseFactory;
|
||||||
import com.volmit.resource.PackResources;
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.resource.ResourceKey;
|
import com.volmit.resource.ResourceKind;
|
||||||
import com.volmit.world.PackBiome;
|
import com.volmit.world.PackBiome;
|
||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
import com.volmit.object.BlockEntityData;
|
import com.volmit.object.BlockEntityData;
|
||||||
@@ -62,7 +63,7 @@ import static org.mockito.Mockito.when;
|
|||||||
* own noise over an empty pack, a few blocks by name and the world's seeds, all in memory, so the module is tested through IrisApi alone.
|
* own noise over an empty pack, a few blocks by name and the world's seeds, all in memory, so the module is tested through IrisApi alone.
|
||||||
* Biomes and regions have the ids {@code test:<key>}; a declaration made for {@code <key>} has the source {@code test:<kind>/<key>}.
|
* Biomes and regions have the ids {@code test:<key>}; a declaration made for {@code <key>} has the source {@code test:<kind>/<key>}.
|
||||||
*/
|
*/
|
||||||
public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
public final class CarveTestWorld implements PackWorld {
|
||||||
public static final String NAMESPACE = "test";
|
public static final String NAMESPACE = "test";
|
||||||
public static final int MIN_HEIGHT = -64;
|
public static final int MIN_HEIGHT = -64;
|
||||||
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
|
private static final Set<String> AIRS = Set.of("minecraft:air", "minecraft:cave_air", "minecraft:void_air");
|
||||||
@@ -149,13 +150,9 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PackWorld withLog(ModuleLog log) {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return this;
|
IrisSeeds seeds = seed -> seed == IrisSeed.CARVE ? carveSeed : carveSeed + seed.ordinal();
|
||||||
}
|
return type == IrisSeeds.class ? Optional.of(type.cast(seeds)) : Optional.empty();
|
||||||
|
|
||||||
@Override
|
|
||||||
public long seed(IrisSeed seed) {
|
|
||||||
return seed == IrisSeed.CARVE ? carveSeed : carveSeed + seed.ordinal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -196,17 +193,16 @@ public final class CarveTestWorld implements PackWorld, IrisSeed.Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
if (!kind.equals(BIOMES)) {
|
||||||
if (key.type() != PackBiome.class) {
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return Optional.ofNullable((T) biomes.get(key.id()));
|
return Optional.ofNullable(kind.type().cast(biomes.get(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourceId> ids(Class<?> type) {
|
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||||
return type == PackBiome.class ? biomes.keySet().stream().sorted().toList() : List.of();
|
return kind.equals(BIOMES) ? biomes.keySet().stream().sorted().toList() : List.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ public class DimensionBottomTest {
|
|||||||
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
graph.define(Stage.placement("test:bottom/placement")).run(context -> {
|
||||||
record(context.terrain());
|
record(context.terrain());
|
||||||
viewBounds.add(context.access().bounds());
|
viewBounds.add(context.access().bounds());
|
||||||
ObjectPlacement.current().anchoredAt(BOTTOM);
|
context.extension(ObjectPlacement.class).orElseThrow().anchoredAt(BOTTOM);
|
||||||
context.access().set(new PlacedBlock(new BlockPosition(0, BOTTOM, 0), STONE, Optional.empty()));
|
context.access().set(new PlacedBlock(new BlockPosition(0, BOTTOM, 0), STONE, Optional.empty()));
|
||||||
context.access().mantle().layer(MARKS).set(0, BOTTOM, 0, "bottom");
|
context.access().mantle().layer(MARKS).set(0, BOTTOM, 0, "bottom");
|
||||||
});
|
});
|
||||||
@@ -187,7 +187,7 @@ public class DimensionBottomTest {
|
|||||||
public void aMantleStageWritingAtHeightZeroHitsTheBottomOfTheMantle() {
|
public void aMantleStageWritingAtHeightZeroHitsTheBottomOfTheMantle() {
|
||||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).stream()
|
ModuleMantleComponent.forPack(engine, pack, Set.of()).stream()
|
||||||
.filter(component -> component.stage().stage().id().toString().equals("test:bottom/mantle"))
|
.filter(component -> component.stage().stage().id().toString().equals("test:bottom/mantle"))
|
||||||
.forEach(component -> component.generate(0, 0, storage::chunk));
|
.forEach(component -> component.generate(0, 0, storage::chunk, new IrisMantleChunk(engine, null, 0, 0, null)));
|
||||||
|
|
||||||
assertEquals("bottom", storage.value(MARKS, TEXT, 0, BOTTOM, 0));
|
assertEquals("bottom", storage.value(MARKS, TEXT, 0, BOTTOM, 0));
|
||||||
assertSamplesAndBoundsAgree();
|
assertSamplesAndBoundsAgree();
|
||||||
|
|||||||
@@ -120,10 +120,11 @@ public class FloatingSettingsDecodingTest {
|
|||||||
ModuleSettings biomeSettings = decoder.decode(Level.BIOME, biome, "biome magnetics/plains");
|
ModuleSettings biomeSettings = decoder.decode(Level.BIOME, biome, "biome magnetics/plains");
|
||||||
ModuleSettings dimensionSettings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld");
|
ModuleSettings dimensionSettings = decoder.decode(Level.DIMENSION, file("dimensions/overworld.json"), "dimension overworld");
|
||||||
|
|
||||||
Set<String> used = biomeSettings.usedBiomes(dimensionSettings);
|
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||||
|
Set<String> used = biomeSettings.usedBiomes(resources, dimensionSettings);
|
||||||
|
|
||||||
assertEquals(new LinkedHashSet<>(List.of("mushroom/forest", "carving/mushroom", "tropical/wilds", "carving/lush-child")), used);
|
assertEquals(new LinkedHashSet<>(List.of("mushroom/forest", "carving/mushroom", "tropical/wilds", "carving/lush-child")), used);
|
||||||
assertEquals(Set.of(), biomeSettings.treeBiomes());
|
assertEquals(Set.of(), biomeSettings.treeBiomes(resources));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,9 +134,10 @@ public class FloatingSettingsDecodingTest {
|
|||||||
ModuleSettings biomeSettings = BuiltInPack.settings(new FloatingChildSettings(List.of(child)));
|
ModuleSettings biomeSettings = BuiltInPack.settings(new FloatingChildSettings(List.of(child)));
|
||||||
ModuleSettings dimensionSettings = BuiltInPack.settings(new CarvingSettings(List.of(band)));
|
ModuleSettings dimensionSettings = BuiltInPack.settings(new CarvingSettings(List.of(band)));
|
||||||
|
|
||||||
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(dimensionSettings));
|
IrisPackResources resources = PackResourceFixture.empty(packFolder.toFile());
|
||||||
|
assertEquals(new LinkedHashSet<>(List.of("floating/target", "carving/deep")), biomeSettings.usedBiomes(resources, dimensionSettings));
|
||||||
assertEquals("without bands the name is taken as a biome key", new LinkedHashSet<>(List.of("floating/target", "deep")),
|
assertEquals("without bands the name is taken as a biome key", new LinkedHashSet<>(List.of("floating/target", "deep")),
|
||||||
biomeSettings.usedBiomes(ModuleSettings.NONE));
|
biomeSettings.usedBiomes(resources, ModuleSettings.NONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class IrisLiveWorldTest {
|
|||||||
ModuleResourceFixture.serve(data);
|
ModuleResourceFixture.serve(data);
|
||||||
when(engine.getData()).thenReturn(data);
|
when(engine.getData()).thenReturn(data);
|
||||||
when(engine.getMinHeight()).thenReturn(BOTTOM);
|
when(engine.getMinHeight()).thenReturn(BOTTOM);
|
||||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -118,11 +118,20 @@ public class IrisModuleMantleTest {
|
|||||||
@Test
|
@Test
|
||||||
public void theMatterSideGivesTheMantleChunksTheInvocationReachesAndNoOthers() {
|
public void theMatterSideGivesTheMantleChunksTheInvocationReachesAndNoOthers() {
|
||||||
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
|
||||||
MatterMantle matter = MatterMantle.of(mantle);
|
MatterMantle matter = mantle;
|
||||||
|
|
||||||
org.junit.Assert.assertSame(chunk(3, 4), matter.chunk(3, 4));
|
org.junit.Assert.assertSame(chunk(3, 4), matter.chunk(3, 4));
|
||||||
org.junit.Assert.assertNull("nothing is loaded that the host did not say is", matter.loadedChunk(3, 4));
|
org.junit.Assert.assertNull("nothing is loaded that the host did not say is", matter.loadedChunk(3, 4));
|
||||||
org.junit.Assert.assertThrows(IllegalArgumentException.class, () -> MatterMantle.of(new InMemoryOnly()));
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aChunkInvocationsMatterHoldsItsOwnChunkAndReadsNeighboursOnlyWhenLoaded() {
|
||||||
|
IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 48, HEIGHT, 48));
|
||||||
|
MatterMantle own = new OwnChunkMatter(mantle, 1, 1);
|
||||||
|
|
||||||
|
org.junit.Assert.assertSame(chunk(1, 1), own.chunk(1, 1));
|
||||||
|
org.junit.Assert.assertNull("a neighbour is no chunk of the invocation's own", own.chunk(2, 1));
|
||||||
|
org.junit.Assert.assertNull("a neighbour the world does not hold is not read", own.loadedChunk(2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -299,7 +308,8 @@ public class IrisModuleMantleTest {
|
|||||||
|
|
||||||
try (LoadedPack pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
try (LoadedPack pack = LoadedPack.load(folder.newFolder("pack").toPath(),
|
||||||
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
|
ModuleHost.of(List.of(veins)).copyingJarsTo(folder.newFolder("copies").toPath()))) {
|
||||||
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk);
|
ModuleMantleComponent.forPack(engine, pack, Set.of()).getFirst().generate(0, 0, this::chunk,
|
||||||
|
new IrisMantleChunk(engine, null, 0, 0, null));
|
||||||
|
|
||||||
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
|
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
|
||||||
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
|
IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
|
||||||
@@ -317,32 +327,4 @@ public class IrisModuleMantleTest {
|
|||||||
private static DataInputStream input(byte[] bytes) {
|
private static DataInputStream input(byte[] bytes) {
|
||||||
return new DataInputStream(new ByteArrayInputStream(bytes));
|
return new DataInputStream(new ByteArrayInputStream(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A mantle that is none of Iris's. */
|
|
||||||
private static final class InMemoryOnly implements com.volmit.mantle.Mantle {
|
|
||||||
@Override
|
|
||||||
public BlockBox bounds() {
|
|
||||||
return new BlockBox(0, 0, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> MantleLayer<T> layer(MantleKey<T> key) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MantleLayer<BlockState> blocks() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MantleLayer<Boolean> caverns() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MantleEdit edit() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,9 @@ import com.volmit.block.BlockState;
|
|||||||
import com.volmit.mantle.BlockBox;
|
import com.volmit.mantle.BlockBox;
|
||||||
import com.volmit.object.GeneratedObject;
|
import com.volmit.object.GeneratedObject;
|
||||||
import com.volmit.object.ObjectBlock;
|
import com.volmit.object.ObjectBlock;
|
||||||
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.resource.ResourceKey;
|
import com.volmit.resource.ResourceKind;
|
||||||
import com.volmit.world.BlockPosition;
|
import com.volmit.world.BlockPosition;
|
||||||
import com.volmit.world.PackBiome;
|
import com.volmit.world.PackBiome;
|
||||||
import com.volmit.world.PackRegion;
|
import com.volmit.world.PackRegion;
|
||||||
@@ -109,21 +110,21 @@ public class IrisPackResourcesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aPackObjectIsItsGeometry() {
|
public void aPackObjectIsItsGeometry() {
|
||||||
Optional<GeneratedObject> found = resources.find(new ResourceKey<>(id("trees/oak"), GeneratedObject.class));
|
Optional<GeneratedObject> found = resources.find(PackResources.OBJECTS, id("trees/oak"));
|
||||||
|
|
||||||
assertSame(tree, found.orElseThrow());
|
assertSame(tree, found.orElseThrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aPackBiomeIsBuiltFromTheBiomeFile() {
|
public void aPackBiomeIsBuiltFromTheBiomeFile() {
|
||||||
PackBiome biome = resources.require(new ResourceKey<>(id("desert/dunes"), PackBiome.class));
|
PackBiome biome = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||||
|
|
||||||
assertEquals(new PackBiome(id("desert/dunes"), "Dunes", ResourceId.parse("minecraft:desert"), 3, List.of(id("desert/oasis"))), biome);
|
assertEquals(new PackBiome(id("desert/dunes"), "Dunes", ResourceId.parse("minecraft:desert"), 3, List.of(id("desert/oasis"))), biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aPackRegionIsBuiltFromTheRegionFileWithItsFourBiomeListsAsPackIds() {
|
public void aPackRegionIsBuiltFromTheRegionFileWithItsFourBiomeListsAsPackIds() {
|
||||||
PackRegion region = resources.require(new ResourceKey<>(id("desert"), PackRegion.class));
|
PackRegion region = resources.require(PackResources.REGIONS, id("desert"));
|
||||||
|
|
||||||
assertEquals(new PackRegion(id("desert"), "The Desert", 2, List.of(id("desert/dunes")), List.of(id("ocean")),
|
assertEquals(new PackRegion(id("desert"), "The Desert", 2, List.of(id("desert/dunes")), List.of(id("ocean")),
|
||||||
List.of(id("beach")), List.of(id("caves/dry"))), region);
|
List.of(id("beach")), List.of(id("caves/dry"))), region);
|
||||||
@@ -131,8 +132,8 @@ public class IrisPackResourcesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void oneIdCanBeABiomeAndARegion() {
|
public void oneIdCanBeABiomeAndARegion() {
|
||||||
PackBiome biome = resources.require(new ResourceKey<>(id("desert"), PackBiome.class));
|
PackBiome biome = resources.require(PackResources.BIOMES, id("desert"));
|
||||||
PackRegion region = resources.require(new ResourceKey<>(id("desert"), PackRegion.class));
|
PackRegion region = resources.require(PackResources.REGIONS, id("desert"));
|
||||||
|
|
||||||
assertEquals("Desert biome", biome.name());
|
assertEquals("Desert biome", biome.name());
|
||||||
assertEquals("The Desert", region.name());
|
assertEquals("The Desert", region.name());
|
||||||
@@ -140,19 +141,27 @@ public class IrisPackResourcesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void anIdThePackLacksForThatKindIsAbsent() {
|
public void anIdThePackLacksForThatKindIsAbsent() {
|
||||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(id("desert/dunes"), PackRegion.class)));
|
assertEquals(Optional.empty(), resources.find(PackResources.REGIONS, id("desert/dunes")));
|
||||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(id("trees/birch"), GeneratedObject.class)));
|
assertEquals(Optional.empty(), resources.find(PackResources.OBJECTS, id("trees/birch")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void anIdOfAnotherNamespaceIsAbsent() {
|
public void anIdOfAnotherNamespaceIsAbsent() {
|
||||||
assertEquals(Optional.empty(), resources.find(new ResourceKey<>(new ResourceId("other", "trees/oak"), GeneratedObject.class)));
|
assertEquals(Optional.empty(), resources.find(PackResources.OBJECTS, new ResourceId("other", "trees/oak")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aTypeIrisDoesNotServeIsRejectedWhetherOrNotTheIdExists() {
|
public void aKindIrisDoesNotServeIsRejectedWhetherOrNotTheIdExists() {
|
||||||
assertThrows(IllegalArgumentException.class, () -> resources.find(new ResourceKey<>(id("trees/oak"), String.class)));
|
ResourceKind<GeneratedObject> unserved = ResourceKind.of("test:unserved", "unserved", GeneratedObject.class);
|
||||||
assertThrows(IllegalArgumentException.class, () -> resources.find(new ResourceKey<>(id("missing"), String.class)));
|
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> resources.find(unserved, id("trees/oak")));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> resources.find(unserved, id("missing")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void theIdsOfAKindAreThePacksKeysOfThatKindInIdOrder() {
|
||||||
|
assertEquals(List.of(id("desert"), id("desert/dunes")), resources.ids(PackResources.BIOMES));
|
||||||
|
assertEquals(List.of(id("trees/oak")), resources.ids(PackResources.OBJECTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -160,15 +169,13 @@ public class IrisPackResourcesTest {
|
|||||||
when(objectLoader.getPossibleKeys()).thenReturn(new String[]{"trees/broken"});
|
when(objectLoader.getPossibleKeys()).thenReturn(new String[]{"trees/broken"});
|
||||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> fresh.find(new ResourceKey<>(id("trees/broken"), GeneratedObject.class)));
|
assertThrows(IllegalStateException.class, () -> fresh.find(PackResources.OBJECTS, id("trees/broken")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eachResourceIsBuiltOncePerSnapshot() {
|
public void eachResourceIsBuiltOncePerSnapshot() {
|
||||||
ResourceKey<PackBiome> key = new ResourceKey<>(id("desert/dunes"), PackBiome.class);
|
PackBiome first = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||||
|
PackBiome second = resources.require(PackResources.BIOMES, id("desert/dunes"));
|
||||||
PackBiome first = resources.require(key);
|
|
||||||
PackBiome second = resources.require(key);
|
|
||||||
|
|
||||||
assertSame(first, second);
|
assertSame(first, second);
|
||||||
verify(biomeLoader, times(1)).load("desert/dunes");
|
verify(biomeLoader, times(1)).load("desert/dunes");
|
||||||
@@ -182,6 +189,6 @@ public class IrisPackResourcesTest {
|
|||||||
when(objectLoader.load("Trees/Oak")).thenReturn(object);
|
when(objectLoader.load("Trees/Oak")).thenReturn(object);
|
||||||
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
IrisPackResources fresh = new IrisPackResources(data, List::of);
|
||||||
|
|
||||||
assertSame(tree, fresh.require(new ResourceKey<>(id("trees/oak"), GeneratedObject.class)));
|
assertSame(tree, fresh.require(PackResources.OBJECTS, id("trees/oak")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ import com.volmit.block.BlockSpec;
|
|||||||
import com.volmit.block.BlockState;
|
import com.volmit.block.BlockState;
|
||||||
import com.volmit.block.PaletteSampler;
|
import com.volmit.block.PaletteSampler;
|
||||||
import com.volmit.block.PaletteSpec;
|
import com.volmit.block.PaletteSpec;
|
||||||
import com.volmit.config.OptionsMetadata;
|
import com.volmit.host.OptionsMetadata;
|
||||||
import com.volmit.noise.NoiseSampler;
|
import com.volmit.noise.NoiseSampler;
|
||||||
import com.volmit.noise.NoiseStyle;
|
import com.volmit.noise.NoiseStyle;
|
||||||
import com.volmit.object.BlockEntityData;
|
import com.volmit.object.BlockEntityData;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.engine.framework.SeedManager;
|
import art.arcane.iris.engine.framework.SeedManager;
|
||||||
@@ -30,7 +31,6 @@ import java.util.EnumMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThrows;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -60,15 +60,10 @@ public class IrisWorldFacadesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (IrisSeed seed : IrisSeed.values()) {
|
for (IrisSeed seed : IrisSeed.values()) {
|
||||||
assertEquals(seed.name(), expected.get(seed).longValue(), seed.of(world));
|
assertEquals(seed.name(), expected.get(seed).longValue(), world.extension(IrisSeeds.class).orElseThrow().seed(seed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void aWorldIrisDoesNotGenerateHasNoIrisSeeds() {
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> IrisSeed.POST.of(mock(PackWorld.class)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Engine engine(IrisDimension dimension) {
|
private static Engine engine(IrisDimension dimension) {
|
||||||
Engine engine = mock(Engine.class);
|
Engine engine = mock(Engine.class);
|
||||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package art.arcane.iris.core.modules;
|
package art.arcane.iris.core.modules;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.core.IrisSettings;
|
import art.arcane.iris.core.IrisSettings;
|
||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
@@ -131,24 +132,18 @@ public class ModuleLogTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aWorldViewCarriesTheModulesLogAndSharesTheWorldsState() {
|
public void theWorldOffersIrissOwnCodeTheEngineAndItsSeedsAsExtensions() {
|
||||||
Engine engine = mock(Engine.class);
|
Engine engine = mock(Engine.class);
|
||||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||||
SeedManager seeds = mock(SeedManager.class);
|
SeedManager seeds = mock(SeedManager.class);
|
||||||
when(seeds.getPost()).thenReturn(POST_SEED);
|
when(seeds.getPost()).thenReturn(POST_SEED);
|
||||||
when(engine.getSeedManager()).thenReturn(seeds);
|
when(engine.getSeedManager()).thenReturn(seeds);
|
||||||
IrisPackWorld world = new IrisPackWorld(engine);
|
PackWorld world = new IrisPackWorld(engine);
|
||||||
ModuleLog decorant = log();
|
|
||||||
|
|
||||||
PackWorld view = world.withLog(decorant);
|
assertSame(engine, world.extension(Engine.class).orElseThrow());
|
||||||
|
assertEquals(POST_SEED, world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.POST));
|
||||||
assertSame(decorant, view.log());
|
assertTrue("nothing else is offered", world.extension(String.class).isEmpty());
|
||||||
assertSame("one view per module", view, world.withLog(decorant));
|
|
||||||
assertSame(view, view.withLog(decorant));
|
|
||||||
assertSame("state is the world's", world.state(Marker.class, ignored -> new Marker()), view.state(Marker.class, ignored -> new Marker()));
|
|
||||||
assertSame("Iris's own code still reaches the engine through a view", engine, IrisPackWorld.of(view).engine());
|
|
||||||
assertEquals("and its seeds", POST_SEED, IrisSeed.POST.of(view));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -172,7 +167,4 @@ public class ModuleLogTest {
|
|||||||
private String err() {
|
private String err() {
|
||||||
return err.toString(StandardCharsets.UTF_8);
|
return err.toString(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class Marker {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -34,7 +35,7 @@ public final class ModuleResourceFixture {
|
|||||||
private static final Map<IrisPackResources, ModuleResourceFixture> SERVED = new IdentityHashMap<>();
|
private static final Map<IrisPackResources, ModuleResourceFixture> SERVED = new IdentityHashMap<>();
|
||||||
|
|
||||||
private final IrisPackResources resources;
|
private final IrisPackResources resources;
|
||||||
private final Map<Class<?>, List<ResourceId>> ids = new HashMap<>();
|
private final Map<ResourceKind<?>, List<ResourceId>> ids = new HashMap<>();
|
||||||
|
|
||||||
private ModuleResourceFixture(IrisPackResources resources) {
|
private ModuleResourceFixture(IrisPackResources resources) {
|
||||||
this.resources = resources;
|
this.resources = resources;
|
||||||
@@ -45,6 +46,8 @@ public final class ModuleResourceFixture {
|
|||||||
IrisPackResources resources = mock(IrisPackResources.class);
|
IrisPackResources resources = mock(IrisPackResources.class);
|
||||||
when(data.getPackResources()).thenReturn(resources);
|
when(data.getPackResources()).thenReturn(resources);
|
||||||
when(resources.idOf(anyString())).thenAnswer(invocation -> idOf(invocation.getArgument(0)));
|
when(resources.idOf(anyString())).thenAnswer(invocation -> idOf(invocation.getArgument(0)));
|
||||||
|
when(resources.keyOf(any(ResourceId.class))).thenAnswer(invocation -> keyOf(invocation.getArgument(0)));
|
||||||
|
when(resources.keyOf(any(ResourceKind.class), any(ResourceId.class))).thenAnswer(invocation -> keyOf(invocation.getArgument(1)));
|
||||||
ModuleResourceFixture fixture = new ModuleResourceFixture(resources);
|
ModuleResourceFixture fixture = new ModuleResourceFixture(resources);
|
||||||
SERVED.put(resources, fixture);
|
SERVED.put(resources, fixture);
|
||||||
return fixture;
|
return fixture;
|
||||||
@@ -82,14 +85,18 @@ public final class ModuleResourceFixture {
|
|||||||
/** Serves {@code resource} as the resource of {@code kind} the pack names by {@code key}. */
|
/** Serves {@code resource} as the resource of {@code kind} the pack names by {@code key}. */
|
||||||
public <T> ModuleResourceFixture resource(ResourceKind<T> kind, String key, T resource) {
|
public <T> ModuleResourceFixture resource(ResourceKind<T> kind, String key, T resource) {
|
||||||
ResourceId id = idOf(key);
|
ResourceId id = idOf(key);
|
||||||
when(resources.find(kind.key(id))).thenReturn(Optional.of(resource));
|
when(resources.find(kind, id)).thenReturn(Optional.of(resource));
|
||||||
List<ResourceId> kindIds = ids.computeIfAbsent(kind.type(), ignored -> new ArrayList<>());
|
List<ResourceId> kindIds = ids.computeIfAbsent(kind, ignored -> new ArrayList<>());
|
||||||
kindIds.add(id);
|
kindIds.add(id);
|
||||||
when(resources.ids(kind.type())).thenReturn(kindIds.stream().sorted().toList());
|
when(resources.ids(kind)).thenReturn(kindIds.stream().sorted().toList());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ResourceId idOf(String key) {
|
private static ResourceId idOf(String key) {
|
||||||
return new ResourceId(NAMESPACE, key.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9_./-]", "_"));
|
return new ResourceId(NAMESPACE, key.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9_./-]", "_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String keyOf(ResourceId id) {
|
||||||
|
return id.namespace().equals(NAMESPACE) ? id.path() : id.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,7 @@ import com.volmit.ModuleSetup;
|
|||||||
import com.volmit.host.LoadedPack;
|
import com.volmit.host.LoadedPack;
|
||||||
import com.volmit.host.ModuleHost;
|
import com.volmit.host.ModuleHost;
|
||||||
import com.volmit.resource.PackResources;
|
import com.volmit.resource.PackResources;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.LocateResult;
|
import com.volmit.service.LocateResult;
|
||||||
import com.volmit.service.ObjectsAt;
|
import com.volmit.service.ObjectsAt;
|
||||||
import com.volmit.service.StructureLocator;
|
import com.volmit.service.StructureLocator;
|
||||||
@@ -88,30 +89,30 @@ public class ModuleServicesTest {
|
|||||||
var registry = setup.registry();
|
var registry = setup.registry();
|
||||||
registry.registerService(ObjectsAt.class, new ObjectsAt() {
|
registry.registerService(ObjectsAt.class, new ObjectsAt() {
|
||||||
@Override
|
@Override
|
||||||
public Set<String> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
public Set<ResourceId> objectsAt(PackWorld world, int chunkX, int chunkZ) {
|
||||||
logOwners.add(id + (world.log() == registeredLog ? " has its own log" : " has another module's log"));
|
logOwners.add(id + (world.log() == registeredLog ? " has its own log" : " has another module's log"));
|
||||||
return Set.of(object + "@" + chunkX + "," + chunkZ);
|
return Set.of(world.resources().idOf(object + "/" + chunkX + "/" + chunkZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlacedBy placedBy(PackWorld world, String objectKey) {
|
public PlacedBy placedBy(PackWorld world, ResourceId placedObject) {
|
||||||
return new PlacedBy(Set.of(object + "-biome"), Set.of(id + "-region"));
|
return new PlacedBy(Set.of(world.resources().idOf(object + "-biome")), Set.of(world.resources().idOf(id.replace(':', '-') + "-region")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
registry.registerService(StructureLocator.class, new StructureLocator() {
|
registry.registerService(StructureLocator.class, new StructureLocator() {
|
||||||
@Override
|
@Override
|
||||||
public Set<String> structures(PackResources resources) {
|
public Set<ResourceId> structures(PackResources resources) {
|
||||||
return Set.of(structure, structure + "/unplaced");
|
return Set.of(resources.idOf(structure), resources.idOf(structure + "/unplaced"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> locatable(PackWorld world) {
|
public Set<ResourceId> locatable(PackWorld world) {
|
||||||
return Set.of(structure);
|
return Set.of(world.resources().idOf(structure));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocateResult locate(PackWorld world, String key, int fromX, int fromZ, int maxRadiusChunks) {
|
public LocateResult locate(PackWorld world, ResourceId located, int fromX, int fromZ, int maxRadiusChunks) {
|
||||||
searches.add(id + " " + key + " " + fromX + " " + fromZ + " " + maxRadiusChunks);
|
searches.add(id + " " + located.path() + " " + fromX + " " + fromZ + " " + maxRadiusChunks);
|
||||||
return LocateResult.found(new BlockPosition(fromX + 16, 70, fromZ));
|
return LocateResult.found(new BlockPosition(fromX + 16, 70, fromZ));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -130,6 +131,7 @@ public class ModuleServicesTest {
|
|||||||
when(modules.pack()).thenReturn(pack);
|
when(modules.pack()).thenReturn(pack);
|
||||||
when(data.getModules()).thenReturn(modules);
|
when(data.getModules()).thenReturn(modules);
|
||||||
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
when(data.getDataFolder()).thenReturn(folder.getRoot());
|
||||||
|
PackResourceFixture.holdNoObjectsBiomesOrRegions(data);
|
||||||
IrisPackResources resources = new IrisPackResources(data, List::of);
|
IrisPackResources resources = new IrisPackResources(data, List::of);
|
||||||
when(data.getPackResources()).thenReturn(resources);
|
when(data.getPackResources()).thenReturn(resources);
|
||||||
engine = mock(Engine.class);
|
engine = mock(Engine.class);
|
||||||
@@ -148,7 +150,7 @@ public class ModuleServicesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void objectsAtCombinesEveryModulesObjectsInModuleOrder() {
|
public void objectsAtCombinesEveryModulesObjectsInModuleOrder() {
|
||||||
assertEquals(List.of("tree@3,-4", "bush@3,-4", "rock@3,-4"), List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
assertEquals(List.of("tree/3/-4", "bush/3/-4", "rock/3/-4"),List.copyOf(ModuleServices.objectsAt(engine, 3, -4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -160,10 +162,10 @@ public class ModuleServicesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void objectPlacersCombineTheBiomesAndRegionsOfEveryModule() {
|
public void objectPlacersCombineTheBiomesAndRegionsOfEveryModule() {
|
||||||
ObjectsAt.PlacedBy placers = ModuleServices.objectPlacers(engine, "trees/oak");
|
ModuleServices.ObjectPlacers placers = ModuleServices.objectPlacers(engine, "trees/oak");
|
||||||
|
|
||||||
assertEquals(Set.of("rock-biome", "tree-biome", "bush-biome"), placers.biomes());
|
assertEquals(Set.of("rock-biome", "tree-biome", "bush-biome"), placers.biomes());
|
||||||
assertEquals(Set.of("test:zeta-region", "test:alpha-region", "test:beta-region"), placers.regions());
|
assertEquals(Set.of("test-zeta-region", "test-alpha-region", "test-beta-region"), placers.regions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -181,7 +183,7 @@ public class ModuleServicesTest {
|
|||||||
ModuleServices.StructureSearch result = ModuleServices.locateStructure(engine, "Castle", 100, -200, 64);
|
ModuleServices.StructureSearch result = ModuleServices.locateStructure(engine, "Castle", 100, -200, 64);
|
||||||
|
|
||||||
assertEquals(new ModuleServices.StructureSearch(ModuleServices.StructureSearch.Outcome.FOUND, 116, 70 - 64, -200), result);
|
assertEquals(new ModuleServices.StructureSearch(ModuleServices.StructureSearch.Outcome.FOUND, 116, 70 - 64, -200), result);
|
||||||
assertEquals(List.of("test:beta Castle 100 -200 64"), searches);
|
assertEquals("the key is read as the pack's lower-case id", List.of("test:beta castle 100 -200 64"), searches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class ModuleWorldsTest {
|
|||||||
assertEquals(List.of("loaded", "started"), calls);
|
assertEquals(List.of("loaded", "started"), calls);
|
||||||
assertEquals(SEED, world.seed());
|
assertEquals(SEED, world.seed());
|
||||||
assertSame(data.getPackResources(), world.resources());
|
assertSame(data.getPackResources(), world.resources());
|
||||||
assertSame(engine, IrisPackWorld.of(world).engine());
|
assertSame(engine, world.engine());
|
||||||
Remembered built = world.state(Remembered.class, ignored -> new Remembered(calls));
|
Remembered built = world.state(Remembered.class, ignored -> new Remembered(calls));
|
||||||
assertSame(built, generation.state(Remembered.class, ignored -> new Remembered(calls)));
|
assertSame(built, generation.state(Remembered.class, ignored -> new Remembered(calls)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,13 +71,13 @@ public class PackModuleResourceKindTest {
|
|||||||
|
|
||||||
public final class KeepValidator implements Validator {
|
public final class KeepValidator implements Validator {
|
||||||
public void validate(ValidationContext pack) {
|
public void validate(ValidationContext pack) {
|
||||||
for (ResourceId id : pack.resources().ids(Keep.class)) {
|
for (ResourceId id : pack.resources().ids(CastleModule.KEEPS)) {
|
||||||
Keep keep = pack.resources().require(CastleModule.KEEPS.key(id));
|
Keep keep = pack.resources().require(CastleModule.KEEPS, id);
|
||||||
if (keep.towers() > 8) {
|
if (keep.towers() > 8) {
|
||||||
pack.report(Problem.error(Subject.file("keeps/" + id.path() + ".json"), "Keep has " + keep.towers() + " towers; at most 8 fit."));
|
pack.report(Problem.error(Subject.file("keeps/" + id.path() + ".json"), "Keep has " + keep.towers() + " towers; at most 8 fit."));
|
||||||
}
|
}
|
||||||
ResourceId next = new ResourceId(id.namespace(), keep.next().isEmpty() ? id.path() : keep.next());
|
ResourceId next = new ResourceId(id.namespace(), keep.next().isEmpty() ? id.path() : keep.next());
|
||||||
if (pack.resources().find(CastleModule.KEEPS.key(next)).isEmpty()) {
|
if (pack.resources().find(CastleModule.KEEPS, next).isEmpty()) {
|
||||||
pack.report(Problem.warning(Subject.resource(id), "Keep leads to missing keep " + keep.next() + "."));
|
pack.report(Problem.warning(Subject.resource(id), "Keep leads to missing keep " + keep.next() + "."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ public class PackModuleResourceKindTest {
|
|||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aPackModulesKindIsReadFromItsFolderAndServedByType() throws Exception {
|
public void aPackModulesKindIsReadFromItsFolderAndServedAsThatKind() throws Exception {
|
||||||
Path pack = castlePack("castles");
|
Path pack = castlePack("castles");
|
||||||
write(pack, "keeps/main.json", "{\"towers\":6,\"next\":\"towers/north\"}");
|
write(pack, "keeps/main.json", "{\"towers\":6,\"next\":\"towers/north\"}");
|
||||||
write(pack, "keeps/towers/north.json", "{}");
|
write(pack, "keeps/towers/north.json", "{}");
|
||||||
@@ -117,14 +117,14 @@ public class PackModuleResourceKindTest {
|
|||||||
ResourceKind<?> keeps = keepKind(data);
|
ResourceKind<?> keeps = keepKind(data);
|
||||||
ResourceId main = new ResourceId("castles", "main");
|
ResourceId main = new ResourceId("castles", "main");
|
||||||
|
|
||||||
assertEquals(List.of(main, new ResourceId("castles", "towers/north")), data.getPackResources().ids(keeps.type()));
|
assertEquals(List.of(main, new ResourceId("castles", "towers/north")), data.getPackResources().ids(keeps));
|
||||||
Object keep = data.getPackResources().find(keeps.key(main)).orElseThrow();
|
Object keep = data.getPackResources().find(keeps, main).orElseThrow();
|
||||||
assertEquals(6, keep.getClass().getMethod("towers").invoke(keep));
|
assertEquals(6, keep.getClass().getMethod("towers").invoke(keep));
|
||||||
assertEquals("towers/north", keep.getClass().getMethod("next").invoke(keep));
|
assertEquals("towers/north", keep.getClass().getMethod("next").invoke(keep));
|
||||||
Object north = data.getPackResources().find(keeps.key(new ResourceId("castles", "towers/north"))).orElseThrow();
|
Object north = data.getPackResources().find(keeps, new ResourceId("castles", "towers/north")).orElseThrow();
|
||||||
assertEquals("an omitted field keeps its default", 4, north.getClass().getMethod("towers").invoke(north));
|
assertEquals("an omitted field keeps its default", 4, north.getClass().getMethod("towers").invoke(north));
|
||||||
assertSame("read once per pack load", keep, data.getPackResources().find(keeps.key(main)).orElseThrow());
|
assertSame("read once per pack load", keep, data.getPackResources().find(keeps, main).orElseThrow());
|
||||||
assertTrue(data.getPackResources().find(keeps.key(new ResourceId("castles", "missing"))).isEmpty());
|
assertTrue(data.getPackResources().find(keeps, new ResourceId("castles", "missing")).isEmpty());
|
||||||
assertTrue(data.getPackResources().moduleFolderNames().containsAll(List.of("keeps", "structures")));
|
assertTrue(data.getPackResources().moduleFolderNames().containsAll(List.of("keeps", "structures")));
|
||||||
assertTrue(data.resourceFolderNames().contains("keeps"));
|
assertTrue(data.resourceFolderNames().contains("keeps"));
|
||||||
} finally {
|
} finally {
|
||||||
@@ -140,7 +140,7 @@ public class PackModuleResourceKindTest {
|
|||||||
try {
|
try {
|
||||||
ResourceKind<?> keeps = keepKind(data);
|
ResourceKind<?> keeps = keepKind(data);
|
||||||
|
|
||||||
assertThrows(IllegalStateException.class, () -> data.getPackResources().find(keeps.key(new ResourceId("broken-castles", "main"))));
|
assertThrows(IllegalStateException.class, () -> data.getPackResources().find(keeps, new ResourceId("broken-castles", "main")));
|
||||||
} finally {
|
} finally {
|
||||||
data.close();
|
data.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package art.arcane.iris.core.modules;
|
|||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
import art.arcane.iris.core.loader.ResourceLoader;
|
import art.arcane.iris.core.loader.ResourceLoader;
|
||||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||||
|
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||||
|
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||||
import com.volmit.block.BlockState;
|
import com.volmit.block.BlockState;
|
||||||
import com.volmit.mantle.BlockBox;
|
import com.volmit.mantle.BlockBox;
|
||||||
import com.volmit.object.GeneratedObject;
|
import com.volmit.object.GeneratedObject;
|
||||||
import com.volmit.object.ObjectBlock;
|
import com.volmit.object.ObjectBlock;
|
||||||
import com.volmit.resource.ResourceKey;
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.world.BlockPosition;
|
import com.volmit.world.BlockPosition;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -39,8 +41,31 @@ public final class PackResourceFixture {
|
|||||||
return resources;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The key of the oak in the pack in {@code packFolder}. */
|
/** The oak {@code resources} serve, as a module finds it by its key. */
|
||||||
public static ResourceKey<GeneratedObject> oakKey(java.io.File packFolder) {
|
public static GeneratedObject oak(PackResources resources) {
|
||||||
return new ResourceKey<>(new PackResourceIds(packFolder).of(OAK_KEY), GeneratedObject.class);
|
return resources.require(PackResources.OBJECTS, resources.idOf(OAK_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The resources of a pack in {@code packFolder} without objects, biomes or regions, which names its keys by id. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static IrisPackResources empty(java.io.File packFolder) {
|
||||||
|
IrisData data = mock(IrisData.class);
|
||||||
|
when(data.getDataFolder()).thenReturn(packFolder);
|
||||||
|
holdNoObjectsBiomesOrRegions(data);
|
||||||
|
return new IrisPackResources(data, List::of);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Makes {@code data} (a mock) a pack without objects, biomes or regions, so resources built over it index none. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static void holdNoObjectsBiomesOrRegions(IrisData data) {
|
||||||
|
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||||
|
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||||
|
ResourceLoader<IrisRegion> regions = mock(ResourceLoader.class);
|
||||||
|
when(objects.getPossibleKeys()).thenReturn(new String[0]);
|
||||||
|
when(biomes.getPossibleKeys()).thenReturn(new String[0]);
|
||||||
|
when(regions.getPossibleKeys()).thenReturn(new String[0]);
|
||||||
|
when(data.getObjectLoader()).thenReturn(objects);
|
||||||
|
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||||
|
when(data.getRegionLoader()).thenReturn(regions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,17 +44,16 @@ public class ToolWorldTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void everyLogViewSharesTheStateAndClosingTheWorldClosesIt() {
|
public void theWorldKeepsItsStateUntilItIsClosed() {
|
||||||
PackResources resources = mock(PackResources.class);
|
PackResources resources = mock(PackResources.class);
|
||||||
Tracked tracked;
|
Tracked tracked;
|
||||||
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class))) {
|
try (ToolWorld world = new ToolWorld(SEED, resources, mock(PackSettings.class))) {
|
||||||
tracked = world.state(Tracked.class, ignored -> new Tracked());
|
tracked = world.state(Tracked.class, ignored -> new Tracked());
|
||||||
PackWorld view = world.withLog(mock(ModuleLog.class));
|
|
||||||
|
|
||||||
assertSame(tracked, view.state(Tracked.class, ignored -> new Tracked()));
|
assertSame(tracked, world.state(Tracked.class, ignored -> new Tracked()));
|
||||||
assertSame(resources, view.resources());
|
assertSame(resources, world.resources());
|
||||||
assertEquals(SEED, view.seed());
|
assertEquals(SEED, world.seed());
|
||||||
assertEquals(0, view.minHeight());
|
assertEquals(0, world.minHeight());
|
||||||
assertFalse(tracked.closed);
|
assertFalse(tracked.closed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class TreeDefinitionIndexTest {
|
|||||||
when(engine.getDimension()).thenReturn(dimension);
|
when(engine.getDimension()).thenReturn(dimension);
|
||||||
IrisData data = mock(IrisData.class);
|
IrisData data = mock(IrisData.class);
|
||||||
when(engine.getData()).thenReturn(data);
|
when(engine.getData()).thenReturn(data);
|
||||||
|
ModuleResourceFixture.serve(data);
|
||||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||||
when(dimension.getAllRegions(engine)).thenReturn(new KList<IrisRegion>().qadd(region));
|
when(dimension.getAllRegions(engine)).thenReturn(new KList<IrisRegion>().qadd(region));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package art.arcane.iris.engine.decorator;
|
package art.arcane.iris.engine.decorator;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
import art.arcane.iris.builtin.decorant.DecorantSettings;
|
||||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||||
import art.arcane.iris.builtin.decorant.Decorator;
|
import art.arcane.iris.builtin.decorant.Decorator;
|
||||||
@@ -71,7 +72,7 @@ public class BiomeDecoratorsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() {
|
public void everyDecoratorNoiseSeedIsAFunctionOfTheWorldsDecoratorSeedItsBiomeAndItsPlace() {
|
||||||
long decoratorSeed = IrisSeed.DECORATOR.of(world);
|
long decoratorSeed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.DECORATOR);
|
||||||
long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed();
|
long first = decorators.decorators(meadow, DecorationPart.NONE)[0].seed();
|
||||||
long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed();
|
long second = decorators.decorators(meadow, DecorationPart.NONE)[1].seed();
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import art.arcane.iris.util.project.stream.ProceduralStream;
|
|||||||
import com.volmit.IrisModule;
|
import com.volmit.IrisModule;
|
||||||
import com.volmit.ModuleInfo;
|
import com.volmit.ModuleInfo;
|
||||||
import com.volmit.ModuleSetup;
|
import com.volmit.ModuleSetup;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.service.CaveBiomes;
|
import com.volmit.service.CaveBiomes;
|
||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -86,6 +87,7 @@ public class EngineCaveBiomeTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void mockEngine() {
|
public void mockEngine() {
|
||||||
data = mock(IrisData.class);
|
data = mock(IrisData.class);
|
||||||
|
ModuleResourceFixture.serve(data);
|
||||||
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||||
when(biomes.load("band/deep")).thenReturn(band);
|
when(biomes.load("band/deep")).thenReturn(band);
|
||||||
@@ -112,13 +114,13 @@ public class EngineCaveBiomeTest {
|
|||||||
private CaveBiomes caves(String overridden, int minDepth) {
|
private CaveBiomes caves(String overridden, int minDepth) {
|
||||||
return new CaveBiomes() {
|
return new CaveBiomes() {
|
||||||
@Override
|
@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.ofNullable(overridden);
|
return Optional.ofNullable(overridden).map(world.resources()::idOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||||
return biomeKey.equals("cave/lush") ? minDepth : 0;
|
return biome.equals(world.resources().idOf("cave/lush")) ? minDepth : 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -170,14 +172,14 @@ public class EngineCaveBiomeTest {
|
|||||||
CaveBiomes counting = caves(null, 10);
|
CaveBiomes counting = caves(null, 10);
|
||||||
serve(new CaveBiomes() {
|
serve(new CaveBiomes() {
|
||||||
@Override
|
@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 y > SURFACE_Y ? Optional.of("band/deep") : Optional.empty();
|
return y > SURFACE_Y ? Optional.of(world.resources().idOf("band/deep")) : Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int minDepthBelowSurface(PackWorld world, String biomeKey) {
|
public int minDepthBelowSurface(PackWorld world, ResourceId biome) {
|
||||||
depthQuestions.incrementAndGet();
|
depthQuestions.incrementAndGet();
|
||||||
return counting.minDepthBelowSurface(world, biomeKey);
|
return counting.minDepthBelowSurface(world, biome);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ public class HintedLocatorTest {
|
|||||||
when(engine.isClosed()).thenReturn(false);
|
when(engine.isClosed()).thenReturn(false);
|
||||||
when(engine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
when(engine.acquireGenerationLease(any(String.class))).thenReturn(GenerationSessionLease.noop());
|
||||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||||
|
ModuleResourceFixture.serve(data);
|
||||||
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
ModuleResourceFixture.serveModules(data, new ObjectModule());
|
||||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||||
stubReachableBiomes();
|
stubReachableBiomes();
|
||||||
|
|||||||
+3
-3
@@ -62,7 +62,7 @@ public class StructureResourcesTest {
|
|||||||
public void theStructureModuleListsThePacksStructuresForIrissIndexThroughItsLocator() throws Exception {
|
public void theStructureModuleListsThePacksStructuresForIrissIndexThroughItsLocator() throws Exception {
|
||||||
IrisData data = IrisData.openValidation(castlePack("listed").toFile());
|
IrisData data = IrisData.openValidation(castlePack("listed").toFile());
|
||||||
try {
|
try {
|
||||||
assertEquals(Set.of("castle"), new StructureLocating().structures(data.getPackResources()));
|
assertEquals(Set.of(new ResourceId("listed", "castle")), new StructureLocating().structures(data.getPackResources()));
|
||||||
assertEquals(Set.of("castle"), ModuleServices.structureKeys(data));
|
assertEquals(Set.of("castle"), ModuleServices.structureKeys(data));
|
||||||
} finally {
|
} finally {
|
||||||
data.close();
|
data.close();
|
||||||
@@ -81,7 +81,7 @@ public class StructureResourcesTest {
|
|||||||
assertEquals("castle", castle.getLoadKey());
|
assertEquals("castle", castle.getLoadKey());
|
||||||
assertEquals(pack.resolve("structures/castle.json").toFile(), castle.getLoadFile());
|
assertEquals(pack.resolve("structures/castle.json").toFile(), castle.getLoadFile());
|
||||||
assertSame(data, castle.getLoader());
|
assertSame(data, castle.getLoader());
|
||||||
assertSame(castle, data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("castles", "castle"))).orElseThrow());
|
assertSame(castle, data.getPackResources().find(StructureResources.STRUCTURES, new ResourceId("castles", "castle")).orElseThrow());
|
||||||
assertEquals("castle/start", StructureResources.pool(data, "castle/start").getPieces().getFirst().getPiece());
|
assertEquals("castle/start", StructureResources.pool(data, "castle/start").getPieces().getFirst().getPiece());
|
||||||
assertEquals("castle/start", StructureResources.piece(data, "castle/start").getObject());
|
assertEquals("castle/start", StructureResources.piece(data, "castle/start").getObject());
|
||||||
assertEquals(List.of("castle"), StructureResources.structureKeys(data));
|
assertEquals(List.of("castle"), StructureResources.structureKeys(data));
|
||||||
@@ -101,7 +101,7 @@ public class StructureResourcesTest {
|
|||||||
try {
|
try {
|
||||||
assertNull(StructureResources.structure(data, "ruin"));
|
assertNull(StructureResources.structure(data, "ruin"));
|
||||||
assertThrows(IllegalStateException.class,
|
assertThrows(IllegalStateException.class,
|
||||||
() -> data.getPackResources().find(StructureResources.STRUCTURES.key(new ResourceId("broken", "ruin"))));
|
() -> data.getPackResources().find(StructureResources.STRUCTURES, new ResourceId("broken", "ruin")));
|
||||||
} finally {
|
} finally {
|
||||||
data.close();
|
data.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.volmit.mantle.BlockBox;
|
|||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.vanilla.DecorationStep;
|
import com.volmit.vanilla.DecorationStep;
|
||||||
import com.volmit.vanilla.PieceKind;
|
import com.volmit.vanilla.PieceKind;
|
||||||
|
import com.volmit.vanilla.StartKey;
|
||||||
import com.volmit.vanilla.StartMemo;
|
import com.volmit.vanilla.StartMemo;
|
||||||
import com.volmit.vanilla.StructureFit;
|
import com.volmit.vanilla.StructureFit;
|
||||||
import com.volmit.vanilla.TemplateCells;
|
import com.volmit.vanilla.TemplateCells;
|
||||||
@@ -249,7 +250,7 @@ final class FitFixture {
|
|||||||
Piece... pieces) {
|
Piece... pieces) {
|
||||||
StartMemo memo = new StartMemo(terrainJson, stiltsJson);
|
StartMemo memo = new StartMemo(terrainJson, stiltsJson);
|
||||||
StructureFit.Start start = new StructureFit.Start() {
|
StructureFit.Start start = new StructureFit.Start() {
|
||||||
private final Object key = new Object();
|
private final StartKey key = StartKey.create();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceId structure() {
|
public ResourceId structure() {
|
||||||
@@ -287,7 +288,7 @@ final class FitFixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object key() {
|
public StartKey key() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ import static org.mockito.Mockito.when;
|
|||||||
/**
|
/**
|
||||||
* What a loot table gives at fixed spots of a fixed world, as the whole drawn items, hashed. The numbers were taken
|
* What a loot table gives at fixed spots of a fixed world, as the whole drawn items, hashed. The numbers were taken
|
||||||
* before the loot classes became settings of the loot module; a change in them changes the loot of existing worlds.
|
* before the loot classes became settings of the loot module; a change in them changes the loot of existing worlds.
|
||||||
|
* They were retaken once when an item's absent values became {@code Optional}s: the items printed the old way (absent
|
||||||
|
* values as {@code null}) still hashed to the old numbers, -492887340, -92432338, -1096436977, -1436497629 and -1714085578.
|
||||||
*/
|
*/
|
||||||
public class LootDrawPinTest {
|
public class LootDrawPinTest {
|
||||||
private static final long LOOT_SEED = 8123456789L;
|
private static final long LOOT_SEED = 8123456789L;
|
||||||
@@ -78,6 +80,6 @@ public class LootDrawPinTest {
|
|||||||
hashes.add(drops.toString().hashCode());
|
hashes.add(drops.toString().hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(List.of(-492887340, -92432338, -1096436977, -1436497629, -1714085578), hashes);
|
assertEquals(List.of(-1656514080, 672855254, -359051997, -717275247, 1936773406), hashes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -52,7 +53,7 @@ public class LootItemsTest {
|
|||||||
assertEquals(amount, drop.amount());
|
assertEquals(amount, drop.amount());
|
||||||
assertEquals(level, drop.enchantments().getFirst().level());
|
assertEquals(level, drop.enchantments().getFirst().level());
|
||||||
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
|
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
|
||||||
assertEquals(damage, drop.damage(), 0D);
|
assertEquals(damage, drop.damage().orElseThrow(), 0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -64,7 +65,7 @@ public class LootItemsTest {
|
|||||||
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
|
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
|
||||||
|
|
||||||
assertEquals(2, drop.amount());
|
assertEquals(2, drop.amount());
|
||||||
assertNull(drop.damage());
|
assertTrue(drop.damage().isEmpty());
|
||||||
assertEquals(untouched.nextLong(), rng.nextLong());
|
assertEquals(untouched.nextLong(), rng.nextLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +86,9 @@ public class LootItemsTest {
|
|||||||
List<ItemDrop> drops = new LootItems(registry, true).draw("dungeon", table, LOOT_SEED, 0, 64, 0);
|
List<ItemDrop> drops = new LootItems(registry, true).draw("dungeon", table, LOOT_SEED, 0, 64, 0);
|
||||||
|
|
||||||
for (ItemDrop drop : drops) {
|
for (ItemDrop drop : drops) {
|
||||||
assertEquals(new ItemDrop.Source("dungeon", 4, 3), drop.source());
|
assertEquals(Optional.of(new ItemDrop.Source(Optional.of("dungeon"), 4, 3)), drop.source());
|
||||||
}
|
}
|
||||||
assertTrue(new LootItems(registry, false).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source() == null));
|
assertTrue(new LootItems(registry, false).draw("dungeon", table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source().isEmpty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class LootValidatorTest {
|
|||||||
public void aTableThatFailsToLoadIsReportedWithoutStoppingTheCheck() {
|
public void aTableThatFailsToLoadIsReportedWithoutStoppingTheCheck() {
|
||||||
table("fine", "{\"loot\":[{\"type\":\"stone\"}]}");
|
table("fine", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||||
table("broken", "{\"loot\":[{\"type\":\"stone\"}]}");
|
table("broken", "{\"loot\":[{\"type\":\"stone\"}]}");
|
||||||
when(resources.find(LootResources.TABLES.key(new ResourceId("test", "broken")))).thenThrow(new IllegalStateException("Expected an int but was STRING at line 1 column 12 path $.rarity"));
|
when(resources.find(LootResources.TABLES, new ResourceId("test", "broken"))).thenThrow(new IllegalStateException("Expected an int but was STRING at line 1 column 12 path $.rarity"));
|
||||||
|
|
||||||
assertEquals(List.of("Loot table 'broken' cannot be read: Expected an int but was STRING at line 1 column 12 path $.rarity"), errors());
|
assertEquals(List.of("Loot table 'broken' cannot be read: Expected an int but was STRING at line 1 column 12 path $.rarity"), errors());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class PlacementLootTest {
|
|||||||
private static final String EAST_CHEST = "minecraft:chest[facing=east]";
|
private static final String EAST_CHEST = "minecraft:chest[facing=east]";
|
||||||
private static final long LOOT_SEED = 99L;
|
private static final long LOOT_SEED = 99L;
|
||||||
|
|
||||||
|
private PackResources resources;
|
||||||
private PlacementLoot placement;
|
private PlacementLoot placement;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -63,7 +64,7 @@ public class PlacementLootTest {
|
|||||||
for (String key : List.of("everywhere", "chests", "this-chest", "other")) {
|
for (String key : List.of("everywhere", "chests", "this-chest", "other")) {
|
||||||
fixture.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, "{\"name\": \"" + key + "\"}"));
|
fixture.resource(LootResources.TABLES, key, TestSettings.of(LootTable.class, "{\"name\": \"" + key + "\"}"));
|
||||||
}
|
}
|
||||||
PackResources resources = data.getPackResources();
|
resources = data.getPackResources();
|
||||||
BlockRegistry blocks = mock(BlockRegistry.class);
|
BlockRegistry blocks = mock(BlockRegistry.class);
|
||||||
when(resources.blocks()).thenReturn(blocks);
|
when(resources.blocks()).thenReturn(blocks);
|
||||||
when(blocks.resolve(any(BlockState.class))).thenAnswer(invocation -> invocation.getArgument(0));
|
when(blocks.resolve(any(BlockState.class))).thenAnswer(invocation -> invocation.getArgument(0));
|
||||||
@@ -71,19 +72,23 @@ public class PlacementLootTest {
|
|||||||
placement = new PlacementLoot(resources, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
placement = new PlacementLoot(resources, () -> Set.of("minecraft:chests/simple_dungeon"), LOOT_SEED, ModuleLogs.discarding());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Loot.Table table(String key) {
|
||||||
|
return new Loot.Table(resources.idOf(key));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aTableThatNamesTheExactStateBeatsOneThatNamesTheKindOfBlock() {
|
public void aTableThatNamesTheExactStateBeatsOneThatNamesTheKindOfBlock() {
|
||||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("chests", 1, false, CHEST), entry("this-chest", 1, true, CHEST));
|
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("chests", 1, false, CHEST), entry("this-chest", 1, true, CHEST));
|
||||||
|
|
||||||
assertEquals(new Loot.Table("this-chest"), pick(List.of(), pack, CHEST));
|
assertEquals(table("this-chest"), pick(List.of(), pack, CHEST));
|
||||||
assertEquals(new Loot.Table("chests"), pick(List.of(), pack, EAST_CHEST));
|
assertEquals(table("chests"), pick(List.of(), pack, EAST_CHEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aTableThatNamesNoBlockServesChestsNothingElseNames() {
|
public void aTableThatNamesNoBlockServesChestsNothingElseNames() {
|
||||||
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("other", 1, false, "minecraft:barrel"));
|
List<ObjectLootEntry> pack = List.of(entry("everywhere", 1, false), entry("other", 1, false, "minecraft:barrel"));
|
||||||
|
|
||||||
assertEquals(new Loot.Table("everywhere"), pick(List.of(), pack, CHEST));
|
assertEquals(table("everywhere"), pick(List.of(), pack, CHEST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,10 +106,10 @@ public class PlacementLootTest {
|
|||||||
|
|
||||||
for (int i = 0; i < 4000; i++) {
|
for (int i = 0; i < 4000; i++) {
|
||||||
Loot.Source picked = placement.pick(List.of(), pack, BlockState.parse(CHEST), rng, 0, 64, 0);
|
Loot.Source picked = placement.pick(List.of(), pack, BlockState.parse(CHEST), rng, 0, 64, 0);
|
||||||
if (picked.equals(new Loot.Table("everywhere"))) {
|
if (picked.equals(table("everywhere"))) {
|
||||||
everywhere++;
|
everywhere++;
|
||||||
} else {
|
} else {
|
||||||
assertEquals(new Loot.Table("chests"), picked);
|
assertEquals(table("chests"), picked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-11
@@ -56,7 +56,7 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
|||||||
|
|
||||||
private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
|
private static PackSettings pack(FloatingChildSettings declared, ObjectHost objects) {
|
||||||
FloatingHost floating = mock(FloatingHost.class);
|
FloatingHost floating = mock(FloatingHost.class);
|
||||||
return new FloatingPack() {
|
return new PackSettings() {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
|
public <T extends IrisFeature> SettingsStack<T> declared(Class<T> featureType) {
|
||||||
@@ -65,17 +65,12 @@ public class FloatingObjectPlacingBoundaryRadiusTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FloatingHost floating() {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return floating;
|
if (type == FloatingHost.class) {
|
||||||
}
|
return Optional.of(type.cast(floating));
|
||||||
|
}
|
||||||
@Override
|
return type == ObjectHost.class ? Optional.of(type.cast(objects)) : Optional.empty();
|
||||||
public ObjectHost objects() {
|
|
||||||
return objects;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface FloatingPack extends PackSettings, FloatingHost.Source, ObjectHost.Source {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package art.arcane.iris.engine.mantle.components;
|
package art.arcane.iris.engine.mantle.components;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||||
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
import art.arcane.iris.builtin.objects.ObjectHost.Declaration;
|
||||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||||
@@ -14,23 +15,23 @@ import com.volmit.world.PackWorld;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.withSettings;
|
|
||||||
|
|
||||||
/** Object placing builds its placements' noise and its procedural objects' variants before generation asks. */
|
/** Object placing builds its placements' noise and its procedural objects' variants before generation asks. */
|
||||||
public class ObjectWarmUpTest {
|
public class ObjectWarmUpTest {
|
||||||
@Test
|
@Test
|
||||||
public void everyPlacementAndProceduralObjectOfBiomesAndRegionsIsBuilt() {
|
public void everyPlacementAndProceduralObjectOfBiomesAndRegionsIsBuilt() {
|
||||||
ObjectHost host = mock(ObjectHost.class);
|
ObjectHost host = mock(ObjectHost.class);
|
||||||
IrisSeed.Source seeds = mock(IrisSeed.Source.class);
|
IrisSeeds seeds = seed -> seed == IrisSeed.COMPONENT ? 1337L : 0L;
|
||||||
PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(ObjectHost.Source.class, IrisSeed.Source.class));
|
PackWorld world = mock(PackWorld.class);
|
||||||
when(((ObjectHost.Source) world).objects()).thenReturn(host);
|
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||||
when(((IrisSeed.Source) world).seed(IrisSeed.COMPONENT)).thenReturn(1337L);
|
when(world.extension(IrisSeeds.class)).thenReturn(Optional.of(seeds));
|
||||||
ObjectPlacement biomePlacement = placement();
|
ObjectPlacement biomePlacement = placement();
|
||||||
ObjectPlacement regionPlacement = placement();
|
ObjectPlacement regionPlacement = placement();
|
||||||
ProceduralObjectSettings biomeProceduralSettings = new ProceduralObjectSettings();
|
ProceduralObjectSettings biomeProceduralSettings = new ProceduralObjectSettings();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.withSettings;
|
|
||||||
|
|
||||||
/** Trees only replace the platform's growth when the dimension asks for it and a placement of the area grows that species. */
|
/** Trees only replace the platform's growth when the dimension asks for it and a placement of the area grows that species. */
|
||||||
public class TreeGrowingTest {
|
public class TreeGrowingTest {
|
||||||
@@ -63,8 +62,8 @@ public class TreeGrowingTest {
|
|||||||
host = mock(ObjectHost.class);
|
host = mock(ObjectHost.class);
|
||||||
settings = mock(FeatureSettings.class);
|
settings = mock(FeatureSettings.class);
|
||||||
when(host.columnSettings()).thenReturn(settings);
|
when(host.columnSettings()).thenReturn(settings);
|
||||||
world = mock(PackWorld.class, withSettings().extraInterfaces(ObjectHost.Source.class));
|
world = mock(PackWorld.class);
|
||||||
when(((ObjectHost.Source) world).objects()).thenReturn(host);
|
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(host));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
|||||||
import art.arcane.volmlib.util.matter.Matter;
|
import art.arcane.volmlib.util.matter.Matter;
|
||||||
import com.volmit.noise.NoiseSampler;
|
import com.volmit.noise.NoiseSampler;
|
||||||
import art.arcane.iris.builtin.IrisStages;
|
import art.arcane.iris.builtin.IrisStages;
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||||
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
import art.arcane.iris.builtin.post.PostProcessingSlabsSettings;
|
||||||
@@ -74,7 +74,7 @@ import com.volmit.object.BlockEntityData;
|
|||||||
import com.volmit.resource.PackResources;
|
import com.volmit.resource.PackResources;
|
||||||
import com.volmit.resource.ResourceId;
|
import com.volmit.resource.ResourceId;
|
||||||
import com.volmit.config.FeatureSettings.Entry;
|
import com.volmit.config.FeatureSettings.Entry;
|
||||||
import com.volmit.resource.ResourceKey;
|
import com.volmit.resource.ResourceKind;
|
||||||
import com.volmit.stage.Pipeline;
|
import com.volmit.stage.Pipeline;
|
||||||
import com.volmit.world.BiomeKind;
|
import com.volmit.world.BiomeKind;
|
||||||
import com.volmit.world.BiomeSample;
|
import com.volmit.world.BiomeSample;
|
||||||
@@ -338,6 +338,11 @@ public final class ApiChunk implements GenerationContext {
|
|||||||
return new ChunkMantle();
|
return new ChunkMantle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
|
return type == MatterMantle.class ? Optional.of(type.cast(new ChunkMantle())) : Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> Hunk<T> hunk(Class<T> type) {
|
public <T> Hunk<T> hunk(Class<T> type) {
|
||||||
@@ -488,8 +493,8 @@ public final class ApiChunk implements GenerationContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MantleLayer<Boolean> caverns() {
|
public boolean isCarved(int x, int y, int z) {
|
||||||
return new CarvedLayer();
|
return carved.contains(new BlockPosition(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -534,55 +539,21 @@ public final class ApiChunk implements GenerationContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class CarvedLayer implements MantleLayer<Boolean> {
|
/**
|
||||||
@Override
|
* A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. It has
|
||||||
public Boolean get(int x, int y, int z) {
|
* no floating islands: its floating host answers no surface biome, so no column has an island.
|
||||||
return carved.contains(new BlockPosition(x, y, z)) ? Boolean.TRUE : null;
|
*/
|
||||||
}
|
private final class World implements PackWorld {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(int x, int y, int z, Boolean value) {
|
|
||||||
throw new UnsupportedOperationException("Caverns are read-only");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(int x, int y, int z) {
|
|
||||||
throw new UnsupportedOperationException("Caverns are read-only");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(BlockBox area, MantleVisitor<Boolean> visitor) {
|
|
||||||
List<BlockPosition> positions = new ArrayList<>(carved);
|
|
||||||
positions.sort(VISIT_ORDER);
|
|
||||||
for (BlockPosition position : positions) {
|
|
||||||
if (area.contains(position.x(), position.y(), position.z())) {
|
|
||||||
visitor.accept(position.x(), position.y(), position.z(), Boolean.TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear(BlockBox area) {
|
|
||||||
throw new UnsupportedOperationException("Caverns are read-only");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** A world of the chunk: its pack's blocks, a state store and Iris's seeds, each the world seed plus its place. */
|
|
||||||
/** A world without floating islands: its floating host answers no surface biome, so no column has an island. */
|
|
||||||
private final class World implements PackWorld, IrisSeed.Source, FloatingHost.Source, ObjectHost.Source {
|
|
||||||
private final Resources resources = new Resources();
|
private final Resources resources = new Resources();
|
||||||
private final Map<Class<?>, Object> states = new HashMap<>();
|
private final Map<Class<?>, Object> states = new HashMap<>();
|
||||||
|
private final IrisSeeds seeds = seed -> SEED + seed.ordinal();
|
||||||
private final FloatingHost floating = mock(FloatingHost.class);
|
private final FloatingHost floating = mock(FloatingHost.class);
|
||||||
private final ObjectHost objects = mock(ObjectHost.class);
|
private final ObjectHost objects = mock(ObjectHost.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FloatingHost floating() {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return floating;
|
Object offered = type == IrisSeeds.class ? seeds : type == FloatingHost.class ? floating : type == ObjectHost.class ? objects : null;
|
||||||
}
|
return Optional.ofNullable(offered).map(type::cast);
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectHost objects() {
|
|
||||||
return objects;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -620,15 +591,6 @@ public final class ApiChunk implements GenerationContext {
|
|||||||
return ModuleLogs.discarding();
|
return ModuleLogs.discarding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackWorld withLog(ModuleLog log) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long seed(IrisSeed seed) {
|
|
||||||
return SEED + seed.ordinal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class Resources implements PackResources {
|
private static final class Resources implements PackResources {
|
||||||
@@ -670,12 +632,12 @@ public final class ApiChunk implements GenerationContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> find(ResourceKey<T> key) {
|
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourceId> ids(Class<?> type) {
|
public List<ResourceId> ids(ResourceKind<?> kind) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,19 +57,19 @@ public class CaveBiomeBandsTest {
|
|||||||
public void aPositionInsideAnEnabledBandGetsTheBandsBiomeKey() {
|
public void aPositionInsideAnEnabledBandGetsTheBandsBiomeKey() {
|
||||||
CaveBiomeBands bands = new CaveBiomeBands();
|
CaveBiomeBands bands = new CaveBiomeBands();
|
||||||
|
|
||||||
assertEquals("world Y -54 is in the band from -64 to 0", Optional.of("band/shallow"), bands.overriddenBiome(world, 5, 10, 5));
|
assertEquals("world Y -54 is in the band from -64 to 0", Optional.of(CarveTestWorld.id("band/shallow")), bands.overriddenBiome(world, 5, 10, 5));
|
||||||
assertEquals("the band's end is in it", Optional.of("band/shallow"), bands.overriddenBiome(world, 5, 64, 5));
|
assertEquals("the band's end is in it", Optional.of(CarveTestWorld.id("band/shallow")), bands.overriddenBiome(world, 5, 64, 5));
|
||||||
assertEquals("above it", Optional.empty(), bands.overriddenBiome(world, 5, 65, 5));
|
assertEquals("above it", Optional.empty(), bands.overriddenBiome(world, 5, 65, 5));
|
||||||
assertEquals("a disabled band overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 200 - MIN_HEIGHT - 50, 5));
|
assertEquals("a disabled band overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 200 - MIN_HEIGHT - 50, 5));
|
||||||
assertEquals("a band whose biome the pack lacks overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 305 - MIN_HEIGHT, 5));
|
assertEquals("a band whose biome the pack lacks overrides nothing", Optional.empty(), bands.overriddenBiome(world, 5, 305 - MIN_HEIGHT, 5));
|
||||||
assertEquals("the key is trimmed as the pack is asked for it", Optional.of("band/padded"), bands.overriddenBiome(world, 5, 550 - MIN_HEIGHT, 5));
|
assertEquals("the key is trimmed as the pack is asked for it", Optional.of(CarveTestWorld.id("band/padded")), bands.overriddenBiome(world, 5, 550 - MIN_HEIGHT, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aBiomeKeyHasTheMinimumDepthItsSettingsDeclareAndZeroWhenTheKeyIsUnknown() {
|
public void aBiomeKeyHasTheMinimumDepthItsSettingsDeclareAndZeroWhenTheKeyIsUnknown() {
|
||||||
CaveBiomeBands bands = new CaveBiomeBands();
|
CaveBiomeBands bands = new CaveBiomeBands();
|
||||||
|
|
||||||
assertEquals(30, bands.minDepthBelowSurface(world, "band/shallow"));
|
assertEquals(30, bands.minDepthBelowSurface(world, CarveTestWorld.id("band/shallow")));
|
||||||
assertEquals(0, bands.minDepthBelowSurface(world, "band/unknown"));
|
assertEquals(0, bands.minDepthBelowSurface(world, CarveTestWorld.id("band/unknown")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package art.arcane.iris.engine.modifier;
|
package art.arcane.iris.engine.modifier;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.floating.FloatingHost;
|
import art.arcane.iris.builtin.floating.FloatingHost;
|
||||||
import art.arcane.iris.builtin.objects.ObjectHost;
|
import art.arcane.iris.builtin.objects.ObjectHost;
|
||||||
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
import art.arcane.iris.engine.decorator.BiomeDecorators;
|
||||||
@@ -16,6 +16,7 @@ import com.volmit.stage.ChunkStageContext;
|
|||||||
import com.volmit.world.PackWorld;
|
import com.volmit.world.PackWorld;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
@@ -25,7 +26,6 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.withSettings;
|
|
||||||
|
|
||||||
/** A column whose biome declares no floating child biomes gets no island: nothing is written or decorated. */
|
/** A column whose biome declares no floating child biomes gets no island: nothing is written or decorated. */
|
||||||
public class FloatingIslandsTest {
|
public class FloatingIslandsTest {
|
||||||
@@ -60,9 +60,10 @@ public class FloatingIslandsTest {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static PackWorld world(FloatingHost host) {
|
private static PackWorld world(FloatingHost host) {
|
||||||
PackWorld world = mock(PackWorld.class, withSettings().extraInterfaces(FloatingHost.Source.class, ObjectHost.Source.class, IrisSeed.Source.class));
|
PackWorld world = mock(PackWorld.class);
|
||||||
when(((FloatingHost.Source) world).floating()).thenReturn(host);
|
when(world.extension(FloatingHost.class)).thenReturn(Optional.of(host));
|
||||||
when(((ObjectHost.Source) world).objects()).thenReturn(mock(ObjectHost.class));
|
when(world.extension(ObjectHost.class)).thenReturn(Optional.of(mock(ObjectHost.class)));
|
||||||
|
when(world.extension(IrisSeeds.class)).thenReturn(Optional.of(seed -> 0L));
|
||||||
when(world.resources()).thenReturn(mock(PackResources.class));
|
when(world.resources()).thenReturn(mock(PackResources.class));
|
||||||
PackSettings nothingDeclared = mock(PackSettings.class);
|
PackSettings nothingDeclared = mock(PackSettings.class);
|
||||||
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
|
when(nothingDeclared.declared(any())).thenAnswer(invocation -> SettingsStack.empty());
|
||||||
|
|||||||
+6
-10
@@ -423,11 +423,9 @@ public class IrisObjectPlacementRegressionTest {
|
|||||||
/** Looks up the pack's oak through the placement's resources. */
|
/** Looks up the pack's oak through the placement's resources. */
|
||||||
private static final class FindModule implements IrisModule {
|
private static final class FindModule implements IrisModule {
|
||||||
private static final PlacementStage<Void> FIND = Stage.placement("test:find/oak");
|
private static final PlacementStage<Void> FIND = Stage.placement("test:find/oak");
|
||||||
private final java.io.File packFolder;
|
|
||||||
private final List<Object> found;
|
private final List<Object> found;
|
||||||
|
|
||||||
private FindModule(java.io.File packFolder, List<Object> found) {
|
private FindModule(List<Object> found) {
|
||||||
this.packFolder = packFolder;
|
|
||||||
this.found = found;
|
this.found = found;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,14 +437,14 @@ public class IrisObjectPlacementRegressionTest {
|
|||||||
@Override
|
@Override
|
||||||
public void setup(ModuleSetup setup) {
|
public void setup(ModuleSetup setup) {
|
||||||
setup.stages().define(FIND).requires(IrisStages.Blocks.COMPLETE).run(context ->
|
setup.stages().define(FIND).requires(IrisStages.Blocks.COMPLETE).run(context ->
|
||||||
found.add(context.world().resources().find(PackResourceFixture.oakKey(packFolder)).orElseThrow()));
|
found.add(PackResourceFixture.oak(context.world().resources())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aPasteWithoutAnEngineFindsThePacksResourcesThroughItsWorld() throws IOException {
|
public void aPasteWithoutAnEngineFindsThePacksResourcesThroughItsWorld() throws IOException {
|
||||||
List<Object> found = new ArrayList<>();
|
List<Object> found = new ArrayList<>();
|
||||||
usePack(List.of(new FindModule(folder.getRoot(), found)));
|
usePack(List.of(new FindModule(found)));
|
||||||
PackResourceFixture.serve(data);
|
PackResourceFixture.serve(data);
|
||||||
|
|
||||||
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
||||||
@@ -511,11 +509,9 @@ public class IrisObjectPlacementRegressionTest {
|
|||||||
/** Lays the pack's oak on its side, a quarter turn about X, through the placement's object transformer. */
|
/** Lays the pack's oak on its side, a quarter turn about X, through the placement's object transformer. */
|
||||||
private static final class TurnModule implements IrisModule {
|
private static final class TurnModule implements IrisModule {
|
||||||
private static final PlacementStage<Void> TURN = Stage.placement("test:turn/oak");
|
private static final PlacementStage<Void> TURN = Stage.placement("test:turn/oak");
|
||||||
private final java.io.File packFolder;
|
|
||||||
private final List<GeneratedObject> turned;
|
private final List<GeneratedObject> turned;
|
||||||
|
|
||||||
private TurnModule(java.io.File packFolder, List<GeneratedObject> turned) {
|
private TurnModule(List<GeneratedObject> turned) {
|
||||||
this.packFolder = packFolder;
|
|
||||||
this.turned = turned;
|
this.turned = turned;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +523,7 @@ public class IrisObjectPlacementRegressionTest {
|
|||||||
@Override
|
@Override
|
||||||
public void setup(ModuleSetup setup) {
|
public void setup(ModuleSetup setup) {
|
||||||
setup.stages().define(TURN).requires(IrisStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
|
setup.stages().define(TURN).requires(IrisStages.Blocks.COMPLETE).run(context -> turned.add(context.objects().transform(
|
||||||
context.world().resources().require(PackResourceFixture.oakKey(packFolder)),
|
PackResourceFixture.oak(context.world().resources()),
|
||||||
new ObjectTransform(90, 0, 0, 1, 1, 1, false, false, false))));
|
new ObjectTransform(90, 0, 0, 1, 1, 1, false, false, false))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -535,7 +531,7 @@ public class IrisObjectPlacementRegressionTest {
|
|||||||
@Test
|
@Test
|
||||||
public void aPlacementStageTurnsAnObjectThroughTheObjectTransformer() throws IOException {
|
public void aPlacementStageTurnsAnObjectThroughTheObjectTransformer() throws IOException {
|
||||||
List<GeneratedObject> turned = new ArrayList<>();
|
List<GeneratedObject> turned = new ArrayList<>();
|
||||||
usePack(List.of(new TurnModule(folder.getRoot(), turned)));
|
usePack(List.of(new TurnModule(turned)));
|
||||||
PackResourceFixture.serve(data);
|
PackResourceFixture.serve(data);
|
||||||
|
|
||||||
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
ObjectPlacementResult result = place(placement(), ANCHOR_Y, new RecordingPlacer(null), null);
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,7 @@
|
|||||||
package art.arcane.iris.engine.object.terrain.carving;
|
package art.arcane.iris.engine.object.terrain.carving;
|
||||||
|
|
||||||
|
import art.arcane.iris.builtin.IrisSeed;
|
||||||
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.builtin.carve.CarvingEntry;
|
import art.arcane.iris.builtin.carve.CarvingEntry;
|
||||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||||
import art.arcane.iris.core.modules.CarveTestWorld;
|
import art.arcane.iris.core.modules.CarveTestWorld;
|
||||||
@@ -259,7 +261,7 @@ public class CarvingResolverParityTest {
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
long seed = world.seed(art.arcane.iris.builtin.IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
long seed = world.extension(IrisSeeds.class).orElseThrow().seed(IrisSeed.CARVE) ^ CHILD_SEED_SALT;
|
||||||
LegacyCarvingChoice selected = legacyChildrenGenerator(parent, seed).fitRarity(options, worldX, worldZ);
|
LegacyCarvingChoice selected = legacyChildrenGenerator(parent, seed).fitRarity(options, worldX, worldZ);
|
||||||
if (selected == null || selected.entry == null) {
|
if (selected == null || selected.entry == null) {
|
||||||
return parent;
|
return parent;
|
||||||
|
|||||||
+7
@@ -9,6 +9,8 @@ import art.arcane.iris.builtin.carve.CarvingEntry;
|
|||||||
import art.arcane.iris.builtin.carve.CarvingSettings;
|
import art.arcane.iris.builtin.carve.CarvingSettings;
|
||||||
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
||||||
import art.arcane.iris.core.modules.BuiltInPack;
|
import art.arcane.iris.core.modules.BuiltInPack;
|
||||||
|
import art.arcane.iris.core.modules.IrisPackResources;
|
||||||
|
import art.arcane.iris.core.modules.PackResourceFixture;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
@@ -17,6 +19,7 @@ import art.arcane.volmlib.util.collection.KList;
|
|||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -59,11 +62,13 @@ public class IrisDimensionReachableBiomesTest {
|
|||||||
IrisBiome disabledDeep = biome("disabled-deep");
|
IrisBiome disabledDeep = biome("disabled-deep");
|
||||||
IrisBiome unused = biome("unused");
|
IrisBiome unused = biome("unused");
|
||||||
|
|
||||||
|
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||||
IrisData data = mock(IrisData.class);
|
IrisData data = mock(IrisData.class);
|
||||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||||
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
||||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||||
|
when(data.getPackResources()).thenReturn(resources);
|
||||||
when(regionLoader.load("reachable")).thenReturn(reachable);
|
when(regionLoader.load("reachable")).thenReturn(reachable);
|
||||||
when(biomeLoader.load("parent")).thenReturn(parent);
|
when(biomeLoader.load("parent")).thenReturn(parent);
|
||||||
when(biomeLoader.load("child")).thenReturn(child);
|
when(biomeLoader.load("child")).thenReturn(child);
|
||||||
@@ -106,11 +111,13 @@ public class IrisDimensionReachableBiomesTest {
|
|||||||
IrisBiome d = biome("d", floatingChildren(floating("b")))
|
IrisBiome d = biome("d", floatingChildren(floating("b")))
|
||||||
.setChildren(new KList<>("a"));
|
.setChildren(new KList<>("a"));
|
||||||
|
|
||||||
|
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||||
IrisData data = mock(IrisData.class);
|
IrisData data = mock(IrisData.class);
|
||||||
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
|
||||||
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
|
||||||
when(data.getRegionLoader()).thenReturn(regionLoader);
|
when(data.getRegionLoader()).thenReturn(regionLoader);
|
||||||
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
when(data.getBiomeLoader()).thenReturn(biomeLoader);
|
||||||
|
when(data.getPackResources()).thenReturn(resources);
|
||||||
when(regionLoader.load("reachable")).thenReturn(reachable);
|
when(regionLoader.load("reachable")).thenReturn(reachable);
|
||||||
when(biomeLoader.load("a")).thenReturn(a);
|
when(biomeLoader.load("a")).thenReturn(a);
|
||||||
when(biomeLoader.load("b")).thenReturn(b);
|
when(biomeLoader.load("b")).thenReturn(b);
|
||||||
|
|||||||
+5
@@ -24,12 +24,15 @@ import art.arcane.iris.builtin.floating.FloatingChildSettings;
|
|||||||
import art.arcane.iris.core.loader.IrisData;
|
import art.arcane.iris.core.loader.IrisData;
|
||||||
import art.arcane.iris.core.loader.ResourceLoader;
|
import art.arcane.iris.core.loader.ResourceLoader;
|
||||||
import art.arcane.iris.core.modules.BuiltInPack;
|
import art.arcane.iris.core.modules.BuiltInPack;
|
||||||
|
import art.arcane.iris.core.modules.IrisPackResources;
|
||||||
|
import art.arcane.iris.core.modules.PackResourceFixture;
|
||||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||||
import art.arcane.volmlib.util.collection.KList;
|
import art.arcane.volmlib.util.collection.KList;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -51,9 +54,11 @@ public class IrisRegionBiomeTreeTest {
|
|||||||
IrisBiome mushroom = biome("carving/mushroom", new CarvingBiomeSettings("carving/nested"));
|
IrisBiome mushroom = biome("carving/mushroom", new CarvingBiomeSettings("carving/nested"));
|
||||||
IrisBiome nested = biome("carving/nested");
|
IrisBiome nested = biome("carving/nested");
|
||||||
|
|
||||||
|
IrisPackResources resources = PackResourceFixture.empty(new File("pack"));
|
||||||
IrisData data = mock(IrisData.class);
|
IrisData data = mock(IrisData.class);
|
||||||
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
ResourceLoader<IrisBiome> biomes = mock(ResourceLoader.class);
|
||||||
when(data.getBiomeLoader()).thenReturn(biomes);
|
when(data.getBiomeLoader()).thenReturn(biomes);
|
||||||
|
when(data.getPackResources()).thenReturn(resources);
|
||||||
when(biomes.load("plains")).thenReturn(plains);
|
when(biomes.load("plains")).thenReturn(plains);
|
||||||
when(biomes.load("meadow")).thenReturn(meadow);
|
when(biomes.load("meadow")).thenReturn(meadow);
|
||||||
when(biomes.load("carving/mushroom")).thenReturn(mushroom);
|
when(biomes.load("carving/mushroom")).thenReturn(mushroom);
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -92,13 +92,13 @@ public class AmbientEffectingTest {
|
|||||||
List<AmbientEffects.Effect> due = new AmbientEffecting().due(world, AT);
|
List<AmbientEffects.Effect> due = new AmbientEffecting().due(world, AT);
|
||||||
|
|
||||||
assertEquals(1, due.size());
|
assertEquals(1, due.size());
|
||||||
AmbientEffects.Sound sound = due.getFirst().sound();
|
AmbientEffects.Sound sound = due.getFirst().sound().orElseThrow();
|
||||||
assertEquals("ambient.cave", sound.key());
|
assertEquals("ambient.cave", sound.key());
|
||||||
assertTrue(Math.abs(sound.offsetX()) <= 4 && Math.abs(sound.offsetY()) <= 4 && Math.abs(sound.offsetZ()) <= 4);
|
assertTrue(Math.abs(sound.offsetX()) <= 4 && Math.abs(sound.offsetY()) <= 4 && Math.abs(sound.offsetZ()) <= 4);
|
||||||
assertEquals(2F, sound.volume(), 0);
|
assertEquals(2F, sound.volume(), 0);
|
||||||
assertEquals(0.5F, sound.pitch(), 0);
|
assertEquals(0.5F, sound.pitch(), 0);
|
||||||
assertEquals(new AmbientEffects.Potion("luck", 1, 100), due.getFirst().potion());
|
assertEquals(Optional.of(new AmbientEffects.Potion("luck", 1, 100)), due.getFirst().potion());
|
||||||
assertNull(due.getFirst().particles());
|
assertTrue(due.getFirst().particles().isEmpty());
|
||||||
assertTrue(due.getFirst().commands().isEmpty());
|
assertTrue(due.getFirst().commands().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,18 +109,19 @@ public class AmbientEffectingTest {
|
|||||||
|
|
||||||
AmbientEffects.Effect effect = new AmbientEffecting().due(world, AT).getFirst();
|
AmbientEffects.Effect effect = new AmbientEffecting().due(world, AT).getFirst();
|
||||||
|
|
||||||
assertEquals("flame", effect.particles().key());
|
AmbientEffects.Particles particles = effect.particles().orElseThrow();
|
||||||
assertEquals(5, effect.particles().forward(), 0);
|
assertEquals("flame", particles.key());
|
||||||
assertEquals(0, effect.particles().sideways(), 0);
|
assertEquals(5, particles.forward(), 0);
|
||||||
assertEquals(0.5, effect.particles().altX(), 0);
|
assertEquals(0, particles.sideways(), 0);
|
||||||
assertEquals(0.25, effect.particles().extra(), 0);
|
assertEquals(0.5, particles.altX(), 0);
|
||||||
assertEquals(2, effect.particles().count());
|
assertEquals(0.25, particles.extra(), 0);
|
||||||
|
assertEquals(2, particles.count());
|
||||||
assertEquals(1, effect.commands().size());
|
assertEquals(1, effect.commands().size());
|
||||||
assertEquals(List.of("say hi {x}"), effect.commands().getFirst().command().commands());
|
assertEquals(List.of("say hi {x}"), effect.commands().getFirst().command().commands());
|
||||||
assertEquals(3, effect.commands().getFirst().command().delay());
|
assertEquals(3, effect.commands().getFirst().command().delay());
|
||||||
assertEquals(2, effect.commands().getFirst().offsetX(), 0);
|
assertEquals(2, effect.commands().getFirst().offsetX(), 0);
|
||||||
assertNull(effect.sound());
|
assertTrue(effect.sound().isEmpty());
|
||||||
assertNull(effect.potion());
|
assertTrue(effect.potion().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import art.arcane.volmlib.util.math.RNG;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.volmit.entity.EntitySpec;
|
import com.volmit.entity.EntitySpec;
|
||||||
import com.volmit.item.ItemRegistry;
|
import com.volmit.item.ItemRegistry;
|
||||||
|
import com.volmit.resource.PackResources;
|
||||||
|
import com.volmit.resource.ResourceId;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -38,6 +40,8 @@ import static org.mockito.Mockito.when;
|
|||||||
/**
|
/**
|
||||||
* What an entity of the pack becomes when it is made from a fixed stream, hashed. The number was taken before the entity
|
* What an entity of the pack becomes when it is made from a fixed stream, hashed. The number was taken before the entity
|
||||||
* classes became settings of the spawn module; a change in it changes the equipment, attributes and passengers worlds spawn.
|
* classes became settings of the spawn module; a change in it changes the equipment, attributes and passengers worlds spawn.
|
||||||
|
* It was retaken once when absent values became {@code Optional}s and loot tables ids: the spec printed the old way (empty
|
||||||
|
* texts as {@code ""}, other absent values as {@code null}, tables by key) still hashed to the old number, -819231818.
|
||||||
*/
|
*/
|
||||||
public class EntityResolutionPinTest {
|
public class EntityResolutionPinTest {
|
||||||
private static final long STREAM_SEED = 4321L;
|
private static final long STREAM_SEED = 4321L;
|
||||||
@@ -67,8 +71,11 @@ public class EntityResolutionPinTest {
|
|||||||
Optional<Sky> sky = Optional.of(new Sky(0L, false, false));
|
Optional<Sky> sky = Optional.of(new Sky(0L, false, false));
|
||||||
EntityDefinition entity = new Gson().fromJson(ENTITY, EntityDefinition.class);
|
EntityDefinition entity = new Gson().fromJson(ENTITY, EntityDefinition.class);
|
||||||
|
|
||||||
EntitySpec spec = new EntityResolution(new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
PackResources resources = mock(PackResources.class);
|
||||||
|
when(resources.idOf(anyString())).thenAnswer(invocation -> new ResourceId("test", invocation.getArgument(0)));
|
||||||
|
|
||||||
assertEquals(-819231818, spec.toString().hashCode());
|
EntitySpec spec = new EntityResolution(resources, new LootItems(registry, false), sky, new EffectTimers()).resolve(entity, new RNG(STREAM_SEED));
|
||||||
|
|
||||||
|
assertEquals(1441930785, spec.toString().hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public class EntitySpawningTest {
|
|||||||
|
|
||||||
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow();
|
EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow();
|
||||||
|
|
||||||
assertEquals(List.of("zombies"), rule.spawners());
|
assertEquals("a spawner the pack lacks is left out", List.of(world.resources().idOf("zombies")), rule.spawners());
|
||||||
assertTrue(rule.emptyAbove());
|
assertTrue(rule.emptyAbove());
|
||||||
assertFalse(rule.removeOnChange());
|
assertFalse(rule.removeOnChange());
|
||||||
}
|
}
|
||||||
@@ -123,16 +123,16 @@ public class EntitySpawningTest {
|
|||||||
when(engine.getMinHeight()).thenReturn(-64);
|
when(engine.getMinHeight()).thenReturn(-64);
|
||||||
|
|
||||||
EntitySpawns.Plan plan = new EntitySpawning()
|
EntitySpawns.Plan plan = new EntitySpawning()
|
||||||
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "camp/zombies", false))
|
.plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("camp/zombies"), false))
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
|
|
||||||
assertEquals("camp/zombies", plan.spawner());
|
assertEquals(world.resources().idOf("camp/zombies"), plan.spawner());
|
||||||
assertTrue("an exhaustion chance above 1 always uses the marker up", plan.exhaustsMarker());
|
assertTrue("an exhaustion chance above 1 always uses the marker up", plan.exhaustsMarker());
|
||||||
assertEquals(2, plan.attempts().size());
|
assertEquals(2, plan.attempts().size());
|
||||||
for (EntitySpawns.Attempt attempt : plan.attempts()) {
|
for (EntitySpawns.Attempt attempt : plan.attempts()) {
|
||||||
assertEquals(new BlockPosition(40, 71, -12), attempt.at());
|
assertEquals(new BlockPosition(40, 71, -12), attempt.at());
|
||||||
assertFalse(attempt.checkSurface());
|
assertFalse(attempt.checkSurface());
|
||||||
assertEquals("minecraft:zombie", attempt.entity().type());
|
assertEquals(Optional.of("minecraft:zombie"), attempt.entity().type());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ public class EntitySpawningTest {
|
|||||||
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
|
public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() {
|
||||||
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
|
fixture.resource(SpawnResources.SPAWNERS, "empty", new Spawner());
|
||||||
|
|
||||||
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "empty", false));
|
Optional<EntitySpawns.Plan> plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", world.resources().idOf("empty"), false));
|
||||||
|
|
||||||
assertTrue(plan.isEmpty());
|
assertTrue(plan.isEmpty());
|
||||||
}
|
}
|
||||||
@@ -150,11 +150,11 @@ public class EntitySpawningTest {
|
|||||||
fixture.resource(SpawnResources.ENTITIES, "cow", TestSettings.of(EntityDefinition.class,
|
fixture.resource(SpawnResources.ENTITIES, "cow", TestSettings.of(EntityDefinition.class,
|
||||||
"{\"type\": \"minecraft:cow\", \"customName\": \"&6Bessie\", \"baby\": true}"));
|
"{\"type\": \"minecraft:cow\", \"customName\": \"&6Bessie\", \"baby\": true}"));
|
||||||
|
|
||||||
EntitySpec spec = new EntitySpawning().entity(world, "cow").orElseThrow();
|
EntitySpec spec = new EntitySpawning().entity(world, world.resources().idOf("cow")).orElseThrow();
|
||||||
|
|
||||||
assertEquals("minecraft:cow", spec.type());
|
assertEquals(Optional.of("minecraft:cow"), spec.type());
|
||||||
assertEquals("&6Bessie", spec.customName());
|
assertEquals(Optional.of("&6Bessie"), spec.customName());
|
||||||
assertTrue(spec.flags().baby());
|
assertTrue(spec.flags().baby());
|
||||||
assertTrue(new EntitySpawning().entity(world, "nothing").isEmpty());
|
assertTrue(new EntitySpawning().entity(world, world.resources().idOf("nothing")).isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public class SpawnerGateTest {
|
|||||||
when(engine.getWorld()).thenReturn(engineWorld);
|
when(engine.getWorld()).thenReturn(engineWorld);
|
||||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||||
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
when(engine.getEngineData()).thenReturn(new IrisEngineData());
|
||||||
live = LiveWorld.of(new EngineGeneration(engine).world());
|
live = new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -105,7 +105,7 @@ public class SpawnerGateTest {
|
|||||||
when(engine.getData()).thenReturn(mock(IrisData.class));
|
when(engine.getData()).thenReturn(mock(IrisData.class));
|
||||||
when(engine.getWorld()).thenReturn(mock(IrisWorld.class));
|
when(engine.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||||
|
|
||||||
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), LiveWorld.of(new EngineGeneration(engine).world()), 0, 0));
|
assertFalse(SpawnerGate.canSpawn("any", spawner("{}"), new EngineGeneration(engine).world().extension(LiveWorld.class).orElseThrow(), 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Spawner spawner(String json) {
|
private static Spawner spawner(String json) {
|
||||||
|
|||||||
@@ -65,10 +65,5 @@ public final class TestLayerBlocks {
|
|||||||
public ModuleLog log() {
|
public ModuleLog log() {
|
||||||
return ModuleLogs.discarding();
|
return ModuleLogs.discarding();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PackWorld withLog(ModuleLog log) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
package art.arcane.iris.engine.terrain;
|
package art.arcane.iris.engine.terrain;
|
||||||
|
|
||||||
import art.arcane.iris.builtin.IrisSeed;
|
import art.arcane.iris.builtin.IrisSeeds;
|
||||||
import art.arcane.iris.core.modules.ModuleSettings;
|
import art.arcane.iris.core.modules.ModuleSettings;
|
||||||
import com.volmit.config.Level;
|
import com.volmit.config.Level;
|
||||||
import com.volmit.IrisFeature;
|
import com.volmit.IrisFeature;
|
||||||
@@ -39,7 +39,7 @@ import java.util.Optional;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/** A world of a pack's resources whose dimension declares the given settings and whose complex and terrain seeds are given, for tests of the terrain's support classes. */
|
/** A world of a pack's resources whose dimension declares the given settings and whose complex and terrain seeds are given, for tests of the terrain's support classes. */
|
||||||
public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
public final class TestPackWorld implements PackWorld {
|
||||||
private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld");
|
private static final ResourceId DIMENSION = ResourceId.parse("test:dimension/overworld");
|
||||||
|
|
||||||
private final PackResources resources;
|
private final PackResources resources;
|
||||||
@@ -83,11 +83,6 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
|||||||
return seed;
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long seed(IrisSeed which) {
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PackResources resources() {
|
public PackResources resources() {
|
||||||
return resources;
|
return resources;
|
||||||
@@ -109,7 +104,8 @@ public final class TestPackWorld implements PackWorld, IrisSeed.Source {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PackWorld withLog(ModuleLog log) {
|
public <T> Optional<T> extension(Class<T> type) {
|
||||||
return this;
|
IrisSeeds everySeedIsTheWorlds = which -> seed;
|
||||||
|
return type == IrisSeeds.class ? Optional.of(type.cast(everySeedIsTheWorlds)) : Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user