适配Minecraft 1.21.4
修正了一个严重Bug,同样是由0.3.3的Vec3d → Vec2f引入。
具体表现就是当传送中心被设置为一个实体时,传送中心点的Z轴坐标被错误地设置为给定实体的Y轴(表示高度的那个轴)坐标。
可能是我测试的时候没用到这个格式所以没发现问题?反正现在修了,已经没事了。
更换Text.translatable成Text.translatableWithFallback,确保未安装模组时至少有人类可读文字,而不是翻译键。
补充英语翻译。
ModMenu显示的详细信息中移除掉博客链接。
增加了一大堆的JavaDoc.
This commit is contained in:
TheWhiteDog9487 2024-12-05 16:00:25 +08:00
parent 7376393f37
commit da6802f605
9 changed files with 78 additions and 31 deletions

View File

@ -71,9 +71,8 @@
1. 服务器需要安装 1. 服务器需要安装
2. 客户端不需要 2. 客户端不需要
**注意情况2和3虽然其他玩家不需要安装本模组就能使用功能。但是由于命令执行后的反馈结果文字使用了翻译如果其他玩家没有安装模组会导致显示不正常玩家会直接看到翻译键而不是对应的文字。 **注意情况2和3如果其他玩家不安装本模组他们看到的命令执行反馈就无法正确使用翻译而在这种情况下默认显示中文文本。
因此,虽然可以但不建议其他人不安装。 如果有查看多语言翻译文本的需求 ,那建议还是都装一下吧。**
能安装的话还是都装一下吧。**
# 一些小彩蛋 # 一些小彩蛋
你可以使用 /随机传送 来替代 /rtp 你可以使用 /随机传送 来替代 /rtp

View File

@ -1,5 +1,5 @@
plugins { plugins {
id("fabric-loom") version "1.8-SNAPSHOT" id("fabric-loom") version "1.9-SNAPSHOT"
id("maven-publish") id("maven-publish")
} }

View File

@ -4,21 +4,21 @@ org.gradle.parallel=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
minecraft_version=1.21.3 minecraft_version=1.21.4
yarn_mappings=1.21.3+build.2 yarn_mappings=1.21.4+build.1
loader_version=0.16.7 loader_version=0.16.9
# Mod Properties # Mod Properties
mod_version=0.3.4 mod_version=0.3.5
maven_group=xyz.thewhitedog9487 maven_group=xyz.thewhitedog9487
archives_base_name=RandomTeleporter archives_base_name=RandomTeleporter
# Dependencies # Dependencies
fabric_version=0.106.1+1.21.3 fabric_version=0.110.5+1.21.4
# https://modrinth.com/mod/modmenu/versions # https://modrinth.com/mod/modmenu/versions
# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu # 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_libraries_base=https://bmclapi2.bangbang93.com/maven/
# loom_resources_base=https://bmclapi2.bangbang93.com/assets/ # loom_resources_base=https://bmclapi2.bangbang93.com/assets/

