Skip to content

Commit

Permalink
0.6.18
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Dec 27, 2024
1 parent 8ce5872 commit 74d9580
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod_name=Sign Me Up
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=BSD-3-Clause
# The mod version. See https://semver.org/
mod_version=0.6.17
mod_version=0.6.18
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/org/teacon/signmeup/command/OpCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.teacon.signmeup.command;

import cn.ussshenzhou.t88.config.ConfigHelper;
import cn.ussshenzhou.t88.network.NetworkHelper;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
Expand All @@ -10,18 +11,28 @@
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.coordinates.RotationArgument;
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
import net.minecraft.commands.arguments.coordinates.WorldCoordinates;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.server.ServerLifecycleHooks;
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.teacon.signmeup.command.argument.SpaceBreakStringArgumentType;
import org.teacon.signmeup.config.Map;
import org.teacon.signmeup.config.waypoints.Waypoint;
import org.teacon.signmeup.network.RemoveWaypointPacket;
import org.teacon.signmeup.network.SetWaypointPacket;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -56,9 +67,34 @@ public static void waypoints(CommandDispatcher<CommandSourceStack> dispatcher) {
)).executes(OpCommands::removeWaypoint)
)
)
.then(Commands.literal("tp")
.then(Commands.argument("location", Vec2Argument.vec2())
.executes(OpCommands::teleport)))
);
}

private static int teleport(CommandContext<CommandSourceStack> context) {
Vec3 location = context.getArgument("location", WorldCoordinates.class).getPosition(context.getSource());

if (context.getSource().getEntity() instanceof ServerPlayer player) {
Map map = ConfigHelper.getConfigRead(Map.class);
double x = location.x, z = location.z;
if (!(x >= map.centerWorldX - map.worldSize - 1024) || !(x <= map.centerWorldX + map.worldSize + 1024) ||
!(z >= map.centerWorldZ - map.worldSize - 1024) || !(z <= map.centerWorldZ + map.worldSize + 1024)) {
context.getSource().sendFailure(Component.literal("Cannot teleport to somewhere outside world boundary."));
}

ServerLevel level = Objects.requireNonNull(Objects.requireNonNull(ServerLifecycleHooks.getCurrentServer()).getLevel(Level.OVERWORLD));
player.teleportTo(
level,
location.x, level.getHeight(Heightmap.Types.WORLD_SURFACE_WG, (int) x, (int) z), location.z, Set.of(),
player.getYRot(), player.getXRot()
);
}

return Command.SINGLE_SUCCESS;
}

private static int setWaypoint(CommandContext<CommandSourceStack> context) {
var pos = context.getArgument("pos", WorldCoordinates.class).getPosition(context.getSource());
var name = context.getArgument("name", String.class);
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/org/teacon/signmeup/gui/map/MapPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class MapPanel extends TVerticalAndHorizontalScrollContainer {
private static final ResourceLocation SCROLLER_HORIZONTAL = SignMeUp.id("scrollbar_hori");
private static final Quaternionf QUATERNION = new Quaternionf();

final InnerMapPanel map = new InnerMapPanel();
public final InnerMapPanel map = new InnerMapPanel();

private final TImage me = new TImage(SignMeUp.id("textures/gui/me_map.png")) {
@Override
Expand Down Expand Up @@ -187,20 +187,22 @@ public InnerMapPanel() {
super(SignMeUp.id("textures/gui/map.png"));
}

public Vector2f guiToWorld(int x, int z) {
Map world = ConfigHelper.getConfigRead(Map.class);

return new Vector2f(
(float) ((((double) x - this.getXT()) / this.getWidth() - 0.5) * world.worldSize + world.centerWorldX),
(float) ((((double) z - this.getYT()) / this.getWidth() - 0.5) * world.worldSize + world.centerWorldZ)
);
}

public Vector2i worldToGui(double x, double z) {
var mapCfg = ConfigHelper.getConfigRead(Map.class);
//world center
var pos = new Vector2f(mapCfg.centerWorldX, mapCfg.centerWorldZ);
//world top left
pos.add(-mapCfg.worldSize / 2f, -mapCfg.worldSize / 2f);
//world top left delta
pos.mul(-1).add((float) x, (float) z);
//world top left delta relative
pos.mul(1f / mapCfg.worldSize);
//gui top left delta
pos.mul(this.getWidth());
pos.add(this.getXT(), this.getYT());
return new Vector2i((int) pos.x, (int) pos.y);
Map world = ConfigHelper.getConfigRead(Map.class);

return new Vector2i(
(int) (((x - world.centerWorldX) / world.worldSize + 0.5) * this.getWidth() + this.getXT()),
(int) (((z - world.centerWorldZ) / world.worldSize + 0.5) * this.getWidth() + this.getYT())
);
}
}
}
49 changes: 44 additions & 5 deletions src/main/java/org/teacon/signmeup/gui/map/WayPointsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import cn.ussshenzhou.t88.gui.widegt.TLabel;
import cn.ussshenzhou.t88.gui.widegt.TPanel;
import cn.ussshenzhou.t88.network.NetworkHelper;
import com.mojang.brigadier.tree.CommandNode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import org.joml.Vector2f;
import org.joml.Vector2i;
import org.teacon.signmeup.SignMeUp;
import org.teacon.signmeup.config.waypoints.Waypoint;
import org.teacon.signmeup.network.TeleportToWayPointPacket;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -84,6 +84,40 @@ public void update(MapPanel.InnerMapPanel map) {
}
}

