Skip to content

Commit

Permalink
Freeze players for a few seconds when starting Columns of Chaos
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 18, 2024
1 parent 129d976 commit 310a33a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -291,17 +293,19 @@ public class GameBehaviorTypes {
public static final GameBehaviorEntry<IncrementStatisticAction> INCREMENT_STATISTIC = register("increment_statistic", IncrementStatisticAction.CODEC);
public static final GameBehaviorEntry<SetStatisticAction> SET_STATISTIC = register("set_statistic", SetStatisticAction.CODEC);
public static final GameBehaviorEntry<StartProgressChannelAction> START_PROGRESS_CHANNEL = register("start_progress_channel", StartProgressChannelAction.CODEC);
public static final GameBehaviorEntry<PreventBreakBehavior> PREVENT_BREAK = REGISTRATE.object("prevent_break").behavior(PreventBreakBehavior.CODEC).register();
public static final GameBehaviorEntry<RisingFluidBehavior> RISING_FLUID = REGISTRATE.object("rising_fluid").behavior(RisingFluidBehavior.CODEC).register();
public static final GameBehaviorEntry<EndGameAction> END_GAME = REGISTRATE.object("end_game").behavior(EndGameAction.CODEC).register();
public static final GameBehaviorEntry<CloseGameAction> CLOSE_GAME = REGISTRATE.object("close_game").behavior(CloseGameAction.CODEC).register();
public static final GameBehaviorEntry<PreventBreakBehavior> PREVENT_BREAK = register("prevent_break", PreventBreakBehavior.CODEC);
public static final GameBehaviorEntry<RisingFluidBehavior> RISING_FLUID = register("rising_fluid", RisingFluidBehavior.CODEC);
public static final GameBehaviorEntry<EndGameAction> END_GAME = register("end_game", EndGameAction.CODEC);
public static final GameBehaviorEntry<CloseGameAction> CLOSE_GAME = register("close_game", CloseGameAction.CODEC);

public static final GameBehaviorEntry<SetupIntegrationsBehavior> SETUP_INTEGRATIONS = register("setup_integrations", SetupIntegrationsBehavior.CODEC);
public static final GameBehaviorEntry<AssignPlayerRolesBehavior> ASSIGN_PLAYER_ROLES = register("assign_player_roles", AssignPlayerRolesBehavior.CODEC);
public static final GameBehaviorEntry<JoinLateWithRoleBehavior> JOIN_LATE_WITH_ROLE = register("join_late_with_role", JoinLateWithRoleBehavior.CODEC);
public static final GameBehaviorEntry<DebugModeBehavior> DEBUG_MODE = register("debug_mode", DebugModeBehavior.CODEC);

public static final GameBehaviorEntry<SetGameClientStateBehavior> SET_CLIENT_STATE = register("set_client_state", SetGameClientStateBehavior.CODEC);
public static final GameBehaviorEntry<ApplyClientStateAction> APPLY_CLIENT_STATE = register("apply_client_state", ApplyClientStateAction.CODEC);
public static final GameBehaviorEntry<RemoveClientStateAction> REMOVE_CLIENT_STATE = register("remove_client_state", RemoveClientStateAction.CODEC);

public static final GameBehaviorEntry<ApplyToBehavior<Plot, PlotActionTarget>> APPLY_TO_PLOT = register("apply_to_plot", ApplyToBehavior.PLOT_CODEC);
public static final GameBehaviorEntry<ApplyToBehavior<ServerPlayer, PlayerActionTarget>> APPLY_TO_PLAYER = register("apply_to_player", ApplyToBehavior.PLAYER_CODEC);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ApplyClientStateAction> 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<UUID> 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);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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<RemoveClientStateAction> 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;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,7 @@ public final class GameClientStateTypes {
public static final GameClientTweakEntry<CollidersClientState> COLLIDERS = register("colliders", CollidersClientState.CODEC, CollidersClientState.STREAM_CODEC);
public static final GameClientTweakEntry<HideNameTagsState> HIDE_NAME_TAGS = register("hide_name_tags", MapCodec.unit(HideNameTagsState.INSTANCE), StreamCodec.unit(HideNameTagsState.INSTANCE));
public static final GameClientTweakEntry<DisableBobbingState> DISABLE_BOBBING = register("disable_bobbing", MapCodec.unit(DisableBobbingState.INSTANCE), StreamCodec.unit(DisableBobbingState.INSTANCE));
public static final GameClientTweakEntry<DisablePlayerMovementState> DISABLE_PLAYER_MOVEMENT = register("disable_player_movement", MapCodec.unit(DisablePlayerMovementState.INSTANCE), StreamCodec.unit(DisablePlayerMovementState.INSTANCE));

public static <T extends GameClientState> GameClientTweakEntry<T> register(final String name, final MapCodec<T> codec) {
return REGISTRATE.object(name)
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 310a33a

Please sign in to comment.