-
Notifications
You must be signed in to change notification settings - 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 1 commit
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 |
|---|---|---|
| @@ -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<WorldMapGui> 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<BlazeRegistry.Key<DataType>> filterKeys = new HashSet<>(); | ||
| filterKeys.add(UnsafeGenerics.stripKey(BlazeMapReferences.MasterData.TERRAIN_HEIGHT)); | ||
| mdView.setFilter(filterKeys); | ||
|
|
||
| TerrainHeightMD heightMD = (TerrainHeightMD) mdView.get(BlazeMapReferences.MasterData.TERRAIN_HEIGHT); | ||
dudebehinddude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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; } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
Clientstuff might not be available when the player's connected to a server. Would need to validate it doesn't break when that's the caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm forgetting something, all this should be available at all times in the client, regardless of what the server is.