diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/AttackInterceptingStateDefinition.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/AttackInterceptingStateDefinition.java index 7172969..1173405 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/AttackInterceptingStateDefinition.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/AttackInterceptingStateDefinition.java @@ -1,13 +1,23 @@ 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 getUnarmedAttackInterceptions(); + @NotNull List getUnarmedAttackInterceptions(); interface AttackInterceptionDefinition { @Nullable Identifier getActionTarget(); @@ -15,7 +25,26 @@ interface AttackInterceptionDefinition { 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 ); } } diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/StatAlteringStateDefinition.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/StatAlteringStateDefinition.java new file mode 100644 index 0000000..5a664ee --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/StatAlteringStateDefinition.java @@ -0,0 +1,4 @@ +package com.fqf.mario_qua_mario.definitions; + +public interface StatAlteringStateDefinition extends MarioStateDefinition { +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/ActionDefinition.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/ActionDefinition.java index 827f60b..ac1f0d4 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/ActionDefinition.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/ActionDefinition.java @@ -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 getBasicTransitions(); + @NotNull List getInputTransitions(); + @NotNull List getWorldCollisionTransitions(); + @NotNull Set getTransitionInjections(); } diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpType.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpType.java new file mode 100644 index 0000000..e123f56 --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpType.java @@ -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) + *

+ * A strength of 3 represents Super Mario and Small Mario both bumping a Brick Block without destroying it. + * (Example: Rolling into a wall, Bonking) + *

+ * 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) + *

+ * 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)); + } +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpingRule.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpingRule.java deleted file mode 100644 index 0f702e4..0000000 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/BumpingRule.java +++ /dev/null @@ -1,41 +0,0 @@ -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 class BumpingRule { - /** - * 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) - *

- * A strength of 3 represents Super Mario and Small Mario both bumping a Brick Block without destroying it. - * (Example: Rolling into a wall, Bonking) - *

- * 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) - *

- * A strength of 1 represents Mario landing on a block and having no effect on it. - * (Example: Regular jump) - */ - public static final BumpingRule JUMPING = new BumpingRule(4, 1); - public static final BumpingRule FALLING = new BumpingRule(4, 1); - public static final BumpingRule SWIMMING = new BumpingRule(4, 0); - public static final BumpingRule GROUND_POUND = new BumpingRule(0, 4); - public static final BumpingRule SPIN_JUMPING = new BumpingRule(2, 2); - - public final int CEILINGS; - public final int FLOORS; - public final int WALLS; - public final CharaStat WALL_SPEED_THRESHOLD; - - public BumpingRule(int ceilingBumpStrength, int floorBumpStrength) { - this(ceilingBumpStrength, floorBumpStrength, 0, 0); - } - - public BumpingRule(int ceilingBumpStrength, int floorBumpStrength, int wallBumpStrength, double wallBumpSpeedThreshold) { - this.CEILINGS = ceilingBumpStrength; - this.FLOORS = floorBumpStrength; - this.WALLS = wallBumpStrength; - this.WALL_SPEED_THRESHOLD = new CharaStat(wallBumpSpeedThreshold, StatCategory.THRESHOLD); - } -} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SlidingStatus.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SlidingStatus.java index 18caa74..51d9b9e 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SlidingStatus.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SlidingStatus.java @@ -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! + *

NOT_SLIDING: Vanilla behavior + *

NOT_SLIDING_SMOOTH: Footsteps occur, but no view-bobbing. + * + *

SLIDING: No footsteps or view-bobbing. Sound effect is highly dependent on speed. + *

