Skip to content

Commit

Permalink
More mixins; useMarioPhysics from old version
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Dec 23, 2024
1 parent cb47b45 commit d40b45a
Show file tree
Hide file tree
Showing 19 changed files with 375 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fqf.mario_qua_mario.definitions.states.actions.util.IncompleteActionDefinition;
import com.fqf.mario_qua_mario.definitions.states.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 org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -70,5 +71,7 @@ void applyDrag(
double forwardAngleContribution, double strafeAngleContribution,
CharaStat redirection
);

double getSlipFactor(IMarioReadableMotionData data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum EvaluatorEnvironment {
CLIENT_ONLY,
SERVER_ONLY,
COMMON
COMMON,
CLIENT_CHECKED
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public interface IMarioReadableMotionData extends IMarioData {
double getStrafeVel();
double getYVel();

double getHorizVel();
double getHorizVelSquared();

MarioInputs getInputs();

abstract class MarioInputs {
Expand Down
16 changes: 11 additions & 5 deletions api/src/main/java/com/fqf/mario_qua_mario/util/CharaStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
* This is used for movement, speed thresholds, and damage calculations.
*/
public class CharaStat {
public final double BASE;
public static final CharaStat ZERO = new CharaStat(0);

public final double BASE_VALUE;
public final Set<StatCategory> CATEGORIES;

public CharaStat(double base, StatCategory... categories) {
this(base, Set.of(categories));
public CharaStat(double baseValue, StatCategory... categories) {
this(baseValue, Set.of(categories));
}
public CharaStat variate(double multiplier) {
return new CharaStat(this.BASE * multiplier, this.CATEGORIES);
return new CharaStat(this.BASE_VALUE * multiplier, this.CATEGORIES);
}

private CharaStat(double base, Set<StatCategory> categorySet) {
this.BASE = base;
this.BASE_VALUE = base;
this.CATEGORIES = categorySet;
}

Expand All @@ -30,6 +32,10 @@ public double get(IMarioData data) {
public double getAsThreshold(IMarioData data) {
return this.get(data) * 0.96;
}
public double getAsSquaredThreshold(IMarioData data) {
double threshold = this.getAsThreshold(data);
return threshold * threshold;
}
public double getAsLimit(IMarioData data) {
return this.get(data) * 1.015;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import com.fqf.mario_qua_mario.mariodata.IMarioAuthoritativeData;
import com.fqf.mario_qua_mario.mariodata.IMarioClientData;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import com.fqf.mario_qua_mario.util.CharaStat;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

import static com.fqf.mario_qua_mario.util.StatCategory.*;

public class SubWalk implements GroundedActionDefinition {
@Override public @NotNull Identifier getID() {
return MarioQuaMarioContent.makeID("sub_walk");
Expand All @@ -25,14 +28,14 @@ public class SubWalk implements GroundedActionDefinition {
return null;
}
@Override public @NotNull SlidingStatus getSlidingStatus() {
return SlidingStatus.SLIDING_SILENT;
return SlidingStatus.NOT_SLIDING;
}

@Override public @NotNull SneakingRule getSneakingRule() {
return SneakingRule.PROHIBIT;
}
@Override public @NotNull SprintingRule getSprintingRule() {
return SprintingRule.ALLOW;
return SprintingRule.PROHIBIT;
}

@Override public @Nullable BumpType getBumpType() {
Expand All @@ -42,19 +45,107 @@ public class SubWalk implements GroundedActionDefinition {
return null;
}

public static final CharaStat WALK_ACCEL = new CharaStat(0.045, WALKING, FORWARD, ACCELERATION);
public static final CharaStat WALK_STANDSTILL_ACCEL = new CharaStat(0.125, WALKING, FORWARD, ACCELERATION, FRICTION);
public static final CharaStat WALK_STANDSTILL_THRESHOLD = new CharaStat(0.12, WALKING, THRESHOLD);
public static final CharaStat WALK_SPEED = new CharaStat(0.275, WALKING, SPEED, FORWARD);
public static final CharaStat WALK_REDIRECTION = new CharaStat(0.0, WALKING, FORWARD, REDIRECTION);

public static final CharaStat OVERWALK_ACCEL = new CharaStat(0.028, WALKING, FORWARD, OVERSPEED_CORRECTION);

public static final CharaStat IDLE_DEACCEL = new CharaStat(0.075, WALKING, FRICTION);

public static final CharaStat BACKPEDAL_ACCEL = new CharaStat(0.055, WALKING, BACKWARD, ACCELERATION);
public static final CharaStat BACKPEDAL_SPEED = new CharaStat(0.225, WALKING, BACKWARD, SPEED);
public static final CharaStat BACKPEDAL_REDIRECTION = new CharaStat(0.0, WALKING, BACKWARD, REDIRECTION);
public static final CharaStat OVERBACKPEDAL_ACCEL = new CharaStat(0.04, WALKING, BACKWARD, OVERSPEED_CORRECTION);
public static final CharaStat UNDERBACKPEDAL_ACCEL = new CharaStat(0.055, WALKING, BACKWARD, ACCELERATION, FRICTION);

public static final CharaStat STRAFE_ACCEL = new CharaStat(0.065, WALKING, STRAFE, ACCELERATION);
public static final CharaStat STRAFE_SPEED = new CharaStat(0.275, WALKING, STRAFE, SPEED);

@Override public void clientTick(IMarioClientData data, boolean isSelf) {

}
@Override public void serverTick(IMarioAuthoritativeData data) {

}
@Override public void travelHook(IMarioTravelData data, GroundedActionHelper helper) {

if(data.getInputs().getForwardInput() > 0) {
if(data.getForwardVel() > WALK_SPEED.getAsLimit(data)) {
// Overwalk
helper.groundAccel(data,
OVERWALK_ACCEL, WALK_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
WALK_REDIRECTION
);
}
else if(data.getForwardVel() <= WALK_STANDSTILL_THRESHOLD.getAsThreshold(data)) {
// Walk accel from low velocity
helper.groundAccel(data,
WALK_STANDSTILL_ACCEL, WALK_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
WALK_REDIRECTION
);
}
else {
// Walk accel
helper.groundAccel(data,
WALK_ACCEL, WALK_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
WALK_REDIRECTION
);
}
}
else if(data.getInputs().getForwardInput() < 0) {
if(data.getForwardVel() > 0) {
// Under-backpedal
helper.groundAccel(data,
UNDERBACKPEDAL_ACCEL, BACKPEDAL_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
BACKPEDAL_REDIRECTION
);
}
else if(data.getForwardVel() < BACKPEDAL_SPEED.getAsLimit(data)) {
// Over-backpedal
helper.groundAccel(data,
OVERBACKPEDAL_ACCEL, BACKPEDAL_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
BACKPEDAL_REDIRECTION
);
}
else {
// Backpedal Accel
helper.groundAccel(data,
BACKPEDAL_ACCEL, BACKPEDAL_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
BACKPEDAL_REDIRECTION
);
}
}
else {
// Idle deaccel
helper.groundAccel(data,
IDLE_DEACCEL, CharaStat.ZERO,
STRAFE_ACCEL, STRAFE_SPEED,
0.0, 0.0, CharaStat.ZERO
);
}
}

@Override public @NotNull List<TransitionDefinition> getBasicTransitions(GroundedActionHelper helper) {
return List.of(

new TransitionDefinition(
MarioQuaMarioContent.makeID("walk_run"),
WalkRun::meetsWalkRunRequirement,
EvaluatorEnvironment.CLIENT_ONLY
)
);
}
@Override public @NotNull List<TransitionDefinition> getInputTransitions(GroundedActionHelper helper) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.fqf.mario_qua_mario.actions.grounded;

import com.fqf.mario_qua_mario.MarioQuaMarioContent;
import com.fqf.mario_qua_mario.definitions.states.actions.GroundedActionDefinition;
import com.fqf.mario_qua_mario.definitions.states.actions.util.*;
import com.fqf.mario_qua_mario.mariodata.IMarioAuthoritativeData;
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 com.fqf.mario_qua_mario.util.CharaStat;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

import static com.fqf.mario_qua_mario.util.StatCategory.*;
import static com.fqf.mario_qua_mario.util.StatCategory.OVERSPEED_CORRECTION;

public class WalkRun extends SubWalk implements GroundedActionDefinition {
@Override public @NotNull Identifier getID() {
return MarioQuaMarioContent.makeID("walk_run");
}

@Override public @NotNull SprintingRule getSprintingRule() {
return SprintingRule.ALLOW;
}

public static final CharaStat RUN_ACCEL = new CharaStat(0.0175, RUNNING, FORWARD, ACCELERATION);
public static final CharaStat RUN_SPEED = new CharaStat(0.55, RUNNING, FORWARD, SPEED);
public static final CharaStat RUN_REDIRECTION = new CharaStat(2.76, RUNNING, FORWARD, REDIRECTION);
public static final CharaStat OVERRUN_ACCEL = new CharaStat(0.0175, RUNNING, FORWARD, OVERSPEED_CORRECTION);

public static boolean meetsWalkRunRequirement(IMarioReadableMotionData data) {
return data.getInputs().getForwardInput() > 0 &&
data.getForwardVel() > WALK_STANDSTILL_THRESHOLD.get(data) &&
data.getHorizVelSquared() > WALK_SPEED.getAsSquaredThreshold(data);
}

@Override public void travelHook(IMarioTravelData data, GroundedActionHelper helper) {
if(data.getMario().isSprinting()) {
if(data.getForwardVel() > RUN_SPEED.getAsLimit(data)) {
// Overrun
helper.groundAccel(data,
OVERRUN_ACCEL, RUN_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput() * 0.8,
RUN_REDIRECTION
);
}
else {
// Run Accel
helper.groundAccel(data,
RUN_ACCEL, RUN_SPEED,
STRAFE_ACCEL, STRAFE_SPEED,
data.getInputs().getForwardInput(), data.getInputs().getStrafeInput(),
RUN_REDIRECTION
);
}
}
else super.travelHook(data, helper);
}

@Override public @NotNull List<TransitionDefinition> getBasicTransitions(GroundedActionHelper helper) {
return List.of(
new TransitionDefinition(
MarioQuaMarioContent.makeID("sub_walk"),
data -> !meetsWalkRunRequirement(data),
EvaluatorEnvironment.CLIENT_ONLY
)
);
}

@Override public @NotNull Set<TransitionInjectionDefinition> getTransitionInjections() {
return Set.of();
}
}
3 changes: 2 additions & 1 deletion content/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"com.fqf.mario_qua_mario.actions.generic.DebugSprint"
],
"mqm-grounded-actions": [
"com.fqf.mario_qua_mario.actions.grounded.SubWalk"
"com.fqf.mario_qua_mario.actions.grounded.SubWalk",
"com.fqf.mario_qua_mario.actions.grounded.WalkRun"
],
"mqm-airborne-actions": [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import org.jetbrains.annotations.NotNull;

public interface MarioMainClientDataHolder extends MarioDataHolder {
@SuppressWarnings("DataFlowIssue") @Override
default @NotNull MarioMainClientData mqm$getMarioData() {
return null;
throw new AssertionError("MarioMainClientDataHolder default method called?!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import org.jetbrains.annotations.NotNull;

public interface MarioOtherClientDataHolder extends MarioDataHolder {
@SuppressWarnings("DataFlowIssue") @Override
default @NotNull MarioOtherClientData mqm$getMarioData() {
return null;
throw new AssertionError("MarioOtherClientDataHolder default method called?!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fqf.mario_qua_mario.mixin.client;

import com.fqf.mario_qua_mario.definitions.states.actions.util.SprintingRule;
import com.fqf.mario_qua_mario.mariodata.injections.MarioMainClientDataHolder;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerEntity.class)
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity implements MarioMainClientDataHolder {
public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
super(world, profile);
throw new AssertionError("Mixin constructor?!");
}

@Inject(method = "canSprint", at = @At("HEAD"), cancellable = true)
private void preventSprinting(CallbackInfoReturnable<Boolean> cir) {
if(mqm$getMarioData().doMarioTravel() && mqm$getMarioData().getAction().SPRINTING_RULE == SprintingRule.PROHIBIT)
cir.setReturnValue(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fqf.mario_qua_mario.packets;

import com.fqf.mario_qua_mario.MarioClientHelperManager;
import com.fqf.mario_qua_mario.MarioQuaMario;
import com.fqf.mario_qua_mario.registries.RegistryManager;
import com.fqf.mario_qua_mario.registries.actions.AbstractParsedAction;
import com.fqf.mario_qua_mario.registries.actions.ParsedActionHelper;
Expand Down Expand Up @@ -55,6 +56,7 @@ public static PlayerEntity getMarioFromID(ClientPlayNetworking.Context context,

@Override
public void setActionC2S(AbstractParsedAction fromAction, AbstractParsedAction toAction, long seed) {
MarioQuaMario.LOGGER.info("Sending setActionC2S Packet for {}->{}", fromAction.ID, toAction.ID);
ClientPlayNetworking.send(new MarioDataPackets.SetActionC2SPayload(fromAction.getIntID(), toAction.getIntID(), seed));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_21",
"client": [
"ClientPlayerEntityMarioDataMixin",
"ClientPlayerEntityMixin",
"InGameHudMixin",
"OtherClientPlayerEntityMarioDataMixin"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ private void apply() {
if(this.VELOCITIES.isGenerated) return this.VELOCITIES.vertical;
else return this.getMario().getVelocity().y;
}
@Override public double getHorizVel() {
return this.getMario().getVelocity().horizontalLength();
}
@Override public double getHorizVelSquared() {
return this.getMario().getVelocity().horizontalLengthSquared();
}

@Override public void setForwardVel(double forward) {
VELOCITIES.ensureDirty().forward = forward;
Expand Down
Loading

0 comments on commit d40b45a

Please sign in to comment.