From 399c03a2fb2ff0f9c346b65547ab7fdd02a47f1b Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Tue, 23 Jul 2024 14:38:35 +0100 Subject: [PATCH] Feature/1.21/map info changes (#308) feat: overhaul minimap info display Configurable components, which can be enabled/disabled/reordered. --- .../ftb/mods/ftbchunks/api/ClaimResult.java | 2 +- .../api/client/FTBChunksClientAPI.java | 23 ++ .../api/client/minimap/MinimapContext.java | 33 +++ .../client/minimap/MinimapInfoComponent.java | 91 ++++++ .../api/client/minimap/TranslatedOption.java | 12 + .../ftbchunks/client/FTBChunksClient.java | 187 ++++++------ .../client/FTBChunksClientAPIImpl.java | 36 +++ .../client/FTBChunksClientConfig.java | 28 +- .../ftbchunks/client/gui/ChunkScreen.java | 2 + .../ftbchunks/client/gui/LargeMapScreen.java | 6 +- .../client/gui/MinimapInfoSortScreen.java | 273 ++++++++++++++++++ .../client/gui/ToggleVisibilityButton.java | 47 +++ .../client/gui/WaypointEditorScreen.java | 40 +-- .../mods/ftbchunks/client/map/MapMode.java | 2 +- .../minimap/components/BiomeComponent.java | 42 +++ .../minimap/components/DebugComponent.java | 61 ++++ .../minimap/components/FPSComponent.java | 30 ++ .../minimap/components/GameTimeComponent.java | 69 +++++ .../components/PlayerPosInfoComponent.java | 29 ++ .../minimap/components/RealTimeComponent.java | 68 +++++ .../minimap/components/ZoneInfoComponent.java | 75 +++++ .../dev/ftb/mods/ftbchunks/data/AllyMode.java | 2 +- .../mods/ftbchunks/data/ForceLoadMode.java | 2 +- .../mods/ftbchunks/data/PartyLimitMode.java | 2 +- .../dev/ftb/mods/ftbchunks/data/PvPMode.java | 2 +- .../mods/ftbchunks/net/AddWaypointPacket.java | 6 +- .../assets/ftbchunks/lang/en_us.json | 48 ++- gradle.properties | 6 +- 28 files changed, 1068 insertions(+), 156 deletions(-) create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapInfoComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/TranslatedOption.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/MinimapInfoSortScreen.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ToggleVisibilityButton.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/BiomeComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/DebugComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/FPSComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/GameTimeComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/PlayerPosInfoComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/RealTimeComponent.java create mode 100644 common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/ZoneInfoComponent.java diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/api/ClaimResult.java b/common/src/main/java/dev/ftb/mods/ftbchunks/api/ClaimResult.java index a2a5a1e3..681acc56 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/api/ClaimResult.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/api/ClaimResult.java @@ -72,7 +72,7 @@ enum StandardProblem implements ClaimResult { NOT_LOADED("not_loaded"), ; - public static final NameMap NAME_MAP = NameMap.of(NOT_OWNER, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(NOT_OWNER, values()).baseNameKey("ftbchunks.standard_problem").create(); private final String resultName; diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/FTBChunksClientAPI.java b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/FTBChunksClientAPI.java index 82c74cbb..678a289d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/FTBChunksClientAPI.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/FTBChunksClientAPI.java @@ -1,5 +1,7 @@ package dev.ftb.mods.ftbchunks.api.client; +import com.google.common.collect.ImmutableList; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; import dev.ftb.mods.ftbchunks.api.client.waypoint.WaypointManager; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; @@ -27,4 +29,25 @@ public interface FTBChunksClientAPI { * entities...) */ void requestMinimapIconRefresh(); + + /** + * Register a custom minimap info component {@link MinimapInfoComponent} to be rendered on the minimap. + * + * This should be called during mod initialization as this list will be finalized once Minecraft has "started" + * per the client lifecycle events + * + * @param component the component to register + */ + void registerMinimapComponent(MinimapInfoComponent component); + + //Todo + boolean isMinimapComponentEnabled(MinimapInfoComponent component); + + //Todo + void setMinimapComponentEnabled(MinimapInfoComponent component, boolean enabled); + + /** + * Provides an immutable list of all registered minimap components. + */ + ImmutableList getMinimapComponents(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java new file mode 100644 index 00000000..9df2e07c --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapContext.java @@ -0,0 +1,33 @@ +package dev.ftb.mods.ftbchunks.api.client.minimap; + +import dev.ftb.mods.ftbchunks.client.map.MapDimension; +import dev.ftb.mods.ftblibrary.math.XZ; +import net.minecraft.client.Minecraft; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.world.phys.Vec3; + +import java.util.Map; + +/** + * Minimal context for Minimap Info Components + * + * @param minecraft The Minecraft instance (Helper) + * @param player The client player + * @param mapDimension The dimension of the players location + * @param mapChunksPos The chunk for the players location + * @param playerPos the players pos + * @param infoSettings raw settings for this component + */ +public record MinimapContext( + Minecraft minecraft, + LocalPlayer player, + MapDimension mapDimension, + XZ mapChunksPos, + Vec3 playerPos, + Map infoSettings +) { + + public String getSetting(MinimapInfoComponent infoComponent) { + return infoSettings.getOrDefault(infoComponent.id().toString(), ""); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapInfoComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapInfoComponent.java new file mode 100644 index 00000000..e25dff03 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/MinimapInfoComponent.java @@ -0,0 +1,91 @@ +package dev.ftb.mods.ftbchunks.api.client.minimap; + +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import java.util.Collections; +import java.util.Set; + +/** + * An entry point for developers to create custom minimap info components. + */ +public interface MinimapInfoComponent { + /** + * The ID of this component. + */ + ResourceLocation id(); + + /** + * Render your component here, the {@link com.mojang.blaze3d.vertex.PoseStack} will already be scaled and + * translated to the correct position (centered by default). We do not provide an X and Y position as + * 0, 0 is the center of the correct location. Use 0, 0 as the center of the component and {@link #height(MinimapContext)} + * to allocate the correct height for the component. + * + * @param context The minimap context + * @param graphics The graphics object see {@link GuiGraphics} + * @param font The font object + */ + void render(MinimapContext context, GuiGraphics graphics, Font font); + + /** + * Set of Info {@link TranslatedOption} that are used to configure options for rendering the waypoint + * this is exposed in the right click action of Minimap Info GUI + * @return the set of {@link TranslatedOption}. + */ + default Set getConfigComponents() { + return Set.of(); + } + + /** + * The height of the component is used to allocate the correct space for the component. Failure to return the correct + * height will result in the component overlapping with other components. + * + * @param context The minimap context + * @return The height of the component + */ + default int height(MinimapContext context) { + return computeLineHeight(context.minecraft(), 1) + 1; + } + + /** + * Checked on each render frame to determine if the height for the component should be allocated + */ + default boolean shouldRender(MinimapContext context) { + return true; + } + + /** + * Helper method to compute the height of a text component whilst taking into account the font scale + */ + default int computeLineHeight(Minecraft minecraft, int lines) { + final float fontScale = FTBChunksClientConfig.MINIMAP_FONT_SCALE.get().floatValue(); + return (int) ((minecraft.font.lineHeight + 2) * lines * fontScale); + } + + /** + * Helper method to draw centered text without the faff of calculating the width of the text + */ + default void drawCenteredText(Font font, GuiGraphics graphics, Component text, int y) { + int textWidth = font.width(text.getVisualOrderText()); + graphics.drawString(font, text, -textWidth / 2, y, 0xFFFFFFFF, true); + } + + + /** + * @return display name render in the Minimap Info Settings GUI + */ + default Component displayName() { + return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".title"); + } + + /** + * @return hover texted displayed render in the Minimap Info Settings GUI + */ + default Component description() { + return Component.translatable("minimap.info." + id().getNamespace() + "." + id().getPath() + ".description"); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/TranslatedOption.java b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/TranslatedOption.java new file mode 100644 index 00000000..e717abfa --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/api/client/minimap/TranslatedOption.java @@ -0,0 +1,12 @@ +package dev.ftb.mods.ftbchunks.api.client.minimap; + +public record TranslatedOption( + String optionName, + String translationKey +) { + + public static TranslatedOption of(String optionName) { + String translatedKey = optionName.toLowerCase().replaceAll("[^a-z0-9]", "_"); + return new TranslatedOption(optionName, "minimap.option." + translatedKey); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java index 50040d12..253bf6d9 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClient.java @@ -18,15 +18,19 @@ import dev.ftb.mods.ftbchunks.FTBChunks; import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig; import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI; import dev.ftb.mods.ftbchunks.api.client.event.MapIconEvent; import dev.ftb.mods.ftbchunks.api.client.icon.MapIcon; import dev.ftb.mods.ftbchunks.api.client.icon.MapType; import dev.ftb.mods.ftbchunks.api.client.icon.WaypointIcon; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; import dev.ftb.mods.ftbchunks.api.client.waypoint.Waypoint; import dev.ftb.mods.ftbchunks.client.gui.*; import dev.ftb.mods.ftbchunks.client.map.*; import dev.ftb.mods.ftbchunks.client.map.color.ColorUtils; import dev.ftb.mods.ftbchunks.client.mapicon.*; +import dev.ftb.mods.ftbchunks.client.minimap.components.*; import dev.ftb.mods.ftbchunks.data.ChunkSyncInfo; import dev.ftb.mods.ftbchunks.net.PartialPackets; import dev.ftb.mods.ftbchunks.net.SendGeneralDataPacket.GeneralChunkData; @@ -43,7 +47,6 @@ import dev.ftb.mods.ftblibrary.ui.GuiHelper; import dev.ftb.mods.ftblibrary.ui.Theme; import dev.ftb.mods.ftblibrary.ui.input.Key; -import dev.ftb.mods.ftblibrary.util.StringUtils; import dev.ftb.mods.ftblibrary.util.client.ClientUtils; import dev.ftb.mods.ftbteams.api.event.ClientTeamPropertiesChangedEvent; import dev.ftb.mods.ftbteams.api.event.TeamEvent; @@ -61,7 +64,6 @@ import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; import net.minecraft.core.GlobalPos; -import net.minecraft.core.Holder; import net.minecraft.core.SectionPos; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -74,14 +76,12 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.resources.ResourceProvider; -import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.status.ChunkStatus; @@ -93,8 +93,9 @@ import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; -import java.time.LocalDateTime; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; public enum FTBChunksClient { INSTANCE; @@ -144,7 +145,7 @@ public enum FTBChunksClient { private Matrix4f worldMatrix; private Vec3 cameraPos; - + private List sortedComponents = new LinkedList<>(); // kludge to move potion effects left to avoid rendering over/under minimap in top right of screen private static double vanillaEffectsOffsetX; @@ -170,9 +171,24 @@ public void init() { TeamEvent.CLIENT_PROPERTIES_CHANGED.register(this::teamPropertiesChanged); MapIconEvent.LARGE_MAP.register(this::mapIcons); MapIconEvent.MINIMAP.register(this::mapIcons); -// RefreshMinimapIconsEvent.EVENT.register(this::refreshMinimapIcons); ClientReloadShadersEvent.EVENT.register(this::reloadShaders); registerPlatform(); + + // Register minimap components + FTBChunksClientAPI clientApi = FTBChunksAPI.clientApi(); + clientApi.registerMinimapComponent(new PlayerPosInfoComponent()); + clientApi.registerMinimapComponent(new ZoneInfoComponent()); + clientApi.registerMinimapComponent(new BiomeComponent()); + clientApi.registerMinimapComponent(new GameTimeComponent()); + clientApi.registerMinimapComponent(new RealTimeComponent()); + clientApi.registerMinimapComponent(new FPSComponent()); + clientApi.registerMinimapComponent(new DebugComponent()); + + ClientLifecycleEvent.CLIENT_STARTED.register(this::clientStarted); + } + + private void clientStarted(Minecraft minecraft) { + this.setupComponents(); } private void registerKeys() { @@ -684,23 +700,28 @@ public void renderHud(GuiGraphics graphics, DeltaTracker tickDelta) { poseStack.popPose(); } - List textList = buildMinimapTextData(mc, playerX, playerY, playerZ, dim); - if (!textList.isEmpty()) { - float fontScale = FTBChunksClientConfig.MINIMAP_FONT_SCALE.get().floatValue(); - float textHeight = (mc.font.lineHeight + 2) * textList.size() * fontScale; - // draw text below minimap if there's room, above otherwise - float yOff = y + size + textHeight >= scaledHeight ? -textHeight : size + 2f; + // The minimap info text + var context = new MinimapContext(mc, mc.player, dim, XZ.of(currentPlayerChunkX, currentPlayerChunkZ), new Vec3(playerX, playerY, playerZ), FTBChunksClientConfig.MINIMAP_SETTINGS.get()); + var fontScale = FTBChunksClientConfig.MINIMAP_FONT_SCALE.get().floatValue(); + + int yOffset = 0; + for (MinimapInfoComponent component : sortedComponents) { + if (!component.shouldRender(context)) { + continue; + } + + var height = component.height(context); + var isBottom = y + size + height >= scaledHeight; + var yOff = isBottom ? (-height - yOffset) : (size + 2f + yOffset); poseStack.pushPose(); poseStack.translate(x + halfSizeD, y + yOff, 0D); poseStack.scale(fontScale, fontScale, 1F); - for (int i = 0; i < textList.size(); i++) { - FormattedCharSequence text = textList.get(i).getVisualOrderText(); - int textWidth = mc.font.width(text); - graphics.drawString(mc.font, text, -textWidth / 2, i * (mc.font.lineHeight + 2), 0xFFFFFFFF, true); - } + component.render(context, graphics, mc.font); poseStack.popPose(); + + yOffset += height; } RenderSystem.enableDepthTest(); @@ -731,87 +752,6 @@ private void drawMinimapCompassPoints(float minimapRotation, int size, double ha } } - private List buildMinimapTextData(Minecraft mc, double playerX, double playerY, double playerZ, MapDimension dim) { - List res = new ArrayList<>(); - - if (FTBChunksClientConfig.MINIMAP_ZONE.get()) { - MapRegionData data = dim.getRegion(XZ.regionFromChunk(currentPlayerChunkX, currentPlayerChunkZ)).getData(); - if (data != null) { - data.getChunk(XZ.of(currentPlayerChunkX, currentPlayerChunkZ)).getTeam() - .ifPresent(team -> res.add(team.getColoredName())); - } - } - - if (FTBChunksClientConfig.MINIMAP_XYZ.get()) { - res.add(Component.literal(Mth.floor(playerX) + " " + Mth.floor(playerY) + " " + Mth.floor(playerZ))); - } - - if (FTBChunksClientConfig.MINIMAP_BIOME.get()) { - Holder biome = mc.level.getBiome(mc.player.blockPosition()); - biome.unwrapKey().ifPresent(e -> - res.add(Component.translatable("biome." + e.location().getNamespace() + "." + e.location().getPath())) - ); - } - - boolean showTimeKey = FTBChunksClientConfig.MINIMAP_SHOW_GAME_TIME.get() != FTBChunksClientConfig.TimeMode.OFF && FTBChunksClientConfig.MINIMAP_SHOW_REAL_TIME.get() != FTBChunksClientConfig.TimeMode.OFF; - - if (FTBChunksClientConfig.MINIMAP_SHOW_GAME_TIME.get() != FTBChunksClientConfig.TimeMode.OFF) { - long time = mc.level.getDayTime() % 24000L; - int hours = (int) (time / 1000L); - int minutes = (int) ((time % 1000L) * 60L / 1000L); - - String timeString = createTimeString(hours, minutes, FTBChunksClientConfig.MINIMAP_SHOW_GAME_TIME.get() == FTBChunksClientConfig.TimeMode.TWENTY_FOUR); - if(showTimeKey) { - timeString = "G: " + timeString; - } - res.add(Component.literal(timeString)); - } - - if (FTBChunksClientConfig.MINIMAP_SHOW_REAL_TIME.get() != FTBChunksClientConfig.TimeMode.OFF) { - LocalDateTime now = LocalDateTime.now(); - int hour = now.getHour(); - int minute = now.getMinute(); - String timeString = createTimeString(hour, minute, FTBChunksClientConfig.MINIMAP_SHOW_REAL_TIME.get() == FTBChunksClientConfig.TimeMode.TWENTY_FOUR); - if(showTimeKey) { - timeString = "R: " + timeString; - } - res.add(Component.literal(timeString)); - } - - if (FTBChunksClientConfig.SHOW_FPS.get()) { - res.add(Component.translatable("ftbchunks.fps", Minecraft.getInstance().getFps())); - } - - if (FTBChunksClientConfig.DEBUG_INFO.get()) { - XZ playerXZ = XZ.regionFromChunk(currentPlayerChunkX, currentPlayerChunkZ); - long memory = MapManager.getInstance().map(MapManager::estimateMemoryUsage).orElse(0L); - res.add(Component.literal("TQ: " + ClientTaskQueue.queueSize()).withStyle(ChatFormatting.GRAY)); - res.add(Component.literal("Rgn: " + playerXZ).withStyle(ChatFormatting.GRAY)); - res.add(Component.literal("Mem: ~" + StringUtils.formatDouble00(memory / 1024D / 1024D) + " MB").withStyle(ChatFormatting.GRAY)); - res.add(Component.literal("Updates: " + renderedDebugCount).withStyle(ChatFormatting.GRAY)); - if (ChunkUpdateTask.getDebugLastTime() > 0L) { - res.add(Component.literal(String.format("Last: %,d ns", ChunkUpdateTask.getDebugLastTime())).withStyle(ChatFormatting.GRAY)); - } - } - - return res; - } - - public static String createTimeString(int hours, int minutes, boolean twentyFourFormat) { - if(twentyFourFormat) { - return String.format("%02d:%02d", hours, minutes); - } else { - String ampm = hours >= 12 ? "PM" : "AM"; - if(hours == 0) { - hours = 12; - } else if(hours > 12) { - hours -= 12; - } - return String.format("%02d:%02d %s", hours, minutes, ampm); - } - - } - private void drawInWorldIcons(Minecraft mc, GuiGraphics graphics, DeltaTracker tickDelta, double playerX, double playerY, double playerZ, int scaledWidth, int scaledHeight) { GuiHelper.setupDrawing(); float scaledWidth2 = scaledWidth / 2F; @@ -1241,6 +1181,45 @@ public static Waypoint addWaypoint(String name, GlobalPos position, int color) { }).orElse(null); } + public void setupComponents() { + this.sortedComponents.clear(); + this.computeOrderedComponents(); + } + + /** + * Handles the headache of sorting logic + */ + private void computeOrderedComponents() { + Map componentMap = FTBChunksAPI.clientApi().getMinimapComponents().stream() + .collect(Collectors.toMap(MinimapInfoComponent::id, Function.identity())); + + List order = FTBChunksClientConfig.MINIMAP_INFO_ORDER.get() + .stream() + .map(ResourceLocation::parse) + .collect(Collectors.toList()); + + // Adds any missing components to the end of the list + boolean save = false; + for (ResourceLocation location : componentMap.keySet()) { + if (!order.contains(location)) { + order.add(location); + save = true; + } + } + + if (save) { + FTBChunksClientConfig.MINIMAP_INFO_ORDER.set(order.stream().map(ResourceLocation::toString).collect(Collectors.toList())); + FTBChunksClientConfig.saveConfig(); + } + + for (ResourceLocation id : order) { + MinimapInfoComponent minimapInfoComponent = componentMap.get(id); + if (minimapInfoComponent != null && FTBChunksAPI.clientApi().isMinimapComponentEnabled(minimapInfoComponent)) { + sortedComponents.add(minimapInfoComponent); + } + } + } + // See GuiMixin // This moves the vanilla potion effects rendering to the left of the minimap if it's in the top-right public static double getVanillaEffectsOffsetX() { @@ -1249,19 +1228,17 @@ public static double getVanillaEffectsOffsetX() { public static class WaypointAddScreen extends BaseScreen { private final StringConfig name; - private final Player player; private final GlobalPos waypointLocation; - public WaypointAddScreen(StringConfig name, Player player, GlobalPos waypointLocation) { + public WaypointAddScreen(StringConfig name, GlobalPos waypointLocation) { super(); this.name = name; - this.player = player; this.waypointLocation = waypointLocation; this.setHeight(35); } public WaypointAddScreen(StringConfig name, Player player) { - this(name, player, new GlobalPos(player.level().dimension(), player.blockPosition())); + this(name, new GlobalPos(player.level().dimension(), player.blockPosition())); } @Override @@ -1290,4 +1267,8 @@ public void onClosed() { pushModalPanel(overlay); } } + + public int getRenderedDebugCount() { + return renderedDebugCount; + } } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientAPIImpl.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientAPIImpl.java index 47d6e148..bc2fc188 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientAPIImpl.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientAPIImpl.java @@ -1,15 +1,21 @@ package dev.ftb.mods.ftbchunks.client; +import com.google.common.collect.ImmutableList; import dev.ftb.mods.ftbchunks.api.client.FTBChunksClientAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; import dev.ftb.mods.ftbchunks.api.client.waypoint.WaypointManager; import dev.ftb.mods.ftbchunks.client.map.MapDimension; import dev.ftb.mods.ftbchunks.client.map.MapManager; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; public class FTBChunksClientAPIImpl implements FTBChunksClientAPI { + private static final List minimapComponents = new ArrayList<>(); + @Override public Optional getWaypointManager() { return MapDimension.getCurrent().flatMap(d -> Optional.ofNullable(d.getWaypointManager())); @@ -24,4 +30,34 @@ public Optional getWaypointManager(ResourceKey dimension public void requestMinimapIconRefresh() { FTBChunksClient.INSTANCE.refreshMinimapIcons(); } + + @Override + public void registerMinimapComponent(MinimapInfoComponent component) { + if (minimapComponents.contains(component)) { + throw new IllegalStateException("Minimap component %s already registered".formatted(component.id())); + } + + minimapComponents.add(component); + } + + @Override + public boolean isMinimapComponentEnabled(MinimapInfoComponent component) { + return !FTBChunksClientConfig.MINIMAP_INFO_HIDDEN.get().contains(component.id().toString()); + } + + @Override + public void setMinimapComponentEnabled(MinimapInfoComponent component, boolean enabled) { + if (enabled) { + FTBChunksClientConfig.MINIMAP_INFO_HIDDEN.get().remove(component.id().toString()); + } else { + FTBChunksClientConfig.MINIMAP_INFO_HIDDEN.get().add(component.id().toString()); + } + FTBChunksClientConfig.saveConfig(); + FTBChunksClient.INSTANCE.setupComponents(); + } + + @Override + public ImmutableList getMinimapComponents() { + return ImmutableList.copyOf(minimapComponents); + } } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientConfig.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientConfig.java index ad911528..5c28f53b 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientConfig.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientConfig.java @@ -7,15 +7,25 @@ import dev.ftb.mods.ftbchunks.client.map.BiomeBlendMode; import dev.ftb.mods.ftbchunks.client.map.MapManager; import dev.ftb.mods.ftbchunks.client.map.MapMode; +import dev.ftb.mods.ftbchunks.client.minimap.components.BiomeComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.DebugComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.FPSComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.GameTimeComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.PlayerPosInfoComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.RealTimeComponent; +import dev.ftb.mods.ftbchunks.client.minimap.components.ZoneInfoComponent; import dev.ftb.mods.ftbchunks.net.ServerConfigRequestPacket; import dev.ftb.mods.ftblibrary.config.ConfigGroup; -import dev.ftb.mods.ftblibrary.config.EnumConfig; import dev.ftb.mods.ftblibrary.config.NameMap; import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen; import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag; import dev.ftb.mods.ftblibrary.snbt.config.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; + +import java.util.Collections; +import java.util.stream.Stream; import static dev.ftb.mods.ftblibrary.snbt.config.ConfigUtil.LOCAL_DIR; import static dev.ftb.mods.ftblibrary.snbt.config.ConfigUtil.loadDefaulted; @@ -62,20 +72,17 @@ public interface FTBChunksClientConfig { BooleanValue MINIMAP_ENTITIES = MINIMAP.addBoolean("entities", true).comment("Show entities on minimap"); BooleanValue MINIMAP_ENTITY_HEADS = MINIMAP.addBoolean("entity_heads", true).comment("Show entity heads on minimap"); BooleanValue MINIMAP_LARGE_ENTITIES = MINIMAP.addBoolean("large_entities", false).comment("Entities in minimap will be larger"); - BooleanValue MINIMAP_XYZ = MINIMAP.addBoolean("xyz", true).comment("Show XYZ under minimap"); - BooleanValue MINIMAP_BIOME = MINIMAP.addBoolean("biome", true).comment("Show biome under minimap"); EnumValue MINIMAP_BLUR_MODE = MINIMAP.addEnum("blur_mode", MinimapBlurMode.NAME_MAP).comment("Blurs minimap"); BooleanValue MINIMAP_COMPASS = MINIMAP.addBoolean("compass", true).comment("Adds NWSE compass inside minimap"); IntValue MINIMAP_VISIBILITY = MINIMAP.addInt("visibility", 255, 0, 255).comment("Minimap visibility"); - BooleanValue MINIMAP_ZONE = MINIMAP.addBoolean("zone", true).comment("Show zone (claimed chunk or wilderness) under minimap"); IntValue MINIMAP_OFFSET_X = MINIMAP.addInt("position_offset_x", 0).comment("Changes the maps X offset from it's origin point. When on the Left, the map will be pushed out from the left, then from the right when on the right."); IntValue MINIMAP_OFFSET_Y = MINIMAP.addInt("position_offset_y", 0).comment("Changes the maps X offset from it's origin point. When on the Left, the map will be pushed out from the left, then from the right when on the right."); EnumValue MINIMAP_POSITION_OFFSET_CONDITION = MINIMAP.addEnum("position_offset_condition", MinimapPosition.MinimapOffsetConditional.NAME_MAP).comment("Applied a conditional check to the offset. When set to anything other that None, the offset will apply only to the selected minimap position.", "When set to none and the maps offset is greater than 0, the offset will apply to all directions"); BooleanValue SQUARE_MINIMAP = MINIMAP.addBoolean("square", false).comment("Draw a square minimap instead of a circular one"); BooleanValue MINIMAP_PROPORTIONAL = MINIMAP.addBoolean("proportional", true).comment("Size minimap proportional to screen width (and scale)"); - EnumValue MINIMAP_SHOW_GAME_TIME = MINIMAP.addEnum("show_game_time", TimeMode.NAME_MAP).comment("Show game time under minimap"); - EnumValue MINIMAP_SHOW_REAL_TIME = MINIMAP.addEnum("show_real_time", TimeMode.NAME_MAP).comment("Show real time under minimap"); - BooleanValue SHOW_FPS = MINIMAP.addBoolean("show_fps", false).comment("Show FPS under minimap"); + StringListValue MINIMAP_INFO_ORDER = MINIMAP.addStringList("info_order", Stream.of(PlayerPosInfoComponent.ID, BiomeComponent.ID, ZoneInfoComponent.ID, FPSComponent.ID, GameTimeComponent.ID, RealTimeComponent.ID, DebugComponent.ID).map(ResourceLocation::toString).toList()).comment("Info displayed under minimap"); + StringListValue MINIMAP_INFO_HIDDEN = MINIMAP.addStringList("info_hidden", Collections.emptyList()).comment("Info hidden under minimap"); + StringMapValue MINIMAP_SETTINGS = MINIMAP.add(new StringMapValue(MINIMAP, "info_settings", Collections.emptyMap())).comment("Settings for minimap info components"); SNBTConfig ADVANCED = CONFIG.addGroup("advanced", 3); BooleanValue DEBUG_INFO = ADVANCED.addBoolean("debug_info", false).comment("Enables debug info"); @@ -131,11 +138,4 @@ static void saveConfig() { CONFIG.save(Platform.getGameFolder().resolve("local/ftbchunks/client-config.snbt")); } - public enum TimeMode { - OFF, - TWENTY_FOUR, - TWELVE; - - public static final NameMap NAME_MAP = NameMap.of(OFF, values()).create(); - } } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ChunkScreen.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ChunkScreen.java index 986aba34..cc149092 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ChunkScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ChunkScreen.java @@ -7,6 +7,7 @@ import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig; import dev.ftb.mods.ftbchunks.api.ClaimResult; import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.icon.MapType; import dev.ftb.mods.ftbchunks.client.FTBChunksClient; import dev.ftb.mods.ftbchunks.client.map.MapChunk; import dev.ftb.mods.ftbchunks.client.map.MapDimension; @@ -160,6 +161,7 @@ public void drawBackground(GuiGraphics graphics, Theme theme, int x, int y, int double hx = sx + FTBChunks.TILE_SIZE * FTBChunks.TILE_OFFSET + MathUtils.mod(player.getX(), 16D); double hy = sy + FTBChunks.TILE_SIZE * FTBChunks.TILE_OFFSET + MathUtils.mod(player.getZ(), 16D); + new PointerIcon().draw(MapType.LARGE_MAP, graphics, (int) (hx - 4D), (int) (hy - 4D), 8, 8, false, 255); FaceIcon.getFace(player.getGameProfile()).draw(graphics, (int) (hx - 4D), (int) (hy - 4D), 8, 8); List list = FTBChunksClient.INSTANCE.getChunkSummary(); diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java index 2df8625b..716913e4 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/LargeMapScreen.java @@ -60,6 +60,7 @@ public class LargeMapScreen extends BaseScreen { private Button settingsButton; private Button serverSettingsButton; private Button clearDeathpointsButton; + private Button infoSortScreen; private boolean needIconRefresh; private final int minZoom; @@ -139,6 +140,8 @@ public void addWidgets() { .append(Component.literal("]")).withStyle(ChatFormatting.GRAY); add(waypointManagerButton = new SimpleTooltipButton(this, Component.translatable("ftbchunks.gui.waypoints"), Icons.COMPASS, (b, m) -> new WaypointEditorScreen().openGui(), tooltip)); + add(infoSortScreen = new SimpleTooltipButton(this, Component.translatable("ftbchunks.gui.sort_minimap_info"), Icons.BOOK, + (b, m) -> new MinimapInfoSortScreen().openGui(), tooltip)); add(infoButton = new SimpleButton(this, Component.translatable("ftbchunks.gui.large_map_info"), Icons.INFO, (b, m) -> new MapKeyReferenceScreen().openGui())); @@ -194,7 +197,8 @@ public void alignWidgets() { claimChunksButton.setPosAndSize(1, 1, 16, 16); waypointManagerButton.setPosAndSize(1, 19, 16, 16); infoButton.setPosAndSize(1, 37, 16, 16); - clearDeathpointsButton.setPosAndSize(1, 55, 16, 16); + infoSortScreen.setPosAndSize(1, 55, 16, 16); + clearDeathpointsButton.setPosAndSize(1, 73, 16, 16); dimensionButton.setPosAndSize(1, height - 36, 16, 16); settingsButton.setPosAndSize(1, height - 18, 16, 16); diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/MinimapInfoSortScreen.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/MinimapInfoSortScreen.java new file mode 100644 index 00000000..99d465c2 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/MinimapInfoSortScreen.java @@ -0,0 +1,273 @@ +package dev.ftb.mods.ftbchunks.client.gui; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.TranslatedOption; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.client.FTBChunksClient; +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import dev.ftb.mods.ftblibrary.icon.Color4I; +import dev.ftb.mods.ftblibrary.icon.Icon; +import dev.ftb.mods.ftblibrary.icon.Icons; +import dev.ftb.mods.ftblibrary.ui.Button; +import dev.ftb.mods.ftblibrary.ui.ContextMenuItem; +import dev.ftb.mods.ftblibrary.ui.Panel; +import dev.ftb.mods.ftblibrary.ui.SimpleButton; +import dev.ftb.mods.ftblibrary.ui.TextField; +import dev.ftb.mods.ftblibrary.ui.Theme; +import dev.ftb.mods.ftblibrary.ui.misc.AbstractThreePanelScreen; +import dev.ftb.mods.ftblibrary.util.TooltipList; +import dev.ftb.mods.ftblibrary.util.client.ClientTextComponentUtils; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class MinimapInfoSortScreen extends AbstractThreePanelScreen { + + private List infoSortList = new LinkedList<>(); + + public MinimapInfoSortScreen() { + super(); + setHeight(200); + setWidth(200); + FTBChunksClientConfig.MINIMAP_INFO_ORDER.get().forEach(s -> infoSortList.add(ResourceLocation.parse(s))); + showBottomPanel(false); + setRenderBlur(false); + } + + @Override + protected void doCancel() { + + } + + @Override + protected void doAccept() { + + } + + @Override + protected int getTopPanelHeight() { + return 22; + } + + @Override + protected MinimapInfoSortEntry createMainPanel() { + return new MinimapInfoSortEntry(this); + } + + @Override + protected Panel createTopPanel() { + return new CustomTopPanel(); + } + + protected class CustomTopPanel extends TopPanel { + private final TextField titleLabel = new TextField(this); + + @Override + public void addWidgets() { + titleLabel.setText(Component.translatable("ftbchunks.gui.sort_minimap_info")); + titleLabel.addFlags(Theme.CENTERED_V); + add(titleLabel); + } + + @Override + public void alignWidgets() { + titleLabel.setPosAndSize(4, 0, titleLabel.width, height); + } + } + + public class MinimapInfoSortEntry extends Panel { + + private final Map entryMap = new HashMap<>(); + + public MinimapInfoSortEntry(Panel panel) { + super(panel); + for (MinimapInfoComponent minimapComponent : FTBChunksAPI.clientApi().getMinimapComponents()) { + entryMap.put(minimapComponent.id(), new InfoEntry(minimapComponent, MinimapInfoSortEntry.this)); + } + } + + @Override + public void addWidgets() { + addAll(entryMap.values()); + } + + @Override + public void alignWidgets() { + int height = 0; + for (ResourceLocation id : infoSortList) { + InfoEntry infoEntry = entryMap.get(id); + if (infoEntry != null) { + infoEntry.setPosAndSize(0, height, width, 24); + infoEntry.alignWidgets(); + height += 24; + } + } + } + } + + public class InfoEntry extends Panel { + + private final Button down; + private final Button up; + private final SimpleButton hideButton; + private final TextField field; + private final MinimapInfoComponent infoComponent; + private final SimpleButton configButton; + + public InfoEntry(MinimapInfoComponent infoComponent, Panel panel) { + super(panel); + hideButton = ToggleVisibilityButton.create(this, !isComponentDisabled(infoComponent), (enabled) -> setComponentEnabled(infoComponent, enabled)); + down = new SortScreenButton(InfoEntry.this, Component.translatable("ftbchunks.gui.move_up"), Icons.UP, (widget, button) -> move(false, isShiftKeyDown())); + up = new SortScreenButton(InfoEntry.this, Component.translatable("ftbchunks.gui.move_down"), Icons.DOWN, (widget, button) -> move(true, isShiftKeyDown())); + configButton = new SimpleButton(InfoEntry.this, Component.translatable("gui.settings"), Icons.SETTINGS, (widget, button) -> { + List items = new ArrayList<>(); + for (TranslatedOption translatedOption : infoComponent.getConfigComponents()) { + ContextMenuItem item = new ContextMenuItem(Component.translatable(translatedOption.translationKey()), isTranslatedOptionEnabled(infoComponent, translatedOption) ? Icons.ACCEPT : Icons.REMOVE_GRAY, (button1) -> setTranslatedOptionEnabled(infoComponent, translatedOption)); + items.add(item); + } + openContextMenu(items); + playClickSound(); + }) { + @Override + public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { + super.drawIcon(graphics, theme, x, y, 12, 12); + } + }; + field = new TextField(InfoEntry.this) { + @Override + public void addMouseOverText(TooltipList list) { + list.add(infoComponent.description()); + } + }; + this.infoComponent = infoComponent; + } + + + @Override + public void addWidgets() { + int listIndex = infoSortList.indexOf(infoComponent.id()); + if (listIndex != 0) { + add(down); + } + if (listIndex != infoSortList.size() - 1) { + add(up); + } + add(hideButton); + add(field); + if(!infoComponent.getConfigComponents().isEmpty()) { + add(configButton); + } + } + + @Override + public void alignWidgets() { + down.setPosAndSize(6, height / 6 + 1, 6, 8); + up.setPosAndSize(6, height / 6 + 11, 6, 8); + hideButton.setPosAndSize(width - 18, height / 6, 12, 12); + field.setPosAndSize(16, 8, width - 37, height); + if(!infoComponent.getConfigComponents().isEmpty()) { + configButton.setPos(width - 18 - 14, height / 6 + 2); + } + field.setText(ClientTextComponentUtils.ellipsize(getTheme().getFont(), infoComponent.displayName(), hideButton.getPosX() - 14 - 5).getString()); + } + + @Override + public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { + theme.drawWidget(graphics, x, y, w, h, getWidgetType()); + if (isMouseOver()) { + Color4I.WHITE.withAlpha(33).draw(graphics, x, y, w, h); + } + super.draw(graphics, theme, x, y, w, h); + } + + /** + * moves the current MiniMapInfoComponent in our ordered list and saves the new order for rendering + * @param forward true if the current value `down` the list and false if `up` the list + * @param end true if the current value is the last value in the list and false if it is not + */ + private void move(boolean forward, boolean end) { + List list = new LinkedList<>(infoSortList); + if (end) { + if (forward) { + list.remove(infoComponent.id()); + list.add(infoComponent.id()); + } else { + list.remove(infoComponent.id()); + list.addFirst(infoComponent.id()); + } + } else { + int index = list.indexOf(infoComponent.id()); + if (index == -1) { + return; + } + if (forward) { + if (index == list.size() - 1) { + return; + } + list.remove(index); + list.add(index + 1, infoComponent.id()); + } else { + if (index == 0) { + return; + } + list.remove(index); + list.add(index - 1, infoComponent.id()); + } + } + infoSortList = list; + saveConfig(); + parent.refreshWidgets(); + } + } + + public static class SortScreenButton extends SimpleButton { + + public SortScreenButton(Panel panel, Component text, Icon icon, Callback c) { + super(panel, text, icon, c); + } + + @Override + public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { + super.drawIcon(graphics, theme, x - 1, y - 2, 6, 8); + } + } + + + private void saveConfig() { + List list = new LinkedList<>(); + infoSortList.forEach(resourceLocation -> list.add(resourceLocation.toString())); + FTBChunksClientConfig.MINIMAP_INFO_ORDER.set(list); + FTBChunksClientConfig.saveConfig(); + FTBChunksClient.INSTANCE.setupComponents(); + } + + private boolean isComponentDisabled(MinimapInfoComponent component) { + return !FTBChunksAPI.clientApi().isMinimapComponentEnabled(component); + } + + private void setComponentEnabled(MinimapInfoComponent component, boolean enabled) { + FTBChunksAPI.clientApi().setMinimapComponentEnabled(component, enabled); + } + + private boolean isTranslatedOptionEnabled(MinimapInfoComponent component, TranslatedOption option) { + Map stringStringMap = FTBChunksClientConfig.MINIMAP_SETTINGS.get(); + if (!stringStringMap.containsKey(component.id().toString())) { + stringStringMap.put(component.id().toString(), option.optionName()); + } + return stringStringMap.get(component.id().toString()).equals(option.optionName()); + } + + private void setTranslatedOptionEnabled(MinimapInfoComponent component, TranslatedOption option) { + Map stringStringMap = FTBChunksClientConfig.MINIMAP_SETTINGS.get(); + stringStringMap.put(component.id().toString(), option.optionName()); + FTBChunksClientConfig.MINIMAP_SETTINGS.set(stringStringMap); + FTBChunksClientConfig.saveConfig(); + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ToggleVisibilityButton.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ToggleVisibilityButton.java new file mode 100644 index 00000000..7a3e9571 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/ToggleVisibilityButton.java @@ -0,0 +1,47 @@ +package dev.ftb.mods.ftbchunks.client.gui; + +import dev.ftb.mods.ftblibrary.icon.Icons; +import dev.ftb.mods.ftblibrary.ui.Panel; +import dev.ftb.mods.ftblibrary.ui.SimpleButton; +import dev.ftb.mods.ftblibrary.ui.Theme; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; + +import java.util.function.Consumer; + +public class ToggleVisibilityButton extends SimpleButton { + + private static final Component TOGGLE_ON = Component.translatable("ftbchunks.gui.toggle_visibility_on"); + private static final Component TOGGLE_OFF = Component.translatable("ftbchunks.gui.toggle_visibility_off"); + + private boolean visible; + + private ToggleVisibilityButton(Panel panel, boolean defaultState, Callback c) { + super(panel, Component.empty(), defaultState ? Icons.ACCEPT : Icons.REMOVE_GRAY, c); + visible = defaultState; + } + + public static ToggleVisibilityButton create(Panel panel, boolean defaultState, Consumer newState) { + return new ToggleVisibilityButton(panel, defaultState, (widget, button) -> { + ToggleVisibilityButton visibilityButton = (ToggleVisibilityButton) widget; + visibilityButton.visible = !visibilityButton.visible; + widget.setIcon(visibilityButton.visible ? Icons.ACCEPT : Icons.REMOVE_GRAY); + newState.accept(visibilityButton.visible); + }); + } + + public boolean isVisible() { + return visible; + } + + @Override + public Component getTitle() { + return visible ? TOGGLE_ON : TOGGLE_OFF; + } + + + @Override + public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { + super.drawIcon(graphics, theme, x, y, width, height); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java index 04810301..3e424a00 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java @@ -14,14 +14,15 @@ import dev.ftb.mods.ftblibrary.ui.input.Key; import dev.ftb.mods.ftblibrary.ui.input.MouseButton; import dev.ftb.mods.ftblibrary.ui.misc.AbstractButtonListScreen; +import dev.ftb.mods.ftblibrary.util.TextComponentUtils; import dev.ftb.mods.ftblibrary.util.TooltipList; +import dev.ftb.mods.ftblibrary.util.client.ClientTextComponentUtils; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.player.LocalPlayer; +import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceKey; @@ -34,7 +35,6 @@ import java.util.*; import static dev.ftb.mods.ftblibrary.util.TextComponentUtils.hotkeyTooltip; -import static net.minecraft.network.chat.CommonComponents.ELLIPSIS; public class WaypointEditorScreen extends AbstractButtonListScreen { private final Map, Boolean> collapsed = new HashMap<>(); @@ -56,17 +56,6 @@ public WaypointEditorScreen() { (widget, button) -> toggleAll(true)); } - private static FormattedText ellipsize(Font font, FormattedText text, int maxWidth) { - final int strWidth = font.width(text); - final int ellipsisWidth = font.width(ELLIPSIS); - if (strWidth > maxWidth) { - return ellipsisWidth >= maxWidth ? - font.substrByWidth(text, maxWidth) : - FormattedText.composite(font.substrByWidth(text, maxWidth - ellipsisWidth), ELLIPSIS); - } - return text; - } - private void toggleAll(boolean collapsed) { this.collapsed.keySet().forEach(levelResourceKey -> this.collapsed.put(levelResourceKey, collapsed)); scrollBar.setValue(0); @@ -144,9 +133,7 @@ public GroupButton(Panel panel, ResourceKey dim, boolean startCollapsed, super(panel); this.dim = dim; - //Todo move the to library or define / get some standard for dim names - //Might need to show more with dim types / level ids - this.titleText = Component.translatableWithFallback(dim.location().toLanguageKey("dimension"), dim.location().getPath()) + this.titleText = TextComponentUtils.translatedDimension(dim).copy() .withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(dim.location().toString())))); setCollapsed(startCollapsed); this.rowPanels = new ArrayList<>(); @@ -188,6 +175,7 @@ public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) @Override public void addMouseOverText(TooltipList list) { + list.add(Component.literal(dim.location().toString())); } } @@ -210,10 +198,7 @@ public RowPanel(Panel panel, WaypointImpl wp) { @Override public void addWidgets() { - add(hideButton = new SimpleButton(this, Component.empty(), wp.isHidden() ? Icons.REMOVE_GRAY : Icons.ACCEPT, (w, mb) -> { - wp.setHidden(!wp.isHidden()); - w.setIcon(wp.isHidden() ? Icons.REMOVE_GRAY : Icons.ACCEPT); - })); + add(hideButton = ToggleVisibilityButton.create(this, !wp.isHidden(), hidden -> wp.setHidden(!hidden))); add(nameField = new TextField(this).setTrim().setColor(Color4I.rgb(wp.getColor())).addFlags(Theme.SHADOW)); @@ -226,6 +211,11 @@ public void addWidgets() { public Component getTitle() { return isShiftKeyDown() ? QUICK_DELETE : DELETE; } + + @Override + public void drawIcon(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { + super.drawIcon(graphics, theme, x, y, 12, 12); + } }); } @@ -242,13 +232,13 @@ public void setWidth(int newWidth) { int yOff = (this.height - getTheme().getFontHeight()) / 2 + 1; - hideButton.setPos(farRight - 8 - 16, 1); - deleteButton.setPos(farRight - 8, 1); + hideButton.setPosAndSize(farRight - 8 - 16, 1, 12, 12); + deleteButton.setPosAndSize(farRight - 8, 1, 12, 12); distField.setPos(hideButton.getPosX() - 5 - distField.width, yOff); nameField.setPos(5, yOff); - nameField.setText(ellipsize(getTheme().getFont(), Component.literal(wp.getName()),distField.getPosX() - 5).getString()); + nameField.setText(ClientTextComponentUtils.ellipsize(getTheme().getFont(), Component.literal(wp.getName()),distField.getPosX() - 5).getString()); nameField.setHeight(getTheme().getFontHeight() + 2); } } @@ -299,7 +289,7 @@ public boolean mousePressed(MouseButton button) { }); })); } - if (Minecraft.getInstance().player.hasPermissions(2)) { // permissions are checked again on server! + if (Minecraft.getInstance().player.hasPermissions(Commands.LEVEL_GAMEMASTERS)) { // permissions are checked again on server! list.add(new ContextMenuItem(Component.translatable("ftbchunks.gui.teleport"), ItemIcon.getItemIcon(Items.ENDER_PEARL), btn -> { NetworkManager.sendToServer(new TeleportFromMapPacket(wp.getPos().above(), false, wp.getDimension())); closeGui(false); diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapMode.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapMode.java index dd619de0..2c7d7fc4 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapMode.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/map/MapMode.java @@ -9,5 +9,5 @@ public enum MapMode { BLOCKS, LIGHT_SOURCES; - public static final NameMap NAME_MAP = NameMap.of(NONE, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(NONE, values()).baseNameKey("ftbchunks.map_mode").create(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/BiomeComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/BiomeComponent.java new file mode 100644 index 00000000..264ad6e6 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/BiomeComponent.java @@ -0,0 +1,42 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import dev.ftb.mods.ftblibrary.snbt.config.BooleanValue; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.Holder; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; + +public class BiomeComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("biome"); + + private ResourceKey biomeKey; + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + drawCenteredText(context.minecraft().font, graphics, Component.translatable("biome." + biomeKey.location().getNamespace() + "." + biomeKey.location().getPath()), 0); + } + + @Override + public boolean shouldRender(MinimapContext context) { + Holder biome = context.minecraft().level.getBiome(context.minecraft().player.blockPosition()); + if (biome.unwrapKey().isPresent()) { + biomeKey = biome.unwrapKey().get(); + return true; + } + + return false; + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/DebugComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/DebugComponent.java new file mode 100644 index 00000000..290b5aac --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/DebugComponent.java @@ -0,0 +1,61 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.client.ClientTaskQueue; +import dev.ftb.mods.ftbchunks.client.FTBChunksClient; +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import dev.ftb.mods.ftbchunks.client.map.ChunkUpdateTask; +import dev.ftb.mods.ftbchunks.client.map.MapManager; +import dev.ftb.mods.ftblibrary.math.XZ; +import dev.ftb.mods.ftblibrary.snbt.config.BooleanValue; +import dev.ftb.mods.ftblibrary.util.StringUtils; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import java.util.ArrayList; +import java.util.List; + +public class DebugComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("debug"); + + public DebugComponent() { + super(); + } + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + List components = new ArrayList<>(); + long memory = MapManager.getInstance().map(MapManager::estimateMemoryUsage).orElse(0L); + components.add(Component.literal("TQ: " + ClientTaskQueue.queueSize()).withStyle(ChatFormatting.GRAY)); + components.add(Component.literal("Rgn: " + XZ.of(context.mapChunksPos().x(), context.mapChunksPos().z())).withStyle(ChatFormatting.GRAY)); + components.add(Component.literal("Mem: ~" + StringUtils.formatDouble00(memory / 1024D / 1024D) + " MB").withStyle(ChatFormatting.GRAY)); + components.add(Component.literal("Updates: " + FTBChunksClient.INSTANCE.getRenderedDebugCount()).withStyle(ChatFormatting.GRAY)); + if(ChunkUpdateTask.getDebugLastTime() > 0L) { + components.add(Component.literal(String.format("Last: %,d ns", ChunkUpdateTask.getDebugLastTime())).withStyle(ChatFormatting.GRAY)); + } + + int y = 0; + int lineHeight = computeLineHeight(context.minecraft(), 1) + font.lineHeight + 1; + for (Component component : components) { + drawCenteredText(context.minecraft().font, graphics, component, y); + y += lineHeight; + } + } + + @Override + public int height(MinimapContext context) { + return computeLineHeight(context.minecraft(), 5) + 1; + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/FPSComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/FPSComponent.java new file mode 100644 index 00000000..69d578a8 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/FPSComponent.java @@ -0,0 +1,30 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +public class FPSComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("fps"); + + public FPSComponent() { + super(); + } + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + drawCenteredText(context.minecraft().font, graphics, Component.translatable("ftbchunks.fps", Minecraft.getInstance().getFps()), 0); + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/GameTimeComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/GameTimeComponent.java new file mode 100644 index 00000000..20d4e8b6 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/GameTimeComponent.java @@ -0,0 +1,69 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.TranslatedOption; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftblibrary.config.NameMap; +import dev.ftb.mods.ftblibrary.icon.Icon; +import dev.ftb.mods.ftblibrary.icon.ItemIcon; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Items; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +public class GameTimeComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("game_time"); + private static final Icon CLOCK_ICON = ItemIcon.getItemIcon(Items.CLOCK); + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + String setting = context.getSetting(this); + if (setting.equals(ClockedTimeMode.CLOCK.name())) { + CLOCK_ICON.draw(graphics, -8, 0, 16, 16); + return; + } + + Minecraft minecraft = context.minecraft(); + + long time = minecraft.level.getDayTime() % 24000L; + int hours = (int) (time / 1000L); + int minutes = (int) ((time % 1000L) * 60L / 1000L); + drawCenteredText(minecraft.font, graphics, Component.literal(RealTimeComponent.createTimeString(hours + 6, minutes, setting.equals(ClockedTimeMode.TWENTY_FOUR.name()))), 0); + } + + + @Override + public int height(MinimapContext context) { + String setting = context.getSetting(this); + return !setting.equals(ClockedTimeMode.CLOCK.name()) ? MinimapInfoComponent.super.height(context) : 10; + } + + @Override + public Set getConfigComponents() { + return Arrays.stream(ClockedTimeMode.values()) + .map(value -> new TranslatedOption(value.name(), "ftbchunks.time_mode." + ClockedTimeMode.NAME_MAP.getName(value))) + .collect(Collectors.toSet()); + } + + public enum ClockedTimeMode { + TWENTY_FOUR, + TWELVE, + CLOCK; + + public static final NameMap NAME_MAP = NameMap.of(TWENTY_FOUR, values()).baseNameKey("ftbchunks.time_mode").create(); + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/PlayerPosInfoComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/PlayerPosInfoComponent.java new file mode 100644 index 00000000..716c0f47 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/PlayerPosInfoComponent.java @@ -0,0 +1,29 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import dev.ftb.mods.ftblibrary.snbt.config.BooleanValue; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; + +public class PlayerPosInfoComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("player_pos"); + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + var text = Component.literal(Mth.floor(context.playerPos().x()) + " " + Mth.floor(context.playerPos().y()) + " " + Mth.floor(context.playerPos().z())); + drawCenteredText(font, graphics, text, 0); + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/RealTimeComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/RealTimeComponent.java new file mode 100644 index 00000000..ca1c70f6 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/RealTimeComponent.java @@ -0,0 +1,68 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.TranslatedOption; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig; +import dev.ftb.mods.ftblibrary.config.NameMap; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class RealTimeComponent implements MinimapInfoComponent { + + public static final ResourceLocation ID = FTBChunksAPI.rl("real_time"); + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + String setting = context.getSetting(this); + LocalDateTime now = LocalDateTime.now(); + int hours = now.getHour(); + int minutes = now.getMinute(); + drawCenteredText(font, graphics, Component.literal(createTimeString(hours, minutes, setting.equals(TimeMode.TWENTY_FOUR.name()))), 0); + } + + @Override + public Set getConfigComponents() { + return Arrays.stream(TimeMode.values()) + .map(value -> new TranslatedOption(value.name(),"ftbchunks.time_mode." + TimeMode.NAME_MAP.getName(value))) + .collect(Collectors.toSet()); + } + + static String createTimeString(int hours, int minutes, boolean twentyFourHourClock) { + if (twentyFourHourClock) { + return String.format("%02d:%02d", hours, minutes); + } + + String ampm = hours >= 12 ? "PM" : "AM"; + if (hours == 0) { + hours = 12; + } else if (hours > 12) { + hours -= 12; + } + + return String.format("%2d:%02d %s", hours, minutes, ampm); + } + + public enum TimeMode { + TWENTY_FOUR, + TWELVE; + + public static final NameMap NAME_MAP = NameMap.of(TWENTY_FOUR, values()).baseNameKey("ftbchunks.time_mode").create(); + } +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/ZoneInfoComponent.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/ZoneInfoComponent.java new file mode 100644 index 00000000..c8191535 --- /dev/null +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/minimap/components/ZoneInfoComponent.java @@ -0,0 +1,75 @@ +package dev.ftb.mods.ftbchunks.client.minimap.components; + +import dev.ftb.mods.ftbchunks.api.FTBChunksAPI; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapContext; +import dev.ftb.mods.ftbchunks.api.client.minimap.MinimapInfoComponent; +import dev.ftb.mods.ftbchunks.api.client.minimap.TranslatedOption; +import dev.ftb.mods.ftblibrary.config.NameMap; +import dev.ftb.mods.ftblibrary.math.XZ; +import dev.ftb.mods.ftbteams.api.Team; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import java.util.Arrays; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +public class ZoneInfoComponent implements MinimapInfoComponent { + public static final ResourceLocation ID = FTBChunksAPI.rl("zone"); + public static final Component WILDNESS = Component.translatable("wilderness").withStyle(s -> s.withColor(ChatFormatting.DARK_GREEN).withItalic(true)); + + private Team team; + + @Override + public ResourceLocation id() { + return ID; + } + + @Override + public void render(MinimapContext context, GuiGraphics graphics, Font font) { + String setting = context.getSetting(this); + + if (team != null) { + drawCenteredText(context.minecraft().font, graphics, team.getColoredName(), 0); + } else if (setting.equals(ShowWilderness.SHOW_WILDERNESS.name())) { + drawCenteredText(context.minecraft().font, graphics, WILDNESS, 0); + } + } + + @Override + public boolean shouldRender(MinimapContext context) { + var data = context.mapDimension().getRegion(XZ.regionFromChunk(context.mapChunksPos().x(), context.mapChunksPos().z())).getData(); + + team = null; + if (data != null) { + Optional foundTeam = data.getChunk(XZ.of(context.mapChunksPos().x(), context.mapChunksPos().z())).getTeam(); + if (foundTeam.isPresent()) { + team = foundTeam.get(); + return true; + } + } + + String setting = context.getSetting(this); + return !setting.isEmpty() && !setting.equals(ShowWilderness.JUST_CLAIMED.name()); + } + + + @Override + public Set getConfigComponents() { + return Arrays.stream(ShowWilderness.values()) + .map(value -> new TranslatedOption(value.name(), "ftbchunks.show_wilderness." + ShowWilderness.NAME_MAP.getName(value))) + .collect(Collectors.toSet()); + } + + public enum ShowWilderness { + JUST_CLAIMED, + SHOW_WILDERNESS; + + public static final NameMap NAME_MAP = NameMap.of(SHOW_WILDERNESS, values()).baseNameKey("ftbchunks.show_wilderness").create(); + } + +} diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/data/AllyMode.java b/common/src/main/java/dev/ftb/mods/ftbchunks/data/AllyMode.java index 67164266..ab96d72f 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/data/AllyMode.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/data/AllyMode.java @@ -7,5 +7,5 @@ public enum AllyMode { FORCED_ALL, FORCED_NONE; - public static final NameMap NAME_MAP = NameMap.of(DEFAULT, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(DEFAULT, values()).baseNameKey("ftbchunks.ally_mode").create(); } \ No newline at end of file diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/data/ForceLoadMode.java b/common/src/main/java/dev/ftb/mods/ftbchunks/data/ForceLoadMode.java index 6c2b98a7..4f06688c 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/data/ForceLoadMode.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/data/ForceLoadMode.java @@ -7,5 +7,5 @@ public enum ForceLoadMode { ALWAYS, NEVER; - public static final NameMap NAME_MAP = NameMap.of(DEFAULT, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(DEFAULT, values()).baseNameKey("ftbchunks.force_load_mode").create(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/data/PartyLimitMode.java b/common/src/main/java/dev/ftb/mods/ftbchunks/data/PartyLimitMode.java index 94078112..e97e7a76 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/data/PartyLimitMode.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/data/PartyLimitMode.java @@ -8,5 +8,5 @@ public enum PartyLimitMode { SUM, AVERAGE; - public static final NameMap NAME_MAP = NameMap.of(LARGEST, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(LARGEST, values()).baseNameKey("ftbchunks.party_limit_mode").create(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/data/PvPMode.java b/common/src/main/java/dev/ftb/mods/ftbchunks/data/PvPMode.java index 71258e85..cf743c9e 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/data/PvPMode.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/data/PvPMode.java @@ -8,5 +8,5 @@ public enum PvPMode { PER_TEAM, ; - public static final NameMap NAME_MAP = NameMap.of(ALWAYS, values()).create(); + public static final NameMap NAME_MAP = NameMap.of(ALWAYS, values()).baseNameKey("ftbchunks.pvp_mode").create(); } diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/net/AddWaypointPacket.java b/common/src/main/java/dev/ftb/mods/ftbchunks/net/AddWaypointPacket.java index d9d33af2..ea874f0d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/net/AddWaypointPacket.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/net/AddWaypointPacket.java @@ -29,11 +29,11 @@ public Type type() { public static void handle(AddWaypointPacket message, NetworkManager.PacketContext context) { context.queue(() -> { - if(message.useGui()) { + if (message.useGui()) { StringConfig configName = new StringConfig(); configName.setValue(message.name); - new FTBChunksClient.WaypointAddScreen(configName, context.getPlayer(), message.position).openGui(); - }else { + new FTBChunksClient.WaypointAddScreen(configName, message.position).openGui(); + } else { FTBChunksClient.addWaypoint(message.name, message.position, message.color); } }); diff --git a/common/src/main/resources/assets/ftbchunks/lang/en_us.json b/common/src/main/resources/assets/ftbchunks/lang/en_us.json index fad97e66..f4caeb98 100644 --- a/common/src/main/resources/assets/ftbchunks/lang/en_us.json +++ b/common/src/main/resources/assets/ftbchunks/lang/en_us.json @@ -219,5 +219,51 @@ "ftbchunks.waypoint_sharing": "Waypoint Sharing", "ftbchunks.waypoint_sharing.waypoint_sharing_party": "Allow Sharing waypoints with Party", "ftbchunks.waypoint_sharing.waypoint_sharing_server": "Allow Sharing waypoints with Server", - "ftbchunks.waypoint_sharing.waypoint_sharing_players": "Allow Sharing waypoints with Players" + "ftbchunks.waypoint_sharing.waypoint_sharing_players": "Allow Sharing waypoints with Players", + "ftbchunks.map_mode.none": "None", + "ftbchunks.map_mode.night": "Night", + "ftbchunks.map_mode.topography": "Topography", + "ftbchunks.map_mode.blocks": "Blocks", + "ftbchunks.map_mode.light_sources": "Light Sources", + "ftbchunks.ally_mode.default": "Default", + "ftbchunks.ally_mode.forced_all": "Forced All", + "ftbchunks.ally_mode.forced_none": "Forced None", + "ftbchunks.pvp_mode.always": "Always", + "ftbchunks.pvp_mode.never": "Never", + "ftbchunks.pvp_mode.per_team": "Per Team", + "ftbchunks.party_limit_mode.largest": "Largest", + "ftbchunks.party_limit_mode.owner": "Owner", + "ftbchunks.party_limit_mode.sum": "Sum", + "ftbchunks.party_limit_mode.average": "Average", + "ftbchunks.force_load_mode.default": "Default", + "ftbchunks.force_load_mode.never": "Never", + "ftbchunks.force_load_mode.always": "Always", + "ftbchunks.time_mode.twenty_four": "Twenty Four", + "ftbchunks.time_mode.twelve": "Twelve", + "ftbchunks.time_mode.clock": "Clock", + "ftbchunks.gui.move_up": "Move Up", + "ftbchunks.gui.move_down": "Move Down", + "minimap.info.ftbchunks.biome.title": "Biome", + "minimap.info.ftbchunks.biome.description": "Render Biome", + "minimap.info.ftbchunks.fps.title": "FPS", + "minimap.info.ftbchunks.fps.description": "Render FPS", + "minimap.info.ftbchunks.game_time.title": "Game Time", + "minimap.info.ftbchunks.game_time.description": "Render Game Time", + "minimap.info.ftbchunks.debug.title": "Debug", + "minimap.info.ftbchunks.debug.description": "Render Debug", + "minimap.info.ftbchunks.player_pos.title": "Player Pos", + "minimap.info.ftbchunks.player_pos.description": "Render Player Pos", + "minimap.info.ftbchunks.real_time.title": "Real Time", + "minimap.info.ftbchunks.real_time.description": "Render Real Time", + "minimap.info.ftbchunks.zone.title": "Zone", + "minimap.info.ftbchunks.zone.description": "Render Zone", + "ftbchunks.gui.toggle_visibility_off": "Toggle Visibility - Off", + "ftbchunks.gui.toggle_visibility_on": "Toggle Visibility - On", + "ftbchunks.gui.sort_minimap_info": "Minimap Info Settings", + "ftbchunks.minimap.info_hidden": "Hidden Minimap Info", + "ftbchunks.minimap.info_order": "Minimap info order", + "ftbchunks.show_wilderness.show_wilderness": "Show Wilderness", + "ftbchunks.show_wilderness.just_claimed": "Show only Claimed Chunks", + "tag.item.ftbchunks.right_click_blacklist": "Right Click Blacklist", + "tag.item.ftbchunks.right_click_whitelist": "Right Click Whitelist" } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 765d8e3c..a969bbb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,15 +13,15 @@ minecraft_version=1.21 # Deps #forge_version=50.0.9 -neoforge_version=21.0.14-beta +neoforge_version=21.0.109-beta # https://maven.neoforged.net/#/releases/net/neoforged/fancymodloader/loader neoforge_loader_version=4 fabric_loader_version=0.15.11 fabric_api_version=0.100.1+1.21 -architectury_api_version=13.0.1 +architectury_api_version=13.0.2 -ftb_library_version=2100.1.0 +ftb_library_version=2100.1.3 ftb_teams_version=2100.1.0 curseforge_id_forge=314906