diff --git a/src/main/java/com/floralquafloral/registries/RegistryManager.java b/src/main/java/com/floralquafloral/registries/RegistryManager.java index e89499c..9041231 100644 --- a/src/main/java/com/floralquafloral/registries/RegistryManager.java +++ b/src/main/java/com/floralquafloral/registries/RegistryManager.java @@ -76,8 +76,8 @@ private static void parseAction(ActionDefinition definition, Map()); - 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); } } diff --git a/src/main/java/com/floralquafloral/registries/states/action/ActionDefinition.java b/src/main/java/com/floralquafloral/registries/states/action/ActionDefinition.java index d8ec39e..5256ef7 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/ActionDefinition.java +++ b/src/main/java/com/floralquafloral/registries/states/action/ActionDefinition.java @@ -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), diff --git a/src/main/java/com/floralquafloral/registries/states/action/ParsedAction.java b/src/main/java/com/floralquafloral/registries/states/action/ParsedAction.java index 43274fa..bc4f2e1 100644 --- a/src/main/java/com/floralquafloral/registries/states/action/ParsedAction.java +++ b/src/main/java/com/floralquafloral/registries/states/action/ParsedAction.java @@ -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; @@ -89,29 +90,46 @@ private List parseTransitionDefinitions( List 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 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 workingList, + @Nullable ArrayList 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; diff --git a/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/DuckJump.java b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/DuckJump.java new file mode 100644 index 0000000..88c3371 --- /dev/null +++ b/src/main/java/com/floralquafloral/registries/states/action/baseactions/airborne/DuckJump.java @@ -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 getPreTickTransitions() { + return List.of( + new ActionTransitionDefinition("qua_mario:duck_waddle", + AerialTransitions.BASIC_LANDING.EVALUATOR + ) + ); + } + + @Override public List getPostTickTransitions() { + return List.of( + new ActionTransitionDefinition("qua_mario:jump", + DuckWaddle.UNDUCK.EVALUATOR + ) + ); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 18ac8ae..f67f065 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -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": [