mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Merge branch 'wave3/l'
# Conflicts: # src/main/java/art/arcane/iris/engine/object/world/biome/IrisBiome.java # src/main/java/art/arcane/iris/engine/object/world/dimension/IrisDimension.java # src/main/java/art/arcane/iris/engine/object/world/region/IrisRegion.java
This commit is contained in:
commit
95a086f3e0
63 files changed
+2288
-1906
No files matched your search
@@ -18,20 +18,25 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.BlockDrop;
|
||||
import art.arcane.iris.builtin.loot.BlockDropSettings;
|
||||
import art.arcane.iris.builtin.loot.LootEntry;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.loot.IrisBlockDrops;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* How {@code iris:loot} drops items for broken blocks: the block drops of the biome, the region and the dimension, the
|
||||
@@ -44,23 +49,53 @@ public final class BlockDropping implements BlockDrops {
|
||||
int x = broken.position().x();
|
||||
int y = broken.position().y();
|
||||
int z = broken.position().z();
|
||||
PlatformBlockState block = IrisPlatforms.get().registries().block(broken.block().key());
|
||||
String brokenKey = IrisPlatforms.get().registries().block(broken.block().key()).key();
|
||||
ResolvedDrops resolved = world.state(ResolvedDrops.class, ignored -> new ResolvedDrops());
|
||||
|
||||
IrisBiome biome = engine.getBiome(x, y, z);
|
||||
List<IrisBlockDrops> providers = dropsFor(biome.getBlockDrops(), block, engine);
|
||||
if (providers.stream().noneMatch(IrisBlockDrops::isSkipParents)) {
|
||||
List<ResolvedBlockDrop> providers = dropsFor(biome, brokenKey, resolved, world);
|
||||
if (providers.stream().noneMatch(provider -> provider.drop().skipParents())) {
|
||||
IrisRegion region = engine.getRegion(x, z);
|
||||
providers.addAll(dropsFor(region.getBlockDrops(), block, engine));
|
||||
providers.addAll(dropsFor(engine.getDimension().getBlockDrops(), block, engine));
|
||||
providers.addAll(dropsFor(region, brokenKey, resolved, world));
|
||||
providers.addAll(dropsFor(engine.getDimension(), brokenKey, resolved, world));
|
||||
}
|
||||
|
||||
LootItems items = new LootItems(world.resources().items(), false);
|
||||
List<ItemDrop> drops = new ArrayList<>();
|
||||
providers.forEach(provider -> provider.fillDrops(items, drops));
|
||||
return new Result(drops, providers.stream().anyMatch(IrisBlockDrops::isReplaceVanillaDrops));
|
||||
providers.forEach(provider -> fillDrops(provider.drop(), items, drops));
|
||||
return new Result(drops, providers.stream().anyMatch(provider -> provider.drop().replaceVanillaDrops()));
|
||||
}
|
||||
|
||||
private static List<IrisBlockDrops> dropsFor(KList<IrisBlockDrops> candidates, PlatformBlockState block, Engine engine) {
|
||||
return new KList<>(candidates.stream().filter(drops -> drops.shouldDropFor(block, engine.getData())).toList());
|
||||
/** Adds the items of the drops that pass their rarity to {@code into}. */
|
||||
private static void fillDrops(BlockDrop drop, LootItems items, List<ItemDrop> into) {
|
||||
for (LootEntry entry : drop.drops()) {
|
||||
if (!LootResolver.oneIn(RNG.r, entry.rarity())) {
|
||||
continue;
|
||||
}
|
||||
ItemDrop given = items.give(entry, RNG.r);
|
||||
if (given != null) {
|
||||
into.add(given);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ResolvedBlockDrop> dropsFor(IrisRegistrant owner, String brokenKey, ResolvedDrops resolved, PackWorld world) {
|
||||
List<ResolvedBlockDrop> matching = new ArrayList<>();
|
||||
for (BlockDrop drop : owner.getModuleSettings().find(BlockDropSettings.class).map(BlockDropSettings::drops).orElse(List.of())) {
|
||||
ResolvedBlockDrop candidate = resolved.of(drop, world);
|
||||
if (candidate.dropsFor(brokenKey)) {
|
||||
matching.add(candidate);
|
||||
}
|
||||
}
|
||||
return matching;
|
||||
}
|
||||
|
||||
/** The drops of the world with their blocks resolved, once per drop. */
|
||||
private static final class ResolvedDrops {
|
||||
private final ConcurrentMap<BlockDrop, ResolvedBlockDrop> byDrop = new ConcurrentHashMap<>();
|
||||
|
||||
private ResolvedBlockDrop of(BlockDrop drop, PackWorld world) {
|
||||
return byDrop.computeIfAbsent(drop, key -> ResolvedBlockDrop.of(key, world.resources().blocks()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,22 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.iris.engine.object.loot.IrisVanillaLootTable;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* How {@code iris:loot} fills containers: the tables of the object placed around a container, then those of the
|
||||
@@ -47,36 +47,42 @@ public final class LootGiving implements Loot {
|
||||
int x = site.position().x();
|
||||
int z = site.position().z();
|
||||
int relativeY = site.position().y();
|
||||
RNG rng = LootResolver.containerRng(lootSeed(engine), x, relativeY + engine.getMinHeight(), z);
|
||||
int worldY = relativeY + engine.getMinHeight();
|
||||
RNG rng = LootResolver.containerRng(lootSeed(engine), x, worldY, z);
|
||||
|
||||
List<IrisLootTable> tables = new KList<>();
|
||||
List<Source> sources = new ArrayList<>();
|
||||
boolean objectLootDefined = site.nativeLootDefined();
|
||||
IrisObjectPlacement placement = site.container() == null ? null : placementAt(engine, x, relativeY, z);
|
||||
if (placement != null) {
|
||||
objectLootDefined = objectLootDefined || placement.getLoot().isNotEmpty() || placement.getVanillaLoot().isNotEmpty();
|
||||
IrisLootTable table = placement.getTable(platformState(site), engine.getData(), rng);
|
||||
if (table != null) {
|
||||
tables.add(table);
|
||||
Source picked = placementLoot(world, engine).pick(placement.getVanillaLoot(), placement.getLoot(), platformState(site), rng, x, worldY, z);
|
||||
if (picked != null) {
|
||||
sources.add(picked);
|
||||
if (placement.isOverrideGlobalLoot()) {
|
||||
return sourcesOf(engine, site, List.of(table));
|
||||
return sources;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LootTables.resolveEnvironmentSources(tables, engine, rng, x, relativeY, z, objectLootDefined, table -> table);
|
||||
return sourcesOf(engine, site, tables);
|
||||
LootTables.resolveEnvironmentSources(sources, engine, rng, x, relativeY, z, objectLootDefined, Table::new);
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDrop> items(PackWorld world, Site site, String key) {
|
||||
Engine engine = engine(world);
|
||||
IrisLootTable table = LootResources.table(engine.getData(), key);
|
||||
LootTable table = LootResources.table(engine.getData(), key);
|
||||
if (table == null) {
|
||||
return List.of();
|
||||
}
|
||||
int worldY = site.position().y() + engine.getMinHeight();
|
||||
return new LootItems(world.resources().items(), site.debug())
|
||||
.draw(table, lootSeed(engine), site.position().x(), worldY, site.position().z());
|
||||
.draw(key, table, lootSeed(engine), site.position().x(), worldY, site.position().z());
|
||||
}
|
||||
|
||||
private static PlacementLoot placementLoot(PackWorld world, Engine engine) {
|
||||
PlatformLootTables platformTables = world.state(PlatformLootTables.class, ignored -> new PlatformLootTables());
|
||||
return new PlacementLoot(engine.getData(), platformTables::keys, lootSeed(engine));
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placementAt(Engine engine, int x, int relativeY, int z) {
|
||||
@@ -84,22 +90,6 @@ public final class LootGiving implements Loot {
|
||||
return placed == null ? null : placed.getPlacement();
|
||||
}
|
||||
|
||||
private static List<Source> sourcesOf(Engine engine, Site site, List<IrisLootTable> tables) {
|
||||
int worldY = site.position().y() + engine.getMinHeight();
|
||||
List<Source> sources = new KList<>();
|
||||
for (IrisLootTable table : tables) {
|
||||
if (table instanceof IrisVanillaLootTable vanilla) {
|
||||
long seed = LootTables.seed(lootSeed(engine), vanilla, site.position().x(), worldY, site.position().z());
|
||||
sources.add(new PlatformTable(vanilla.getLootTableKey(), seed));
|
||||
continue;
|
||||
}
|
||||
if (table != null && table.getLoadKey() != null) {
|
||||
sources.add(new Table(table.getLoadKey()));
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
private static PlatformBlockState platformState(Site site) {
|
||||
return IrisPlatforms.get().registries().block(site.container().key());
|
||||
}
|
||||
@@ -111,4 +101,18 @@ public final class LootGiving implements Loot {
|
||||
private static Engine engine(PackWorld world) {
|
||||
return IrisPackWorld.of(world).engine();
|
||||
}
|
||||
|
||||
/** The loot table keys of the platform, which do not change while a world runs. */
|
||||
private static final class PlatformLootTables {
|
||||
private volatile Set<String> keys;
|
||||
|
||||
private Set<String> keys() {
|
||||
Set<String> known = keys;
|
||||
if (known == null) {
|
||||
known = PlacementLoot.platformTableKeys();
|
||||
keys = known;
|
||||
}
|
||||
return known;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.ItemAttributeModifier;
|
||||
import art.arcane.iris.builtin.loot.LootEnchantment;
|
||||
import art.arcane.iris.builtin.loot.LootEntry;
|
||||
import art.arcane.iris.builtin.loot.LootSlot;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.entity.IrisAttributeModifier;
|
||||
import art.arcane.iris.engine.object.loot.IrisEnchantment;
|
||||
import art.arcane.iris.engine.object.loot.InventorySlotType;
|
||||
import art.arcane.iris.engine.object.loot.IrisLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.ItemDrop;
|
||||
@@ -54,26 +54,28 @@ public final class LootItems {
|
||||
}
|
||||
|
||||
/**
|
||||
* The items {@code table} gives at the spot {@code x}, {@code y}, {@code z} (world coordinates): picks entries
|
||||
* from the table's own random stream until it has the number of items the table asks for or runs out of tries.
|
||||
* The items {@code table}, which the pack names {@code tableKey}, gives at the spot {@code x}, {@code y}, {@code z}
|
||||
* (world coordinates): picks entries from the table's own random stream until it has the number of items the table
|
||||
* asks for or runs out of tries.
|
||||
*/
|
||||
public List<ItemDrop> draw(IrisLootTable table, long lootSeed, int x, int y, int z) {
|
||||
public List<ItemDrop> draw(String tableKey, LootTable table, long lootSeed, int x, int y, int z) {
|
||||
List<ItemDrop> drops = new ArrayList<>();
|
||||
List<IrisLoot> entries = table.getLoot();
|
||||
if (entries.isEmpty() || table.getMaxTries() <= 0) {
|
||||
List<LootEntry> entries = table.loot();
|
||||
if (entries.isEmpty() || table.maxTries() <= 0) {
|
||||
return drops;
|
||||
}
|
||||
|
||||
RNG rng = LootTables.rng(lootSeed, table, x, y, z);
|
||||
int wanted = Math.max(0, LootResolver.inclusive(rng, table.getMinPicked(), table.getMaxPicked()));
|
||||
String identity = LootTables.identity(tableKey);
|
||||
RNG rng = LootTables.rng(lootSeed, identity, x, y, z);
|
||||
int wanted = Math.max(0, LootResolver.inclusive(rng, table.minPicked(), table.maxPicked()));
|
||||
int tries = 0;
|
||||
while (drops.size() < wanted && tries++ < table.getMaxTries()) {
|
||||
while (drops.size() < wanted && tries++ < table.maxTries()) {
|
||||
int index = rng.nextInt(entries.size());
|
||||
IrisLoot entry = entries.get(index);
|
||||
if (entry == null || entry.getSlotTypes() != InventorySlotType.STORAGE) {
|
||||
LootEntry entry = entries.get(index);
|
||||
if (entry == null || entry.slotTypes() != LootSlot.STORAGE) {
|
||||
continue;
|
||||
}
|
||||
ItemDrop drop = drawEntry(entry, table, rng, lootSeed, index, x, y, z);
|
||||
ItemDrop drop = drawEntry(entry, table, identity, rng, lootSeed, index, x, y, z);
|
||||
if (drop != null) {
|
||||
drops.add(drop);
|
||||
}
|
||||
@@ -82,66 +84,67 @@ public final class LootItems {
|
||||
}
|
||||
|
||||
/** The item {@code entry} gives when nothing else decides whether it does, such as a block's drop or a mob's equipment; null for no item. */
|
||||
public ItemDrop give(IrisLoot entry, RNG rng) {
|
||||
public ItemDrop give(LootEntry entry, RNG rng) {
|
||||
return resolve(entry, rng, null);
|
||||
}
|
||||
|
||||
private ItemDrop drawEntry(IrisLoot entry, IrisLootTable table, RNG rng, long lootSeed, int index, int x, int y, int z) {
|
||||
long combinedRarity = LootResolver.combinedRarity(entry.getRarity(), table.getRarity());
|
||||
if (!LootTables.spatialOneIn(lootSeed, table, index, x, y, z, combinedRarity)) {
|
||||
private ItemDrop drawEntry(LootEntry entry, LootTable table, String identity, RNG rng, long lootSeed, int index, int x, int y, int z) {
|
||||
long combinedRarity = LootResolver.combinedRarity(entry.rarity(), table.rarity());
|
||||
if (!LootTables.spatialOneIn(lootSeed, identity, index, x, y, z, combinedRarity)) {
|
||||
return null;
|
||||
}
|
||||
return resolve(entry, rng, table);
|
||||
}
|
||||
|
||||
private ItemDrop resolve(IrisLoot entry, RNG rng, IrisLootTable table) {
|
||||
String type = entry.getTypeKey();
|
||||
private ItemDrop resolve(LootEntry entry, RNG rng, LootTable table) {
|
||||
String type = entry.type();
|
||||
OptionalInt maxDurability = items.maxDurability(type);
|
||||
if (maxDurability.isEmpty() || isAir(type)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int amount = Math.max(MIN_AMOUNT, LootResolver.inclusive(rng, entry.getMinAmount(), entry.getMaxAmount()));
|
||||
int amount = Math.max(MIN_AMOUNT, LootResolver.inclusive(rng, entry.minAmount(), entry.maxAmount()));
|
||||
List<ItemEnchantment> enchantments = drawEnchantments(entry, rng);
|
||||
List<ItemAttribute> attributes = drawAttributes(entry, rng);
|
||||
Double damage = maxDurability.getAsInt() > 0 ? 1D - rng.d(entry.getMinDurability(), entry.getMaxDurability()) : null;
|
||||
return new ItemDrop(type, amount, entry.getDisplayName(), entry.getLore(), enchantments, attributes,
|
||||
entry.isUnbreakable(), entry.getItemFlags(), entry.getCustomModel(), damage, entry.getLeatherColor(),
|
||||
entry.getDyeColorKey(), entry.getCustomNbt(), debug ? sourceOf(entry, table) : null);
|
||||
Double damage = maxDurability.getAsInt() > 0 ? 1D - rng.d(entry.minDurability(), entry.maxDurability()) : null;
|
||||
return new ItemDrop(type, amount, entry.displayName(), entry.lore(), enchantments, attributes,
|
||||
entry.unbreakable(), entry.itemFlags(), entry.customModel(), damage, entry.leatherColor(),
|
||||
entry.dyeColor(), entry.customNbt(), debug ? sourceOf(entry, table) : null);
|
||||
}
|
||||
|
||||
private static List<ItemEnchantment> drawEnchantments(IrisLoot entry, RNG rng) {
|
||||
private static List<ItemEnchantment> drawEnchantments(LootEntry entry, RNG rng) {
|
||||
List<ItemEnchantment> enchantments = new ArrayList<>();
|
||||
for (IrisEnchantment enchantment : entry.getEnchantments()) {
|
||||
String key = enchantment.getEnchantment();
|
||||
if (key == null || key.isBlank() || rng.nextDouble() >= enchantment.getChance()) {
|
||||
for (LootEnchantment enchantment : entry.enchantments()) {
|
||||
String key = enchantment.enchantment();
|
||||
if (key == null || key.isBlank() || rng.nextDouble() >= enchantment.chance()) {
|
||||
continue;
|
||||
}
|
||||
enchantments.add(new ItemEnchantment(key, Math.max(1, enchantment.getLevel(rng))));
|
||||
int level = LootResolver.inclusive(rng, enchantment.minLevel(), enchantment.maxLevel());
|
||||
enchantments.add(new ItemEnchantment(key, Math.max(1, level)));
|
||||
}
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
private static List<ItemAttribute> drawAttributes(IrisLoot entry, RNG rng) {
|
||||
private static List<ItemAttribute> drawAttributes(LootEntry entry, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (IrisAttributeModifier modifier : entry.getAttributes()) {
|
||||
if (rng.nextDouble() >= modifier.getChance()) {
|
||||
for (ItemAttributeModifier modifier : entry.attributes()) {
|
||||
if (rng.nextDouble() >= modifier.chance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.getAttribute();
|
||||
String attribute = modifier.attribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
attributes.add(new ItemAttribute(attribute, modifier.getName(), modifier.getOperation(), modifier.getAmount(rng)));
|
||||
attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount())));
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static ItemDrop.Source sourceOf(IrisLoot entry, IrisLootTable table) {
|
||||
private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table) {
|
||||
if (table == null) {
|
||||
return new ItemDrop.Source(null, 0, entry.getRarity());
|
||||
return new ItemDrop.Source(null, 0, entry.rarity());
|
||||
}
|
||||
return new ItemDrop.Source(table.getName(), table.getRarity(), entry.getRarity());
|
||||
return new ItemDrop.Source(table.name(), table.rarity(), entry.rarity());
|
||||
}
|
||||
|
||||
private static boolean isAir(String type) {
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.BlockDropSettings;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
@@ -26,9 +28,10 @@ import com.volmit.service.Loot;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
/**
|
||||
* Module {@code iris:loot}: the loot tables of the pack ({@link LootResources}) and the items they and the block drops
|
||||
* of the dimension, regions and biomes give. It checks the tables and the references to them ({@link LootValidator}). It has no generation stage; Iris asks it through {@link Loot} when a container is filled and through
|
||||
* {@link BlockDrops} when a player breaks a block.
|
||||
* Module {@code iris:loot}: the loot tables of the pack ({@link LootResources}), the {@link LootSettings} and
|
||||
* {@link BlockDropSettings} that dimensions, regions and biomes declare, and the items they give. It checks the tables
|
||||
* and the references to them ({@link LootValidator}). It has no generation stage; Iris asks it through {@link Loot} when
|
||||
* a container is filled and through {@link BlockDrops} when a player breaks a block.
|
||||
*/
|
||||
public final class LootModule implements IrisModule {
|
||||
private static final String VERSION = "built-in";
|
||||
@@ -44,6 +47,8 @@ public final class LootModule implements IrisModule {
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerSettings(LootSettings.class);
|
||||
registry.registerSettings(BlockDropSettings.class);
|
||||
LootResources.kinds().forEach(registry::registerResourceKind);
|
||||
registry.registerValidator(new LootValidator());
|
||||
registry.registerService(Loot.class, new LootGiving());
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
|
||||
@@ -37,7 +36,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class LootResources {
|
||||
/** Loot tables, in {@code loot/}. */
|
||||
public static final ResourceKind<IrisLootTable> TABLES = ResourceKind.of("iris:loot/table", "loot", IrisLootTable.class);
|
||||
public static final ResourceKind<LootTable> TABLES = ResourceKind.of("iris:loot/table", "loot", LootTable.class);
|
||||
|
||||
private LootResources() {
|
||||
}
|
||||
@@ -47,7 +46,7 @@ public final class LootResources {
|
||||
return List.of(TABLES);
|
||||
}
|
||||
|
||||
public static IrisLootTable table(IrisData data, String key) {
|
||||
public static LootTable table(IrisData data, String key) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
@@ -59,18 +58,6 @@ public final class LootResources {
|
||||
}
|
||||
}
|
||||
|
||||
/** The tables of the pack named by {@code keys}, in order, without the ones the pack lacks. */
|
||||
public static KList<IrisLootTable> tables(IrisData data, List<String> keys) {
|
||||
KList<IrisLootTable> tables = new KList<>();
|
||||
for (String key : keys) {
|
||||
IrisLootTable table = table(data, key);
|
||||
if (table != null) {
|
||||
tables.add(table);
|
||||
}
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
/** The key of every loot table of the pack, in key order. */
|
||||
public static List<String> tableKeys(IrisData data) {
|
||||
return data.getPackResources().ids(TABLES.type()).stream().map(ResourceId::path).toList();
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootMode;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootMode;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
@@ -34,42 +33,46 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Which loot tables a place in the world draws from, and the random streams that draw from them: the part of loot
|
||||
* that reads the pack's tables, loot references and layout. The streams themselves are
|
||||
* {@link LootResolver}'s; here a table is named by its {@linkplain #identity identity}.
|
||||
* that reads the pack's tables, loot settings and layout. The streams themselves are {@link LootResolver}'s; here a
|
||||
* table is named by its {@linkplain #identity identity}, the key the pack names it by.
|
||||
*/
|
||||
public final class LootTables {
|
||||
private static final String VANILLA_IDENTITY_PREFIX = "Vanilla ";
|
||||
|
||||
private LootTables() {
|
||||
}
|
||||
|
||||
/** What names a table in the random streams: its key, else its name. */
|
||||
public static String identity(IrisLootTable table) {
|
||||
if (table == null) {
|
||||
return "";
|
||||
}
|
||||
String loadKey = table.getLoadKey();
|
||||
if (loadKey != null && !loadKey.isBlank()) {
|
||||
return loadKey;
|
||||
}
|
||||
String name = table.getName();
|
||||
return name == null ? "" : name;
|
||||
/** What names a table in the random streams: the key a pack table is named by. */
|
||||
public static String identity(String tableKey) {
|
||||
return tableKey;
|
||||
}
|
||||
|
||||
public static RNG rng(long lootSeed, IrisLootTable table, int x, int y, int z) {
|
||||
return LootResolver.tableRng(lootSeed, identity(table), x, y, z);
|
||||
/** What names a table of the platform in the random streams. */
|
||||
public static String platformIdentity(String platformKey) {
|
||||
return VANILLA_IDENTITY_PREFIX + platformKey;
|
||||
}
|
||||
|
||||
public static long seed(long lootSeed, IrisLootTable table, int x, int y, int z) {
|
||||
return LootResolver.tableSeed(lootSeed, identity(table), x, y, z);
|
||||
public static RNG rng(long lootSeed, String identity, int x, int y, int z) {
|
||||
return LootResolver.tableRng(lootSeed, identity, x, y, z);
|
||||
}
|
||||
|
||||
public static boolean spatialOneIn(long lootSeed, IrisLootTable table, int entryIndex, int x, int y, int z, long rarity) {
|
||||
return LootResolver.spatialOneIn(lootSeed, identity(table), entryIndex, x, y, z, rarity);
|
||||
public static long seed(long lootSeed, String identity, int x, int y, int z) {
|
||||
return LootResolver.tableSeed(lootSeed, identity, x, y, z);
|
||||
}
|
||||
|
||||
public static boolean spatialOneIn(long lootSeed, String identity, int entryIndex, int x, int y, int z, long rarity) {
|
||||
return LootResolver.spatialOneIn(lootSeed, identity, entryIndex, x, y, z, rarity);
|
||||
}
|
||||
|
||||
/** The loot settings a dimension, region or biome declares; the defaults, which add nothing, when it declares none. */
|
||||
public static LootSettings settingsOf(IrisRegistrant owner) {
|
||||
return owner.getModuleSettings().find(LootSettings.class).orElseGet(LootSettings::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the tables of the dimension, the region, the surface biome and (below the surface) the cave biome at a
|
||||
* column to {@code sources}, as their loot references say, then scales their number by the areas' multipliers.
|
||||
* {@code mapper} turns a table into the caller's own source; a null result skips it.
|
||||
* column to {@code sources}, as their loot settings say, then scales their number by the areas' multipliers.
|
||||
* {@code mapper} turns the key of a table into the caller's own source; a null result skips it.
|
||||
*/
|
||||
public static <T> void resolveEnvironmentSources(
|
||||
List<T> sources,
|
||||
@@ -79,7 +82,7 @@ public final class LootTables {
|
||||
int relativeY,
|
||||
int z,
|
||||
boolean objectLootDefined,
|
||||
Function<IrisLootTable, T> mapper
|
||||
Function<String, T> mapper
|
||||
) {
|
||||
IrisRegion region = engine.getComplex().getRegionStream().get(x, z);
|
||||
IrisBiome surfaceBiome = engine.getComplex().getTrueBiomeStream().get(x, z);
|
||||
@@ -91,20 +94,21 @@ public final class LootTables {
|
||||
contextualBiome = surfaceBiome;
|
||||
}
|
||||
|
||||
LootSettings dimensionLoot = settingsOf(engine.getDimension());
|
||||
LootSettings regionLoot = settingsOf(region);
|
||||
LootSettings surfaceLoot = settingsOf(surfaceBiome);
|
||||
boolean distinctContextualBiome = !sameBiome(surfaceBiome, contextualBiome);
|
||||
double multiplier = engine.getDimension().getLoot().getMultiplier()
|
||||
* region.getLoot().getMultiplier()
|
||||
* surfaceBiome.getLoot().getMultiplier();
|
||||
double multiplier = dimensionLoot.multiplier() * regionLoot.multiplier() * surfaceLoot.multiplier();
|
||||
if (distinctContextualBiome) {
|
||||
multiplier *= contextualBiome.getLoot().getMultiplier();
|
||||
multiplier *= settingsOf(contextualBiome).multiplier();
|
||||
}
|
||||
|
||||
boolean fallback = !objectLootDefined;
|
||||
injectReference(sources, engine.getDimension().getLoot(), engine, mapper, fallback);
|
||||
injectReference(sources, region.getLoot(), engine, mapper, fallback);
|
||||
injectReference(sources, surfaceBiome.getLoot(), engine, mapper, fallback);
|
||||
injectReference(sources, dimensionLoot, engine, mapper, fallback);
|
||||
injectReference(sources, regionLoot, engine, mapper, fallback);
|
||||
injectReference(sources, surfaceLoot, engine, mapper, fallback);
|
||||
if (distinctContextualBiome) {
|
||||
injectReference(sources, contextualBiome.getLoot(), engine, mapper, fallback);
|
||||
injectReference(sources, settingsOf(contextualBiome), engine, mapper, fallback);
|
||||
}
|
||||
LootResolver.scaleSources(sources, multiplier, rng);
|
||||
}
|
||||
@@ -113,17 +117,17 @@ public final class LootTables {
|
||||
public static <T> void injectSources(
|
||||
List<T> sources,
|
||||
List<? extends T> additions,
|
||||
IrisLootMode mode,
|
||||
LootMode mode,
|
||||
boolean fallback
|
||||
) {
|
||||
if (mode == IrisLootMode.FALLBACK && !fallback) {
|
||||
if (mode == LootMode.FALLBACK && !fallback) {
|
||||
return;
|
||||
}
|
||||
if (mode == IrisLootMode.CLEAR) {
|
||||
if (mode == LootMode.CLEAR) {
|
||||
sources.clear();
|
||||
return;
|
||||
}
|
||||
if (mode == IrisLootMode.REPLACE) {
|
||||
if (mode == LootMode.REPLACE) {
|
||||
sources.clear();
|
||||
}
|
||||
sources.addAll(additions);
|
||||
@@ -141,22 +145,16 @@ public final class LootTables {
|
||||
|
||||
private static <T> void injectReference(
|
||||
List<T> sources,
|
||||
IrisLootReference reference,
|
||||
LootSettings loot,
|
||||
Engine engine,
|
||||
Function<IrisLootTable, T> mapper,
|
||||
Function<String, T> mapper,
|
||||
boolean fallback
|
||||
) {
|
||||
KList<IrisLootTable> tables = reference.getLootTables(engine.getComplex());
|
||||
KList<T> additions = new KList<>();
|
||||
for (IrisLootTable table : tables) {
|
||||
if (table == null) {
|
||||
continue;
|
||||
}
|
||||
T source = mapper.apply(table);
|
||||
if (source != null) {
|
||||
additions.add(source);
|
||||
}
|
||||
}
|
||||
injectSources(sources, additions, reference.getMode(), fallback);
|
||||
List<T> additions = loot.tables().stream()
|
||||
.filter(key -> LootResources.table(engine.getData(), key) != null)
|
||||
.map(mapper)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
injectSources(sources, additions, loot.mode(), fallback);
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,9 @@ package art.arcane.iris.engine.loot;
|
||||
import art.arcane.iris.core.modules.IrisValidationContext;
|
||||
import art.arcane.iris.core.pack.PackIntegerChecks;
|
||||
import art.arcane.iris.core.pack.PackValidationIo;
|
||||
import art.arcane.iris.engine.object.loot.IrisLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.iris.builtin.loot.LootEntry;
|
||||
import art.arcane.iris.builtin.loot.LootSettings;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.volmit.validation.Problem;
|
||||
@@ -162,9 +162,9 @@ public final class LootValidator implements Validator {
|
||||
PackIntegerChecks.requireMinimum(path + ".minPicked", minimumPicked, 0, blockingErrors);
|
||||
PackIntegerChecks.requireMinimum(path + ".maxPicked", maximumPicked, 1, blockingErrors);
|
||||
PackIntegerChecks.requireMinimum(path + ".maxTries", maximumTries, 1, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".minPicked", minimumPicked, IrisLootTable.MAX_PICKED, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".maxPicked", maximumPicked, IrisLootTable.MAX_PICKED, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".maxTries", maximumTries, IrisLootTable.MAX_TRIES, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".minPicked", minimumPicked, LootTable.MAX_PICKED, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".maxPicked", maximumPicked, LootTable.MAX_PICKED, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(path + ".maxTries", maximumTries, LootTable.MAX_TRIES, blockingErrors);
|
||||
PackIntegerChecks.requireOrdered(path + ".minPicked", minimumPicked, path + ".maxPicked", maximumPicked, blockingErrors);
|
||||
|
||||
JSONArray entries = table.optJSONArray("loot");
|
||||
@@ -189,8 +189,8 @@ public final class LootValidator implements Validator {
|
||||
PackIntegerChecks.requireMinimum(entryPath + ".rarity", entryRarity, 1, blockingErrors);
|
||||
PackIntegerChecks.requireMinimum(entryPath + ".minAmount", minimumAmount, 1, blockingErrors);
|
||||
PackIntegerChecks.requireMinimum(entryPath + ".maxAmount", maximumAmount, 1, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(entryPath + ".minAmount", minimumAmount, IrisLoot.MAX_AMOUNT, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(entryPath + ".maxAmount", maximumAmount, IrisLoot.MAX_AMOUNT, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(entryPath + ".minAmount", minimumAmount, LootEntry.MAX_AMOUNT, blockingErrors);
|
||||
PackIntegerChecks.requireMaximum(entryPath + ".maxAmount", maximumAmount, LootEntry.MAX_AMOUNT, blockingErrors);
|
||||
PackIntegerChecks.requireOrdered(entryPath + ".minAmount", minimumAmount,
|
||||
entryPath + ".maxAmount", maximumAmount, blockingErrors);
|
||||
validateLootEnchantments(entryPath, entry.opt("enchantments"), blockingErrors);
|
||||
@@ -256,9 +256,9 @@ public final class LootValidator implements Validator {
|
||||
if (!(rawMultiplier instanceof Number multiplier)
|
||||
|| !Double.isFinite(multiplier.doubleValue())
|
||||
|| multiplier.doubleValue() < 0D
|
||||
|| multiplier.doubleValue() > IrisLootReference.MAX_MULTIPLIER) {
|
||||
|| multiplier.doubleValue() > LootSettings.MAX_MULTIPLIER) {
|
||||
blockingErrors.add(path + ".multiplier must be a finite number from 0 to "
|
||||
+ (int) IrisLootReference.MAX_MULTIPLIER + ".");
|
||||
+ (int) LootSettings.MAX_MULTIPLIER + ".");
|
||||
}
|
||||
}
|
||||
if (!reference.has("tables")) {
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.engine.loot;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.loot.IObjectLoot;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.service.Loot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* The loot table an object placement gives to one of its containers: the placement's tables and the platform's own,
|
||||
* each with the blocks it applies to and a weight. A table that names the container's exact block wins over one that
|
||||
* names the container's kind of block, which wins over one that names no blocks; among equals the weights pick.
|
||||
*/
|
||||
final class PlacementLoot {
|
||||
private static final String VANILLA_NAMESPACE = "minecraft:";
|
||||
private static final char NAMESPACE_SEPARATOR = ':';
|
||||
private static final char PROPERTIES_START = '[';
|
||||
|
||||
private final IrisData data;
|
||||
private final Supplier<Set<String>> platformTables;
|
||||
private final long lootSeed;
|
||||
|
||||
/** @param platformTables the keys of the loot tables the platform has, asked for only when a placement names one */
|
||||
PlacementLoot(IrisData data, Supplier<Set<String>> platformTables, long lootSeed) {
|
||||
this.data = data;
|
||||
this.platformTables = platformTables;
|
||||
this.lootSeed = lootSeed;
|
||||
}
|
||||
|
||||
/** The platform's loot table keys, which a placement may name, in the form a placement names them. */
|
||||
static Set<String> platformTableKeys() {
|
||||
return Set.copyOf(IrisPlatforms.get().registries().lootTableKeys());
|
||||
}
|
||||
|
||||
/**
|
||||
* The table a placement, whose platform tables are {@code platformLoot} and whose pack tables are {@code packLoot},
|
||||
* gives {@code container}, a storage chest, at the spot {@code x}, {@code worldY}, {@code z}; null when it gives
|
||||
* it none.
|
||||
*/
|
||||
Loot.Source pick(List<? extends IObjectLoot> platformLoot, List<? extends IObjectLoot> packLoot, PlatformBlockState container,
|
||||
RNG rng, int x, int worldY, int z) {
|
||||
Candidates candidates = new Candidates(container);
|
||||
add(candidates, platformLoot, name -> platformSource(name, x, worldY, z));
|
||||
add(candidates, packLoot, this::packSource);
|
||||
List<Candidate> pool = candidates.pool();
|
||||
Candidate picked = LootResolver.pickWeighted(pool, Candidate::weight, rng);
|
||||
return picked == null ? null : picked.source();
|
||||
}
|
||||
|
||||
private void add(Candidates candidates, List<? extends IObjectLoot> entries, Function<String, Loot.Source> sourceOf) {
|
||||
for (IObjectLoot entry : entries) {
|
||||
if (entry == null || entry.getWeight() <= 0) {
|
||||
continue;
|
||||
}
|
||||
Loot.Source source = sourceOf.apply(entry.getName());
|
||||
if (source == null) {
|
||||
IrisLogging.warn("Couldn't find loot table " + entry.getName());
|
||||
continue;
|
||||
}
|
||||
candidates.add(entry, data, new Candidate(source, entry.getWeight()));
|
||||
}
|
||||
}
|
||||
|
||||
private Loot.Source packSource(String key) {
|
||||
return LootResources.table(data, key) == null ? null : new Loot.Table(key);
|
||||
}
|
||||
|
||||
private Loot.Source platformSource(String name, int x, int worldY, int z) {
|
||||
String key = platformKey(name);
|
||||
if (key == null || !platformTables.get().contains(key)) {
|
||||
return null;
|
||||
}
|
||||
return new Loot.PlatformTable(key, LootTables.seed(lootSeed, LootTables.platformIdentity(key), x, worldY, z));
|
||||
}
|
||||
|
||||
/** A placement's name for a platform table as the platform's key for it, or null for a name that cannot be one. */
|
||||
static String platformKey(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return name.indexOf(NAMESPACE_SEPARATOR) < 0 ? VANILLA_NAMESPACE + name : name;
|
||||
}
|
||||
|
||||
private record Candidate(Loot.Source source, int weight) {
|
||||
}
|
||||
|
||||
/** The candidates for one container, in the groups the placement gives them. */
|
||||
private static final class Candidates {
|
||||
private final String containerKey;
|
||||
private final String containerMaterial;
|
||||
private final List<Candidate> exact = new ArrayList<>();
|
||||
private final List<Candidate> basic = new ArrayList<>();
|
||||
private final List<Candidate> global = new ArrayList<>();
|
||||
|
||||
private Candidates(PlatformBlockState container) {
|
||||
this.containerKey = container.key();
|
||||
this.containerMaterial = materialOf(containerKey);
|
||||
}
|
||||
|
||||
void add(IObjectLoot entry, IrisData data, Candidate candidate) {
|
||||
List<PlatformBlockState> filter = entry.getFilter(data);
|
||||
if (filter.isEmpty()) {
|
||||
global.add(candidate);
|
||||
return;
|
||||
}
|
||||
for (PlatformBlockState filterState : filter) {
|
||||
if (entry.isExact() && filterState.key().equals(containerKey)) {
|
||||
exact.add(candidate);
|
||||
} else if (!entry.isExact() && materialOf(filterState.key()).equals(containerMaterial)) {
|
||||
basic.add(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Candidate> pool() {
|
||||
if (!exact.isEmpty()) {
|
||||
return exact;
|
||||
}
|
||||
return basic.isEmpty() ? global : basic;
|
||||
}
|
||||
|
||||
private static String materialOf(String blockKey) {
|
||||
int properties = blockKey.indexOf(PROPERTIES_START);
|
||||
return properties < 0 ? blockKey : blockKey.substring(0, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.engine.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.BlockDrop;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockSpec;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** A {@link BlockDrop} with the blocks it names resolved to the platform's: which broken blocks it drops for. */
|
||||
final class ResolvedBlockDrop {
|
||||
private static final char PROPERTIES_START = '[';
|
||||
|
||||
private final BlockDrop drop;
|
||||
private final boolean exact;
|
||||
private final Set<String> blocks;
|
||||
|
||||
private ResolvedBlockDrop(BlockDrop drop, Set<String> blocks) {
|
||||
this.drop = drop;
|
||||
this.exact = drop.exactBlocks();
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
/** @param blocks the pack's blocks, which the drop's block specs resolve against */
|
||||
static ResolvedBlockDrop of(BlockDrop drop, BlockRegistry blocks) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (BlockSpec spec : drop.blocks()) {
|
||||
PlatformBlockState state = IrisPlatforms.get().registries().block(blocks.resolve(spec).key());
|
||||
if (state != null) {
|
||||
keys.add(comparable(state.key(), drop.exactBlocks()));
|
||||
}
|
||||
}
|
||||
return new ResolvedBlockDrop(drop, keys);
|
||||
}
|
||||
|
||||
BlockDrop drop() {
|
||||
return drop;
|
||||
}
|
||||
|
||||
/** Whether the drop applies to {@code brokenKey}, the platform's key for the broken block: its exact state, or just its kind of block. */
|
||||
boolean dropsFor(String brokenKey) {
|
||||
return blocks.contains(comparable(brokenKey, exact));
|
||||
}
|
||||
|
||||
private static String comparable(String key, boolean exact) {
|
||||
if (exact) {
|
||||
return key;
|
||||
}
|
||||
int properties = key.indexOf(PROPERTIES_START);
|
||||
return properties < 0 ? key : key.substring(0, properties);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.annotations;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@@ -31,5 +29,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Retention(RUNTIME)
|
||||
@Target({PARAMETER, TYPE, FIELD})
|
||||
public @interface RegistryListResource {
|
||||
Class<? extends IrisRegistrant> value();
|
||||
/** The class pack resources of the kind are read into: an Iris resource or the class of a module resource kind. */
|
||||
Class<?> value();
|
||||
}
|
||||
@@ -1,66 +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.engine.object.entity;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
@Snippet("attribute-modifier")
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents an attribute modifier for an item or an entity. This allows you to create modifications to basic game attributes such as MAX_HEALTH or ARMOR_VALUE.")
|
||||
@Data
|
||||
public class IrisAttributeModifier {
|
||||
@Required
|
||||
@Desc("The Attribute type key such as max_health or minecraft:armor. This type is pulled from the game attributes. Zombie & Horse attributes will not work on non-zombie/horse entities.\nUsing an attribute on an item will have affects when held, or worn. There is no way to specify further granularity as the game picks this depending on the item type.")
|
||||
private String attribute = null;
|
||||
|
||||
@MinNumber(2)
|
||||
@Required
|
||||
@Desc("The Attribute Name is used internally only for the game. This value should be unique to all other attributes applied to this item/entity. It is not shown in game.")
|
||||
private String name = "";
|
||||
|
||||
@Desc("The application operation: ADD_NUMBER (default), ADD_SCALAR or MULTIPLY_SCALAR_1. Add Number adds to the default value. \nAdd scalar_1 will multiply by 1 for example if the health is 20 and you multiply_scalar_1 by 0.5, the health will result in 30, not 10. Use negative values to achieve that.")
|
||||
private String operation = "ADD_NUMBER";
|
||||
|
||||
@Desc("Minimum amount for this modifier. Iris randomly chooses an amount, this is the minimum it can choose randomly for this attribute.")
|
||||
private double minAmount = 1;
|
||||
|
||||
@Desc("Maximum amount for this modifier Iris randomly chooses an amount, this is the maximum it can choose randomly for this attribute.")
|
||||
private double maxAmount = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The chance that this attribute is applied (0 to 1). If the chance is 0.5 (50%), then Iris will only apply this attribute 50% of the time.")
|
||||
private double chance = 1;
|
||||
|
||||
public double getAmount(RNG rng) {
|
||||
return rng.d(getMinAmount(), getMaxAmount());
|
||||
}
|
||||
}
|
||||
@@ -1,288 +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.engine.object.entity;
|
||||
|
||||
import art.arcane.iris.engine.object.marker.IrisCommandRegistry;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.DependsOn;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListPotionEffect;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
import art.arcane.iris.util.common.data.registry.RegistryUtil;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@Snippet("effect")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("An iris effect")
|
||||
@Data
|
||||
public class IrisEffect {
|
||||
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
||||
private final transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
|
||||
private final transient AtomicCache<Particle> particleEffectResolved = new AtomicCache<>();
|
||||
private final transient AtomicCache<Sound> soundResolved = new AtomicCache<>();
|
||||
@RegistryListPotionEffect
|
||||
@Desc("The potion effect to apply in this area")
|
||||
private String potionEffect = "";
|
||||
@Desc("The particle effect to apply in the area")
|
||||
private String particleEffect = null;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(-32)
|
||||
@MaxNumber(32)
|
||||
@Desc("Randomly offset from the surface to this surface+value")
|
||||
private int particleOffset = 0;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double particleAltX = 0;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double particleAltY = 0;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double particleAltZ = 0;
|
||||
@DependsOn({"particleEffect"})
|
||||
@Desc("Randomize the altX by -altX to altX")
|
||||
private boolean randomAltX = true;
|
||||
@DependsOn({"particleEffect"})
|
||||
@Desc("Randomize the altY by -altY to altY")
|
||||
private boolean randomAltY = false;
|
||||
@DependsOn({"particleEffect"})
|
||||
@Desc("Randomize the altZ by -altZ to altZ")
|
||||
private boolean randomAltZ = true;
|
||||
@Desc("The sound to play")
|
||||
private String sound = null;
|
||||
@DependsOn({"sound"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(512)
|
||||
@Desc("The max distance from the player the sound will play")
|
||||
private int soundDistance = 12;
|
||||
@DependsOn({"sound", "maxPitch"})
|
||||
@MinNumber(0.01)
|
||||
@MaxNumber(1.99)
|
||||
@Desc("The minimum sound pitch")
|
||||
private double minPitch = 0.5D;
|
||||
@DependsOn({"sound", "minVolume"})
|
||||
@MinNumber(0.01)
|
||||
@MaxNumber(1.99)
|
||||
@Desc("The max sound pitch")
|
||||
private double maxPitch = 1.5D;
|
||||
@DependsOn({"sound"})
|
||||
@MinNumber(0.001)
|
||||
@MaxNumber(512)
|
||||
@Desc("The sound volume.")
|
||||
private double volume = 1.5D;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(512)
|
||||
@Desc("The particle count. Try setting to zero for using the alt xyz to a motion value instead of an offset")
|
||||
private int particleCount = 0;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(64)
|
||||
@Desc("How far away from the player particles can play")
|
||||
private int particleDistance = 20;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(128)
|
||||
@Desc("How wide the particles can play (player's view left and right) RADIUS")
|
||||
private int particleDistanceWidth = 24;
|
||||
@DependsOn({"particleEffect"})
|
||||
@Desc("An extra value for some particles... Which bukkit doesn't even document.")
|
||||
private double extra = 0;
|
||||
@DependsOn({"potionEffect"})
|
||||
@MinNumber(-1)
|
||||
@MaxNumber(1024)
|
||||
@Desc("The Potion Strength or -1 to disable")
|
||||
private int potionStrength = -1;
|
||||
@DependsOn({"potionEffect", "potionTicksMin"})
|
||||
@MinNumber(1)
|
||||
@Desc("The max time the potion will last for")
|
||||
private int potionTicksMax = 155;
|
||||
@DependsOn({"potionEffect", "potionTicksMax"})
|
||||
@MinNumber(1)
|
||||
@Desc("The min time the potion will last for")
|
||||
private int potionTicksMin = 75;
|
||||
@Required
|
||||
@MinNumber(0)
|
||||
@Desc("The effect interval in milliseconds")
|
||||
private int interval = 150;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(16)
|
||||
@Desc("The effect distance start away")
|
||||
private int particleAway = 5;
|
||||
@Required
|
||||
@MinNumber(1)
|
||||
@Desc("The chance is 1 in CHANCE per interval")
|
||||
private int chance = 50;
|
||||
@Desc("Run commands, with configurable location parameters")
|
||||
private IrisCommandRegistry commandRegistry = null;
|
||||
|
||||
|
||||
public boolean canTick() {
|
||||
return latch.aquire(() -> new ChronoLatch(interval)).flip();
|
||||
}
|
||||
|
||||
public boolean shouldApplyNow() {
|
||||
return canTick() && RNG.r.nextInt(chance) == 0;
|
||||
}
|
||||
|
||||
public String getParticleEffectKey() {
|
||||
return particleEffect;
|
||||
}
|
||||
|
||||
public String getSoundKey() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public Particle getParticleEffect() {
|
||||
if (particleEffect == null) {
|
||||
return null;
|
||||
}
|
||||
return particleEffectResolved.aquire(() -> resolveKeyed(Particle.class, particleEffect));
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
if (sound == null) {
|
||||
return null;
|
||||
}
|
||||
return soundResolved.aquire(() -> resolveKeyed(Sound.class, sound));
|
||||
}
|
||||
|
||||
private static <T> T resolveKeyed(Class<T> type, String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
|
||||
return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey);
|
||||
}
|
||||
|
||||
public PotionEffectType getRealType() {
|
||||
return pt.aquire(() ->
|
||||
{
|
||||
if (getPotionEffect() == null || getPotionEffect().isEmpty()) {
|
||||
return PotionEffectType.LUCK;
|
||||
}
|
||||
|
||||
try {
|
||||
PotionEffectType resolved = PotionEffectTypes.resolve(getPotionEffect());
|
||||
if (resolved != null) {
|
||||
return resolved;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
|
||||
if (PotionEffectTypes.shouldWarn(getPotionEffect())) {
|
||||
IrisLogging.warn("Unknown Potion Effect Type: \"" + getPotionEffect() + "\". Valid types: " + PotionEffectTypes.knownTypesList());
|
||||
}
|
||||
|
||||
return PotionEffectType.LUCK;
|
||||
});
|
||||
}
|
||||
|
||||
private static final class BukkitFx {
|
||||
private static void run(Player p, Runnable r) {
|
||||
J.runEntity(p, r);
|
||||
}
|
||||
}
|
||||
|
||||
public void apply(Player p, Engine g) {
|
||||
if (!shouldApplyNow()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BukkitFx.run(p, () -> {
|
||||
Sound soundType = getSound();
|
||||
Particle particleType = getParticleEffect();
|
||||
if (soundType != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||
p.playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
Location part = p.getLocation().clone().add(p.getLocation().getDirection().clone().multiply(RNG.r.i(particleDistance) + particleAway)).clone().add(p.getLocation().getDirection().clone().rotateAroundY(Math.toRadians(90)).multiply(RNG.r.d(-particleDistanceWidth, particleDistanceWidth)));
|
||||
|
||||
part.setY(Math.round(g.getHeight(part.getBlockX(), part.getBlockZ())) + 1);
|
||||
part.add(RNG.r.d(), 0, RNG.r.d());
|
||||
int offset = p.getWorld().getMinHeight();
|
||||
if (extra != 0) {
|
||||
p.spawnParticle(particleType, part.getX(), part.getY() + offset + RNG.r.i(particleOffset),
|
||||
part.getZ(),
|
||||
particleCount,
|
||||
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
|
||||
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
|
||||
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ,
|
||||
extra);
|
||||
} else {
|
||||
p.spawnParticle(particleType, part.getX(), part.getY() + offset + RNG.r.i(particleOffset), part.getZ(),
|
||||
particleCount,
|
||||
randomAltX ? RNG.r.d(-particleAltX, particleAltX) : particleAltX,
|
||||
randomAltY ? RNG.r.d(-particleAltY, particleAltY) : particleAltY,
|
||||
randomAltZ ? RNG.r.d(-particleAltZ, particleAltZ) : particleAltZ);
|
||||
}
|
||||
}
|
||||
|
||||
if (commandRegistry != null) {
|
||||
commandRegistry.run(p);
|
||||
}
|
||||
|
||||
if (potionStrength > -1) {
|
||||
if (p.hasPotionEffect(getRealType())) {
|
||||
PotionEffect e = p.getPotionEffect(getRealType());
|
||||
if (e != null && e.getAmplifier() > getPotionStrength()) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.removePotionEffect(getRealType());
|
||||
}
|
||||
|
||||
p.addPotionEffect(new PotionEffect(getRealType(),
|
||||
RNG.r.i(Math.min(potionTicksMax, potionTicksMin),
|
||||
Math.max(potionTicksMax, potionTicksMin)),
|
||||
getPotionStrength(),
|
||||
true, false, false));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,160 +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.engine.object.entity;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSurface;
|
||||
import art.arcane.iris.engine.object.loot.IrisLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.marker.IrisCommand;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListEntityType;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListSpecialEntity;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
|
||||
@Desc("Represents an iris entity.")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisEntity extends IrisRegistrant {
|
||||
@Required
|
||||
@RegistryListEntityType
|
||||
@Desc("The namespaced key of the entity type to spawn, such as minecraft:zombie or alexsmobs:grizzly_bear. To spawn a mob from another plugin or provider, set this type to unknown and define the special type.")
|
||||
private String type = null;
|
||||
|
||||
@Desc("The SpawnReason name to spawn the entity with, such as NATURAL or COMMAND.")
|
||||
private String reason = null;
|
||||
|
||||
@Desc("The custom name of this entity")
|
||||
private String customName = "";
|
||||
|
||||
@Desc("Should the name on this entity be visible even if you arent looking at it.")
|
||||
private boolean customNameVisible = false;
|
||||
|
||||
@Desc("If this entity type is a mob, should it be aware of it's surroundings & interact with the world.")
|
||||
private boolean aware = true;
|
||||
|
||||
@Desc("If this entity type is a creature, should it have ai goals.")
|
||||
private boolean ai = true;
|
||||
|
||||
@Desc("Should this entity be glowing")
|
||||
private boolean glowing = false;
|
||||
|
||||
@Desc("Should gravity apply to this entity")
|
||||
private boolean gravity = true;
|
||||
|
||||
@Desc("When an entity is invulnerable it can only be damaged by players increative mode.")
|
||||
private boolean invulnerable = false;
|
||||
|
||||
@Desc("When an entity is silent it will not produce any sound.")
|
||||
private boolean silent = false;
|
||||
|
||||
@Desc("Should this entity be allowed to pickup items")
|
||||
private boolean pickupItems = false;
|
||||
|
||||
@Desc("Should this entity be removed when far away")
|
||||
private boolean removable = false;
|
||||
|
||||
@Desc("Entity helmet equipment")
|
||||
private IrisLoot helmet = null;
|
||||
|
||||
@Desc("Entity chestplate equipment")
|
||||
private IrisLoot chestplate = null;
|
||||
|
||||
@Desc("Entity boots equipment")
|
||||
private IrisLoot boots = null;
|
||||
|
||||
@Desc("Entity leggings equipment")
|
||||
private IrisLoot leggings = null;
|
||||
|
||||
@Desc("Entity main hand equipment")
|
||||
private IrisLoot mainHand = null;
|
||||
|
||||
@Desc("Entity off hand equipment")
|
||||
private IrisLoot offHand = null;
|
||||
|
||||
@Desc("Make other entities ride this entity")
|
||||
@ArrayType(min = 1, type = IrisEntity.class)
|
||||
private KList<IrisEntity> passengers = new KList<>();
|
||||
|
||||
@Desc("Attribute modifiers for this entity")
|
||||
@ArrayType(min = 1, type = IrisAttributeModifier.class)
|
||||
private KList<IrisAttributeModifier> attributes = new KList<>();
|
||||
|
||||
@Desc("Loot tables for drops. Only the tables list is honored for entities; mode and multiplier are ignored, and the tables replace vanilla drops entirely.")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
|
||||
@Desc("If specified, this entity will be leashed by this entity. I.e. THIS ENTITY Leashed by SPECIFIED. This has no effect on EnderDragons, Withers, Players, or Bats.Non-living entities excluding leashes will not persist as leashholders.")
|
||||
private IrisEntity leashHolder = null;
|
||||
|
||||
@Desc("If specified, this entity will spawn with an effect")
|
||||
private IrisEffect spawnEffect = null;
|
||||
|
||||
@Desc("Simply moves the entity from below the surface slowly out of the ground as a spawn-in effect")
|
||||
private boolean spawnEffectRiseOutOfGround = false;
|
||||
|
||||
@Desc("The main gene for a panda if the entity type is a panda. One of NORMAL, LAZY, WORRIED, PLAYFUL, BROWN, WEAK or AGGRESSIVE.")
|
||||
private String pandaMainGene = null;
|
||||
|
||||
@Desc("The hidden gene for a panda if the entity type is a panda. One of NORMAL, LAZY, WORRIED, PLAYFUL, BROWN, WEAK or AGGRESSIVE.")
|
||||
private String pandaHiddenGene = null;
|
||||
|
||||
@Desc("The this entity is ageable, set it's baby status")
|
||||
private boolean baby = false;
|
||||
|
||||
@Desc("If the entity should never be culled.")
|
||||
private boolean keepEntity = false;
|
||||
|
||||
@Desc("The surface type to spawn this mob on")
|
||||
private IrisSurface surface = IrisSurface.LAND;
|
||||
|
||||
@RegistryListSpecialEntity
|
||||
@Desc("Create a mob from another plugin, such as Mythic Mobs. Should be in the format of a namespace of PluginName:MobName")
|
||||
private String specialType = "";
|
||||
|
||||
@Desc("Set to true if you want to apply all of the settings here to the mob, even though an external plugin has already done so.")
|
||||
private boolean applySettingsToCustomMobAnyways = false;
|
||||
|
||||
@ArrayType(min = 1, type = IrisCommand.class)
|
||||
@Desc("Run raw commands when this entity is spawned. Use {x}, {y}, and {z} for location. /summon pig {x} {y} {z}")
|
||||
private KList<IrisCommand> rawCommands = new KList<>();
|
||||
|
||||
public boolean isSpecialType() {
|
||||
return specialType != null && !specialType.equals("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "entities";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Entity";
|
||||
}
|
||||
}
|
||||
@@ -1,66 +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.engine.object.entity;
|
||||
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.marker.IrisMarker;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("entity-spawn")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents an entity spawn during initial chunk generation")
|
||||
@Data
|
||||
public class IrisEntitySpawn implements IRare {
|
||||
private final transient AtomicCache<RNG> rng = new AtomicCache<>();
|
||||
private final transient AtomicCache<IrisEntity> ent = new AtomicCache<>();
|
||||
@RegistryListResource(IrisEntity.class)
|
||||
@Required
|
||||
@Desc("The entity")
|
||||
private String entity = "";
|
||||
@MinNumber(1)
|
||||
@Desc("The 1 in RARITY chance for this entity to spawn")
|
||||
private int rarity = 1;
|
||||
@MinNumber(1)
|
||||
@Desc("The minumum of this entity to spawn")
|
||||
private int minSpawns = 1;
|
||||
@MinNumber(1)
|
||||
@Desc("The max of this entity to spawn")
|
||||
private int maxSpawns = 1;
|
||||
private transient IrisSpawner referenceSpawner;
|
||||
private transient IrisMarker referenceMarker;
|
||||
|
||||
public IrisEntity getRealEntity(Engine g) {
|
||||
return ent.aquire(() -> SpawnResources.entity(g.getData(), getEntity()));
|
||||
}
|
||||
}
|
||||
@@ -1,102 +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.engine.object.entity;
|
||||
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListPotionEffect;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
|
||||
@Snippet("potion-effect")
|
||||
@Desc("An iris potion effect")
|
||||
@Data
|
||||
public class IrisPotionEffect {
|
||||
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
||||
@Required
|
||||
@RegistryListPotionEffect
|
||||
@Desc("The potion effect to apply in this area")
|
||||
private String potionEffect = "";
|
||||
@Required
|
||||
@MinNumber(-1)
|
||||
@MaxNumber(1024)
|
||||
@Desc("The Potion Strength or -1 to disable")
|
||||
private int strength = -1;
|
||||
@Required
|
||||
@MinNumber(1)
|
||||
@Desc("The time the potion will last for")
|
||||
private int ticks = 200;
|
||||
@Desc("Is the effect ambient")
|
||||
private boolean ambient = false;
|
||||
@Desc("Is the effect showing particles")
|
||||
private boolean particles = true;
|
||||
|
||||
public PotionEffectType getRealType() {
|
||||
return pt.aquire(() ->
|
||||
{
|
||||
if (getPotionEffect() == null || getPotionEffect().isEmpty()) {
|
||||
return PotionEffectType.LUCK;
|
||||
}
|
||||
|
||||
try {
|
||||
PotionEffectType resolved = PotionEffectTypes.resolve(getPotionEffect());
|
||||
if (resolved != null) {
|
||||
return resolved;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
|
||||
if (PotionEffectTypes.shouldWarn(getPotionEffect())) {
|
||||
IrisLogging.warn("Unknown Potion Effect Type: \"" + getPotionEffect() + "\". Valid types: " + PotionEffectTypes.knownTypesList());
|
||||
}
|
||||
|
||||
return PotionEffectType.LUCK;
|
||||
});
|
||||
}
|
||||
|
||||
public void apply(LivingEntity p) {
|
||||
if (strength > -1) {
|
||||
if (p.hasPotionEffect(getRealType())) {
|
||||
PotionEffect e = p.getPotionEffect(getRealType());
|
||||
if (e.getAmplifier() > strength) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.removePotionEffect(getRealType());
|
||||
}
|
||||
|
||||
p.addPotionEffect(new PotionEffect(getRealType(), ticks, strength, ambient, particles, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +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.engine.object.entity;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -18,8 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.entity.spawn;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IrisRate;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -28,11 +26,11 @@ public class IrisEngineSpawnerCooldown {
|
||||
private long lastSpawn = 0;
|
||||
private String spawner;
|
||||
|
||||
public void spawn(Engine engine) {
|
||||
public void spawn() {
|
||||
lastSpawn = M.ms();
|
||||
}
|
||||
|
||||
public boolean canSpawn(IrisRate s) {
|
||||
return M.ms() - lastSpawn > s.getInterval();
|
||||
public boolean canSpawn(long intervalMilliseconds) {
|
||||
return M.ms() - lastSpawn > intervalMilliseconds;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +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.engine.object.entity.spawn;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("Terrain modes are used to decide the generator type currently used")
|
||||
public enum IrisSpawnGroup {
|
||||
@Desc("Spawns on the terrain surface")
|
||||
NORMAL,
|
||||
|
||||
@Desc("Spawns in cave-air and low light level areas")
|
||||
CAVE,
|
||||
|
||||
@Desc("Spawns underwater")
|
||||
UNDERWATER,
|
||||
|
||||
@Desc("Spawns in beaches")
|
||||
BEACH
|
||||
}
|
||||
@@ -1,142 +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.engine.object.entity.spawn;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.IrisEntitySpawn;
|
||||
import art.arcane.iris.engine.object.marker.IrisMarker;
|
||||
import art.arcane.iris.engine.object.value.IrisRange;
|
||||
import art.arcane.iris.engine.object.value.IrisRate;
|
||||
import art.arcane.iris.engine.object.world.IrisTimeBlock;
|
||||
import art.arcane.iris.engine.object.world.IrisWeather;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents an entity spawn during initial chunk generation")
|
||||
@Data
|
||||
public class IrisSpawner extends IrisRegistrant {
|
||||
|
||||
private transient IrisMarker referenceMarker;
|
||||
|
||||
@ArrayType(min = 1, type = IrisEntitySpawn.class)
|
||||
@Desc("The entity spawns to add")
|
||||
private KList<IrisEntitySpawn> spawns = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = IrisEntitySpawn.class)
|
||||
@Desc("The entity spawns to add initially. EXECUTES PER CHUNK!")
|
||||
private KList<IrisEntitySpawn> initialSpawns = new KList<>();
|
||||
|
||||
@Desc("This spawner will not spawn in a given chunk if that chunk has more than the defined amount of living entities.")
|
||||
private int maxEntitiesPerChunk = 1;
|
||||
|
||||
@Desc("The block of 24 hour time to contain this spawn in.")
|
||||
private IrisTimeBlock timeBlock = new IrisTimeBlock();
|
||||
|
||||
@Desc("The weather condition required for this spawner to fire.")
|
||||
private IrisWeather weather = IrisWeather.ANY;
|
||||
|
||||
@Desc("The maximum rate this spawner can fire")
|
||||
private IrisRate maximumRate = new IrisRate();
|
||||
|
||||
@Desc("The maximum rate this spawner can fire on a specific chunk")
|
||||
private IrisRate maximumRatePerChunk = new IrisRate();
|
||||
|
||||
@Desc("The light levels this spawn is allowed to run in (0-15 inclusive)")
|
||||
private IrisRange allowedLightLevels = new IrisRange(0, 15);
|
||||
|
||||
@Desc("Where should these spawns be placed")
|
||||
private IrisSpawnGroup group = IrisSpawnGroup.NORMAL;
|
||||
|
||||
public boolean isValid(IrisBiome biome) {
|
||||
return switch (group) {
|
||||
case NORMAL -> switch (biome.getInferredType()) {
|
||||
case SHORE, SEA, CAVE -> false;
|
||||
case LAND -> true;
|
||||
};
|
||||
case CAVE -> true;
|
||||
case UNDERWATER -> switch (biome.getInferredType()) {
|
||||
case SHORE, LAND, CAVE -> false;
|
||||
case SEA -> true;
|
||||
};
|
||||
case BEACH -> switch (biome.getInferredType()) {
|
||||
case SHORE -> true;
|
||||
case LAND, CAVE, SEA -> false;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isValid(PlatformWorld world) {
|
||||
return timeBlock.isWithin(world) && weather.is(world);
|
||||
}
|
||||
|
||||
public boolean canSpawn(Engine engine) {
|
||||
PlatformWorld world = engine.getWorld().platformWorld();
|
||||
if (world == null || !isValid(world))
|
||||
return false;
|
||||
|
||||
IrisRate rate = getMaximumRate();
|
||||
return rate.isInfinite() || engine.getEngineData().getCooldown(this).canSpawn(rate);
|
||||
}
|
||||
|
||||
public boolean canSpawn(Engine engine, int x, int z) {
|
||||
if (!canSpawn(engine))
|
||||
return false;
|
||||
|
||||
IrisRate rate = getMaximumRatePerChunk();
|
||||
return rate.isInfinite() || engine.getEngineData().getChunk(x, z).getCooldown(this).canSpawn(rate);
|
||||
}
|
||||
|
||||
public void spawn(Engine engine) {
|
||||
if (getMaximumRate().isInfinite())
|
||||
return;
|
||||
|
||||
engine.getEngineData().getCooldown(this).spawn(engine);
|
||||
}
|
||||
|
||||
public void spawn(Engine engine, int x, int z) {
|
||||
spawn(engine);
|
||||
if (getMaximumRatePerChunk().isInfinite())
|
||||
return;
|
||||
|
||||
engine.getEngineData().getChunk(x, z).getCooldown(this).spawn(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "spawners";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Spawner";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.engine.object.entity.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
@@ -10,10 +11,6 @@ import lombok.NonNull;
|
||||
public class IrisSpawnerCooldowns {
|
||||
private final KMap<String, IrisEngineSpawnerCooldown> cooldowns = new KMap<>();
|
||||
|
||||
public IrisEngineSpawnerCooldown getCooldown(@NonNull IrisSpawner spawner) {
|
||||
return getCooldown(spawner.getLoadKey());
|
||||
}
|
||||
|
||||
public IrisEngineSpawnerCooldown getCooldown(@NonNull String loadKey) {
|
||||
return cooldowns.computeIfAbsent(loadKey, k -> {
|
||||
IrisEngineSpawnerCooldown cd = new IrisEngineSpawnerCooldown();
|
||||
@@ -24,8 +21,8 @@ public class IrisSpawnerCooldowns {
|
||||
|
||||
public void cleanup(Engine engine) {
|
||||
cooldowns.values().removeIf(cd -> {
|
||||
IrisSpawner sp = SpawnResources.spawner(engine.getData(), cd.getSpawner());
|
||||
return sp == null || cd.canSpawn(sp.getMaximumRate());
|
||||
Spawner spawner = SpawnResources.spawner(engine.getData(), cd.getSpawner());
|
||||
return spawner == null || cd.canSpawn(spawner.maximumRate().interval());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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.engine.object.entity.spawn;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("The type of surface entities should spawn on")
|
||||
public enum IrisSurface {
|
||||
|
||||
@Desc("Land surfaces")
|
||||
LAND,
|
||||
|
||||
@Desc("Any surfaces animals can spawn on, such as dirt, grass and podzol")
|
||||
ANIMAL,
|
||||
|
||||
@Desc("Within the water")
|
||||
WATER,
|
||||
|
||||
@Desc("On land or on water")
|
||||
OVERWORLD,
|
||||
|
||||
@Desc("Within lava")
|
||||
LAVA;
|
||||
}
|
||||
@@ -1,38 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("An inventory slot type is used to represent a type of slot for items to fit into in any given inventory.")
|
||||
public enum InventorySlotType {
|
||||
@Desc("Typically the one you want to go with. Storage represnents most slots in inventories.")
|
||||
STORAGE,
|
||||
|
||||
@Desc("Used for the fuel slot in Furnaces, Blast furnaces, smokers etc.")
|
||||
FUEL,
|
||||
|
||||
@Desc("Used for the cook slot in furnaces")
|
||||
FURNACE,
|
||||
@Desc("Used for the cook slot in blast furnaces")
|
||||
BLAST_FURNACE,
|
||||
|
||||
@Desc("Used for the cook slot in smokers")
|
||||
SMOKER,
|
||||
}
|
||||
@@ -1,105 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import lombok.experimental.Accessors;
|
||||
import com.volmit.item.ItemDrop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Snippet("block-drops")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a block drop list")
|
||||
@Data
|
||||
public class IrisBlockDrops {
|
||||
private final transient AtomicCache<KList<PlatformBlockState>> data = new AtomicCache<>();
|
||||
@Required
|
||||
@ArrayType(min = 1, type = IrisBlockData.class)
|
||||
@Desc("The blocks that drop loot")
|
||||
private KList<IrisBlockData> blocks = new KList<>();
|
||||
@Desc("If exact blocks is set to true, minecraft:barrel[axis=x] will only drop for that axis. When exact is false (default) any barrel will drop the defined drops.")
|
||||
private boolean exactBlocks = false;
|
||||
@Desc("Add in specific items to drop")
|
||||
@ArrayType(min = 1, type = IrisLoot.class)
|
||||
private KList<IrisLoot> drops = new KList<>();
|
||||
@Desc("If this is in a biome, setting skipParents to true will ignore the drops in the region and dimension for this block type. The default (false) will allow all three nodes to fire and add to a list of drops.")
|
||||
private boolean skipParents = false;
|
||||
@Desc("Removes the default vanilla block drops and only drops the given items & any parent loot tables specified for this block type.")
|
||||
private boolean replaceVanillaDrops = false;
|
||||
|
||||
public boolean shouldDropFor(PlatformBlockState broken, IrisData rdata) {
|
||||
KList<PlatformBlockState> list = this.data.aquire(() -> {
|
||||
KList<PlatformBlockState> b = new KList<>();
|
||||
|
||||
for (IrisBlockData i : getBlocks()) {
|
||||
PlatformBlockState state = i.getBlockData(rdata);
|
||||
|
||||
if (state != null) {
|
||||
b.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
return b.removeDuplicates();
|
||||
});
|
||||
|
||||
for (PlatformBlockState i : list) {
|
||||
if (exactBlocks ? i.key().equals(broken.key()) : materialOf(i).equals(materialOf(broken))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Adds the items of the drops that pass their rarity to {@code d}. */
|
||||
public void fillDrops(LootItems items, List<ItemDrop> d) {
|
||||
for (IrisLoot i : getDrops()) {
|
||||
if (!LootResolver.oneIn(RNG.r, i.getRarity())) {
|
||||
continue;
|
||||
}
|
||||
ItemDrop drop = items.give(i, RNG.r);
|
||||
if (drop != null) {
|
||||
d.add(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String materialOf(PlatformBlockState state) {
|
||||
String key = state.key();
|
||||
int properties = key.indexOf('[');
|
||||
return properties < 0 ? key : key.substring(0, properties);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListEnchantment;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
|
||||
@Snippet("enchantment")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents an enchantment & level")
|
||||
@Data
|
||||
public class IrisEnchantment {
|
||||
@Required
|
||||
@RegistryListEnchantment
|
||||
@Desc("The enchantment")
|
||||
private String enchantment;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("Minimum amount of this loot")
|
||||
private int minLevel = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("Maximum amount of this loot")
|
||||
private int maxLevel = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The chance that this enchantment is applied (0 to 1)")
|
||||
private double chance = 1;
|
||||
|
||||
public int getLevel(RNG rng) {
|
||||
return LootResolver.inclusive(rng, getMinLevel(), getMaxLevel());
|
||||
}
|
||||
}
|
||||
@@ -1,113 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.IrisAttributeModifier;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListItemType;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("loot")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a loot entry")
|
||||
@Data
|
||||
@EqualsAndHashCode(doNotUseGetters = true)
|
||||
@ToString(doNotUseGetters = true)
|
||||
public class IrisLoot {
|
||||
public static final int MAX_AMOUNT = 64;
|
||||
|
||||
@Desc("The target inventory slot types to fill this loot with. World generation only ever fills STORAGE; the other values are inert during worldgen.")
|
||||
private InventorySlotType slotTypes = InventorySlotType.STORAGE;
|
||||
@MinNumber(1)
|
||||
@Desc("The sub rarity of this loot. Calculated after this loot table has been picked.")
|
||||
private int rarity = 1;
|
||||
@MinNumber(1)
|
||||
@MaxNumber(MAX_AMOUNT)
|
||||
@Desc("Minimum amount of this loot, from 1 to 64")
|
||||
private int minAmount = 1;
|
||||
@MinNumber(1)
|
||||
@MaxNumber(MAX_AMOUNT)
|
||||
@Desc("Maximum amount of this loot, from 1 to 64")
|
||||
private int maxAmount = 1;
|
||||
@MinNumber(1)
|
||||
@Desc("The display name of this item")
|
||||
private String displayName = null;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Minimum durability percent")
|
||||
private double minDurability = 0;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Maximum durability percent")
|
||||
private double maxDurability = 1;
|
||||
@Desc("Define a custom model identifier 1.14+ only")
|
||||
private Integer customModel = null;
|
||||
@Desc("Set this to true to prevent it from being broken")
|
||||
private boolean unbreakable = false;
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("The item flags to add")
|
||||
private KList<String> itemFlags = new KList<>();
|
||||
@Desc("Apply enchantments to this item")
|
||||
@ArrayType(min = 1, type = IrisEnchantment.class)
|
||||
private KList<IrisEnchantment> enchantments = new KList<>();
|
||||
@Desc("Apply attribute modifiers to this item")
|
||||
@ArrayType(min = 1, type = IrisAttributeModifier.class)
|
||||
private KList<IrisAttributeModifier> attributes = new KList<>();
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("Add lore to this item")
|
||||
private KList<String> lore = new KList<>();
|
||||
@RegistryListItemType
|
||||
@Required
|
||||
@Desc("This is the item or block type. Does not accept minecraft:*, only materials such as DIAMOND_SWORD or DIRT. The exception are modded materials, as they require a namespace.")
|
||||
private String type = "";
|
||||
@Desc("The dye color")
|
||||
private String dyeColor = null;
|
||||
@Desc("The leather armor color")
|
||||
private String leatherColor = null;
|
||||
@Desc("Defines a custom NBT Tag for the item.")
|
||||
private KMap<String, Object> customNbt;
|
||||
|
||||
/**
|
||||
* The authored item key, exactly as written in the pack. Each platform resolves it against its own item registry.
|
||||
*/
|
||||
public String getTypeKey() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The authored dye colour name, or null when unset.
|
||||
*/
|
||||
public String getDyeColorKey() {
|
||||
return dyeColor;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
|
||||
@Desc("A loot mode is used to describe what to do with the existing loot layers before adding this loot. ADD appends to the building list of tables (dimension tables, then region tables, then biome tables). REPLACE swaps the parent tables for this reference's tables. CLEAR suppresses loot entirely at this point.")
|
||||
public enum IrisLootMode {
|
||||
@Desc("Add to the existing parent loot tables")
|
||||
ADD,
|
||||
@Desc("Clear all parent loot tables and contribute nothing at this level. Any tables listed here are ignored.")
|
||||
CLEAR,
|
||||
@Desc("Replace all parent loot tables with this reference's tables")
|
||||
REPLACE,
|
||||
@Desc("Only use when there was no loot table defined by an object")
|
||||
FALLBACK
|
||||
}
|
||||
@@ -1,69 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.engine.loot.LootResources;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.util.common.data.DataProvider;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("loot-registry")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a loot entry")
|
||||
@Data
|
||||
public class IrisLootReference {
|
||||
public static final double MAX_MULTIPLIER = 16D;
|
||||
|
||||
private final transient AtomicCache<KList<IrisLootTable>> tt = new AtomicCache<>();
|
||||
@Desc("ADD = add on top of parent tables. REPLACE = clear parent tables, then add these. CLEAR = clear parent tables and add nothing, even if tables are listed. FALLBACK = only used when nothing else defined a table.")
|
||||
private IrisLootMode mode = IrisLootMode.ADD;
|
||||
@RegistryListResource(IrisLootTable.class)
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("Add loot table registries here")
|
||||
private KList<String> tables = new KList<>();
|
||||
@MinNumber(0)
|
||||
@MaxNumber(MAX_MULTIPLIER)
|
||||
@Desc("Scale loot sources in this area from 0 to 16 times their normal count")
|
||||
private double multiplier = 1D;
|
||||
|
||||
public KList<IrisLootTable> getLootTables(DataProvider g) {
|
||||
return tt.aquire(() ->
|
||||
{
|
||||
KList<IrisLootTable> t = new KList<>();
|
||||
|
||||
for (String i : tables) {
|
||||
t.add(LootResources.table(g.getData(), i));
|
||||
}
|
||||
|
||||
return t;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,81 +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.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents a loot table. Biomes, Regions & Objects can add or replace the virtual table with these loot tables")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisLootTable extends IrisRegistrant {
|
||||
public static final int MAX_PICKED = 64;
|
||||
public static final int MAX_TRIES = 256;
|
||||
|
||||
@Required
|
||||
@Desc("The name of this loot table")
|
||||
@MinNumber(2)
|
||||
private String name = "";
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("The rarity as in 1 in X chance")
|
||||
private int rarity = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(MAX_PICKED)
|
||||
@Desc("The maximum amount of loot that can be picked in this table at a time, from 1 to 64")
|
||||
private int maxPicked = 5;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(MAX_PICKED)
|
||||
@Desc("The minimum amount of loot that can be picked in this table at a time, from 0 to 64")
|
||||
private int minPicked = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(MAX_TRIES)
|
||||
@Desc("The maximum amount of tries to generate loot, from 1 to 256")
|
||||
private int maxTries = 10;
|
||||
|
||||
@Desc("The loot in this table")
|
||||
@ArrayType(min = 1, type = IrisLoot.class)
|
||||
private KList<IrisLoot> loot = new KList<>();
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "loot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Loot";
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
@@ -50,7 +51,7 @@ public class IrisObjectLoot implements IObjectLoot {
|
||||
private boolean exact = false;
|
||||
@Desc("The loot table name")
|
||||
@Required
|
||||
@RegistryListResource(IrisLootTable.class)
|
||||
@RegistryListResource(LootTable.class)
|
||||
private String name;
|
||||
@Desc("The weight of this loot table being chosen")
|
||||
@MinNumber(1)
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package art.arcane.iris.engine.object.loot;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisVanillaLootTable extends IrisLootTable {
|
||||
/**
|
||||
* The vanilla loot table key ("minecraft:chests/simple_dungeon"), not the LootTable itself. A
|
||||
* raw org.bukkit.loot.LootTable field - and the constructor lombok would generate for it - makes
|
||||
* every reflective walk over the IrisLootTable hierarchy (Gson, schema generation, the purity
|
||||
* gate) resolve a Bukkit class. The host resolves the table when it pulls loot from it. The key text is
|
||||
* identical to what {@code LootTable.getKey().toString()} produced before, so
|
||||
* {@code LootTables.identity} (which falls back to
|
||||
* {@link #getName()}) yields the same loot seed.
|
||||
*/
|
||||
private final String lootTableKey;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Vanilla " + lootTableKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRarity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPicked() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinPicked() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxTries() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<IrisLoot> getLoot() {
|
||||
return new KList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
throw new UnsupportedOperationException("VanillaLootTables do not have a folder name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
throw new UnsupportedOperationException("VanillaLootTables do not have a type name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getLoadFile() {
|
||||
throw new UnsupportedOperationException("VanillaLootTables do not have a load file");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisData getLoader() {
|
||||
throw new UnsupportedOperationException("VanillaLootTables do not have a loader");
|
||||
}
|
||||
}
|
||||
@@ -1,72 +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.engine.object.marker;
|
||||
|
||||
import art.arcane.iris.engine.object.world.IrisTimeBlock;
|
||||
import art.arcane.iris.engine.object.world.IrisWeather;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.iris.util.common.scheduling.ConsoleCommands;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("command")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents a set of Iris commands")
|
||||
@Data
|
||||
public class IrisCommand {
|
||||
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("List of commands. Iris replaces {x} {y} and {z} with the location of the entity spawn")
|
||||
private KList<String> commands = new KList<>();
|
||||
|
||||
@Desc("The delay for running the command. Instant by default")
|
||||
private long delay = 0;
|
||||
|
||||
@Desc("If this should be repeated (indefinitely, cannot be cancelled). This does not persist with server-restarts, so it only repeats when the chunk is generated.")
|
||||
private boolean repeat = false;
|
||||
|
||||
@Desc("The delay between repeats, in server ticks (by default 100, so 5 seconds)")
|
||||
private long repeatDelay = 100;
|
||||
|
||||
@Desc("The block of 24 hour time in which the command should execute.")
|
||||
private IrisTimeBlock timeBlock = new IrisTimeBlock();
|
||||
|
||||
@Desc("The weather that is required for the command to execute.")
|
||||
private IrisWeather weather = IrisWeather.ANY;
|
||||
|
||||
public boolean isValid(PlatformWorld world) {
|
||||
return timeBlock.isWithin(world) && weather.is(world);
|
||||
}
|
||||
|
||||
public void run(PlatformWorld world, int x, int y, int z) {
|
||||
if (!isValid(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ConsoleCommands.run(commands, delay, repeat, repeatDelay, x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +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.engine.object.marker;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.DependsOn;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.platform.bukkit.BukkitWorld;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Snippet("command-registry")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents a casting location for a command")
|
||||
@Data
|
||||
public class IrisCommandRegistry {
|
||||
@Required
|
||||
@ArrayType(min = 1, type = IrisCommand.class)
|
||||
@Desc("Run commands, at the exact location of the player")
|
||||
private KList<IrisCommand> rawCommands = new KList<>();
|
||||
@DependsOn({"rawCommands"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double commandOffsetX = 0;
|
||||
@DependsOn({"rawCommands"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double commandOffsetY = 0;
|
||||
@DependsOn({"rawCommands"})
|
||||
@MinNumber(-8)
|
||||
@MaxNumber(8)
|
||||
@Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.")
|
||||
private double commandOffsetZ = 0;
|
||||
@DependsOn({"rawCommands"})
|
||||
@Desc("Randomize the altX from -altX to altX")
|
||||
private boolean commandRandomAltX = true;
|
||||
@DependsOn({"rawCommands"})
|
||||
@Desc("Randomize the altY from -altY to altY")
|
||||
private boolean commandRandomAltY = false;
|
||||
@DependsOn({"rawCommands"})
|
||||
@Desc("Randomize the altZ from -altZ to altZ")
|
||||
private boolean commandRandomAltZ = true;
|
||||
@DependsOn({"rawCommands"})
|
||||
@Desc("Randomize location for all separate commands (true), or run all on the same location (false)")
|
||||
private boolean commandAllRandomLocations = true;
|
||||
|
||||
public void run(Player p) {
|
||||
if (rawCommands.isNotEmpty()) {
|
||||
PlatformWorld world = new BukkitWorld(p.getWorld());
|
||||
Location part = p.getLocation().clone().add(
|
||||
commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX,
|
||||
commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY,
|
||||
commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ);
|
||||
for (IrisCommand rawCommand : rawCommands) {
|
||||
rawCommand.run(world, part.getBlockX(), part.getBlockY(), part.getBlockZ());
|
||||
if (commandAllRandomLocations) {
|
||||
part = p.getLocation().clone().add(
|
||||
commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX,
|
||||
commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY,
|
||||
commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +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.engine.object.marker;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents a marker")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class IrisMarker extends IrisRegistrant {
|
||||
@Desc("A list of spawners to add to anywhere this marker is.")
|
||||
@RegistryListResource(IrisSpawner.class)
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
private KList<String> spawners = new KList<>();
|
||||
|
||||
@Desc("Remove this marker when the block it's assigned to is changed.")
|
||||
private boolean removeOnChange = true;
|
||||
|
||||
@Desc("If true, markers will only be placed here if there is 2 air blocks above it.")
|
||||
private boolean emptyAbove = true;
|
||||
|
||||
@Desc("If this marker is used, what is the chance it removes itself. For example 25% (0.25) would mean that on average 4 uses will remove a specific marker. Set this below 0 (-1) to never exhaust & set this to 1 or higher to always exhaust on first use.")
|
||||
private double exhaustionChance = 0;
|
||||
|
||||
public boolean shouldExhaust() {
|
||||
return exhaustionChance > RNG.r.nextDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFolderName() {
|
||||
return "markers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "Marker";
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.marker;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
@@ -54,7 +55,7 @@ public class IrisObjectMarker {
|
||||
@Desc("If true, markers will only be placed if the block matches the mark list perfectly.")
|
||||
private boolean exact = false;
|
||||
@Required
|
||||
@RegistryListResource(IrisMarker.class)
|
||||
@RegistryListResource(SpawnMarker.class)
|
||||
@Desc("The marker to add")
|
||||
private String marker;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import art.arcane.iris.builtin.blocks.ObjectMarkers;
|
||||
import art.arcane.iris.builtin.blocks.WrittenBlocks;
|
||||
import art.arcane.iris.core.modules.BlockEntities;
|
||||
import art.arcane.iris.core.modules.IrisPlacement;
|
||||
import art.arcane.iris.engine.object.marker.IrisMarker;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.engine.object.marker.IrisObjectMarker;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
@@ -205,7 +205,7 @@ public final class BlocksModule implements IrisModule {
|
||||
RNG markerRandom = new RNG(context.random().nextLong());
|
||||
int salt = 0;
|
||||
for (IrisObjectMarker markerConfig : config.getMarkers()) {
|
||||
IrisMarker marker = SpawnResources.marker(placement.object().getLoader(), markerConfig.getMarker());
|
||||
SpawnMarker marker = SpawnResources.marker(placement.object().getLoader(), markerConfig.getMarker());
|
||||
int markerSalt = salt++;
|
||||
if (marker == null) {
|
||||
continue;
|
||||
@@ -216,7 +216,7 @@ public final class BlocksModule implements IrisModule {
|
||||
if (remaining <= 0) {
|
||||
break;
|
||||
}
|
||||
if (!marker.isEmptyAbove() || hasAirAbove(world, position)) {
|
||||
if (!marker.emptyAbove() || hasAirAbove(world, position)) {
|
||||
context.access().marker(ObjectMarkers.of(position, markerConfig.getMarker()));
|
||||
remaining--;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.engine.loot.LootResources;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
@@ -28,11 +27,8 @@ import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.validate.ObjectLimit;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.object.loot.IObjectLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.iris.engine.object.loot.IrisObjectLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisObjectVanillaLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisVanillaLootTable;
|
||||
import art.arcane.iris.engine.object.marker.IrisObjectMarker;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
@@ -42,13 +38,10 @@ import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.data.cache.AtomicCache;
|
||||
import art.arcane.iris.engine.data.cache.LazyBoundedCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
@@ -56,10 +49,7 @@ import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.iris.util.common.data.DataProvider;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
@@ -73,14 +63,9 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Snippet("object-placer")
|
||||
@EqualsAndHashCode()
|
||||
@@ -204,7 +189,6 @@ public class IrisObjectPlacement {
|
||||
@Desc("Ignore any placement restrictions for this object")
|
||||
@SerializedName(value = "forcePlace", alternate = {"force"})
|
||||
private boolean forcePlace = false;
|
||||
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
|
||||
/** The pack modules' settings this placement declares, decoded with it. */
|
||||
private transient ModuleSettings moduleSettings = ModuleSettings.NONE;
|
||||
|
||||
@@ -313,96 +297,6 @@ public class IrisObjectPlacement {
|
||||
return (int) Math.round(densityStyle.get(rng, x, z, data));
|
||||
}
|
||||
|
||||
private TableCache getCache(IrisData manager) {
|
||||
return cache.aquire(() -> {
|
||||
TableCache cache = new TableCache();
|
||||
|
||||
cache.merge(getCache(manager, getVanillaLoot(), IrisObjectPlacement::getVanillaTable));
|
||||
cache.merge(getCache(manager, getLoot(), key -> LootResources.table(manager, key)));
|
||||
|
||||
return cache;
|
||||
});
|
||||
}
|
||||
|
||||
private TableCache getCache(IrisData manager, KList<? extends IObjectLoot> list, Function<String, IrisLootTable> loader) {
|
||||
TableCache tc = new TableCache();
|
||||
|
||||
for (IObjectLoot loot : list) {
|
||||
if (loot == null || loot.getWeight() <= 0)
|
||||
continue;
|
||||
IrisLootTable table = loader.apply(loot.getName());
|
||||
if (table == null) {
|
||||
IrisLogging.warn("Couldn't find loot table " + loot.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (loot.getFilter().isEmpty()) //Table applies to all containers
|
||||
{
|
||||
tc.global.put(table, loot.getWeight());
|
||||
} else if (!loot.isExact()) //Table is meant to be by type
|
||||
{
|
||||
for (PlatformBlockState filterState : loot.getFilter(manager)) {
|
||||
BlockData filterData = (BlockData) filterState.nativeHandle();
|
||||
if (!tc.basic.containsKey(filterData.getMaterial())) {
|
||||
tc.basic.put(filterData.getMaterial(), new WeightedTables());
|
||||
}
|
||||
|
||||
tc.basic.get(filterData.getMaterial()).put(table, loot.getWeight());
|
||||
}
|
||||
} else //Filter is exact
|
||||
{
|
||||
for (PlatformBlockState filterState : loot.getFilter(manager)) {
|
||||
BlockData filterData = (BlockData) filterState.nativeHandle();
|
||||
if (!tc.exact.containsKey(filterData.getMaterial())) {
|
||||
tc.exact.put(filterData.getMaterial(), new KMap<>());
|
||||
}
|
||||
|
||||
if (!tc.exact.get(filterData.getMaterial()).containsKey(filterData)) {
|
||||
tc.exact.get(filterData.getMaterial()).put(filterData, new WeightedTables());
|
||||
}
|
||||
|
||||
tc.exact.get(filterData.getMaterial()).get(filterData).put(table, loot.getWeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
return tc;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IrisVanillaLootTable getVanillaTable(String name) {
|
||||
return Optional.ofNullable(NamespacedKey.fromString(name))
|
||||
.map(Bukkit::getLootTable)
|
||||
// Hand over the key, not the LootTable: IrisVanillaLootTable holds no Bukkit fields.
|
||||
.map(table -> new IrisVanillaLootTable(String.valueOf(table.getKey())))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the loot table that should be used for the block
|
||||
*
|
||||
* @param state The block state of the block
|
||||
* @param dataManager Iris Data Manager
|
||||
* @return The loot table it should use.
|
||||
*/
|
||||
public IrisLootTable getTable(PlatformBlockState state, IrisData dataManager, RNG rng) {
|
||||
TableCache cache = getCache(dataManager);
|
||||
BlockData data = (BlockData) state.nativeHandle();
|
||||
if (BukkitBlockResolution.isStorageChest(data)) {
|
||||
IrisLootTable picked = null;
|
||||
if (cache.exact.containsKey(data.getMaterial()) && cache.exact.get(data.getMaterial()).containsKey(data)) {
|
||||
picked = cache.exact.get(data.getMaterial()).get(data).pullRandom(rng);
|
||||
} else if (cache.basic.containsKey(data.getMaterial())) {
|
||||
picked = cache.basic.get(data.getMaterial()).pullRandom(rng);
|
||||
} else if (!cache.global.isEmpty()) {
|
||||
picked = cache.global.pullRandom(rng);
|
||||
}
|
||||
|
||||
return picked;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final class SurfaceWarpCacheKey {
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
@@ -432,41 +326,4 @@ public class IrisObjectPlacement {
|
||||
return 31 * result + Long.hashCode(seed);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TableCache {
|
||||
final transient WeightedTables global = new WeightedTables();
|
||||
final transient KMap<Material, WeightedTables> basic = new KMap<>();
|
||||
final transient KMap<Material, KMap<BlockData, WeightedTables>> exact = new KMap<>();
|
||||
|
||||
private void merge(TableCache other) {
|
||||
global.merge(other.global);
|
||||
basic.merge(other.basic, WeightedTables::merge);
|
||||
exact.merge(other.exact, (a, b) -> a.merge(b, WeightedTables::merge));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class WeightedTables {
|
||||
private final KList<WeightedTable> tables = new KList<>();
|
||||
|
||||
private void put(IrisLootTable table, int weight) {
|
||||
tables.add(new WeightedTable(table, weight));
|
||||
}
|
||||
|
||||
private IrisLootTable pullRandom(RNG rng) {
|
||||
WeightedTable picked = LootResolver.pickWeighted(tables, WeightedTable::weight, rng);
|
||||
return picked == null ? null : picked.table();
|
||||
}
|
||||
|
||||
private boolean isEmpty() {
|
||||
return tables.isEmpty();
|
||||
}
|
||||
|
||||
private WeightedTables merge(WeightedTables other) {
|
||||
tables.addAll(other.tables);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private record WeightedTable(IrisLootTable table, int weight) {
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.object.structure;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.blocks.ObjectReplace;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.engine.object.loot.IrisObjectLoot;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawBranchFailurePolicy;
|
||||
@@ -102,7 +102,7 @@ public class IrisStructure extends IrisRegistrant {
|
||||
private KList<ObjectReplace> edit = new KList<>();
|
||||
|
||||
@ArrayType(type = String.class, min = 1)
|
||||
@RegistryListResource(IrisLootTable.class)
|
||||
@RegistryListResource(LootTable.class)
|
||||
@Desc("Loot tables applied to containers placed by this structure's pieces.")
|
||||
private KList<String> loot = new KList<>();
|
||||
|
||||
|
||||
@@ -1,78 +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.engine.object.value;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.format.Form;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Snippet("duration")
|
||||
@Data
|
||||
@Desc("Represents a combined duration. Fill each property to add time into a single duration")
|
||||
public class IrisDuration {
|
||||
@Desc("Milliseconds (1000ms = 1 second)")
|
||||
private int milliseconds = 0;
|
||||
|
||||
@Desc("Minecraft Ticks (20 minecraft ticks = 1 second)")
|
||||
private int minecraftTicks = 0;
|
||||
|
||||
@Desc("Seconds (60 seconds = 1 minute)")
|
||||
private int seconds = 0;
|
||||
|
||||
@Desc("Minutes (60 minutes = 1 hour)")
|
||||
private int minutes = 0;
|
||||
|
||||
@Desc("Minecraft Hours (about 50 real seconds)")
|
||||
private int minecraftHours = 0;
|
||||
|
||||
@Desc("Hours (24 hours = 1 day)")
|
||||
private int hours = 0;
|
||||
|
||||
@Desc("Minecraft Days (1 minecraft day = 20 real minutes)")
|
||||
private int minecraftDays = 0;
|
||||
|
||||
@Desc("Minecraft Weeks (7 minecraft days = 2 real hours and 20 real minutes)")
|
||||
private int minecraftWeeks = 0;
|
||||
|
||||
@Desc("Minecraft Lunar Cycles (8 minecraft days = 2 real hours and 40 real minutes)")
|
||||
private int minecraftLunarCycles = 0;
|
||||
|
||||
@Desc("REAL (not minecraft) Days")
|
||||
private int days = 0;
|
||||
|
||||
public String toString() {
|
||||
return Form.duration((double) toMilliseconds(), 2);
|
||||
}
|
||||
|
||||
public long toMilliseconds() {
|
||||
return getMilliseconds()
|
||||
+ TimeUnit.SECONDS.toMillis(getSeconds())
|
||||
+ TimeUnit.MINUTES.toMillis(getMinutes())
|
||||
+ TimeUnit.HOURS.toMillis(getHours())
|
||||
+ TimeUnit.DAYS.toMillis(getDays())
|
||||
+ (getMinecraftTicks() * 50L)
|
||||
+ (getMinecraftHours() * 50000L)
|
||||
+ (getMinecraftDays() * 1_200_000L)
|
||||
+ (getMinecraftWeeks() * 8_400_000L)
|
||||
+ (getMinecraftLunarCycles() * 9_600_000L);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +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.engine.object.value;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.format.Form;
|
||||
import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Snippet("rate")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@Desc("Represents a count of something per time duration")
|
||||
public class IrisRate {
|
||||
@Desc("The amount of things. Leave 0 for infinite (meaning always spawn whenever)")
|
||||
private int amount = 0;
|
||||
|
||||
@Desc("The time interval. Leave blank for infinite 0 (meaning always spawn all the time)")
|
||||
private IrisDuration per = new IrisDuration();
|
||||
|
||||
public String toString() {
|
||||
return Form.f(amount) + "/" + per;
|
||||
}
|
||||
|
||||
public long getInterval() {
|
||||
long t = per.toMilliseconds() / (amount == 0 ? 1 : amount);
|
||||
return Math.abs(t <= 0 ? 1 : t);
|
||||
}
|
||||
|
||||
public ChronoLatch toChronoLatch() {
|
||||
return new ChronoLatch(getInterval());
|
||||
}
|
||||
|
||||
public boolean isInfinite() {
|
||||
return per.toMilliseconds() == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +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.engine.object.world;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import lombok.Data;
|
||||
|
||||
@Snippet("time-block")
|
||||
@Data
|
||||
@Desc("Represents a time of day (24h time, not 12h am/pm). Set both to the same number for any time. If they are both set to -1, it will always be not allowed.")
|
||||
public class IrisTimeBlock {
|
||||
@Desc("The beginning hour. Set both to the same number for any time. If they are both set to -1, it will always be not allowed.")
|
||||
private double startHour = 0;
|
||||
|
||||
@Desc("The ending hour. Set both to the same number for any time. If they are both set to -1, it will always be not allowed.")
|
||||
private double endHour = 0;
|
||||
|
||||
public boolean isWithin(PlatformWorld world) {
|
||||
return isWithin(((world.getTime() / 1000D) + 6) % 24);
|
||||
}
|
||||
|
||||
public boolean isWithin(double hour) {
|
||||
if (startHour == endHour) {
|
||||
return endHour != -1;
|
||||
}
|
||||
|
||||
if (startHour > endHour) {
|
||||
return hour >= startHour || hour <= endHour;
|
||||
}
|
||||
|
||||
return hour >= startHour && hour <= endHour;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +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.engine.object.world;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
|
||||
@Desc("Represents a weather type")
|
||||
public enum IrisWeather {
|
||||
@Desc("Represents when weather is not causing downfall")
|
||||
NONE,
|
||||
|
||||
@Desc("Represents rain or snow")
|
||||
DOWNFALL,
|
||||
|
||||
@Desc("Represents rain or snow with thunder")
|
||||
DOWNFALL_WITH_THUNDER,
|
||||
|
||||
@Desc("Any weather")
|
||||
ANY;
|
||||
|
||||
public boolean is(PlatformWorld world) {
|
||||
return switch (this) {
|
||||
case NONE -> !world.isStorming() && !world.isThundering();
|
||||
case DOWNFALL -> world.isStorming();
|
||||
case DOWNFALL_WITH_THUNDER -> world.isStorming() && world.isThundering();
|
||||
case ANY -> true;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.world.biome;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.IrisEffect;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.loot.IrisBlockDrops;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
@@ -110,21 +106,9 @@ public class IrisBiome extends IrisRegistrant implements IRare {
|
||||
@ArrayType(min = 1, type = IrisBiomeCustom.class)
|
||||
@Desc("If the biome type custom is defined, specify this")
|
||||
private KList<IrisBiomeCustom> customDerivitives;
|
||||
@Desc("Spawn Entities in this area over time. Iris will continually replenish these mobs just like vanilla does.")
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@RegistryListResource(IrisSpawner.class)
|
||||
private KList<String> entitySpawners = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisEffect.class)
|
||||
@Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play around the player even if where the effect was played is no longer in the biome the player is in.")
|
||||
private KList<IrisEffect> effects = new KList<>();
|
||||
@DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"})
|
||||
@Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.")
|
||||
private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style();
|
||||
@ArrayType(min = 1, type = IrisBlockDrops.class)
|
||||
@Desc("Define custom block drops for this biome")
|
||||
private KList<IrisBlockDrops> blockDrops = new KList<>();
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
@MinNumber(1)
|
||||
@MaxNumber(512)
|
||||
@Desc("The rarity of this biome (integer)")
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
package art.arcane.iris.engine.object.world.dimension;
|
||||
|
||||
import art.arcane.iris.engine.object.decoration.IrisImportedFeatureControl;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMap;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMapApplication;
|
||||
import art.arcane.iris.engine.object.image.IrisImageMapBinding;
|
||||
import art.arcane.iris.engine.object.loot.IrisBlockDrops;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisShapedGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
@@ -128,18 +125,9 @@ public class IrisDimension extends IrisRegistrant {
|
||||
private int debugCrossSectionsMod = 3;
|
||||
@Desc("Tree growth override settings")
|
||||
private IrisTreeSettings treeSettings = new IrisTreeSettings();
|
||||
@Desc("Spawn Entities in this dimension over time. Iris will continually replenish these mobs just like vanilla does.")
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@RegistryListResource(IrisSpawner.class)
|
||||
private KList<String> entitySpawners = new KList<>();
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
@MinNumber(0)
|
||||
@Desc("The version of this dimension. Changing this will stop users from accidentally upgrading (and breaking their worlds).")
|
||||
private int version = 1;
|
||||
@ArrayType(min = 1, type = IrisBlockDrops.class)
|
||||
@Desc("Define custom block drops for this dimension")
|
||||
private KList<IrisBlockDrops> blockDrops = new KList<>();
|
||||
@Desc("Should bedrock be generated or not.")
|
||||
private boolean bedrock = true;
|
||||
@MinNumber(0)
|
||||
|
||||
@@ -18,10 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.world.region;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.IrisEffect;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.loot.IrisBlockDrops;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootReference;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralObjects;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructurePlacement;
|
||||
@@ -76,20 +72,10 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
@Required
|
||||
@Desc("The name of the region")
|
||||
private String name = "A Region";
|
||||
@ArrayType(min = 1, type = IrisEffect.class)
|
||||
@Desc("Effects are ambient effects such as potion effects, random sounds, or even particles around each player. All of these effects are played via packets so two players won't see/hear each others effects.\nDue to performance reasons, effects will play arround the player even if where the effect was played is no longer in the biome the player is in.")
|
||||
private KList<IrisEffect> effects = new KList<>();
|
||||
@Desc("Spawn Entities in this region over time. Iris will continually replenish these mobs just like vanilla does.")
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@RegistryListResource(IrisSpawner.class)
|
||||
private KList<String> entitySpawners = new KList<>();
|
||||
@MinNumber(1)
|
||||
@MaxNumber(128)
|
||||
@Desc("The rarity of the region")
|
||||
private int rarity = 1;
|
||||
@ArrayType(min = 1, type = IrisBlockDrops.class)
|
||||
@Desc("Define custom block drops for this region")
|
||||
private KList<IrisBlockDrops> blockDrops = new KList<>();
|
||||
@ArrayType(min = 1, type = IrisObjectPlacement.class)
|
||||
@Desc("Objects define what schematics (iob files) iris will place in this region")
|
||||
private KList<IrisObjectPlacement> objects = new KList<>();
|
||||
@@ -101,8 +87,6 @@ public class IrisRegion extends IrisRegistrant implements IRare {
|
||||
@MinNumber(0)
|
||||
@Desc("The min shore height")
|
||||
private double shoreHeightMin = 1.2;
|
||||
@Desc("Reference loot tables in this area")
|
||||
private IrisLootReference loot = new IrisLootReference();
|
||||
@MinNumber(0)
|
||||
@Desc("The the max shore height")
|
||||
private double shoreHeightMax = 3.2;
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.AmbientEffect;
|
||||
import art.arcane.iris.builtin.spawn.EffectCommands;
|
||||
import art.arcane.iris.builtin.spawn.EffectSettings;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCommand;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.world.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* How {@code iris:spawn} plays the ambient effects of regions and biomes: the region's effects, then the biome's, each
|
||||
* when its interval and chance say, with every random choice made here so the host only carries them out.
|
||||
*/
|
||||
public final class AmbientEffecting implements AmbientEffects {
|
||||
@Override
|
||||
public List<Effect> due(PackWorld world, BlockPosition at) {
|
||||
Engine engine = IrisPackWorld.of(world).engine();
|
||||
EffectTimers timers = world.state(EffectTimers.class, ignored -> new EffectTimers());
|
||||
PlatformWorld platformWorld = engine.getWorld().platformWorld();
|
||||
|
||||
List<Effect> due = new ArrayList<>();
|
||||
addDue(due, effectsOf(engine.getRegion(at.x(), at.z())), timers, platformWorld);
|
||||
addDue(due, effectsOf(engine.getBiome(at.x(), at.y(), at.z())), timers, platformWorld);
|
||||
return due;
|
||||
}
|
||||
|
||||
private static List<AmbientEffect> effectsOf(IrisRegistrant owner) {
|
||||
return owner.getModuleSettings().find(EffectSettings.class).map(EffectSettings::effects).orElse(List.of());
|
||||
}
|
||||
|
||||
private static void addDue(List<Effect> due, List<AmbientEffect> effects, EffectTimers timers, PlatformWorld world) {
|
||||
for (AmbientEffect effect : effects) {
|
||||
if (timers.shouldPlayNow(effect)) {
|
||||
due.add(play(effect, world));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Effect play(AmbientEffect effect, PlatformWorld world) {
|
||||
Sound sound = effect.sound() == null ? null : soundOf(effect);
|
||||
Particles particles = effect.particleEffect() == null ? null : particlesOf(effect);
|
||||
return new Effect(sound, particles, commandsOf(effect.commandRegistry(), world), potionOf(effect));
|
||||
}
|
||||
|
||||
private static Sound soundOf(AmbientEffect effect) {
|
||||
int distance = effect.soundDistance();
|
||||
int offsetX = RNG.r.i(-distance, distance);
|
||||
int offsetY = RNG.r.i(-distance, distance);
|
||||
int offsetZ = RNG.r.i(-distance, distance);
|
||||
float pitch = (float) RNG.r.d(effect.minPitch(), effect.maxPitch());
|
||||
return new Sound(effect.sound(), offsetX, offsetY, offsetZ, (float) effect.volume(), pitch);
|
||||
}
|
||||
|
||||
private static Particles particlesOf(AmbientEffect effect) {
|
||||
double forward = RNG.r.i(effect.particleDistance()) + effect.particleAway();
|
||||
double sideways = RNG.r.d(-effect.particleDistanceWidth(), effect.particleDistanceWidth());
|
||||
double jitterX = RNG.r.d();
|
||||
double jitterZ = RNG.r.d();
|
||||
int lift = RNG.r.i(effect.particleOffset());
|
||||
double altX = randomized(effect.particleAltX(), effect.randomAltX());
|
||||
double altY = randomized(effect.particleAltY(), effect.randomAltY());
|
||||
double altZ = randomized(effect.particleAltZ(), effect.randomAltZ());
|
||||
return new Particles(effect.particleEffect(), forward, sideways, jitterX, jitterZ, lift, effect.particleCount(),
|
||||
altX, altY, altZ, effect.extra());
|
||||
}
|
||||
|
||||
private static List<Command> commandsOf(EffectCommands registry, PlatformWorld world) {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
if (registry == null) {
|
||||
return commands;
|
||||
}
|
||||
|
||||
double offsetX = commandOffset(registry.commandOffsetX(), registry.commandRandomAltX());
|
||||
double offsetY = commandOffset(registry.commandOffsetY(), registry.commandRandomAltY());
|
||||
double offsetZ = commandOffset(registry.commandOffsetZ(), registry.commandRandomAltZ());
|
||||
for (SpawnCommand command : registry.rawCommands()) {
|
||||
if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) {
|
||||
commands.add(new Command(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(),
|
||||
command.repeatDelay()), offsetX, offsetY, offsetZ));
|
||||
}
|
||||
if (registry.commandAllRandomLocations()) {
|
||||
offsetX = commandOffset(registry.commandOffsetX(), registry.commandRandomAltX());
|
||||
offsetY = commandOffset(registry.commandOffsetY(), registry.commandRandomAltY());
|
||||
offsetZ = commandOffset(registry.commandOffsetZ(), registry.commandRandomAltZ());
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
private static Potion potionOf(AmbientEffect effect) {
|
||||
if (effect.potionStrength() <= -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int shortest = Math.min(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
int longest = Math.max(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
return new Potion(effect.potionEffect(), effect.potionStrength(), RNG.r.i(shortest, longest));
|
||||
}
|
||||
|
||||
private static double commandOffset(double offset, boolean random) {
|
||||
return randomized(offset, random);
|
||||
}
|
||||
|
||||
private static double randomized(double value, boolean random) {
|
||||
return random ? RNG.r.d(-value, value) : value;
|
||||
}
|
||||
}
|
||||
@@ -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.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.AmbientEffect;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.ChronoLatch;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* When the effects of a world play: an effect plays at most once per interval, and then only with its chance. The timers
|
||||
* are the world's, shared by every player, like the effects themselves.
|
||||
*/
|
||||
final class EffectTimers {
|
||||
private final ConcurrentMap<AmbientEffect, ChronoLatch> latches = new ConcurrentHashMap<>();
|
||||
|
||||
/** Whether {@code effect} plays now; asking starts its interval over when it has elapsed. */
|
||||
boolean shouldPlayNow(AmbientEffect effect) {
|
||||
ChronoLatch latch = latches.computeIfAbsent(effect, key -> new ChronoLatch(key.interval()));
|
||||
return latch.flip() && RNG.r.nextInt(effect.chance()) == 0;
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.loot.ItemAttributeModifier;
|
||||
import art.arcane.iris.builtin.loot.LootEntry;
|
||||
import art.arcane.iris.builtin.spawn.AmbientEffect;
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCommand;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.engine.object.entity.IrisAttributeModifier;
|
||||
import art.arcane.iris.engine.object.entity.IrisEffect;
|
||||
import art.arcane.iris.engine.object.entity.IrisEntity;
|
||||
import art.arcane.iris.engine.object.loot.IrisLoot;
|
||||
import art.arcane.iris.engine.object.marker.IrisCommand;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
@@ -44,83 +44,85 @@ final class EntityResolution {
|
||||
|
||||
private final LootItems items;
|
||||
private final PlatformWorld world;
|
||||
private final EffectTimers timers;
|
||||
|
||||
/** @param world the world the entity appears in, whose time and weather decide which of its commands run */
|
||||
EntityResolution(LootItems items, PlatformWorld world) {
|
||||
EntityResolution(LootItems items, PlatformWorld world, EffectTimers timers) {
|
||||
this.items = items;
|
||||
this.world = world;
|
||||
this.timers = timers;
|
||||
}
|
||||
|
||||
EntitySpec resolve(IrisEntity entity, RNG rng) {
|
||||
EntitySpec resolve(EntityDefinition entity, RNG rng) {
|
||||
List<EntitySpec> passengers = new ArrayList<>();
|
||||
long passengerIndex = 0;
|
||||
for (IrisEntity passenger : entity.getPassengers()) {
|
||||
for (EntityDefinition passenger : entity.passengers()) {
|
||||
passengers.add(resolve(passenger, rng.nextParallelRNG(PASSENGER_STREAM_BASE + passengerIndex++)));
|
||||
}
|
||||
|
||||
List<ItemAttribute> attributes = drawAttributes(entity, rng);
|
||||
List<String> lootTables = List.copyOf(entity.getLoot().getTables());
|
||||
List<String> lootTables = List.copyOf(entity.loot().tables());
|
||||
long lootShuffleSeed = lootTables.isEmpty() ? 0L : rng.nextLong();
|
||||
EntitySpec leashHolder = entity.getLeashHolder() == null ? null : resolve(entity.getLeashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM));
|
||||
EntitySpec leashHolder = entity.leashHolder() == null ? null : resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM));
|
||||
EntitySpec.Equipment equipment = new EntitySpec.Equipment(
|
||||
equip(entity.getHelmet(), rng), equip(entity.getChestplate(), rng), equip(entity.getLeggings(), rng),
|
||||
equip(entity.getBoots(), rng), equip(entity.getMainHand(), rng), equip(entity.getOffHand(), rng));
|
||||
equip(entity.helmet(), rng), equip(entity.chestplate(), rng), equip(entity.leggings(), rng),
|
||||
equip(entity.boots(), rng), equip(entity.mainHand(), rng), equip(entity.offHand(), rng));
|
||||
|
||||
return new EntitySpec(
|
||||
entity.getType() == null ? "" : entity.getType(),
|
||||
entity.getSpecialType() == null ? "" : entity.getSpecialType(),
|
||||
entity.getReason(),
|
||||
entity.getCustomName() == null ? "" : entity.getCustomName(),
|
||||
entity.type() == null ? "" : entity.type(),
|
||||
entity.specialType() == null ? "" : entity.specialType(),
|
||||
entity.reason(),
|
||||
entity.customName() == null ? "" : entity.customName(),
|
||||
flagsOf(entity), equipment, passengers, attributes, lootTables, lootShuffleSeed, leashHolder,
|
||||
spawnEffectOf(entity), entity.isSpawnEffectRiseOutOfGround(), entity.getPandaMainGene(),
|
||||
entity.getPandaHiddenGene(), entity.isApplySettingsToCustomMobAnyways(), commandsOf(entity));
|
||||
spawnEffectOf(entity), entity.spawnEffectRiseOutOfGround(), entity.pandaMainGene(),
|
||||
entity.pandaHiddenGene(), entity.applySettingsToCustomMobAnyways(), commandsOf(entity));
|
||||
}
|
||||
|
||||
private static EntitySpec.Flags flagsOf(IrisEntity entity) {
|
||||
return new EntitySpec.Flags(entity.isCustomNameVisible(), entity.isAware(), entity.isAi(), entity.isGlowing(),
|
||||
entity.isGravity(), entity.isInvulnerable(), entity.isSilent(), entity.isPickupItems(), entity.isRemovable(),
|
||||
entity.isKeepEntity(), entity.isBaby());
|
||||
private static EntitySpec.Flags flagsOf(EntityDefinition entity) {
|
||||
return new EntitySpec.Flags(entity.customNameVisible(), entity.aware(), entity.ai(), entity.glowing(),
|
||||
entity.gravity(), entity.invulnerable(), entity.silent(), entity.pickupItems(), entity.removable(),
|
||||
entity.keepEntity(), entity.baby());
|
||||
}
|
||||
|
||||
private static List<ItemAttribute> drawAttributes(IrisEntity entity, RNG rng) {
|
||||
private static List<ItemAttribute> drawAttributes(EntityDefinition entity, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (IrisAttributeModifier modifier : entity.getAttributes()) {
|
||||
if (rng.nextDouble() >= modifier.getChance()) {
|
||||
for (ItemAttributeModifier modifier : entity.attributes()) {
|
||||
if (rng.nextDouble() >= modifier.chance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.getAttribute();
|
||||
String attribute = modifier.attribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
attributes.add(new ItemAttribute(attribute, modifier.getName(), modifier.getOperation(), modifier.getAmount(rng)));
|
||||
attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount())));
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private ItemDrop equip(IrisLoot piece, RNG rng) {
|
||||
if (piece == null || !LootResolver.oneIn(rng, piece.getRarity())) {
|
||||
private ItemDrop equip(LootEntry piece, RNG rng) {
|
||||
if (piece == null || !LootResolver.oneIn(rng, piece.rarity())) {
|
||||
return null;
|
||||
}
|
||||
return items.give(piece, rng);
|
||||
}
|
||||
|
||||
/** The entity's spawn effect when it shows this time: an effect only shows now and then, as its interval and chance say. */
|
||||
private static EntitySpec.SpawnEffect spawnEffectOf(IrisEntity entity) {
|
||||
IrisEffect effect = entity.getSpawnEffect();
|
||||
if (effect == null || !effect.shouldApplyNow()) {
|
||||
private EntitySpec.SpawnEffect spawnEffectOf(EntityDefinition entity) {
|
||||
AmbientEffect effect = entity.spawnEffect();
|
||||
if (effect == null || !timers.shouldPlayNow(effect)) {
|
||||
return null;
|
||||
}
|
||||
return new EntitySpec.SpawnEffect(effect.getSoundKey(), effect.getSoundDistance(), effect.getMinPitch(),
|
||||
effect.getMaxPitch(), effect.getVolume(), effect.getParticleEffectKey(), effect.getParticleOffset(),
|
||||
effect.getParticleCount(), effect.getParticleAltX(), effect.getParticleAltY(), effect.getParticleAltZ(),
|
||||
effect.isRandomAltX(), effect.isRandomAltY(), effect.isRandomAltZ(), effect.getExtra());
|
||||
return new EntitySpec.SpawnEffect(effect.sound(), effect.soundDistance(), effect.minPitch(),
|
||||
effect.maxPitch(), effect.volume(), effect.particleEffect(), effect.particleOffset(),
|
||||
effect.particleCount(), effect.particleAltX(), effect.particleAltY(), effect.particleAltZ(),
|
||||
effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra());
|
||||
}
|
||||
|
||||
private List<EntitySpec.Command> commandsOf(IrisEntity entity) {
|
||||
private List<EntitySpec.Command> commandsOf(EntityDefinition entity) {
|
||||
List<EntitySpec.Command> commands = new ArrayList<>();
|
||||
for (IrisCommand command : entity.getRawCommands()) {
|
||||
if (command.isValid(world)) {
|
||||
commands.add(new EntitySpec.Command(command.getCommands(), command.getDelay(), command.isRepeat(), command.getRepeatDelay()));
|
||||
for (SpawnCommand command : entity.rawCommands()) {
|
||||
if (SpawnConditions.allow(command.timeBlock(), command.weather(), world)) {
|
||||
commands.add(new EntitySpec.Command(command.commands(), command.delay(), command.repeat(), command.repeatDelay()));
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
|
||||
@@ -18,26 +18,29 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.EntitySpawn;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.builtin.spawn.SpawnSurface;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.builtin.spawn.SpawnerSettings;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.LootResolver;
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.engine.object.entity.IrisEntity;
|
||||
import art.arcane.iris.engine.object.entity.IrisEntitySpawn;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSurface;
|
||||
import art.arcane.iris.engine.object.marker.IrisMarker;
|
||||
import art.arcane.iris.engine.object.value.IRare;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.value.IrisRange;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.spawn.SpawnResources.KeyedSpawner;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
import com.volmit.world.BlockPosition;
|
||||
@@ -76,15 +79,15 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
if (count <= 0) {
|
||||
return;
|
||||
}
|
||||
IrisSpawner spawner = SpawnResources.spawner(engine(world).getData(), plan.spawner());
|
||||
Spawner spawner = SpawnResources.spawner(engine(world).getData(), plan.spawner());
|
||||
if (spawner != null) {
|
||||
spawner.spawn(engine(world), plan.chunkX(), plan.chunkZ());
|
||||
SpawnerGate.spawned(plan.spawner(), spawner, engine(world), plan.chunkX(), plan.chunkZ());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EntitySpec> entity(PackWorld world, String key) {
|
||||
IrisEntity entity = SpawnResources.entity(engine(world).getData(), key);
|
||||
EntityDefinition entity = SpawnResources.entity(engine(world).getData(), key);
|
||||
if (entity == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -97,40 +100,40 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
return Optional.empty();
|
||||
}
|
||||
Engine engine = engine(world);
|
||||
IrisMarker marker = SpawnResources.marker(engine.getData(), tag);
|
||||
SpawnMarker marker = SpawnResources.marker(engine.getData(), tag);
|
||||
if (marker == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<String> spawners = new ArrayList<>();
|
||||
for (String key : marker.getSpawners()) {
|
||||
for (String key : marker.spawners()) {
|
||||
if (SpawnResources.spawner(engine.getData(), key) == null) {
|
||||
IrisLogging.error("Cannot load spawner: " + key + " for marker " + tag);
|
||||
continue;
|
||||
}
|
||||
spawners.add(key);
|
||||
}
|
||||
return Optional.of(new MarkerRule(spawners, marker.isEmptyAbove(), marker.isRemoveOnChange()));
|
||||
return Optional.of(new MarkerRule(spawners, marker.emptyAbove(), marker.removeOnChange()));
|
||||
}
|
||||
|
||||
private Optional<Plan> planChunk(PackWorld world, Engine engine, Chunk chunk) {
|
||||
Predicate<IrisSpawner> canSpawn = spawner -> spawner.canSpawn(engine, chunk.chunkX(), chunk.chunkZ());
|
||||
Predicate<KeyedSpawner> canSpawn = keyed -> SpawnerGate.canSpawn(keyed.key(), keyed.spawner(), engine, chunk.chunkX(), chunk.chunkZ());
|
||||
int blockX = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkX());
|
||||
int blockZ = PowerOfTwoCoordinates.chunkToBlock(chunk.chunkZ());
|
||||
IrisBiome centreBiome = engine.getSurfaceBiome(blockX + BLOCKS_TO_CHUNK_CENTRE, blockZ + BLOCKS_TO_CHUNK_CENTRE);
|
||||
IrisRegion region = engine.getRegion(blockX, blockZ);
|
||||
IrisBiome biome = engine.getSurfaceBiome(blockX, blockZ);
|
||||
|
||||
List<IrisSpawner> candidates = Stream.concat(
|
||||
shuffled(engine, engine.getDimension().getEntitySpawners()).stream()
|
||||
.filter(canSpawn).filter(spawner -> spawner.isValid(centreBiome)),
|
||||
List<KeyedSpawner> candidates = Stream.concat(
|
||||
shuffled(engine, engine.getDimension()).stream()
|
||||
.filter(canSpawn).filter(keyed -> SpawnerGate.suits(keyed.spawner(), centreBiome)),
|
||||
Stream.concat(
|
||||
shuffled(engine, region.getEntitySpawners()).stream().filter(canSpawn),
|
||||
shuffled(engine, biome.getEntitySpawners()).stream().filter(canSpawn)))
|
||||
.filter(spawner -> chunk.livingEntities() < spawner.getMaxEntitiesPerChunk())
|
||||
shuffled(engine, region).stream().filter(canSpawn),
|
||||
shuffled(engine, biome).stream().filter(canSpawn)))
|
||||
.filter(keyed -> chunk.livingEntities() < keyed.spawner().maxEntitiesPerChunk())
|
||||
.toList();
|
||||
|
||||
List<Candidate> spawns = candidates.stream().flatMap(spawner -> spawnsOf(spawner, chunk.initial())).collect(Collectors.toList());
|
||||
List<Candidate> spawns = candidates.stream().flatMap(keyed -> spawnsOf(keyed, chunk.initial())).collect(Collectors.toList());
|
||||
Candidate chosen = IRare.expandWeighted(spawns).getRandom();
|
||||
if (chosen == null) {
|
||||
return Optional.empty();
|
||||
@@ -139,26 +142,25 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
}
|
||||
|
||||
private Optional<Plan> planChunkSpawn(PackWorld world, Engine engine, Chunk chunk, Candidate chosen) {
|
||||
IrisSpawner spawner = chosen.spawner();
|
||||
IrisEntitySpawn spawn = chosen.spawn();
|
||||
int count = LootResolver.inclusive(RNG.r, spawn.getMinSpawns(), spawn.getMaxSpawns());
|
||||
EntitySpawn spawn = chosen.spawn();
|
||||
int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns());
|
||||
List<Attempt> attempts = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
int x = (chunk.chunkX() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
|
||||
int z = (chunk.chunkZ() * CHUNK_SIZE) + RNG.r.i(CHUNK_SIZE);
|
||||
BlockPosition at = spawnPosition(engine, spawner, chunk.chunkX(), chunk.chunkZ(), x, z);
|
||||
BlockPosition at = spawnPosition(engine, chosen.spawner(), chunk.chunkX(), chunk.chunkZ(), x, z);
|
||||
if (at != null) {
|
||||
addAttempt(attempts, world, engine, chosen, at, true);
|
||||
}
|
||||
}
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(spawner.getLoadKey(), chunk.chunkX(), chunk.chunkZ(), false, attempts));
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(chosen.key(), chunk.chunkX(), chunk.chunkZ(), false, attempts));
|
||||
}
|
||||
|
||||
/** Where a spawner of its group puts an entity at the column; null when it has no place for one. */
|
||||
private static BlockPosition spawnPosition(Engine engine, IrisSpawner spawner, int chunkX, int chunkZ, int x, int z) {
|
||||
private static BlockPosition spawnPosition(Engine engine, Spawner spawner, int chunkX, int chunkZ, int x, int z) {
|
||||
int height = engine.getHeight(x, z, true);
|
||||
int heightWithFluid = engine.getHeight(x, z, false);
|
||||
return switch (spawner.getGroup()) {
|
||||
return switch (spawner.group()) {
|
||||
case NORMAL -> new BlockPosition(x, heightWithFluid + 1, z);
|
||||
case CAVE -> caveSpawnPosition(engine, chunkX, chunkZ);
|
||||
case UNDERWATER, BEACH -> new BlockPosition(x, RNG.r.i(height + 1, heightWithFluid), z);
|
||||
@@ -175,78 +177,92 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
}
|
||||
|
||||
private Optional<Plan> planMarker(PackWorld world, Engine engine, Marker marker) {
|
||||
IrisSpawner spawner = SpawnResources.spawner(engine.getData(), marker.spawner());
|
||||
IrisMarker irisMarker = SpawnResources.marker(engine.getData(), marker.marker());
|
||||
Spawner spawner = SpawnResources.spawner(engine.getData(), marker.spawner());
|
||||
SpawnMarker spawnMarker = SpawnResources.marker(engine.getData(), marker.marker());
|
||||
if (spawner == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
KList<IrisEntitySpawn> candidates = marker.initial() ? spawner.getInitialSpawns() : spawner.getSpawns();
|
||||
List<EntitySpawn> candidates = marker.initial() ? spawner.initialSpawns() : spawner.spawns();
|
||||
if (candidates.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
IrisEntitySpawn spawn = IRare.expandWeighted(candidates).getRandom();
|
||||
EntitySpawn spawn = IRare.expandWeighted(candidates.stream().map(RareSpawn::new).toList()).getRandom().spawn();
|
||||
|
||||
BlockPosition position = marker.position();
|
||||
int chunkX = PowerOfTwoCoordinates.blockToChunkFloor(position.x());
|
||||
int chunkZ = PowerOfTwoCoordinates.blockToChunkFloor(position.z());
|
||||
if (!spawner.canSpawn(engine, chunkX, chunkZ)) {
|
||||
if (!SpawnerGate.canSpawn(marker.spawner(), spawner, engine, chunkX, chunkZ)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
int count = LootResolver.inclusive(RNG.r, spawn.getMinSpawns(), spawn.getMaxSpawns());
|
||||
int count = LootResolver.inclusive(RNG.r, spawn.minSpawns(), spawn.maxSpawns());
|
||||
if (count <= 0) {
|
||||
return Optional.empty();
|
||||
}
|
||||
boolean exhaustsMarker = irisMarker != null && irisMarker.shouldExhaust();
|
||||
boolean exhaustsMarker = spawnMarker != null && shouldExhaust(spawnMarker);
|
||||
List<Attempt> attempts = new ArrayList<>();
|
||||
BlockPosition above = new BlockPosition(position.x(), position.y() + AIR_ABOVE_MARKER, position.z());
|
||||
for (int i = 0; i < count; i++) {
|
||||
addAttempt(attempts, world, engine, new Candidate(spawner, spawn), above, false);
|
||||
addAttempt(attempts, world, engine, new Candidate(marker.spawner(), spawner, spawn), above, false);
|
||||
}
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(spawner.getLoadKey(), chunkX, chunkZ, exhaustsMarker, attempts));
|
||||
return attempts.isEmpty() ? Optional.empty() : Optional.of(new Plan(marker.spawner(), chunkX, chunkZ, exhaustsMarker, attempts));
|
||||
}
|
||||
|
||||
private static boolean shouldExhaust(SpawnMarker marker) {
|
||||
return marker.exhaustionChance() > RNG.r.nextDouble();
|
||||
}
|
||||
|
||||
private void addAttempt(List<Attempt> attempts, PackWorld world, Engine engine, Candidate candidate, BlockPosition at, boolean checkSurface) {
|
||||
IrisEntity entity = candidate.spawn().getRealEntity(engine);
|
||||
EntityDefinition entity = SpawnResources.entity(engine.getData(), candidate.spawn().entity());
|
||||
if (entity == null) {
|
||||
IrisLogging.debug(" You are trying to spawn an entity that does not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
IrisRange light = candidate.spawner().getAllowedLightLevels();
|
||||
Range light = candidate.spawner().allowedLightLevels();
|
||||
EntitySpec spec = resolution(world, engine).resolve(entity, entityRandom(world).rng());
|
||||
attempts.add(new Attempt(at, spec, surfaceOf(entity.getSurface()),
|
||||
(int) Math.ceil(light.getMin()), (int) Math.floor(light.getMax()), checkSurface));
|
||||
attempts.add(new Attempt(at, spec, surfaceOf(entity.surface()),
|
||||
(int) Math.ceil(light.min()), (int) Math.floor(light.max()), checkSurface));
|
||||
}
|
||||
|
||||
private static EntityResolution resolution(PackWorld world, Engine engine) {
|
||||
LootItems items = new LootItems(world.resources().items(), engine.isStudio());
|
||||
return new EntityResolution(items, engine.getWorld().platformWorld());
|
||||
return new EntityResolution(items, engine.getWorld().platformWorld(), world.state(EffectTimers.class, ignored -> new EffectTimers()));
|
||||
}
|
||||
|
||||
private static EntityRandom entityRandom(PackWorld world) {
|
||||
return world.state(EntityRandom.class, EntityRandom::new);
|
||||
}
|
||||
|
||||
private static Surface surfaceOf(IrisSurface surface) {
|
||||
private static Surface surfaceOf(SpawnSurface surface) {
|
||||
return Surface.valueOf(surface.name());
|
||||
}
|
||||
|
||||
private static KList<IrisSpawner> shuffled(Engine engine, KList<String> keys) {
|
||||
return SpawnResources.spawners(engine.getData(), keys).shuffleCopy(RNG.r);
|
||||
/** The spawners an area lists, in a random order. */
|
||||
private static List<KeyedSpawner> shuffled(Engine engine, IrisRegistrant owner) {
|
||||
List<String> keys = owner.getModuleSettings().find(SpawnerSettings.class).map(SpawnerSettings::spawners).orElse(List.of());
|
||||
return new KList<>(SpawnResources.spawners(engine.getData(), keys)).shuffleCopy(RNG.r);
|
||||
}
|
||||
|
||||
private static Stream<Candidate> spawnsOf(IrisSpawner spawner, boolean initial) {
|
||||
KList<IrisEntitySpawn> spawns = initial ? spawner.getInitialSpawns() : spawner.getSpawns();
|
||||
return spawns.stream().map(spawn -> new Candidate(spawner, spawn));
|
||||
private static Stream<Candidate> spawnsOf(KeyedSpawner keyed, boolean initial) {
|
||||
List<EntitySpawn> spawns = initial ? keyed.spawner().initialSpawns() : keyed.spawner().spawns();
|
||||
return spawns.stream().map(spawn -> new Candidate(keyed.key(), keyed.spawner(), spawn));
|
||||
}
|
||||
|
||||
/** A spawn of a spawner, which picks as often as the spawn's rarity says. */
|
||||
private record Candidate(IrisSpawner spawner, IrisEntitySpawn spawn) implements IRare {
|
||||
private record Candidate(String key, Spawner spawner, EntitySpawn spawn) implements IRare {
|
||||
@Override
|
||||
public int getRarity() {
|
||||
return spawn.getRarity();
|
||||
return spawn.rarity();
|
||||
}
|
||||
}
|
||||
|
||||
/** A spawn that picks as often as its rarity says. */
|
||||
private record RareSpawn(EntitySpawn spawn) implements IRare {
|
||||
@Override
|
||||
public int getRarity() {
|
||||
return spawn.rarity();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.SpawnTimeBlock;
|
||||
import art.arcane.iris.builtin.spawn.SpawnWeather;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
|
||||
/** The time of day and the weather a command or spawner of the pack asks for, checked against a world. */
|
||||
final class SpawnConditions {
|
||||
private static final double TICKS_PER_HOUR = 1000D;
|
||||
private static final double HOURS_AT_TIME_ZERO = 6;
|
||||
private static final double HOURS_PER_DAY = 24;
|
||||
|
||||
private SpawnConditions() {
|
||||
}
|
||||
|
||||
static boolean allow(SpawnTimeBlock time, SpawnWeather weather, PlatformWorld world) {
|
||||
return time.contains(hourOf(world)) && weather.matches(world.isStorming(), world.isThundering());
|
||||
}
|
||||
|
||||
/** The world's time of day as a clock hour: tick 0 is 6 in the morning. */
|
||||
static double hourOf(PlatformWorld world) {
|
||||
return ((world.getTime() / TICKS_PER_HOUR) + HOURS_AT_TIME_ZERO) % HOURS_PER_DAY;
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,21 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.EffectSettings;
|
||||
import art.arcane.iris.builtin.spawn.SpawnerSettings;
|
||||
import com.volmit.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
/**
|
||||
* Module {@code iris:spawn}: the spawners, entities and markers of the pack ({@link SpawnResources}), and the entities that appear in the world
|
||||
* over time because of them. It has no generation stage; Iris asks it through {@link EntitySpawns} when it looks for
|
||||
* something to spawn in a chunk or at a marker.
|
||||
* Module {@code iris:spawn}: the spawners, entities and markers of the pack ({@link SpawnResources}), the
|
||||
* {@link SpawnerSettings} that dimensions, regions and biomes list, the entities that appear in the world over time
|
||||
* because of them, and the ambient effects ({@link EffectSettings}) that play around players. It has no generation
|
||||
* stage; Iris asks it through {@link EntitySpawns} when it looks for something to spawn in a chunk or at a marker, and
|
||||
* through {@link AmbientEffects} for the effects due around a player.
|
||||
*/
|
||||
public final class SpawnModule implements IrisModule {
|
||||
private static final String VERSION = "built-in";
|
||||
@@ -43,7 +48,10 @@ public final class SpawnModule implements IrisModule {
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerSettings(SpawnerSettings.class);
|
||||
registry.registerSettings(EffectSettings.class);
|
||||
SpawnResources.kinds().forEach(registry::registerResourceKind);
|
||||
registry.registerService(EntitySpawns.class, new EntitySpawning());
|
||||
registry.registerService(AmbientEffects.class, new AmbientEffecting());
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,15 @@
|
||||
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.EntityDefinition;
|
||||
import art.arcane.iris.builtin.spawn.SpawnMarker;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.object.entity.IrisEntity;
|
||||
import art.arcane.iris.engine.object.entity.spawn.IrisSpawner;
|
||||
import art.arcane.iris.engine.object.marker.IrisMarker;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -39,39 +39,43 @@ import java.util.List;
|
||||
*/
|
||||
public final class SpawnResources {
|
||||
/** Spawners, in {@code spawners/}. */
|
||||
public static final ResourceKind<IrisSpawner> SPAWNERS = ResourceKind.of("iris:spawn/spawner", "spawners", IrisSpawner.class);
|
||||
public static final ResourceKind<Spawner> SPAWNERS = ResourceKind.of("iris:spawn/spawner", "spawners", Spawner.class);
|
||||
/** Entities, in {@code entities/}. */
|
||||
public static final ResourceKind<IrisEntity> ENTITIES = ResourceKind.of("iris:spawn/entity", "entities", IrisEntity.class);
|
||||
public static final ResourceKind<EntityDefinition> ENTITIES = ResourceKind.of("iris:spawn/entity", "entities", EntityDefinition.class);
|
||||
/** Markers, in {@code markers/}. */
|
||||
public static final ResourceKind<IrisMarker> MARKERS = ResourceKind.of("iris:spawn/marker", "markers", IrisMarker.class);
|
||||
public static final ResourceKind<SpawnMarker> MARKERS = ResourceKind.of("iris:spawn/marker", "markers", SpawnMarker.class);
|
||||
|
||||
private SpawnResources() {
|
||||
}
|
||||
|
||||
/** A spawner and the key the pack names it by. */
|
||||
public record KeyedSpawner(String key, Spawner spawner) {
|
||||
}
|
||||
|
||||
/** Every resource kind of the spawn module. */
|
||||
public static List<ResourceKind<?>> kinds() {
|
||||
return List.of(SPAWNERS, ENTITIES, MARKERS);
|
||||
}
|
||||
|
||||
public static IrisSpawner spawner(IrisData data, String key) {
|
||||
public static Spawner spawner(IrisData data, String key) {
|
||||
return find(data, SPAWNERS, key);
|
||||
}
|
||||
|
||||
public static IrisEntity entity(IrisData data, String key) {
|
||||
public static EntityDefinition entity(IrisData data, String key) {
|
||||
return find(data, ENTITIES, key);
|
||||
}
|
||||
|
||||
public static IrisMarker marker(IrisData data, String key) {
|
||||
public static SpawnMarker marker(IrisData data, String key) {
|
||||
return find(data, MARKERS, key);
|
||||
}
|
||||
|
||||
/** The spawners of the pack named by {@code keys}, in order, without the ones the pack lacks. */
|
||||
public static KList<IrisSpawner> spawners(IrisData data, List<String> keys) {
|
||||
KList<IrisSpawner> spawners = new KList<>();
|
||||
public static List<KeyedSpawner> spawners(IrisData data, List<String> keys) {
|
||||
List<KeyedSpawner> spawners = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
IrisSpawner spawner = spawner(data, key);
|
||||
Spawner spawner = spawner(data, key);
|
||||
if (spawner != null) {
|
||||
spawners.add(spawner);
|
||||
spawners.add(new KeyedSpawner(key, spawner));
|
||||
}
|
||||
}
|
||||
return spawners;
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.SpawnRate;
|
||||
import art.arcane.iris.builtin.spawn.Spawner;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.spi.PlatformWorld;
|
||||
|
||||
/**
|
||||
* Whether a spawner may fire: in a biome of the kind its group wants, in the time and weather it asks for, and not
|
||||
* more often than its rates allow. The rates count in the engine's persisted data, by the key the pack names the
|
||||
* spawner by.
|
||||
*/
|
||||
final class SpawnerGate {
|
||||
private SpawnerGate() {
|
||||
}
|
||||
|
||||
/** Whether a spawner of this group fires in {@code biome}. */
|
||||
static boolean suits(Spawner spawner, IrisBiome biome) {
|
||||
return switch (spawner.group()) {
|
||||
case NORMAL -> switch (biome.getInferredType()) {
|
||||
case SHORE, SEA, CAVE -> false;
|
||||
case LAND -> true;
|
||||
};
|
||||
case CAVE -> true;
|
||||
case UNDERWATER -> switch (biome.getInferredType()) {
|
||||
case SHORE, LAND, CAVE -> false;
|
||||
case SEA -> true;
|
||||
};
|
||||
case BEACH -> switch (biome.getInferredType()) {
|
||||
case SHORE -> true;
|
||||
case LAND, CAVE, SEA -> false;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Whether the world is in the time and weather the spawner asks for. */
|
||||
static boolean suits(Spawner spawner, PlatformWorld world) {
|
||||
return SpawnConditions.allow(spawner.timeBlock(), spawner.weather(), world);
|
||||
}
|
||||
|
||||
/** Whether the spawner may fire in the chunk now. */
|
||||
static boolean canSpawn(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) {
|
||||
if (!canSpawn(key, spawner, engine)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnRate rate = spawner.maximumRatePerChunk();
|
||||
return rate.isInfinite() || engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).canSpawn(rate.interval());
|
||||
}
|
||||
|
||||
/** Counts a spawn of the spawner in the chunk against its rates. */
|
||||
static void spawned(String key, Spawner spawner, Engine engine, int chunkX, int chunkZ) {
|
||||
spawned(key, spawner, engine);
|
||||
if (spawner.maximumRatePerChunk().isInfinite()) {
|
||||
return;
|
||||
}
|
||||
|
||||
engine.getEngineData().getChunk(chunkX, chunkZ).getCooldown(key).spawn();
|
||||
}
|
||||
|
||||
private static boolean canSpawn(String key, Spawner spawner, Engine engine) {
|
||||
PlatformWorld world = engine.getWorld().platformWorld();
|
||||
if (world == null || !suits(spawner, world)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpawnRate rate = spawner.maximumRate();
|
||||
return rate.isInfinite() || engine.getEngineData().getCooldown(key).canSpawn(rate.interval());
|
||||
}
|
||||
|
||||
private static void spawned(String key, Spawner spawner, Engine engine) {
|
||||
if (spawner.maximumRate().isInfinite()) {
|
||||
return;
|
||||
}
|
||||
|
||||
engine.getEngineData().getCooldown(key).spawn();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user