-
Couldn't load subscription status.
- Fork 6
BME-100 Make waypoint keybind create a waypoint at cursor position in world map #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mc-1.18.2-v0.8.0-overhaul
Are you sure you want to change the base?
Changes from 2 commits
97f4463
b7039c3
fa8559f
8932884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,16 @@ | |
| 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; | ||
|
|
@@ -54,19 +64,20 @@ public static void open() { | |
| } | ||
|
|
||
| public static void apply(Consumer<WorldMapGui> 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("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") | ||
| }; | ||
|
|
||
|
|
||
|
|
@@ -116,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<LineContainer> 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"))); | ||
|
|
@@ -137,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); | ||
|
|
@@ -171,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); | ||
|
|
@@ -192,29 +203,53 @@ 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()) { | ||
| 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); | ||
| } | ||
| } | ||
| new WaypointEditorFragment(position).open(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
|
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should I be calling setMouse() here instead? I think that it would be required for BME-216 to work anyway There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only need to call setMouse when there is mouse input. On render the values are the same as the last frame that the mouse had just moved. Unless something is broken? |
||
|
|
||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, we should just keep the same values from the last change. This does nothing unless you have run into a bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It didn't work without me adding this, I am pretty sure that the |
||
| int dx = 0, dz = 0; | ||
|
|
||
| if( isKeyUp (key) ){ dz -= 16; } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.