Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -8,30 +8,48 @@
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;
Expand Down Expand Up @@ -63,6 +81,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"),
Expand Down Expand Up @@ -116,7 +135,7 @@ 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<>();
Expand Down Expand Up @@ -215,6 +234,12 @@ public boolean keyPressed(int key, int scancode, int modifiers) {
return true;
}

if(key == BlazeMapFeaturesClient.KEY_WAYPOINTS.getKey().getValue()) {
var position = getCursorBlockPos();
new WaypointEditorFragment(position).open();
return true;
}

return false;
}

Expand All @@ -230,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;
}
}
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