Skip to content

Commit

Permalink
Starting on unarmed attack interception
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Nov 24, 2024
1 parent 5aa3149 commit 565751c
Show file tree
Hide file tree
Showing 48 changed files with 485 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import java.util.Map;

public interface CharacterDefinition extends MarioMajorStateDefinition {
public interface CharacterDefinition extends MarioStatAlteringStateDefinition {
@NotNull Map<String, String> getPoweredUpPlayermodels();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.floralquafloral.definitions;

import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioTravelData;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

public interface MarioAttackInterceptingStateDefinition extends MarioStateDefinition {
boolean interceptAttack(
MarioData data, @Nullable MarioClientSideData clientData, @Nullable MarioTravelData travelData,
@Nullable Entity entityTarget, @Nullable BlockPos blockTarget
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Map;
import java.util.Set;

public interface MarioMajorStateDefinition extends MarioStateDefinition {
public interface MarioStatAlteringStateDefinition extends MarioStateDefinition {
void populateStatModifiers(Map<Set<StatCategory>, Double> modifiers);

int getBumpStrengthModifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.Map;

public interface PowerUpDefinition extends MarioMajorStateDefinition {
public interface PowerUpDefinition extends MarioStatAlteringStateDefinition, MarioAttackInterceptingStateDefinition {
@NotNull Map<String, String> getCharacterPlayermodels();

void acquirePower(MarioData data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.floralquafloral.definitions.actions;

import com.floralquafloral.definitions.MarioAttackInterceptingStateDefinition;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.definitions.MarioStateDefinition;
import com.floralquafloral.mariodata.MarioData;
Expand All @@ -11,7 +12,7 @@

import java.util.List;

public interface ActionDefinition extends MarioStateDefinition {
public interface ActionDefinition extends MarioStateDefinition, MarioAttackInterceptingStateDefinition {
@Nullable String getAnimationName();
@Nullable CameraAnimationSet getCameraAnimations();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public static ActionTransitionDefinition makeJumpCapTransition(ActionDefinition
public static final ActionTransitionDefinition DOUBLE_JUMPABLE_LANDING = new ActionTransitionDefinition(
"qua_mario:basic",
BASIC_LANDING.EVALUATOR,
data -> data.getTimers().jumpLandingTime = 5,
data -> data.getTimers().jumpLandingTime = 3,
null
);
public static final ActionTransitionDefinition TRIPLE_JUMPABLE_LANDING = new ActionTransitionDefinition(
"qua_mario:basic",
BASIC_LANDING.EVALUATOR,
data -> data.getTimers().doubleJumpLandingTime = 5,
data -> data.getTimers().doubleJumpLandingTime = 3,
null
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract static class AquaticStats {
public static final CharaStat BACKWARD_SWIM_ACCEL = new CharaStat(0.035, SWIMMING, BACKWARD, ACCELERATION);
public static final CharaStat BACKWARD_SWIM_SPEED = new CharaStat(0.2, SWIMMING, BACKWARD, SPEED);

public static final CharaStat STRAFE_SWIM_ACCEL = new CharaStat(0.055, SWIMMING, STRAFE, ACCELERATION);
public static final CharaStat STRAFE_SWIM_ACCEL = new CharaStat(0.025, SWIMMING, STRAFE, ACCELERATION);
public static final CharaStat STRAFE_SWIM_SPEED = new CharaStat(0.25, SWIMMING, STRAFE, SPEED);

public static final CharaStat SWIM_REDIRECTION = new CharaStat(2.0, SWIMMING, REDIRECTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ PositionedSoundInstance playSoundEvent(
PositionedSoundInstance voice(VoiceLine line, long seed);
float getVoicePitch();

void storeSound(PositionedSoundInstance instance);
void stopStoredSound(SoundEvent event);

enum VoiceLine {
SELECT,
DUCK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,7 @@ class MarioTimers {
public int doubleJumpLandingTime = 0;

public boolean jumpCapped = false;

public boolean actionInterceptedAttack = false;
}
}
13 changes: 13 additions & 0 deletions mod/src/main/java/com/floralquafloral/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.SimpleParticleType;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundCategory;
Expand Down Expand Up @@ -81,6 +84,16 @@ public void onInitialize() {

MarioCommand.registerMarioCommand();

// ServerLivingEntityEvents.ALLOW_DAMAGE.register((livingEntity, damageSource, amount) -> {
// if(damageSource.isDirect() && damageSource.isOf(DamageTypes.PLAYER_ATTACK) && damageSource.getAttacker() instanceof PlayerEntity player) {
// ItemStack weapon = damageSource.getWeaponStack();
// if(weapon != null && weapon.isEmpty()) {
// // Unarmed player attack
// }
// }
// return true;
// });

// 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())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ default PositionedSoundInstance voice(MarioClientSideData.VoiceLine line, long s
JumpSoundPlayer.fadeJumpSfx(this);
}

Map<Identifier, PositionedSoundInstance> STORED_SOUNDS = new HashMap<>();

@Override default void storeSound(PositionedSoundInstance instance) {
STORED_SOUNDS.put(instance.getId(), instance);
}

@Override
default void stopStoredSound(SoundEvent event) {
MinecraftClient.getInstance().getSoundManager().stop(STORED_SOUNDS.get(event.getId()));
}

EnumMap<VoiceLine, Map<Identifier, SoundEvent>> VOICE_SOUND_EVENTS = new EnumMap<>(VoiceLine.class);
class VoiceSoundEventInitializer {
public static void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void setPowerUp(ParsedPowerUp powerUp) {
MarioQuaMario.LOGGER.info("Set Power-up to {}", powerUp.ID);
this.powerUp.losePower(this);
powerUp.acquirePower(this);
this.mario.setHealth(this.mario.getMaxHealth());
this.mario.heal(this.mario.getMaxHealth());
this.powerUp = powerUp;
this.mario.calculateDimensions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setAction(ParsedAction action, long seed) {
public final float[] CAMERA_ROTATIONS = new float[3];

@Override public void setActionTransitionless(ParsedAction action) {
// MarioQuaMario.LOGGER.info("MarioMainClientData setAction to " + action.ID);
MarioQuaMario.LOGGER.info("MarioMainClientData setAction to " + action.ID);
if(action != getAction()) getTimers().actionTimer = 0;

// CPM animation
Expand Down Expand Up @@ -103,9 +103,6 @@ public void setAction(ParsedAction action, long seed) {
getAction().travelHook(this);
getAction().attemptTransitions(this, TransitionPhase.INPUT);

getTimers().jumpLandingTime--;
getTimers().doubleJumpLandingTime--;

applyModifiedVelocity();
marioClient.move(MovementType.SELF, marioClient.getVelocity());

Expand Down Expand Up @@ -137,6 +134,10 @@ public void setAction(ParsedAction action, long seed) {

applyModifiedVelocity();

getTimers().jumpLandingTime--;
getTimers().doubleJumpLandingTime--;
getTimers().actionInterceptedAttack = false;

marioClient.updateLimbs(false);
return !marioClient.hasVehicle();
}
Expand Down
24 changes: 24 additions & 0 deletions mod/src/main/java/com/floralquafloral/mixin/PlayerEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.floralquafloral.mixin;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioDataManager;
import com.floralquafloral.mariodata.MarioPlayerData;
import com.floralquafloral.mariodata.MarioTravelData;
import com.floralquafloral.mariodata.moveable.MarioMoveableData;
import com.floralquafloral.mariodata.moveable.MarioServerData;
import com.floralquafloral.registries.states.character.ParsedCharacter;
import com.floralquafloral.registries.states.powerup.ParsedPowerUp;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -95,4 +100,23 @@ public void changeDismounting(CallbackInfoReturnable<Boolean> cir) {
if(data.attemptDismount) data.attemptDismount = false;
}
}

// @Inject(method = "attack", at = @At("HEAD"), cancellable = true)
// public void interceptUnarmedAttacks(Entity target, CallbackInfo ci) {
// PlayerEntity player = (PlayerEntity) (Object) this;
// if(!target.isAttackable() || target.handleAttack(player)) return;
//
// if(player.isUsingRiptide() || !player.getWeaponStack().isEmpty()) return;
//
// MarioPlayerData data = MarioDataManager.getMarioData(player);
// if(data.getAction().interceptAttack(
// data,
// data instanceof MarioClientSideData clientData ? clientData : null,
// data instanceof MarioTravelData travelData ? travelData : null,
// target, null
// )) ci.cancel();
//
// MarioQuaMario.LOGGER.info("Intercepted unarmed attack!!!");
// ci.cancel();
// }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.floralquafloral.registries.states;

import com.floralquafloral.definitions.actions.CharaStat;
import com.floralquafloral.definitions.MarioMajorStateDefinition;
import com.floralquafloral.definitions.MarioStatAlteringStateDefinition;
import com.floralquafloral.definitions.actions.StatCategory;

import java.util.HashMap;
Expand Down Expand Up @@ -29,7 +29,7 @@ public double getStatMultiplier(CharaStat stat) {
return combinedModifier;
}

protected ParsedMajorMarioState(MarioMajorStateDefinition definition) {
protected ParsedMajorMarioState(MarioStatAlteringStateDefinition definition) {
super(definition);

this.BUMP_STRENGTH_MODIFIER = definition.getBumpStrengthModifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.floralquafloral.registries.RegistryManager;
import com.floralquafloral.registries.stomp.ParsedStomp;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.RandomSeed;
import org.jetbrains.annotations.Nullable;
import net.minecraft.entity.Entity;

import java.util.*;

Expand Down Expand Up @@ -169,4 +171,11 @@ private void execute(MarioData data, long seed) {
this.EXECUTOR_CLIENTS.execute(clientData, data.getMario().isMainPlayer(), seed);
}
}

public boolean interceptAttack(
MarioData data, @Nullable MarioClientSideData clientData, @Nullable MarioTravelData travelData,
@Nullable Entity entityTarget, @Nullable BlockPos blockTarget
) {
return this.ACTION_DEFINITION.interceptAttack(data, clientData, travelData, entityTarget, blockTarget);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioAuthoritativeData;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioTravelData;
import com.floralquafloral.definitions.actions.ActionDefinition;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.minecraft.entity.Entity;

import java.util.List;

Expand Down Expand Up @@ -82,4 +85,11 @@ public List<ActionTransitionDefinition> getWorldCollisionTransitions() {
public List<ActionTransitionInjection> getTransitionInjections() {
return List.of();
}

@Override public boolean interceptAttack(
MarioData data, @Nullable MarioClientSideData clientData, @Nullable MarioTravelData travelData,
@Nullable Entity entityTarget, @Nullable BlockPos blockTarget
) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.mariodata.MarioAuthoritativeData;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioTravelData;
import com.floralquafloral.definitions.actions.ActionDefinition;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.minecraft.entity.Entity;

import java.util.List;

Expand Down Expand Up @@ -83,4 +86,11 @@ public List<ActionTransitionDefinition> getWorldCollisionTransitions() {
public List<ActionTransitionInjection> getTransitionInjections() {
return List.of();
}

@Override public boolean interceptAttack(
MarioData data, @Nullable MarioClientSideData clientData, @Nullable MarioTravelData travelData,
@Nullable Entity entityTarget, @Nullable BlockPos blockTarget
) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.definitions.actions.AirborneActionDefinition;
import com.floralquafloral.mariodata.MarioClientSideData;
import com.floralquafloral.mariodata.MarioData;
import com.floralquafloral.mariodata.MarioTravelData;
import com.floralquafloral.registries.states.action.baseactions.airborne.GroundPound;
import com.floralquafloral.util.MarioSFX;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.minecraft.entity.Entity;

import java.util.List;

Expand All @@ -22,7 +27,7 @@ public class AquaticGroundPoundWindup extends GroundPoundWindup {
@Override public @Nullable CameraAnimationSet getCameraAnimations() {
return new CameraAnimationSet(
new CameraAnimation(
false, 0.55F,
false, 0.45F,
(progress, offsets) -> offsets[1] = mixedEase(progress, SINE, CUBIC) * 360
),
null,
Expand All @@ -34,20 +39,27 @@ public class AquaticGroundPoundWindup extends GroundPoundWindup {
return List.of(
new ActionTransitionDefinition("qua_mario:aquatic_ground_pound",
data -> AirborneActionDefinition.AerialTransitions.ENTER_WATER.EVALUATOR.shouldTransition(data)
&& data.getTimers().actionTimer > 9,
&& data.getTimers().actionTimer > 7,
data -> {
data.setYVel(GroundPound.GROUND_POUND_VEL.get(data));
data.getInputs().JUMP.isPressed(); // Unbuffers jump
},
(data, isSelf, seed) -> data.playSoundEvent(MarioSFX.DIVE, seed)
(data, isSelf, seed) -> data.storeSound(data.playSoundEvent(MarioSFX.DIVE, seed))
),
new ActionTransitionDefinition("qua_mario:ground_pound",
data -> data.getTimers().actionTimer > 9,
data -> data.getTimers().actionTimer > 7,
data -> {
data.setYVel(GroundPound.GROUND_POUND_VEL.get(data));
data.getInputs().JUMP.isPressed(); // Unbuffers jump
}
)
);
}

@Override public boolean interceptAttack(
MarioData data, @Nullable MarioClientSideData clientData, @Nullable MarioTravelData travelData,
@Nullable Entity entityTarget, @Nullable BlockPos blockTarget
) {
return false;
}
}
Loading

0 comments on commit 565751c

Please sign in to comment.