mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
iris:loot: Loot and BlockDrops providers, loot table resolution and item drawing moved out of core
This commit is contained in:
1 parent
37bc1a0e70
commit
a1af4a85ff
11 files changed
+590
-15
No files matched your search
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.modules.IrisPackWorld;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.loot.IrisBlockDrops;
|
||||
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 com.volmit.item.ItemDrop;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* How {@code iris:loot} drops items for broken blocks: the block drops of the biome, the region and the dimension, the
|
||||
* biome's first and the biome able to keep the others from dropping.
|
||||
*/
|
||||
public final class BlockDropping implements BlockDrops {
|
||||
@Override
|
||||
public Result drops(PackWorld world, Broken broken) {
|
||||
Engine engine = IrisPackWorld.of(world).engine();
|
||||
int x = broken.position().x();
|
||||
int y = broken.position().y();
|
||||
int z = broken.position().z();
|
||||
PlatformBlockState block = IrisPlatforms.get().registries().block(broken.block().key());
|
||||
|
||||
IrisBiome biome = engine.getBiome(x, y, z);
|
||||
List<IrisBlockDrops> providers = dropsFor(biome.getBlockDrops(), block, engine);
|
||||
if (providers.stream().noneMatch(IrisBlockDrops::isSkipParents)) {
|
||||
IrisRegion region = engine.getRegion(x, z);
|
||||
providers.addAll(dropsFor(region.getBlockDrops(), block, engine));
|
||||
providers.addAll(dropsFor(engine.getDimension().getBlockDrops(), block, engine));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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.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.List;
|
||||
|
||||
/**
|
||||
* How {@code iris:loot} fills containers: the tables of the object placed around a container, then those of the
|
||||
* dimension, region and biomes at its column, and the items each table gives. Draws are deterministic per container, so
|
||||
* a container always holds the same loot.
|
||||
*/
|
||||
public final class LootGiving implements Loot {
|
||||
@Override
|
||||
public List<Source> tables(PackWorld world, Site site) {
|
||||
Engine engine = engine(world);
|
||||
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);
|
||||
|
||||
List<IrisLootTable> tables = new KList<>();
|
||||
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);
|
||||
if (placement.isOverrideGlobalLoot()) {
|
||||
return sourcesOf(engine, site, List.of(table));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LootTables.resolveEnvironmentSources(tables, engine, rng, x, relativeY, z, objectLootDefined, table -> table);
|
||||
return sourcesOf(engine, site, tables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemDrop> items(PackWorld world, Site site, String key) {
|
||||
Engine engine = engine(world);
|
||||
IrisLootTable table = engine.getData().getLootLoader().load(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());
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placementAt(Engine engine, int x, int relativeY, int z) {
|
||||
PlacedObject placed = engine.getObjectPlacement(x, relativeY, z);
|
||||
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());
|
||||
}
|
||||
|
||||
private static long lootSeed(Engine engine) {
|
||||
return engine.getSeedManager().getLoot();
|
||||
}
|
||||
|
||||
private static Engine engine(PackWorld world) {
|
||||
return IrisPackWorld.of(world).engine();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.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;
|
||||
import com.volmit.item.ItemEnchantment;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
* Turns loot entries into the items they give: every random choice is made here, in the order Iris always made them
|
||||
* (amount, enchantments, attribute modifiers, damage), so that a container's loot stays what it was. What the platform
|
||||
* 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 int MIN_AMOUNT = 1;
|
||||
|
||||
private final ItemRegistry items;
|
||||
private final boolean debug;
|
||||
|
||||
/** @param debug whether the items say where they came from */
|
||||
public LootItems(ItemRegistry items, boolean debug) {
|
||||
this.items = items;
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public List<ItemDrop> draw(IrisLootTable 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) {
|
||||
return drops;
|
||||
}
|
||||
|
||||
RNG rng = LootTables.rng(lootSeed, table, x, y, z);
|
||||
int wanted = Math.max(0, LootResolver.inclusive(rng, table.getMinPicked(), table.getMaxPicked()));
|
||||
int tries = 0;
|
||||
while (drops.size() < wanted && tries++ < table.getMaxTries()) {
|
||||
int index = rng.nextInt(entries.size());
|
||||
IrisLoot entry = entries.get(index);
|
||||
if (entry == null || entry.getSlotTypes() != InventorySlotType.STORAGE) {
|
||||
continue;
|
||||
}
|
||||
ItemDrop drop = drawEntry(entry, table, rng, lootSeed, index, x, y, z);
|
||||
if (drop != null) {
|
||||
drops.add(drop);
|
||||
}
|
||||
}
|
||||
return drops;
|
||||
}
|
||||
|
||||
/** 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) {
|
||||
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)) {
|
||||
return null;
|
||||
}
|
||||
return resolve(entry, rng, table);
|
||||
}
|
||||
|
||||
private ItemDrop resolve(IrisLoot entry, RNG rng, IrisLootTable table) {
|
||||
String type = entry.getTypeKey();
|
||||
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()));
|
||||
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);
|
||||
}
|
||||
|
||||
private static List<ItemEnchantment> drawEnchantments(IrisLoot 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()) {
|
||||
continue;
|
||||
}
|
||||
enchantments.add(new ItemEnchantment(key, Math.max(1, enchantment.getLevel(rng))));
|
||||
}
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
private static List<ItemAttribute> drawAttributes(IrisLoot entry, RNG rng) {
|
||||
List<ItemAttribute> attributes = new ArrayList<>();
|
||||
for (IrisAttributeModifier modifier : entry.getAttributes()) {
|
||||
if (rng.nextDouble() >= modifier.getChance()) {
|
||||
continue;
|
||||
}
|
||||
String attribute = modifier.getAttribute();
|
||||
if (attribute == null || attribute.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
attributes.add(new ItemAttribute(attribute, modifier.getName(), modifier.getOperation(), modifier.getAmount(rng)));
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static ItemDrop.Source sourceOf(IrisLoot entry, IrisLootTable table) {
|
||||
if (table == null) {
|
||||
return new ItemDrop.Source(null, 0, entry.getRarity());
|
||||
}
|
||||
return new ItemDrop.Source(table.getName(), table.getRarity(), entry.getRarity());
|
||||
}
|
||||
|
||||
private static boolean isAir(String type) {
|
||||
String key = type.startsWith(MINECRAFT_PREFIX) ? type.substring(MINECRAFT_PREFIX.length()) : type;
|
||||
return AIR.equalsIgnoreCase(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.FeatureRegistry;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.stage.StageGraph;
|
||||
|
||||
/**
|
||||
* Module {@code iris:loot}: the loot tables of the pack and the items they and the block drops of the dimension, regions
|
||||
* and biomes give. 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";
|
||||
|
||||
@Override
|
||||
public ModuleInfo info() {
|
||||
return ModuleInfo.of("iris:loot", "Loot", VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(StageGraph graph) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(FeatureRegistry registry) {
|
||||
registry.registerService(Loot.class, new LootGiving());
|
||||
registry.registerService(BlockDrops.class, new BlockDropping());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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.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;
|
||||
import java.util.Objects;
|
||||
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}.
|
||||
*/
|
||||
public final class LootTables {
|
||||
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;
|
||||
}
|
||||
|
||||
public static RNG rng(long lootSeed, IrisLootTable table, int x, int y, int z) {
|
||||
return LootResolver.tableRng(lootSeed, identity(table), x, y, z);
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static <T> void resolveEnvironmentSources(
|
||||
List<T> sources,
|
||||
Engine engine,
|
||||
RNG rng,
|
||||
int x,
|
||||
int relativeY,
|
||||
int z,
|
||||
boolean objectLootDefined,
|
||||
Function<IrisLootTable, T> mapper
|
||||
) {
|
||||
IrisRegion region = engine.getComplex().getRegionStream().get(x, z);
|
||||
IrisBiome surfaceBiome = engine.getComplex().getTrueBiomeStream().get(x, z);
|
||||
double terrainHeight = engine.getComplex().getHeightStream().get(x, z);
|
||||
IrisBiome contextualBiome = relativeY < terrainHeight
|
||||
? engine.getCaveBiome(x, relativeY, z)
|
||||
: surfaceBiome;
|
||||
if (contextualBiome == null) {
|
||||
contextualBiome = surfaceBiome;
|
||||
}
|
||||
|
||||
boolean distinctContextualBiome = !sameBiome(surfaceBiome, contextualBiome);
|
||||
double multiplier = engine.getDimension().getLoot().getMultiplier()
|
||||
* region.getLoot().getMultiplier()
|
||||
* surfaceBiome.getLoot().getMultiplier();
|
||||
if (distinctContextualBiome) {
|
||||
multiplier *= contextualBiome.getLoot().getMultiplier();
|
||||
}
|
||||
|
||||
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);
|
||||
if (distinctContextualBiome) {
|
||||
injectReference(sources, contextualBiome.getLoot(), engine, mapper, fallback);
|
||||
}
|
||||
LootResolver.scaleSources(sources, multiplier, rng);
|
||||
}
|
||||
|
||||
/** Adds {@code additions} to {@code sources} the way {@code mode} says; {@code fallback} is whether nothing else defined a table. */
|
||||
public static <T> void injectSources(
|
||||
List<T> sources,
|
||||
List<? extends T> additions,
|
||||
IrisLootMode mode,
|
||||
boolean fallback
|
||||
) {
|
||||
if (mode == IrisLootMode.FALLBACK && !fallback) {
|
||||
return;
|
||||
}
|
||||
if (mode == IrisLootMode.CLEAR) {
|
||||
sources.clear();
|
||||
return;
|
||||
}
|
||||
if (mode == IrisLootMode.REPLACE) {
|
||||
sources.clear();
|
||||
}
|
||||
sources.addAll(additions);
|
||||
}
|
||||
|
||||
static boolean sameBiome(IrisBiome first, IrisBiome second) {
|
||||
if (first == second) {
|
||||
return true;
|
||||
}
|
||||
if (first == null || second == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(first.getLoadKey(), second.getLoadKey());
|
||||
}
|
||||
|
||||
private static <T> void injectReference(
|
||||
List<T> sources,
|
||||
IrisLootReference reference,
|
||||
Engine engine,
|
||||
Function<IrisLootTable, 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);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.mantle.components;
|
||||
|
||||
import art.arcane.iris.core.modules.IrisPackWorld;
|
||||
|
||||
@@ -22,6 +22,7 @@ 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;
|
||||
@@ -33,8 +34,9 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import com.volmit.item.ItemDrop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Snippet("block-drops")
|
||||
@Accessors(chain = true)
|
||||
@@ -43,7 +45,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
@Desc("Represents a block drop list")
|
||||
@Data
|
||||
public class IrisBlockDrops {
|
||||
private final transient AtomicCache<KList<BlockData>> data = new AtomicCache<>();
|
||||
private final transient AtomicCache<KList<PlatformBlockState>> data = new AtomicCache<>();
|
||||
@Required
|
||||
@ArrayType(min = 1, type = IrisBlockData.class)
|
||||
@Desc("The blocks that drop loot")
|
||||
@@ -58,23 +60,23 @@ public class IrisBlockDrops {
|
||||
@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(BlockData data, IrisData rdata) {
|
||||
KList<BlockData> list = this.data.aquire(() -> {
|
||||
KList<BlockData> b = new KList<>();
|
||||
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((BlockData) state.nativeHandle());
|
||||
b.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
return b.removeDuplicates();
|
||||
});
|
||||
|
||||
for (BlockData i : list) {
|
||||
if (exactBlocks ? i.equals(data) : i.getMaterial().equals(data.getMaterial())) {
|
||||
for (PlatformBlockState i : list) {
|
||||
if (exactBlocks ? i.key().equals(broken.key()) : materialOf(i).equals(materialOf(broken))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -82,11 +84,22 @@ public class IrisBlockDrops {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void fillDrops(boolean debug, KList<ItemStack> d) {
|
||||
/** 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())) {
|
||||
d.add(i.get(debug, RNG.r));
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class IrisLoot {
|
||||
|
||||
public ItemStack get(boolean debug, IrisLootTable table, RNG rng, long lootSeed, int entryIndex, int x, int y, int z) {
|
||||
long combinedRarity = LootResolver.combinedRarity(rarity, table.getRarity());
|
||||
if (!LootResolver.spatialOneIn(lootSeed, table, entryIndex, x, y, z, combinedRarity)) {
|
||||
if (!art.arcane.iris.engine.loot.LootTables.spatialOneIn(lootSeed, table, entryIndex, x, y, z, combinedRarity)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ public class IrisLootTable extends IrisRegistrant {
|
||||
return lootf;
|
||||
}
|
||||
|
||||
RNG rng = LootResolver.tableRng(lootSeed, this, x, y, z);
|
||||
RNG rng = art.arcane.iris.engine.loot.LootTables.rng(lootSeed, this, x, y, z);
|
||||
int m = 0;
|
||||
int c = 0;
|
||||
int mx = Math.max(0, LootResolver.inclusive(rng, getMinPicked(), getMaxPicked()));
|
||||
|
||||
@@ -78,7 +78,7 @@ public class IrisVanillaLootTable extends IrisLootTable {
|
||||
IrisLogging.warn("Unknown vanilla loot table " + lootTableKey);
|
||||
return new KList<>();
|
||||
}
|
||||
RNG rng = LootResolver.tableRng(lootSeed, this, x, y, z);
|
||||
RNG rng = art.arcane.iris.engine.loot.LootTables.rng(lootSeed, this, x, y, z);
|
||||
return new KList<>(table.populateLoot(rng, new LootContext.Builder(new Location(world, x, y, z)).build()));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user