View File

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@ -19,11 +19,30 @@ import static net.minecraft.server.command.CommandManager.argument;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
public class CommandRegister { public class CommandRegister {
/**
* 世界边界
* <br>
* @see <a href="https://zh.minecraft.wiki/w/%E4%B8%96%E7%95%8C%E8%BE%B9%E7%95%8C#%E5%A4%A7%E5%B0%8F">Minecraft Wiki (中文)</a>
* @see <a href="https://minecraft.wiki/w/World_border#General_information">Minecraft Wiki (English)</a>
*/
final static Integer WorldBorder = (int) 2.9e7; 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; final static byte PermissionLevel = 2;
/**
* 使用Fabric API向游戏内注册命令
* @param Name 根命令名
* <br>
* @see <a href="https://docs.fabricmc.net/zh_cn/develop/commands/basics">Fabric Wiki (新样式中文)</a>
* @see <a href="https://wiki.fabricmc.net/zh_cn:tutorial:commands">Fabric Wiki (旧样式中文)</a>
* @see <a href="https://docs.fabricmc.net/develop/commands/basics">Fabric Wiki (New style,English)</a>
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (Old style,English)</a>
*/
public static void Register(String Name){ public static void Register(String Name){
// /rtp // /rtp
CommandRegistrationCallback.EVENT CommandRegistrationCallback.EVENT
@ -95,6 +114,7 @@ public class CommandRegister {
// LongArgumentType.getLong(context, "Radius(半径)"), // LongArgumentType.getLong(context, "Radius(半径)"),
// null, // null,
// EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));}); // EntityArgumentType.getEntity(context,"Origin(随机中心)"))))));});
// /rtp <Radius(半径)> <OriginPos(随机中心坐标)> // /rtp <Radius(半径)> <OriginPos(随机中心坐标)>
CommandRegistrationCallback.EVENT CommandRegistrationCallback.EVENT
.register((dispatcher, registryAccess, environment) -> { .register((dispatcher, registryAccess, environment) -> {
@ -121,7 +141,7 @@ public class CommandRegister {
IntegerArgumentType.getInteger(context, "Radius(半径)"), IntegerArgumentType.getInteger(context, "Radius(半径)"),
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x,
(float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().z )))))));});
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心坐标)> // /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心坐标)>
CommandRegistrationCallback.EVENT CommandRegistrationCallback.EVENT
@ -150,7 +170,7 @@ public class CommandRegister {
IntegerArgumentType.getInteger(context, "Radius(半径)"), IntegerArgumentType.getInteger(context, "Radius(半径)"),
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, 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)> <Radius(半径)> <OriginPos(随机中心坐标)> // /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心坐标)>
CommandRegistrationCallback.EVENT CommandRegistrationCallback.EVENT
@ -166,13 +186,37 @@ public class CommandRegister {
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});} Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});}
/**
* 向游戏内注册命令
* <br>
* {@link CommandRegister#Register(String)} 的包装器
* @see CommandRegister#Register(String)
*/
public static void Register(){ public static void Register(){
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){ static int execute_command(ServerCommandSource Source, @Nullable Integer Radius, @Nullable Entity Player, @Nullable Vec2f Origin){
Entity entity = Player == null ? Source.getPlayer() : Player; Entity entity = Player == null ? Source.getPlayer() : Player;
/*
Entity entity = null;
if (Player == null){
entity = Source.getPlayer();}
else{
entity = Player;}
*/
if (entity == null) { if (entity == null) {
Source.sendFeedback(()->{ return Text.translatable("error.not_player"); }, true); Source.sendFeedback(()->{ return Text.translatableWithFallback("error.no_target","不存在被传送目标由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true);
return -1;} return -1;}
if (Radius == null){Radius = (int) (WorldBorder - 1e4);} 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); 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; int finalCoordinate_Y = Coordinate_Y;
Source.sendFeedback(()->{ return Text.translatable("info.success", entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true); // "lambda 表达式中使用的变量应为 final 或有效 final"
return 0;} 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;}
} }

View File

@ -16,7 +16,10 @@ public class RandomTeleporter implements ModInitializer {
// This code runs as soon as Minecraft is in a mod-load-ready state. // This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized. // However, some things (like resources) may still be uninitialized.
// Proceed with mild caution. // Proceed with mild caution.
CommandRegister.Register();
LOGGER.info("RandomTeleporter Loading!"); LOGGER.info("RandomTeleporter Loading!");
CommandRegister.Register();
LOGGER.info("RandomTeleporter Loaded!");
} }
} }

View File

@ -1,6 +1,7 @@
{ {
"modmenu.nameTranslation.randomteleporter": "RandomTeleporter", "modmenu.nameTranslation.randomteleporter": "RandomTeleporter",
"modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation", "modmenu.descriptionTranslation.randomteleporter": "Added two commands for random teleportation",
"bilibili": "Bilibili", "info.success": "Teleported %s to %d %d %d",
"blog": "Blog" "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"
} }

View File

@ -2,7 +2,6 @@
"modmenu.nameTranslation.randomteleporter": "随机传送", "modmenu.nameTranslation.randomteleporter": "随机传送",
"modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令", "modmenu.descriptionTranslation.randomteleporter": "增加了两个用于随机传送的命令",
"info.success": "已将玩家%s传送到%d %d %d", "info.success": "已将玩家%s传送到%d %d %d",
"error.not_player": "执行命令的不是玩家", "error.no_target": "不存在被传送目标由非玩家物体执行命令时请显式指定被传送玩家ID",
"bilibili": "TheWhiteDog9487的哔哩哔哩主页", "bilibili": "TheWhiteDog9487的哔哩哔哩主页"
"blog": "TheWhiteDog9487的博客"
} }

View File

@ -27,10 +27,10 @@
} }
], ],
"depends": { "depends": {
"fabricloader": ">=0.16.7", "fabricloader": ">=0.16.9",
"minecraft": "1.21.3", "minecraft": "1.21.4",
"java": ">=21", "java": ">=21",
"fabric-api": "*" "fabric-api": ">=0.110.5"
}, },
"suggests": { "suggests": {
"another-mod": "*" "another-mod": "*"
@ -38,7 +38,6 @@
"custom": { "custom": {
"modmenu": { "modmenu": {
"links": { "links": {
"bilibili": "https://space.bilibili.com/401746666", "bilibili": "https://space.bilibili.com/401746666"},
"blog": "www.thewhitedog9487.xyz"},
"update_checker": true}} "update_checker": true}}
} }