Skip to content

Commit

Permalink
why is playing sounds on the client side so hard! i'm sad!
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Oct 21, 2024
1 parent cb88e0c commit 85ce505
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/floralquafloral/CharaStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -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),

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/floralquafloral/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/floralquafloral/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -134,7 +135,16 @@ else if(data.getForwardVel() < BACKPEDAL_SPEED.getAsLimit(data)) {
public List<ActionTransitionDefinition> 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) -> {

}
)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ActionTransitionDefinition> getPreTickTransitions() {
return List.of(
// GroundedTransitions.FALL,
GroundedTransitions.DUCK_WADDLE,
new ActionTransitionDefinition("qua_mario:basic",
(data) -> data.getForwardVel() < RUN_SPEED.getAsThreshold(data))
);
}

@Override
public List<ActionTransitionDefinition> getPostTickTransitions() {
return List.of();
}

@Override
public List<ActionTransitionDefinition> getPostMoveTransitions() {
return List.of();
}

@Override
public List<ActionTransitionInjection> getTransitionInjections() {
return List.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/floralquafloral/util/MarioSFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit 85ce505

Please sign in to comment.