Skip to content

Commit

Permalink
Skidding sounds implemented. Starting to work on Airborne states.
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Oct 25, 2024
1 parent b2232f5 commit fc0392f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 38 deletions.
48 changes: 29 additions & 19 deletions src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import com.floralquafloral.util.CPMIntegration;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import org.joml.Vector2d;

import java.util.List;

public class MarioPlayerData implements MarioData {
private boolean enabled;
private ParsedAction action;
Expand Down Expand Up @@ -159,14 +163,12 @@ public void tick() {
}

private class SkidSoundInstance extends MovingSoundInstance {
private final PlayerEntity MARIO;
private final boolean IS_WALL;
private final SkidMaterial MATERIAL;
private int ticks;

protected SkidSoundInstance(boolean isWall, SkidMaterial material) {
super(isWall ? MarioSFX.SKID_WALL : MarioSFX.SKID_BLOCK, SoundCategory.PLAYERS, SoundInstance.createRandom());
this.MARIO = getMario();
super(isWall ? MarioSFX.SKID_WALL : material.EVENT, SoundCategory.PLAYERS, SoundInstance.createRandom());
this.IS_WALL = isWall;
this.MATERIAL = material;
this.updatePos();
Expand All @@ -177,11 +179,13 @@ protected SkidSoundInstance(boolean isWall, SkidMaterial material) {
}

private static SkidMaterial getFloorSkidMaterial(PlayerEntity mario) {

BlockState block = mario.getWorld().getBlockState(mario.getVelocityAffectingPos());
if(block.getBlock().getSlipperiness() > 0.85) return SkidMaterial.ICE;
return SkidMaterial.BASIC;
}

private enum SkidMaterial {
ICE(MarioSFX.SKID_ICE),
BASIC(MarioSFX.SKID_BLOCK);

public final SoundEvent EVENT;
Expand All @@ -191,27 +195,26 @@ private enum SkidMaterial {
}

@Override public void tick() {
if(isDone()) return; //WHY???
this.ticks++;
MarioQuaMario.LOGGER.info("Ticking sound!");
if(this.IS_WALL || this.MARIO.isOnGround()) {
SkidMaterial newMaterial = getFloorSkidMaterial(this.MARIO);
if(this.IS_WALL || getMario().isOnGround()) {
SkidMaterial newMaterial = getFloorSkidMaterial(getMario());
if(newMaterial != this.MATERIAL && !this.IS_WALL) {
MarioQuaMario.LOGGER.info("Switching skid sound effect!");
this.kill();
// SkidSoundInstance.create(this.DATA, false);
MarioQuaMario.LOGGER.info("Switching skid material from {} to {}!", this.MATERIAL, newMaterial);
makeSkidSFX(false, newMaterial);

}
else this.updatePos();
}
else this.volume = 0.0F;
}

private void updatePos() {
this.x = this.MARIO.getX();
this.y = this.MARIO.getY();
this.z = this.MARIO.getZ();
MarioQuaMario.LOGGER.info("X: " + this.x);
this.x = getMario().getX();
this.y = getMario().getY();
this.z = getMario().getZ();
if(this.IS_WALL) return;
float slidingSpeed = (float) this.MARIO.getVelocity().horizontalLengthSquared();
float slidingSpeed = (float) getMario().getVelocity().horizontalLengthSquared();
this.volume = Math.min(1.0F, ((float) ticks) / 3.0F) * Math.min(1.0F, 0.7F * slidingSpeed);
this.pitch = 1.0F + Math.min(0.15F, 0.5F * slidingSpeed);
}
Expand All @@ -221,11 +224,19 @@ private void updatePos() {
}

private void kill() {
skidSFX = null;
this.setDone();
// skidSFX = null;
}
}
private SkidSoundInstance skidSFX;
private void makeSkidSFX(boolean isWall, SkidSoundInstance.SkidMaterial material) {
if(this.skidSFX != null) this.skidSFX.kill();
this.skidSFX = new SkidSoundInstance(isWall, material);
MinecraftClient.getInstance().getSoundManager().playNextTick(this.skidSFX);
}
private void makeSkidSFX(boolean isWall) {
this.makeSkidSFX(isWall, SkidSoundInstance.getFloorSkidMaterial(this.getMario()));
}

@Override public void setAction(ParsedAction action, long seed) {
getAction().transitionTo(this, action, seed);
Expand All @@ -236,9 +247,7 @@ private void kill() {
// Skid SFX
if(this.skidSFX != null) this.skidSFX.kill();
if(action.SLIDING_STATUS.doSlideSfx() || action.SLIDING_STATUS.doWallSlideSfx()) {
this.skidSFX = new SkidSoundInstance(action.SLIDING_STATUS.doWallSlideSfx(), SkidSoundInstance.getFloorSkidMaterial(getMario()));
MinecraftClient.getInstance().getSoundManager().play(this.skidSFX);
MarioQuaMario.LOGGER.info("SFX? " + this.skidSFX);
makeSkidSFX(action.SLIDING_STATUS.doWallSlideSfx());
}
}
else {
Expand All @@ -248,6 +257,7 @@ private void kill() {
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.mario, action.ANIMATION, 1);
}
this.action = action;
MarioQuaMario.LOGGER.info("SFX? " + this.skidSFX);
}
@Override public ParsedPowerUp getPowerUp() {
return powerUp;
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/floralquafloral/mixin/ExampleMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.states.action.ActionDefinition;
import com.floralquafloral.registries.states.action.AirborneActionDefinition;
import com.floralquafloral.registries.states.action.GroundedActionDefinition;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.registries.states.character.CharacterDefinition;
Expand Down Expand Up @@ -101,6 +102,9 @@ private static void registerActions() {
for(GroundedActionDefinition definition : getEntrypoints("mario-actions-grounded", GroundedActionDefinition.class)) {
parseAction(definition, transitionInjections);
}
for(AirborneActionDefinition definition : getEntrypoints("mario-actions-airborne", AirborneActionDefinition.class)) {
parseAction(definition, transitionInjections);
}

for(ParsedAction action : ACTIONS) {
MarioQuaMario.LOGGER.info("Parsing and populating Action Transitions for {}...", action.ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.floralquafloral.registries.states.action;

import com.floralquafloral.mariodata.client.Input;
import com.floralquafloral.mariodata.client.MarioClientData;
import com.floralquafloral.stats.CharaStat;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class AirborneActionDefinition implements ActionDefinition {
public static boolean jumpCapped;

public abstract static class AerialTransitions {
public static final ActionTransitionDefinition BASIC_LANDING = new ActionTransitionDefinition(
"qua_mario:basic",
(data) -> data.getMario().isOnGround()
);
public static final ActionTransitionDefinition DOUBLE_JUMPABLE_LANDING = new ActionTransitionDefinition(
"qua_mario:basic",
BASIC_LANDING.EVALUATOR,
(data, isSelf, seed) -> {
if(isSelf && data instanceof MarioClientData clientData)
clientData.jumpLandingTime = 5;
},
(data, seed) -> {

}
);
public static final ActionTransitionDefinition TRIPLE_JUMPABLE_LANDING = new ActionTransitionDefinition(
"qua_mario:basic",
BASIC_LANDING.EVALUATOR,
(data, isSelf, seed) -> {
if(isSelf && data instanceof MarioClientData clientData)
clientData.doubleJumpLandingTime = 5;
},
(data, seed) -> {

}
);
}

private final @NotNull CharaStat GRAVITY = getGravity();
private final @NotNull CharaStat JUMP_GRAVITY = getJumpGravity();
private final @Nullable CharaStat JUMP_CAP = getJumpCap();
//TODO: Make Grounded states use CharaStats as well!

protected abstract @NotNull CharaStat getGravity();
protected abstract @NotNull CharaStat getJumpGravity();
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);

CharaStat useGravity = aboveJumpCap ? JUMP_GRAVITY : GRAVITY;
yVel += useGravity.getValue(data);
if(aboveJumpCap && !Input.JUMP.isHeld() && !jumpCapped) {
yVel = JUMP_CAP.getValue(data);
jumpCapped = true;
}

data.setYVel(yVel);
aerialSelfTick();
}

public abstract void aerialSelfTick();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static com.floralquafloral.MarioQuaMario.LOGGER;

public abstract class GroundedActionDefinition implements ActionDefinition {
protected abstract static class GroundedTransitions {
public abstract static class GroundedTransitions {
public static final ActionTransitionDefinition FALL = new ActionTransitionDefinition(
"qua_mario:fall",
(data) -> !data.getMario().isOnGround()
Expand Down Expand Up @@ -39,8 +39,9 @@ protected abstract static class GroundedTransitions {
);
}

@Override public void selfTick(MarioClientData data) {
@Override public final void selfTick(MarioClientData data) {
data.setYVel(data.getYVel() - 0.05);
AirborneActionDefinition.jumpCapped = false;
this.groundedSelfTick(data);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/floralquafloral/util/MarioSFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public abstract class MarioSFX {
public static final SoundEvent JUMP = makeMovementSound("jump");
public static final SoundEvent FLIP = makeMovementSound("flip");
public static final SoundEvent SKID_BLOCK = makeMovementSound("skid_block");
public static final SoundEvent SKID_BLOCK = makeMovementSound("skid");
public static final SoundEvent SKID_ICE = makeMovementSound("skid_ice");
public static final SoundEvent SKID_SAND = makeMovementSound("skid_sand");
public static final SoundEvent SKID_SNOW = makeMovementSound("skid_snow");
Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/resources/qua_mario.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"EntityMixin",
"ExampleMixin",
"JumpMixin",
"PlayerEntityMixin"
],
Expand Down

0 comments on commit fc0392f

Please sign in to comment.