diff --git a/src/main/java/com/lovetropics/minigames/common/core/game/behavior/GameBehaviorTypes.java b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/GameBehaviorTypes.java index 1d53e2c2..b196cc66 100644 --- a/src/main/java/com/lovetropics/minigames/common/core/game/behavior/GameBehaviorTypes.java +++ b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/GameBehaviorTypes.java @@ -32,6 +32,7 @@ import com.lovetropics.minigames.common.core.game.behavior.instances.action.AddAttributeModifierAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.AddCollidersAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.AddEquipmentAction; +import com.lovetropics.minigames.common.core.game.behavior.instances.action.ApplyClientStateAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.ApplyForTimeAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.ChestDropAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.ClearAttributeModifierAction; @@ -49,6 +50,7 @@ import com.lovetropics.minigames.common.core.game.behavior.instances.action.IncrementStatisticAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.NotificationToastAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.PlaySoundAction; +import com.lovetropics.minigames.common.core.game.behavior.instances.action.RemoveClientStateAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.RemoveCollidersAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.ResetHungerAction; import com.lovetropics.minigames.common.core.game.behavior.instances.action.RunCommandsAction; @@ -291,10 +293,10 @@ public class GameBehaviorTypes { public static final GameBehaviorEntry INCREMENT_STATISTIC = register("increment_statistic", IncrementStatisticAction.CODEC); public static final GameBehaviorEntry SET_STATISTIC = register("set_statistic", SetStatisticAction.CODEC); public static final GameBehaviorEntry START_PROGRESS_CHANNEL = register("start_progress_channel", StartProgressChannelAction.CODEC); - public static final GameBehaviorEntry PREVENT_BREAK = REGISTRATE.object("prevent_break").behavior(PreventBreakBehavior.CODEC).register(); - public static final GameBehaviorEntry RISING_FLUID = REGISTRATE.object("rising_fluid").behavior(RisingFluidBehavior.CODEC).register(); - public static final GameBehaviorEntry END_GAME = REGISTRATE.object("end_game").behavior(EndGameAction.CODEC).register(); - public static final GameBehaviorEntry CLOSE_GAME = REGISTRATE.object("close_game").behavior(CloseGameAction.CODEC).register(); + public static final GameBehaviorEntry PREVENT_BREAK = register("prevent_break", PreventBreakBehavior.CODEC); + public static final GameBehaviorEntry RISING_FLUID = register("rising_fluid", RisingFluidBehavior.CODEC); + public static final GameBehaviorEntry END_GAME = register("end_game", EndGameAction.CODEC); + public static final GameBehaviorEntry CLOSE_GAME = register("close_game", CloseGameAction.CODEC); public static final GameBehaviorEntry SETUP_INTEGRATIONS = register("setup_integrations", SetupIntegrationsBehavior.CODEC); public static final GameBehaviorEntry ASSIGN_PLAYER_ROLES = register("assign_player_roles", AssignPlayerRolesBehavior.CODEC); @@ -302,6 +304,8 @@ public class GameBehaviorTypes { public static final GameBehaviorEntry DEBUG_MODE = register("debug_mode", DebugModeBehavior.CODEC); public static final GameBehaviorEntry SET_CLIENT_STATE = register("set_client_state", SetGameClientStateBehavior.CODEC); + public static final GameBehaviorEntry APPLY_CLIENT_STATE = register("apply_client_state", ApplyClientStateAction.CODEC); + public static final GameBehaviorEntry REMOVE_CLIENT_STATE = register("remove_client_state", RemoveClientStateAction.CODEC); public static final GameBehaviorEntry> APPLY_TO_PLOT = register("apply_to_plot", ApplyToBehavior.PLOT_CODEC); public static final GameBehaviorEntry> APPLY_TO_PLAYER = register("apply_to_player", ApplyToBehavior.PLAYER_CODEC); diff --git a/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/ApplyClientStateAction.java b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/ApplyClientStateAction.java new file mode 100644 index 00000000..13b8bac0 --- /dev/null +++ b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/ApplyClientStateAction.java @@ -0,0 +1,35 @@ +package com.lovetropics.minigames.common.core.game.behavior.instances.action; + +import com.lovetropics.minigames.common.core.game.IGamePhase; +import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior; +import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar; +import com.lovetropics.minigames.common.core.game.behavior.event.GameActionEvents; +import com.lovetropics.minigames.common.core.game.behavior.event.GamePlayerEvents; +import com.lovetropics.minigames.common.core.game.client_state.GameClientState; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public record ApplyClientStateAction(GameClientState state) implements IGameBehavior { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group( + GameClientState.CODEC.fieldOf("state").forGetter(ApplyClientStateAction::state) + ).apply(i, ApplyClientStateAction::new)); + + @Override + public void register(IGamePhase game, EventRegistrar events) { + Set appliedToPlayers = new HashSet<>(); + events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> { + GameClientState.sendToPlayer(state, target); + appliedToPlayers.add(target.getUUID()); + return true; + }); + events.listen(GamePlayerEvents.REMOVE, player -> { + if (appliedToPlayers.remove(player.getUUID())) { + GameClientState.removeFromPlayer(state.getType(), player); + } + }); + } +} diff --git a/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/RemoveClientStateAction.java b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/RemoveClientStateAction.java new file mode 100644 index 00000000..bcffeff4 --- /dev/null +++ b/src/main/java/com/lovetropics/minigames/common/core/game/behavior/instances/action/RemoveClientStateAction.java @@ -0,0 +1,25 @@ +package com.lovetropics.minigames.common.core.game.behavior.instances.action; + +import com.lovetropics.minigames.common.core.game.IGamePhase; +import com.lovetropics.minigames.common.core.game.behavior.IGameBehavior; +import com.lovetropics.minigames.common.core.game.behavior.event.EventRegistrar; +import com.lovetropics.minigames.common.core.game.behavior.event.GameActionEvents; +import com.lovetropics.minigames.common.core.game.client_state.GameClientState; +import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; +import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +public record RemoveClientStateAction(GameClientStateType type) implements IGameBehavior { + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(i -> i.group( + GameClientStateTypes.TYPE_CODEC.fieldOf("state").forGetter(RemoveClientStateAction::type) + ).apply(i, RemoveClientStateAction::new)); + + @Override + public void register(IGamePhase game, EventRegistrar events) { + events.listen(GameActionEvents.APPLY_TO_PLAYER, (context, target) -> { + GameClientState.removeFromPlayer(type, target); + return true; + }); + } +} diff --git a/src/main/java/com/lovetropics/minigames/common/core/game/client_state/GameClientStateTypes.java b/src/main/java/com/lovetropics/minigames/common/core/game/client_state/GameClientStateTypes.java index 73fde261..11c5828e 100644 --- a/src/main/java/com/lovetropics/minigames/common/core/game/client_state/GameClientStateTypes.java +++ b/src/main/java/com/lovetropics/minigames/common/core/game/client_state/GameClientStateTypes.java @@ -5,6 +5,7 @@ import com.lovetropics.minigames.common.core.game.client_state.instance.CollidersClientState; import com.lovetropics.minigames.common.core.game.client_state.instance.CraftingBeeCraftsClientState; import com.lovetropics.minigames.common.core.game.client_state.instance.DisableBobbingState; +import com.lovetropics.minigames.common.core.game.client_state.instance.DisablePlayerMovementState; import com.lovetropics.minigames.common.core.game.client_state.instance.FogClientState; import com.lovetropics.minigames.common.core.game.client_state.instance.GlowTeamMembersState; import com.lovetropics.minigames.common.core.game.client_state.instance.HealthTagClientState; @@ -59,6 +60,7 @@ public final class GameClientStateTypes { public static final GameClientTweakEntry COLLIDERS = register("colliders", CollidersClientState.CODEC, CollidersClientState.STREAM_CODEC); public static final GameClientTweakEntry HIDE_NAME_TAGS = register("hide_name_tags", MapCodec.unit(HideNameTagsState.INSTANCE), StreamCodec.unit(HideNameTagsState.INSTANCE)); public static final GameClientTweakEntry DISABLE_BOBBING = register("disable_bobbing", MapCodec.unit(DisableBobbingState.INSTANCE), StreamCodec.unit(DisableBobbingState.INSTANCE)); + public static final GameClientTweakEntry DISABLE_PLAYER_MOVEMENT = register("disable_player_movement", MapCodec.unit(DisablePlayerMovementState.INSTANCE), StreamCodec.unit(DisablePlayerMovementState.INSTANCE)); public static GameClientTweakEntry register(final String name, final MapCodec codec) { return REGISTRATE.object(name) diff --git a/src/main/java/com/lovetropics/minigames/common/core/game/client_state/instance/DisablePlayerMovementState.java b/src/main/java/com/lovetropics/minigames/common/core/game/client_state/instance/DisablePlayerMovementState.java new file mode 100644 index 00000000..44216d9e --- /dev/null +++ b/src/main/java/com/lovetropics/minigames/common/core/game/client_state/instance/DisablePlayerMovementState.java @@ -0,0 +1,17 @@ +package com.lovetropics.minigames.common.core.game.client_state.instance; + +import com.lovetropics.minigames.common.core.game.client_state.GameClientState; +import com.lovetropics.minigames.common.core.game.client_state.GameClientStateType; +import com.lovetropics.minigames.common.core.game.client_state.GameClientStateTypes; + +public class DisablePlayerMovementState implements GameClientState { + public static final DisablePlayerMovementState INSTANCE = new DisablePlayerMovementState(); + + private DisablePlayerMovementState() { + } + + @Override + public GameClientStateType getType() { + return GameClientStateTypes.DISABLE_PLAYER_MOVEMENT.get(); + } +} diff --git a/src/main/java/com/lovetropics/minigames/mixin/client/KeyboardInputMixin.java b/src/main/java/com/lovetropics/minigames/mixin/client/KeyboardInputMixin.java index 2bba29d5..7663d619 100644 --- a/src/main/java/com/lovetropics/minigames/mixin/client/KeyboardInputMixin.java +++ b/src/main/java/com/lovetropics/minigames/mixin/client/KeyboardInputMixin.java @@ -12,7 +12,13 @@ @Mixin(KeyboardInput.class) public class KeyboardInputMixin extends Input { @Inject(method = "tick", at = @At("TAIL")) - private void respectSwappedMovement(boolean isSneaking, float sneakingSpeedMultiplier, CallbackInfo ci) { + private void respectMovementRules(boolean isSneaking, float sneakingSpeedMultiplier, CallbackInfo ci) { + if (ClientGameStateManager.getOrNull(GameClientStateTypes.DISABLE_PLAYER_MOVEMENT) != null) { + leftImpulse = 0.0f; + forwardImpulse = 0.0f; + jumping = false; + return; + } if (ClientGameStateManager.getOrNull(GameClientStateTypes.SWAP_MOVEMENT) != null) { float oldLeft = leftImpulse; leftImpulse = forwardImpulse;