mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Loot and block drops ask the Loot and BlockDrops services
EngineBukkitOps, WorldObjectPlacer and WorldBlockDropRouter no longer read loot classes: the modules name the tables and return resolved ItemDrops, which BukkitItemStacks creates. LootResolver keeps the generic stream helpers; table resolution moved to LootTables in iris:loot. IrisLootEvent carries the Loot sources.
This commit is contained in:
1 parent
8137f6dba9
commit
946ad61f7f
22 files changed
+714
-261
No files matched your search
@@ -19,10 +19,13 @@
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.framework.structure.StructureLocating;
|
||||
import art.arcane.iris.engine.loot.LootGiving;
|
||||
import art.arcane.iris.engine.mantle.components.StructureModule;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.host.FeatureCatalog;
|
||||
import com.volmit.host.LifecycleRegistration;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import org.junit.Test;
|
||||
@@ -41,6 +44,13 @@ public class BuiltInServicesTest {
|
||||
assertEquals(1, BUILT_INS.services(ObjectsAt.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lootAndBlockDropsComeFromTheLootModule() {
|
||||
assertEquals(1, BUILT_INS.services(Loot.class).size());
|
||||
assertEquals(1, BUILT_INS.services(BlockDrops.class).size());
|
||||
assertTrue(BUILT_INS.services(Loot.class).getFirst() instanceof LootGiving);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresAreFoundThroughTheStructureModule() {
|
||||
List<StructureLocator> locators = BUILT_INS.services(StructureLocator.class);
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.entity.IrisAttributeModifier;
|
||||
import art.arcane.iris.engine.object.loot.IrisEnchantment;
|
||||
import art.arcane.iris.engine.object.loot.IrisLoot;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootTable;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Loot entries turn into items with the random choices made in Iris's order: amount, enchantments, attributes, damage. */
|
||||
public class LootItemsTest {
|
||||
private static final long LOOT_SEED = 77L;
|
||||
|
||||
private ItemRegistry registry;
|
||||
|
||||
@Before
|
||||
public void knowTheItems() {
|
||||
registry = mock(ItemRegistry.class);
|
||||
when(registry.maxDurability(anyString())).thenReturn(OptionalInt.empty());
|
||||
when(registry.maxDurability("diamond_sword")).thenReturn(OptionalInt.of(1561));
|
||||
when(registry.maxDurability("diamond")).thenReturn(OptionalInt.of(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anEntryDrawsAmountEnchantmentsAttributesAndDamageFromOneStreamInThatOrder() {
|
||||
IrisLoot entry = new IrisLoot().setType("diamond_sword").setMinAmount(1).setMaxAmount(3)
|
||||
.setMinDurability(0.25).setMaxDurability(0.75)
|
||||
.setEnchantments(new KList<>(new IrisEnchantment("sharpness", 1, 5, 1D)))
|
||||
.setAttributes(new KList<>(new IrisAttributeModifier("max_health", "bonus", "ADD_NUMBER", 2, 6, 1D)));
|
||||
RNG expected = new RNG(5L);
|
||||
int amount = (int) (1 + expected.nextLong(3));
|
||||
expected.nextDouble();
|
||||
int level = (int) (1 + expected.nextLong(5));
|
||||
expected.nextDouble();
|
||||
double bonus = expected.d(2, 6);
|
||||
double damage = 1D - expected.d(0.25, 0.75);
|
||||
|
||||
ItemDrop drop = new LootItems(registry, false).give(entry, new RNG(5L));
|
||||
|
||||
assertEquals(amount, drop.amount());
|
||||
assertEquals(level, drop.enchantments().getFirst().level());
|
||||
assertEquals(bonus, drop.attributes().getFirst().amount(), 0D);
|
||||
assertEquals(damage, drop.damage(), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anItemThatCannotBeDamagedDrawsNoDamageAndKeepsTheStreamAligned() {
|
||||
IrisLoot entry = new IrisLoot().setType("diamond").setMinAmount(2).setMaxAmount(2);
|
||||
RNG rng = new RNG(9L);
|
||||
RNG untouched = new RNG(9L);
|
||||
|
||||
ItemDrop drop = new LootItems(registry, false).give(entry, rng);
|
||||
|
||||
assertEquals(2, drop.amount());
|
||||
assertNull(drop.damage());
|
||||
assertEquals(untouched.nextLong(), rng.nextLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anItemThePlatformDoesNotKnowIsNotGivenAndDrawsNothing() {
|
||||
RNG rng = new RNG(9L);
|
||||
RNG untouched = new RNG(9L);
|
||||
|
||||
assertNull(new LootItems(registry, false).give(new IrisLoot().setType("not_an_item"), rng));
|
||||
assertNull(new LootItems(registry, false).give(new IrisLoot().setType("air"), rng));
|
||||
assertEquals(untouched.nextLong(), rng.nextLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void debugItemsSayWhereTheyCameFrom() {
|
||||
IrisLootTable table = new IrisLootTable().setName("dungeon").setRarity(4);
|
||||
table.setLoot(new KList<>(new IrisLoot().setType("diamond").setRarity(3)));
|
||||
table.setMinPicked(1).setMaxPicked(1);
|
||||
|
||||
List<ItemDrop> drops = new LootItems(registry, true).draw(table, LOOT_SEED, 0, 64, 0);
|
||||
|
||||
for (ItemDrop drop : drops) {
|
||||
assertEquals(new ItemDrop.Source("dungeon", 4, 3), drop.source());
|
||||
}
|
||||
assertTrue(new LootItems(registry, false).draw(table, LOOT_SEED, 0, 64, 0).stream().allMatch(drop -> drop.source() == null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTableGivesTheSameItemsAtTheSameSpotAndSeed() {
|
||||
IrisLootTable table = new IrisLootTable().setName("tools").setMinPicked(2).setMaxPicked(4);
|
||||
table.setLoot(new KList<>(new IrisLoot().setType("diamond").setMaxAmount(5), new IrisLoot().setType("diamond_sword")));
|
||||
|
||||
LootItems items = new LootItems(registry, false);
|
||||
|
||||
assertEquals(items.draw(table, LOOT_SEED, 10, 64, -30), items.draw(table, LOOT_SEED, 10, 64, -30));
|
||||
}
|
||||
}
|
||||
+16
-13
@@ -1,7 +1,9 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
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.IrisComplex;
|
||||
import art.arcane.iris.engine.object.loot.InventorySlotType;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.loot.IrisLootMode;
|
||||
@@ -12,6 +14,7 @@ import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -70,12 +73,12 @@ public class LootResolverTest {
|
||||
IrisLootTable first = new IrisLootTable().setName("first");
|
||||
IrisLootTable second = new IrisLootTable().setName("second");
|
||||
|
||||
long baseline = LootResolver.tableSeed(41L, first, 0, 64, 0);
|
||||
long baseline = LootTables.seed(41L, first, 0, 64, 0);
|
||||
|
||||
assertEquals(baseline, LootResolver.tableSeed(41L, first, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootResolver.tableSeed(42L, first, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootResolver.tableSeed(41L, second, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootResolver.tableSeed(41L, first, 16, 64, 0));
|
||||
assertEquals(baseline, LootTables.seed(41L, first, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootTables.seed(42L, first, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootTables.seed(41L, second, 0, 64, 0));
|
||||
assertNotEquals(baseline, LootTables.seed(41L, first, 16, 64, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +87,7 @@ public class LootResolverTest {
|
||||
int successes = 0;
|
||||
|
||||
for (int x = 0; x < 65_536; x++) {
|
||||
if (LootResolver.spatialOneIn(91L, table, 3, x, 40, x * 31, 8L)) {
|
||||
if (LootTables.spatialOneIn(91L, table, 3, x, 40, x * 31, 8L)) {
|
||||
successes++;
|
||||
}
|
||||
}
|
||||
@@ -92,8 +95,8 @@ public class LootResolverTest {
|
||||
assertTrue(successes > 7_600);
|
||||
assertTrue(successes < 8_800);
|
||||
assertEquals(
|
||||
LootResolver.spatialOneIn(91L, table, 3, 112, 40, 992, 8L),
|
||||
LootResolver.spatialOneIn(91L, table, 3, 112, 40, 992, 8L)
|
||||
LootTables.spatialOneIn(91L, table, 3, 112, 40, 992, 8L),
|
||||
LootTables.spatialOneIn(91L, table, 3, 112, 40, 992, 8L)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ public class LootResolverTest {
|
||||
ResolutionFixture fixture = new ResolutionFixture();
|
||||
List<IrisLootTable> sources = new ArrayList<>();
|
||||
|
||||
LootResolver.resolveEnvironmentSources(
|
||||
LootTables.resolveEnvironmentSources(
|
||||
sources,
|
||||
fixture.engine,
|
||||
new RNG(19L),
|
||||
@@ -121,7 +124,7 @@ public class LootResolverTest {
|
||||
ResolutionFixture fixture = new ResolutionFixture();
|
||||
List<IrisLootTable> sources = new ArrayList<>();
|
||||
|
||||
LootResolver.resolveEnvironmentSources(
|
||||
LootTables.resolveEnvironmentSources(
|
||||
sources,
|
||||
fixture.engine,
|
||||
new RNG(19L),
|
||||
@@ -247,7 +250,7 @@ public class LootResolverTest {
|
||||
public void emptyLootTableReturnsNoItems() {
|
||||
IrisLootTable table = new IrisLootTable().setName("empty");
|
||||
|
||||
assertTrue(table.getLoot(false, 7L, InventorySlotType.STORAGE, null, 0, 64, 0).isEmpty());
|
||||
assertTrue(new LootItems(mock(ItemRegistry.class), false).draw(table, 7L, 0, 64, 0).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package art.arcane.iris.engine.framework;
|
||||
package art.arcane.iris.engine.loot;
|
||||
|
||||
import art.arcane.iris.engine.object.loot.IrisLootMode;
|
||||
import org.junit.Test;
|
||||
@@ -9,22 +9,22 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LootResolverClearModeTest {
|
||||
public class LootTablesClearModeTest {
|
||||
@Test
|
||||
public void clearSuppressesItsOwnTablesAndReplaceDoesNot() {
|
||||
List<String> cleared = new ArrayList<>(List.of("placement", "dimension"));
|
||||
LootResolver.injectSources(cleared, List.of("biome"), IrisLootMode.CLEAR, false);
|
||||
LootTables.injectSources(cleared, List.of("biome"), IrisLootMode.CLEAR, false);
|
||||
assertTrue("CLEAR must clear parents and contribute nothing", cleared.isEmpty());
|
||||
|
||||
List<String> replaced = new ArrayList<>(List.of("placement", "dimension"));
|
||||
LootResolver.injectSources(replaced, List.of("biome"), IrisLootMode.REPLACE, false);
|
||||
LootTables.injectSources(replaced, List.of("biome"), IrisLootMode.REPLACE, false);
|
||||
assertEquals(List.of("biome"), replaced);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearIgnoresTheFallbackFlag() {
|
||||
List<String> sources = new ArrayList<>(List.of("placement"));
|
||||
LootResolver.injectSources(sources, List.of("biome"), IrisLootMode.CLEAR, true);
|
||||
LootTables.injectSources(sources, List.of("biome"), IrisLootMode.CLEAR, true);
|
||||
assertTrue(sources.isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user