Merge branch 'wave3/l' into feat/irisapi-host

This commit is contained in:
piexel committed 2026-10-10 13:05:52 +02:00
commit b60ca588fe
74 files changed
+4776 -1538

No files matched your search

@@ -0,0 +1,44 @@
/*
* 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.content;
import java.util.List;
/**
* An ambient effect that plays now, in host terms: what {@code com.volmit.service.AmbientEffects.Effect} says. The
* adapter carries out the parts it has, in the order sound, particles, commands, potion.
*/
public record ContentEffect(Sound sound, Particles particles, List<Command> commands, Potion potion) {
/** A sound, with blocks offset from the player and the volume and pitch decided. */
public record Sound(String key, int offsetX, int offsetY, int offsetZ, float volume, float pitch) {
}
/** Particles {@code forward} blocks ahead of the player and {@code sideways} to the right, on the surface there. */
public record Particles(String key, double forward, double sideways, double jitterX, double jitterZ, int lift, int count,
double altX, double altY, double altZ, double extra) {
}
/** Commands run offset from the player. */
public record Command(ContentEntity.Command command, double offsetX, double offsetY, double offsetZ) {
}
/** A potion effect for the player; one with a stronger amplifier already on the player stays. */
public record Potion(String key, int strength, int ticks) {
}
}
@@ -0,0 +1,57 @@
/*
* 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.content;
import java.util.List;
/**
* An entity a module decided on, in host terms: what {@code com.volmit.entity.EntitySpec} says, for adapters that cannot
* name IrisApi types. Everything random was decided by the module; the adapter creates and configures the entity.
*/
public record ContentEntity(String type, String specialType, String reason, String customName, Flags flags, Equipment equipment,
List<ContentEntity> passengers, List<ContentItem.Attribute> attributes, List<String> lootTables,
long lootShuffleSeed, ContentEntity leashHolder, SpawnEffect spawnEffect, boolean riseOutOfGround,
String pandaMainGene, String pandaHiddenGene, boolean applySettingsToSpecial,
List<Command> commands) {
/** Whether the entity is a mob of another plugin. */
public boolean isSpecial() {
return !specialType.isEmpty();
}
/** What an entity can be set to be, whatever its kind. */
public record Flags(boolean customNameVisible, boolean aware, boolean ai, boolean glowing, boolean gravity,
boolean invulnerable, boolean silent, boolean pickupItems, boolean removable,
boolean keepEntity, boolean baby) {
}
/** The items an entity wears and holds; null for an empty slot. */
public record Equipment(ContentItem helmet, ContentItem chestplate, ContentItem leggings, ContentItem boots,
ContentItem mainHand, ContentItem offHand) {
}
/** Sound and particles shown around an entity that appears; the adapter makes the random choices of the particle motion. */
public record SpawnEffect(String sound, int soundDistance, double minPitch, double maxPitch, double volume,
String particle, int particleOffset, int particleCount, double altX, double altY,
double altZ, boolean randomAltX, boolean randomAltY, boolean randomAltZ, double extra) {
}
/** Console commands run when an entity appears; {@code {x}}, {@code {y}} and {@code {z}} stand for its block position. */
public record Command(List<String> commands, long delay, boolean repeat, long repeatDelay) {
}
}
@@ -0,0 +1,40 @@
/*
* 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.content;
import java.util.List;
import java.util.Map;
/**
* An item a module decided on, in host terms: what {@code com.volmit.item.ItemDrop} says, for adapters that cannot name
* IrisApi types. The module made every random choice; the adapter only creates the item on its platform.
*
* @param damage the fraction of the item's durability already used, or null to leave it undamaged
*/
public record ContentItem(String item, int amount, String displayName, List<String> lore, List<Enchantment> enchantments,
List<Attribute> attributes, boolean unbreakable, List<String> flags, Integer customModel,
Double damage, String leatherColor, String dyeColor, Map<String, Object> customNbt) {
/** An enchantment at the level the module decided. */
public record Enchantment(String key, int level) {
}
/** An attribute modifier with the amount the module decided. */
public record Attribute(String attribute, String name, String operation, double amount) {
}
}
@@ -0,0 +1,47 @@
/*
* 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.content;
import java.util.List;
/** Where a container's items come from and what a broken block drops, in host terms. */
public final class ContentLoot {
private ContentLoot() {
}
/** One source of a container's items, in the order their items are added. */
public sealed interface Part permits Items, PlatformTable {
}
/** Items a module drew from one of the pack's loot tables. */
public record Items(List<ContentItem> items) implements Part {
}
/** A loot table of the platform, which the adapter draws with {@code seed} so the same container always gets the same items. */
public record PlatformTable(String key, long seed) implements Part {
}
/**
* What the modules drop for a broken block.
*
* @param replacesVanillaDrops whether the platform's own drops of the block are not dropped
*/
public record BlockDrops(List<ContentItem> drops, boolean replacesVanillaDrops) {
}
}
@@ -0,0 +1,192 @@
/*
* 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.content;
import art.arcane.iris.core.modules.ModuleServices;
import art.arcane.iris.core.modules.PlatformBlockStates;
import art.arcane.iris.engine.framework.Engine;
import com.volmit.block.BlockState;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemAttribute;
import com.volmit.item.ItemDrop;
import com.volmit.item.ItemEnchantment;
import com.volmit.service.AmbientEffects;
import com.volmit.service.BlockDrops;
import com.volmit.service.EntitySpawns;
import com.volmit.service.Loot;
import com.volmit.world.BlockPosition;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* What the pack's modules say about loot, block drops, spawns and ambient effects, for adapters that cannot name IrisApi
* types: the questions take plain values and the answers are the host types of this package. The modded adapters, which
* fill containers, drop blocks, spawn mobs and play effects themselves, ask here instead of reading the pack's classes.
*/
public final class ContentServices {
private ContentServices() {
}
/**
* The sources of the loot of the container at {@code x}, {@code worldY}, {@code z}, in the order their items are added.
*
* @param containerKey the platform's key for the block when it is a storage chest an object may have given loot, else null
*/
public static List<ContentLoot.Part> containerLoot(Engine engine, int x, int worldY, int z, String containerKey, boolean nativeLootDefined) {
BlockState container = containerKey == null ? null : BlockState.parse(PlatformBlockStates.namespaced(containerKey));
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), container, nativeLootDefined, false);
List<ContentLoot.Part> parts = new ArrayList<>();
for (Loot.Source source : ModuleServices.lootTables(engine, site)) {
switch (source) {
case Loot.Table table -> parts.add(new ContentLoot.Items(tableItems(engine, x, worldY, z, table.key())));
case Loot.PlatformTable table -> parts.add(new ContentLoot.PlatformTable(table.key(), table.seed()));
}
}
return parts;
}
/** The items the pack's loot table {@code tableKey} gives at the spot. */
public static List<ContentItem> tableItems(Engine engine, int x, int worldY, int z, String tableKey) {
Loot.Site site = new Loot.Site(position(engine, x, worldY, z), null, false, false);
return ModuleServices.lootItems(engine, site, tableKey).stream().map(ContentServices::itemOf).toList();
}
/** What the modules drop for the block with the platform's key {@code blockKey} broken at the spot. */
public static ContentLoot.BlockDrops blockDrops(Engine engine, int x, int worldY, int z, String blockKey) {
BlockDrops.Result result = ModuleServices.blockDrops(engine, new BlockDrops.Broken(position(engine, x, worldY, z),
BlockState.parse(PlatformBlockStates.namespaced(blockKey))));
return new ContentLoot.BlockDrops(result.drops().stream().map(ContentServices::itemOf).toList(), result.replacesVanillaDrops());
}
/** What the first module with something to spawn in the chunk plans. */
public static Optional<ContentSpawns.Plan> planChunkSpawn(Engine engine, int chunkX, int chunkZ, int livingEntities, boolean initial) {
return planned(engine, new EntitySpawns.Chunk(chunkX, chunkZ, livingEntities, initial));
}
/** What the first module that knows the spawner plans at the marker block. */
public static Optional<ContentSpawns.Plan> planMarkerSpawn(Engine engine, int x, int worldY, int z, String marker, String spawner, boolean initial) {
return planned(engine, new EntitySpawns.Marker(position(engine, x, worldY, z), marker, spawner, initial));
}
/** 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) {
return ModuleServices.markerRule(engine, tag)
.map(rule -> new ContentSpawns.MarkerRule(rule.spawners(), rule.emptyAbove(), rule.removeOnChange()));
}
/** The entity of the pack named {@code key} as a module would spawn it; empty for an unknown key. */
public static Optional<ContentEntity> entity(Engine engine, String key) {
return ModuleServices.entity(engine, key).map(ContentServices::entityOf);
}
/** The ambient effects due for a player standing at the spot. */
public static List<ContentEffect> ambientEffects(Engine engine, int x, int worldY, int z) {
return ModuleServices.ambientEffects(engine, position(engine, x, worldY, z)).stream().map(ContentServices::effectOf).toList();
}
private static Optional<ContentSpawns.Plan> planned(Engine engine, EntitySpawns.Site site) {
return ModuleServices.planSpawn(engine, site).map(planned -> new ContentSpawns.Plan(planned, attemptsOf(engine, planned.plan())));
}
private static List<ContentSpawns.Attempt> attemptsOf(Engine engine, EntitySpawns.Plan plan) {
List<ContentSpawns.Attempt> attempts = new ArrayList<>();
for (EntitySpawns.Attempt attempt : plan.attempts()) {
attempts.add(new ContentSpawns.Attempt(attempt.at().x(), attempt.at().y() + engine.getMinHeight(), attempt.at().z(),
entityOf(attempt.entity()), ContentSpawns.surfaceOf(attempt.surface()), attempt.minLight(), attempt.maxLight(),
attempt.checkSurface()));
}
return attempts;
}
private static BlockPosition position(Engine engine, int x, int worldY, int z) {
return new BlockPosition(x, worldY - engine.getMinHeight(), z);
}
private static ContentItem itemOf(ItemDrop drop) {
return new ContentItem(drop.item(), drop.amount(), drop.displayName(), drop.lore(),
drop.enchantments().stream().map(ContentServices::enchantmentOf).toList(),
drop.attributes().stream().map(ContentServices::attributeOf).toList(), drop.unbreakable(), drop.flags(),
drop.customModel(), drop.damage(), drop.leatherColor(), drop.dyeColor(), drop.customNbt());
}
private static ContentItem.Enchantment enchantmentOf(ItemEnchantment enchantment) {
return new ContentItem.Enchantment(enchantment.key(), enchantment.level());
}
private static ContentItem.Attribute attributeOf(ItemAttribute attribute) {
return new ContentItem.Attribute(attribute.attribute(), attribute.name(), attribute.operation(), attribute.amount());
}
private static ContentEntity entityOf(EntitySpec spec) {
return new ContentEntity(spec.type(), spec.specialType(), spec.reason(), spec.customName(), flagsOf(spec.flags()),
equipmentOf(spec.equipment()), spec.passengers().stream().map(ContentServices::entityOf).toList(),
spec.attributes().stream().map(ContentServices::attributeOf).toList(), spec.lootTables(), spec.lootShuffleSeed(),
spec.leashHolder() == null ? null : entityOf(spec.leashHolder()), spawnEffectOf(spec.spawnEffect()),
spec.riseOutOfGround(), spec.pandaMainGene(), spec.pandaHiddenGene(), spec.applySettingsToSpecial(),
spec.commands().stream().map(ContentServices::commandOf).toList());
}
private static ContentEntity.Flags flagsOf(EntitySpec.Flags flags) {
return new ContentEntity.Flags(flags.customNameVisible(), flags.aware(), flags.ai(), flags.glowing(), flags.gravity(),
flags.invulnerable(), flags.silent(), flags.pickupItems(), flags.removable(), flags.keepEntity(), flags.baby());
}
private static ContentEntity.Equipment equipmentOf(EntitySpec.Equipment equipment) {
return new ContentEntity.Equipment(optionalItem(equipment.helmet()), optionalItem(equipment.chestplate()),
optionalItem(equipment.leggings()), optionalItem(equipment.boots()), optionalItem(equipment.mainHand()),
optionalItem(equipment.offHand()));
}
private static ContentItem optionalItem(ItemDrop drop) {
return drop == null ? null : itemOf(drop);
}
private static ContentEntity.SpawnEffect spawnEffectOf(EntitySpec.SpawnEffect effect) {
if (effect == null) {
return null;
}
return new ContentEntity.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(), effect.maxPitch(),
effect.volume(), effect.particle(), effect.particleOffset(), effect.particleCount(), effect.altX(), effect.altY(),
effect.altZ(), effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra());
}
private static ContentEntity.Command commandOf(EntitySpec.Command command) {
return new ContentEntity.Command(command.commands(), command.delay(), command.repeat(), command.repeatDelay());
}
private static ContentEffect effectOf(AmbientEffects.Effect effect) {
return new ContentEffect(soundOf(effect.sound()), particlesOf(effect.particles()),
effect.commands().stream().map(command -> new ContentEffect.Command(commandOf(command.command()),
command.offsetX(), command.offsetY(), command.offsetZ())).toList(),
effect.potion() == null ? null : new ContentEffect.Potion(effect.potion().key(), effect.potion().strength(), effect.potion().ticks()));
}
private static ContentEffect.Sound soundOf(AmbientEffects.Sound sound) {
return sound == null ? null : new ContentEffect.Sound(sound.key(), sound.offsetX(), sound.offsetY(), sound.offsetZ(),
sound.volume(), sound.pitch());
}
private static ContentEffect.Particles particlesOf(AmbientEffects.Particles particles) {
return particles == null ? null : new ContentEffect.Particles(particles.key(), particles.forward(), particles.sideways(),
particles.jitterX(), particles.jitterZ(), particles.lift(), particles.count(), particles.altX(), particles.altY(),
particles.altZ(), particles.extra());
}
}
@@ -0,0 +1,85 @@
/*
* 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.content;
import art.arcane.iris.core.modules.ModuleServices;
import com.volmit.service.EntitySpawns;
import java.util.List;
/** What the modules plan to spawn, in host terms. */
public final class ContentSpawns {
private ContentSpawns() {
}
/** The ground or fluid an entity spawns on. */
public enum Surface {
LAND, ANIMAL, WATER, OVERWORLD, LAVA
}
/**
* One entity to spawn at a block, if the light there lies in the range (when {@link #restrictsLight()}) and, when
* {@code checkSurface}, the block below suits the entity's surface and the space it needs is free.
*
* @param x world X
* @param worldY world Y
* @param z world Z
* @param checkSurface whether to check the surface and the free space
*/
public record Attempt(int x, int worldY, int z, ContentEntity entity, Surface surface, int minLight, int maxLight,
boolean checkSurface) {
/** Whether the light level matters. */
public boolean restrictsLight() {
return minLight > 0 || maxLight < 15;
}
}
/** What a marker does: the keys of its spawners, whether it needs free space above it and whether it goes away when its block changes. */
public record MarkerRule(List<String> spawners, boolean emptyAbove, boolean removeOnChange) {
}
/** Entities to spawn, tried one after the other; tell the plan how many appeared, so the spawner's rate limits count them. */
public static final class Plan {
private final ModuleServices.PlannedSpawn planned;
private final List<Attempt> attempts;
Plan(ModuleServices.PlannedSpawn planned, List<Attempt> attempts) {
this.planned = planned;
this.attempts = List.copyOf(attempts);
}
public List<Attempt> attempts() {
return attempts;
}
/** Whether the marker that led here is used up and should be removed. */
public boolean exhaustsMarker() {
return planned.plan().exhaustsMarker();
}
/** Reports how many of the planned entities appeared. */
public void spawned(int count) {
planned.spawned(count);
}
}
static Surface surfaceOf(EntitySpawns.Surface surface) {
return Surface.valueOf(surface.name());
}
}
@@ -0,0 +1,33 @@
/*
* 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.events;
/** The kind of slot of an inventory that loot fills. World generation only ever fills {@link #STORAGE}. */
public enum InventorySlotType {
/** Most slots of an inventory. */
STORAGE,
/** The fuel slot of furnaces, blast furnaces and smokers. */
FUEL,
/** The cook slot of furnaces. */
FURNACE,
/** The cook slot of blast furnaces. */
BLAST_FURNACE,
/** The cook slot of smokers. */
SMOKER
}
@@ -51,6 +51,7 @@ public class IrisLootEvent extends Event {
private final Engine engine;
private final Block block;
private final InventorySlotType slot;
private final KList<Loot.Source> tables;
/**
@@ -58,11 +59,13 @@ public class IrisLootEvent extends Event {
*
* @param engine The engine instance.
* @param block The block associated with the event.
* @param slot The inventory slot type the loot fills.
* @param tables The loot tables the container draws from, as the pack's modules named them. (mutable*)
*/
public IrisLootEvent(Engine engine, Block block, KList<Loot.Source> tables) {
public IrisLootEvent(Engine engine, Block block, InventorySlotType slot, KList<Loot.Source> tables) {
this.engine = engine;
this.block = block;
this.slot = slot;
this.tables = tables;
}
@@ -23,6 +23,7 @@ import art.arcane.iris.engine.framework.Engine;
import com.volmit.host.FeatureCatalog;
import com.volmit.entity.EntitySpec;
import com.volmit.item.ItemDrop;
import com.volmit.service.AmbientEffects;
import com.volmit.service.BlockDrops;
import com.volmit.service.CaveBiomes;
import com.volmit.service.EntitySpawns;
@@ -31,6 +32,7 @@ import com.volmit.service.Loot;
import com.volmit.service.ObjectsAt;
import com.volmit.service.SaplingGrowth;
import com.volmit.service.StructureLocator;
import com.volmit.world.BlockPosition;
import com.volmit.world.PackWorld;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@@ -178,6 +180,16 @@ public final class ModuleServices {
return Optional.empty();
}
/** The ambient effects every module says are due for a player standing at {@code at}, in module order. */
public static List<AmbientEffects.Effect> ambientEffects(Engine engine, BlockPosition at) {
PackWorld world = engine.getGeneration().world();
List<AmbientEffects.Effect> effects = new ArrayList<>();
for (AmbientEffects provider : catalog(engine.getData()).services(AmbientEffects.class)) {
effects.addAll(provider.due(world, at));
}
return effects;
}
/** A plan and the module that made it, which hears how many of its entities appeared. */
public record PlannedSpawn(EntitySpawns provider, PackWorld world, EntitySpawns.Plan plan) {
public void spawned(int count) {
@@ -20,8 +20,10 @@ package art.arcane.iris.core.modules;
import art.arcane.volmlib.util.json.JSONArray;
import art.arcane.volmlib.util.json.JSONObject;
import art.arcane.volmlib.util.json.JSONTokener;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
@@ -129,6 +131,24 @@ public final class ModuleSettingsDecoder {
return decoded;
}
/**
* The JSON that declares {@code values} at {@code target}: each settings feature under its key, in the shape the
* feature is written in (a rooted feature as its root option's value), the inverse of {@link #decode}.
*/
public JSONObject encode(Target target, ModuleSettings values) {
JSONObject json = new JSONObject();
for (FeatureDescriptor<?> feature : settings.get(target)) {
values.find(feature.type()).ifPresent(value -> json.put(feature.key(), writtenShape(feature, value)));
}
return json;
}
private Object writtenShape(FeatureDescriptor<?> feature, IrisFeature value) {
JsonElement settingsTree = gson.toJsonTree(value, feature.type());
JsonElement written = feature.root().map(root -> settingsTree.getAsJsonObject().get(root)).orElse(settingsTree);
return new JSONTokener(gson.toJson(written)).nextValue();
}
private IrisFeature read(FeatureDescriptor<?> feature, Object value, String resource) {
try {
requireShape(feature, value);
@@ -0,0 +1,211 @@
/*
* 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.pack;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.core.modules.IrisPackResources;
import art.arcane.iris.engine.object.annotations.RegistryListResource;
import art.arcane.volmlib.util.io.IO;
import art.arcane.volmlib.util.json.JSONObject;
import com.google.gson.Gson;
import com.volmit.config.ResourceRef;
import com.volmit.host.ResourceKindRegistration;
import com.volmit.resource.ResourceKind;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* The resources of the pack's module resource kinds that a pack export has to carry: what the settings of the
* exported dimension, regions and biomes (and anything else handed to {@link #follow}) name by {@link ResourceRef} or
* {@link RegistryListResource}, and what those resources name in turn. Core does not know the kinds: it follows the
* references the modules declare on their classes.
*/
public final class ModuleResourceClosure {
private static final String JAVA_PACKAGE_PREFIX = "java.";
private static final String JSON_EXTENSION = ".json";
private static final int PRETTY_INDENT = 4;
private final IrisData data;
private final Map<Class<?>, ResourceKind<?>> kindsByType = new HashMap<>();
private final Map<ResourceKind<?>, Map<String, Object>> found = new LinkedHashMap<>();
private final Set<Object> visited = java.util.Collections.newSetFromMap(new IdentityHashMap<>());
public ModuleResourceClosure(IrisData data) {
this.data = data;
for (ResourceKindRegistration registration : data.getModules().pack().catalog().resourceKinds()) {
kindsByType.put(registration.kind().type(), registration.kind());
}
}
/** Adds the resources that the module settings of {@code owner} reference, and those they reference. */
public void followSettingsOf(IrisRegistrant owner) {
owner.getModuleSettings().values().forEach(this::follow);
}
/** Adds the resources that {@code holder} references, and those they reference. */
public void follow(Object holder) {
if (holder == null || !visited.add(holder)) {
return;
}
if (holder instanceof Collection<?> collection) {
collection.forEach(this::follow);
return;
}
if (holder instanceof Map<?, ?> map) {
map.values().forEach(this::follow);
return;
}
if (holder instanceof Object[] array) {
for (Object element : array) {
follow(element);
}
return;
}
if (isLeaf(holder.getClass())) {
return;
}
for (Class<?> type = holder.getClass(); type != null && type != Object.class; type = type.getSuperclass()) {
for (Field field : type.getDeclaredFields()) {
followField(holder, field);
}
}
}
/** Whether nothing was found. */
public boolean isEmpty() {
return found.isEmpty();
}
/** The keys of the resources found of the kind that reads into {@code type}, in key order. */
public List<String> keysOf(Class<?> type) {
ResourceKind<?> kind = kindsByType.get(type);
return kind == null || !found.containsKey(kind) ? List.of() : new ArrayList<>(new TreeMap<>(found.get(kind)).keySet());
}
/**
* Writes every resource found as {@code <folder of its kind>/<key>.json} below {@code targetRoot}, kinds in folder
* order and keys in key order.
*
* @return the hashes of the files written, to put into the package's hash
*/
public String writeTo(File targetRoot, boolean minify) throws IOException {
StringBuilder hashes = new StringBuilder();
List<Map.Entry<ResourceKind<?>, Map<String, Object>>> kinds = new ArrayList<>(found.entrySet());
kinds.sort(Comparator.comparing(entry -> entry.getKey().folder()));
for (Map.Entry<ResourceKind<?>, Map<String, Object>> kind : kinds) {
for (Map.Entry<String, Object> resource : new TreeMap<>(kind.getValue()).entrySet()) {
String json = new JSONObject(new Gson().toJson(resource.getValue())).toString(minify ? 0 : PRETTY_INDENT);
IO.writeAll(new File(targetRoot, kind.getKey().folder() + "/" + resource.getKey() + JSON_EXTENSION), json);
hashes.append(IO.hash(json));
}
}
return hashes.toString();
}
private void followField(Object holder, Field field) {
if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers()) || field.getType().isPrimitive()) {
return;
}
Object value = valueOf(holder, field);
if (value == null) {
return;
}
Class<?> referenced = referencedType(field);
if (referenced == null) {
follow(value);
return;
}
for (String key : keysIn(value)) {
add(referenced, key);
}
}
/** The class of the resources the field names by key, or null when it names none. */
private static Class<?> referencedType(Field field) {
ResourceRef reference = field.getAnnotation(ResourceRef.class);
if (reference != null) {
return reference.value();
}
RegistryListResource registry = field.getAnnotation(RegistryListResource.class);
return registry == null ? null : registry.value();
}
private static List<String> keysIn(Object value) {
List<String> keys = new ArrayList<>();
if (value instanceof String key) {
keys.add(key);
} else if (value instanceof Collection<?> collection) {
collection.stream().filter(String.class::isInstance).map(String.class::cast).forEach(keys::add);
}
return keys;
}
private void add(Class<?> type, String key) {
ResourceKind<?> kind = kindsByType.get(type);
if (kind == null || key == null || key.isBlank()) {
return;
}
Map<String, Object> ofKind = found.computeIfAbsent(kind, ignored -> new LinkedHashMap<>());
if (ofKind.containsKey(key)) {
return;
}
Object resource = lookup(kind, key);
if (resource == null) {
return;
}
ofKind.put(key, resource);
follow(resource);
}
private Object lookup(ResourceKind<?> kind, String key) {
IrisPackResources resources = data.getPackResources();
try {
return resources.find(kind.key(resources.idOf(key))).orElse(null);
} catch (IllegalStateException failedToLoad) {
return null;
}
}
private static boolean isLeaf(Class<?> type) {
return type.isEnum() || type.getName().startsWith(JAVA_PACKAGE_PREFIX);
}
private static Object valueOf(Object holder, Field field) {
try {
field.setAccessible(true);
return field.get(holder);
} catch (ReflectiveOperationException | RuntimeException inaccessible) {
return null;
}
}
}
@@ -18,7 +18,6 @@
package art.arcane.iris.core.pack;
import art.arcane.iris.engine.object.marker.IrisObjectMarker;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.volmlib.util.collection.KSet;
@@ -32,25 +31,6 @@ public final class PackExportClosure {
private PackExportClosure() {
}
public static KSet<String> collectMarkerKeys(Iterable<IrisObjectPlacement> placements) {
KSet<String> markerKeys = new KSet<>();
if (placements == null) {
return markerKeys;
}
for (IrisObjectPlacement placement : placements) {
if (placement == null || placement.getMarkers() == null) {
continue;
}
for (IrisObjectMarker marker : placement.getMarkers()) {
if (marker == null || marker.getMarker() == null || marker.getMarker().isBlank()) {
continue;
}
markerKeys.add(marker.getMarker());
}
}
return markerKeys;
}
public static KSet<String> collectObjectKeys(Iterable<IrisObjectPlacement> placements) {
KSet<String> objectKeys = new KSet<>();
if (placements == null) {
@@ -18,27 +18,22 @@
package art.arcane.iris.core.project;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.iris.engine.loot.LootResources;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import com.google.gson.Gson;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.core.localization.BukkitRuntimeMessages;
import art.arcane.iris.core.localization.IrisLanguage;
import art.arcane.iris.core.pack.ImageMapPackageClosure;
import art.arcane.iris.core.pack.ModuleResourceClosure;
import art.arcane.iris.core.pack.PackValidationResult;
import art.arcane.iris.core.pack.PackValidator;
import art.arcane.iris.core.pack.StructurePackageClosure;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.material.IrisBlockData;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.entity.IrisEntity;
import art.arcane.iris.engine.object.terrain.IrisGenerator;
import art.arcane.iris.engine.object.loot.IrisLootTable;
import art.arcane.iris.core.pack.PackExportClosure;
import art.arcane.iris.engine.object.marker.IrisMarker;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
@@ -52,11 +47,11 @@ import art.arcane.volmlib.util.localization.MessageArgument;
import art.arcane.volmlib.util.math.M;
import art.arcane.volmlib.util.scheduling.ChronoLatch;
import art.arcane.volmlib.util.scheduling.O;
import com.volmit.FeatureAttachment.Target;
import org.zeroturnaround.zip.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
@@ -109,10 +104,8 @@ public class IrisPackageCompiler {
IrisLogging.info("Packaging Dimension " + dimension.getName() + " " + (obfuscate ? "(Obfuscated)" : ""));
KSet<IrisRegion> regions = new KSet<>();
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisEntity> entities = new KSet<>();
KSet<IrisSpawner> spawners = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
KSet<IrisLootTable> loot = new KSet<>();
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm);
KSet<IrisBlockData> blocks = new KSet<>();
// KSet is ConcurrentHashMap-backed: both add(null) and remove(null) throw NPE, so a
@@ -122,29 +115,16 @@ public class IrisPackageCompiler {
}
dimension.getAllRegions(() -> dm).forEach((region) -> addIfPresent(regions, region));
dimension.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i)));
moduleResources.followSettingsOf(dimension);
regions.forEach((i) -> biomes.addAll(i.getAllBiomes(() -> dm)));
dimension.getReachableBiomes(() -> dm).forEach((biome) -> addIfPresent(biomes, biome));
regions.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i))));
regions.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp))));
dimension.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp)));
regions.forEach(moduleResources::followSettingsOf);
biomes.forEach((i) -> i.getGenerators().forEach((j) -> addIfPresent(generators, j.getCachedGenerator(() -> dm))));
biomes.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i))));
biomes.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp))));
biomes.forEach(moduleResources::followSettingsOf);
KList<IrisObjectPlacement> allPlacements = new KList<>();
regions.forEach((r) -> allPlacements.addAll(r.getObjects()));
biomes.forEach((i) -> allPlacements.addAll(i.getObjects()));
KSet<IrisMarker> markers = new KSet<>();
for (String markerKey : PackExportClosure.collectMarkerKeys(allPlacements)) {
IrisMarker marker = SpawnResources.marker(dm, markerKey);
if (marker == null) {
continue;
}
markers.add(marker);
marker.getSpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp)));
}
collectSpawnerEntityKeys(spawners).forEach((i) -> addIfPresent(entities, SpawnResources.entity(dm, i)));
entities.forEach((e) -> e.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i))));
moduleResources.follow(allPlacements);
Set<String> structureKeys = new LinkedHashSet<>();
collectStructureKeys(structureKeys, dimension.getStructures());
regions.forEach((region) -> collectStructureKeys(structureKeys, region.getStructures()));
@@ -224,7 +204,7 @@ public class IrisPackageCompiler {
}
b.append(structureClosure.writeTo(folder, minify));
b.append(ImageMapPackageClosure.writeAll(dm, folder, minify));
a = new JSONObject(new Gson().toJson(dimension)).toString(minify ? 0 : 4);
a = withModuleSettings(dimension, Target.DIMENSION, dm).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
@@ -238,7 +218,7 @@ public class IrisPackageCompiler {
b = new StringBuilder();
for (IrisRegion i : regions) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
a = withModuleSettings(i, Target.REGION, dm).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
@@ -250,35 +230,12 @@ public class IrisPackageCompiler {
}
for (IrisBiome i : biomes) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
a = withModuleSettings(i, Target.BIOME, dm).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
for (IrisEntity i : entities) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "entities/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
for (IrisLootTable i : loot) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "loot/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
// Sorted so package.json.hash stays stable across runs.
for (IrisSpawner i : spawners.stream().sorted(Comparator.comparing(IrisSpawner::getLoadKey)).toList()) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "spawners/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
for (IrisMarker i : markers.stream().sorted(Comparator.comparing(IrisMarker::getLoadKey)).toList()) {
a = new JSONObject(new Gson().toJson(i)).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "markers/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
b.append(moduleResources.writeTo(folder, minify));
c.append(IO.hash(b.toString()));
String finalHash = IO.hash(c.toString());
@@ -301,13 +258,12 @@ public class IrisPackageCompiler {
return null;
}
static KSet<String> collectSpawnerEntityKeys(KSet<IrisSpawner> spawners) {
KSet<String> entityKeys = new KSet<>();
for (IrisSpawner spawner : spawners) {
spawner.getSpawns().forEach((spawn) -> entityKeys.add(spawn.getEntity()));
spawner.getInitialSpawns().forEach((spawn) -> entityKeys.add(spawn.getEntity()));
}
return entityKeys;
/** The JSON of a dimension, region or biome with the settings its modules declare, which the resource itself does not hold. */
private static JSONObject withModuleSettings(IrisRegistrant resource, Target target, IrisData data) {
JSONObject json = new JSONObject(new Gson().toJson(resource));
JSONObject settings = data.getModules().settings().encode(target, resource.getModuleSettings());
settings.keySet().forEach(key -> json.put(key, settings.get(key)));
return json;
}
private static void collectStructureKeys(Set<String> keys, KList<IrisStructurePlacement> placements) {
@@ -19,14 +19,13 @@
package art.arcane.iris.engine.framework;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.entity.IrisEffect;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.platform.EngineBukkitOps;
import art.arcane.iris.core.modules.ModuleServices;
import art.arcane.iris.platform.bukkit.BukkitAmbientEffects;
import art.arcane.iris.platform.bukkit.BukkitWorldBinding;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.math.M;
import com.volmit.world.BlockPosition;
import lombok.Data;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@@ -35,8 +34,7 @@ import org.bukkit.entity.Player;
public class EnginePlayer {
private final Engine engine;
private final Player player;
private IrisBiome biome;
private IrisRegion region;
private BlockPosition sampledPosition;
private Location lastLocation;
private long lastSample;
@@ -56,26 +54,14 @@ public class EnginePlayer {
return;
}
if (region != null) {
for (IrisEffect effect : region.getEffects()) {
try {
effect.apply(player, getEngine());
} catch (Throwable e) {
IrisLogging.reportError(e);
}
}
if (sampledPosition == null) {
return;
}
if (biome != null) {
for (IrisEffect effect : biome.getEffects()) {
try {
effect.apply(player, getEngine());
} catch (Throwable e) {
IrisLogging.reportError(e);
}
}
try {
BukkitAmbientEffects.play(player, engine, ModuleServices.ambientEffects(engine, sampledPosition));
} catch (Throwable e) {
IrisLogging.reportError(e);
}
}
@@ -94,8 +80,7 @@ public class EnginePlayer {
if (needsSample(sampled, ticksSinceLastSample(), distanceSquared)) {
lastLocation = current;
lastSample = M.ms();
biome = EngineBukkitOps.getBiome(engine, current);
region = EngineBukkitOps.getRegion(engine, current);
sampledPosition = new BlockPosition(current.getBlockX(), current.getBlockY() - engine.getWorld().minHeight(), current.getBlockZ());
}
return false;
} catch (Throwable e) {
@@ -5,6 +5,7 @@ import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.tools.IrisToolbelt;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.core.events.InventorySlotType;
import art.arcane.iris.core.events.IrisLootEvent;
import art.arcane.iris.engine.mantle.EngineMantle;
import art.arcane.iris.engine.platform.EngineBukkitOps;
@@ -86,7 +87,7 @@ public class WorldObjectPlacer implements IObjectPlacer {
KList<Loot.Source> tables = EngineBukkitOps.getLootTables(engine, block);
try {
Bukkit.getPluginManager().callEvent(new IrisLootEvent(engine, block, tables));
Bukkit.getPluginManager().callEvent(new IrisLootEvent(engine, block, InventorySlotType.STORAGE, tables));
if (tables.isEmpty()) {
return;
}
@@ -19,6 +19,7 @@
package art.arcane.iris.engine.platform;
import art.arcane.iris.platform.bukkit.BukkitWorldBinding;
import art.arcane.iris.core.events.InventorySlotType;
import art.arcane.iris.core.events.IrisLootEvent;
import art.arcane.iris.core.link.Identifier;
import art.arcane.iris.core.service.ExternalDataSVC;
@@ -304,7 +305,7 @@ public final class EngineBukkitOps {
KList<Loot.Source> tables = new KList<>(getLootTables(engine, block, hasNativeLootTable(block)));
try {
Bukkit.getPluginManager().callEvent(new IrisLootEvent(engine, block, tables));
Bukkit.getPluginManager().callEvent(new IrisLootEvent(engine, block, InventorySlotType.STORAGE, tables));
if (tables.isEmpty()) return;
InventoryHolder m = (InventoryHolder) block.getState();
addItems(engine, false, m.getInventory(), tables, c.getWorld(), block.getX(), y, block.getZ());
@@ -0,0 +1,144 @@
/*
* 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.platform.bukkit;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.util.common.data.registry.RegistryUtil;
import art.arcane.iris.util.common.scheduling.ConsoleCommands;
import art.arcane.iris.util.common.scheduling.J;
import com.volmit.entity.EntitySpec;
import com.volmit.service.AmbientEffects;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.List;
/**
* Plays the ambient effects a module decided on to a Bukkit player: the sound, the particles, the commands and the
* potion effect of each, in that order. Everything random was decided by the module; what the platform lacks is skipped.
*/
public final class BukkitAmbientEffects {
private static final double QUARTER_TURN_RADIANS = Math.toRadians(90);
private static final int ABOVE_SURFACE_BLOCKS = 1;
private BukkitAmbientEffects() {
}
public static void play(Player player, Engine engine, List<AmbientEffects.Effect> effects) {
for (AmbientEffects.Effect effect : effects) {
J.runEntity(player, () -> playOnEntityThread(player, engine, effect));
}
}
private static void playOnEntityThread(Player player, Engine engine, AmbientEffects.Effect effect) {
if (effect.sound() != null) {
playSound(player, effect.sound());
}
if (effect.particles() != null) {
showParticles(player, engine, effect.particles());
}
effect.commands().forEach(command -> runCommand(player, command));
if (effect.potion() != null) {
givePotion(player, effect.potion());
}
}
private static void playSound(Player player, AmbientEffects.Sound sound) {
Sound type = lookup(Sound.class, sound.key());
if (type == null) {
return;
}
Location at = player.getLocation().clone().add(sound.offsetX(), sound.offsetY(), sound.offsetZ());
player.playSound(at, type, sound.volume(), sound.pitch());
}
private static void showParticles(Player player, Engine engine, AmbientEffects.Particles particles) {
Particle type = lookup(Particle.class, particles.key());
if (type == null) {
return;
}
Location location = player.getLocation();
Vector direction = location.getDirection();
Location spot = location.clone()
.add(direction.clone().multiply(particles.forward()))
.add(direction.clone().rotateAroundY(QUARTER_TURN_RADIANS).multiply(particles.sideways()));
spot.setY(Math.round(engine.getHeight(spot.getBlockX(), spot.getBlockZ())) + ABOVE_SURFACE_BLOCKS);
spot.add(particles.jitterX(), 0, particles.jitterZ());
double x = spot.getX();
double y = spot.getY() + player.getWorld().getMinHeight() + particles.lift();
double z = spot.getZ();
if (particles.extra() != 0) {
player.spawnParticle(type, x, y, z, particles.count(), particles.altX(), particles.altY(), particles.altZ(), particles.extra());
return;
}
player.spawnParticle(type, x, y, z, particles.count(), particles.altX(), particles.altY(), particles.altZ());
}
private static void runCommand(Player player, AmbientEffects.Command command) {
Location at = player.getLocation().clone().add(command.offsetX(), command.offsetY(), command.offsetZ());
EntitySpec.Command run = command.command();
ConsoleCommands.run(run.commands(), run.delay(), run.repeat(), run.repeatDelay(), at.getBlockX(), at.getBlockY(), at.getBlockZ());
}
private static void givePotion(Player player, AmbientEffects.Potion potion) {
PotionEffectType type = potionType(potion.key());
PotionEffect current = player.getPotionEffect(type);
if (current != null) {
if (current.getAmplifier() > potion.strength()) {
return;
}
player.removePotionEffect(type);
}
player.addPotionEffect(new PotionEffect(type, potion.ticks(), potion.strength(), true, false, false));
}
/** The potion effect type a pack names, or luck for a name the platform does not know, with a warning once. */
private static PotionEffectType potionType(String name) {
if (name == null || name.isEmpty()) {
return PotionEffectType.LUCK;
}
try {
PotionEffectType resolved = PotionEffectTypes.resolve(name);
if (resolved != null) {
return resolved;
}
} catch (Throwable e) {
IrisLogging.reportError(e);
}
if (PotionEffectTypes.shouldWarn(name)) {
IrisLogging.warn("Unknown Potion Effect Type: \"" + name + "\". Valid types: " + PotionEffectTypes.knownTypesList());
}
return PotionEffectType.LUCK;
}
private static <T> T lookup(Class<T> type, String key) {
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey);
}
}
@@ -0,0 +1,98 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.platform.bukkit;
import art.arcane.iris.util.common.reflect.KeyedType;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.potion.PotionEffectType;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
public final class PotionEffectTypes {
private static final Map<String, String> LEGACY_ALIASES;
private static final Set<String> MISSING_WARNED = ConcurrentHashMap.newKeySet();
static {
Map<String, String> m = new HashMap<>();
m.put("SLOW", "SLOWNESS");
m.put("FAST_DIGGING", "HASTE");
m.put("SLOW_DIGGING", "MINING_FATIGUE");
m.put("INCREASE_DAMAGE", "STRENGTH");
m.put("HEAL", "INSTANT_HEALTH");
m.put("HARM", "INSTANT_DAMAGE");
m.put("JUMP", "JUMP_BOOST");
m.put("CONFUSION", "NAUSEA");
m.put("DAMAGE_RESISTANCE", "RESISTANCE");
LEGACY_ALIASES = Collections.unmodifiableMap(m);
}
private PotionEffectTypes() {
}
public static String normalize(String input) {
if (input == null) {
return "";
}
String upper = input.trim().toUpperCase(Locale.ROOT).replace(' ', '_');
if (upper.contains(":")) {
upper = upper.substring(upper.indexOf(':') + 1);
}
return LEGACY_ALIASES.getOrDefault(upper, upper);
}
public static PotionEffectType resolve(String rawName) {
if (rawName == null || rawName.trim().isEmpty()) {
return null;
}
String wanted = normalize(rawName);
for (PotionEffectType i : Registry.EFFECT) {
NamespacedKey key = KeyedType.getKey(i);
if (key == null) {
continue;
}
String candidate = key.getKey().toUpperCase(Locale.ROOT).replace(' ', '_');
if (candidate.equals(wanted)) {
return i;
}
}
return null;
}
public static String knownTypesList() {
TreeSet<String> names = new TreeSet<>();
for (PotionEffectType i : Registry.EFFECT) {
NamespacedKey key = KeyedType.getKey(i);
if (key != null) {
names.add(key.getKey().toUpperCase(Locale.ROOT).replace(' ', '_'));
}
}
return String.join(", ", names);
}
public static boolean shouldWarn(String rawName) {
return MISSING_WARNED.add(normalize(rawName));
}
}
@@ -1,49 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.util.common.director.handlers;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.entity.IrisEntity;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.iris.util.common.director.specialhandlers.RegistrantHandler;
public class EntityHandler extends RegistrantHandler<IrisEntity> {
public EntityHandler() {
super(IrisEntity.class, false);
}
@Override
protected KList<IrisEntity> loadAll(IrisData data) {
KList<IrisEntity> entities = new KList<>();
for (String key : SpawnResources.entityKeys(data)) {
IrisEntity entity = SpawnResources.entity(data, key);
if (entity != null) {
entities.add(entity);
}
}
return entities;
}
@Override
public String getRandomDefault() {
return "entity";
}
}
@@ -0,0 +1,77 @@
/*
* 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.util.common.director.specialhandlers;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.modules.PackModulesException;
import art.arcane.iris.core.pack.PackDirectoryResolver;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.util.common.director.DirectorParameterHandler;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
import java.io.File;
import java.util.LinkedHashSet;
import java.util.Set;
/** The key of an entity of a pack: the open pack's, then those of the packs in the packs folder. */
public final class EntityKeyHandler implements DirectorParameterHandler<String> {
@Override
public KList<String> getPossibilities() {
Set<String> keys = new LinkedHashSet<>();
IrisData activeData = data();
if (activeData != null) {
addEntityKeys(keys, activeData);
}
for (File pack : PackDirectoryResolver.listVisiblePackDirectories(
IrisPlatforms.get().packsFolder())) {
addEntityKeys(keys, IrisData.get(pack));
}
return new KList<>(keys);
}
@Override
public String toString(String value) {
return value == null ? "" : value;
}
@Override
public String parse(String input, boolean force) throws DirectorParsingException {
for (String option : getPossibilities(input)) {
if (option.equalsIgnoreCase(input)) {
return option;
}
}
throw new DirectorParsingException("Unable to find Entity \"" + input + "\"");
}
@Override
public boolean supports(Class<?> type) {
return type == String.class;
}
/** A pack whose modules fail to load has no entities to offer; its failure was reported when it loaded. */
private static void addEntityKeys(Set<String> keys, IrisData data) {
try {
keys.addAll(SpawnResources.entityKeys(data));
} catch (PackModulesException ignored) {
}
}
}
@@ -26,7 +26,6 @@ import art.arcane.iris.util.project.matter.slices.IdentifierMatter;
import art.arcane.iris.util.project.matter.slices.ModuleLayerMatter;
import art.arcane.iris.util.project.matter.slices.NativeStructureOwnershipMatter;
import art.arcane.iris.util.project.matter.slices.PlatformBlockMatter;
import art.arcane.iris.util.project.matter.slices.SpawnerMatter;
import art.arcane.iris.util.project.matter.slices.TileMatter;
import art.arcane.iris.util.project.matter.slices.TreeBlockMaterialMatter;
import art.arcane.volmlib.util.matter.IrisMatter;
@@ -52,7 +51,6 @@ public final class IrisMatterSupport {
IrisMatter.registerSliceType(new ModuleLayerMatter());
IrisMatter.registerSliceType(new NativeStructureOwnershipMatter());
IrisMatter.registerSliceType(new PlatformBlockMatter());
IrisMatter.registerSliceType(new SpawnerMatter());
IrisMatter.registerSliceType(new TileMatter());
IrisMatter.registerSliceType(new TreeBlockMaterialMatter());
registered = true;
@@ -1,53 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.util.project.matter.slices;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.loader.IrisRegistrant;
import art.arcane.iris.util.project.matter.IrisMatterContext;
import art.arcane.volmlib.util.data.palette.Palette;
import art.arcane.volmlib.util.matter.slices.RawMatter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public abstract class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
public RegistryMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c);
}
@Override
public Palette<T> getGlobalPalette() {
return null;
}
@Override
public void writeNode(T b, DataOutputStream dos) throws IOException {
dos.writeUTF(b.getLoadKey());
}
@Override
public T readNode(DataInputStream din) throws IOException {
return load(IrisMatterContext.require(), din.readUTF());
}
/** The resource of the pack {@code data} named by {@code key}, or null when the pack has none. */
protected abstract T load(IrisData data, String key);
}
@@ -1,40 +0,0 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 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.util.project.matter.slices;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
import art.arcane.iris.engine.spawn.SpawnResources;
import art.arcane.volmlib.util.matter.Sliced;
@Sliced
public class SpawnerMatter extends RegistryMatter<IrisSpawner> {
public SpawnerMatter() {
this(1, 1, 1);
}
public SpawnerMatter(int width, int height, int depth) {
super(width, height, depth, IrisSpawner.class, new IrisSpawner());
}
@Override
protected IrisSpawner load(IrisData data, String key) {
return SpawnResources.spawner(data, key);
}
}