Merge remote-tracking branch 'origin/master'

This commit is contained in:
SwiftSwamp committed 2026-11-01 10:16:11 -07:00
commit 8b99f0b75f
25 files changed
+1043 -84

No files matched your search

@@ -11,11 +11,15 @@ import art.arcane.volmlib.util.math.RNG;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockSupport;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.MultipleFacing;
import org.junit.Test;
import org.mockito.MockedStatic;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -25,15 +29,23 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
public class DecoratorCoreTest {
private static final String VINE = "minecraft:vine";
private static final String GLOW_LICHEN = "minecraft:glow_lichen";
private static final Set<BlockFace> VINE_FACES = EnumSet.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH,
BlockFace.WEST, BlockFace.UP);
private static final Set<BlockFace> LICHEN_FACES = EnumSet.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH,
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
@Test
public void partSeed_differsByPartOrdinal() {
@@ -741,6 +753,141 @@ public class DecoratorCoreTest {
}
}
@Test
public void stackedVineCurtainHangsFromTheWallItsTopStrandFaces() {
IrisDecorator decorator = mock(IrisDecorator.class);
IrisData data = mock(IrisData.class);
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
when(decorator.getTopThreshold()).thenReturn(1.0);
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
output.set(8, 6, 8, sturdyState());
output.set(8, 5, 7, sturdyState());
output.set(9, 4, 8, sturdyState());
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
new DecoratorCore.PlaceOpts(), null);
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 4, 8)));
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 3, 8)));
}
@Test
public void stackedVineCurtainHangsUnderAnOpenCeiling() {
IrisDecorator decorator = mock(IrisDecorator.class);
IrisData data = mock(IrisData.class);
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
when(decorator.getTopThreshold()).thenReturn(1.0);
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
output.set(8, 6, 8, sturdyState());
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
new DecoratorCore.PlaceOpts(), null);
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 4, 8)));
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 3, 8)));
}
@Test
public void unsupportedAuthoredSideFaceOnALoneVineIsDroppedAndReattached() {
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
Hunk<NativeBlockState> walled = Hunk.newArrayHunk(16, 8, 16);
walled.set(9, 3, 8, sturdyState());
assertEquals(EnumSet.of(BlockFace.EAST), faces(DecoratorCore.fixFacesForHunk(vine, walled, 8, 8, 8, 3, 8, null)));
assertEquals(EnumSet.of(BlockFace.UP),
faces(DecoratorCore.fixFacesForHunk(vine, Hunk.newArrayHunk(16, 8, 16), 8, 8, 8, 3, 8, null)));
}
@Test
public void glowLichenSideFaceIsNotHeldByTheLichenAboveIt() {
NativeBlockState lichen = facingState(GLOW_LICHEN, LICHEN_FACES, EnumSet.of(BlockFace.NORTH));
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
output.set(8, 2, 8, sturdyState());
output.set(8, 4, 8, facingState(GLOW_LICHEN, LICHEN_FACES, EnumSet.of(BlockFace.NORTH)));
assertEquals(EnumSet.of(BlockFace.DOWN), faces(DecoratorCore.fixFacesForHunk(lichen, output, 8, 8, 8, 3, 8, null)));
}
@Test
public void supportedAuthoredSideFaceKeepsItsDirection() {
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
output.set(8, 3, 7, sturdyState());
output.set(9, 3, 8, sturdyState());
assertEquals(EnumSet.of(BlockFace.NORTH), faces(DecoratorCore.fixFacesForHunk(vine, output, 8, 8, 8, 3, 8, null)));
}
@Test
public void vineWithoutAuthoredSideFaceReattachesToEverySturdyNeighbour() {
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.UP));
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
output.set(7, 3, 8, sturdyState());
output.set(8, 3, 9, sturdyState());
output.set(8, 4, 8, sturdyState());
assertEquals(EnumSet.of(BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP),
faces(DecoratorCore.fixFacesForHunk(vine, output, 8, 8, 8, 3, 8, null)));
}
private NativeBlockState facingState(String material, Set<BlockFace> allowed, Set<BlockFace> faces) {
MultipleFacing handle = facing(material, allowed, faces);
String key = handle.getAsString();
NativeBlockState state = mock(NativeBlockState.class);
when(state.isVineBlock()).thenReturn(true);
when(state.materialKey()).thenReturn(material);
when(state.key()).thenReturn(key);
when(state.nativeHandle()).thenReturn(handle);
return state;
}
private static MultipleFacing facing(String material, Set<BlockFace> allowed, Set<BlockFace> faces) {
EnumSet<BlockFace> current = EnumSet.noneOf(BlockFace.class);
current.addAll(faces);
MultipleFacing data = mock(MultipleFacing.class);
when(data.getAllowedFaces()).thenReturn(allowed);
when(data.getFaces()).thenAnswer(invocation -> EnumSet.copyOf(current));
when(data.hasFace(any(BlockFace.class))).thenAnswer(invocation -> current.contains(invocation.<BlockFace>getArgument(0)));
doAnswer(invocation -> {
BlockFace face = invocation.getArgument(0);
if (!allowed.contains(face)) {
throw new IllegalArgumentException(face + " is not allowed on " + material);
}
if (invocation.<Boolean>getArgument(1)) {
current.add(face);
} else {
current.remove(face);
}
return null;
}).when(data).setFace(any(BlockFace.class), anyBoolean());
when(data.clone()).thenAnswer(invocation -> facing(material, allowed, current));
when(data.getAsString()).thenAnswer(invocation -> {
StringBuilder key = new StringBuilder(material).append('[');
for (BlockFace face : allowed) {
if (key.charAt(key.length() - 1) != '[') {
key.append(',');
}
key.append(face.name().toLowerCase(Locale.ROOT)).append('=').append(current.contains(face));
}
return key.append(']').toString();
});
return data;
}
private static Set<BlockFace> faces(NativeBlockState state) {
EnumSet<BlockFace> faces = EnumSet.noneOf(BlockFace.class);
faces.addAll(((MultipleFacing) state.nativeHandle()).getFaces());
return faces;
}
private NativeBlockState airState() {
NativeBlockState air = mock(NativeBlockState.class);
when(air.isAir()).thenReturn(true);
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.plan;
import art.arcane.iris.generation.block.IrisBlockData;
import art.arcane.iris.generation.decoration.IrisDecorationPart;
import art.arcane.iris.generation.decoration.IrisDecorator;
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
@@ -17,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
@@ -250,6 +252,33 @@ public class HydrologySettingsTest {
assertRejected(config, "lava");
}
@Test
public void seamsLeaveTheFingerprintAlone() {
assertEquals(compile(lavaAndCrust(null)).fingerprint(), compile(lavaAndCrust("crust")).fingerprint());
assertEquals(Map.of("lava", "crust"), compile(lavaAndCrust("crust")).seams());
assertTrue(compile(lavaAndCrust(null)).seams().isEmpty());
}
@Test
public void compileRejectsAnUnknownSeam() {
assertRejected(lavaAndCrust("ash"), "ash");
}
@Test
public void compileRejectsASeamThatAlsoFillsWater() {
IrisHydrology tier = lavaAndCrust("crust");
tier.getTiers().get(2).setFluid("crust");
assertRejected(tier, "crust");
IrisHydrology ponds = lavaAndCrust("crust");
ponds.getPonds().setFluid("crust");
assertRejected(ponds, "crust");
IrisHydrology chained = lavaAndCrust("crust");
chained.getFluids().get(2).setSeam("lava");
assertRejected(chained, "crust");
}
@Test
public void compileRejectsMalformedRange() {
IrisHydrology inverted = new IrisHydrology();
@@ -554,6 +583,15 @@ public class HydrologySettingsTest {
assertTrue(failure.getMessage(), failure.getMessage().contains("\"palette\" list is missing, misspelt or empty"));
}
private static IrisHydrology lavaAndCrust(String seam) {
IrisHydrology config = new IrisHydrology();
config.getFluids().add(new IrisFluidProfile().setName("lava").setSeam(seam)
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
config.getFluids().add(new IrisFluidProfile().setName("crust")
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:obsidian")));
return config;
}
private static HydrologySettings compile(IrisHydrology config) {
return HydrologySettings.compile(config, SEED, SEA_LEVEL, MIN_Y, MAX_Y);
}
@@ -465,11 +465,14 @@ public class ChunkWaterRasterTest {
}
@Test
public void channelTakesTheAreaFluidWhereOneIsSet() {
public void reachKeepsThePolicyFluidOfItsUpstreamEnd() {
HydrologySettings settings = settings(new IrisHydrology());
Reach reach = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH);
Reach outflow = line(61L, stream, 0L, 400f, 403f, 480f, 403f, (x, z) -> 69);
Reach inflow = line(62L, stream, 0L, 480f, 412f, 400f, 412f, (x, z) -> 69);
WindowKey key = new WindowKey(0, 0);
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of(), List.of()), ReachIndex.build(List.of(reach), List.of()));
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of(), List.of()),
ReachIndex.build(List.of(outflow, inflow), List.of()));
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
int lava = 0;
@@ -479,9 +482,9 @@ public class ChunkWaterRasterTest {
if (!isChannel(raster.role(lx, lz))) {
continue;
}
boolean inside = 27 * 16 + lx < 440;
assertEquals("column " + lx + "," + lz, inside ? "lava" : "water", raster.fluid(lx, lz));
if (inside) {
boolean startsVolcanic = raster.featureId(lx, lz) == 61L;
assertEquals("column " + lx + "," + lz, startsVolcanic ? "lava" : "water", raster.fluid(lx, lz));
if (startsVolcanic) {
lava++;
} else {
water++;
@@ -0,0 +1,87 @@
package art.arcane.iris.generation.hydrology.raster;
import org.junit.Test;
import java.util.Map;
import java.util.function.IntFunction;
import java.util.function.IntPredicate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class FluidSeamsTest {
private static final long SEED = 4242L;
private static final Map<String, String> LAVA_CRUST = Map.of("lava", "crust");
@Test
public void lavaSealsEveryColumnTouchingWater() {
FluidSeams.Columns columns = columns(x -> x < 100 ? "lava" : "water", x -> false);
String[] sealed = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns);
int spread = 0;
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
int x = 96 + lx;
String seam = sealed[lz << 4 | lx];
if (x == 99) {
assertEquals("touching column " + x + "," + lz, "crust", seam);
} else if (x == 98) {
spread += seam == null ? 0 : 1;
} else {
assertNull("column " + x + "," + lz, seam);
}
}
}
assertTrue("spread columns " + spread, spread > 0 && spread < 16);
}
@Test
public void spreadReachesAcrossTheChunkEdge() {
FluidSeams.Columns columns = columns(x -> x < 97 ? "lava" : "water", x -> false);
int spread = 0;
int rows = 0;
for (int chunkZ = 0; chunkZ < 8; chunkZ++) {
String[] west = FluidSeams.seal(LAVA_CRUST, SEED, 5, chunkZ, columns);
String[] east = FluidSeams.seal(LAVA_CRUST, SEED, 6, chunkZ, columns);
for (int lz = 0; lz < 16; lz++) {
rows++;
assertEquals("crust", east[lz << 4]);
assertNull(west[lz << 4 | 14]);
spread += west[lz << 4 | 15] == null ? 0 : 1;
}
}
double fraction = spread / (double) rows;
assertTrue("spread fraction at the chunk edge " + fraction, fraction > 0.45D && fraction < 0.75D);
}
@Test
public void dryGroundBelowSeaLevelCountsAsTheSea() {
String[] sea = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> x >= 100));
for (int lz = 0; lz < 16; lz++) {
assertEquals("crust", sea[lz << 4 | 3]);
}
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> false)));
}
@Test
public void nothingSealsWithoutASeamOrAnotherFluid() {
assertNull(FluidSeams.seal(Map.of(), SEED, 6, 0, columns(x -> x < 100 ? "lava" : "water", x -> false)));
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "water", x -> true)));
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "lava", x -> false)));
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : "crust", x -> false)));
}
private static FluidSeams.Columns columns(IntFunction<String> fluid, IntPredicate sea) {
return new FluidSeams.Columns() {
@Override
public String fluid(int x, int z) {
return fluid.apply(x);
}
@Override
public boolean sea(int x, int z) {
return sea.test(x);
}
};
}
}
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.runtime;
import art.arcane.iris.generation.context.ChunkContext;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.hydrology.water.Pond;
import art.arcane.iris.generation.hydrology.water.Reach;
@@ -159,11 +160,25 @@ public class EffectiveWaterTest {
}
}
@Test
public void sealedColumnsTakeTheirSeamAndTheRestKeepTheRasterFluid() {
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
when(raster.fluid(anyInt(), anyInt())).thenReturn("lava");
String[] seams = new String[256];
seams[3 << 4 | 2] = "crust";
EffectiveWater.Chunk sealed = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, seams);
EffectiveWater.Chunk open = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, null);
assertEquals("crust", sealed.fluid(2, 3));
assertEquals("lava", sealed.fluid(3, 2));
assertEquals("lava", open.fluid(2, 3));
}
@Test
public void chunksSharingACacheSlotNeverAnswerForEachOther() {
EffectiveWater.Chunks chunks = new EffectiveWater.Chunks();
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
chunks.put(0, 0, first);
assertSame(first, chunks.get(0, 0));
@@ -24,6 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
@@ -39,6 +40,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class IrisComplexSurfaceBiomeTest {
private static final int INLAND_SEA_LEVEL = 85;
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
@Rule
@@ -208,6 +211,25 @@ public class IrisComplexSurfaceBiomeTest {
}
}
@Test(timeout = 120_000L)
public void pondAboveSeaLevelKeepsTheLandBiomeOverAFloorBelowIt() throws Exception {
Path pack = HydrologyFixture.pack(temporaryFolder.newFolder().toPath(), null, null);
Files.writeString(pack.resolve("dimensions/main.json"), """
{"regions":["plain"],"landChance":1,"fluidHeight":%d,"carvingEnabled":false}
""".formatted(INLAND_SEA_LEVEL));
Files.writeString(pack.resolve("regions/plain.json"), "{\"landBiomes\":[\"plain\"],\"seaBiomes\":[\"ocean\"]}");
Files.writeString(pack.resolve("biomes/ocean.json"), "{\"generators\":[{\"generator\":\"flat\",\"min\":10,\"max\":10}]}");
try (HydrologyFixture fixture = new HydrologyFixture(pack)) {
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(0, 0);
int sea = fixture.engine.getDimension().getFluidHeight();
assertEquals(WaterRole.POND, raster.role(8, 8));
assertTrue("the pond floor sits below sea level", raster.terrainHeight(8, 8) < sea);
assertTrue("the pond surface sits above sea level", raster.waterHead(8, 8) > sea);
assertTrue("the land around the pond sits above sea level", HydrologyFixture.NATURAL > sea);
assertEquals("plain", fixture.complex.getTrueBiomeStream().get(8, 8).getLoadKey());
}
}
private static int shoreColumn(HydrologyFixture fixture, int distance) {
for (int x = 0; x < 64; x++) {
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(x >> 4, 0);
@@ -93,6 +93,31 @@ public class PackHydrologyValidatorTest {
assertEquals(validation.errors().toString(), 6, validation.errors().size());
}
@Test
public void rejectsPoliciesThatFillWaterWithASeamProfile() throws Exception {
File pack = pack(dimension("""
{
"enabled": true,
"fluids": [
{"name": "water"},
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}, "seam": "crust"},
{"name": "crust", "palette": {"palette": [{"block": "minecraft:obsidian"}]}}
]
}
""", ""));
write(pack, "regions/region.json", """
{"landBiomes": ["biome"], "hydrologyPolicy": {"fluid": "lava"}}
""");
write(pack, "biomes/biome.json", """
{"name": "Biome", "hydrologyPolicy": {"fluid": "crust"}}
""");
List<String> errors = validate(pack).errors();
assertContains(errors, "Biome 'biome'.hydrologyPolicy.fluid names fluid 'crust', which is a seam profile");
assertEquals(errors.toString(), 1, errors.size());
}
@Test
public void rejectsFluidReferencesTheFluidProfilesDoNotDefine() throws Exception {
File pack = pack(dimension("""
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "2224e73a1e9d76231d4df8bb1992451340e5f533b3fbafae9f4e1437747e666c";
private static final String EXPECTED_SCHEMA_DIGEST = "0b7bc58cb81a7e630d13662b2157868bd306f3afef571942dc5b8e667323a250";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -0,0 +1,58 @@
package art.arcane.iris.world.entity;
import org.bukkit.SoundCategory;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
public class IrisEffectSoundCategoryTest {
private static final Map<String, SoundCategory> VANILLA_CATEGORIES = Map.ofEntries(
Map.entry("master", SoundCategory.MASTER),
Map.entry("music", SoundCategory.MUSIC),
Map.entry("record", SoundCategory.RECORDS),
Map.entry("weather", SoundCategory.WEATHER),
Map.entry("block", SoundCategory.BLOCKS),
Map.entry("hostile", SoundCategory.HOSTILE),
Map.entry("neutral", SoundCategory.NEUTRAL),
Map.entry("player", SoundCategory.PLAYERS),
Map.entry("ambient", SoundCategory.AMBIENT),
Map.entry("voice", SoundCategory.VOICE),
Map.entry("ui", SoundCategory.UI));
@Test
public void soundCategoryIsStoredAsAPlainStringField() throws NoSuchFieldException {
assertEquals(String.class, IrisEffect.class.getDeclaredField("soundCategory").getType());
}
@Test
public void soundCategoryDefaultsToMaster() {
assertEquals("master", new IrisEffect().getSoundCategoryKey());
assertEquals("master", new IrisEffect().setSoundCategory(null).getSoundCategoryKey());
assertEquals("master", new IrisEffect().setSoundCategory(" ").getSoundCategoryKey());
}
@Test
public void soundCategoryKeyIgnoresCaseAndSurroundingSpace() {
assertEquals("ambient", new IrisEffect().setSoundCategory(" Ambient ").getSoundCategoryKey());
assertEquals("music", new IrisEffect().setSoundCategory("MUSIC").getSoundCategoryKey());
}
@Test
public void everyVanillaCategoryNameResolvesToItsBukkitCategory() {
for (Map.Entry<String, SoundCategory> entry : VANILLA_CATEGORIES.entrySet()) {
assertSame(entry.getKey(), entry.getValue(), IrisEffect.bukkitSoundCategory(entry.getKey()));
}
assertEquals(SoundCategory.values().length, VANILLA_CATEGORIES.size());
}
@Test
public void unknownCategoryNamesDoNotResolve() {
assertNull(IrisEffect.bukkitSoundCategory("ambiant"));
assertNull(IrisEffect.bukkitSoundCategory("records"));
assertNull(IrisEffect.bukkitSoundCategory("players"));
}
}