Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
};


Expand Down Expand Up @@ -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")));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Client stuff might not be available when the player's connected to a server. Would need to validate it doesn't break when that's the case

Copy link
Owner

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.

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;
}

Expand Down
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;
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand Down Expand Up @@ -93,6 +103,7 @@ private void setMouse(double mouseX, double mouseY) {

@Override
public boolean keyPressed(int key, int scancode, int modifiers) {
setMouse(lastMouseX, lastMouseY);
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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 mouseMoved() method is broken or only works on drag or something. Before adding this it would only update the mouse coords after clicking on something and moving the map around

int dx = 0, dz = 0;

if( isKeyUp (key) ){ dz -= 16; }
Expand Down