From 85ce5054229034c268d3b1b38088908027cd0950 Mon Sep 17 00:00:00 2001 From: Floral <49110090+floral-qua-floral@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:35:15 -0400 Subject: [PATCH] why is playing sounds on the client side so hard! i'm sad! --- .../java/com/floralquafloral/CharaStat.java | 8 +- .../com/floralquafloral/MarioQuaMario.java | 16 +++- .../floralquafloral/mixin/EntityMixin.java | 1 + .../baseactions/grounded/ActionBasic.java | 12 ++- .../action/baseactions/grounded/PRun.java | 74 +++++++++++++++++++ .../registries/stomp/ParsedStomp.java | 8 +- .../registries/stomp/StompDefinition.java | 5 +- .../registries/stomp/StompHandler.java | 9 ++- .../stomp/basestomptypes/JumpStomp.java | 26 ++++++- .../com/floralquafloral/util/MarioSFX.java | 7 +- src/main/resources/fabric.mod.json | 1 + 11 files changed, 148 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/PRun.java diff --git a/src/main/java/com/floralquafloral/CharaStat.java b/src/main/java/com/floralquafloral/CharaStat.java index 405e11d..2b9c952 100644 --- a/src/main/java/com/floralquafloral/CharaStat.java +++ b/src/main/java/com/floralquafloral/CharaStat.java @@ -14,7 +14,7 @@ public enum CharaStat { WALK_STANDSTILL_THRESHOLD(0.12), WALK_SPEED(0.275), WALK_REDIRECTION(0), - OVERWALK_ACCEL(0.02), + OVERWALK_ACCEL(0.028), IDLE_DEACCEL(0.075, ALL_FRICTIONS), @@ -46,12 +46,12 @@ public enum CharaStat { SKID_DRAG_MIN(0.02, ALL_FRICTIONS), SKID_REDIRECTION(4.5), - RUN_ACCEL(0.0155), - RUN_SPEED(0.5), + RUN_ACCEL(0.0102), + RUN_SPEED(0.575), RUN_REDIRECTION(2.75), OVERRUN_ACCEL(0.0175), - P_SPEED(1.0), + P_SPEED(0.665), P_SPEED_ACCEL(0.13), P_SPEED_REDIRECTION(6.0), diff --git a/src/main/java/com/floralquafloral/MarioQuaMario.java b/src/main/java/com/floralquafloral/MarioQuaMario.java index 7a50b7e..76c73fe 100644 --- a/src/main/java/com/floralquafloral/MarioQuaMario.java +++ b/src/main/java/com/floralquafloral/MarioQuaMario.java @@ -19,6 +19,8 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.world.GameRules; import org.slf4j.Logger; @@ -82,9 +84,19 @@ public void onInitialize() { if(revertTargetID != null) { MarioDataPackets.setMarioPowerUp(player, RegistryManager.POWER_UPS.get(revertTargetID)); - player.playSound(MarioSFX.REVERT); +// player.playSound(MarioSFX.REVERT, 1.0F, 1.0F); +// player.playSound(SoundEvents.BLOCK_BEACON_POWER_SELECT, 1.0F, 1.0F); + player.getWorld().playSound( + null, + player.getX(), + player.getY(), + player.getZ(), + MarioSFX.REVERT, + SoundCategory.PLAYERS, + 0.6F, + 1.0F + ); - data.setYVel(0.5); player.setHealth(player.getMaxHealth()); return false; } diff --git a/src/main/java/com/floralquafloral/mixin/EntityMixin.java b/src/main/java/com/floralquafloral/mixin/EntityMixin.java index f6e0ef0..c7af2d6 100644 --- a/src/main/java/com/floralquafloral/mixin/EntityMixin.java +++ b/src/main/java/com/floralquafloral/mixin/EntityMixin.java @@ -1,5 +1,6 @@ package com.floralquafloral.mixin; +import com.floralquafloral.MarioQuaMario; import com.floralquafloral.mariodata.MarioData; import com.floralquafloral.mariodata.MarioDataManager; import com.floralquafloral.registries.states.action.ParsedAction; 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 34525ae..438ab1b 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 @@ -1,5 +1,6 @@ package com.floralquafloral.registries.states.action.baseactions.grounded; +import com.floralquafloral.CharaStat; import com.floralquafloral.MarioQuaMario; import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.mariodata.client.Input; @@ -134,7 +135,16 @@ else if(data.getForwardVel() < BACKPEDAL_SPEED.getAsLimit(data)) { public List getPreTickTransitions() { return List.of( // GroundedTransitions.FALL, - GroundedTransitions.DUCK_WADDLE + GroundedTransitions.DUCK_WADDLE, + new ActionTransitionDefinition("qua_mario:p_run", + (data) -> data.getForwardVel() >= RUN_SPEED.getAsThreshold(data), + (data, isSelf, seed) -> { + if(isSelf) data.setForwardVel(P_SPEED.get(data)); + }, + (data, seed) -> { + + } + ) ); } diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/PRun.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/PRun.java new file mode 100644 index 0000000..29d041a --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/PRun.java @@ -0,0 +1,74 @@ +package com.floralquafloral.registries.states.action.baseactions.grounded; + +import com.floralquafloral.MarioQuaMario; +import com.floralquafloral.mariodata.MarioPlayerData; +import com.floralquafloral.mariodata.client.Input; +import com.floralquafloral.mariodata.client.MarioClientData; +import com.floralquafloral.registries.states.action.GroundedActionDefinition; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +import static com.floralquafloral.CharaStat.*; + +public class PRun extends GroundedActionDefinition { + @Override public @NotNull Identifier getID() { + return Identifier.of(MarioQuaMario.MOD_ID, "p_run"); + } + @Override public @Nullable String getAnimationName() { + return "p-run"; + } + + @Override + public void groundedSelfTick(MarioClientData data) { + boolean sprinting = data.getMario().isSprinting(); + groundAccel(data, + sprinting ? OVERRUN_ACCEL.get(data) : OVERWALK_ACCEL.get(data), + sprinting ? P_SPEED.get(data) : WALK_SPEED.get(data), + STRAFE_ACCEL.get(data), STRAFE_SPEED.get(data), + Input.getForwardInput(), Input.getStrafeInput(), + P_SPEED_REDIRECTION.get(data) + ); + } + + @Override public void otherClientsTick(MarioPlayerData data) {} + + @Override public void serverTick(MarioPlayerData data) {} + + @Override public SneakLegalityRule getSneakLegalityRule() { + return SneakLegalityRule.ALLOW; + } + @Override public SlidingStatus getConstantSlidingStatus() { + return SlidingStatus.NOT_SLIDING_SMOOTH; + } + @Override public @Nullable Identifier getStompType() { + return null; + } + + @Override + public List getPreTickTransitions() { + return List.of( +// GroundedTransitions.FALL, + GroundedTransitions.DUCK_WADDLE, + new ActionTransitionDefinition("qua_mario:basic", + (data) -> data.getForwardVel() < RUN_SPEED.getAsThreshold(data)) + ); + } + + @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/stomp/ParsedStomp.java b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java index 0781d74..5fab700 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java @@ -25,6 +25,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.random.RandomSeed; +import net.minecraft.world.World; import java.util.List; @@ -73,10 +74,11 @@ public void executeServer(MarioPlayerData data, Entity target, boolean harmless, target.damage(damageSource, damage); - this.DEFINITION.executeServer(data, target, harmless, seed); + this.DEFINITION.executeServer(target.getWorld(), data, target, harmless, seed); } - public void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { - this.DEFINITION.executeClient(data, isSelf, target, harmless, seed); + public void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { + this.DEFINITION.executeClient(world, data, isSelf, target, harmless, seed); + data.applyModifiedVelocity(); } public void attempt(MarioData data, Vec3d movement) { diff --git a/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java b/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java index 00e991d..d3846b7 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java +++ b/src/main/java/com/floralquafloral/registries/stomp/StompDefinition.java @@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; +import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,8 +25,8 @@ public interface StompDefinition { float calculateDamage(MarioData data, ServerPlayerEntity mario, ItemStack equipment, double equipmentArmor, double equipmentToughness, Entity target); - void executeServer(MarioPlayerData data, Entity target, boolean harmless, long seed); - void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed); + 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); 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 a48fb14..6f889a0 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java +++ b/src/main/java/com/floralquafloral/registries/stomp/StompHandler.java @@ -67,7 +67,14 @@ public static void registerReceiver() { MarioQuaMario.LOGGER.error("Target: {}", target); return; } - stompType.executeClient((MarioPlayerData) getMarioData(mario), mario.isMainPlayer(), target, payload.harmless, payload.seed); + MarioQuaMario.LOGGER.info("receiver:" + + "\ncontextPlayerWorld: " + context.player().getWorld() + + "\nmarioWorld: " + mario.getWorld() + + "\nareEqual: " + (context.player().getWorld() == mario.getWorld()) + + "\nareEqual2: " + (context.player().getWorld().equals(mario.getWorld())) + + "\nmarioDataMarioWorld: " + getMarioData(mario).getMario().getWorld() + ); + stompType.executeClient(context.player().getWorld(), (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 e66fca3..91916c1 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/basestomptypes/JumpStomp.java @@ -5,13 +5,20 @@ import com.floralquafloral.mariodata.MarioPlayerData; import com.floralquafloral.registries.stomp.StompDefinition; import com.floralquafloral.registries.stomp.StompHandler; +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.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; 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; @@ -55,14 +62,27 @@ public float calculateDamage(MarioData data, ServerPlayerEntity mario, ItemStack } @Override - public void executeServer(MarioPlayerData data, Entity target, boolean harmless, long seed) { + public void executeServer(World world, MarioPlayerData data, Entity target, boolean harmless, long seed) { executeCommon(data, target); +// world.playSound( +// null, +// +// ); } @Override - public void executeClient(MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { + public void executeClient(World world, MarioPlayerData data, boolean isSelf, Entity target, boolean harmless, long seed) { executeCommon(data, target); - target.playSound(SoundEvents.BLOCK_BEACON_POWER_SELECT, 1.0F, 1.0F); +// world.playSound( +// target.getX(), +// target.getY(), +// target.getZ(), +// SoundEvents.ENTITY_SKELETON_DEATH, +// SoundCategory.PLAYERS, +// 1.0F, +// 1.0F, +// false +// ); } private void executeCommon(MarioPlayerData data, Entity target) { diff --git a/src/main/java/com/floralquafloral/util/MarioSFX.java b/src/main/java/com/floralquafloral/util/MarioSFX.java index e6fc432..a0f5b1e 100644 --- a/src/main/java/com/floralquafloral/util/MarioSFX.java +++ b/src/main/java/com/floralquafloral/util/MarioSFX.java @@ -19,7 +19,7 @@ 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(""); + public static final SoundEvent DUCK = makeAndRegisterSound("duck"); private static SoundEvent makeMovementSound(String name) { return makeAndRegisterSound("sfx.movement." + name); @@ -34,9 +34,10 @@ private static SoundEvent makeActionSound(String name) { return makeAndRegisterSound("sfx.action." + name); } - private static SoundEvent makeAndRegisterSound(String id) { - Identifier identifier = Identifier.of(MarioQuaMario.MOD_ID, id); + private static SoundEvent makeAndRegisterSound(String path) { + Identifier identifier = Identifier.of(MarioQuaMario.MOD_ID, path); SoundEvent event = SoundEvent.of(identifier); + MarioQuaMario.LOGGER.info("Register sound {} ({})", identifier, event); Registry.register(Registries.SOUND_EVENT, identifier, event); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c5b20c3..1a0590d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -25,6 +25,7 @@ ], "mario-actions-grounded": [ "com.floralquafloral.registries.states.action.baseactions.grounded.ActionBasic", + "com.floralquafloral.registries.states.action.baseactions.grounded.PRun", "com.floralquafloral.registries.states.action.baseactions.grounded.DuckWaddle", "com.floralquafloral.registries.states.action.baseactions.grounded.DuckSlide" ],