Skip to content

Commit

Permalink
Vehicles no longer cancel Mario's Action FSM. Instead he has a Mounte…
Browse files Browse the repository at this point in the history
…d action and dismounts by doing a backflip (currently just a regular jump). Also Toadette's enabled again (when did she leave??)
  • Loading branch information
floral-qua-floral committed Nov 9, 2024
1 parent 3af2880 commit e3e4136
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 17 deletions.
11 changes: 3 additions & 8 deletions src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public MarioPlayerData(PlayerEntity mario) {
isEnabled()
&& !mario.getAbilities().flying
&& !mario.isFallFlying()
&& !mario.hasVehicle()
// && !mario.hasVehicle()
// && !mario.isClimbing()
);
}


public boolean attemptDismount = false;

public abstract void tick();

Expand Down Expand Up @@ -169,12 +169,7 @@ public void setActionTransitionless(ParsedAction action) {
makeSkidSFX(action.SLIDING_STATUS.doWallSlideSfx(), action.SLIDING_STATUS.doSpeedScaling());
}
}
else {
if(this.action.ANIMATION != null)
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.mario, this.action.ANIMATION, 0);
if(action.ANIMATION != null)
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.mario, action.ANIMATION, 1);
}

this.action = action;
this.mario.setPose(this.mario.getPose());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public MarioMainClientData(ClientPlayerEntity mario) {
applyModifiedVelocity();

marioClient.updateLimbs(false);
return true;
return !marioClient.hasVehicle();
}

@Override public @NotNull MarioInputs getInputs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.floralquafloral.mariodata.moveable;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.registries.states.action.ParsedAction;
import com.floralquafloral.util.CPMIntegration;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;
Expand All @@ -25,7 +27,19 @@ public MarioServerData(ServerPlayerEntity mario) {
@Override public boolean travelHook(double forwardInput, double strafeInput) {
getAction().travelHook(this);
applyModifiedVelocity();
return true;
return !marioServer.hasVehicle();
}

@Override
public void setActionTransitionless(ParsedAction action) {
MarioQuaMario.LOGGER.info("MarioServerData setAction to {}", action.ID);

if(this.getAction().ANIMATION != null)
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.marioServer, this.getAction().ANIMATION, 0);
if(action.ANIMATION != null)
CPMIntegration.commonAPI.playAnimation(PlayerEntity.class, this.marioServer, action.ANIMATION, 1);

super.setActionTransitionless(action);
}

@Override public void tick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMarioClient;
import com.floralquafloral.mariodata.moveable.MarioMainClientData;
import com.floralquafloral.registries.stomp.StompHandler;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.option.GameOptions;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -19,4 +26,13 @@ private void onDamaged(Entity instance, DamageSource damageSource) {
}
instance.onDamaged(damageSource);
}

@WrapOperation(method = "onEntityPassengersSet", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/text/MutableText;"))
private MutableText adjustDismountHint(String key, Object[] args, Operation<MutableText> original) {
MarioMainClientData data = MarioMainClientData.getInstance();
if(data == null || !data.isEnabled()) return original.call(key, args);

GameOptions options = MinecraftClient.getInstance().options;
return Text.translatable("mount.onboard.mario", options.sneakKey.getBoundKeyLocalizedText(), options.jumpKey.getBoundKeyLocalizedText());
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/floralquafloral/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.mariodata.moveable.MarioServerData;
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.states.action.ParsedAction;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -77,4 +80,14 @@ private void executeStompsOnServer(MovementType movementType, Vec3d movement, Ca
}
}
}

