Core stops reading loot, spawn and effect classes: services, resource closure for exports, key handler for entities

This commit is contained in:
piexel committed 2026-10-10 08:46:33 +02:00
1 parent ee2818514f
commit f404dec7d7
50 files changed
+2916 -616

No files matched your search

@@ -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.EntitySpawns;
import com.volmit.service.LocateResult;
@@ -30,6 +31,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;
@@ -164,6 +166,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);
}
}