Skip to content

Commit

Permalink
Add client state to hide name tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Nov 17, 2024
1 parent 0a23fb0 commit 5c7f59d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.neoforged.neoforge.client.ClientHooks;
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
import net.neoforged.neoforge.client.event.RenderNameTagEvent;
import net.neoforged.neoforge.common.util.TriState;

import java.util.List;

Expand Down Expand Up @@ -190,6 +191,11 @@ public static void buildEastFacing(VertexConsumer buffer, PoseStack.Pose pose, f
@SubscribeEvent
public static void onRenderPlayerName(RenderNameTagEvent event) {
if (event.getEntity() instanceof Player player) {
if (ClientGameStateManager.getOrNull(GameClientStateTypes.HIDE_NAME_TAGS) != null) {
event.setCanRender(TriState.FALSE);
return;
}

PointTagClientState state = ClientGameStateManager.getOrNull(GameClientStateTypes.POINT_TAGS);
Component points = state != null ? state.getPointsTextFor(player.getUUID()) : null;
if (points != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
import com.lovetropics.minigames.common.core.game.client_state.instance.HideNameTagsState;
import com.lovetropics.minigames.common.core.game.client_state.instance.HideRecipeBookClientState;
import com.lovetropics.minigames.common.core.game.client_state.instance.InvertControlsClientState;
import com.lovetropics.minigames.common.core.game.client_state.instance.PointTagClientState;
Expand Down Expand Up @@ -48,13 +49,14 @@ public final class GameClientStateTypes {
public static final GameClientTweakEntry<BeaconClientState> BEACON = register("beacon", BeaconClientState.CODEC);
public static final GameClientTweakEntry<FogClientState> FOG = register("fog", FogClientState.CODEC);
public static final GameClientTweakEntry<TeamMembersClientState> TEAM_MEMBERS = register("team_members", TeamMembersClientState.CODEC);
public static final GameClientTweakEntry<GlowTeamMembersState> GLOW_TEAM_MEMBERS = register("glow_team_members", MapCodec.unit(GlowTeamMembersState.INSTANCE));
public static final GameClientTweakEntry<GlowTeamMembersState> GLOW_TEAM_MEMBERS = register("glow_team_members", MapCodec.unit(GlowTeamMembersState.INSTANCE), StreamCodec.unit(GlowTeamMembersState.INSTANCE));
public static final GameClientTweakEntry<PointTagClientState> POINT_TAGS = register("point_tags", PointTagClientState.CODEC);
public static final GameClientTweakEntry<HideRecipeBookClientState> HIDE_RECIPE_BOOK = register("hide_recipe_book", HideRecipeBookClientState.CODEC);
public static final GameClientTweakEntry<CraftingBeeCraftsClientState> CRAFTING_BEE_CRAFTS = register("crafting_bee_crafts", CraftingBeeCraftsClientState.CODEC);
public static final GameClientTweakEntry<InvertControlsClientState> INVERT_CONTROLS = register("invert_controls", InvertControlsClientState.CODEC);
public static final GameClientTweakEntry<SwapMovementClientState> SWAP_MOVEMENT = register("swap_movement", SwapMovementClientState.CODEC);
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 <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 HideNameTagsState implements GameClientState {
public static final HideNameTagsState INSTANCE = new HideNameTagsState();

private HideNameTagsState() {
}

@Override
public GameClientStateType<?> getType() {
return GameClientStateTypes.HIDE_NAME_TAGS.get();
}
}

0 comments on commit 5c7f59d

Please sign in to comment.