From cd425c0bd4484ec1f5616c67645fc35d126d14b0 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 28 Jul 2022 04:20:58 +0200 Subject: stuff --- .../notenoughupdates/NotEnoughUpdates.java | 2 + .../commands/dev/DevTestCommand.java | 5 ++ .../dungeons/map/DungeonMapDebugOverlay.java | 10 ++- .../dungeons/map/DungeonMapPlayers.java | 92 +++++++++++----------- .../dungeons/map/DungeonMapRenderer.java | 22 ++++-- .../mixins/AccessorEntityPlayerSP.java | 33 ++++++++ src/main/resources/mixins.notenoughupdates.json | 1 + 7 files changed, 109 insertions(+), 56 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorEntityPlayerSP.java diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index 9701005f..5c47c3c3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -27,6 +27,7 @@ import io.github.moulberry.notenoughupdates.commands.Commands; import io.github.moulberry.notenoughupdates.core.BackgroundBlur; import io.github.moulberry.notenoughupdates.cosmetics.CapeManager; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; +import io.github.moulberry.notenoughupdates.dungeons.map.DungeonMap; import io.github.moulberry.notenoughupdates.listener.ChatListener; import io.github.moulberry.notenoughupdates.listener.ItemTooltipListener; import io.github.moulberry.notenoughupdates.listener.NEUEventListener; @@ -286,6 +287,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new SignCalculator()); MinecraftForge.EVENT_BUS.register(TrophyRewardOverlay.getInstance()); MinecraftForge.EVENT_BUS.register(navigation); + MinecraftForge.EVENT_BUS.register(new DungeonMap()); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 7cca9d3b..9f6faa81 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.commands.dev; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; +import io.github.moulberry.notenoughupdates.dungeons.map.DungeonMapPlayers; import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; @@ -163,6 +164,10 @@ public class DevTestCommand extends ClientCommandBase { "I would never search")); return; } + if(args.length == 2 && "mapscale".equalsIgnoreCase(args[0])) { + DungeonMapPlayers.mapScale = Float.parseFloat(args[1]); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Set mapsacle.")); + } if (args.length == 2 && args[0].equalsIgnoreCase("openGui")) { try { NotEnoughUpdates.INSTANCE.openGui = (GuiScreen) Class.forName(args[1]).newInstance(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapDebugOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapDebugOverlay.java index 74c3b587..eccc18fd 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapDebugOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapDebugOverlay.java @@ -12,14 +12,11 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.time.Duration; -import java.time.Instant; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; -import java.util.Calendar; import java.util.List; import java.util.Map; -import java.util.TimeZone; public class DungeonMapDebugOverlay extends TextOverlay { public DungeonMapDebugOverlay(DungeonMap map) { @@ -38,6 +35,7 @@ public class DungeonMapDebugOverlay extends TextOverlay { } public void newDungeon() { + finishDungeon(); File file = new File(NotEnoughUpdates.INSTANCE.getNeuDir(), String.format( "dungeonlog/log-%s.txt", DateTimeFormatter.ofPattern("dd-MM-yyyy-HH-mm-ss").format(LocalDateTime.now()) @@ -82,6 +80,12 @@ public class DungeonMapDebugOverlay extends TextOverlay { overlayStrings.add("Player Coords:"); addMap(map.dungeonMapPlayers.getRunnerEntityPosition()); + DungeonMapPlayers.PlayerMarker playerMarker = map.dungeonMapPlayers.getPlayerMarker(); + overlayStrings.add("Player Marker: " + (playerMarker == null ? "None" : playerMarker.x + " " + playerMarker.z)); + + overlayStrings.add( + "Map Offset: " + map.dungeonMapPlayers.getMapOffsetX() + " " + map.dungeonMapPlayers.getMapOffsetZ()); + overlayStrings.add(""); overlayStrings.add("Rendered Coords:"); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapPlayers.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapPlayers.java index 53b2e602..9a2113c3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapPlayers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapPlayers.java @@ -2,6 +2,7 @@ package io.github.moulberry.notenoughupdates.dungeons.map; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import io.github.moulberry.notenoughupdates.mixins.AccessorEntityPlayerSP; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.resources.DefaultPlayerSkin; @@ -17,41 +18,17 @@ import java.util.Objects; public class DungeonMapPlayers { - public static class Linear { - private final float slope; - private final float intercept; - - public Linear(float slope, float intercept) { - this.slope = slope; - this.intercept = intercept; - } - - public float getSlope() { - return slope; - } - - public float getIntercept() { - return intercept; - } - - public float calculate(float x) { - return slope * x + intercept; - } + public PlayerMarker getPlayerMarker() { + return mainPlayerMarker; + } - public float calculateInverse(float y) { - return (y - intercept) / slope; - } + public float getMapOffsetX() { + return mapXOffset; } - public static Map FLOOR_MAP_SCALINGS = new HashMap() {{ - put("F1", new Linear(1.5F, -215F)); - put("F2", new Linear(1.5F, -215F)); - put("F3", new Linear(1.5F, -215F)); - put("F4", new Linear(1.6F, -206F)); - put("F5", new Linear(1.6F, -206F)); - put("F6", new Linear(1.6F, -206F)); - put("F7", new Linear(1.6F, -206F)); - }}; + public float getMapOffsetZ() { + return mapZOffset; + } public static class PlayerMarker { public final int x, z; @@ -93,17 +70,22 @@ public class DungeonMapPlayers { private final Map skinMap = new HashMap<>(); private final Map allMapPositions = new HashMap<>(); private final Map orphanedMarkers = new HashMap<>(); + private PlayerMarker mainPlayerMarker; private float mainPlayerRotation; private float mainPlayerX; private float mainPlayerZ; + private float mapXOffset; + private float mapZOffset; + public static float mapScale = 0.66F; private boolean isRealPlayer(String playerName) { - return Minecraft.getMinecraft().thePlayer.getWorldScoreboard().getTeams().stream() - .anyMatch(it - -> it.getMembershipCollection().size() == 1 - && it.getMembershipCollection().contains(playerName) - && it.getTeamName().startsWith("a") - && it.getNameTagVisibility() == Team.EnumVisible.ALWAYS); + return Minecraft.getMinecraft().thePlayer + .getWorldScoreboard().getTeams().stream() + .anyMatch(it + -> it.getMembershipCollection().size() == 1 + && it.getMembershipCollection().contains(playerName) + && it.getTeamName().startsWith("a") + && it.getNameTagVisibility() == Team.EnumVisible.ALWAYS); } public void parse(DungeonMapStaticParser mapData, DungeonMapPlayers last) { @@ -111,15 +93,21 @@ public class DungeonMapPlayers { if (last != null) { playerNameToIconName.putAll(last.playerNameToIconName); skinMap.putAll(last.skinMap); + mapXOffset = last.mapXOffset; + mapZOffset = last.mapZOffset; } if (mapData == null) return; + Map mapDecorations = mapData.mapDecorations; + if (mapDecorations != null) { + parseMapPositions(mapDecorations); + if (mainPlayerMarker != null) + calculateMapOffset(mainPlayerMarker); + } parseEntityPositions(mapData); - Map mapDecorations = mapData.mapDecorations; if (mapDecorations != null) { - parseMapPositions(mapDecorations); assignKnownMapMarkers(mapData.dungeonMap); findOrphanedMarkers(); } else if (last != null) { @@ -136,6 +124,13 @@ public class DungeonMapPlayers { }); } + private void calculateMapOffset(PlayerMarker marker) { + AccessorEntityPlayerSP thePlayer = ((AccessorEntityPlayerSP) Minecraft.getMinecraft().thePlayer); + + mapXOffset = (float) (marker.x - (mapScale * thePlayer.getLastReportedPosX())); + mapZOffset = (float) (marker.z - (mapScale * thePlayer.getLastReportedPosZ())); + } + private void findOrphanedMarkers() { for (Map.Entry marker : allMapPositions.entrySet()) { if (!playerNameToIconName.containsValue(marker.getKey())) { @@ -152,7 +147,11 @@ public class DungeonMapPlayers { int mapX = (int) entry.getValue().func_176112_b() / 2 + 64; int mapZ = (int) entry.getValue().func_176113_c() / 2 + 64; float angle = entry.getValue().func_176111_d() * 360 / 16F; - allMapPositions.put(entry.getKey(), new PlayerMarker(mapX, mapZ, angle)); + PlayerMarker marker = new PlayerMarker(mapX, mapZ, angle); + allMapPositions.put(entry.getKey(), marker); + if (id == 1) { + mainPlayerMarker = marker; + } } } @@ -162,12 +161,15 @@ public class DungeonMapPlayers { for (Map.Entry mapPos : allMapPositions.entrySet()) { String oldPlayer = playerNameToIconName.inverse().get(mapPos.getKey()); String newPlayer = findExclusivePlayerNextToPoint(mapPos.getValue()); + if (mainPlayerMarker == mapPos.getValue()) { + newPlayer = Minecraft.getMinecraft().thePlayer.getName(); + } if (newPlayer == null && oldPlayer != null) { dungeonMap.dungeonMapDebugOverlay.logAssignmentChange( EnumChatFormatting.GOLD + "Player " + oldPlayer + " is far away from their respective marker (" + mapPos.getKey() + "). Still keeping marker."); } - + if (oldPlayer != null) continue; if (newPlayer != null && !Objects.equals(newPlayer, oldPlayer)) { if (playerNameToIconName.containsKey(newPlayer)) { String oldMarker = playerNameToIconName.remove(newPlayer); @@ -196,8 +198,6 @@ public class DungeonMapPlayers { } private void parseEntityPositions(DungeonMapStaticParser mapData) { - Linear coordMapping = FLOOR_MAP_SCALINGS.get(mapData.floorName); - if (coordMapping == null) return; for (EntityPlayer entity : Minecraft.getMinecraft().theWorld.playerEntities) { if (entity.isPlayerSleeping() || !isRealPlayer(entity.getName())) continue; if (entity instanceof AbstractClientPlayer) { @@ -206,8 +206,8 @@ public class DungeonMapPlayers { skinMap.put(entity.getName(), skin); } - float x = coordMapping.calculateInverse((float) entity.posX); - float z = coordMapping.calculateInverse((float) entity.posZ); + float x = ((float) entity.posX) * mapScale + mapXOffset; + float z = ((float) entity.posZ) * mapScale + mapZOffset; if (entity.getName().equals(Minecraft.getMinecraft().thePlayer.getName())) { mainPlayerX = x; mainPlayerZ = z; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapRenderer.java index b284a8b6..560a51f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/map/DungeonMapRenderer.java @@ -9,7 +9,6 @@ import io.github.moulberry.notenoughupdates.util.NEUResourceManager; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -258,12 +257,21 @@ public class DungeonMapRenderer { orphanedMarker ); } - if (NEUDebugFlag.MAP.isSet()) - players.getAllMapPositions().forEach((label, playerMarker) -> { - float x = playerMarker.x * pixelToMapScale; - float y = playerMarker.z * pixelToMapScale; - Utils.drawStringF(label, Minecraft.getMinecraft().fontRendererObj, x, y, true, 0xffd3d3d3); - }); + if (NEUDebugFlag.MAP.isSet()) { + if (Minecraft.getMinecraft().thePlayer.isSneaking()) { + players.getRunnerEntityPosition().forEach((name, playerMarker) -> { + float x = playerMarker.x * pixelToMapScale; + float y = playerMarker.z * pixelToMapScale; + Utils.drawStringF(name, Minecraft.getMinecraft().fontRendererObj, x, y, true, 0xffd3d3d3); + }); + } else { + players.getAllMapPositions().forEach((label, playerMarker) -> { + float x = playerMarker.x * pixelToMapScale; + float y = playerMarker.z * pixelToMapScale; + Utils.drawStringF(label, Minecraft.getMinecraft().fontRendererObj, x, y, true, 0xffd3d3d3); + }); + } + } if (useFb) { GlStateManager.enableBlend(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorEntityPlayerSP.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorEntityPlayerSP.java new file mode 100644 index 00000000..ef74a062 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/AccessorEntityPlayerSP.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import net.minecraft.client.entity.EntityPlayerSP; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(EntityPlayerSP.class) +public interface AccessorEntityPlayerSP { + @Accessor(value = "lastReportedPosX") + double getLastReportedPosX(); + + @Accessor(value = "lastReportedPosZ") + double getLastReportedPosZ(); +} diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 8b1d4559..19bce633 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -47,6 +47,7 @@ "MixinWorldClient" ], "client": [ + "AccessorEntityPlayerSP", "AccessorGuiContainer", "AccessorGuiEditSign", "AccessorMinecraft", -- cgit