Skip to content

Commit

Permalink
为loc、here、whereis添加主世界/下界坐标转换
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Oct 28, 2024
1 parent 6f91dec commit be88671
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/main/java/dev/dubhe/gugle/carpet/commands/HereCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ public static int execute(@NotNull CommandContext<CommandSourceStack> context) {
)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(dimension.location().toString())))
);
double scale = 0;
if (dimension == Level.NETHER) {
scale = 8;
} else if (dimension == Level.OVERWORLD) {
scale = 0.125;
}
MutableComponent toPos = Component.literal("[%.2f, %.2f, %.2f]".formatted(position.x * scale, position.y * scale, position.z * scale)).withStyle(
Style.EMPTY
.applyFormat(
dimension == Level.OVERWORLD ?
ChatFormatting.RED :
dimension == Level.NETHER ?
ChatFormatting.GREEN :
ChatFormatting.AQUA
)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(dimension.location().toString())))
);
MutableComponent addMap = Component.literal("[+X]").withStyle(
Style.EMPTY
.applyFormat(ChatFormatting.GREEN)
Expand All @@ -74,8 +91,8 @@ public static int execute(@NotNull CommandContext<CommandSourceStack> context) {
)
))
);
return Component.literal("%s at".formatted(name))
.append(" ").append(pos)
.append(" ").append(addMap);
MutableComponent component = Component.literal("%s at".formatted(name)).append(" ").append(pos);
if (scale > 0) component.append("->").append(toPos);
return component.append(" ").append(addMap);
}
}
23 changes: 21 additions & 2 deletions src/main/java/dev/dubhe/gugle/carpet/commands/LocCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@ public static int list(CommandContext<CommandSourceStack> context) {
)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(locPoint.dimType.location().toString())))
);
double scale = 0;
if (locPoint.dimType == Level.NETHER) {
scale = 8;
} else if (locPoint.dimType == Level.OVERWORLD) {
scale = 0.125;
}
MutableComponent toPos = Component.literal("[%.2f, %.2f, %.2f]".formatted(locPoint.x * scale, locPoint.y * scale, locPoint.z * scale)).withStyle(
Style.EMPTY
.applyFormat(
locPoint.dimType == Level.OVERWORLD ?
ChatFormatting.RED :
locPoint.dimType == Level.NETHER ?
ChatFormatting.GREEN :
ChatFormatting.AQUA
)
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal(locPoint.dimType.location().toString())))
);
MutableComponent addMap = Component.literal("[+X]").withStyle(
Style.EMPTY
.applyFormat(ChatFormatting.GREEN)
Expand All @@ -208,8 +225,10 @@ public static int list(CommandContext<CommandSourceStack> context) {
.applyFormat(ChatFormatting.RED)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/loc remove %s".formatted(locPoint.id)))
);
return Component.literal("▶ ").append(component)
.append(" ").append(pos)
MutableComponent component1 = Component.literal("▶ ").append(component)
.append(" ").append(pos);
if (scale > 0) component1.append("->").append(toPos);
return component1
.append(" ").append(addMap)
.append(" ").append(remove);
}
Expand Down

0 comments on commit be88671

Please sign in to comment.