From da6802f60584fc013a75514ca573dd8cc9af71d1 Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Thu, 5 Dec 2024 16:00:25 +0800 Subject: [PATCH] =?UTF-8?q?0.3.5=20=E9=80=82=E9=85=8DMinecraft=201.21.4=20?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E4=B8=80=E4=B8=AA=E4=B8=A5=E9=87=8D?= =?UTF-8?q?Bug=EF=BC=8C=E5=90=8C=E6=A0=B7=E6=98=AF=E7=94=B10.3.3=E7=9A=84V?= =?UTF-8?q?ec3d=20=E2=86=92=20Vec2f=E5=BC=95=E5=85=A5=E3=80=82=20=E5=85=B7?= =?UTF-8?q?=E4=BD=93=E8=A1=A8=E7=8E=B0=E5=B0=B1=E6=98=AF=E5=BD=93=E4=BC=A0?= =?UTF-8?q?=E9=80=81=E4=B8=AD=E5=BF=83=E8=A2=AB=E8=AE=BE=E7=BD=AE=E4=B8=BA?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AE=9E=E4=BD=93=E6=97=B6=EF=BC=8C=E4=BC=A0?= =?UTF-8?q?=E9=80=81=E4=B8=AD=E5=BF=83=E7=82=B9=E7=9A=84Z=E8=BD=B4?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E8=A2=AB=E9=94=99=E8=AF=AF=E5=9C=B0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BA=E7=BB=99=E5=AE=9A=E5=AE=9E=E4=BD=93=E7=9A=84?= =?UTF-8?q?Y=E8=BD=B4=EF=BC=88=E8=A1=A8=E7=A4=BA=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E7=9A=84=E9=82=A3=E4=B8=AA=E8=BD=B4=EF=BC=89=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E3=80=82=20=E5=8F=AF=E8=83=BD=E6=98=AF=E6=88=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=9A=84=E6=97=B6=E5=80=99=E6=B2=A1=E7=94=A8=E5=88=B0?= =?UTF-8?q?=E8=BF=99=E4=B8=AA=E6=A0=BC=E5=BC=8F=E6=89=80=E4=BB=A5=E6=B2=A1?= =?UTF-8?q?=E5=8F=91=E7=8E=B0=E9=97=AE=E9=A2=98=EF=BC=9F=E5=8F=8D=E6=AD=A3?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=BF=AE=E4=BA=86=EF=BC=8C=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E6=B2=A1=E4=BA=8B=E4=BA=86=E3=80=82=20=E6=9B=B4=E6=8D=A2Text.t?= =?UTF-8?q?ranslatable=E6=88=90Text.translatableWithFallback=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E6=9C=AA=E5=AE=89=E8=A3=85=E6=A8=A1=E7=BB=84?= =?UTF-8?q?=E6=97=B6=E8=87=B3=E5=B0=91=E6=9C=89=E4=BA=BA=E7=B1=BB=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=96=87=E5=AD=97=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E9=94=AE=E3=80=82=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E8=8B=B1=E8=AF=AD=E7=BF=BB=E8=AF=91=E3=80=82=20ModMenu?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E8=AF=A6=E7=BB=86=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E4=B8=AD=E7=A7=BB=E9=99=A4=E6=8E=89=E5=8D=9A=E5=AE=A2=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E3=80=82=20=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E5=A4=A7=E5=A0=86=E7=9A=84JavaDoc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- build.gradle.kts | 2 +- gradle.properties | 12 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../xyz/thewhitedog9487/CommandRegister.java | 64 ++++++++++++++++--- .../xyz/thewhitedog9487/RandomTeleporter.java | 5 +- .../assets/randomteleporter/lang/en_us.json | 5 +- .../assets/randomteleporter/lang/zh_cn.json | 5 +- src/main/resources/fabric.mod.json | 9 ++- 9 files changed, 78 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 24f3cb6..c8317aa 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,8 @@ 1. 服务器需要安装 2. 客户端不需要 -**注意:情况2和3,虽然其他玩家不需要安装本模组就能使用功能。但是由于命令执行后的反馈结果文字使用了翻译,如果其他玩家没有安装模组会导致显示不正常,玩家会直接看到翻译键而不是对应的文字。 -因此,虽然可以但不建议其他人不安装。 -能安装的话还是都装一下吧。** +**注意:情况2和3,如果其他玩家不安装本模组,他们看到的命令执行反馈就无法正确使用翻译,而在这种情况下默认显示中文文本。 +如果有查看多语言翻译文本的需求 ,那建议还是都装一下吧。** # 一些小彩蛋 你可以使用 /随机传送 来替代 /rtp diff --git a/build.gradle.kts b/build.gradle.kts index 8532aeb..a56e42a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("fabric-loom") version "1.8-SNAPSHOT" + id("fabric-loom") version "1.9-SNAPSHOT" id("maven-publish") } diff --git a/gradle.properties b/gradle.properties index 24019ac..bec2381 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,21 +4,21 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.3 -yarn_mappings=1.21.3+build.2 -loader_version=0.16.7 +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.1 +loader_version=0.16.9 # Mod Properties -mod_version=0.3.4 +mod_version=0.3.5 maven_group=xyz.thewhitedog9487 archives_base_name=RandomTeleporter # Dependencies -fabric_version=0.106.1+1.21.3 +fabric_version=0.110.5+1.21.4 # https://modrinth.com/mod/modmenu/versions # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu -modmenu_version=12.0.0-beta.1 +modmenu_version=13.0.0-beta.1 # loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ # loom_resources_base=https://bmclapi2.bangbang93.com/assets/ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5fd121c..b6d150f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index 8d6892c..01e8701 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -19,11 +19,30 @@ import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class CommandRegister { + + /** + * 世界边界 + *
+ * @see Minecraft Wiki (中文) + * @see Minecraft Wiki (English) + */ final static Integer WorldBorder = (int) 2.9e7; - // ↑ - // https://zh.minecraft.wiki/w/%E4%B8%96%E7%95%8C%E8%BE%B9%E7%95%8C#%E5%A4%A7%E5%B0%8F - // https://minecraft.wiki/w/World_border#General_information + + /** + * 执行命令所需权限等级 + * @see net.minecraft.server.command.TeleportCommand + */ final static byte PermissionLevel = 2; + + /** + * 使用Fabric API向游戏内注册命令 + * @param Name 根命令名 + *
+ * @see Fabric Wiki (新样式,中文) + * @see Fabric Wiki (旧样式,中文) + * @see Fabric Wiki (New style,English) + * @see Fabric Wiki (Old style,English) + */ public static void Register(String Name){ // /rtp CommandRegistrationCallback.EVENT @@ -95,6 +114,7 @@ public class CommandRegister { // LongArgumentType.getLong(context, "Radius(半径)"), // null, // EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));}); + // /rtp CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { @@ -121,7 +141,7 @@ public class CommandRegister { IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, - (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); + (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT @@ -150,7 +170,7 @@ public class CommandRegister { IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, - (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); + (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT @@ -166,13 +186,37 @@ public class CommandRegister { EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});} + /** + * 向游戏内注册命令 + *
+ * 是 {@link CommandRegister#Register(String)} 的包装器 + * @see CommandRegister#Register(String) + */ public static void Register(){ Register("随机传送"); - Register("rtp");} + Register("rtp"); + } + + /** + * + * @param Source 命令执行者 + * @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离 + * @param Player 被传送的玩家 + * @param Origin 随机选择的目的坐标的中心 + * @return 命令运行是否成功 + */ static int execute_command(ServerCommandSource Source, @Nullable Integer Radius, @Nullable Entity Player, @Nullable Vec2f Origin){ Entity entity = Player == null ? Source.getPlayer() : Player; + /* + ↑ + Entity entity = null; + if (Player == null){ + entity = Source.getPlayer();} + else{ + entity = Player;} + */ if (entity == null) { - Source.sendFeedback(()->{ return Text.translatable("error.not_player"); }, true); + Source.sendFeedback(()->{ return Text.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true); return -1;} if (Radius == null){Radius = (int) (WorldBorder - 1e4);} // ↑ 远离世界边界 @@ -211,6 +255,8 @@ public class CommandRegister { // ↑ 高一层,人别站在土里了 entity.teleport(Source.getWorld(),Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), entity.getYaw(), entity.getPitch(), false); int finalCoordinate_Y = Coordinate_Y; - Source.sendFeedback(()->{ return Text.translatable("info.success", entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true); - return 0;} + // ↑ "lambda 表达式中使用的变量应为 final 或有效 final" + final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", entity.getName().getString(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); + Source.sendFeedback(()->{ return Text.translatableWithFallback("info.success", FeedbackFallbackString, entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true); + return 16;} } \ No newline at end of file diff --git a/src/main/java/xyz/thewhitedog9487/RandomTeleporter.java b/src/main/java/xyz/thewhitedog9487/RandomTeleporter.java index 1dca3d3..572b774 100644 --- a/src/main/java/xyz/thewhitedog9487/RandomTeleporter.java +++ b/src/main/java/xyz/thewhitedog9487/RandomTeleporter.java @@ -16,7 +16,10 @@ public class RandomTeleporter implements ModInitializer { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. - CommandRegister.Register(); LOGGER.info("RandomTeleporter Loading!"); + + CommandRegister.Register(); + + LOGGER.info("RandomTeleporter Loaded!"); } } \ No newline at end of file diff --git a/src/main/resources/assets/randomteleporter/lang/en_us.json b/src/main/resources/assets/randomteleporter/lang/en_us.json index 0abd4b5..ff5ae8a 100644 --- a/src/main/resources/assets/randomteleporter/lang/en_us.json +++ b/src/main/resources/assets/randomteleporter/lang/en_us.json @@ -1,6 +1,7 @@ { "modmenu.nameTranslation.randomteleporter": "RandomTeleporter", "modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation", - "bilibili": "Bilibili", - "blog": "Blog" + "info.success": "Teleported %s to %d %d %d", + "error.no_target": "There is no teleported target, and the teleported player ID is explicitly specified when executed by a non-player object", + "bilibili": "Bilibili" } \ No newline at end of file diff --git a/src/main/resources/assets/randomteleporter/lang/zh_cn.json b/src/main/resources/assets/randomteleporter/lang/zh_cn.json index ccd77ac..df31470 100644 --- a/src/main/resources/assets/randomteleporter/lang/zh_cn.json +++ b/src/main/resources/assets/randomteleporter/lang/zh_cn.json @@ -2,7 +2,6 @@ "modmenu.nameTranslation.randomteleporter": "随机传送", "modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令", "info.success": "已将玩家%s传送到%d %d %d", - "error.not_player": "执行命令的不是玩家", - "bilibili": "TheWhiteDog9487的哔哩哔哩主页", - "blog": "TheWhiteDog9487的博客" + "error.no_target": "不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID", + "bilibili": "TheWhiteDog9487的哔哩哔哩主页" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 74017ae..be1174c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,10 +27,10 @@ } ], "depends": { - "fabricloader": ">=0.16.7", - "minecraft": "1.21.3", + "fabricloader": ">=0.16.9", + "minecraft": "1.21.4", "java": ">=21", - "fabric-api": "*" + "fabric-api": ">=0.110.5" }, "suggests": { "another-mod": "*" @@ -38,7 +38,6 @@ "custom": { "modmenu": { "links": { - "bilibili": "https://space.bilibili.com/401746666", - "blog": "www.thewhitedog9487.xyz"}, + "bilibili": "https://space.bilibili.com/401746666"}, "update_checker": true}} } \ No newline at end of file