From 7903a55a3e25e4c1c528f390030f80a4d5e3038f Mon Sep 17 00:00:00 2001 From: Floral <49110090+floral-qua-floral@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:23:35 -0500 Subject: [PATCH] Implemented sideflip. Mario now negates damage from entities he's eligible to stomp. --- .../com/floralquafloral/MarioQuaMario.java | 16 +++++- .../mariodata/MarioClientSideData.java | 2 +- .../action/baseactions/airborne/Sideflip.java | 53 +++++++++++++++++++ .../action/baseactions/grounded/Skid.java | 14 ++++- .../registries/stomp/ParsedStomp.java | 2 + src/main/resources/fabric.mod.json | 1 + 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Sideflip.java diff --git a/src/main/java/com/floralquafloral/MarioQuaMario.java b/src/main/java/com/floralquafloral/MarioQuaMario.java index 25f45aa..811d08c 100644 --- a/src/main/java/com/floralquafloral/MarioQuaMario.java +++ b/src/main/java/com/floralquafloral/MarioQuaMario.java @@ -19,6 +19,8 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.particle.SimpleParticleType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; @@ -79,7 +81,19 @@ public void onInitialize() { MarioCommand.registerMarioCommand(); - ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, damageAmount) -> { + // Mario can't be damaged by a mob that he's high enough to stomp on + ServerLivingEntityEvents.ALLOW_DAMAGE.register((livingEntity, damageSource, amount) -> { + if(livingEntity instanceof PlayerEntity player && damageSource.getSource() instanceof LivingEntity sourceEntity && sourceEntity.equals(damageSource.getAttacker())) { + MarioData data = MarioDataManager.getMarioData(player); + if(data.isEnabled() && livingEntity.getY() >= sourceEntity.getY() + sourceEntity.getHeight() && data.getAction().STOMP != null) { + LOGGER.info("Prevented Mario from taking damage against {} due to stomp eligibility.", sourceEntity); + return false; + } + } + return true; + }); + + ServerLivingEntityEvents.ALLOW_DEATH.register((livingEntity, damageSource, amount) -> { if(livingEntity instanceof ServerPlayerEntity player) { MarioData data = MarioDataManager.getMarioData(player); if(data.isEnabled()) { diff --git a/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java b/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java index 84239fd..487dc4b 100644 --- a/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java +++ b/src/main/java/com/floralquafloral/mariodata/MarioClientSideData.java @@ -78,7 +78,7 @@ default PositionedSoundInstance voice(VoiceLine line, long seed) { PositionedSoundInstance newSoundInstance = this.playSoundEvent( line.SOUND_EVENTS.get(this.getCharacter()), SoundCategory.VOICE, mario.getX(), mario.getY(), mario.getZ(), - 1.0F, this.getPowerUp().VOICE_PITCH, + this.getPowerUp().VOICE_PITCH, 1.0F, seed ); VoiceLine.MARIO_VOICE_LINES.put(this, newSoundInstance); diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Sideflip.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Sideflip.java new file mode 100644 index 0000000..6e64dca --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/Sideflip.java @@ -0,0 +1,53 @@ +package com.floralquafloral.registries.states.action.baseactions.airborne; + +import com.floralquafloral.MarioQuaMario; +import com.floralquafloral.mariodata.moveable.MarioTravelData; +import com.floralquafloral.stats.CharaStat; +import com.floralquafloral.stats.StatCategory; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +import static com.floralquafloral.util.MixedEasing.*; + +public class Sideflip extends Jump { + @Override public @NotNull Identifier getID() { + return Identifier.of(MarioQuaMario.MOD_ID, "sideflip"); + } + @Override public @Nullable String getAnimationName() { + return "sideflip"; + } + @Override @Nullable public CameraAnimationSet getCameraAnimations() { + return new CameraAnimationSet( + new CameraAnimation( + false, 1.0F, + (progress, offsets) -> { + offsets[0] = 180 * (1 - mixedEase(progress, SINE, SINE)); + offsets[2] = mixedEase(progress, SINE, CUBIC) * -360; + } + ), + null, + null + ); + } + + public static CharaStat SIDEFLIP_VEL = new CharaStat(1.065, StatCategory.JUMP_VELOCITY); + public static CharaStat SIDEFLIP_BACKWARDS_SPEED = new CharaStat(-0.375, + StatCategory.DRIFTING, StatCategory.BACKWARD, StatCategory.SPEED); + public static CharaStat SIDEFLIP_THRESHOLD = new CharaStat(0.2, + StatCategory.RUNNING, StatCategory.THRESHOLD); + + @Override + public void airborneTravel(MarioTravelData data) { + if(data.getYVel() < 0.1) airborneAccel(data); + } + + @Override public List getPostTickTransitions() { + return List.of( + AerialTransitions.GROUND_POUND, + AerialTransitions.makeJumpCapTransition(this, 0.65) + ); + } +} diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/Skid.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/Skid.java index cc06d07..30f715a 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/Skid.java +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/grounded/Skid.java @@ -5,6 +5,7 @@ import com.floralquafloral.mariodata.moveable.MarioServerData; import com.floralquafloral.mariodata.moveable.MarioTravelData; import com.floralquafloral.registries.states.action.GroundedActionDefinition; +import com.floralquafloral.registries.states.action.baseactions.airborne.Sideflip; import com.floralquafloral.stats.CharaStat; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -79,7 +80,18 @@ public List getPreTickTransitions() { @Override public List getPostTickTransitions() { return List.of( - // Sideflip!!! + new ActionTransitionDefinition("qua_mario:sideflip", + data -> data.getForwardVel() < Sideflip.SIDEFLIP_THRESHOLD.get(data) && data.getInputs().JUMP.isPressed(), + data -> { + GroundedTransitions.performJump(data, Sideflip.SIDEFLIP_VEL, null); + data.setForwardStrafeVel(Sideflip.SIDEFLIP_BACKWARDS_SPEED.get(data), 0); + data.getMario().setYaw(data.getMario().getYaw() + 180); + }, + (data, isSelf, seed) -> { + data.playJumpSound(seed); + data.voice(MarioClientSideData.VoiceLine.SIDEFLIP, seed); + } + ), GroundedTransitions.JUMP ); } diff --git a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java index feeabfe..7b04ee2 100644 --- a/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java +++ b/src/main/java/com/floralquafloral/registries/stomp/ParsedStomp.java @@ -101,6 +101,7 @@ else if (entry.attribute().value().equals(EntityAttributes.GENERIC_ARMOR_TOUGHNE if(target.damage(stompDamageSource, Math.max(1.0F, damage - 0.6F * stompDamageSource.piercing))) { if(affectMario) { + mario.fallDistance = 0; this.DEFINITION.executeTravellers(data, target, harmless); if(this.POST_STOMP_ACTION != null) data.setActionTransitionless(Objects.requireNonNull(RegistryManager.ACTIONS.get(this.POST_STOMP_ACTION))); @@ -111,6 +112,7 @@ else if (entry.attribute().value().equals(EntityAttributes.GENERIC_ARMOR_TOUGHNE return false; } public void executeClient(MarioClientSideData data, boolean isSelf, Entity target, boolean harmless, long seed) { + data.getMario().fallDistance = 0; if(this.SOUND_EVENT != null) { data.playSoundEvent( this.SOUND_EVENT, diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0fcb131..ce09a19 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -39,6 +39,7 @@ "com.floralquafloral.registries.states.action.baseactions.airborne.LongJump", "com.floralquafloral.registries.states.action.baseactions.airborne.Stomp", "com.floralquafloral.registries.states.action.baseactions.airborne.Backflip", + "com.floralquafloral.registries.states.action.baseactions.airborne.Sideflip", "com.floralquafloral.registries.states.action.baseactions.airborne.DoubleJump", "com.floralquafloral.registries.states.action.baseactions.airborne.TripleJump" ],