Skip to content

Commit

Permalink
Implemented sideflip. Mario now negates damage from entities he's eli…
Browse files Browse the repository at this point in the history
…gible to stomp.
  • Loading branch information
floral-qua-floral committed Nov 17, 2024
1 parent 3a410d7 commit 7903a55
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/floralquafloral/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ActionTransitionDefinition> getPostTickTransitions() {
return List.of(
AerialTransitions.GROUND_POUND,
AerialTransitions.makeJumpCapTransition(this, 0.65)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +80,18 @@ public List<ActionTransitionDefinition> getPreTickTransitions() {
@Override
public List<ActionTransitionDefinition> 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
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down

0 comments on commit 7903a55

Please sign in to comment.