From e3b3a53777991365b3dc71090f118187dcde03d2 Mon Sep 17 00:00:00 2001 From: Hendrix-Shen Date: Tue, 24 Oct 2023 14:28:23 +0800 Subject: [PATCH] New feature quickTeleport --- gradle.properties | 2 +- .../java/com/plusls/xma/config/Configs.java | 14 ++++- .../com/plusls/xma/mixin/AccessorGuiMap.java | 24 ++++++++ .../com/plusls/xma/mixin/MixinGuiMap.java | 1 - .../plusls/xma/util/QuickTeleportUtil.java | 56 +++++++++++++++++++ .../assets/xaero_map_addition/lang/en_us.json | 4 ++ .../assets/xaero_map_addition/lang/zh_cn.json | 4 ++ .../resources/xaero_map_addition.mixins.json | 1 + 8 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/plusls/xma/mixin/AccessorGuiMap.java create mode 100644 src/main/java/com/plusls/xma/util/QuickTeleportUtil.java diff --git a/gradle.properties b/gradle.properties index f4800e7..76f4901 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ magiclib_dependency=0.7.387 magiclib_version=0.7.387 # Oh My Minecraft Client ommc_dependency=0.5.319 -ommc_version=nyan-work~dev.41 +ommc_version=nyan-work~dev.43 # Annotation processor lombok_version=1.18.30 \ No newline at end of file diff --git a/src/main/java/com/plusls/xma/config/Configs.java b/src/main/java/com/plusls/xma/config/Configs.java index 30120ce..ff084fd 100644 --- a/src/main/java/com/plusls/xma/config/Configs.java +++ b/src/main/java/com/plusls/xma/config/Configs.java @@ -2,7 +2,9 @@ import com.plusls.xma.ModInfo; import com.plusls.xma.gui.GuiConfigs; +import com.plusls.xma.util.QuickTeleportUtil; import fi.dy.masa.malilib.config.options.ConfigHotkey; +import fi.dy.masa.malilib.hotkeys.KeybindSettings; import net.minecraft.client.Minecraft; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.config.Configurator; @@ -33,6 +35,12 @@ public class Configs { @Dependency("xaerominimap"), @Dependency("xaerobetterpvp")})) public static boolean minimapHighlightWaypoint = true; + @Config(category = ConfigCategory.XAERO_WORLD_MAP, dependencies = @Dependencies(and = @Dependency("xaeroworldmap"))) + public static boolean closeMapAfterQuickTeleport; + + @Hotkey(hotkey = "T") + @Config(category = ConfigCategory.XAERO_WORLD_MAP, dependencies = @Dependencies(and = @Dependency("xaeroworldmap"))) + public static ConfigHotkey quickTeleport; @Config(category = ConfigCategory.XAERO_WORLD_MAP, dependencies = @Dependencies(and = @Dependency("xaeroworldmap"))) public static boolean worldMapHighlightWaypoint = true; @@ -49,12 +57,16 @@ public static void init(@NotNull ConfigManager cm) { return true; }); + quickTeleport.getKeybind().setSettings(KeybindSettings.GUI); + quickTeleport.getKeybind().setCallback(QuickTeleportUtil::teleport); + cm.setValueChangeCallback("debug", option -> { Configurator.setLevel(ModInfo.getModIdentifier(), debug ? Level.DEBUG : Level.INFO); GuiConfigs.getInstance().reDraw(); }); + if (debug) { - Configurator.setLevel(ModInfo.getModIdentifier(), Level.toLevel("DEBUG")); + Configurator.setLevel(ModInfo.getModIdentifier(), Level.DEBUG); } } diff --git a/src/main/java/com/plusls/xma/mixin/AccessorGuiMap.java b/src/main/java/com/plusls/xma/mixin/AccessorGuiMap.java new file mode 100644 index 0000000..07ad5d6 --- /dev/null +++ b/src/main/java/com/plusls/xma/mixin/AccessorGuiMap.java @@ -0,0 +1,24 @@ +package com.plusls.xma.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies; +import top.hendrixshen.magiclib.dependency.api.annotation.Dependency; +import xaero.map.MapProcessor; +import xaero.map.gui.GuiMap; + +@Dependencies(and = @Dependency("xaeroworldmap")) +@Mixin(value = GuiMap.class, remap = false) +public interface AccessorGuiMap { + @Accessor + int getMouseBlockPosX(); + + @Accessor + int getMouseBlockPosY(); + + @Accessor + int getMouseBlockPosZ(); + + @Accessor + MapProcessor getMapProcessor(); +} diff --git a/src/main/java/com/plusls/xma/mixin/MixinGuiMap.java b/src/main/java/com/plusls/xma/mixin/MixinGuiMap.java index cd8eace..d785bec 100644 --- a/src/main/java/com/plusls/xma/mixin/MixinGuiMap.java +++ b/src/main/java/com/plusls/xma/mixin/MixinGuiMap.java @@ -33,7 +33,6 @@ @Dependencies(and = @Dependency("xaeroworldmap")) @Mixin(value = GuiMap.class, remap = false) public abstract class MixinGuiMap extends ScreenBase implements IRightClickableElement { - @Shadow private int rightClickX; @Shadow diff --git a/src/main/java/com/plusls/xma/util/QuickTeleportUtil.java b/src/main/java/com/plusls/xma/util/QuickTeleportUtil.java new file mode 100644 index 0000000..00738d6 --- /dev/null +++ b/src/main/java/com/plusls/xma/util/QuickTeleportUtil.java @@ -0,0 +1,56 @@ +package com.plusls.xma.util; + +import com.plusls.xma.config.Configs; +import com.plusls.xma.mixin.AccessorGuiMap; +import fi.dy.masa.malilib.hotkeys.IKeybind; +import fi.dy.masa.malilib.hotkeys.KeyAction; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.sounds.SoundEvents; +import top.hendrixshen.magiclib.util.InfoUtil; +import xaero.map.gui.GuiMap; +import xaero.map.world.MapDimension; + +public class QuickTeleportUtil { + public static boolean teleport(KeyAction keyAction, IKeybind iKeybind) { + if (!(Minecraft.getInstance().screen instanceof GuiMap)) { + return false; + } + + GuiMap guiMap = ((GuiMap) Minecraft.getInstance().screen); + MapDimension currentDimension = ((AccessorGuiMap) guiMap).getMapProcessor().getMapWorld().getCurrentDimension(); + + // Disable teleport feature in survival or current world un-writeable. + if (Minecraft.getInstance().gameMode == null || Minecraft.getInstance().gameMode.canHurtPlayer() + || currentDimension == null || !currentDimension.currentMultiworldWritable + ) { + return false; + } + + int mouseBlockPosX = ((AccessorGuiMap) guiMap).getMouseBlockPosX(); + int mouseBlockPosY = ((AccessorGuiMap) guiMap).getMouseBlockPosY(); + int mouseBlockPosZ = ((AccessorGuiMap) guiMap).getMouseBlockPosZ(); + + // Disable teleport feature if xaero map denied or mouseBlockPos cannot get. + if ( + //#if MC > 11502 + !((AccessorGuiMap) guiMap).getMapProcessor().getMapWorld().isTeleportAllowed() || + //#endif + mouseBlockPosY == 32767 + ) { + return false; + } + + InfoUtil.sendCommand(String.format("tp @s %s %s %s", mouseBlockPosX, Minecraft.getInstance().player == null ? + mouseBlockPosY : Minecraft.getInstance().player.getBlockYCompat(), mouseBlockPosZ)); + Minecraft.getInstance().getSoundManager() + .play(SimpleSoundInstance.forUI(SoundEvents.CHORUS_FRUIT_TELEPORT, 1.0F)); + + if (Configs.closeMapAfterQuickTeleport) { + guiMap.onClose(); + return true; + } + + return false; + } +} diff --git a/src/main/resources/assets/xaero_map_addition/lang/en_us.json b/src/main/resources/assets/xaero_map_addition/lang/en_us.json index 0b411ee..083c054 100644 --- a/src/main/resources/assets/xaero_map_addition/lang/en_us.json +++ b/src/main/resources/assets/xaero_map_addition/lang/en_us.json @@ -13,6 +13,10 @@ "xaero_map_addition.config.xaerominimap.directDeleteButton.comment": "Add direct delete button in waypoints GUI.", "xaero_map_addition.config.xaerominimap.minimapHighlightWaypoint.name": "minimapHighlightWaypoint", "xaero_map_addition.config.xaerominimap.minimapHighlightWaypoint.comment": "Make minimap support highlight waypoint.", + "xaero_map_addition.config.xaeroworldmap.closeMapAfterQuickTeleport.name": "closeMapAfterQuickTeleport", + "xaero_map_addition.config.xaeroworldmap.closeMapAfterQuickTeleport.comment": "Turn off xaero world map after triggering quickTeleport", + "xaero_map_addition.config.xaeroworldmap.quickTeleport.name": "quickTeleport", + "xaero_map_addition.config.xaeroworldmap.quickTeleport.comment": "Press the hotkey in xaero world map to quickly teleport to location pointed by mouse.", "xaero_map_addition.config.xaeroworldmap.worldMapHighlightWaypoint.name": "worldMapHighlightWaypoint", "xaero_map_addition.config.xaeroworldmap.worldMapHighlightWaypoint.comment": "Make world map support highlight waypoint.", "xaero_map_addition.gui.xaero_right_click_map_highlight_location": "Highlight location", diff --git a/src/main/resources/assets/xaero_map_addition/lang/zh_cn.json b/src/main/resources/assets/xaero_map_addition/lang/zh_cn.json index 96b1492..f16808a 100644 --- a/src/main/resources/assets/xaero_map_addition/lang/zh_cn.json +++ b/src/main/resources/assets/xaero_map_addition/lang/zh_cn.json @@ -13,6 +13,10 @@ "xaero_map_addition.config.xaerominimap.directDeleteButton.comment": "在路径点管理的界面添加一个直接删除的按钮", "xaero_map_addition.config.xaerominimap.minimapHighlightWaypoint.name": "小地图支持高亮路径点", "xaero_map_addition.config.xaerominimap.minimapHighlightWaypoint.comment": "让小地图支持高亮路径点", + "xaero_map_addition.config.xaeroworldmap.closeMapAfterQuickTeleport.name": "快速传送后关闭世界地图", + "xaero_map_addition.config.xaeroworldmap.closeMapAfterQuickTeleport.comment": "触发 快速传送 后关闭 Xaero世界地图", + "xaero_map_addition.config.xaeroworldmap.quickTeleport.name": "快速传送", + "xaero_map_addition.config.xaeroworldmap.quickTeleport.comment": "在 Xaero世界地图 中按下快捷键快速传送至鼠标指向位置", "xaero_map_addition.config.xaeroworldmap.worldMapHighlightWaypoint.name": "世界地图支持高亮路径点", "xaero_map_addition.config.xaeroworldmap.worldMapHighlightWaypoint.comment": "让世界地图支持高亮路径点", "xaero_map_addition.gui.xaero_right_click_map_highlight_location": "高亮位置", diff --git a/src/main/resources/xaero_map_addition.mixins.json b/src/main/resources/xaero_map_addition.mixins.json index f8b9324..13c232a 100644 --- a/src/main/resources/xaero_map_addition.mixins.json +++ b/src/main/resources/xaero_map_addition.mixins.json @@ -6,6 +6,7 @@ "plugin": "top.hendrixshen.magiclib.dependency.impl.MagicMixinPlugin", "client": [ "AccessorClientboundChatPacket", + "AccessorGuiMap", "MixinGuiMap", "MixinGuiWaypoints", "MixinGuiWaypoints_List",