Skip to content

Commit

Permalink
Transition Injections can now be injected before or after their targe…
Browse files Browse the repository at this point in the history
…t transition, instead of only before. Planning to use this for i.e. Raccoon Mario air-stall action, a transition to which could be injected after landing-related transitions.
  • Loading branch information
floral-qua-floral committed Oct 29, 2024
1 parent a21c62a commit f12058c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ private static void parseAction(ActionDefinition definition, Map<Identifier, Arr
Registry.register(ACTIONS, action.ID, action);

for(ActionDefinition.ActionTransitionInjection injection : definition.getTransitionInjections()) {
transitionInjections.putIfAbsent(injection.INJECT_BEFORE_TRANSITIONS_TO, new ArrayList<>());
transitionInjections.get(injection.INJECT_BEFORE_TRANSITIONS_TO).add(injection);
transitionInjections.putIfAbsent(injection.INJECT_NEAR_TRANSITIONS_TO, new ArrayList<>());
transitionInjections.get(injection.INJECT_NEAR_TRANSITIONS_TO).add(injection);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,28 @@ public boolean doParticles() {
}

class ActionTransitionInjection {
public final Identifier INJECT_BEFORE_TRANSITIONS_TO;
public final Identifier INJECT_NEAR_TRANSITIONS_TO;
public final boolean INJECT_BEFORE_TARGET;
public final ActionCategory ONLY_FOR_CATEGORY;
public final ActionTransitionDefinition TRANSITION;

public ActionTransitionInjection(
String injectBeforeTransitionsTo,
InjectionPlacement placement,
String injectNearTransitionsTo,
ActionCategory category,
ActionTransitionDefinition injectedTransition
) {
INJECT_BEFORE_TRANSITIONS_TO = Identifier.of(injectBeforeTransitionsTo);
INJECT_NEAR_TRANSITIONS_TO = Identifier.of(injectNearTransitionsTo);
INJECT_BEFORE_TARGET = placement == InjectionPlacement.BEFORE;
ONLY_FOR_CATEGORY = category;
TRANSITION = injectedTransition;
}

public enum InjectionPlacement {
BEFORE,
AFTER
}

public enum ActionCategory {
ANY(true, true, true),
GROUNDED(true, false, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.floralquafloral.registries.stomp.ParsedStomp;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.RandomSeed;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.EnumMap;
Expand Down Expand Up @@ -89,29 +90,46 @@ private List<ParsedTransition> parseTransitionDefinitions(
List<ParsedTransition> workingList = new ArrayList<>();
for(ActionDefinition.ActionTransitionDefinition definition : definitions) {
MarioQuaMario.LOGGER.info("Parsing transition to {}", definition.TARGET_IDENTIFIER);
if(injections.containsKey(definition.TARGET_IDENTIFIER)) {
MarioQuaMario.LOGGER.info("Injections found that might be inserted before this transition! Checking:");
for(ActionDefinition.ActionTransitionInjection injection : injections.get(definition.TARGET_IDENTIFIER)) {
if(injection.ONLY_FOR_CATEGORY == ActionDefinition.ActionTransitionInjection.ActionCategory.ANY
|| this.DEFINITION instanceof GroundedActionDefinition && injection.ONLY_FOR_CATEGORY.IS_GROUNDED
|| this.DEFINITION instanceof AirborneActionDefinition && injection.ONLY_FOR_CATEGORY.IS_AIRBORNE
// || this.DEFINITION instanceof AquaticActionDefinition && injection.ONLY_FOR_CATEGORY.IS_GROUNDED
) {
MarioQuaMario.LOGGER.info("Parsing & injecting transition to {}", injection.TRANSITION.TARGET_IDENTIFIER);
workingList.add(new ParsedTransition(injection.TRANSITION));
}
else {
MarioQuaMario.LOGGER.info("Injection to {} should only occur from actions in category {}. Skipping...",
injection.TRANSITION.TARGET_IDENTIFIER, injection.ONLY_FOR_CATEGORY);
}
}
MarioQuaMario.LOGGER.info("Finished injections, now parsing {} as planned", definition.TARGET_IDENTIFIER);
}

ArrayList<ActionDefinition.ActionTransitionInjection> relevantInjections = injections.get(definition.TARGET_IDENTIFIER);
handleInjections(workingList, relevantInjections, true);
workingList.add(new ParsedTransition(definition));
handleInjections(workingList, relevantInjections, false);
}
return workingList;
}

private void handleInjections(
List<ParsedTransition> workingList,
@Nullable ArrayList<ActionDefinition.ActionTransitionInjection> relevantInjections,
boolean isBefore
) {
if(relevantInjections == null) return;

MarioQuaMario.LOGGER.info("Some injections exist for this transition! Inserting those for placement {}...", (isBefore ? "BEFORE": "AFTER"));

for(ActionDefinition.ActionTransitionInjection injection : relevantInjections) {
boolean timingAligned = injection.INJECT_BEFORE_TARGET == isBefore;
boolean categoryAligned = (
injection.ONLY_FOR_CATEGORY == ActionDefinition.ActionTransitionInjection.ActionCategory.ANY
|| (this.DEFINITION instanceof GroundedActionDefinition && injection.ONLY_FOR_CATEGORY.IS_GROUNDED)
|| (this.DEFINITION instanceof AirborneActionDefinition && injection.ONLY_FOR_CATEGORY.IS_AIRBORNE)
// || (this.DEFINITION instanceof AquaticActionDefinition && injection.ONLY_FOR_CATEGORY.IS_AQUATIC)
);


if(timingAligned && categoryAligned) {
MarioQuaMario.LOGGER.info("Parsing & injecting transition to {}...", injection.TRANSITION.TARGET_IDENTIFIER);
workingList.add(new ParsedTransition(injection.TRANSITION));
}
else {
MarioQuaMario.LOGGER.info("Skipping injection to {}. Reason: {}", injection.TRANSITION.TARGET_IDENTIFIER,
timingAligned ? "Should only occur for category " + injection.ONLY_FOR_CATEGORY
: "Should be injected " + (injection.INJECT_BEFORE_TARGET ? "BEFORE": "AFTER") + " transition.");
}
}
}

private static class ParsedTransition {
private final ParsedAction TARGET_ACTION;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.floralquafloral.registries.states.action.baseactions.airborne;

import com.floralquafloral.MarioQuaMario;
import com.floralquafloral.registries.states.action.baseactions.grounded.DuckWaddle;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class DuckJump extends Jump {
@Override public @NotNull Identifier getID() {
return Identifier.of(MarioQuaMario.MOD_ID, "duck_jump");
}

@Override public SneakLegalityRule getSneakLegalityRule() {
return SneakLegalityRule.ALLOW;
}

@Override public List<ActionTransitionDefinition> getPreTickTransitions() {
return List.of(
new ActionTransitionDefinition("qua_mario:duck_waddle",
AerialTransitions.BASIC_LANDING.EVALUATOR
)
);
}

@Override public List<ActionTransitionDefinition> getPostTickTransitions() {
return List.of(
new ActionTransitionDefinition("qua_mario:jump",
DuckWaddle.UNDUCK.EVALUATOR
)
);
}
}
4 changes: 3 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"mario-actions-airborne" : [
"com.floralquafloral.registries.states.action.baseactions.airborne.Fall",
"com.floralquafloral.registries.states.action.baseactions.airborne.Jump",
"com.floralquafloral.registries.states.action.baseactions.airborne.PJump"
"com.floralquafloral.registries.states.action.baseactions.airborne.PJump",
"com.floralquafloral.registries.states.action.baseactions.airborne.DuckFall",
"com.floralquafloral.registries.states.action.baseactions.airborne.DuckJump"
],
"mario-actions-aquatic": [

Expand Down

0 comments on commit f12058c

Please sign in to comment.