mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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:
1 parent
64dc22025e
commit
c2eb8b5f42
8 files changed
+498
-26
No files matched your search
+10
-1
@@ -55,6 +55,7 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
|||||||
private static final double PLAYER_REFRESH_CHANCE = 0.02D;
|
private static final double PLAYER_REFRESH_CHANCE = 0.02D;
|
||||||
private static final Set<String> UNKNOWN_POTIONS = ConcurrentHashMap.newKeySet();
|
private static final Set<String> UNKNOWN_POTIONS = ConcurrentHashMap.newKeySet();
|
||||||
private static final Set<String> UNKNOWN_SOUNDS = ConcurrentHashMap.newKeySet();
|
private static final Set<String> UNKNOWN_SOUNDS = ConcurrentHashMap.newKeySet();
|
||||||
|
private static final Set<String> UNKNOWN_SOUND_CATEGORIES = ConcurrentHashMap.newKeySet();
|
||||||
private static final Set<String> UNKNOWN_PARTICLES = ConcurrentHashMap.newKeySet();
|
private static final Set<String> UNKNOWN_PARTICLES = ConcurrentHashMap.newKeySet();
|
||||||
private static final Set<String> UNSUPPORTED_PARTICLES = ConcurrentHashMap.newKeySet();
|
private static final Set<String> UNSUPPORTED_PARTICLES = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
@@ -252,6 +253,14 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
|||||||
warnUnknown(UNKNOWN_SOUNDS, "sound", key);
|
warnUnknown(UNKNOWN_SOUNDS, "sound", key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String categoryKey = effect.getSoundCategoryKey();
|
||||||
|
NativePlayerEffects.SoundCategory category = NativePlayerEffects.soundCategory(categoryKey);
|
||||||
|
if (category == null) {
|
||||||
|
if (UNKNOWN_SOUND_CATEGORIES.add(categoryKey)) {
|
||||||
|
IrisLogging.warn("Unknown sound category: \"" + categoryKey + "\".");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int distance = effect.getSoundDistance();
|
int distance = effect.getSoundDistance();
|
||||||
double x = player.x() + RNG.r.i(-distance, distance);
|
double x = player.x() + RNG.r.i(-distance, distance);
|
||||||
@@ -260,7 +269,7 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
|||||||
float volume = (float) effect.getVolume();
|
float volume = (float) effect.getVolume();
|
||||||
float pitch = (float) RNG.r.d(effect.getMinPitch(), effect.getMaxPitch());
|
float pitch = (float) RNG.r.d(effect.getMinPitch(), effect.getMaxPitch());
|
||||||
NativePlayerEffects.sound(player, sound, new NativePlayerEffects.SoundEmission(
|
NativePlayerEffects.sound(player, sound, new NativePlayerEffects.SoundEmission(
|
||||||
x, y, z, volume, pitch, ThreadLocalRandom.current().nextLong()));
|
category, x, y, z, volume, pitch, ThreadLocalRandom.current().nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyParticles(NativeWorld level, NativeProtocolPlayer player, IrisEffect effect) {
|
private void applyParticles(NativeWorld level, NativeProtocolPlayer player, IrisEffect effect) {
|
||||||
|
|||||||
+127
@@ -1,14 +1,32 @@
|
|||||||
package art.arcane.iris.modded;
|
package art.arcane.iris.modded;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||||
|
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeBlockFaces;
|
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeBlockFaces;
|
||||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||||
import art.arcane.volmlib.util.hunk.Hunk;
|
import art.arcane.volmlib.util.hunk.Hunk;
|
||||||
|
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||||
|
import art.arcane.volmlib.util.matter.Matter;
|
||||||
|
import net.minecraft.SharedConstants;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.server.Bootstrap;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||||
|
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.mockStatic;
|
import static org.mockito.Mockito.mockStatic;
|
||||||
@@ -17,6 +35,12 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class ModdedDecoratorHooksTest {
|
public class ModdedDecoratorHooksTest {
|
||||||
|
@BeforeClass
|
||||||
|
public static void bootstrap() {
|
||||||
|
SharedConstants.tryDetectVersion();
|
||||||
|
Bootstrap.bootStrap();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void faceFixingExcludesTheUpperBoundaryWhileKeepingTheLastRowAccessible() {
|
public void faceFixingExcludesTheUpperBoundaryWhileKeepingTheLastRowAccessible() {
|
||||||
NativeBlockState state = mock(NativeBlockState.class);
|
NativeBlockState state = mock(NativeBlockState.class);
|
||||||
@@ -41,4 +65,107 @@ public class ModdedDecoratorHooksTest {
|
|||||||
verify(hunk, never()).get(1, 4, 2);
|
verify(hunk, never()).get(1, 4, 2);
|
||||||
verify(hunk).get(1, 3, 2);
|
verify(hunk).get(1, 3, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void stackedVineCurtainHangsFromTheWallItsTopStrandFaces() {
|
||||||
|
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||||
|
hunk.set(8, 6, 8, stone());
|
||||||
|
hunk.set(8, 5, 7, stone());
|
||||||
|
hunk.set(9, 4, 8, stone());
|
||||||
|
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||||
|
|
||||||
|
for (int y = 5; y >= 3; y--) {
|
||||||
|
hunk.set(8, y, 8, fix(vine, hunk, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(EnumSet.of(Direction.NORTH, Direction.UP), faces(hunk.get(8, 5, 8)));
|
||||||
|
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 4, 8)));
|
||||||
|
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 3, 8)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unsupportedAuthoredSideFaceOnALoneVineIsDroppedAndReattached() {
|
||||||
|
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||||
|
Hunk<NativeBlockState> walled = Hunk.newArrayHunk(16, 8, 16);
|
||||||
|
walled.set(9, 3, 8, stone());
|
||||||
|
|
||||||
|
assertEquals(EnumSet.of(Direction.EAST), faces(fix(vine, walled, 3)));
|
||||||
|
assertEquals(EnumSet.of(Direction.UP), faces(fix(vine, Hunk.newArrayHunk(16, 8, 16), 3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void glowLichenSideFaceIsNotHeldByTheLichenAboveIt() {
|
||||||
|
NativeBlockState lichen = state(Blocks.GLOW_LICHEN, Direction.NORTH);
|
||||||
|
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||||
|
hunk.set(8, 2, 8, stone());
|
||||||
|
hunk.set(8, 4, 8, state(Blocks.GLOW_LICHEN, Direction.NORTH));
|
||||||
|
|
||||||
|
assertEquals(EnumSet.of(Direction.DOWN), faces(fix(lichen, hunk, 3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void supportedAuthoredSideFaceKeepsItsDirection() {
|
||||||
|
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||||
|
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||||
|
hunk.set(8, 3, 7, stone());
|
||||||
|
hunk.set(9, 3, 8, stone());
|
||||||
|
|
||||||
|
assertEquals(EnumSet.of(Direction.NORTH), faces(fix(vine, hunk, 3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void vineWithoutAuthoredSideFaceReattachesToEverySturdyNeighbour() {
|
||||||
|
NativeBlockState vine = state(Blocks.VINE, Direction.UP);
|
||||||
|
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||||
|
hunk.set(7, 3, 8, stone());
|
||||||
|
hunk.set(8, 3, 9, stone());
|
||||||
|
hunk.set(8, 4, 8, stone());
|
||||||
|
|
||||||
|
assertEquals(EnumSet.of(Direction.SOUTH, Direction.WEST, Direction.UP), faces(fix(vine, hunk, 3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static NativeBlockState fix(NativeBlockState state, Hunk<NativeBlockState> hunk, int y) {
|
||||||
|
EngineMantle mantle = mock(EngineMantle.class);
|
||||||
|
Mantle<Matter> storage = mock(Mantle.class);
|
||||||
|
NativeBlockState air = ModdedBlockState.of(Blocks.AIR.defaultBlockState(), null);
|
||||||
|
when(mantle.getMantle()).thenReturn(storage);
|
||||||
|
when(storage.get(anyInt(), anyInt(), anyInt(), eq(NativeBlockState.class))).thenReturn(air);
|
||||||
|
return new ModdedDecoratorHooks().fixFaces(state, hunk, 8, 8, 8, y, 8, mantle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NativeBlockState stone() {
|
||||||
|
return ModdedBlockState.of(Blocks.STONE.defaultBlockState(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NativeBlockState state(Block block, Direction... faces) {
|
||||||
|
BlockState state = block.defaultBlockState();
|
||||||
|
for (Direction face : faces) {
|
||||||
|
state = state.setValue(property(face), Boolean.TRUE);
|
||||||
|
}
|
||||||
|
return ModdedBlockState.of(state, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<Direction> faces(NativeBlockState state) {
|
||||||
|
BlockState handle = (BlockState) state.nativeHandle();
|
||||||
|
EnumSet<Direction> faces = EnumSet.noneOf(Direction.class);
|
||||||
|
for (Direction face : Direction.values()) {
|
||||||
|
BooleanProperty property = property(face);
|
||||||
|
if (handle.hasProperty(property) && handle.getValue(property)) {
|
||||||
|
faces.add(face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return faces;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BooleanProperty property(Direction face) {
|
||||||
|
return switch (face) {
|
||||||
|
case NORTH -> BlockStateProperties.NORTH;
|
||||||
|
case EAST -> BlockStateProperties.EAST;
|
||||||
|
case SOUTH -> BlockStateProperties.SOUTH;
|
||||||
|
case WEST -> BlockStateProperties.WEST;
|
||||||
|
case UP -> BlockStateProperties.UP;
|
||||||
|
case DOWN -> BlockStateProperties.DOWN;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
package art.arcane.volmlib.nativelib.minecraft26_2.modded;
|
||||||
|
|
||||||
|
import art.arcane.iris.world.entity.IrisEffect;
|
||||||
|
import net.minecraft.SharedConstants;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||||
|
import net.minecraft.server.Bootstrap;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||||
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
public class NativePlayerEffectsTest {
|
||||||
|
private static final String SOUND = "minecraft:block.amethyst_block.chime";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void bootstrap() {
|
||||||
|
SharedConstants.tryDetectVersion();
|
||||||
|
Bootstrap.bootStrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void everyVanillaSoundSourceIsReachableByItsName() {
|
||||||
|
for (SoundSource source : SoundSource.values()) {
|
||||||
|
assertSame(source.getName(), source, sentSource(NativePlayerEffects.soundCategory(source.getName())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void effectCategoryNamesResolveIgnoringCase() {
|
||||||
|
assertSame(SoundSource.AMBIENT, sentSource(category(" Ambient ")));
|
||||||
|
assertSame(SoundSource.RECORDS, sentSource(category("RECORD")));
|
||||||
|
assertSame(SoundSource.MASTER, sentSource(category(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unknownCategoryNamesDoNotResolve() {
|
||||||
|
assertNull(category("ambiant"));
|
||||||
|
assertNull(category("records"));
|
||||||
|
assertNull(category("players"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NativePlayerEffects.SoundCategory category(String authored) {
|
||||||
|
return NativePlayerEffects.soundCategory(new IrisEffect().setSoundCategory(authored).getSoundCategoryKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SoundSource sentSource(NativePlayerEffects.SoundCategory category) {
|
||||||
|
assertNotNull(category);
|
||||||
|
NativePlayerEffects.Sound sound = NativePlayerEffects.sound(SOUND);
|
||||||
|
assertNotNull(sound);
|
||||||
|
ServerPlayer handle = mock(ServerPlayer.class);
|
||||||
|
ServerGamePacketListenerImpl connection = mock(ServerGamePacketListenerImpl.class);
|
||||||
|
handle.connection = connection;
|
||||||
|
|
||||||
|
NativePlayerEffects.sound(NativeProtocolPlayer.fromHandle(handle), sound,
|
||||||
|
new NativePlayerEffects.SoundEmission(category, 1.0D, 64.0D, -3.0D, 1.0F, 1.0F, 7L));
|
||||||
|
|
||||||
|
ArgumentCaptor<ClientboundSoundPacket> packet = ArgumentCaptor.forClass(ClientboundSoundPacket.class);
|
||||||
|
verify(connection).send(packet.capture());
|
||||||
|
return packet.getValue().getSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,7 @@ final class DecoratorCore {
|
|||||||
|
|
||||||
private static final long SEED_OFFSET = 29356788L;
|
private static final long SEED_OFFSET = 29356788L;
|
||||||
private static final long PART_FACTOR = 10439677L;
|
private static final long PART_FACTOR = 10439677L;
|
||||||
|
private static final String VINE = "minecraft:vine";
|
||||||
private static final String WEEPING_VINES = "minecraft:weeping_vines";
|
private static final String WEEPING_VINES = "minecraft:weeping_vines";
|
||||||
private static final String WEEPING_VINES_PLANT = "minecraft:weeping_vines_plant";
|
private static final String WEEPING_VINES_PLANT = "minecraft:weeping_vines_plant";
|
||||||
private static final String TWISTING_VINES = "minecraft:twisting_vines";
|
private static final String TWISTING_VINES = "minecraft:twisting_vines";
|
||||||
@@ -454,22 +455,20 @@ final class DecoratorCore {
|
|||||||
if (fixer != null) {
|
if (fixer != null) {
|
||||||
return fixer.fixFaces(b, hunk, rX, rZ, x, y, z, mantle);
|
return fixer.fixFaces(b, hunk, rX, rZ, x, y, z, mantle);
|
||||||
}
|
}
|
||||||
BlockData rawB = (BlockData) b.nativeHandle();
|
BlockData cloned = ((BlockData) b.nativeHandle()).clone();
|
||||||
BlockData cloned = rawB.clone();
|
|
||||||
MultipleFacing data = (MultipleFacing) cloned;
|
MultipleFacing data = (MultipleFacing) cloned;
|
||||||
if (data.getFaces().stream().anyMatch(f -> f != BlockFace.UP && f != BlockFace.DOWN)) {
|
if (keepSupportedSides(data, VINE.equals(IrisProceduralBlocks.materialKey(b)), hunk, rX, rZ, x, y, z, mantle)) {
|
||||||
// The pack chose which side a hanging strand faces: keep it (the vine above holds it up), and tie the
|
|
||||||
// block under a solid ceiling to it, so ceiling decorators hang curtains instead of flat ceiling sheets.
|
|
||||||
if (data.getAllowedFaces().contains(BlockFace.UP) && sturdy(BlockFace.UP, hunk, rX, rZ, x, y, z, mantle)) {
|
|
||||||
data.setFace(BlockFace.UP, true);
|
|
||||||
}
|
|
||||||
return BukkitBlockState.of(cloned);
|
return BukkitBlockState.of(cloned);
|
||||||
}
|
}
|
||||||
data.getFaces().forEach(f -> data.setFace(f, false));
|
for (BlockFace f : Faces.CARTESIAN) {
|
||||||
|
if (data.hasFace(f)) {
|
||||||
|
data.setFace(f, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (BlockFace f : BlockFace.values()) {
|
for (BlockFace f : Faces.CARTESIAN) {
|
||||||
if (f.isCartesian() && sturdy(f, hunk, rX, rZ, x, y, z, mantle) && data.getAllowedFaces().contains(f)) {
|
if (data.getAllowedFaces().contains(f) && sturdy(f, hunk, rX, rZ, x, y, z, mantle)) {
|
||||||
found = true;
|
found = true;
|
||||||
data.setFace(f, true);
|
data.setFace(f, true);
|
||||||
}
|
}
|
||||||
@@ -483,20 +482,58 @@ final class DecoratorCore {
|
|||||||
return BukkitBlockState.of(cloned);
|
return BukkitBlockState.of(cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether the neighbour on that face (mantle first, then this chunk's hunk) offers a full sturdy face to attach to. */
|
private static boolean keepSupportedSides(MultipleFacing data, boolean vine, Hunk<NativeBlockState> hunk,
|
||||||
|
int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
||||||
|
boolean side = false;
|
||||||
|
for (BlockFace f : Faces.SIDES) {
|
||||||
|
if (!data.hasFace(f)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (sturdy(f, hunk, rX, rZ, x, y, z, mantle) || vine && vineAboveCarries(f, hunk, rX, rZ, x, y, z, mantle)) {
|
||||||
|
side = true;
|
||||||
|
} else {
|
||||||
|
data.setFace(f, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!side) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (data.getAllowedFaces().contains(BlockFace.UP)) {
|
||||||
|
data.setFace(BlockFace.UP, sturdy(BlockFace.UP, hunk, rX, rZ, x, y, z, mantle));
|
||||||
|
}
|
||||||
|
if (data.hasFace(BlockFace.DOWN) && !sturdy(BlockFace.DOWN, hunk, rX, rZ, x, y, z, mantle)) {
|
||||||
|
data.setFace(BlockFace.DOWN, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean sturdy(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
private static boolean sturdy(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
||||||
int yy = y + f.getModY();
|
int yy = y + f.getModY();
|
||||||
NativeBlockState rs = mantle == null ? null : mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class);
|
BlockFace attached = f.getOppositeFace();
|
||||||
BlockData r = rs == null ? (BlockData) EngineMantle.AIR.get().nativeHandle() : (BlockData) rs.nativeHandle();
|
if (mantle != null && sturdy(mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class), attached)) {
|
||||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int xx = rX + f.getModX();
|
int xx = rX + f.getModX();
|
||||||
int zz = rZ + f.getModZ();
|
int zz = rZ + f.getModZ();
|
||||||
if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy >= hunk.getHeight()) {
|
return xx >= 0 && xx <= 15 && zz >= 0 && zz <= 15 && yy >= 0 && yy < hunk.getHeight()
|
||||||
return false;
|
&& sturdy(hunk.get(xx, yy, zz), attached);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean sturdy(NativeBlockState state, BlockFace attached) {
|
||||||
|
return state != null && ((BlockData) state.nativeHandle()).isFaceSturdy(attached, BlockSupport.FULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean vineAboveCarries(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ,
|
||||||
|
int x, int y, int z, EngineMantle mantle) {
|
||||||
|
if (mantle != null && carries(mantle.getMantle().get(x, y + 1, z, NativeBlockState.class), f)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return ((BlockData) hunk.get(xx, yy, zz).nativeHandle()).isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL);
|
return y + 1 < hunk.getHeight() && carries(hunk.get(rX, y + 1, rZ), f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean carries(NativeBlockState state, BlockFace f) {
|
||||||
|
return state != null && VINE.equals(IrisProceduralBlocks.materialKey(state))
|
||||||
|
&& state.nativeHandle() instanceof MultipleFacing facing && facing.hasFace(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean canGoOn(NativeBlockState decorator, NativeBlockState surface) {
|
static boolean canGoOn(NativeBlockState decorator, NativeBlockState surface) {
|
||||||
@@ -586,4 +623,10 @@ final class DecoratorCore {
|
|||||||
default -> state;
|
default -> state;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class Faces {
|
||||||
|
private static final BlockFace[] SIDES = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||||
|
private static final BlockFace[] CARTESIAN = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST,
|
||||||
|
BlockFace.UP, BlockFace.DOWN};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +51,10 @@ import org.bukkit.potion.PotionEffect;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@Snippet("effect")
|
@Snippet("effect")
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -58,6 +62,9 @@ import org.bukkit.util.Vector;
|
|||||||
@Description("An iris effect")
|
@Description("An iris effect")
|
||||||
@Data
|
@Data
|
||||||
public class IrisEffect {
|
public class IrisEffect {
|
||||||
|
private static final String MASTER_SOUND_CATEGORY = "master";
|
||||||
|
private static final Set<String> UNKNOWN_SOUND_CATEGORIES = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
||||||
private final transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
|
private final transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
|
||||||
private final transient AtomicCache<Particle> particleEffectResolved = new AtomicCache<>();
|
private final transient AtomicCache<Particle> particleEffectResolved = new AtomicCache<>();
|
||||||
@@ -119,8 +126,8 @@ public class IrisEffect {
|
|||||||
@Description("The sound volume.")
|
@Description("The sound volume.")
|
||||||
private double volume = 1.5D;
|
private double volume = 1.5D;
|
||||||
@DependsOn({"sound"})
|
@DependsOn({"sound"})
|
||||||
@Description("The sound category the sound plays in, which picks the client volume slider that controls it (for example MUSIC, AMBIENT or HOSTILE).")
|
@Description("The sound category the sound plays in, which picks the client volume slider that controls it: master, music, record, weather, block, hostile, neutral, player, ambient, voice or ui.")
|
||||||
private SoundCategory soundCategory = SoundCategory.MASTER;
|
private String soundCategory = MASTER_SOUND_CATEGORY;
|
||||||
@DependsOn({"particleEffect"})
|
@DependsOn({"particleEffect"})
|
||||||
@MinNumber(0)
|
@MinNumber(0)
|
||||||
@MaxNumber(512)
|
@MaxNumber(512)
|
||||||
@@ -185,6 +192,10 @@ public class IrisEffect {
|
|||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSoundCategoryKey() {
|
||||||
|
return soundCategory == null || soundCategory.isBlank() ? MASTER_SOUND_CATEGORY : soundCategory.trim().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
public Particle getParticleEffect() {
|
public Particle getParticleEffect() {
|
||||||
if (particleEffect == null) {
|
if (particleEffect == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -199,6 +210,32 @@ public class IrisEffect {
|
|||||||
return soundResolved.aquire(() -> resolveKeyed(Sound.class, sound));
|
return soundResolved.aquire(() -> resolveKeyed(Sound.class, sound));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SoundCategory bukkitSoundCategory(String key) {
|
||||||
|
return switch (key) {
|
||||||
|
case "master" -> SoundCategory.MASTER;
|
||||||
|
case "music" -> SoundCategory.MUSIC;
|
||||||
|
case "record" -> SoundCategory.RECORDS;
|
||||||
|
case "weather" -> SoundCategory.WEATHER;
|
||||||
|
case "block" -> SoundCategory.BLOCKS;
|
||||||
|
case "hostile" -> SoundCategory.HOSTILE;
|
||||||
|
case "neutral" -> SoundCategory.NEUTRAL;
|
||||||
|
case "player" -> SoundCategory.PLAYERS;
|
||||||
|
case "ambient" -> SoundCategory.AMBIENT;
|
||||||
|
case "voice" -> SoundCategory.VOICE;
|
||||||
|
case "ui" -> SoundCategory.UI;
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private SoundCategory resolveSoundCategory() {
|
||||||
|
String key = getSoundCategoryKey();
|
||||||
|
SoundCategory category = bukkitSoundCategory(key);
|
||||||
|
if (category == null && UNKNOWN_SOUND_CATEGORIES.add(key)) {
|
||||||
|
IrisLogging.warn("Unknown sound category: \"" + key + "\".");
|
||||||
|
}
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
private static <T> T resolveKeyed(Class<T> type, String key) {
|
private static <T> T resolveKeyed(Class<T> type, String key) {
|
||||||
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
|
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
|
||||||
return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey);
|
return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey);
|
||||||
@@ -242,9 +279,10 @@ public class IrisEffect {
|
|||||||
BukkitFx.run(p, () -> {
|
BukkitFx.run(p, () -> {
|
||||||
Sound soundType = getSound();
|
Sound soundType = getSound();
|
||||||
Particle particleType = getParticleEffect();
|
Particle particleType = getParticleEffect();
|
||||||
if (soundType != null) {
|
SoundCategory category = soundType == null ? null : resolveSoundCategory();
|
||||||
|
if (category != null) {
|
||||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||||
p.playSound(part, soundType, soundCategory, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
p.playSound(part, soundType, category, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (particleType != null) {
|
if (particleType != null) {
|
||||||
@@ -319,9 +357,10 @@ public class IrisEffect {
|
|||||||
J.runEntity(p, () -> {
|
J.runEntity(p, () -> {
|
||||||
Sound soundType = getSound();
|
Sound soundType = getSound();
|
||||||
Particle particleType = getParticleEffect();
|
Particle particleType = getParticleEffect();
|
||||||
if (soundType != null) {
|
SoundCategory category = soundType == null ? null : resolveSoundCategory();
|
||||||
|
if (category != null) {
|
||||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||||
p.getWorld().playSound(part, soundType, soundCategory, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
p.getWorld().playSound(part, soundType, category, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (particleType != null) {
|
if (particleType != null) {
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ import art.arcane.volmlib.util.math.RNG;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockSupport;
|
import org.bukkit.block.BlockSupport;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.MultipleFacing;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
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.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
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.mock;
|
||||||
import static org.mockito.Mockito.mockStatic;
|
import static org.mockito.Mockito.mockStatic;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class DecoratorCoreTest {
|
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
|
@Test
|
||||||
public void partSeed_differsByPartOrdinal() {
|
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() {
|
private NativeBlockState airState() {
|
||||||
NativeBlockState air = mock(NativeBlockState.class);
|
NativeBlockState air = mock(NativeBlockState.class);
|
||||||
when(air.isAir()).thenReturn(true);
|
when(air.isAir()).thenReturn(true);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
|||||||
@ClassRule
|
@ClassRule
|
||||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
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(
|
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||||
IrisDimension.class,
|
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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user