@Inject(method = "startRiding(Lnet/minecraft/entity/Entity;Z)Z", at = @At("HEAD"))
private void setMountedAction(Entity entity, boolean force, CallbackInfoReturnable<Boolean> cir) {
if((Entity) (Object) this instanceof PlayerEntity mario) {
MarioPlayerData data = MarioDataManager.getMarioData(mario);

data.attemptDismount = false;
data.setActionTransitionless(RegistryManager.ACTIONS.get(Identifier.of("qua_mario:mounted")));
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/floralquafloral/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.registries.stomp.ParsedStomp;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -18,4 +23,12 @@ private void addStompPiercingDamage(DamageSource source, float amount, CallbackI
cir.setReturnValue(cir.getReturnValue() + stompDamageSource.getPiercing());
}
}

@WrapOperation(method = "onDismounted", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;requestTeleportAndDismount(DDD)V"))
private void marioDismountsInPlace(LivingEntity instance, double x, double y, double z, Operation<Void> original) {
if((LivingEntity) (Object) this instanceof PlayerEntity mario && ((MarioData) MarioDataManager.getMarioData(mario)).isEnabled())
original.call(instance, mario.getX(), Math.max(mario.getY(), instance.getY()), mario.getZ());
else
original.call(instance, x, y, z);
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,19 @@ public void slideOffLedges(CallbackInfoReturnable<Boolean> cir) {
}

@Inject(method = "tickMovement", at = @At("TAIL"))
public void uwuuber(CallbackInfo ci) {
public void preventViewBobbing(CallbackInfo ci) {
MarioData data = MarioDataManager.getMarioData(this);
if(data.isClient() && !data.getAction().SLIDING_STATUS.doViewBobbing()) {
strideDistance = prevStrideDistance * 0.6F;
}
}

@Inject(method = "shouldDismount", at = @At("HEAD"), cancellable = true)
public void changeDismounting(CallbackInfoReturnable<Boolean> cir) {
MarioPlayerData data = MarioDataManager.getMarioData(this);
if(data.isEnabled()) {
cir.setReturnValue(data.attemptDismount);
if(data.attemptDismount) data.attemptDismount = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.floralquafloral.registries.states.action.baseactions;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.mariodata.moveable.MarioServerData;
import com.floralquafloral.mariodata.moveable.MarioTravelData;
import com.floralquafloral.registries.states.action.ActionDefinition;
import com.floralquafloral.registries.states.action.AirborneActionDefinition;
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;

public class Mounted implements ActionDefinition {
@Override @NotNull public Identifier getID() {
return Identifier.of(MarioQuaMario.MOD_ID, "mounted");
}
@Override @Nullable public String getAnimationName() {
return null;
}

@Override
public void travelHook(MarioTravelData data) {
AirborneActionDefinition.jumpCapped = false;
}

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

@Override
public void serverTick(MarioServerData data) {

}

@Override public SneakLegalityRule getSneakLegalityRule() {
return SneakLegalityRule.ALLOW;
}
@Override public SlidingStatus getConstantSlidingStatus() {
return SlidingStatus.NOT_SLIDING;
}
@Override public @Nullable Identifier getStompType() {
return null;
}

@Override
public List<ActionTransitionDefinition> getPreTickTransitions() {
return List.of(
new ActionTransitionDefinition("qua_mario:jump",
data -> !data.getMario().hasVehicle() && ((MarioPlayerData) data).attemptDismount,
data -> {
((MarioPlayerData) data).attemptDismount = false;
assert GroundedActionDefinition.GroundedTransitions.JUMP.EXECUTOR_TRAVELLERS != null;
GroundedActionDefinition.GroundedTransitions.JUMP.EXECUTOR_TRAVELLERS.execute(data);
},
GroundedActionDefinition.GroundedTransitions.JUMP.EXECUTOR_CLIENTS
),
new ActionTransitionDefinition("qua_mario:fall",
data -> !data.getMario().hasVehicle() && !((MarioPlayerData) data).attemptDismount
),
new ActionTransitionDefinition("qua_mario:mounted",
(data) -> (!((MarioPlayerData) data).attemptDismount) && data.getInputs().DUCK.isHeld() && data.getInputs().JUMP.isPressed(),
data -> ((MarioPlayerData) data).attemptDismount = true,
null
)
);
}

@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 @@ -149,10 +149,7 @@ private boolean attemptOnTarget(ServerPlayerEntity mario, MarioServerData data,
if(this.SHOULD_ATTEMPT_MOUNTING) {
if((target instanceof Saddleable saddleableTarget && saddleableTarget.isSaddled())
|| target instanceof VehicleEntity) {
if(mario.startRiding(target)) {
MarioDataPackets.forceSetMarioAction(mario, RegistryManager.ACTIONS.get(Identifier.of("qua_mario:basic")));
return true;
}
if(mario.startRiding(target)) return true;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/qua_mario/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"text.autoconfig.qua_mario.option.spinputType": "Spin Input Type",
"fabric.mods.qua_mario.spin": "Spin",

"mount.onboard.mario": "Hold %s and press %s to Dismount",

"text.autoconfig.qua_mario.option.sideflipAnimType": "Sideflip Camera Animation",
"text.autoconfig.qua_mario.option.backflipAnimType": "Backflip Camera Animation",
"text.autoconfig.qua_mario.option.tripleJumpAnimType": "Triple Jump Camera Animation",
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

"mario-actions-uncategorized": [
"com.floralquafloral.registries.states.action.baseactions.ActionDebug",
"com.floralquafloral.registries.states.action.baseactions.ActionDebugAlt"
"com.floralquafloral.registries.states.action.baseactions.ActionDebugAlt",
"com.floralquafloral.registries.states.action.baseactions.Mounted"
],
"mario-actions-grounded": [
"com.floralquafloral.registries.states.action.baseactions.grounded.ActionBasic",
Expand Down Expand Up @@ -49,7 +50,8 @@
],
"mario-characters": [
"com.floralquafloral.registries.states.character.basecharacters.Mario",
"com.floralquafloral.registries.states.character.basecharacters.Luigi"
"com.floralquafloral.registries.states.character.basecharacters.Luigi",
"com.floralquafloral.registries.states.character.basecharacters.Toadette"
],

"main": [
Expand Down

0 comments on commit e3e4136

Please sign in to comment.