diff --git a/src/main/java/com/floralquafloral/VoiceLine.java b/src/main/java/com/floralquafloral/VoiceLine.java index 0d5cad4..1f5a961 100644 --- a/src/main/java/com/floralquafloral/VoiceLine.java +++ b/src/main/java/com/floralquafloral/VoiceLine.java @@ -3,6 +3,7 @@ import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.registries.RegistryManager; import com.floralquafloral.registries.states.character.ParsedCharacter; +import com.floralquafloral.util.ClientSoundPlayer; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; @@ -68,25 +69,29 @@ public void play(MarioData data, long seed) { PlayerEntity mario = data.getMario(); if(mario.getWorld().isClient) { - PositionedSoundInstance prevVoiceSound = PLAYER_VOICE_LINES.get(mario); - SoundManager soundManager = MinecraftClient.getInstance().getSoundManager(); - soundManager.stop(prevVoiceSound); - - PositionedSoundInstance voiceSound = new PositionedSoundInstance( + ClientSoundPlayer.SOUND_MANAGER.stop(PLAYER_VOICE_LINES.get(mario)); + +// PositionedSoundInstance voiceSound = new PositionedSoundInstance( +// SOUND_EVENTS.get(data.getCharacter()), +// SoundCategory.VOICE, +// 1.0F, +// 1.0F, +// Random.create(seed), +// data.getMario().getX(), +// data.getMario().getY(), +// data.getMario().getZ() +// ); +// ClientSoundPlayer.SOUND_MANAGER.play(voiceSound); + PLAYER_VOICE_LINES.put(mario, ClientSoundPlayer.playSound( SOUND_EVENTS.get(data.getCharacter()), SoundCategory.VOICE, + mario, 1.0F, 1.0F, - Random.create(seed), - data.getMario().getX(), - data.getMario().getY(), - data.getMario().getZ() - ); - soundManager.play(voiceSound); - PLAYER_VOICE_LINES.put(mario, voiceSound); + seed + )); } else { - MarioQuaMario.LOGGER.info("Send voiceline packet!!!"); MarioPackets.sendPacketToTrackers((ServerPlayerEntity) data.getMario(), new PlayVoiceLineS2CPayload(data.getMario(), this, seed)); } } diff --git a/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java b/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java index cb0b5c1..f020451 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java +++ b/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java @@ -41,7 +41,6 @@ public abstract static class AerialTransitions { private final @NotNull OldCharaStat GRAVITY = getGravity(); private final @NotNull OldCharaStat JUMP_GRAVITY = getJumpGravity(); private final @Nullable OldCharaStat JUMP_CAP = getJumpCap(); - //TODO: Make Grounded states use CharaStats as well! protected abstract @NotNull OldCharaStat getGravity(); protected abstract @NotNull OldCharaStat getJumpGravity(); diff --git a/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java b/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java index 0045164..26211c1 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java +++ b/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java @@ -5,7 +5,9 @@ import com.floralquafloral.mariodata.client.Input; import com.floralquafloral.mariodata.client.MarioClientData; import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.util.ClientSoundPlayer; import com.floralquafloral.util.MarioSFX; +import net.minecraft.sound.SoundCategory; import net.minecraft.util.math.BlockPos; import org.joml.Vector2d; @@ -32,13 +34,10 @@ public abstract static class GroundedTransitions { (data) -> Input.DUCK.isHeld(), (data, isSelf, seed) -> { // Play duck voiceline - data.getMario().playSound(MarioSFX.DUCK); + ClientSoundPlayer.playSound(MarioSFX.DUCK, data, seed); VoiceLine.DUCK.play(data, seed); - LOGGER.info("Ducking voiceline with seed {}", seed); }, - (data, seed) -> { - LOGGER.info("Entering duck_waddle on server with seed {}", seed); - } + null ); } diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java index 5ac1d41..e7995fa 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckSlide.java @@ -91,7 +91,9 @@ public List getTransitionInjections() { && data.getMario().isOnGround() && !data.getAction().ID.equals(getID()) && Vector2d.lengthSquared(data.getForwardVel(), data.getStrafeVel()) > threshold * threshold; - } + }, + GroundedTransitions.DUCK_WADDLE.EXECUTOR_CLIENT, + GroundedTransitions.DUCK_WADDLE.EXECUTOR_SERVER ) ) ); diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckWaddle.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckWaddle.java index e0f4ff5..83888da 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckWaddle.java +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/DuckWaddle.java @@ -6,6 +6,9 @@ import com.floralquafloral.mariodata.client.MarioClientData; import com.floralquafloral.registries.states.action.GroundedActionDefinition; import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.util.ClientSoundPlayer; +import com.floralquafloral.util.MarioSFX; +import net.minecraft.sound.SoundCategory; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,7 +27,11 @@ public class DuckWaddle extends GroundedActionDefinition { public static final ActionTransitionDefinition UNDUCK = new ActionTransitionDefinition( "qua_mario:basic", - (data) -> !Input.DUCK.isHeld() + (data) -> !Input.DUCK.isHeld(), + (data, isSelf, seed) -> { + ClientSoundPlayer.playSound(MarioSFX.UNDUCK, data, seed); + }, + null ); public static final CharaStat WADDLE_ACCEL = new CharaStat(0.06, DUCKING, FORWARD, ACCELERATION); diff --git a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java index 37a282f..242d346 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java @@ -3,6 +3,7 @@ import com.floralquafloral.MarioQuaMario; import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioPlayerData; +import com.floralquafloral.util.ClientSoundPlayer; import net.minecraft.entity.Entity; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LivingEntity; @@ -38,7 +39,7 @@ public class ParsedStomp { private final boolean HITS_NONLIVING_ENTITIES; private final RegistryKey DAMAGE_TYPE; - private final RegistryEntry SOUND_ENTRY; + private final SoundEvent SOUND_EVENT; private final Identifier POST_STOMP_ACTION; public ParsedStomp(StompDefinition definition) { @@ -51,7 +52,7 @@ public ParsedStomp(StompDefinition definition) { this.HITS_NONLIVING_ENTITIES = definition.canHitNonLiving(); this.DAMAGE_TYPE = RegistryKey.of(RegistryKeys.DAMAGE_TYPE, definition.getDamageType()); - this.SOUND_ENTRY = Registries.SOUND_EVENT.getEntry(definition.getSoundEvent()); + this.SOUND_EVENT = definition.getSoundEvent(); this.POST_STOMP_ACTION = definition.getPostStompAction(); } @@ -71,23 +72,22 @@ public void executeServer(MarioPlayerData data, Entity target, boolean harmless, target.damage(damageSource, damage); - this.DEFINITION.executeServer(target.getWorld(), data, target, harmless, seed); + this.DEFINITION.executeServer(data, target, harmless, seed); } - public void executeClient(PlayerEntity hearingPlayer, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { - if(this.SOUND_ENTRY != null) { - target.getWorld().playSound( - hearingPlayer, - target.getX(), - target.getY(), - target.getZ(), - this.SOUND_ENTRY, + public void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { + if(this.SOUND_EVENT != null) { + ClientSoundPlayer.playSound( + this.SOUND_EVENT, SoundCategory.PLAYERS, + data.getMario().getX(), + target.getY() + target.getHeight(), + data.getMario().getZ(), 1.0F, 1.0F, seed ); } - this.DEFINITION.executeClient(hearingPlayer.getWorld(), data, isSelf, target, harmless, seed); + this.DEFINITION.executeClient(data, isSelf, target, harmless, seed); data.applyModifiedVelocity(); } diff --git a/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java b/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java index 503a8e0..5bb4c11 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java +++ b/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java @@ -7,7 +7,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; -import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,8 +26,8 @@ public interface StompDefinition { float calculateDamage(MarioData data, ServerPlayerEntity mario, ItemStack equipment, double equipmentArmor, double equipmentToughness, Entity target); - void executeServer(World world, MarioPlayerData data, Entity target, boolean harmless, long seed); - void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed); + void executeServer(MarioPlayerData data, Entity target, boolean harmless, long seed); + void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed); enum PainfulStompResponse { INJURY, diff --git a/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java b/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java index 3c51cbf..cfb73f4 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java +++ b/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java @@ -74,7 +74,7 @@ public static void registerReceiver() { + "\nareEqual2: " + (context.player().getWorld().equals(mario.getWorld())) + "\nmarioDataMarioWorld: " + getMarioData(mario).getMario().getWorld() ); - stompType.executeClient(context.player(), (MarioPlayerData) getMarioData(mario), mario.isMainPlayer(), target, payload.harmless, payload.seed); + stompType.executeClient((MarioPlayerData) getMarioData(mario), mario.isMainPlayer(), target, payload.harmless, payload.seed); }); } diff --git a/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java b/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java index 150fe0c..3d3e398 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java @@ -6,22 +6,13 @@ import com.floralquafloral.registries.stomp.StompDefinition; import com.floralquafloral.registries.stomp.StompHandler; import com.floralquafloral.util.MarioSFX; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.MovementType; import net.minecraft.item.ItemStack; -import net.minecraft.registry.Registries; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; -import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.random.Random; -import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,7 +59,7 @@ public float calculateDamage(MarioData data, ServerPlayerEntity mario, ItemStack } @Override - public void executeServer(World world, MarioPlayerData data, Entity target, boolean harmless, long seed) { + public void executeServer(MarioPlayerData data, Entity target, boolean harmless, long seed) { executeCommon(data, target); // world.playSound( // null, @@ -77,7 +68,7 @@ public void executeServer(World world, MarioPlayerData data, Entity target, bool } @Override - public void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { + public void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { executeCommon(data, target); // world.playSoundFromEntity(null, target, Registries.SOUND_EVENT.getEntry(MarioSFX.STOMP), SoundCategory.PLAYERS, 1.0F, 1.0F, seed); diff --git a/src/main/java/com/floralquafloral/util/ClientSoundPlayer.java b/src/main/java/com/floralquafloral/util/ClientSoundPlayer.java new file mode 100644 index 0000000..5e7d41c --- /dev/null +++ b/src/main/java/com/floralquafloral/util/ClientSoundPlayer.java @@ -0,0 +1,47 @@ +package com.floralquafloral.util; + +import com.floralquafloral.mariodata.MarioData; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.sound.SoundManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.math.random.Random; + +@SuppressWarnings("UnusedReturnValue") +public abstract class ClientSoundPlayer { + public static final SoundManager SOUND_MANAGER = MinecraftClient.getInstance().getSoundManager(); + + public static PositionedSoundInstance playSound(SoundEvent event, SoundCategory category, double x, double y, double z, float volume, float pitch, long seed) { + PositionedSoundInstance sound = new PositionedSoundInstance( + event, + category, + volume, + pitch, + Random.create(seed), + x, + y, + z + ); + SOUND_MANAGER.play(sound); + return sound; + } + + public static PositionedSoundInstance playSound(SoundEvent event, SoundCategory category, Entity entity, float volume, float pitch, long seed) { + return playSound(event, category, entity.getX(), entity.getY(), entity.getZ(), volume, pitch, seed); + } + + public static PositionedSoundInstance playSound(SoundEvent event, MarioData data, float volume, float pitch, long seed) { + return playSound(event, SoundCategory.PLAYERS, data.getMario(), volume, pitch, seed); + } + + public static PositionedSoundInstance playSound(SoundEvent event, MarioData data, long seed) { + return playSound(event, data, 1.0F, 1.0F, seed); + } + + public static void kill(PositionedSoundInstance sound) { + SOUND_MANAGER.stop(sound); + } +} diff --git a/src/main/java/com/floralquafloral/util/MarioSFX.java b/src/main/java/com/floralquafloral/util/MarioSFX.java index c307cbe..cf414c7 100644 --- a/src/main/java/com/floralquafloral/util/MarioSFX.java +++ b/src/main/java/com/floralquafloral/util/MarioSFX.java @@ -6,7 +6,7 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; -public abstract class MarioSFX { +public final class MarioSFX { public static final SoundEvent JUMP = makeMovementSound("jump"); public static final SoundEvent FLIP = makeMovementSound("flip"); public static final SoundEvent SKID_BLOCK = makeMovementSound("skid"); @@ -24,7 +24,8 @@ public abstract class MarioSFX { public static final SoundEvent STOMP_HEAVY = makeStompSound("heavy"); public static final SoundEvent STOMP_YOSHI = makeStompSound("yoshi"); - public static final SoundEvent DUCK = makeAndRegisterSound("duck"); + public static final SoundEvent DUCK = makeActionSound("duck"); + public static final SoundEvent UNDUCK = makeActionSound("unduck"); private static SoundEvent makeMovementSound(String name) { return makeAndRegisterSound("sfx.movement." + name); diff --git a/src/main/resources/assets/qua_mario/sounds/sfx/action/unduck.ogg b/src/main/resources/assets/qua_mario/sounds/sfx/action/unduck.ogg index 94f9351..411bff4 100644 Binary files a/src/main/resources/assets/qua_mario/sounds/sfx/action/unduck.ogg and b/src/main/resources/assets/qua_mario/sounds/sfx/action/unduck.ogg differ