mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Hand the API typed keys and grouped item and entity values
Batch 6, findings 41 and 42. - PlatformKeys turns pack keys into ResourceIds and ContentKeys, dropping a key that cannot be one with a warning once; random draws keep their order, so loot and entities stay the same. - Loot items and entities build the grouped ItemDrop and EntitySpec; Iris-only entity knobs travel as the IrisEntityExtras extension. - Settings name pack resources with @Ref(kind = ...); Iris structure-model keys use the Iris extension @IrisStructureRef. - Markers, sapling species and the upper dimension are ids.
This commit is contained in:
1 parent
32703269a3
commit
06b3f10220
23 files changed
+370
-131
No files matched your search
@@ -24,7 +24,7 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.LinkedBiomes;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.util.Set;
|
||||
@Desc("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.")
|
||||
@Feature(id = "iris:carve/biome", name = "Carving biome", key = "carvingBiome", root = "biome", targets = Level.BIOME)
|
||||
public final class CarvingBiomeSettings implements IrisFeature, LinkedBiomes {
|
||||
@Ref(Reference.PACK_BIOME)
|
||||
@Ref(kind = PackBiome.class)
|
||||
@Desc("Registers the referenced biome with this pack's reachable biome set. It is NOT applied as a substitute under carvings; cave biomes come from the region's caveBiomes list.")
|
||||
private String biome = "";
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.builtin.carve;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class CarvingEntry {
|
||||
@Desc("Enable or disable this carving entry")
|
||||
private boolean enabled = true;
|
||||
|
||||
@Ref(Reference.PACK_BIOME)
|
||||
@Ref(kind = PackBiome.class)
|
||||
@Desc("Cave biome to apply when world Y falls within worldYRange")
|
||||
private String biome = "";
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.world.PackBiome;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -51,7 +52,7 @@ public final class FloatingChildBiome {
|
||||
private static final NoiseStyle DEFAULT_EDGE_TAPER_VARIATION_STYLE = NoiseStyle.of("SIMPLEX").withZoom(0.18D);
|
||||
private static final NoiseStyle DEFAULT_FOOTPRINT_STYLE = NoiseStyle.of("SIMPLEX");
|
||||
|
||||
@Ref(Reference.PACK_BIOME)
|
||||
@Ref(kind = PackBiome.class)
|
||||
@Desc("The target biome whose visual design (layers, palette, decorators, surface objects, derivative, and — when topShapeMode=BIOME — generator profile) drives the floating island. Leave empty to reuse the parent biome (self).")
|
||||
private String biome = "";
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -44,7 +44,7 @@ public final class LootSettings implements IrisFeature {
|
||||
@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 LootMode mode = LootMode.ADD;
|
||||
|
||||
@ResourceRef(LootTable.class)
|
||||
@Ref(kind = LootTable.class)
|
||||
@Desc("Add loot table registries here")
|
||||
private List<String> tables = List.of();
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.volmit.config.Desc;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -39,7 +39,7 @@ public final class ObjectLoot implements ObjectLootEntry {
|
||||
private boolean exact = false;
|
||||
@Desc("The loot table name")
|
||||
@Required
|
||||
@ResourceRef(LootTable.class)
|
||||
@Ref(kind = LootTable.class)
|
||||
private String name;
|
||||
@Desc("The weight of this loot table being chosen")
|
||||
@MinNumber(1)
|
||||
|
||||
@@ -45,11 +45,11 @@ import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.config.Snippet;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.noise.StyledRange;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -71,7 +71,7 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
|
||||
@Required
|
||||
@MinItems(1)
|
||||
@Ref(Reference.PACK_OBJECT)
|
||||
@Ref(kind = GeneratedObject.class)
|
||||
@Desc("List of objects to place")
|
||||
private List<String> place = List.of();
|
||||
@Desc("Rotate this objects placement")
|
||||
@@ -168,11 +168,11 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
@Desc("This object / these objects override the following trees when they grow...")
|
||||
private List<TreeOverride> trees = List.of();
|
||||
@MinItems(1)
|
||||
@Ref(Reference.PACK_OBJECT)
|
||||
@Ref(kind = GeneratedObject.class)
|
||||
@Desc("List of objects to this object is allowed to collied with")
|
||||
private List<String> allowedCollisions = List.of();
|
||||
@MinItems(1)
|
||||
@Ref(Reference.PACK_OBJECT)
|
||||
@Ref(kind = GeneratedObject.class)
|
||||
@Desc("List of objects to this object is forbidden to collied with")
|
||||
private List<String> forbiddenCollisions = List.of();
|
||||
@Desc("Ignore any placement restrictions for this object")
|
||||
|
||||
@@ -21,13 +21,13 @@ package art.arcane.iris.builtin.spawn;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
@Snippet("entity-spawn")
|
||||
@Desc("Represents an entity spawn during initial chunk generation")
|
||||
public final class EntitySpawn {
|
||||
@ResourceRef(EntityDefinition.class)
|
||||
@Ref(kind = EntityDefinition.class)
|
||||
@Required
|
||||
@Desc("The entity")
|
||||
private String entity = "";
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.builtin.spawn;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Iris extension of an {@link com.volmit.entity.EntitySpec}, read by Iris's Bukkit host with
|
||||
* {@code spec.extension(IrisEntityExtras.class)}: what Iris packs set on an entity that only Bukkit has a name for or
|
||||
* only Iris does. Other hosts ignore it.
|
||||
*
|
||||
* @param reason Bukkit's spawn reason by name, such as {@code COMMAND}; empty for a natural spawn
|
||||
* @param riseOutOfGround whether the entity slowly climbs out of the ground when players are near
|
||||
* @param pandaMainGene for pandas the main gene by Bukkit's name; empty to leave it to the platform
|
||||
* @param pandaHiddenGene for pandas the hidden gene by Bukkit's name; empty to leave it to the platform
|
||||
* @param applySettingsToProvidedMob whether the rest of the spec also applies to a mob of a content provider, which is
|
||||
* otherwise left as the provider set it up
|
||||
*/
|
||||
public record IrisEntityExtras(Optional<String> reason, boolean riseOutOfGround, Optional<String> pandaMainGene,
|
||||
Optional<String> pandaHiddenGene, boolean applySettingsToProvidedMob) {
|
||||
/** What an entity without the extension gets: a natural spawn, standing, with the platform's genes. */
|
||||
public static final IrisEntityExtras NONE = new IrisEntityExtras(Optional.empty(), false, Optional.empty(), Optional.empty(), false);
|
||||
|
||||
public IrisEntityExtras {
|
||||
Objects.requireNonNull(reason, "reason");
|
||||
Objects.requireNonNull(pandaMainGene, "pandaMainGene");
|
||||
Objects.requireNonNull(pandaHiddenGene, "pandaHiddenGene");
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Required;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -45,7 +45,7 @@ public final class PlacementMarker {
|
||||
@Desc("If true, markers will only be placed if the block matches the mark list perfectly.")
|
||||
private boolean exact = false;
|
||||
@Required
|
||||
@ResourceRef(SpawnMarker.class)
|
||||
@Ref(kind = SpawnMarker.class)
|
||||
@Desc("The marker to add")
|
||||
private String marker;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package art.arcane.iris.builtin.spawn;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -29,7 +29,7 @@ import java.util.List;
|
||||
@Desc("Represents a marker")
|
||||
public final class SpawnMarker {
|
||||
@Desc("A list of spawners to add to anywhere this marker is.")
|
||||
@ResourceRef(Spawner.class)
|
||||
@Ref(kind = Spawner.class)
|
||||
@MinItems(1)
|
||||
private List<String> spawners = List.of();
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.ResourceRef;
|
||||
import com.volmit.config.Ref;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -36,7 +36,7 @@ import java.util.List;
|
||||
@Feature(id = "iris:spawn", name = "Entity spawners", key = "entitySpawners", root = "spawners", targets = {Level.DIMENSION, Level.REGION, Level.BIOME})
|
||||
public final class SpawnerSettings implements IrisFeature {
|
||||
@MinItems(1)
|
||||
@ResourceRef(Spawner.class)
|
||||
@Ref(kind = Spawner.class)
|
||||
@Desc("Entity spawners to add to this area")
|
||||
private List<String> spawners = List.of();
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.builtin.structure;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Iris extension: says that a text option names structures of Iris's structure model by key, which Iris completes in
|
||||
* studio and carries along when it exports the pack. The structure model is Iris's own resource kind, whose class a
|
||||
* module cannot see, so {@code @Ref(kind = ...)} cannot name it; to another host the option is plain text.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface IrisStructureRef {
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.world.PackBiome;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -37,7 +37,7 @@ import java.util.Optional;
|
||||
@Desc("Attaches structures to a biome, region or dimension and controls where and how often they generate. This is independent of a structure's own native generation, so you can add custom placements in tandem with native generation or instead of it.")
|
||||
public final class StructurePlacement {
|
||||
@MinItems(1)
|
||||
@Ref(Reference.PACK_STRUCTURE)
|
||||
@IrisStructureRef
|
||||
@Desc("Editable Iris assembly resources offered by this placement. Leave empty when nativeStructures supplies the source.")
|
||||
private List<String> structures = List.of();
|
||||
|
||||
@@ -96,7 +96,7 @@ public final class StructurePlacement {
|
||||
private StructureAnchorMode anchor = StructureAnchorMode.LEGACY;
|
||||
|
||||
@MinItems(1)
|
||||
@Ref(Reference.PACK_BIOME)
|
||||
@Ref(kind = PackBiome.class)
|
||||
@Desc("Optional cave-biome allowlist for cave anchor modes. Empty accepts the cave biome resolved at the selected anchor. Entries match by load key, including prefix matches.")
|
||||
private List<String> caveBiomes = List.of();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.world.UpperDimension;
|
||||
|
||||
@@ -58,7 +59,7 @@ public final class TerrainPalettes {
|
||||
private final long complexSeed;
|
||||
private final AtomicCache<ColumnBlocks> rock = new AtomicCache<>();
|
||||
private final AtomicCache<ColumnBlocks> fluid = new AtomicCache<>();
|
||||
private final Map<String, ColumnBlocks> upperRocks = new ConcurrentHashMap<>();
|
||||
private final Map<ResourceId, ColumnBlocks> upperRocks = new ConcurrentHashMap<>();
|
||||
|
||||
TerrainPalettes(PackWorld world) {
|
||||
this.world = world;
|
||||
@@ -88,7 +89,7 @@ public final class TerrainPalettes {
|
||||
|
||||
/** The rock at the column of the upper dimension: the world's own when the upper dimension is the dimension itself. */
|
||||
public BlockState upperRockAt(UpperDimension upper, double x, double z) {
|
||||
return upperRocks.computeIfAbsent(upper.key(), key -> upperRock(upper, x, z)).at(x, z);
|
||||
return upperRocks.computeIfAbsent(upper.id(), id -> upperRock(upper, x, z)).at(x, z);
|
||||
}
|
||||
|
||||
private ColumnBlocks rock() {
|
||||
@@ -110,7 +111,8 @@ public final class TerrainPalettes {
|
||||
return rock();
|
||||
}
|
||||
|
||||
long seedOffset = upper.key().hashCode();
|
||||
// Iris seeded this from the dimension's key; the id's path is that key for every key an id can hold unchanged.
|
||||
long seedOffset = upper.id().path().hashCode();
|
||||
RNG rng = new RNG(complexSeed ^ seedOffset);
|
||||
SettingsStack<RockPaletteSettings> declared = upper.settings().at(RockPaletteSettings.class, (int) x, (int) z);
|
||||
return columns(rockPalette(declared), rng.nextParallelRNG(ROCK_SIGNATURE), upper.resources());
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class BlockDropping implements BlockDrops {
|
||||
providers.addAll(dropsFor(live, Level.DIMENSION, x, y, z, brokenKey, resolved, world));
|
||||
}
|
||||
|
||||
LootItems items = new LootItems(world.resources().items(), false);
|
||||
LootItems items = new LootItems(world.resources().items(), false, world.log());
|
||||
List<ItemDrop> drops = new ArrayList<>();
|
||||
providers.forEach(provider -> fillDrops(provider.drop(), items, drops));
|
||||
return new Result(drops, providers.stream().anyMatch(provider -> provider.drop().replaceVanillaDrops()));
|
||||
|
||||
@@ -76,7 +76,7 @@ public final class LootGiving implements Loot {
|
||||
return List.of();
|
||||
}
|
||||
int worldY = site.position().y() + world.extension(LiveWorld.class).orElseThrow().bottomY();
|
||||
return new LootItems(world.resources().items(), site.debug())
|
||||
return new LootItems(world.resources().items(), site.debug(), world.log())
|
||||
.draw(tableId.path(), table, lootSeed(world), site.position().x(), worldY, site.position().z());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,13 @@ import art.arcane.iris.builtin.loot.LootSlot;
|
||||
import art.arcane.iris.builtin.loot.LootTable;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.item.ItemEnchantment;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.resource.ContentKey;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -44,17 +47,21 @@ import java.util.OptionalInt;
|
||||
* must do with the result is the host's.
|
||||
*/
|
||||
public final class LootItems {
|
||||
private static final String AIR = "air";
|
||||
private static final String MINECRAFT_PREFIX = "minecraft:";
|
||||
private static final ContentKey AIR = new ContentKey.Registered(ResourceId.parse("minecraft:air"));
|
||||
private static final int MIN_AMOUNT = 1;
|
||||
|
||||
private final ItemRegistry items;
|
||||
private final boolean debug;
|
||||
private final ModuleLog log;
|
||||
|
||||
/** @param debug whether the items say where they came from */
|
||||
public LootItems(ItemRegistry items, boolean debug) {
|
||||
/**
|
||||
* @param debug whether the items say where they came from
|
||||
* @param log hears of keys that name nothing the platform could have
|
||||
*/
|
||||
public LootItems(ItemRegistry items, boolean debug, ModuleLog log) {
|
||||
this.items = items;
|
||||
this.debug = debug;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +99,24 @@ public final class LootItems {
|
||||
return resolve(entry, rng, null);
|
||||
}
|
||||
|
||||
/** The attribute modifiers that pass their chances, with their amounts drawn, as for an item or an entity. */
|
||||
public List<ItemAttribute> attributes(List<ItemAttributeModifier> modifiers, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (ItemAttributeModifier modifier : modifiers) {
|
||||
if (rng.nextDouble() >= modifier.chance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.attribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
double amount = rng.d(modifier.minAmount(), modifier.maxAmount());
|
||||
PlatformKeys.id(attribute, log).ifPresent(id -> attributes.add(
|
||||
new ItemAttribute(id, modifier.name(), PlatformKeys.operation(modifier.operation()), amount)));
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
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)) {
|
||||
@@ -101,66 +126,50 @@ public final class LootItems {
|
||||
}
|
||||
|
||||
private ItemDrop resolve(LootEntry entry, RNG rng, LootTable table) {
|
||||
String type = entry.type();
|
||||
OptionalInt maxDurability = items.maxDurability(type);
|
||||
if (maxDurability.isEmpty() || isAir(type)) {
|
||||
Optional<ContentKey> item = PlatformKeys.item(entry.type(), log);
|
||||
if (item.isEmpty() || item.get().equals(AIR)) {
|
||||
return null;
|
||||
}
|
||||
OptionalInt maxDurability = items.maxDurability(item.get());
|
||||
if (maxDurability.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
List<ItemAttribute> attributes = attributes(entry.attributes(), rng);
|
||||
OptionalDouble damage = maxDurability.getAsInt() > 0
|
||||
? OptionalDouble.of(1D - rng.d(entry.minDurability(), entry.maxDurability()))
|
||||
: OptionalDouble.empty();
|
||||
return new ItemDrop(type, amount, Optional.ofNullable(entry.displayName()), entry.lore(), enchantments, attributes,
|
||||
entry.unbreakable(), entry.itemFlags(), customModelOf(entry), damage, Optional.ofNullable(entry.leatherColor()),
|
||||
Optional.ofNullable(entry.dyeColor()), Objects.requireNonNullElse(entry.customNbt(), Map.of()),
|
||||
return new ItemDrop(item.get(), amount, lookOf(entry), enchantments, attributes, new ItemDrop.Wear(entry.unbreakable(), damage),
|
||||
new ItemDrop.PlatformExtras(entry.itemFlags(), Objects.requireNonNullElse(entry.customNbt(), Map.of())),
|
||||
debug ? Optional.of(sourceOf(entry, table)) : Optional.empty());
|
||||
}
|
||||
|
||||
private static OptionalInt customModelOf(LootEntry entry) {
|
||||
private ItemDrop.Look lookOf(LootEntry entry) {
|
||||
Integer customModel = entry.customModel();
|
||||
return customModel == null ? OptionalInt.empty() : OptionalInt.of(customModel);
|
||||
return new ItemDrop.Look(Optional.ofNullable(entry.displayName()), entry.lore(),
|
||||
customModel == null ? OptionalInt.empty() : OptionalInt.of(customModel),
|
||||
PlatformKeys.rgb(entry.leatherColor(), log), PlatformKeys.dye(entry.dyeColor(), log));
|
||||
}
|
||||
|
||||
private static List<ItemEnchantment> drawEnchantments(LootEntry entry, RNG rng) {
|
||||
private List<ItemEnchantment> drawEnchantments(LootEntry entry, RNG rng) {
|
||||
List<ItemEnchantment> enchantments = new ArrayList<>();
|
||||
for (LootEnchantment enchantment : entry.enchantments()) {
|
||||
String key = enchantment.enchantment();
|
||||
if (key == null || key.isBlank() || rng.nextDouble() >= enchantment.chance()) {
|
||||
continue;
|
||||
}
|
||||
int level = LootResolver.inclusive(rng, enchantment.minLevel(), enchantment.maxLevel());
|
||||
enchantments.add(new ItemEnchantment(key, Math.max(1, level)));
|
||||
int level = Math.max(1, LootResolver.inclusive(rng, enchantment.minLevel(), enchantment.maxLevel()));
|
||||
PlatformKeys.id(key, log).ifPresent(id -> enchantments.add(new ItemEnchantment(id, level)));
|
||||
}
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
private static List<ItemAttribute> drawAttributes(LootEntry entry, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (ItemAttributeModifier modifier : entry.attributes()) {
|
||||
if (rng.nextDouble() >= modifier.chance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.attribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount())));
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static ItemDrop.Source sourceOf(LootEntry entry, LootTable table) {
|
||||
if (table == null) {
|
||||
return new ItemDrop.Source(Optional.empty(), 0, entry.rarity());
|
||||
}
|
||||
return new ItemDrop.Source(Optional.ofNullable(table.name()), table.rarity(), entry.rarity());
|
||||
}
|
||||
|
||||
private static boolean isAir(String type) {
|
||||
String key = type.startsWith(MINECRAFT_PREFIX) ? type.substring(MINECRAFT_PREFIX.length()) : type;
|
||||
return AIR.equalsIgnoreCase(key);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.Loot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -94,7 +95,7 @@ final class PlacementLoot {
|
||||
if (key == null || !platformTables.get().contains(key)) {
|
||||
return null;
|
||||
}
|
||||
return new Loot.PlatformTable(key, LootTables.seed(lootSeed, LootTables.platformIdentity(key), x, worldY, z));
|
||||
return new Loot.PlatformTable(ResourceId.parse(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. */
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 com.volmit.ModuleLog;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.DyeColor;
|
||||
import com.volmit.resource.ContentKey;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
* The platform things packs name, as they write them, turned into what IrisApi hands the host: ids, items and mobs,
|
||||
* attribute operations and colours. A blank key names nothing; a key that names nothing the host could look up is left
|
||||
* out with a warning, once per key.
|
||||
*/
|
||||
public final class PlatformKeys {
|
||||
private static final String PLATFORM_NAMESPACE = "minecraft";
|
||||
private static final char NAMESPACE_SEPARATOR = ':';
|
||||
private static final String WARNING_KEY = "iris:platform-key/";
|
||||
|
||||
private PlatformKeys() {
|
||||
}
|
||||
|
||||
/** {@code key} as an id, such as {@code minecraft:sharpness} for {@code Sharpness}; see {@link ResourceId#ofPlatformKey}. */
|
||||
public static Optional<ResourceId> id(String key, ModuleLog log) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.of(ResourceId.ofPlatformKey(key));
|
||||
} catch (IllegalArgumentException invalid) {
|
||||
log.warnOnce(WARNING_KEY + key, "Ignoring '" + key + "': it names nothing the platform could have");
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The item {@code key} names. A key of the platform's own namespace, or of none, is a registered item; so is a key of
|
||||
* another namespace an id can hold as written, such as {@code itemsadder:ruby}, which the host routes to its owner.
|
||||
* Any other namespaced key is a provider's item, kept as written.
|
||||
*/
|
||||
public static Optional<ContentKey> item(String key, ModuleLog log) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String written = key.trim();
|
||||
int separator = written.indexOf(NAMESPACE_SEPARATOR);
|
||||
if (separator < 0 || PLATFORM_NAMESPACE.equalsIgnoreCase(written.substring(0, separator))) {
|
||||
return id(written, log).map(ContentKey.Registered::new);
|
||||
}
|
||||
try {
|
||||
return Optional.of(new ContentKey.Registered(ResourceId.parse(written)));
|
||||
} catch (IllegalArgumentException notAnId) {
|
||||
return provided(written, log);
|
||||
}
|
||||
}
|
||||
|
||||
/** A provider's mob or item, written {@code provider:name}, such as {@code mythicmobs:SkeletonKing}. */
|
||||
public static Optional<ContentKey> provided(String key, ModuleLog log) {
|
||||
if (key == null || key.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String written = key.trim();
|
||||
int separator = written.indexOf(NAMESPACE_SEPARATOR);
|
||||
if (separator <= 0 || separator == written.length() - 1) {
|
||||
log.warnOnce(WARNING_KEY + key, "Ignoring '" + key + "': a provider's content is written provider:name");
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ContentKey.Provided(written.substring(0, separator), written.substring(separator + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* The attribute operation packs name by Bukkit's names, {@code ADD_NUMBER}, {@code ADD_SCALAR} and
|
||||
* {@code MULTIPLY_SCALAR_1}, or by the platform's own; adding the amount for a name it does not know.
|
||||
*/
|
||||
public static ItemAttribute.Operation operation(String name) {
|
||||
String normalized = name == null ? "" : name.trim().toUpperCase(Locale.ROOT);
|
||||
return switch (normalized) {
|
||||
case "ADD_SCALAR", "ADD_MULTIPLIED_BASE" -> ItemAttribute.Operation.ADD_MULTIPLIED_BASE;
|
||||
case "MULTIPLY_SCALAR_1", "ADD_MULTIPLIED_TOTAL" -> ItemAttribute.Operation.ADD_MULTIPLIED_TOTAL;
|
||||
default -> ItemAttribute.Operation.ADD_VALUE;
|
||||
};
|
||||
}
|
||||
|
||||
/** The colour {@code text} writes, {@code #rrggbb}, {@code 0xrrggbb} or a number; empty, with a warning, for anything else. */
|
||||
public static OptionalInt rgb(String text, ModuleLog log) {
|
||||
if (text == null || text.isBlank()) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
try {
|
||||
return OptionalInt.of(Integer.decode(text.trim()) & 0xFFFFFF);
|
||||
} catch (NumberFormatException notAColour) {
|
||||
log.warnOnce(WARNING_KEY + text, "Ignoring the colour '" + text + "': write it as #rrggbb");
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/** The dye colour {@code name} names, such as {@code RED} or {@code light_blue}; empty, with a warning, for anything else. */
|
||||
public static Optional<DyeColor> dye(String name, ModuleLog log) {
|
||||
if (name == null || name.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.of(DyeColor.valueOf(name.trim().toUpperCase(Locale.ROOT)));
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
log.warnOnce(WARNING_KEY + name, "Ignoring the dye colour '" + name + "', which is none of the sixteen dyes");
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,10 +114,11 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
return Optional.of(placements.get(RNG.r.i(placements.size())));
|
||||
}
|
||||
|
||||
private static List<ObjectPlacement> matching(ObjectSettings settings, String species) {
|
||||
/** The placements whose trees override {@code species}, which packs name by the path of its id, ignoring case. */
|
||||
private static List<ObjectPlacement> matching(ObjectSettings settings, ResourceId species) {
|
||||
List<ObjectPlacement> matches = new ArrayList<>();
|
||||
for (ObjectPlacement placement : settings.objects()) {
|
||||
if (placement.trees().stream().anyMatch(tree -> tree.matches(SAPLING_WIDTH, SAPLING_DEPTH, species))) {
|
||||
if (placement.trees().stream().anyMatch(tree -> tree.matches(SAPLING_WIDTH, SAPLING_DEPTH, species.path()))) {
|
||||
matches.add(placement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,11 @@ 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.engine.loot.PlatformKeys;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -47,8 +50,8 @@ public final class AmbientEffecting implements AmbientEffects {
|
||||
Optional<Sky> sky = live.sky();
|
||||
|
||||
List<Effect> due = new ArrayList<>();
|
||||
addDue(due, effectsOf(live, Level.REGION, at), timers, sky);
|
||||
addDue(due, effectsOf(live, Level.BIOME, at), timers, sky);
|
||||
addDue(due, effectsOf(live, Level.REGION, at), timers, sky, world.log());
|
||||
addDue(due, effectsOf(live, Level.BIOME, at), timers, sky, world.log());
|
||||
return due;
|
||||
}
|
||||
|
||||
@@ -56,40 +59,36 @@ public final class AmbientEffecting implements AmbientEffects {
|
||||
return live.settings(EffectSettings.class, level, at.x(), at.y(), at.z()).map(EffectSettings::effects).orElse(List.of());
|
||||
}
|
||||
|
||||
private static void addDue(List<Effect> due, List<AmbientEffect> effects, EffectTimers timers, Optional<Sky> sky) {
|
||||
private static void addDue(List<Effect> due, List<AmbientEffect> effects, EffectTimers timers, Optional<Sky> sky, ModuleLog log) {
|
||||
for (AmbientEffect effect : effects) {
|
||||
if (timers.shouldPlayNow(effect)) {
|
||||
due.add(play(effect, sky));
|
||||
due.add(play(effect, sky, log));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Effect play(AmbientEffect effect, Optional<Sky> sky) {
|
||||
Optional<Sound> sound = effect.sound() == null ? Optional.empty() : Optional.of(soundOf(effect));
|
||||
Optional<Particles> particles = effect.particleEffect() == null ? Optional.empty() : Optional.of(particlesOf(effect));
|
||||
return new Effect(sound, particles, commandsOf(effect.commandRegistry(), sky), potionOf(effect));
|
||||
private static Effect play(AmbientEffect effect, Optional<Sky> sky, ModuleLog log) {
|
||||
Optional<Sound> sound = PlatformKeys.id(effect.sound(), log).map(key -> soundOf(key, effect));
|
||||
Optional<Particles> particles = PlatformKeys.id(effect.particleEffect(), log).map(key -> particlesOf(key, effect));
|
||||
return new Effect(sound, particles, commandsOf(effect.commandRegistry(), sky), potionOf(effect, log));
|
||||
}
|
||||
|
||||
private static Sound soundOf(AmbientEffect effect) {
|
||||
private static Sound soundOf(ResourceId key, 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);
|
||||
return new Sound(key, offsetX, offsetY, offsetZ, (float) effect.volume(), pitch);
|
||||
}
|
||||
|
||||
private static Particles particlesOf(AmbientEffect effect) {
|
||||
private static Particles particlesOf(ResourceId key, 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());
|
||||
Spot spot = new Spot(forward, sideways, RNG.r.d(), RNG.r.d(), RNG.r.i(effect.particleOffset()));
|
||||
Spread spread = new Spread(randomized(effect.particleAltX(), effect.randomAltX()),
|
||||
randomized(effect.particleAltY(), effect.randomAltY()), randomized(effect.particleAltZ(), effect.randomAltZ()));
|
||||
return new Particles(key, spot, effect.particleCount(), spread, effect.extra());
|
||||
}
|
||||
|
||||
private static List<Command> commandsOf(EffectCommands registry, Optional<Sky> sky) {
|
||||
@@ -115,14 +114,15 @@ public final class AmbientEffecting implements AmbientEffects {
|
||||
return commands;
|
||||
}
|
||||
|
||||
private static Optional<Potion> potionOf(AmbientEffect effect) {
|
||||
private static Optional<Potion> potionOf(AmbientEffect effect, ModuleLog log) {
|
||||
if (effect.potionStrength() <= -1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
int shortest = Math.min(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
int longest = Math.max(effect.potionTicksMax(), effect.potionTicksMin());
|
||||
return Optional.of(new Potion(effect.potionEffect(), effect.potionStrength(), RNG.r.i(shortest, longest)));
|
||||
int ticks = RNG.r.i(shortest, longest);
|
||||
return PlatformKeys.id(effect.potionEffect(), log).map(key -> new Potion(key, effect.potionStrength(), ticks));
|
||||
}
|
||||
|
||||
private static double commandOffset(double offset, boolean random) {
|
||||
|
||||
@@ -19,17 +19,20 @@
|
||||
package art.arcane.iris.engine.spawn;
|
||||
|
||||
import art.arcane.iris.builtin.LiveWorld.Sky;
|
||||
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.IrisEntityExtras;
|
||||
import art.arcane.iris.builtin.spawn.SpawnCommand;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.engine.loot.LootItems;
|
||||
import art.arcane.iris.engine.loot.PlatformKeys;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.resource.ContentKey;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
@@ -39,7 +42,9 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Turns an entity of the pack into the {@link EntitySpec} the host spawns, making every random choice in the order Iris
|
||||
* always made them: the passengers, the attribute modifiers, the leash holder and then the six pieces of equipment.
|
||||
* always made them: the passengers, the attribute modifiers, the leash holder and then the six pieces of equipment. An
|
||||
* entity that names no type the host could spawn resolves to nothing, after its random choices, so that the ones after
|
||||
* it stay what they were.
|
||||
*/
|
||||
final class EntityResolution {
|
||||
private static final long PASSENGER_STREAM_BASE = 234858L;
|
||||
@@ -49,39 +54,50 @@ final class EntityResolution {
|
||||
private final LootItems items;
|
||||
private final Optional<Sky> sky;
|
||||
private final EffectTimers timers;
|
||||
private final ModuleLog log;
|
||||
|
||||
/**
|
||||
* @param resources names the entity's loot tables by id
|
||||
* @param sky the sky of the world the entity appears in, whose time and weather decide which of its commands run; none while the world has no platform world
|
||||
* @param log hears of keys that name nothing the platform could have
|
||||
*/
|
||||
EntityResolution(PackResources resources, LootItems items, Optional<Sky> sky, EffectTimers timers) {
|
||||
EntityResolution(PackResources resources, LootItems items, Optional<Sky> sky, EffectTimers timers, ModuleLog log) {
|
||||
this.resources = resources;
|
||||
this.items = items;
|
||||
this.sky = sky;
|
||||
this.timers = timers;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
EntitySpec resolve(EntityDefinition entity, RNG rng) {
|
||||
Optional<EntitySpec> resolve(EntityDefinition entity, RNG rng) {
|
||||
List<EntitySpec> passengers = new ArrayList<>();
|
||||
long passengerIndex = 0;
|
||||
for (EntityDefinition passenger : entity.passengers()) {
|
||||
passengers.add(resolve(passenger, rng.nextParallelRNG(PASSENGER_STREAM_BASE + passengerIndex++)));
|
||||
resolve(passenger, rng.nextParallelRNG(PASSENGER_STREAM_BASE + passengerIndex++)).ifPresent(passengers::add);
|
||||
}
|
||||
|
||||
List<ItemAttribute> attributes = drawAttributes(entity, rng);
|
||||
List<ItemAttribute> attributes = items.attributes(entity.attributes(), rng);
|
||||
List<ResourceId> lootTables = entity.loot().tables().stream().map(resources::idOf).toList();
|
||||
long lootShuffleSeed = lootTables.isEmpty() ? 0L : rng.nextLong();
|
||||
Optional<EntitySpec> leashHolder = entity.leashHolder() == null
|
||||
? Optional.empty()
|
||||
: Optional.of(resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM)));
|
||||
: resolve(entity.leashHolder(), rng.nextParallelRNG(LEASH_HOLDER_STREAM));
|
||||
EntitySpec.Equipment equipment = new EntitySpec.Equipment(
|
||||
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(textOf(entity.type()), textOf(entity.specialType()), textOf(entity.reason()),
|
||||
textOf(entity.customName()), flagsOf(entity), equipment, passengers, attributes, lootTables, lootShuffleSeed,
|
||||
leashHolder, spawnEffectOf(entity), entity.spawnEffectRiseOutOfGround(), textOf(entity.pandaMainGene()),
|
||||
textOf(entity.pandaHiddenGene()), entity.applySettingsToCustomMobAnyways(), commandsOf(entity));
|
||||
return typeOf(entity).map(type -> new EntitySpec(type, appearanceOf(entity), behaviourOf(entity), equipment, attributes,
|
||||
new EntitySpec.Company(passengers, leashHolder), new EntitySpec.Drops(lootTables, lootShuffleSeed),
|
||||
new EntitySpec.Arrival(spawnEffectOf(entity), commandsOf(entity)), List.of(extrasOf(entity))));
|
||||
}
|
||||
|
||||
/** The provider's mob when the pack names one, otherwise the entity type. */
|
||||
private Optional<ContentKey> typeOf(EntityDefinition entity) {
|
||||
Optional<String> provided = textOf(entity.specialType());
|
||||
if (provided.isPresent()) {
|
||||
return PlatformKeys.provided(provided.get(), log);
|
||||
}
|
||||
return PlatformKeys.id(entity.type(), log).map(ContentKey.Registered::new);
|
||||
}
|
||||
|
||||
/** A text the pack may leave out or blank, as absent then. */
|
||||
@@ -89,25 +105,18 @@ final class EntityResolution {
|
||||
return text == null || text.isBlank() ? Optional.empty() : Optional.of(text);
|
||||
}
|
||||
|
||||
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 EntitySpec.Appearance appearanceOf(EntityDefinition entity) {
|
||||
return new EntitySpec.Appearance(textOf(entity.customName()), entity.customNameVisible(), entity.glowing(), entity.baby());
|
||||
}
|
||||
|
||||
private static List<ItemAttribute> drawAttributes(EntityDefinition entity, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (ItemAttributeModifier modifier : entity.attributes()) {
|
||||
if (rng.nextDouble() >= modifier.chance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.attribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
attributes.add(new ItemAttribute(attribute, modifier.name(), modifier.operation(), rng.d(modifier.minAmount(), modifier.maxAmount())));
|
||||
}
|
||||
return attributes;
|
||||
private static EntitySpec.Behaviour behaviourOf(EntityDefinition entity) {
|
||||
return new EntitySpec.Behaviour(entity.aware(), entity.ai(), entity.gravity(), entity.invulnerable(), entity.silent(),
|
||||
entity.pickupItems(), entity.removable(), entity.keepEntity());
|
||||
}
|
||||
|
||||
private static IrisEntityExtras extrasOf(EntityDefinition entity) {
|
||||
return new IrisEntityExtras(textOf(entity.reason()), entity.spawnEffectRiseOutOfGround(), textOf(entity.pandaMainGene()),
|
||||
textOf(entity.pandaHiddenGene()), entity.applySettingsToCustomMobAnyways());
|
||||
}
|
||||
|
||||
private Optional<ItemDrop> equip(LootEntry piece, RNG rng) {
|
||||
@@ -123,10 +132,16 @@ final class EntityResolution {
|
||||
if (effect == null || !timers.shouldPlayNow(effect)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new EntitySpec.SpawnEffect(textOf(effect.sound()), effect.soundDistance(), effect.minPitch(),
|
||||
effect.maxPitch(), effect.volume(), textOf(effect.particleEffect()), effect.particleOffset(),
|
||||
effect.particleCount(), effect.particleAltX(), effect.particleAltY(), effect.particleAltZ(),
|
||||
effect.randomAltX(), effect.randomAltY(), effect.randomAltZ(), effect.extra()));
|
||||
Optional<EntitySpec.SpawnEffect.Sound> sound = PlatformKeys.id(effect.sound(), log).map(key ->
|
||||
new EntitySpec.SpawnEffect.Sound(key, effect.soundDistance(), effect.minPitch(), effect.maxPitch(), effect.volume()));
|
||||
Optional<EntitySpec.SpawnEffect.Burst> particles = PlatformKeys.id(effect.particleEffect(), log).map(key ->
|
||||
new EntitySpec.SpawnEffect.Burst(key, effect.particleOffset(), effect.particleCount(), motionOf(effect), effect.extra()));
|
||||
return Optional.of(new EntitySpec.SpawnEffect(sound, particles));
|
||||
}
|
||||
|
||||
private static EntitySpec.SpawnEffect.Motion motionOf(AmbientEffect effect) {
|
||||
return new EntitySpec.SpawnEffect.Motion(effect.particleAltX(), effect.particleAltY(), effect.particleAltZ(),
|
||||
effect.randomAltX(), effect.randomAltY(), effect.randomAltZ());
|
||||
}
|
||||
|
||||
private List<EntitySpec.Command> commandsOf(EntityDefinition entity) {
|
||||
|
||||
@@ -91,15 +91,15 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
if (entity == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(resolution(world).resolve(entity, entityRandom(world).rng()));
|
||||
return resolution(world).resolve(entity, entityRandom(world).rng());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MarkerRule> marker(PackWorld world, String tag) {
|
||||
if (tag.equals(CAVE_FLOOR_MARKER) || tag.equals(CAVE_CEILING_MARKER)) {
|
||||
public Optional<MarkerRule> marker(PackWorld world, ResourceId tag) {
|
||||
if (tag.path().equals(CAVE_FLOOR_MARKER) || tag.path().equals(CAVE_CEILING_MARKER)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
SpawnMarker marker = SpawnResources.marker(world.resources(), tag);
|
||||
SpawnMarker marker = SpawnResources.marker(world.resources(), tag.path());
|
||||
if (marker == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
private Optional<Plan> planMarker(PackWorld world, Marker marker) {
|
||||
String spawnerKey = marker.spawner().path();
|
||||
Spawner spawner = SpawnResources.spawner(world.resources(), spawnerKey);
|
||||
SpawnMarker spawnMarker = SpawnResources.marker(world.resources(), marker.marker());
|
||||
SpawnMarker spawnMarker = SpawnResources.marker(world.resources(), marker.marker().path());
|
||||
if (spawner == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -231,15 +231,15 @@ public final class EntitySpawning implements EntitySpawns {
|
||||
}
|
||||
|
||||
Range light = candidate.spawner().allowedLightLevels();
|
||||
EntitySpec spec = resolution(world).resolve(entity, entityRandom(world).rng());
|
||||
attempts.add(new Attempt(at, spec, surfaceOf(entity.surface()),
|
||||
(int) Math.ceil(light.min()), (int) Math.floor(light.max()), checkSurface));
|
||||
resolution(world).resolve(entity, entityRandom(world).rng()).ifPresent(spec -> 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) {
|
||||
LiveWorld live = world.extension(LiveWorld.class).orElseThrow();
|
||||
LootItems items = new LootItems(world.resources().items(), live.studio());
|
||||
return new EntityResolution(world.resources(), items, live.sky(),world.state(EffectTimers.class, ignored -> new EffectTimers()));
|
||||
LootItems items = new LootItems(world.resources().items(), live.studio(), world.log());
|
||||
return new EntityResolution(world.resources(), items, live.sky(), world.state(EffectTimers.class, ignored -> new EffectTimers()),
|
||||
world.log());
|
||||
}
|
||||
|
||||
private static EntityRandom entityRandom(PackWorld world) {
|
||||
|
||||
Reference in new issue
Block a user