Skip to content

Commit

Permalink
Feature: Use '#' as a waypoint name prefix to specific prinary waypoi…
Browse files Browse the repository at this point in the history
…nts. Fix: waypoint facing. Bump to 0.6.2
  • Loading branch information
burningtnt committed Dec 12, 2024
1 parent e0001a7 commit 5b15ed7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 30 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.0
mod_version=0.6.2
# 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
18 changes: 9 additions & 9 deletions run/config/SignMeUp/Waypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
"rx": 0.0,
"ry": 0.0
},
{
"name": "主展馆",
"description": "",
"x": -127,
"y": 96,
"z": 40,
"rx": 0.0,
"ry": 0.0
},
{
"name": "111",
"description": "222",
Expand All @@ -35,6 +26,15 @@
"z": 40,
"rx": 0.0,
"ry": 0.0
},
{
"name": "#主展馆",
"description": "描述内容",
"x": -130,
"y": 74,
"z": 28,
"rx": 9.150063,
"ry": 53.999992
}
]
}
7 changes: 2 additions & 5 deletions src/main/java/org/teacon/signmeup/command/OpCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public static void waypoints(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(Commands.argument("rotation", RotationArgument.rotation())
.then(Commands.argument("name", StringArgumentType.string())
.executes(OpCommands::setWaypoint)
.then(Commands.argument("description", StringArgumentType.string())
.executes(OpCommands::setWaypoint)
)
)
)
)
Expand All @@ -56,15 +53,15 @@ private static int setWaypoint(CommandContext<CommandSourceStack> context) {
var name = context.getArgument("name", String.class);
var description = context.getArgument("description", String.class);
var rotation = context.getArgument("rotation", WorldCoordinates.class).getRotation(context.getSource());
var waypoint = new Waypoints.WayPoint(name, description, pos.getX(), pos.getY(), pos.getZ(), rotation.x, rotation.y);
var waypoint = new Waypoints.WayPoint(name, description, pos.getX(), pos.getY(), pos.getZ(), rotation.y, rotation.x);

ConfigHelper.getConfigWrite(Waypoints.class, waypoints -> {
waypoints.waypoints.stream().filter(w -> w.name.equals(waypoint.name)).findFirst().ifPresentOrElse(
point -> context.getSource().sendSuccess(() -> Component.literal("[" + point + "] already exists. Remove it first if you want to replace it."), true),
() -> {
context.getSource().sendSuccess(() -> Component.literal("Added " + waypoint), true);
waypoints.waypoints.add(waypoint);
NetworkHelper.sendToAllPlayers(new SetWaypointPacket(name, description, pos, new Rotations(rotation.x, 0, rotation.y)));
NetworkHelper.sendToAllPlayers(new SetWaypointPacket(name, description, pos, new Rotations(rotation.y, 0, rotation.x)));
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public String getChildDirName() {

public ArrayList<Command> playerCommands = new ArrayList<>();

public static class Command{
public static class Command {
public String title = "";
public String tooltip = "";
public ArrayList<String> commands = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,77 @@
import cn.ussshenzhou.t88.gui.advanced.THoverSensitiveImageButton;
import cn.ussshenzhou.t88.gui.widegt.TWidget;
import cn.ussshenzhou.t88.network.NetworkHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import org.teacon.signmeup.SignMeUp;
import org.teacon.signmeup.config.Waypoints;
import org.teacon.signmeup.gui.map.ButtonPanelBase;
import org.teacon.signmeup.network.TeleportToWayPointPacket;

import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
* @author USS_Shenzhou
*/
public class WayPointsButtonPanel extends ButtonPanelBase {
private static final class THoverSensitiveImageButtonImpl extends THoverSensitiveImageButton {
private final String waypointName;

public THoverSensitiveImageButtonImpl(String waypointName, Button.OnPress onPress, @Nullable ResourceLocation backgroundImageLocation, @Nullable ResourceLocation backgroundImageLocationHovered) {
super(
Component.literal(waypointName.startsWith("#") ? waypointName.substring(1) : waypointName),
onPress, backgroundImageLocation, backgroundImageLocationHovered
);
this.waypointName = waypointName;
}
}


public WayPointsButtonPanel() {
super(true);
ConfigHelper.getConfigRead(Waypoints.class).waypoints.forEach(wayPoint -> {
var button = new THoverSensitiveImageButton(
Component.literal(wayPoint.name),
Waypoints.WayPoint[] waypoints = ConfigHelper.getConfigRead(Waypoints.class).waypoints.toArray(Waypoints.WayPoint[]::new);

int staticWP = 0;
for (int i = 0; i < waypoints.length; i++) {
Waypoints.WayPoint item = waypoints[i];
if (item.name.startsWith("#")) {
waypoints[i] = waypoints[staticWP];
waypoints[staticWP] = item;
staticWP++;
}
}

UUID uuid = Minecraft.getInstance().getUser().getProfileId();
Random random = new Random(uuid.getLeastSignificantBits() ^ uuid.getMostSignificantBits());
for (int i = waypoints.length; i > staticWP + 1; --i) {
int k1 = random.nextInt(i - staticWP) + staticWP, k2 = i - 1;
Waypoints.WayPoint t = waypoints[k2];
waypoints[k2] = waypoints[k1];
waypoints[k1] = t;
}

for (Waypoints.WayPoint wayPoint : waypoints) {
var button = new THoverSensitiveImageButtonImpl(
wayPoint.name,
b -> {
NetworkHelper.sendToServer(new TeleportToWayPointPacket(wayPoint.name));
getTopParentScreenOptional().ifPresent(tScreen -> tScreen.onClose(false));
},
SignMeUp.id( "textures/gui/button_panel_button.png"),
SignMeUp.id( "textures/gui/button_panel_button_hovered.png")
SignMeUp.id("textures/gui/button_panel_button.png"),
SignMeUp.id("textures/gui/button_panel_button_hovered.png")
);
button.setPadding(0);
button.setTooltip(Tooltip.create(Component.literal(wayPoint.description)));
this.buttons.add(button);
});
}
}

public void highlight(List<Waypoints.WayPoint> highlightWaypoints) {
Expand All @@ -50,7 +89,7 @@ public void highlight(List<Waypoints.WayPoint> highlightWaypoints) {

Set<String> lookup = highlightWaypoints.stream().map(w -> w.name).collect(Collectors.toSet());
for (TWidget child : this.buttons.getChildren()) {
if (!(child instanceof THoverSensitiveImageButton btn)) {
if (!(child instanceof THoverSensitiveImageButtonImpl btn)) {
continue;
}
btn.getButton().setFocused(lookup.contains(btn.getText().getText().getString()));
Expand All @@ -59,9 +98,9 @@ public void highlight(List<Waypoints.WayPoint> highlightWaypoints) {

public String getHighlightWaypoints() {
for (TWidget child : this.buttons.getChildren()) {
if (child instanceof THoverSensitiveImageButton btn) {
if (child instanceof THoverSensitiveImageButtonImpl btn) {
if (btn.getButton().isHovered()) {
return btn.getText().getText().getString();
return btn.waypointName;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/teacon/signmeup/hud/MiniMapAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String getHiderString() {
return m1 + ", " + m2 + ", ... (" + size + " more mods)";
} else if (size == 1) {
return m1 + ", " + m2 + ", ... (1 more mod)";
}else {
} else {
return m1 + ", " + m2;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/teacon/signmeup/input/ModKeyInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ public class ModKeyInput {

@SubscribeEvent
public static void onKeyInput(InputEvent.Key event) {
MapScreen screen;
if (OPEN_NEW_MAP.consumeClick()) {
Minecraft.getInstance().setScreen(MapScreen.getNewInstance());
}
if (OPEN_MAP.consumeClick()) {
Minecraft.getInstance().setScreen(MapScreen.getInstance());
screen = MapScreen.getNewInstance();
} else if (OPEN_MAP.consumeClick()) {
screen = MapScreen.getInstance();
} else {
return;
}
screen.layout();
Minecraft.getInstance().setScreen(screen);
}
}

0 comments on commit 5b15ed7

Please sign in to comment.