Skip to content

Commit

Permalink
Renamed transition phases to be more descriptive. Added Aquatic Actio…
Browse files Browse the repository at this point in the history
…ns and Submerged+Swim actions.
  • Loading branch information
floral-qua-floral committed Nov 22, 2024
1 parent a12d525 commit 5ee47ba
Show file tree
Hide file tree
Showing 43 changed files with 353 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.floralquafloral.definitions;

import org.jetbrains.annotations.NotNull;

import java.util.Map;

public interface CharacterDefinition extends MarioMajorStateDefinition {

@NotNull Map<String, String> getPoweredUpPlayermodels();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public interface PowerUpDefinition extends MarioMajorStateDefinition {
@NotNull Map<String, String> getCharacterPlayermodels();

void acquirePower(MarioData data);
void losePower(MarioData data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@

import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.definitions.MarioStateDefinition;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioTravelData;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public interface ActionDefinition extends MarioStateDefinition {
default void boogersaur() {
Logger logger = LoggerFactory.getLogger("qua_mario_api");

logger.info("Boogersaur running!");
Identifier tester = Identifier.of("qua_mario:stinker");
logger.info("tester: {}", tester);
}


@Nullable String getAnimationName();
@Nullable CameraAnimationSet getCameraAnimations();

Expand All @@ -39,9 +30,9 @@ default void boogersaur() {
* POST-MOVE transitions are meant to be used for transitions based on Mario's position. For instance, falling is a
* post-move transition.
*/
List<ActionTransitionDefinition> getPreTickTransitions();
List<ActionTransitionDefinition> getPostTickTransitions();
List<ActionTransitionDefinition> getPostMoveTransitions();
List<ActionTransitionDefinition> getPreTravelTransitions();
List<ActionTransitionDefinition> getInputTransitions();
List<ActionTransitionDefinition> getWorldCollisionTransitions();

List<ActionTransitionInjection> getTransitionInjections();

Expand Down Expand Up @@ -164,19 +155,15 @@ public BumpingRule(int ceilingBumpStrength, int floorBumpStrength, int wallBumpS
this.WALLS = wallBumpStrength;
}
}
// enum BumpType {
// NONE(0, 0),
// HIT_CEILINGS(2, 0),
// GROUND_POUND(0, 2),
// SPIN_JUMP(2, 1);
//
// public final int HIT_CEILING_STRENGTH;
// public final int HIT_FLOOR_STRENGTH;
// BumpType(int hitCeilingStrength, int hitFloorStrength) {
// this.HIT_CEILING_STRENGTH = hitCeilingStrength;
// this.HIT_FLOOR_STRENGTH = hitFloorStrength;
// }
// }

abstract class CommonTransitions {
public static final ActionTransitionDefinition ENTER_WATER = new ActionTransitionDefinition(
"qua_mario:submerged",
data -> data.getInputs().SPIN.isPressed(),
data -> {},
(data, isSelf, seed) -> data.playSoundEvent(SoundEvents.AMBIENT_UNDERWATER_ENTER, seed)
);
}

class ActionTransitionDefinition {
@FunctionalInterface public interface TransitionEvaluator {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.floralquafloral.definitions.actions;

import com.floralquafloral.mariodata.MarioTravelData;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2d;

public abstract class AquaticActionDefinition implements ActionDefinition {
public abstract static class AquaticTransitions {
public static final ActionTransitionDefinition EXIT_WATER = new ActionTransitionDefinition(
"qua_mario:fall",
data -> data.getInputs().SPIN.isPressed()
);
}

public abstract static class AquaticStats {
public final CharaStat GRAVITY = new CharaStat(0, StatCategory.AQUATIC_GRAVITY);
public final CharaStat TERMINAL_VELOCITY = new CharaStat(0, StatCategory.AQUATIC_TERMINAL_VELOCITY);

public final CharaStat DRAG = new CharaStat(0.07, StatCategory.WATER_DRAG);
public final CharaStat DRAG_MIN = new CharaStat(0.01, StatCategory.WATER_DRAG);
}

private final @Nullable CharaStat ACTION_GRAVITY = getGravity() == 0 ? null : new CharaStat(getGravity(), StatCategory.AQUATIC_GRAVITY);
private final @Nullable CharaStat ACTION_TERMINAL_VELOCITY = getGravity() == 0 ? null : new CharaStat(getTerminalVelocity(), StatCategory.AQUATIC_TERMINAL_VELOCITY);
private final @Nullable CharaStat ACTION_DRAG = getDrag() == 0 ? null : new CharaStat(getDrag(), StatCategory.WATER_DRAG);
private final @Nullable CharaStat ACTION_DRAG_MINIMUM = getDrag() == 0 ? null : new CharaStat(getDragMinimum(), StatCategory.WATER_DRAG);

public abstract double getGravity();
public abstract double getTerminalVelocity();
public abstract double getDrag();
public abstract double getDragMinimum();

@Override
public void travelHook(MarioTravelData data) {
if(ACTION_TERMINAL_VELOCITY != null) {
double yVel = data.getYVel();
double terminalVelocity = ACTION_TERMINAL_VELOCITY.get(data);

if(yVel > terminalVelocity) {
assert ACTION_GRAVITY != null;
yVel += ACTION_GRAVITY.get(data);

data.setYVel(Math.max(terminalVelocity, yVel));
}
}
if(ACTION_DRAG_MINIMUM != null) {
assert ACTION_DRAG != null;
applyAquaticDrag(data, ACTION_DRAG, ACTION_DRAG_MINIMUM);
}
}

public abstract void aquaticTravel(MarioTravelData data);

public static void applyAquaticDrag(MarioTravelData data, CharaStat drag, CharaStat dragMin) {
double dragValue = drag.get(data);
boolean dragInverted = dragValue < 0;
double slipFactor = 1.0;
double dragMinValue = dragMin.get(data) * slipFactor;
if(!dragInverted) dragValue *= slipFactor;


Vec3d deltaVelocities = new Vec3d(
-dragValue * data.getForwardVel(),
-dragValue * data.getYVel(),
-dragValue * data.getStrafeVel()
);
double dragVelocitySquared = deltaVelocities.lengthSquared();
if(dragVelocitySquared != 0 && dragVelocitySquared < dragMinValue * dragMinValue)
deltaVelocities = deltaVelocities.normalize().multiply(dragMinValue);

data.setForwardVel(data.getForwardVel() + deltaVelocities.x);
data.setYVel(data.getYVel() + deltaVelocities.y);
data.setStrafeVel(data.getStrafeVel() + deltaVelocities.z);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import java.util.Set;

/**
* Represents a numerical value that might vary depending on character and power-up form.
* This is used for movement, speed thresholds, and damage calculations.
*/
public class CharaStat {
public final double BASE;
public final Set<StatCategory> CATEGORIES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class GroundedActionDefinition implements ActionDefinition {
public static final CharaStat ZERO = new CharaStat(0.0);

public abstract static class GroundedTransitions {
public static final CharaStat P_SPEED = new CharaStat(0.665, P_RUNNING, FORWARD, SPEED);
public static final CharaStat P_SPEED = new CharaStat(0.5875, P_RUNNING, FORWARD, SPEED);
public static void performJump(MarioTravelData data, CharaStat velocityStat, @Nullable CharaStat addendStat) {
if(data.getMario().isMainPlayer() || !data.getMario().getWorld().isClient) {
double jumpVel = velocityStat.get(data);
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void performJump(MarioTravelData data, CharaStat velocityStat, @Nu

public abstract void groundedTravel(MarioTravelData data);

public void groundAccel(
public static void groundAccel(
MarioTravelData data,
CharaStat forwardAccel, CharaStat forwardTarget, CharaStat strafeAccel, CharaStat strafeTarget,
double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectDelta
Expand All @@ -76,7 +76,7 @@ public void groundAccel(
);
}

public void applyDrag(
public static void applyDrag(
MarioTravelData data,
CharaStat drag, CharaStat dragMin,
double forwardAngleContribution, double strafeAngleContribution,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ public enum StatCategory {

DRAG,
FRICTION, // Mostly for Luigi?
WATER_DRAG,

JUMP_VELOCITY,
JUMP_CAP,

JUMPING_GRAVITY,
NORMAL_GRAVITY,
AQUATIC_GRAVITY,
TERMINAL_VELOCITY,
AQUATIC_TERMINAL_VELOCITY,

STOMP_BASE_DAMAGE,
STOMP_ARMOR_MULTIPLIER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public interface MarioData {
int getBumpStrengthModifier();
boolean isSneakProhibited();


boolean isSubmerged();
boolean isWading();

boolean isEnabled();
Identifier getActionID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import com.floralquafloral.definitions.actions.StatCategory;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.sound.*;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
Expand All @@ -30,8 +33,6 @@ public abstract class MarioPlayerData implements MarioData {
ATTACK_SLOWDOWN_ID, -0.5, EntityAttributeModifier.Operation.ADD_MULTIPLIED_TOTAL
);



private boolean enabled;
private final boolean IS_CLIENT;
private ParsedAction action;
Expand Down Expand Up @@ -111,6 +112,16 @@ public int getBumpStrengthModifier() {
return this.powerUp.BUMP_STRENGTH_MODIFIER + this.character.BUMP_STRENGTH_MODIFIER;
}

@Override
public boolean isSubmerged() {
return this.mario.isSubmergedInWater();
}

@Override
public boolean isWading() {
return this.mario.getFluidHeight(FluidTags.WATER) > 0.3;
}

public float getVoicePitch() {
return this.powerUp.VOICE_PITCH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MarioMainClientData(ClientPlayerEntity mario) {

@Override
public void setAction(ParsedAction action, long seed) {
MarioQuaMario.LOGGER.warn("Triggered setAction with transitions for the main client. This is abnormal!");
MarioQuaMario.LOGGER.warn("Triggered setAction with transitions on the main client. This is abnormal!");
super.setAction(action, seed);
}

Expand Down Expand Up @@ -98,9 +98,10 @@ public void setAction(ParsedAction action, long seed) {

// TODO: Levitation effect functionality

getAction().attemptTransitions(this, TransitionPhase.PRE_TICK);
getAction().attemptTransitions(this, TransitionPhase.WORLD_COLLISION);
getAction().attemptTransitions(this, TransitionPhase.PRE_TRAVEL);
getAction().travelHook(this);
getAction().attemptTransitions(this, TransitionPhase.POST_TICK);
getAction().attemptTransitions(this, TransitionPhase.INPUT);

getTimers().jumpLandingTime--;
getTimers().doubleJumpLandingTime--;
Expand Down Expand Up @@ -132,7 +133,7 @@ public void setAction(ParsedAction action, long seed) {
}
}

getAction().attemptTransitions(this, TransitionPhase.POST_MOVE);
// getAction().attemptTransitions(this, TransitionPhase.WORLD_COLLISION);

applyModifiedVelocity();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.floralquafloral.registries;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.definitions.actions.AquaticActionDefinition;
import com.floralquafloral.mariodata.MarioClientSideDataImplementation;
import com.floralquafloral.definitions.actions.ActionDefinition;
import com.floralquafloral.definitions.actions.AirborneActionDefinition;
Expand Down Expand Up @@ -109,6 +110,9 @@ private static void registerActions() {
for(AirborneActionDefinition definition : getEntrypoints("mario-actions-airborne", AirborneActionDefinition.class)) {
parseAction(definition, transitionInjections);
}
for(AquaticActionDefinition definition : getEntrypoints("mario-actions-aquatic", AquaticActionDefinition.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
Expand Up @@ -37,7 +37,8 @@ public ParsedAction(ActionDefinition definition) {
this.ANIMATION = definition.getAnimationName();
this.CAMERA_ANIMATIONS = definition.getCameraAnimations();
this.SNEAK_LEGALITY = definition.getSneakLegalityRule();
this.SLIDING_STATUS = definition.getActionSlidingStatus();
ActionDefinition.SlidingStatus status = definition.getActionSlidingStatus();
this.SLIDING_STATUS = status == null ? ActionDefinition.SlidingStatus.NOT_SLIDING : status;
Identifier stompID = definition.getStompType();
this.STOMP = stompID == null ? null : RegistryManager.STOMP_TYPES.get(stompID);
this.BUMPING_RULE = definition.getBumpingRule();
Expand All @@ -57,8 +58,6 @@ public void travelHook(MarioTravelData data) {
public boolean attemptTransitions(MarioMainClientData data, TransitionPhase phase) {
for(ParsedTransition transition : this.TRANSITION_LISTS.get(phase)) {
if(transition.EVALUATOR.shouldTransition(data)) {
// Send C2S packet to tell the server!

long seed = RandomSeed.getSeed();
if(transition.EXECUTOR_TRAVELLERS != null) transition.EXECUTOR_TRAVELLERS.execute(data);
if(transition.EXECUTOR_CLIENTS != null) transition.EXECUTOR_CLIENTS.execute(data, true, seed);
Expand All @@ -72,9 +71,9 @@ public boolean attemptTransitions(MarioMainClientData data, TransitionPhase phas

public boolean transitionTo(MarioPlayerData data, ParsedAction toAction, long seed) {
if(
transitionTo(data, toAction, TransitionPhase.PRE_TICK, seed) ||
transitionTo(data, toAction, TransitionPhase.POST_TICK, seed) ||
transitionTo(data, toAction, TransitionPhase.POST_MOVE, seed)
transitionTo(data, toAction, TransitionPhase.PRE_TRAVEL, seed) ||
transitionTo(data, toAction, TransitionPhase.INPUT, seed) ||
transitionTo(data, toAction, TransitionPhase.WORLD_COLLISION, seed)
) return true;

MarioQuaMario.LOGGER.warn("{} attempted an invalid action transition: {} -> {}", data.getMario().getName().getString(), this.ID, toAction.ID);
Expand All @@ -94,11 +93,11 @@ public void populateTransitionLists(Map<Identifier, ArrayList<ActionDefinition.A
MarioQuaMario.LOGGER.info("Parsing transitions out of {}...", this.ID);
ActionDefinition definition = (ActionDefinition) this.DEFINITION;
MarioQuaMario.LOGGER.info("PRE-TICK:-------");
this.TRANSITION_LISTS.put(TransitionPhase.PRE_TICK, this.parseTransitionDefinitions(definition.getPreTickTransitions(), injections));
this.TRANSITION_LISTS.put(TransitionPhase.PRE_TRAVEL, this.parseTransitionDefinitions(definition.getPreTravelTransitions(), injections));
MarioQuaMario.LOGGER.info("POST-TICK:------");
this.TRANSITION_LISTS.put(TransitionPhase.POST_TICK, this.parseTransitionDefinitions(definition.getPostTickTransitions(), injections));
this.TRANSITION_LISTS.put(TransitionPhase.INPUT, this.parseTransitionDefinitions(definition.getInputTransitions(), injections));
MarioQuaMario.LOGGER.info("POST-MOVE:------");
this.TRANSITION_LISTS.put(TransitionPhase.POST_MOVE, this.parseTransitionDefinitions(definition.getPostMoveTransitions(), injections));
this.TRANSITION_LISTS.put(TransitionPhase.WORLD_COLLISION, this.parseTransitionDefinitions(definition.getWorldCollisionTransitions(), injections));
}

private List<ParsedTransition> parseTransitionDefinitions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.floralquafloral.registries.states.action;

public enum TransitionPhase {
PRE_TICK,
POST_TICK,
POST_MOVE
PRE_TRAVEL,
INPUT,
WORLD_COLLISION
}
Loading

0 comments on commit 5ee47ba

Please sign in to comment.