From fefa871d5a2f3cec5f737e886c7cd96188be825c Mon Sep 17 00:00:00 2001 From: Floral <49110090+floral-qua-floral@users.noreply.github.com> Date: Sun, 27 Oct 2024 01:26:40 -0400 Subject: [PATCH] Added aerial state system (Fall and Jump implemented) --- .../com/floralquafloral/MarioPackets.java | 3 + .../action/AirborneActionDefinition.java | 140 +++++++++++++++--- .../action/GroundedActionDefinition.java | 27 +++- .../action/baseactions/airborne/Fall.java | 74 +++++++++ .../action/baseactions/airborne/Jump.java | 78 ++++++++++ .../baseactions/grounded/ActionBasic.java | 6 +- .../floralquafloral/stats/StatCategory.java | 1 + .../floralquafloral/util/JumpSoundPlayer.java | 115 ++++++++++++++ .../com/floralquafloral/util/MarioSFX.java | 2 + src/main/resources/fabric.mod.json | 3 +- 10 files changed, 420 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Fall.java create mode 100644 src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Jump.java create mode 100644 src/main/java/com/floralquafloral/util/JumpSoundPlayer.java diff --git a/src/main/java/com/floralquafloral/MarioPackets.java b/src/main/java/com/floralquafloral/MarioPackets.java index 309f1e0..e663d43 100644 --- a/src/main/java/com/floralquafloral/MarioPackets.java +++ b/src/main/java/com/floralquafloral/MarioPackets.java @@ -3,6 +3,7 @@ import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.mariodata.MarioDataPackets; import com.floralquafloral.registries.stomp.StompHandler; +import com.floralquafloral.util.JumpSoundPlayer; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; import net.fabricmc.fabric.api.networking.v1.PlayerLookup; @@ -24,6 +25,7 @@ public static void registerCommon() { MarioDataPackets.registerCommon(); StompHandler.registerPackets(); VoiceLine.registerPackets(); + JumpSoundPlayer.registerPackets(); ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { MarioQuaMario.LOGGER.info(""); @@ -34,6 +36,7 @@ public static void registerClient() { MarioDataPackets.registerClient(); StompHandler.registerPacketsClient(); VoiceLine.registerPacketsClient(); + JumpSoundPlayer.registerPacketsClient(); } public static PlayerEntity getPlayerFromInt(ClientPlayNetworking.Context context, int playerID) { 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 f020451..b305faa 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java +++ b/src/main/java/com/floralquafloral/registries/states/action/AirborneActionDefinition.java @@ -2,10 +2,16 @@ import com.floralquafloral.mariodata.client.Input; import com.floralquafloral.mariodata.client.MarioClientData; -import com.floralquafloral.stats.OldCharaStat; +import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; +import com.floralquafloral.util.ClientSoundPlayer; +import com.floralquafloral.util.JumpSoundPlayer; +import com.floralquafloral.util.MarioSFX; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.floralquafloral.stats.StatCategory.*; + public abstract class AirborneActionDefinition implements ActionDefinition { public static boolean jumpCapped; @@ -21,9 +27,7 @@ public abstract static class AerialTransitions { if(isSelf && data instanceof MarioClientData clientData) clientData.jumpLandingTime = 5; }, - (data, seed) -> { - - } + null ); public static final ActionTransitionDefinition TRIPLE_JUMPABLE_LANDING = new ActionTransitionDefinition( "qua_mario:basic", @@ -32,34 +36,128 @@ public abstract static class AerialTransitions { if(isSelf && data instanceof MarioClientData clientData) clientData.doubleJumpLandingTime = 5; }, - (data, seed) -> { + null + ); - } + public static final ActionTransitionDefinition GROUND_POUND = new ActionTransitionDefinition( + "qua_mario:ground_pound", + data -> Input.DUCK.isPressed(), + (data, isSelf, seed) -> ClientSoundPlayer.playSound(MarioSFX.GROUND_POUND_PRE, data, seed), + null ); } - private final @NotNull OldCharaStat GRAVITY = getGravity(); - private final @NotNull OldCharaStat JUMP_GRAVITY = getJumpGravity(); - private final @Nullable OldCharaStat JUMP_CAP = getJumpCap(); + public abstract static class AerialStats { + public static final CharaStat GRAVITY = new CharaStat(-0.115, NORMAL_GRAVITY); + public static final CharaStat TERMINAL_VELOCITY = new CharaStat(-3.25, StatCategory.TERMINAL_VELOCITY); + + public static final CharaStat JUMP_GRAVITY = new CharaStat(-0.095, JUMPING_GRAVITY); + public static final CharaStat JUMP_CAP = new CharaStat(0.39, StatCategory.JUMP_CAP); + + public static final CharaStat FORWARD_DRIFT_ACCEL = new CharaStat(0.04, DRIFTING, FORWARD, ACCELERATION); + public static final CharaStat FORWARD_DRIFT_SPEED = new CharaStat(0.275, DRIFTING, FORWARD, SPEED); + + public static final CharaStat BACKWARD_DRIFT_ACCEL = new CharaStat(0.05, DRIFTING, BACKWARD, ACCELERATION); + public static final CharaStat BACKWARD_DRIFT_SPEED = new CharaStat(0.2, DRIFTING, BACKWARD, SPEED); + + public static final CharaStat STRAFE_DRIFT_ACCEL = new CharaStat(0.04, DRIFTING, STRAFE, ACCELERATION); + public static final CharaStat STRAFE_DRIFT_SPEED = new CharaStat(0.2, DRIFTING, STRAFE, SPEED); + + public static final CharaStat DRIFT_REDIRECTION = new CharaStat(6.0, DRIFTING, REDIRECTION); + } + + private final @NotNull CharaStat ACTION_GRAVITY = getGravity(); + private final @Nullable CharaStat ACTION_JUMP_GRAVITY = getJumpGravity(); + private final @NotNull CharaStat ACTION_TERMINAL_VELOCITY = getTerminalVelocity(); + private final @Nullable CharaStat ACTION_JUMP_CAP = getJumpCap(); - protected abstract @NotNull OldCharaStat getGravity(); - protected abstract @NotNull OldCharaStat getJumpGravity(); - protected abstract @Nullable OldCharaStat getJumpCap(); + protected abstract @NotNull CharaStat getGravity(); + protected abstract @Nullable CharaStat getJumpGravity(); + protected abstract @NotNull CharaStat getTerminalVelocity(); + protected abstract @Nullable CharaStat getJumpCap(); @Override public final void selfTick(MarioClientData data) { double yVel = data.getYVel(); - boolean aboveJumpCap = JUMP_CAP != null && yVel > JUMP_CAP.getValue(data); + double terminalVelocity = ACTION_TERMINAL_VELOCITY.get(data); + + if(yVel > terminalVelocity) { + boolean aboveJumpCap = ACTION_JUMP_CAP != null && ACTION_JUMP_GRAVITY != null && yVel > ACTION_JUMP_CAP.get(data); + + CharaStat useGravity = aboveJumpCap ? ACTION_JUMP_GRAVITY : ACTION_GRAVITY; + yVel += useGravity.get(data); - OldCharaStat useGravity = aboveJumpCap ? JUMP_GRAVITY : GRAVITY; - yVel += useGravity.getValue(data); - if(aboveJumpCap && !Input.JUMP.isHeld() && !jumpCapped) { - yVel = JUMP_CAP.getValue(data); - jumpCapped = true; + if(!jumpCapped) { + if(!aboveJumpCap) { + jumpCapped = true; + JumpSoundPlayer.fadeJumpSfx(data); + } + else if(!Input.JUMP.isHeld()) { + yVel = ACTION_JUMP_CAP.get(data); + jumpCapped = true; + JumpSoundPlayer.fadeJumpSfx(data); + } + } + + data.setYVel(Math.max(terminalVelocity, yVel)); } - data.setYVel(yVel); - aerialSelfTick(); + aerialSelfTick(data); } - public abstract void aerialSelfTick(); + public abstract void aerialSelfTick(MarioClientData data); + + public static void airborneAccel( + MarioClientData data, + CharaStat accelStat, CharaStat speedStat, + CharaStat strafeAccelStat, CharaStat strafeSpeedStat, + double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectStat + ) { + double forwardInput = Input.getForwardInput(); + double strafeInput = Input.getStrafeInput(); + double forwardVel = data.getForwardVel(); + double strafeVel = data.getStrafeVel(); + + double accelValue, strafeAccelValue; + + if(forwardInput != 0 && (Math.signum(forwardVel) != Math.signum(forwardInput) || Math.abs(forwardVel) < Math.abs(speedStat.get(data)))) + accelValue = accelStat.get(data) * forwardInput; + else accelValue = 0; + + if(strafeInput != 0 && (Math.signum(strafeVel) != Math.signum(strafeInput) || Math.abs(strafeVel) < Math.abs(strafeSpeedStat.get(data)))) + strafeAccelValue = strafeAccelStat.get(data) * strafeInput; + else strafeAccelValue = 0; + + data.approachAngleAndAccel( + accelValue, speedStat.get(data) * Math.signum(forwardInput), + strafeAccelValue, strafeSpeedStat.get(data) * Math.signum(strafeInput), + forwardAngleContribution * forwardInput, + strafeAngleContribution * strafeInput, + redirectStat.get(data) + ); + } + public static void airborneAccel( + MarioClientData data, + CharaStat forwardAccelStat, CharaStat forwardSpeedStat, + CharaStat backwardAccelStat, CharaStat backwardSpeedStat, + CharaStat strafeAccelStat, CharaStat strafeSpeedStat, + double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectStat + ) { + // Unlike when on the ground, when Mario is in midair, neutral inputs don't cause him to accelerate towards 0. + // He only accelerates when actively making an input, and will always try to accelerate in that direction, never backwards. + boolean forwards = Input.getForwardInput() >= 0; + airborneAccel(data, + forwards ? forwardAccelStat : backwardAccelStat, + forwards ? forwardSpeedStat : backwardSpeedStat, + strafeAccelStat, strafeSpeedStat, + forwardAngleContribution, strafeAngleContribution, redirectStat + ); + } + public static void airborneAccel(MarioClientData data) { + airborneAccel(data, + AerialStats.FORWARD_DRIFT_ACCEL, AerialStats.FORWARD_DRIFT_SPEED, + AerialStats.BACKWARD_DRIFT_ACCEL, AerialStats.BACKWARD_DRIFT_SPEED, + AerialStats.STRAFE_DRIFT_ACCEL, AerialStats.STRAFE_DRIFT_SPEED, + Input.getForwardInput(), Input.getStrafeInput(), AerialStats.DRIFT_REDIRECTION + ); + } } 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 26211c1..c157d2b 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java +++ b/src/main/java/com/floralquafloral/registries/states/action/GroundedActionDefinition.java @@ -4,11 +4,15 @@ import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.client.Input; import com.floralquafloral.mariodata.client.MarioClientData; +import com.floralquafloral.registries.states.action.baseactions.airborne.Jump; +import com.floralquafloral.registries.states.action.baseactions.grounded.PRun; import com.floralquafloral.stats.CharaStat; import com.floralquafloral.util.ClientSoundPlayer; +import com.floralquafloral.util.JumpSoundPlayer; import com.floralquafloral.util.MarioSFX; import net.minecraft.sound.SoundCategory; import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; import org.joml.Vector2d; import static com.floralquafloral.MarioQuaMario.LOGGER; @@ -17,6 +21,19 @@ public abstract class GroundedActionDefinition implements ActionDefinition { public static final CharaStat ZERO = new CharaStat(0.0); public abstract static class GroundedTransitions { + public static void performJump(MarioData data, CharaStat velocityStat, @Nullable CharaStat addendStat, + long seed, boolean playSound) { + if(data.getMario().isMainPlayer() || !data.getMario().getWorld().isClient) { + double jumpVel = velocityStat.get(data); + if(addendStat != null) + jumpVel += Math.max(0.0, data.getForwardVel() / PRun.P_SPEED.get(data)) * addendStat.get(data); + + data.setYVel(jumpVel); + } + + if(data.getMario().getWorld().isClient && playSound) JumpSoundPlayer.playJumpSfx(data, seed); + } + public static final ActionTransitionDefinition FALL = new ActionTransitionDefinition( "qua_mario:fall", (data) -> !data.getMario().isOnGround() @@ -24,9 +41,9 @@ public abstract static class GroundedTransitions { public static final ActionTransitionDefinition JUMP = new ActionTransitionDefinition( "qua_mario:jump", - (data) -> Input.DUCK.isHeld() -// double threshold = DUCK_SLIDE_THRESHOLD.get(data); -// return Input.DUCK.isHeld() && Vector2d.lengthSquared(data.getForwardVel(), data.getStrafeVel()) > threshold * threshold; + (data) -> Input.JUMP.isPressed(), + (data, isSelf, seed) -> performJump(data, Jump.JUMP_VEL, Jump.JUMP_ADDEND, seed, true), + (data, seed) -> performJump(data, Jump.JUMP_VEL, Jump.JUMP_ADDEND, seed, false) ); public static final ActionTransitionDefinition DUCK_WADDLE = new ActionTransitionDefinition( @@ -34,7 +51,7 @@ public abstract static class GroundedTransitions { (data) -> Input.DUCK.isHeld(), (data, isSelf, seed) -> { // Play duck voiceline - ClientSoundPlayer.playSound(MarioSFX.DUCK, data, seed); + ClientSoundPlayer.playSound(MarioSFX.DUCK, data, 0.5F, 1.0F, seed); VoiceLine.DUCK.play(data, seed); }, null @@ -42,7 +59,7 @@ public abstract static class GroundedTransitions { } @Override public final void selfTick(MarioClientData data) { - data.setYVel(data.getYVel() - 0.05); + data.setYVel(data.getYVel() - 0.01); AirborneActionDefinition.jumpCapped = false; this.groundedSelfTick(data); } diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Fall.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Fall.java new file mode 100644 index 0000000..5e8886c --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Fall.java @@ -0,0 +1,74 @@ +package com.floralquafloral.registries.states.action.baseactions.airborne; + +import com.floralquafloral.MarioQuaMario; +import com.floralquafloral.mariodata.MarioPlayerData; +import com.floralquafloral.mariodata.client.MarioClientData; +import com.floralquafloral.registries.states.action.AirborneActionDefinition; +import com.floralquafloral.stats.CharaStat; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class Fall extends AirborneActionDefinition { + @Override public @NotNull Identifier getID() { + return Identifier.of(MarioQuaMario.MOD_ID, "fall"); + } + @Override public @Nullable String getAnimationName() { + return ""; + } + + @Override public SneakLegalityRule getSneakLegalityRule() { + return SneakLegalityRule.PROHIBIT; + } + @Override public SlidingStatus getConstantSlidingStatus() { + return SlidingStatus.NOT_SLIDING; + } + @Override public @Nullable Identifier getStompType() { + return Identifier.of("qua_mario", "stomp"); + } + + @Override protected @NotNull CharaStat getGravity() { + return AerialStats.GRAVITY; + } + @Override protected @Nullable CharaStat getJumpGravity() { + return null; + } + @Override protected @NotNull CharaStat getTerminalVelocity() { + return AerialStats.TERMINAL_VELOCITY; + } + @Override protected @Nullable CharaStat getJumpCap() { + return null; + } + + @Override public void aerialSelfTick(MarioClientData data) { + airborneAccel(data); + } + + @Override public void otherClientsTick(MarioPlayerData data) { + + } + + @Override public void serverTick(MarioPlayerData data) { + + } + + @Override public List getPreTickTransitions() { + return List.of( + AerialTransitions.BASIC_LANDING + ); + } + + @Override public List getPostTickTransitions() { + return List.of(); + } + + @Override public List getPostMoveTransitions() { + return List.of(); + } + + @Override public List getTransitionInjections() { + return List.of(); + } +} diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Jump.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Jump.java new file mode 100644 index 0000000..813ac27 --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Jump.java @@ -0,0 +1,78 @@ +package com.floralquafloral.registries.states.action.baseactions.airborne; + +import com.floralquafloral.MarioQuaMario; +import com.floralquafloral.mariodata.MarioPlayerData; +import com.floralquafloral.mariodata.client.MarioClientData; +import com.floralquafloral.registries.states.action.AirborneActionDefinition; +import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class Jump extends AirborneActionDefinition { + public static final CharaStat JUMP_VEL = new CharaStat(0.858, StatCategory.JUMP_VELOCITY); + public static final CharaStat JUMP_ADDEND = new CharaStat(0.117, StatCategory.JUMP_VELOCITY); + + @Override public @NotNull Identifier getID() { + return Identifier.of(MarioQuaMario.MOD_ID, "jump"); + } + @Override public @Nullable String getAnimationName() { + return null; + } + + @Override public SneakLegalityRule getSneakLegalityRule() { + return SneakLegalityRule.PROHIBIT; + } + @Override public SlidingStatus getConstantSlidingStatus() { + return SlidingStatus.NOT_SLIDING; + } + @Override public @Nullable Identifier getStompType() { + return Identifier.of("qua_mario", "stomp"); + } + + @Override protected @NotNull CharaStat getGravity() { + return AerialStats.GRAVITY; + } + @Override protected @Nullable CharaStat getJumpGravity() { + return AerialStats.JUMP_GRAVITY; + } + @Override protected @NotNull CharaStat getTerminalVelocity() { + return AerialStats.TERMINAL_VELOCITY; + } + @Override protected @Nullable CharaStat getJumpCap() { + return AerialStats.JUMP_CAP; + } + + @Override public void aerialSelfTick(MarioClientData data) { + airborneAccel(data); + } + + @Override public void otherClientsTick(MarioPlayerData data) { + + } + + @Override public void serverTick(MarioPlayerData data) { + + } + + @Override public List getPreTickTransitions() { + return List.of( + AerialTransitions.DOUBLE_JUMPABLE_LANDING + ); + } + + @Override public List getPostTickTransitions() { + return List.of(); + } + + @Override public List getPostMoveTransitions() { + return List.of(); + } + + @Override public List getTransitionInjections() { + return List.of(); + } +} diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/ActionBasic.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/ActionBasic.java index 35b0dd1..4912da8 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/ActionBasic.java +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/ActionBasic.java @@ -158,7 +158,7 @@ else if(data.getForwardVel() < BACKPEDAL_SPEED.getAsLimit(data)) { @Override public List getPreTickTransitions() { return List.of( -// GroundedTransitions.FALL, + GroundedTransitions.FALL, GroundedTransitions.DUCK_WADDLE, new ActionTransitionDefinition("qua_mario:p_run", (data) -> data.getForwardVel() >= RUN_SPEED.getAsThreshold(data), @@ -174,7 +174,9 @@ public List getPreTickTransitions() { @Override public List getPostTickTransitions() { - return List.of(); + return List.of( + GroundedTransitions.JUMP + ); } @Override diff --git a/src/main/java/com/floralquafloral/stats/StatCategory.java b/src/main/java/com/floralquafloral/stats/StatCategory.java index 8231877..3ecbbc7 100644 --- a/src/main/java/com/floralquafloral/stats/StatCategory.java +++ b/src/main/java/com/floralquafloral/stats/StatCategory.java @@ -24,6 +24,7 @@ public enum StatCategory { FRICTION, // Mostly for Luigi? JUMP_VELOCITY, + JUMP_CAP, JUMPING_GRAVITY, NORMAL_GRAVITY, diff --git a/src/main/java/com/floralquafloral/util/JumpSoundPlayer.java b/src/main/java/com/floralquafloral/util/JumpSoundPlayer.java new file mode 100644 index 0000000..78ef801 --- /dev/null +++ b/src/main/java/com/floralquafloral/util/JumpSoundPlayer.java @@ -0,0 +1,115 @@ +package com.floralquafloral.util; + +import com.floralquafloral.MarioPackets; +import com.floralquafloral.MarioQuaMario; +import com.floralquafloral.mariodata.MarioData; +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; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.sound.TickableSoundInstance; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.random.Random; + +import java.util.*; + +import static com.floralquafloral.mariodata.MarioDataManager.getMarioData; + +public class JumpSoundPlayer { + public static void registerPackets() { + FadeJumpSoundS2CPayload.register(); + FadeJumpSoundC2SPayload.register(); + + FadeJumpSoundC2SPayload.registerReceiver(); + } + public static void registerPacketsClient() { + FadeJumpSoundS2CPayload.registerReceiver(); + } + + private static final Set FADING_JUMPS = new HashSet<>(); + + private static class JumpSoundInstance extends PositionedSoundInstance implements TickableSoundInstance { + private final PlayerEntity owner; + + public JumpSoundInstance(SoundEvent event, PlayerEntity mario, long seed) { + super(event, SoundCategory.PLAYERS, 1.0F, 1.0F, Random.create(seed), mario.getX(), mario.getY(), mario.getZ()); + owner = mario; + FADING_JUMPS.remove(this.owner); + } + + @Override + public boolean isDone() { + return volume <= 0.0F; + } + + @Override + public void tick() { + if(FADING_JUMPS.contains(this.owner)) + this.volume -= 0.2F; + } + } + + public static void playJumpSfx(SoundEvent event, MarioData data, long seed) { + PlayerEntity mario = data.getMario(); + ClientSoundPlayer.SOUND_MANAGER.play(new JumpSoundInstance(event, mario, seed)); + } + public static void playJumpSfx(MarioData data, long seed) { + playJumpSfx(MarioSFX.JUMP, data, seed); + } + public static void fadeJumpSfx(PlayerEntity mario) { + FADING_JUMPS.add(mario); + if(mario.isMainPlayer()) ClientPlayNetworking.send(new FadeJumpSoundC2SPayload()); + } + public static void fadeJumpSfx(MarioData data) { + fadeJumpSfx(data.getMario()); + } + + private record FadeJumpSoundC2SPayload() implements CustomPayload { + public static final Id ID = new Id<>(Identifier.of(MarioQuaMario.MOD_ID, "fade_jump_c2s")); + public static final PacketCodec CODEC = PacketCodec.unit(new FadeJumpSoundC2SPayload()); + public static void registerReceiver() { + ServerPlayNetworking.registerGlobalReceiver(ID, (payload, context) -> + { + MarioPackets.sendPacketToTrackersExclusive(context.player(), new FadeJumpSoundS2CPayload(context.player())); + MarioQuaMario.LOGGER.info("Received C2S packet to fade the jump sound!"); + } + ); + } + + @Override public Id getId() { + return ID; + } + public static void register() { + PayloadTypeRegistry.playC2S().register(ID, CODEC); + } + } + + private record FadeJumpSoundS2CPayload(int player) implements CustomPayload { + public static final Id ID = new Id<>(Identifier.of(MarioQuaMario.MOD_ID, "fade_jump_s2c")); + public static final PacketCodec CODEC = PacketCodec.tuple( + PacketCodecs.INTEGER, FadeJumpSoundS2CPayload::player, + FadeJumpSoundS2CPayload::new + ); + public FadeJumpSoundS2CPayload(PlayerEntity player) { + this(player.getId()); + } + public static void registerReceiver() { + ClientPlayNetworking.registerGlobalReceiver(ID, (payload, context) -> + FADING_JUMPS.add(MarioPackets.getPlayerFromInt(context, payload.player))); + } + + @Override public Id getId() { + return ID; + } + public static void register() { + PayloadTypeRegistry.playS2C().register(ID, CODEC); + } + } +} diff --git a/src/main/java/com/floralquafloral/util/MarioSFX.java b/src/main/java/com/floralquafloral/util/MarioSFX.java index cf414c7..d757af9 100644 --- a/src/main/java/com/floralquafloral/util/MarioSFX.java +++ b/src/main/java/com/floralquafloral/util/MarioSFX.java @@ -26,6 +26,8 @@ public final class MarioSFX { public static final SoundEvent DUCK = makeActionSound("duck"); public static final SoundEvent UNDUCK = makeActionSound("unduck"); + public static final SoundEvent GROUND_POUND_PRE = makeActionSound("ground_pound_pre"); + public static final SoundEvent GROUND_POUND = makeActionSound("ground_pound"); private static SoundEvent makeMovementSound(String name) { return makeAndRegisterSound("sfx.movement." + name); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b6f89d2..0e3e176 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,7 +30,8 @@ "com.floralquafloral.registries.states.action.baseactions.grounded.DuckSlide" ], "mario-actions-airborne" : [ - + "com.floralquafloral.registries.states.action.baseactions.airborne.Fall", + "com.floralquafloral.registries.states.action.baseactions.airborne.Jump" ], "mario-actions-aquatic": [