From 4b679c2a55427c0f7945c51db46cede3e04b30b2 Mon Sep 17 00:00:00 2001 From: nea Date: Sun, 1 May 2022 00:46:48 +0200 Subject: make navigation actually good --- .../core/util/render/RenderUtils.java | 68 ++++++++++++++-------- .../notenoughupdates/miscfeatures/Navigation.java | 34 ++++++++++- .../notenoughupdates/miscgui/GuiNavigation.java | 35 ++++++----- .../notenoughupdates/options/NEUConfig.java | 3 + .../options/seperateSections/Misc.java | 26 ++++++++- 5 files changed, 123 insertions(+), 43 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java index d7fd7907..96e9729f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/render/RenderUtils.java @@ -13,11 +13,20 @@ import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; -import net.minecraft.util.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3i; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Vector3f; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class RenderUtils { public static void drawFloatingRectDark(int x, int y, int width, int height) { drawFloatingRectDark(x, y, width, height, true); @@ -345,11 +354,19 @@ public class RenderUtils { } } - public static void renderWayPoint(String str, BlockPos loc, float partialTicks) { + public static void renderWayPoint(String str, Vec3i loc, float partialTicks) { + renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks); + } + + public static void renderWayPoint(List str, Vec3i loc, float partialTicks) { renderWayPoint(str, new Vector3f(loc.getX(), loc.getY(), loc.getZ()), partialTicks); } public static void renderWayPoint(String str, Vector3f loc, float partialTicks) { + renderWayPoint(Arrays.asList(str), loc, partialTicks); + } + + public static void renderWayPoint(List lines, Vector3f loc, float partialTicks) { GlStateManager.alphaFunc(516, 0.1F); GlStateManager.pushMatrix(); @@ -373,15 +390,9 @@ public class RenderUtils { GlStateManager.translate(x, y, z); GlStateManager.translate(0, viewer.getEyeHeight(), 0); - renderNametag(str); - - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.translate(0, -0.25f, 0); - GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); - GlStateManager.rotate(Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); - - renderNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); + lines = new ArrayList<>(lines); + lines.add(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + "m"); + renderNametag(lines); GlStateManager.popMatrix(); @@ -389,6 +400,10 @@ public class RenderUtils { } public static void renderNametag(String str) { + renderNametag(Arrays.asList(str)); + } + + public static void renderNametag(List lines) { FontRenderer fontrenderer = Minecraft.getMinecraft().fontRendererObj; float f = 1.6F; float f1 = 0.016666668F * f; @@ -406,20 +421,23 @@ public class RenderUtils { WorldRenderer worldrenderer = tessellator.getWorldRenderer(); int i = 0; - int j = fontrenderer.getStringWidth(str) / 2; - GlStateManager.disableTexture2D(); - worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); - worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); - tessellator.draw(); - GlStateManager.enableTexture2D(); - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); - GlStateManager.depthMask(true); - - fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); - + for (String str : lines) { + int j = fontrenderer.getStringWidth(str) / 2; + + GlStateManager.disableTexture2D(); + worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); + worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); + GlStateManager.depthMask(true); + + fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); + GlStateManager.translate(0, 10f, 0); + } GlStateManager.enableDepth(); GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java index b2574b76..4baa9e6e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/Navigation.java @@ -6,7 +6,9 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; +import io.github.moulberry.notenoughupdates.miscgui.GuiNavigation; import io.github.moulberry.notenoughupdates.util.JsonUtils; +import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -16,8 +18,12 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.input.Keyboard; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -90,6 +96,13 @@ public class Navigation { showError("Could not track waypoint. This is likely due to an outdated or broken repository."); return; } + if (!neu.config.hidden.hasOpenedWaypointMenu) + NotificationHandler.displayNotification(Arrays.asList( + "You just tracked a waypoint.", + "Press [N] to open the waypoint menu to untrack it", + "or to find other waypoints to track.", + "Press [X] to close this message." + ), true, false); currentlyTrackedWaypoint = trackNow; updateData(); } @@ -120,6 +133,14 @@ public class Navigation { this.areaNames = JsonUtils.transformJsonObjectToMap(obj.getAsJsonObject("area_names"), JsonElement::getAsString); } + @SubscribeEvent + public void onKeybindPressed(InputEvent.KeyInputEvent event) { + int key = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); + if (neu.config.misc.keybindWaypoint == key) { + Minecraft.getMinecraft().displayGuiScreen(new GuiNavigation()); + } + } + public String getNameForAreaMode(String mode) { return areaNames.get(mode); } @@ -217,6 +238,17 @@ public class Navigation { new RuntimeException("[NEU-Waypoint] " + message).printStackTrace(); } + @SubscribeEvent + public void onEvent(TickEvent.ClientTickEvent event) { + if (event.phase == TickEvent.Phase.END && currentlyTrackedWaypoint != null + && NotEnoughUpdates.INSTANCE.config.misc.untrackCloseWaypoints + && island.equals(SBInfo.getInstance().mode)) { + EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer; + if (thePlayer.getDistanceSq(position) < 16) + untrackWaypoint(); + } + } + @SubscribeEvent public void onRenderLast(RenderWorldLastEvent event) { if (currentlyTrackedWaypoint != null) { @@ -226,7 +258,7 @@ public class Navigation { String to = nextTeleporter.to; String toName = getNameForAreaModeOrUnknown(to); RenderUtils.renderWayPoint( - "Teleporter to " + toName + " (towards " + displayName + "§r)", + Arrays.asList("Teleporter to " + toName, "(towards " + displayName + "§r)"), new BlockPos( nextTeleporter.x, nextTeleporter.y, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java index c0ff5b93..d34988f6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -39,7 +39,7 @@ public class GuiNavigation extends GuiScreen { public static final int TEXT_OFFSET_X = 28; public static final int LIST_COUNT = 6; - List searchResults = new ArrayList<>(); + List searchResults = new ArrayList<>(); public int xSize = 176; public int ySize = 222; @@ -50,6 +50,7 @@ public class GuiNavigation extends GuiScreen { @Override public void initGui() { super.initGui(); + NotEnoughUpdates.INSTANCE.config.hidden.hasOpenedWaypointMenu = true; guiLeft = (width - xSize) / 2; guiTop = (height - ySize) / 2; } @@ -65,9 +66,9 @@ public class GuiNavigation extends GuiScreen { for (int i = 0; i < LIST_COUNT; i++) { if (i < searchResults.size()) { Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); - JsonObject thing = searchResults.get(i); - boolean selected = - thing.get("internalname").getAsString().equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); + String name = searchResults.get(i); + JsonObject json = NotEnoughUpdates.INSTANCE.navigation.getWaypoints().get(name); + boolean selected = name.equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); int baseX = guiLeft + LIST_START_X; int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; @@ -79,7 +80,7 @@ public class GuiNavigation extends GuiScreen { ICON_SIZE, ICON_SIZE ); Utils.drawStringF( - thing.get("displayname").getAsString(), + json.get("displayname").getAsString(), Minecraft.getMinecraft().fontRendererObj, baseX + TEXT_OFFSET_X, baseY + LIST_OFFSET_Y / 2F - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2F, @@ -92,21 +93,24 @@ public class GuiNavigation extends GuiScreen { private void refreshResults() { String text = textField.getText().toLowerCase(); - searchResults = NotEnoughUpdates.INSTANCE.navigation + List results = NotEnoughUpdates.INSTANCE.navigation .getWaypoints() .values() .stream() .filter(it -> it.get("internalname").getAsString().toLowerCase().contains(text) || it.get("displayname").getAsString().toLowerCase().contains(text)) - .sorted(Comparator - .comparing( - it -> it.get("internalname").getAsString(), - Comparator.comparing(String::length) - .thenComparing(String.CASE_INSENSITIVE_ORDER) - ) - ) + .map(it -> it.get("internalname").getAsString()) + .sorted(Comparator.comparing(String::length) + .thenComparing(String.CASE_INSENSITIVE_ORDER)) .collect(Collectors.toList()); + + String internalname = NotEnoughUpdates.INSTANCE.navigation.getInternalname(); + if (internalname != null) { + results.remove(internalname); + results.add(0, internalname); + } + searchResults = results; } @Override @@ -135,9 +139,8 @@ public class GuiNavigation extends GuiScreen { int baseX = guiLeft + LIST_START_X; int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; if (Utils.isWithinRect(mouseX, mouseY, baseX, baseY, ICON_SIZE, ICON_SIZE)) { - JsonObject thing = searchResults.get(i); - boolean selected = - thing.get("internalname").getAsString().equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); + String thing = searchResults.get(i); + boolean selected = thing.equals(NotEnoughUpdates.INSTANCE.navigation.getInternalname()); if (selected) { NotEnoughUpdates.INSTANCE.navigation.untrackWaypoint(); } else { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 68449ba8..e0d46a1e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -417,6 +417,9 @@ public class NEUConfig extends Config { @Expose public boolean npcRetextureOnSelf = false; + @Expose + public boolean hasOpenedWaypointMenu = false; + } public static ArrayList createDefaultEnchantColours() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 631ce545..4c521023 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -1,7 +1,15 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; import com.google.gson.annotations.Expose; -import io.github.moulberry.notenoughupdates.core.config.annotations.*; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorKeybind; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; public class Misc { @Expose @@ -163,4 +171,20 @@ public class Misc { "Fandom" }) public int wiki = 0; + + @Expose + @ConfigOption( + name = "Waypoint Keybind", + desc = "Press this keybind to show waypoints to various NPCs" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_N) + public int keybindWaypoint = Keyboard.KEY_N; + + @Expose + @ConfigOption( + name = "Untrack close Waypoints", + desc = "Automatically untrack waypoints once you get close to them." + ) + @ConfigEditorBoolean + public boolean untrackCloseWaypoints = true; } -- cgit