SKIDDING: No footsteps or view-bobbing. Sound effect mostly ignores speed. + *

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, diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SprintingRule.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SprintingRule.java new file mode 100644 index 0000000..9d6f08c --- /dev/null +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/SprintingRule.java @@ -0,0 +1,6 @@ +package com.fqf.mario_qua_mario.definitions.actions.util; + +public enum SprintingRule { + ALLOW, + PROHIBIT +} diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionDefinition.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionDefinition.java index f946016..c35958c 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionDefinition.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionDefinition.java @@ -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; } diff --git a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionInjectionDefinition.java b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionInjectionDefinition.java index 93b1257..2e54b86 100644 --- a/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionInjectionDefinition.java +++ b/api/src/main/java/com/fqf/mario_qua_mario/definitions/actions/util/TransitionInjectionDefinition.java @@ -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 { @@ -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; } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java b/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java index da82782..8a23f33 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/MarioQuaMario.java @@ -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 @@ -15,4 +17,8 @@ public void onInitialize() { MarioCommand.registerMarioCommand(); } + + public static Identifier makeID(String path) { + return Identifier.of(MOD_ID_SHORT, path); + } } \ No newline at end of file diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/mixin/PlayerEntityMixin.java b/mod/src/main/java/com/fqf/mario_qua_mario/mixin/PlayerEntityMixin.java index 1d6bab4..db16172 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/mixin/PlayerEntityMixin.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/mixin/PlayerEntityMixin.java @@ -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(); } } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/ParsedMarioThing.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/ParsedMarioThing.java new file mode 100644 index 0000000..d2b3fb6 --- /dev/null +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/ParsedMarioThing.java @@ -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 +} diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java index cc9b5e9..bba59f3 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/RegistryManager.java @@ -14,36 +14,36 @@ public class RegistryManager { public static void register() { - Registry.register(STOMP_TYPES, Identifier.of(MarioQuaMario.MOD_ID, "stomp"), "BOING!"); - Registry.register(STOMP_TYPES, Identifier.of(MarioQuaMario.MOD_ID, "ground_pound"), "POW!"); + Registry.register(STOMP_TYPES, MarioQuaMario.makeID("stomp"), "BOING!"); + Registry.register(STOMP_TYPES, MarioQuaMario.makeID("ground_pound"), "POW!"); - Registry.register(POWER_UPS, Identifier.of(MarioQuaMario.MOD_ID, "super"), "wahoo!"); - Registry.register(POWER_UPS, Identifier.of(MarioQuaMario.MOD_ID, "small"), "owch!"); + Registry.register(POWER_UPS, MarioQuaMario.makeID("super"), "wahoo!"); + Registry.register(POWER_UPS, MarioQuaMario.makeID("small"), "owch!"); - Registry.register(CHARACTERS, Identifier.of(MarioQuaMario.MOD_ID, "mario"), "yippee!"); - Registry.register(CHARACTERS, Identifier.of(MarioQuaMario.MOD_ID, "toadette"), "nice!"); + Registry.register(CHARACTERS, MarioQuaMario.makeID("mario"), "yippee!"); + Registry.register(CHARACTERS, MarioQuaMario.makeID("toadette"), "nice!"); } - public static final RegistryKey> STOMP_TYPES_KEY = RegistryKey.ofRegistry( - Identifier.of(MarioQuaMario.MOD_ID, "stomp_types")); + public static final RegistryKey> STOMP_TYPES_KEY = + RegistryKey.ofRegistry(MarioQuaMario.makeID("stomp_types")); public static final Registry STOMP_TYPES = FabricRegistryBuilder.createSimple(STOMP_TYPES_KEY) .attribute(RegistryAttribute.SYNCED) .buildAndRegister(); - public static final RegistryKey> ACTIONS_KEY = RegistryKey.ofRegistry( - Identifier.of(MarioQuaMario.MOD_ID, "actions")); + public static final RegistryKey> ACTIONS_KEY = + RegistryKey.ofRegistry(MarioQuaMario.makeID("actions")); public static final Registry ACTIONS = FabricRegistryBuilder.createSimple(ACTIONS_KEY) .attribute(RegistryAttribute.SYNCED) .buildAndRegister(); - public static final RegistryKey> POWER_UPS_KEY = RegistryKey.ofRegistry( - Identifier.of(MarioQuaMario.MOD_ID, "power_ups")); + public static final RegistryKey> POWER_UPS_KEY = + RegistryKey.ofRegistry(MarioQuaMario.makeID("power_ups")); public static final Registry POWER_UPS = FabricRegistryBuilder.createSimple(POWER_UPS_KEY) .attribute(RegistryAttribute.SYNCED) .buildAndRegister(); - public static final RegistryKey> CHARACTERS_KEY = RegistryKey.ofRegistry( - Identifier.of(MarioQuaMario.MOD_ID, "characters")); + public static final RegistryKey> CHARACTERS_KEY = + RegistryKey.ofRegistry(MarioQuaMario.makeID("characters")); public static final Registry CHARACTERS = FabricRegistryBuilder.createSimple(CHARACTERS_KEY) .attribute(RegistryAttribute.SYNCED) .buildAndRegister(); diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/InitAction.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/InitAction.java index ef7ecb0..ab0a42c 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/InitAction.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/InitAction.java @@ -1,4 +1,77 @@ package com.fqf.mario_qua_mario.registries.actions; -public class InitAction { +import com.fqf.mario_qua_mario.MarioQuaMario; +import com.fqf.mario_qua_mario.definitions.actions.ActionDefinition; +import com.fqf.mario_qua_mario.definitions.actions.util.*; +import com.fqf.mario_qua_mario.mariodata.IMarioAuthoritativeData; +import com.fqf.mario_qua_mario.mariodata.IMarioClientData; +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 class InitAction implements ActionDefinition { + @Override public @NotNull Identifier getID() { + return MarioQuaMario.makeID("init"); + } + + @Override public @Nullable String getAnimationName() { + return null; + } + @Override public @Nullable CameraAnimationSet getCameraAnimations() { + return null; + } + @Override public @NotNull SlidingStatus getSlidingStatus() { + return SlidingStatus.NOT_SLIDING; + } + + @Override public @NotNull SneakingRule getSneakingRule() { + return SneakingRule.PROHIBIT; + } + @Override public @NotNull SprintingRule getSprintingRule() { + return SprintingRule.PROHIBIT; + } + + @Override public @Nullable BumpType getBumpType() { + return null; + } + @Override public @Nullable Identifier getStompTypeID() { + return null; + } + + @Override public void clientTick(IMarioClientData data, boolean isSelf) { + + } + @Override public void serverTick(IMarioAuthoritativeData data) { + + } + @Override public void travelHook(IMarioTravelData data) { + + } + + @Override public @NotNull List getBasicTransitions() { + return List.of( + new TransitionDefinition( + MarioQuaMario.makeID("init"), + data -> false + ) + ); + } + @Override public @NotNull List getInputTransitions() { + return List.of(); + } + @Override public @NotNull List getWorldCollisionTransitions() { + return List.of(); + } + + @Override public @NotNull Set getTransitionInjections() { + return Set.of(); + } + + @Override public @NotNull List getUnarmedAttackInterceptions() { + return List.of(); + } } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedAction.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedAction.java index da428a4..82805b9 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedAction.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedAction.java @@ -1,12 +1,85 @@ package com.fqf.mario_qua_mario.registries.actions; import com.fqf.mario_qua_mario.definitions.actions.ActionDefinition; +import com.fqf.mario_qua_mario.definitions.actions.util.*; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; + +import java.util.*; public class ParsedAction { private final ActionDefinition DEFINITION; -// private final Identifier ID; - public ParsedAction(ActionDefinition definition) { + public final Identifier ID; + + public final @Nullable String ANIMATION; + public final @Nullable CameraAnimationSet CAMERA_ANIMATIONS; + public final SlidingStatus SLIDING_STATUS; + + public final SneakingRule SNEAKING_RULE; + public final SprintingRule SPRINTING_RULE; + + public final @Nullable BumpType BUMP_TYPE; +// public final @Nullable ParsedStompType STOMP_TYPE; + + public final EnumMap> TRANSITIONS; + + public ParsedAction(ActionDefinition definition, HashMap> allInjections) { this.DEFINITION = definition; + + this.ID = definition.getID(); + this.ANIMATION = definition.getAnimationName(); + this.CAMERA_ANIMATIONS = definition.getCameraAnimations(); + this.SLIDING_STATUS = definition.getSlidingStatus(); + + this.SNEAKING_RULE = definition.getSneakingRule(); + this.SPRINTING_RULE = definition.getSprintingRule(); + + this.BUMP_TYPE = definition.getBumpType(); + + this.TRANSITIONS = new EnumMap<>(TransitionPhase.class); + + for(TransitionInjectionDefinition injection : definition.getTransitionInjections()) { + allInjections.putIfAbsent(injection.injectNearTransitionsTo(), new HashSet<>()); + allInjections.get(injection.injectNearTransitionsTo()).add(injection); + } + } + + public void parseTransitions(HashMap> allInjections) { + this.parseTransitions(TransitionPhase.BASIC, this.DEFINITION.getBasicTransitions(), allInjections); + this.parseTransitions(TransitionPhase.INPUT, this.DEFINITION.getInputTransitions(), allInjections); + this.parseTransitions(TransitionPhase.WORLD_COLLISION, this.DEFINITION.getWorldCollisionTransitions(), allInjections); + } + private void parseTransitions( + TransitionPhase phase, List transitions, + HashMap> allInjections + ) { + this.TRANSITIONS.putIfAbsent(phase, new ArrayList<>()); + List buildingTransitionList = this.TRANSITIONS.get(phase); + + for(TransitionDefinition definition : transitions) { + Set relevantInjections = new HashSet<>(allInjections.get(definition.targetID())); + relevantInjections.removeIf(injection -> !this.isOfCategory(injection.category())); + + this.conditionallyInjectTransitions(buildingTransitionList, relevantInjections, + TransitionInjectionDefinition.InjectionPlacement.BEFORE, definition); + buildingTransitionList.add(new ParsedTransition(definition)); + } + } + private void conditionallyInjectTransitions( + List buildingTransitionList, + Set relevantInjections, + TransitionInjectionDefinition.InjectionPlacement placement, + TransitionDefinition originalTransition + ) { + for(TransitionInjectionDefinition injection : relevantInjections) { + if(injection.placement() == placement) { + buildingTransitionList.add(new ParsedTransition(injection.injectedTransitionCreator().makeTransition(originalTransition))); + } + } + } + + private boolean isOfCategory(TransitionInjectionDefinition.ActionCategory category) { + return true; } } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedTransition.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedTransition.java index 610e4f3..097bd23 100644 --- a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedTransition.java +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/ParsedTransition.java @@ -2,21 +2,19 @@ import com.fqf.mario_qua_mario.definitions.actions.util.TransitionDefinition; import com.fqf.mario_qua_mario.registries.RegistryManager; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class ParsedTransition { - public final ParsedAction TARGET; - public final TransitionDefinition.Evaluator EVALUATOR; - public final TransitionDefinition.TravelExecutor TRAVEL_EXECUTOR; - public final TransitionDefinition.ClientsExecutor CLIENTS_EXECUTOR; +import java.util.Objects; - public final int INDEX; - - public ParsedTransition(TransitionDefinition definition, int index) { - this.TARGET = RegistryManager.ACTIONS.get(definition.TARGET_IDENTIFIER); - this.EVALUATOR = definition.EVALUATOR; - this.TRAVEL_EXECUTOR = definition.TRAVEL_EXECUTOR; - this.CLIENTS_EXECUTOR = definition.CLIENTS_EXECUTOR; - - this.INDEX = index; +public record ParsedTransition( + @NotNull ParsedAction targetID, + @NotNull TransitionDefinition.Evaluator evaluator, + @Nullable TransitionDefinition.TravelExecutor travelExecutor, + @Nullable TransitionDefinition.ClientsExecutor clientsExecutor +) { + public ParsedTransition(TransitionDefinition definition) { + this(Objects.requireNonNull(RegistryManager.ACTIONS.get(definition.targetID())), definition.evaluator(), definition.travelExecutor(), definition.clientsExecutor()); } } diff --git a/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/TransitionPhase.java b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/TransitionPhase.java new file mode 100644 index 0000000..c16aaf6 --- /dev/null +++ b/mod/src/main/java/com/fqf/mario_qua_mario/registries/actions/TransitionPhase.java @@ -0,0 +1,7 @@ +package com.fqf.mario_qua_mario.registries.actions; + +public enum TransitionPhase { + BASIC, + INPUT, + WORLD_COLLISION +}