From 97f446355dd38670a62063a7fc65149ad4867e20 Mon Sep 17 00:00:00 2001 From: DUDEbehindDUDE Date: Sat, 12 Jul 2025 22:37:57 -0400 Subject: [PATCH 1/4] Make waypoint keybind create a waypoint at cursor pos in world map --- .../blazemap/feature/maps/WorldMapGui.java | 43 +++++++++++++++++++ .../maps/ui/InteractiveMapDisplay.java | 11 +++++ 2 files changed, 54 insertions(+) diff --git a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java index f133f48..1d629a4 100644 --- a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java +++ b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java @@ -1,10 +1,25 @@ package com.eerussianguy.blazemap.feature.maps; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; +import com.eerussianguy.blazemap.api.BlazeMapReferences; +import com.eerussianguy.blazemap.api.builtin.TerrainHeightMD; +import com.eerussianguy.blazemap.api.pipeline.DataType; +import com.eerussianguy.blazemap.api.pipeline.MasterDatum; +import com.eerussianguy.blazemap.config.ServerConfig; +import com.eerussianguy.blazemap.engine.UnsafeGenerics; +import com.eerussianguy.blazemap.engine.cache.ChunkMDCache; +import com.eerussianguy.blazemap.engine.cache.ChunkMDCacheView; +import com.eerussianguy.blazemap.engine.client.ClientEngine; +import com.eerussianguy.blazemap.feature.waypoints.WaypointEditorFragment; +import net.minecraft.core.BlockPos; +import net.minecraft.core.SectionPos; +import net.minecraft.world.level.ChunkPos; import org.lwjgl.glfw.GLFW; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -63,6 +78,7 @@ public static void apply(Consumer function) { new WorldMapHotkey("LMB", "Drag to pan the map"), new WorldMapHotkey("RMB", "Open context menu"), new WorldMapHotkey("Scroll", "Zoom in / out"), + new WorldMapHotkey(BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getDisplayName().getString().toUpperCase(),"Create waypoint at cursor"), new WorldMapHotkey("F1", "Toggle map UI"), new WorldMapHotkey("F3", "Toggle debug info"), new WorldMapHotkey("F12", "Export atlas"), @@ -215,6 +231,33 @@ public boolean keyPressed(int key, int scancode, int modifiers) { return true; } + if (key == BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getValue()) { + Level level = Minecraft.getInstance().level; + int posY = level == null ? 60 : level.getSeaLevel(); + Coordination coordination = map.getCoordination(); + BlockPos position = new BlockPos(coordination.blockX, posY, coordination.blockZ); + ChunkPos chunkPos = new ChunkPos(position); + + // Attempt to get y actual level from MDCache + ChunkMDCache mdCache = ClientEngine.getMDCache(chunkPos); + if (mdCache != null) { + ChunkMDCacheView mdView = new ChunkMDCacheView().setSource(mdCache); + Set> filterKeys = new HashSet<>(); + filterKeys.add(UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT)); + mdView.setFilter(filterKeys); + + TerrainHeightMD heightMD = (TerrainHeightMD) mdView.get(BlazeMapReferences.MasterData.TERRAIN_HEIGHT); + + if (heightMD != null) { + int chunkX = SectionPos.sectionRelative(position.getX()); + int chunkZ = SectionPos.sectionRelative(position.getZ()); + posY = heightMD.heightmap[chunkX][chunkZ]; + position = position.atY(posY); + } + } + new WaypointEditorFragment(position).open(); + } + return false; } diff --git a/src/main/java/com/eerussianguy/blazemap/feature/maps/ui/InteractiveMapDisplay.java b/src/main/java/com/eerussianguy/blazemap/feature/maps/ui/InteractiveMapDisplay.java index ebb483f..1cbbb46 100644 --- a/src/main/java/com/eerussianguy/blazemap/feature/maps/ui/InteractiveMapDisplay.java +++ b/src/main/java/com/eerussianguy/blazemap/feature/maps/ui/InteractiveMapDisplay.java @@ -1,5 +1,6 @@ package com.eerussianguy.blazemap.feature.maps.ui; +import com.mojang.blaze3d.vertex.PoseStack; import org.lwjgl.glfw.GLFW; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; @@ -18,6 +19,15 @@ public class InteractiveMapDisplay extends MapDisplay implements UIEventListener private final Coordination coordination = new Coordination(); private VolatileContainer volatiles; private double zoom; + int lastMouseX; + int lastMouseY; + + @Override + public void render(PoseStack stack, boolean hasMouse, int mouseX, int mouseY) { + this.lastMouseX = mouseX; + this.lastMouseY = mouseY; + super.render(stack, hasMouse, mouseX, mouseY); + } public InteractiveMapDisplay(ResourceLocation mapLocation, double minZoom, double maxZoom) { this(0, 0, mapLocation, minZoom, maxZoom); @@ -93,6 +103,7 @@ private void setMouse(double mouseX, double mouseY) { @Override public boolean keyPressed(int key, int scancode, int modifiers) { + setMouse(lastMouseX, lastMouseY); int dx = 0, dz = 0; if( isKeyUp (key) ){ dz -= 16; } From b7039c338af93f368ff8887173b4d3a6d0df0028 Mon Sep 17 00:00:00 2001 From: DUDEbehindDUDE Date: Wed, 23 Jul 2025 01:32:28 -0400 Subject: [PATCH 2/4] Use ChunkMDCache directly (and format WorldMapGui) --- .../blazemap/feature/maps/WorldMapGui.java | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java index 1d629a4..8943677 100644 --- a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java +++ b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java @@ -1,20 +1,15 @@ package com.eerussianguy.blazemap.feature.maps; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; import com.eerussianguy.blazemap.api.BlazeMapReferences; import com.eerussianguy.blazemap.api.builtin.TerrainHeightMD; import com.eerussianguy.blazemap.api.pipeline.DataType; -import com.eerussianguy.blazemap.api.pipeline.MasterDatum; -import com.eerussianguy.blazemap.config.ServerConfig; import com.eerussianguy.blazemap.engine.UnsafeGenerics; import com.eerussianguy.blazemap.engine.cache.ChunkMDCache; -import com.eerussianguy.blazemap.engine.cache.ChunkMDCacheView; import com.eerussianguy.blazemap.engine.client.ClientEngine; import com.eerussianguy.blazemap.feature.waypoints.WaypointEditorFragment; import net.minecraft.core.BlockPos; @@ -69,20 +64,20 @@ public static void open() { } public static void apply(Consumer function) { - if(Minecraft.getInstance().screen instanceof WorldMapGui gui) { + if (Minecraft.getInstance().screen instanceof WorldMapGui gui) { function.accept(gui); } } - private static final WorldMapHotkey[] HOTKEYS = new WorldMapHotkey[] { - new WorldMapHotkey("LMB", "Drag to pan the map"), - new WorldMapHotkey("RMB", "Open context menu"), - new WorldMapHotkey("Scroll", "Zoom in / out"), - new WorldMapHotkey(BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getDisplayName().getString().toUpperCase(),"Create waypoint at cursor"), - new WorldMapHotkey("F1", "Toggle map UI"), - new WorldMapHotkey("F3", "Toggle debug info"), - new WorldMapHotkey("F12", "Export atlas"), - new WorldMapHotkey("W A S D", "Pan the map") + private static final WorldMapHotkey[] HOTKEYS = new WorldMapHotkey[]{ + new WorldMapHotkey("LMB", "Drag to pan the map"), + new WorldMapHotkey("RMB", "Open context menu"), + new WorldMapHotkey("Scroll", "Zoom in / out"), + new WorldMapHotkey(BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getDisplayName().getString().toUpperCase(), "Create waypoint at cursor"), + new WorldMapHotkey("F1", "Toggle map UI"), + new WorldMapHotkey("F3", "Toggle debug info"), + new WorldMapHotkey("F12", "Export atlas"), + new WorldMapHotkey("W A S D", "Pan the map") }; @@ -132,18 +127,18 @@ protected void init() { // MAPS AND LAYERS LineContainer maps = new LineContainer(ContainerAxis.HORIZONTAL, ContainerDirection.POSITIVE, 2).withBackground(); - components.anchor(maps,brand_icon, ContainerAxis.HORIZONTAL, ContainerDirection.POSITIVE); + components.anchor(maps, brand_icon, ContainerAxis.HORIZONTAL, ContainerDirection.POSITIVE); maps.add(new Image(HEADER_MAPS, 16, 16).tooltip(new TextComponent("Maps"))); maps.addSpacer(); List layerSets = new ArrayList<>(); - for(var mapType : mapTypes) { + for (var mapType : mapTypes) { LineContainer layerSet = new LineContainer(ContainerAxis.VERTICAL, ContainerDirection.NEGATIVE, 2).withBackground(); components.anchor(layerSet, brand_icon, ContainerAxis.VERTICAL, ContainerDirection.POSITIVE); layerSets.add(layerSet); maps.add(new MapTypeButton(mapType.getID(), map, layerSets, layerSet)); layerSet.setVisible(map.getMapType().getID().equals(mapType.getID())); - for(var layer : mapType.getLayers()) { + for (var layer : mapType.getLayers()) { layerSet.add(new LayerButton(layer, map)); } layerSet.addSpacer().add(new Image(HEADER_LAYERS, 16, 16).tooltip(new TextComponent("Layers"))); @@ -153,7 +148,7 @@ protected void init() { LineContainer overlaySet = new LineContainer(ContainerAxis.HORIZONTAL, ContainerDirection.POSITIVE, 2).withBackground(); overlaySet.add(new Image(HEADER_OVERLAYS, 16, 16).tooltip(new TextComponent("Overlays"))); overlaySet.addSpacer(); - for(var overlay : overlays) { + for (var overlay : overlays) { overlaySet.add(new OverlayButton(overlay.getID(), map)); } components.add(overlaySet, ContainerAnchor.BOTTOM_LEFT); @@ -187,7 +182,7 @@ protected void init() { private void updateLegend() { var legend = WrappedComponent.ofNullable(map.getMapType().getLayers().iterator().next().value().getLegendWidget()); - if(legend == null) { + if (legend == null) { this.legend.clear(); } else { this.legend.add(legend); @@ -208,25 +203,25 @@ public boolean mouseDragged(double p_94699_, double p_94700_, int p_94701_, doub @Override public boolean keyPressed(int key, int scancode, int modifiers) { - if(key == GLFW.GLFW_KEY_F1) { + if (key == GLFW.GLFW_KEY_F1) { visibilityController.toggleVisible(); return true; } - if(key == GLFW.GLFW_KEY_F12) { + if (key == GLFW.GLFW_KEY_F12) { AtlasExporter.exportAsync(new AtlasTask(this.dimension, map.getMapType().getID(), map.getRenderer().getVisibleLayers(), TileResolution.FULL, map.getRenderer().getCenterRegion())); return true; } - if(key == GLFW.GLFW_KEY_F3) { + if (key == GLFW.GLFW_KEY_F3) { renderDebug = !renderDebug; return true; } - if(root.keyPressed(key, scancode, modifiers)) return true; - if(super.keyPressed(key, scancode, modifiers)) return true; + if (root.keyPressed(key, scancode, modifiers)) return true; + if (super.keyPressed(key, scancode, modifiers)) return true; - if(key == BlazeMapFeaturesClient.KEY_MAPS.getKey().getValue()) { + if (key == BlazeMapFeaturesClient.KEY_MAPS.getKey().getValue()) { this.onClose(); return true; } @@ -241,12 +236,9 @@ public boolean keyPressed(int key, int scancode, int modifiers) { // Attempt to get y actual level from MDCache ChunkMDCache mdCache = ClientEngine.getMDCache(chunkPos); if (mdCache != null) { - ChunkMDCacheView mdView = new ChunkMDCacheView().setSource(mdCache); - Set> filterKeys = new HashSet<>(); - filterKeys.add(UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT)); - mdView.setFilter(filterKeys); - - TerrainHeightMD heightMD = (TerrainHeightMD) mdView.get(BlazeMapReferences.MasterData.TERRAIN_HEIGHT); + TerrainHeightMD heightMD = (TerrainHeightMD) mdCache.get( + UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT) + ); if (heightMD != null) { int chunkX = SectionPos.sectionRelative(position.getX()); From fa8559f96e3aa7fc9b6e497aa95a8b0933ded3e9 Mon Sep 17 00:00:00 2001 From: DUDEbehindDUDE Date: Fri, 25 Jul 2025 20:23:02 -0400 Subject: [PATCH 3/4] Fix formatting --- .../blazemap/feature/maps/WorldMapGui.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java index 8943677..65fd737 100644 --- a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java +++ b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java @@ -12,6 +12,7 @@ import com.eerussianguy.blazemap.engine.cache.ChunkMDCache; import com.eerussianguy.blazemap.engine.client.ClientEngine; import com.eerussianguy.blazemap.feature.waypoints.WaypointEditorFragment; + import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.ChunkPos; @@ -64,20 +65,20 @@ public static void open() { } public static void apply(Consumer function) { - if (Minecraft.getInstance().screen instanceof WorldMapGui gui) { + if(Minecraft.getInstance().screen instanceof WorldMapGui gui) { function.accept(gui); } } - private static final WorldMapHotkey[] HOTKEYS = new WorldMapHotkey[]{ - new WorldMapHotkey("LMB", "Drag to pan the map"), - new WorldMapHotkey("RMB", "Open context menu"), - new WorldMapHotkey("Scroll", "Zoom in / out"), - new WorldMapHotkey(BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getDisplayName().getString().toUpperCase(), "Create waypoint at cursor"), - new WorldMapHotkey("F1", "Toggle map UI"), - new WorldMapHotkey("F3", "Toggle debug info"), - new WorldMapHotkey("F12", "Export atlas"), - new WorldMapHotkey("W A S D", "Pan the map") + private static final WorldMapHotkey[] HOTKEYS = new WorldMapHotkey[] { + new WorldMapHotkey("LMB", "Drag to pan the map"), + new WorldMapHotkey("RMB", "Open context menu"), + new WorldMapHotkey("Scroll", "Zoom in / out"), + new WorldMapHotkey(BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getDisplayName().getString().toUpperCase(), "Create waypoint at cursor"), + new WorldMapHotkey("F1", "Toggle map UI"), + new WorldMapHotkey("F3", "Toggle debug info"), + new WorldMapHotkey("F12", "Export atlas"), + new WorldMapHotkey("W A S D", "Pan the map") }; @@ -131,14 +132,14 @@ protected void init() { maps.add(new Image(HEADER_MAPS, 16, 16).tooltip(new TextComponent("Maps"))); maps.addSpacer(); List layerSets = new ArrayList<>(); - for (var mapType : mapTypes) { + for(var mapType : mapTypes) { LineContainer layerSet = new LineContainer(ContainerAxis.VERTICAL, ContainerDirection.NEGATIVE, 2).withBackground(); components.anchor(layerSet, brand_icon, ContainerAxis.VERTICAL, ContainerDirection.POSITIVE); layerSets.add(layerSet); maps.add(new MapTypeButton(mapType.getID(), map, layerSets, layerSet)); layerSet.setVisible(map.getMapType().getID().equals(mapType.getID())); - for (var layer : mapType.getLayers()) { + for(var layer : mapType.getLayers()) { layerSet.add(new LayerButton(layer, map)); } layerSet.addSpacer().add(new Image(HEADER_LAYERS, 16, 16).tooltip(new TextComponent("Layers"))); @@ -148,7 +149,7 @@ protected void init() { LineContainer overlaySet = new LineContainer(ContainerAxis.HORIZONTAL, ContainerDirection.POSITIVE, 2).withBackground(); overlaySet.add(new Image(HEADER_OVERLAYS, 16, 16).tooltip(new TextComponent("Overlays"))); overlaySet.addSpacer(); - for (var overlay : overlays) { + for(var overlay : overlays) { overlaySet.add(new OverlayButton(overlay.getID(), map)); } components.add(overlaySet, ContainerAnchor.BOTTOM_LEFT); @@ -182,7 +183,7 @@ protected void init() { private void updateLegend() { var legend = WrappedComponent.ofNullable(map.getMapType().getLayers().iterator().next().value().getLegendWidget()); - if (legend == null) { + if(legend == null) { this.legend.clear(); } else { this.legend.add(legend); @@ -203,30 +204,30 @@ public boolean mouseDragged(double p_94699_, double p_94700_, int p_94701_, doub @Override public boolean keyPressed(int key, int scancode, int modifiers) { - if (key == GLFW.GLFW_KEY_F1) { + if(key == GLFW.GLFW_KEY_F1) { visibilityController.toggleVisible(); return true; } - if (key == GLFW.GLFW_KEY_F12) { + if(key == GLFW.GLFW_KEY_F12) { AtlasExporter.exportAsync(new AtlasTask(this.dimension, map.getMapType().getID(), map.getRenderer().getVisibleLayers(), TileResolution.FULL, map.getRenderer().getCenterRegion())); return true; } - if (key == GLFW.GLFW_KEY_F3) { + if(key == GLFW.GLFW_KEY_F3) { renderDebug = !renderDebug; return true; } - if (root.keyPressed(key, scancode, modifiers)) return true; - if (super.keyPressed(key, scancode, modifiers)) return true; + if(root.keyPressed(key, scancode, modifiers)) return true; + if(super.keyPressed(key, scancode, modifiers)) return true; - if (key == BlazeMapFeaturesClient.KEY_MAPS.getKey().getValue()) { + if(key == BlazeMapFeaturesClient.KEY_MAPS.getKey().getValue()) { this.onClose(); return true; } - if (key == BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getValue()) { + if(key == BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getValue()) { Level level = Minecraft.getInstance().level; int posY = level == null ? 60 : level.getSeaLevel(); Coordination coordination = map.getCoordination(); @@ -235,12 +236,12 @@ public boolean keyPressed(int key, int scancode, int modifiers) { // Attempt to get y actual level from MDCache ChunkMDCache mdCache = ClientEngine.getMDCache(chunkPos); - if (mdCache != null) { + if(mdCache != null) { TerrainHeightMD heightMD = (TerrainHeightMD) mdCache.get( - UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT) + UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT) ); - if (heightMD != null) { + if(heightMD != null) { int chunkX = SectionPos.sectionRelative(position.getX()); int chunkZ = SectionPos.sectionRelative(position.getZ()); posY = heightMD.heightmap[chunkX][chunkZ]; From 89328845a342178b79dd62669e7f7bd8694d7395 Mon Sep 17 00:00:00 2001 From: DUDEbehindDUDE Date: Sat, 26 Jul 2025 20:40:28 -0400 Subject: [PATCH 4/4] Abstract getCursorBlockPos and add missing return statement --- .../blazemap/feature/maps/WorldMapGui.java | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java index 65fd737..0a3e1b0 100644 --- a/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java +++ b/src/main/java/com/eerussianguy/blazemap/feature/maps/WorldMapGui.java @@ -5,44 +5,51 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import com.eerussianguy.blazemap.api.BlazeMapReferences; -import com.eerussianguy.blazemap.api.builtin.TerrainHeightMD; -import com.eerussianguy.blazemap.api.pipeline.DataType; -import com.eerussianguy.blazemap.engine.UnsafeGenerics; -import com.eerussianguy.blazemap.engine.cache.ChunkMDCache; -import com.eerussianguy.blazemap.engine.client.ClientEngine; -import com.eerussianguy.blazemap.feature.waypoints.WaypointEditorFragment; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.SectionPos; -import net.minecraft.world.level.ChunkPos; import org.lwjgl.glfw.GLFW; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.core.BlockPos; +import net.minecraft.core.SectionPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import com.eerussianguy.blazemap.BlazeMap; import com.eerussianguy.blazemap.api.BlazeMapAPI; +import com.eerussianguy.blazemap.api.BlazeMapReferences; import com.eerussianguy.blazemap.api.BlazeRegistry; +import com.eerussianguy.blazemap.api.builtin.TerrainHeightMD; import com.eerussianguy.blazemap.api.maps.MapType; import com.eerussianguy.blazemap.api.maps.Overlay; import com.eerussianguy.blazemap.api.maps.TileResolution; import com.eerussianguy.blazemap.config.BlazeMapConfig; +import com.eerussianguy.blazemap.engine.UnsafeGenerics; +import com.eerussianguy.blazemap.engine.cache.ChunkMDCache; +import com.eerussianguy.blazemap.engine.client.ClientEngine; import com.eerussianguy.blazemap.feature.BlazeMapFeaturesClient; -import com.eerussianguy.blazemap.feature.atlas.*; -import com.eerussianguy.blazemap.feature.maps.ui.*; -import com.eerussianguy.blazemap.feature.maps.ui.NamedMapComponentButton.*; +import com.eerussianguy.blazemap.feature.atlas.AtlasExportProgress; +import com.eerussianguy.blazemap.feature.atlas.AtlasExporter; +import com.eerussianguy.blazemap.feature.atlas.AtlasTask; +import com.eerussianguy.blazemap.feature.maps.ui.InteractiveMapDisplay; +import com.eerussianguy.blazemap.feature.maps.ui.MapScaleDisplay; +import com.eerussianguy.blazemap.feature.maps.ui.NamedMapComponentButton.LayerButton; +import com.eerussianguy.blazemap.feature.maps.ui.NamedMapComponentButton.MapTypeButton; +import com.eerussianguy.blazemap.feature.maps.ui.NamedMapComponentButton.OverlayButton; +import com.eerussianguy.blazemap.feature.maps.ui.WorldMapDebug; +import com.eerussianguy.blazemap.feature.maps.ui.WorldMapHotkey; +import com.eerussianguy.blazemap.feature.waypoints.WaypointEditorFragment; import com.eerussianguy.blazemap.lib.ObjHolder; import com.eerussianguy.blazemap.lib.gui.components.Image; import com.eerussianguy.blazemap.lib.gui.components.LineContainer; import com.eerussianguy.blazemap.lib.gui.components.Placeholder; import com.eerussianguy.blazemap.lib.gui.components.VanillaComponents; import com.eerussianguy.blazemap.lib.gui.core.*; -import com.eerussianguy.blazemap.lib.gui.fragment.*; +import com.eerussianguy.blazemap.lib.gui.fragment.BaseFragment; +import com.eerussianguy.blazemap.lib.gui.fragment.FragmentHost; +import com.eerussianguy.blazemap.lib.gui.fragment.HostWindowComponent; import com.eerussianguy.blazemap.lib.gui.util.VisibilityController; import com.eerussianguy.blazemap.profiling.Profiler; import com.mojang.blaze3d.vertex.PoseStack; @@ -228,27 +235,9 @@ public boolean keyPressed(int key, int scancode, int modifiers) { } if(key == BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getValue()) { - Level level = Minecraft.getInstance().level; - int posY = level == null ? 60 : level.getSeaLevel(); - Coordination coordination = map.getCoordination(); - BlockPos position = new BlockPos(coordination.blockX, posY, coordination.blockZ); - ChunkPos chunkPos = new ChunkPos(position); - - // Attempt to get y actual level from MDCache - ChunkMDCache mdCache = ClientEngine.getMDCache(chunkPos); - if(mdCache != null) { - TerrainHeightMD heightMD = (TerrainHeightMD) mdCache.get( - UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT) - ); - - if(heightMD != null) { - int chunkX = SectionPos.sectionRelative(position.getX()); - int chunkZ = SectionPos.sectionRelative(position.getZ()); - posY = heightMD.heightmap[chunkX][chunkZ]; - position = position.atY(posY); - } - } + var position = getCursorBlockPos(); new WaypointEditorFragment(position).open(); + return true; } return false; @@ -266,4 +255,29 @@ public void addInspector(MDInspectorWidget widget) { this.addRenderableWidget(widget); widget.setDismisser(() -> this.removeWidget(widget)); } + + public BlockPos getCursorBlockPos() { + Level level = Minecraft.getInstance().level; + int posY = level == null ? 65 : level.getSeaLevel(); + Coordination coordination = map.getCoordination(); + BlockPos position = new BlockPos(coordination.blockX, posY, coordination.blockZ); + ChunkPos chunkPos = new ChunkPos(position); + + // Attempt to get y actual level from MDCache + ChunkMDCache mdCache = ClientEngine.getMDCache(chunkPos); + if(mdCache != null) { + TerrainHeightMD heightMD = (TerrainHeightMD) mdCache.get( + UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT) + ); + + if(heightMD != null) { + int chunkX = SectionPos.sectionRelative(position.getX()); + int chunkZ = SectionPos.sectionRelative(position.getZ()); + posY = heightMD.heightmap[chunkX][chunkZ]; + position = position.atY(posY); + } + } + + return position; + } }