Skip to content

Commit

Permalink
Further work on Actions implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Dec 16, 2024
1 parent 7a355be commit 440968c
Show file tree
Hide file tree
Showing 44 changed files with 1,495 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,4 @@ public class MarioQuaMarioAPI implements ModInitializer {
public void onInitialize() {
LOGGER.info("Mario qua Mario API initializing!");
}

@Environment(EnvType.CLIENT)
private void testasaur() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import com.fqf.mario_qua_mario.util.CharaStat;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface AirborneActionDefinition extends IncompleteActionDefinition {
void travelHook(IMarioTravelData data, AirborneActionHelper helper);

@NotNull List<TransitionDefinition> getBasicTransitions(AirborneActionHelper helper);
@NotNull List<TransitionDefinition> getInputTransitions(AirborneActionHelper helper);
@NotNull List<TransitionDefinition> getWorldCollisionTransitions(AirborneActionHelper helper);

/**
* Contains a number of methods intended to help with the creation of Airborne Actions.
*/
interface AirborneActionHelper {
void applyGravity(
IMarioTravelData data,
CharaStat gravity, @Nullable CharaStat jumpingGravity,
CharaStat terminalVelocity
);

void airborneAccel(
IMarioTravelData data,
CharaStat forwardAccelStat, CharaStat forwardSpeedStat,
CharaStat backwardAccelStat, CharaStat backwardSpeedStat,
CharaStat strafeAccelStat, CharaStat strafeSpeedStat,
double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectStat
);

TransitionDefinition makeJumpCapTransition(IncompleteActionDefinition forAction, double capThreshold);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import com.fqf.mario_qua_mario.util.CharaStat;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface AquaticActionDefinition extends IncompleteActionDefinition {
void travelHook(IMarioTravelData data, AquaticActionHelper helper);

@NotNull List<TransitionDefinition> getBasicTransitions(AquaticActionHelper helper);
@NotNull List<TransitionDefinition> getInputTransitions(AquaticActionHelper helper);
@NotNull List<TransitionDefinition> getWorldCollisionTransitions(AquaticActionHelper helper);

/**
* Contains a number of methods intended to help with the creation of Aquatic Actions.
*/
interface AquaticActionHelper {
void applyGravity(IMarioTravelData data, CharaStat gravity, CharaStat terminalVelocity);

void applyWaterDrag(IMarioTravelData data, CharaStat drag, CharaStat dragMin);

void aquaticAccel(
IMarioTravelData data,
CharaStat forwardAccelStat, CharaStat forwardSpeedStat,
CharaStat backwardAccelStat, CharaStat backwardSpeedStat,
CharaStat strafeAccelStat, CharaStat strafeSpeedStat,
double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectStat
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface GenericActionDefinition extends IncompleteActionDefinition {
void travelHook(IMarioTravelData data);

@NotNull List<TransitionDefinition> getBasicTransitions();
@NotNull List<TransitionDefinition> getInputTransitions();
@NotNull List<TransitionDefinition> getWorldCollisionTransitions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import com.fqf.mario_qua_mario.util.CharaStat;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface GroundedActionDefinition extends IncompleteActionDefinition {
void travelHook(IMarioTravelData data, GroundedActionHelper helper);

@NotNull List<TransitionDefinition> getBasicTransitions(GroundedActionHelper helper);
@NotNull List<TransitionDefinition> getInputTransitions(GroundedActionHelper helper);
@NotNull List<TransitionDefinition> getWorldCollisionTransitions(GroundedActionHelper helper);

/**
* Contains a number of methods intended to help with the creation of Grounded Actions. Can be cast to any of the
* other ActionHelpers, if for whatever reason you need them.
*/
interface GroundedActionHelper {
/**
* Accelerates Mario using a custom formula. This detaches Mario's ability to gain or lose speed from his
* ability to redirect the angle of existing speed. Unlike a regular entity, Mario's acceleration and
* decceleration is almost always linear, rather than being based on drag.
*
* @param forwardAccelStat The rate at which Mario's forward velocity will change. The absolute value is used.
* @param forwardSpeedStat The forward speed that Mario will try to reach. His acceleration won't overshoot
* this value; if {@code forwardAccelStat} is sufficient to accelerate him past it,
* he'll instead snap to its value. The value of this is scaled by the magnitude of
* Mario's forward input; when using a keyboard, the magnitude is either 0 or 1,
* but if the player is using a controller with an analog stick, it may be values in
* between.
* @param strafeAccelStat The rate at which Mario's sideways velocity will change. The absolute value is used.
* @param strafeSpeedStat The rightwards speed that Mario will try to accelerate towards. Works similarly to
* {@code forwardSpeedStat}. Negative values correspond to leftwards movement.
* @param forwardAngleContribution The forward component of Mario's intended angle of motion.
* @param strafeAngleContribution The rightward component of Mario's intended angle of motion.
* @param redirectStat How far, in degrees, Mario's current motion vector will rotate towards the vector made
* by {@code forwardAngleContribution} and {@code strafeAngleContribution}. This rotation
* occurs before acceleration; even with a {@code redirectStat} of 0 he'll still be able
* to change direction with his acceleration.
*/
void groundAccel(
IMarioTravelData data,
CharaStat forwardAccelStat, CharaStat forwardSpeedStat,
CharaStat strafeAccelStat, CharaStat strafeSpeedStat,
double forwardAngleContribution, double strafeAngleContribution, CharaStat redirectStat
);

/**
* Reduces Mario's speed by a portion of his current speed. It is recommended to use this sparingly;
* normal Minecraft entities are subject to drag every tick, but Mario should only experience drag when
* he's in an explicitly sliding-related action (or underwater). Under other circumstances, he should use
* {@link #groundAccel}.
*
* @param drag The fractional portion of Mario's speed that should be lost each tick. For example, a drag of
* 0.1 will result in 10% of Mario's speed being lost per tick.
* @param dragMin The minimum amount of speed lost per tick. Used to ensure Mario comes to a prompt stop
* instead of lingering on very low speed values.
* @param forwardAngleContribution The forward component of Mario's intended angle of motion.
* @param strafeAngleContribution The rightward component of Mario's intended angle of motion.
* @param redirection How far, in degrees, Mario's current motion vector will rotate towards the intended
* direction given by forwardAngleContribution and strafeAngleContribution.
*/
void applyDrag(
IMarioTravelData data,
CharaStat drag, CharaStat dragMin,
double forwardAngleContribution, double strafeAngleContribution,
CharaStat redirection
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition;
import com.fqf.mario_qua_mario.mariodata.IMarioReadableMotionData;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import com.fqf.mario_qua_mario.util.CharaStat;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public interface WallboundActionDefinition extends IncompleteActionDefinition {
void travelHook(IMarioTravelData data, WallInfo wall, WallboundActionHelper helper);

@NotNull List<TransitionDefinition> getBasicTransitions(WallboundActionHelper helper);
@NotNull List<TransitionDefinition> getInputTransitions(WallboundActionHelper helper);
@NotNull List<TransitionDefinition> getWorldCollisionTransitions(WallboundActionHelper helper);

/**
* Provides some information about the wall Mario is interacting with and his relationship to it.
*/
interface WallInfo {
Vec3d getWallNormal();
double getNormalYaw();

double getTowardsWallInput();
double getSidleInput();

double getSidleVel();
}

/**
* Contains a number of methods intended to help with the creation of Wallbound Actions.
*/
interface WallboundActionHelper {
WallInfo getWallInfo(IMarioReadableMotionData data);

void applyGravity(IMarioTravelData data, CharaStat gravity, CharaStat terminalVelocity);

void climbWall(
IMarioTravelData data,
CharaStat ascendSpeedStat, CharaStat ascendAccelStat,
CharaStat descendSpeedStat, CharaStat descendAccelStat,
CharaStat sidleSpeedStat, CharaStat sidleAccelStat
);

void setSidleVel(IMarioTravelData data, double sidleVel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

public enum EvaluatorContext {
CLIENT_ONLY,
SERVER_ONLY,
COMMON
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.fqf.mario_qua_mario.definitions.actions;
package com.fqf.mario_qua_mario.definitions.actions.util;

import com.fqf.mario_qua_mario.definitions.AttackInterceptingStateDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.*;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Set;

public interface ActionDefinition extends AttackInterceptingStateDefinition {
public interface IncompleteActionDefinition extends AttackInterceptingStateDefinition {
@Nullable String getAnimationName();
@Nullable CameraAnimationSet getCameraAnimations();
@NotNull SlidingStatus getSlidingStatus();
Expand All @@ -21,11 +18,5 @@ public interface ActionDefinition extends AttackInterceptingStateDefinition {
@Nullable BumpType getBumpType();
@Nullable Identifier getStompTypeID();

void travelHook(IMarioTravelData data);

@NotNull List<TransitionDefinition> getBasicTransitions();
@NotNull List<TransitionDefinition> getInputTransitions();
@NotNull List<TransitionDefinition> getWorldCollisionTransitions();

@NotNull Set<TransitionInjectionDefinition> getTransitionInjections();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
* This does have a server-side effect - if footsteps are suppressed, Sculk Sensors won't be triggered!
* <p>NOT_SLIDING: Vanilla behavior
* <p>NOT_SLIDING_SMOOTH: Footsteps occur, but no view-bobbing.
*
* <p>
* <p>SLIDING: No footsteps or view-bobbing. Sound effect is highly dependent on speed.
* <p>SKIDDING: No footsteps or view-bobbing. Sound effect mostly ignores speed.
* <p>WALL_SLIDING: No footsteps or view-bobbing. Plays a different sound effect, which completely ignores
* horizontal speed.
* <p>
* <p>SLIDING_SILENT: No footsteps or view-bobbing. No sound effect.
*/
public enum SlidingStatus {
NOT_SLIDING,
NOT_SLIDING_SMOOTH,

SLIDING,
SKIDDING,
WALL_SLIDING
WALL_SLIDING,

SLIDING_SILENT
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

import com.fqf.mario_qua_mario.mariodata.IMarioClientData;
import com.fqf.mario_qua_mario.mariodata.IMarioReadableMotionData;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
Expand All @@ -14,22 +15,22 @@
*/
public record TransitionDefinition(
@NotNull Identifier targetID,
@NotNull Evaluator evaluator,
@NotNull Evaluator evaluator, @NotNull EvaluatorContext context,
@Nullable TravelExecutor travelExecutor,
@Nullable ClientsExecutor clientsExecutor
) {
/**
* Alternate constructor provided for convenience
*/
public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator evaluator) {
this(targetID, evaluator, null, null);
public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator evaluator, @NotNull EvaluatorContext context) {
this(targetID, evaluator, context, null, null);
}

/**
* Runs on the client-side to test if the associated transition should occur.
*/
@FunctionalInterface public interface Evaluator {
boolean shouldTransition(IMarioTravelData data);
boolean shouldTransition(IMarioReadableMotionData data);
}

/**
Expand All @@ -45,6 +46,6 @@ public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator eva
* Runs on the client side for anyone who is in range to see Mario transition.
*/
@FunctionalInterface public interface ClientsExecutor {
boolean execute(IMarioClientData data, boolean isSelf, long seed);
void execute(IMarioClientData data, boolean isSelf, long seed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public enum InjectionPlacement {

public enum ActionCategory {
ANY,
GENERIC,
GROUNDED,
AIRBORNE,
AQUATIC,
WALL,
UNDEFINED
WALL
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.fqf.mario_qua_mario.mariodata;

import net.minecraft.util.Pair;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface IMarioTravelData extends IMarioReadableMotionData {
void setForwardVel(double forward);
void setStrafeVel(double strafe);
Expand All @@ -8,4 +14,26 @@ default void setForwardStrafeVel(double forward, double strafe) {
this.setStrafeVel(strafe);
}
void setYVel(double vertical);

void approachAngleAndAccel(
double forwardAccel, double forwardTarget, double strafeAccel, double strafeTarget,
double forwardAngleContribution, double strafeAngleContribution, double redirectDelta
);

@NotNull MarioTimers getTimers();
class MarioTimers {
public int actionTimer = 0;
public int jumpLandingTime = 0;
public int doubleJumpLandingTime = 0;

public boolean jumpCapped = false;

public boolean actionInterceptedAttack = false;

public boolean bumpedCeiling = false;
public boolean bumpedFloor = false;
public @Nullable WallBumpReaction bumpedWall = null;

public record WallBumpReaction(Direction direction, Vec3d originalVelocity) { }
}
}
Loading

0 comments on commit 440968c

Please sign in to comment.