Fixed effect sounds and vines

- Store the effect sound category as a vanilla category name
- Resolve the sound category to a Bukkit category when an effect plays
- Send modded effect sounds on the authored category
- Skip the sound and warn once for an unknown sound category
- Keep authored vine side faces only where a sturdy block or the vine above holds them
- Attach kept vine faces upward under a sturdy block
- Reattach multi-face blocks with no holdable side face to sturdy neighbours
- Cover sound category and vine face rules on Bukkit and modded
- Repin the studio schema digest
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-31 21:58:58 -04:00
1 parent 64dc22025e
commit c2eb8b5f42
8 files changed
+498 -26

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,121 @@ 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 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);
@@ -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 = "f7890d23da41a0411eb92828d59c68d89ecc9ca266b357a9fd5d92107a9da4a5";
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"));
}
}