Skip to content

Commit

Permalink
New feature quickTeleport
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrix-Shen committed Oct 24, 2023
1 parent ccf1637 commit e3b3a53
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 13 additions & 1 deletion src/main/java/com/plusls/xma/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/plusls/xma/mixin/AccessorGuiMap.java
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 0 additions & 1 deletion src/main/java/com/plusls/xma/mixin/MixinGuiMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/plusls/xma/util/QuickTeleportUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/xaero_map_addition/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/xaero_map_addition/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "高亮位置",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/xaero_map_addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"plugin": "top.hendrixshen.magiclib.dependency.impl.MagicMixinPlugin",
"client": [
"AccessorClientboundChatPacket",
"AccessorGuiMap",
"MixinGuiMap",
"MixinGuiWaypoints",
"MixinGuiWaypoints_List",
Expand Down

0 comments on commit e3b3a53

Please sign in to comment.