Skip to content

Commit

Permalink
Working on Action implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
floral-qua-floral committed Dec 11, 2024
1 parent 4199844 commit 7a355be
Show file tree
Hide file tree
Showing 17 changed files with 343 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
package com.fqf.mario_qua_mario.definitions;

import com.fqf.mario_qua_mario.mariodata.IMarioClientData;
import com.fqf.mario_qua_mario.mariodata.IMarioData;
import com.fqf.mario_qua_mario.mariodata.IMarioReadableMotionData;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface AttackInterceptingStateDefinition extends MarioStateDefinition {
List<AttackInterceptionDefinition> getUnarmedAttackInterceptions();
@NotNull List<AttackInterceptionDefinition> getUnarmedAttackInterceptions();

interface AttackInterceptionDefinition {
@Nullable Identifier getActionTarget();
@Nullable Hand getHandToSwing();
boolean shouldTriggerAttackCooldown();

boolean shouldIntercept(
IMarioReadableMotionData data, float attackCooldownProgress,
@Nullable BlockHitResult blockHitResult,
@Nullable EntityHitResult entityHitResult
);

void executeTravellers(
IMarioTravelData data, float attackCooldownProgress,
@Nullable BlockHitResult blockHitResult,
@Nullable EntityHitResult entityHitResult
);

void executeClients(
IMarioClientData data, float attackCooldownProgress,
@Nullable BlockHitResult blockHitResult,
@Nullable EntityHitResult entityHitResult
);

void strikeEntity(
IMarioData data, float attackCooldownProgress,
ServerWorld world, @NotNull Entity target
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.fqf.mario_qua_mario.definitions;

public interface StatAlteringStateDefinition extends MarioStateDefinition {
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package com.fqf.mario_qua_mario.definitions.actions;

import com.fqf.mario_qua_mario.definitions.AttackInterceptingStateDefinition;
import com.fqf.mario_qua_mario.definitions.actions.util.BumpingRule;
import com.fqf.mario_qua_mario.definitions.actions.util.CameraAnimationSet;
import com.fqf.mario_qua_mario.definitions.actions.util.SneakingRule;
import com.fqf.mario_qua_mario.definitions.actions.util.*;
import com.fqf.mario_qua_mario.mariodata.IMarioTravelData;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Set;

public interface ActionDefinition extends AttackInterceptingStateDefinition {
@Nullable String getAnimationName();
@Nullable CameraAnimationSet getCameraAnimations();
@NotNull SlidingStatus getSlidingStatus();

@NotNull SneakingRule getSneakingRule();
@NotNull SprintingRule getSprintingRule();

@Nullable BumpType getBumpType();
@Nullable Identifier getStompTypeID();

boolean canSprint();

@Nullable Identifier getStompType();
void travelHook(IMarioTravelData data);

@Nullable BumpingRule getBumpingRule();
@NotNull List<TransitionDefinition> getBasicTransitions();
@NotNull List<TransitionDefinition> getInputTransitions();
@NotNull List<TransitionDefinition> getWorldCollisionTransitions();

@NotNull Set<TransitionInjectionDefinition> getTransitionInjections();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

import com.fqf.mario_qua_mario.util.CharaStat;
import com.fqf.mario_qua_mario.util.StatCategory;

public record BumpType(int ceilingBumpStrength, int floorBumpStrength, int wallBumpStrength, CharaStat wallBumpSpeedThreshold) {
/**
* A strength of 4 represents Super Mario being able to destroy a Brick Block, but Small Mario only bumping it.
* (Example: Ground Pound, hitting a block from below)
* <p>
* A strength of 3 represents Super Mario and Small Mario both bumping a Brick Block without destroying it.
* (Example: Rolling into a wall, Bonking)
* <p>
* A strength of 2 represents Super Mario being able to shatter a Flip Block, and Small Mario having no effect on it.
* (Example: Spin Jump)
* <p>
* A strength of 1 represents Mario landing on a block and having no effect on it.
* (Example: Regular jump)
*/
public static final BumpType GROUNDED = new BumpType(0, 0);
public static final BumpType JUMPING = new BumpType(4, 1);
public static final BumpType FALLING = new BumpType(4, 1);
public static final BumpType SWIMMING = new BumpType(4, 0);
public static final BumpType GROUND_POUND = new BumpType(0, 4);
public static final BumpType SPIN_JUMPING = new BumpType(2, 2);

public BumpType(int ceilingBumpStrength, int floorBumpStrength) {
this(ceilingBumpStrength, floorBumpStrength, 0, new CharaStat(0, StatCategory.THRESHOLD));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

/**
* Affects whether Mario plays footstep sounds and whether view-bobbing occurs.
* This does have a server-side effect - if footsteps are suppressed, Sculk Sensors won't be triggered!
* <p>NOT_SLIDING: Vanilla behavior
* <p>NOT_SLIDING_SMOOTH: Footsteps occur, but no view-bobbing.
*
* <p>SLIDING: No footsteps or view-bobbing. Sound effect is highly dependent on speed.
* <p>SKIDDING: No footsteps or view-bobbing. Sound effect mostly ignores speed.
* <p>WALL_SLIDING: No footsteps or view-bobbing. Plays a different sound effect, which completely ignores
* horizontal speed.
*/
public enum SlidingStatus {
NOT_SLIDING,
NOT_SLIDING_SMOOTH,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.fqf.mario_qua_mario.definitions.actions.util;

public enum SprintingRule {
ALLOW,
PROHIBIT
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,45 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class TransitionDefinition {
@FunctionalInterface
public interface Evaluator {
/**
* @param targetID The ID of the action that this transition leads to.
* @param evaluator The Evaluator that determines if this transition should fire.
* @param travelExecutor The effect the transition has on Mario's motion.
* @param clientsExecutor Client-side effects of this transition firing.
*/
public record TransitionDefinition(
@NotNull Identifier targetID,
@NotNull Evaluator evaluator,
@Nullable TravelExecutor travelExecutor,
@Nullable ClientsExecutor clientsExecutor
) {
/**
* Alternate constructor provided for convenience
*/
public TransitionDefinition(@NotNull Identifier targetID, @NotNull Evaluator evaluator) {
this(targetID, evaluator, null, null);
}

/**
* Runs on the client-side to test if the associated transition should occur.
*/
@FunctionalInterface public interface Evaluator {
boolean shouldTransition(IMarioTravelData data);
}

@FunctionalInterface
public interface TravelExecutor {
/**
* Runs on the main client and on the server when the associated transition occurs.
* In a multiplayer environment, this won't run on your client when another player does the transition, but it will
* when you're the one transitioning.
*/
@FunctionalInterface public interface TravelExecutor {
boolean execute(IMarioTravelData data);
}

@FunctionalInterface
public interface ClientsExecutor {
/**
* Runs on the client side for anyone who is in range to see Mario transition.
*/
@FunctionalInterface public interface ClientsExecutor {
boolean execute(IMarioClientData data, boolean isSelf, long seed);
}

public TransitionDefinition(
@NotNull String targetID,
@NotNull Evaluator evaluator,
@Nullable TravelExecutor travelExecutor,
@Nullable ClientsExecutor clientsExecutor
) {
this.TARGET_IDENTIFIER = Identifier.of(targetID);
this.EVALUATOR = evaluator;
this.TRAVEL_EXECUTOR = travelExecutor;
this.CLIENTS_EXECUTOR = clientsExecutor;
}

public TransitionDefinition(@NotNull String targetID, @NotNull Evaluator evaluator) {
this(targetID, evaluator, null, null);
}

public final Identifier TARGET_IDENTIFIER;
public final Evaluator EVALUATOR;
public final TravelExecutor TRAVEL_EXECUTOR;
public final ClientsExecutor CLIENTS_EXECUTOR;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import net.minecraft.util.Identifier;

public class TransitionInjectionDefinition {
public record TransitionInjectionDefinition(
InjectionPlacement placement,
Identifier injectNearTransitionsTo,
ActionCategory category,
TransitionCreator injectedTransitionCreator
) {
@FunctionalInterface
public interface TransitionCreator {
TransitionDefinition makeTransition(TransitionDefinition previousTransition);
TransitionDefinition makeTransition(TransitionDefinition nearbyTransition);
}

public enum InjectionPlacement {
Expand All @@ -21,21 +26,4 @@ public enum ActionCategory {
WALL,
UNDEFINED
}

public TransitionInjectionDefinition(
InjectionPlacement placement,
String injectNearTransitionsTo,
ActionCategory category,
TransitionCreator injectedTransitionCreator
) {
this.PLACEMENT = placement;
this.INJECT_NEAR = Identifier.of(injectNearTransitionsTo);
this.INJECT_IN_CATEGORY = category;
this.TRANSITION_CREATOR = injectedTransitionCreator;
}

public final InjectionPlacement PLACEMENT;
public final Identifier INJECT_NEAR;
public final ActionCategory INJECT_IN_CATEGORY;
public final TransitionCreator TRANSITION_CREATOR;
}
6 changes: 6 additions & 0 deletions mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import net.fabricmc.api.ModInitializer;

import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MarioQuaMario implements ModInitializer {
public static final String MOD_ID = "mario_qua_mario";
public static final String MOD_ID_SHORT = "mqm";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@Override
Expand All @@ -15,4 +17,8 @@ public void onInitialize() {

MarioCommand.registerMarioCommand();
}

public static Identifier makeID(String path) {
return Identifier.of(MOD_ID_SHORT, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.fqf.mario_qua_mario.mixin;

import com.fqf.mario_qua_mario.MarioQuaMario;
import com.fqf.mario_qua_mario.mariodata.MarioPlayerData;
import com.fqf.mario_qua_mario.mariodata.injections.MarioDataHolder;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
public abstract class PlayerEntityMixin implements MarioDataHolder {
@Inject(method = "travel", at = @At("HEAD"))
private void travelHook(Vec3d movementInput, CallbackInfo ci) {
PlayerEntity meAsPlayer = (PlayerEntity) (Object) this;
MarioQuaMario.LOGGER.info("Travel hook: \n{}\n{}\n{}", meAsPlayer, meAsPlayer.mqm$getMarioData(), meAsPlayer.mqm$getMarioData().getValue());
mqm$getMarioData().isClient();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fqf.mario_qua_mario.registries;

import com.fqf.mario_qua_mario.definitions.MarioStateDefinition;
import net.minecraft.util.Identifier;

public class ParsedMarioThing {
public final Identifier ID;

public ParsedMarioThing(MarioStateDefinition definition) {
this.ID = definition.getID();
}

// TODO: Additional constructor for use with Stomp Types
}
Loading

0 comments on commit 7a355be

Please sign in to comment.