mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Type platform keys and fold pack references into @Ref(kind)
Batch 6, findings 41 and 42. - Platform keys travel as ResourceId: enchantments, attributes, sounds, particles, potions, loot tables, sapling species, marker tags, upper dimension ids and jigsaw start pools. ResourceId.ofPlatformKey normalises a key a pack wrote. - Item and entity types are a ContentKey (Registered id, or Provided provider and name) instead of strings and a special-type flag. - ItemDrop groups into Look, Wear and PlatformExtras; colours are an RGB int and DyeColor, attribute operations an enum. - EntitySpec groups into Appearance, Behaviour, Company, Drops and Arrival, and carries host extensions instead of Iris-only fields. - @Ref(kind = Type.class) replaces @ResourceRef and the PACK_* references; expressions and image maps become the host kinds EXPRESSIONS and IMAGE_MAPS.
This commit is contained in:
1 parent
05f621d82d
commit
6b24e6f150
31 files changed
+620
-295
No files matched your search
@@ -4,6 +4,8 @@ import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.item.ItemDrop;
|
||||
import com.volmit.item.ItemEnchantment;
|
||||
import com.volmit.resource.ContentKey;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.AmbientEffects;
|
||||
import com.volmit.service.BlockDrops;
|
||||
import com.volmit.service.EntitySpawns;
|
||||
@@ -12,55 +14,71 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** The values services hand the host are immutable and refuse what the host could not create. */
|
||||
class ItemAndEntityValuesTest {
|
||||
private static final ContentKey STICK = new ContentKey.Registered(ResourceId.parse("minecraft:stick"));
|
||||
private static final ResourceId SHARPNESS = ResourceId.parse("minecraft:sharpness");
|
||||
|
||||
@Test
|
||||
void anItemDropRefusesNothingToDropAndKeepsItsListsApart() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ItemDrop.of("stick", 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> ItemDrop.of(STICK, 0));
|
||||
|
||||
List<ItemEnchantment> enchantments = new ArrayList<>(List.of(new ItemEnchantment("sharpness", 3)));
|
||||
ItemDrop drop = new ItemDrop("diamond_sword", 1, Optional.empty(), List.of(), enchantments, List.of(), false, List.of(),
|
||||
OptionalInt.empty(), OptionalDouble.of(0.25), Optional.empty(), Optional.empty(), Map.of(), Optional.empty());
|
||||
List<ItemEnchantment> enchantments = new ArrayList<>(List.of(new ItemEnchantment(SHARPNESS, 3)));
|
||||
ItemDrop drop = new ItemDrop(STICK, 1, ItemDrop.Look.PLAIN, enchantments, List.of(),
|
||||
new ItemDrop.Wear(false, OptionalDouble.of(0.25)), ItemDrop.PlatformExtras.NONE, Optional.empty());
|
||||
enchantments.clear();
|
||||
|
||||
assertEquals(1, drop.enchantments().size());
|
||||
assertThrows(UnsupportedOperationException.class, () -> drop.enchantments().clear());
|
||||
assertThrows(IllegalArgumentException.class, () -> new ItemEnchantment("sharpness", 0));
|
||||
assertThrows(IllegalArgumentException.class, () -> new ItemEnchantment(SHARPNESS, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void absentValuesAreEmptyNeverNull() {
|
||||
ItemDrop stick = ItemDrop.of("stick", 1);
|
||||
ItemDrop stick = ItemDrop.of(STICK, 1);
|
||||
|
||||
assertTrue(stick.displayName().isEmpty());
|
||||
assertTrue(stick.damage().isEmpty());
|
||||
assertTrue(stick.look().displayName().isEmpty());
|
||||
assertTrue(stick.wear().damage().isEmpty());
|
||||
assertTrue(stick.source().isEmpty());
|
||||
assertThrows(NullPointerException.class, () -> new ItemDrop("stick", 1, null, List.of(), List.of(), List.of(), false,
|
||||
List.of(), OptionalInt.empty(), OptionalDouble.empty(), Optional.empty(), Optional.empty(), Map.of(), Optional.empty()));
|
||||
assertThrows(NullPointerException.class, () -> new ItemDrop(STICK, 1, null, List.of(), List.of(), ItemDrop.Wear.NEW,
|
||||
ItemDrop.PlatformExtras.NONE, Optional.empty()));
|
||||
assertThrows(NullPointerException.class, () -> new AmbientEffects.Effect(null, Optional.empty(), List.of(), Optional.empty()));
|
||||
assertThrows(NullPointerException.class, () -> new EntitySpawns.MarkerRule(null, false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEntityKnowsWhetherItIsAnotherPluginsMob() {
|
||||
EntitySpec zombie = entity(Optional.of("minecraft:zombie"), Optional.empty());
|
||||
EntitySpec special = entity(Optional.empty(), Optional.of("mythic:dragon"));
|
||||
void aProvidedKeyKeepsTheProvidersNameAsWrittenAndRefusesABlankOne() {
|
||||
ContentKey mob = new ContentKey.Provided("mmoitems_SWORD", "EXCALIBUR:Gold");
|
||||
|
||||
assertFalse(zombie.isSpecial());
|
||||
assertTrue(special.isSpecial());
|
||||
assertEquals("mmoitems_SWORD:EXCALIBUR:Gold", mob.toString());
|
||||
assertThrows(IllegalArgumentException.class, () -> new ContentKey.Provided("mythicmobs", " "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPlatformKeyAsPacksWriteItBecomesAMinecraftIdUnlessItNamesANamespace() {
|
||||
assertEquals(ResourceId.parse("minecraft:diamond_sword"), ResourceId.ofPlatformKey(" DIAMOND_SWORD "));
|
||||
assertEquals(ResourceId.parse("minecraft:fire_protection"), ResourceId.ofPlatformKey("Fire Protection"));
|
||||
assertEquals(ResourceId.parse("mymod:vorpal"), ResourceId.ofPlatformKey("mymod:vorpal"));
|
||||
assertThrows(IllegalArgumentException.class, () -> ResourceId.ofPlatformKey("a:b:c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEntityHandsAHostTheExtensionItReadsAndNothingForAnotherType() {
|
||||
EntitySpec zombie = entity(List.of("iris extras"));
|
||||
|
||||
assertEquals(Optional.of("iris extras"), zombie.extension(String.class));
|
||||
assertEquals(Optional.empty(), zombie.extension(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAttemptSaysWhetherLightMatters() {
|
||||
BlockPosition at = new BlockPosition(1, 2, 3);
|
||||
EntitySpec zombie = entity(Optional.of("minecraft:zombie"), Optional.empty());
|
||||
EntitySpec zombie = entity(List.of());
|
||||
|
||||
assertFalse(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 15, true).restrictsLight());
|
||||
assertTrue(new EntitySpawns.Attempt(at, zombie, EntitySpawns.Surface.LAND, 0, 7, true).restrictsLight());
|
||||
@@ -79,7 +97,7 @@ class ItemAndEntityValuesTest {
|
||||
List<AmbientEffects.Command> commands = new ArrayList<>(List.of(
|
||||
new AmbientEffects.Command(new EntitySpec.Command(List.of("say hi"), 0, false, 100), 1, 0, -1)));
|
||||
AmbientEffects.Effect effect = new AmbientEffects.Effect(Optional.empty(), Optional.empty(), commands,
|
||||
Optional.of(new AmbientEffects.Potion("luck", 0, 100)));
|
||||
Optional.of(new AmbientEffects.Potion(ResourceId.parse("minecraft:luck"), 0, 100)));
|
||||
commands.clear();
|
||||
|
||||
assertEquals(1, effect.commands().size());
|
||||
@@ -88,9 +106,9 @@ class ItemAndEntityValuesTest {
|
||||
assertThrows(NullPointerException.class, () -> new AmbientEffects.Command(null, 0, 0, 0));
|
||||
}
|
||||
|
||||
private static EntitySpec entity(Optional<String> type, Optional<String> specialType) {
|
||||
return new EntitySpec(type, specialType, Optional.empty(), Optional.empty(), new EntitySpec.Flags(false, true, true, false,
|
||||
true, false, false, false, false, false, false), EntitySpec.Equipment.NONE, List.of(), List.of(), List.of(), 0L,
|
||||
Optional.empty(), Optional.empty(), false, Optional.empty(), Optional.empty(), false, List.of());
|
||||
private static EntitySpec entity(List<Object> extensions) {
|
||||
return new EntitySpec(new ContentKey.Registered(ResourceId.parse("minecraft:zombie")), EntitySpec.Appearance.PLAIN,
|
||||
EntitySpec.Behaviour.NATURAL, EntitySpec.Equipment.NONE, List.of(), EntitySpec.Company.NONE,
|
||||
EntitySpec.Drops.PLATFORM, EntitySpec.Arrival.QUIET, extensions);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user