From e3e413647a81783f6657452c16d579979ee7e91c Mon Sep 17 00:00:00 2001 From: Floral <49110090+floral-qua-floral@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:47:33 -0500 Subject: [PATCH] Vehicles no longer cancel Mario's Action FSM. Instead he has a Mounted action and dismounts by doing a backflip (currently just a regular jump). Also Toadette's enabled again (when did she leave??) --- .../mariodata/MarioPlayerData.java | 11 +-- .../moveable/MarioMainClientData.java | 2 +- .../mariodata/moveable/MarioServerData.java | 16 +++- .../mixin/ClientPlayNetworkHandlerMixin.java | 16 ++++ .../floralquafloral/mixin/EntityMixin.java | 13 +++ .../mixin/LivingEntityMixin.java | 13 +++ .../mixin/PlayerEntityMixin.java | 11 ++- .../states/action/baseactions/Mounted.java | 85 +++++++++++++++++++ .../registries/stomp/ParsedStomp.java | 5 +- .../assets/qua_mario/lang/en_us.json | 2 + src/main/resources/fabric.mod.json | 6 +- 11 files changed, 163 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/floralquafloral/registries/states/action/baseactions/Mounted.java diff --git a/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java b/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java index 5357719..cf3e03b 100644 --- a/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java +++ b/src/main/java/com/floralquafloral/mariodata/MarioPlayerData.java @@ -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(); @@ -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()); diff --git a/src/main/java/com/floralquafloral/mariodata/moveable/MarioMainClientData.java b/src/main/java/com/floralquafloral/mariodata/moveable/MarioMainClientData.java index 924e962..e5cf373 100644 --- a/src/main/java/com/floralquafloral/mariodata/moveable/MarioMainClientData.java +++ b/src/main/java/com/floralquafloral/mariodata/moveable/MarioMainClientData.java @@ -73,7 +73,7 @@ public MarioMainClientData(ClientPlayerEntity mario) { applyModifiedVelocity(); marioClient.updateLimbs(false); - return true; + return !marioClient.hasVehicle(); } @Override public @NotNull MarioInputs getInputs() { diff --git a/src/main/java/com/floralquafloral/mariodata/moveable/MarioServerData.java b/src/main/java/com/floralquafloral/mariodata/moveable/MarioServerData.java index d22f2e0..88a96a2 100644 --- a/src/main/java/com/floralquafloral/mariodata/moveable/MarioServerData.java +++ b/src/main/java/com/floralquafloral/mariodata/moveable/MarioServerData.java @@ -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; @@ -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() { diff --git a/src/main/java/com/floralquafloral/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/com/floralquafloral/mixin/ClientPlayNetworkHandlerMixin.java index 3519e3b..b0ccfe0 100644 --- a/src/main/java/com/floralquafloral/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/com/floralquafloral/mixin/ClientPlayNetworkHandlerMixin.java @@ -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; @@ -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 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()); + } } diff --git a/src/main/java/com/floralquafloral/mixin/EntityMixin.java b/src/main/java/com/floralquafloral/mixin/EntityMixin.java index 6682b84..6512117 100644 --- a/src/main/java/com/floralquafloral/mixin/EntityMixin.java +++ b/src/main/java/com/floralquafloral/mixin/EntityMixin.java @@ -3,7 +3,9 @@ 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; @@ -11,6 +13,7 @@ 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; @@ -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 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"))); + } + } } diff --git a/src/main/java/com/floralquafloral/mixin/LivingEntityMixin.java b/src/main/java/com/floralquafloral/mixin/LivingEntityMixin.java index 0b19c95..0d61d08 100644 --- a/src/main/java/com/floralquafloral/mixin/LivingEntityMixin.java +++ b/src/main/java/com/floralquafloral/mixin/LivingEntityMixin.java @@ -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; @@ -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 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); + } } diff --git a/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java b/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java index a5cae88..a8d65b3 100644 --- a/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java @@ -75,10 +75,19 @@ public void slideOffLedges(CallbackInfoReturnable 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 cir) { + MarioPlayerData data = MarioDataManager.getMarioData(this); + if(data.isEnabled()) { + cir.setReturnValue(data.attemptDismount); + if(data.attemptDismount) data.attemptDismount = false; + } + } } diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/Mounted.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/Mounted.java new file mode 100644 index 0000000..6341ae9 --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/Mounted.java @@ -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 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 getPostTickTransitions() { + return List.of(); + } + + @Override + public List getPostMoveTransitions() { + return List.of(); + } + + @Override + public List getTransitionInjections() { + return List.of(); + } +} diff --git a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java index e87a426..1e334cd 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java @@ -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; } } diff --git a/src/main/resources/assets/qua_mario/lang/en_us.json b/src/main/resources/assets/qua_mario/lang/en_us.json index 0a6c208..99a7344 100644 --- a/src/main/resources/assets/qua_mario/lang/en_us.json +++ b/src/main/resources/assets/qua_mario/lang/en_us.json @@ -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", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 12e6af7..396fd6d 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -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", @@ -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": [