mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +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
+127
@@ -1,14 +1,32 @@
|
||||
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.terrain.NativeBlockState;
|
||||
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.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.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
@@ -17,6 +35,12 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedDecoratorHooksTest {
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faceFixingExcludesTheUpperBoundaryWhileKeepingTheLastRowAccessible() {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
@@ -41,4 +65,107 @@ public class ModdedDecoratorHooksTest {
|
||||
verify(hunk, never()).get(1, 4, 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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user