private long lastClickedTime = 0;

@Override
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
if (super.mouseClicked(pMouseX, pMouseY, pButton)) {
return true;
}

if (this.isInRange(pMouseX, pMouseY)) {
long time = System.currentTimeMillis();
if (time - lastClickedTime <= 200) {
lastClickedTime = 0;

Minecraft mc = Minecraft.getInstance();
if (mc.player != null) {
CommandNode<SharedSuggestionProvider> node = mc.player.connection.commands.findNode(List.of("smu", "tp"));
if (node != null) {
MapPanel map = getParentInstanceOf(MapPanel.class);
if (map != null) {
Vector2f pos = map.map.guiToWorld((int) pMouseX, (int) pMouseY);
mc.player.connection.sendCommand(String.format("smu tp %f %f", pos.x, pos.y));
getTopParentScreenOptional().ifPresent(tScreen -> tScreen.onClose(false));
return true;
}
}
}
} else {
lastClickedTime = time;
}
}

return false;
}

private int distance2(Waypoint left, Waypoint right, MapPanel.InnerMapPanel map) {
return (int) map.worldToGui(right.pos().x, right.pos().z).distanceSquared(map.worldToGui(left.pos().x, left.pos().z));
}
Expand All @@ -108,7 +142,7 @@ public SingleVisualWaypoint(MapPanel.InnerMapPanel map, Waypoint waypoint) {
this.waypoint = waypoint;
this.waypoints = Set.of(waypoint);

setTooltip(Tooltip.create(Component.translatable("gui.sign_up.map.teleport", waypoint.name())));
setTooltip(Tooltip.create(Component.translatable("gui.sign_up.map.teleport", waypoint.name(), waypoint.description())));

Vector2i pos = map.worldToGui(waypoint.pos().x(), waypoint.pos().z());
setAbsBounds(pos.x - DOT_SIZE / 2, pos.y - DOT_SIZE / 2, DOT_SIZE, DOT_SIZE);
Expand All @@ -121,6 +155,11 @@ public Set<Waypoint> getWaypoints() {

private long lastClickedTime = 0;

@Override
public void mouseMoved(double mouseX, double mouseY) {
super.mouseMoved(mouseX, mouseY);
}

@Override
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
if (this.isInRange(pMouseX, pMouseY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import cn.ussshenzhou.t88.network.annotation.ServerHandler;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.teacon.signmeup.SignMeUp;
import org.teacon.signmeup.config.waypoints.Waypoint;
Expand All @@ -31,7 +31,7 @@ public record TeleportToWayPointPacket(UUID id) {
public void serverHandler(IPayloadContext context) {
context.enqueueWork(() -> {
var player = context.player();
if (!(player.level() instanceof ServerLevel level)) {
if (!(player.level() instanceof ServerLevel level) || level.dimension() != Level .OVERWORLD) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/sign_up/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"gui.sign_up.minimap.refresh.another": "Every 2 Frames",
"gui.sign_up.minimap.refresh.tick": "Every Tick",
"gui.sign_up.minimap.refresh.tick20": "Every 20 Ticks",
"gui.sign_up.map.teleport": "%s\n[Double click to teleport]",
"gui.sign_up.map.teleport": "%s\n%s\n[Double click to teleport]",

"hud.sign_up.minimap.hide": "Minimap is hided by: %s"
}
2 changes: 1 addition & 1 deletion src/main/resources/assets/sign_up/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"gui.sign_up.minimap.refresh.another": "每2帧",
"gui.sign_up.minimap.refresh.tick": "每刻",
"gui.sign_up.minimap.refresh.tick20": "每20刻",
"gui.sign_up.map.teleport": "%s\n[双击来传送]",
"gui.sign_up.map.teleport": "%s\n%s\n[双击来传送]",

"hud.sign_up.minimap.hide": "小地图被以下模组隐藏:%s"
}

0 comments on commit 74d9580

Please sign in to comment.