mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2026-02-23 13:06:12 +08:00
Compare commits
1 Commits
主要
...
dca7fa256e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dca7fa256e |
97
README.md
97
README.md
@@ -1,84 +1,61 @@
|
|||||||
# 介绍
|
# 介绍
|
||||||
这个模组增加了一个命令 `/rtp`,用于将玩家随机传送到世界的任何一个位置。
|
这个模组增加了一个命令(/rtp),用于将玩家随机传送到世界的任何一个位置。
|
||||||
|
|
||||||
# 命令格式
|
# 命令格式
|
||||||
- `/rtp`
|
- /rtp
|
||||||
- `/rtp <随机半径>`
|
- /rtp <Radius(半径)>
|
||||||
- `/rtp <被传送玩家ID>`
|
- /rtp <被传送玩家名(PlayerID)>
|
||||||
- `/rtp <随机半径> <被传送玩家ID>`
|
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
||||||
- `/rtp <被传送玩家ID> <随机半径>`
|
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
||||||
- `/rtp <随机半径> <随机中心点坐标>`
|
- /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
- `/rtp <随机半径> <被传送玩家ID> <作为随机中心的实体>`
|
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||||
- `/rtp <随机半径> <被传送玩家ID> <随机中心点坐标>`
|
- /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||||
- `/rtp <被传送玩家ID> <随机半径> <作为随机中心的实体>`
|
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||||
- `/rtp <被传送玩家ID> <随机半径> <随机中心点坐标>`
|
- /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
- `/rtp <随机区域起点坐标> <随机区域终点坐标>`
|
|
||||||
- `/rtp <被传送玩家ID> <随机区域起点坐标> <随机区域终点坐标>`
|
|
||||||
- `/rtp <随机区域起点坐标> <随机区域终点坐标> <被传送玩家ID>`
|
|
||||||
- `/rtp <随机区域起点实体> <随机区域终点实体>`
|
|
||||||
- `/rtp <随机区域起点实体> <随机区域终点实体> <被传送玩家ID>`
|
|
||||||
|
|
||||||
## 命令示例
|
## 命令示例
|
||||||
- `/rtp`
|
- /rtp
|
||||||
将执行命令的玩家随机传送到以`(0,0)`为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点
|
将执行命令的玩家随机传送到以(0,0)为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点
|
||||||
2.9e+7 = 2.9 x 10^7 = 29000000 = 两千九百万
|
2.9e+7 = 2.9 x 10^7 = 29000000 = 两千九百万
|
||||||
1e4 = 10^4 = 10000 = 一万
|
1e4 = 10^4 = 10000 = 一万
|
||||||
|
|
||||||
- `/rtp 1000`
|
- /rtp 1000
|
||||||
将执行命令的玩家随机传送到以`(0,0)`为中心点,1000作为随机半径的范围内的随机一点
|
将执行命令的玩家随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487`
|
- /rtp TheWhiteDog9487
|
||||||
将TheWhiteDog9487随机传送到以`(0,0)`为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以(0,0)为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 1000`
|
- /rtp TheWhiteDog9487 1000
|
||||||
将TheWhiteDog9487随机传送到以`(0,0)`为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp 1000 TheWhiteDog9487`
|
- /rtp 1000 TheWhiteDog9487
|
||||||
将TheWhiteDog9487随机传送到以`(0,0)`为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp 1000 10000 10000`
|
- /rtp 1000 10000 10000
|
||||||
将执行命令的玩家随机传送到以`(10000,10000)`为中心点,1000作为随机半径的范围内的随机一点
|
将执行命令的玩家随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp 1000 TheWhiteDog9487 TheWhiteDog_CN`
|
- /rtp 1000 TheWhiteDog9487 TheWhiteDog_CN
|
||||||
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp 1000 TheWhiteDog9487 10000 10000`
|
- /rtp 1000 TheWhiteDog9487 10000 10000
|
||||||
将TheWhiteDog9487随机传送到以`(10000,10000)`为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 1000 TheWhiteDog_CN`
|
- /rtp TheWhiteDog9487 1000 TheWhiteDog_CN
|
||||||
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以TheWhiteDog_CN所在位置为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 1000 10000 10000`
|
- /rtp TheWhiteDog9487 1000 10000 10000
|
||||||
将TheWhiteDog9487随机传送到以`(10000,10000)`为中心点,1000作为随机半径的范围内的随机一点
|
将TheWhiteDog9487随机传送到以(10000,10000)为中心点,1000作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
- `/rtp 10000 10000 20000 20000`
|
|
||||||
将执行命令的玩家随机传送到以`(10000,10000)`,`(20000,10000)`,`(20000,20000)`,`(10000,20000)`四个顶点围成的长方形区域内的随机一点
|
|
||||||
您需要提供的坐标是这个长方形的任意一个顶点和这个顶点对应的斜对角顶点的位置
|
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 10000 10000 20000 20000`
|
|
||||||
将TheWhiteDog9487随机传送到以`(10000,10000)`,`(20000,10000)`,`(20000,20000)`,`(10000,20000)`四个顶点围成的长方形区域内的随机一点
|
|
||||||
|
|
||||||
- `/rtp 10000 10000 20000 20000 TheWhiteDog9487`
|
|
||||||
将TheWhiteDog9487随机传送到以`(10000,10000)`,`(20000,10000)`,`(20000,20000)`,`(10000,20000)`四个顶点围成的长方形区域内的随机一点
|
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 TheWhiteDog_CN`
|
|
||||||
将命令执行者传送到以TheWhiteDog9487和TheWhiteDog_CN当前所在位置为对角线的长方形区域内的随机一点
|
|
||||||
|
|
||||||
- `/rtp TheWhiteDog9487 TheWhiteDog_CN TheWhiteDog4568`
|
|
||||||
将TheWhiteDog4568随机传送到以TheWhiteDog9487和TheWhiteDog_CN当前所在位置为对角线的长方形区域内的随机一点
|
|
||||||
|
|
||||||
### 特别提示
|
### 特别提示
|
||||||
`/rtp <随机半径> <作为随机中心的实体>` 这种格式不存在。
|
/rtp <Radius(半径)> <Origin(随机中心,实体)> 这种格式不存在。
|
||||||
因为第二个参数可能是被传送玩家名,也可能是做随机中心点的实体。
|
因为第二个参数可能是被传送玩家名,也可能是做随机中心点的实体。
|
||||||
这两种都是实体类型,无法区分到底是哪一种,存在歧义。
|
这两种都是实体类型,无法区分到底是哪一种,存在歧义。
|
||||||
同样,`/rtp <被传送玩家ID> <随机区域起点实体> <随机区域终点实体>` 这一组也是不存在的
|
|
||||||
三个参数都是实体类型,没办法区分`被传送玩家ID`是第一个还是第三个
|
|
||||||
|
|
||||||
# 依赖项
|
# 依赖项
|
||||||
Fabric API
|
由于我使用了fabric.api.command.v2中的CommandRegistrationCallback.EVENT来向游戏注册命令,所以这个模组需要依赖Fabric API
|
||||||
|
|
||||||
# 关于玩家权限
|
# 关于玩家权限
|
||||||
我参照原版的 `/tp` 命令,给 `/rtp` 设置了2级的权限要求。
|
我参照原版的 /tp 命令,给 /rtp 设置了2级的权限要求。
|
||||||
如果是原版或者类原版,你只需要让玩家有作弊的权限就可以用。
|
如果是原版或者类原版,你只需要让玩家有作弊的权限就可以用。
|
||||||
插件服务器方面那些具体的权限分配,因为我自己没玩过所以我也没法给出参考意见。
|
插件服务器方面那些具体的权限分配,因为我自己没玩过所以我也没法给出参考意见。
|
||||||
|
|
||||||
@@ -90,7 +67,7 @@ Fabric API
|
|||||||
2. 单人游戏 + 开放局域网
|
2. 单人游戏 + 开放局域网
|
||||||
1. 使用客户端内置的服务器,开放局域网的那位玩家的客户端需要安装
|
1. 使用客户端内置的服务器,开放局域网的那位玩家的客户端需要安装
|
||||||
2. 其他加入游戏的玩家不需要安装
|
2. 其他加入游戏的玩家不需要安装
|
||||||
3. 使用独立服务器(类似`server.jar`这种文件)
|
3. 使用独立服务器(类似server.jar这种文件)
|
||||||
1. 服务器需要安装
|
1. 服务器需要安装
|
||||||
2. 客户端不需要
|
2. 客户端不需要
|
||||||
|
|
||||||
@@ -98,11 +75,11 @@ Fabric API
|
|||||||
如果有查看多语言翻译文本的需求 ,那建议还是都装一下吧。**
|
如果有查看多语言翻译文本的需求 ,那建议还是都装一下吧。**
|
||||||
|
|
||||||
# 一些小彩蛋
|
# 一些小彩蛋
|
||||||
你可以使用 `/随机传送` 来替代 `/rtp`
|
你可以使用 /随机传送 来替代 /rtp
|
||||||
没错,Minecraft的命令是可以存在非ASCII字符的,所以我就整了一个
|
没错,Minecraft的命令是可以存在非ASCII字符的,所以我就整了一个
|
||||||
例如:
|
例如:
|
||||||
- `/rtp TheWhiteDog9487 1000`
|
- /rtp TheWhiteDog9487 1000
|
||||||
- `/随机传送 TheWhiteDog9487 1000`
|
- /随机传送 TheWhiteDog9487 1000
|
||||||
|
|
||||||
这两个命令的效果没有任何差别
|
这两个命令的效果没有任何差别
|
||||||
玩家权限限制和 `/rtp` 当然也是一样的,都是2级
|
玩家权限限制和 /rtp 当然也是一样的,都是2级
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("fabric-loom") version "1.15-SNAPSHOT"
|
id("fabric-loom") version "1.11-SNAPSHOT"
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,16 +25,17 @@ loom {
|
|||||||
splitEnvironmentSourceSets()
|
splitEnvironmentSourceSets()
|
||||||
|
|
||||||
mods {
|
mods {
|
||||||
val mod = create("randomteleporter")
|
create("randomteleporter") {
|
||||||
mod.sourceSet("main")
|
sourceSet(sourceSets["main"])
|
||||||
mod.sourceSet("client")
|
sourceSet(sourceSets["client"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft("com.mojang:minecraft:${project.extra["minecraft_version"]}")
|
minecraft("com.mojang:minecraft:${project.extra["minecraft_version"]}")
|
||||||
mappings(loom.officialMojangMappings())
|
mappings("net.fabricmc:yarn:${project.extra["yarn_mappings"]}:v2")
|
||||||
modImplementation("net.fabricmc:fabric-loader:${project.extra["loader_version"]}")
|
modImplementation("net.fabricmc:fabric-loader:${project.extra["loader_version"]}")
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ 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.11
|
minecraft_version=1.21.9
|
||||||
loader_version=0.18.2
|
yarn_mappings=1.21.9+build.1
|
||||||
|
loader_version=0.17.2
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=0.5.0
|
mod_version=0.4.0
|
||||||
maven_group=xyz.thewhitedog9487
|
maven_group=xyz.thewhitedog9487
|
||||||
archives_base_name=RandomTeleporter
|
archives_base_name=RandomTeleporter
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.139.4+1.21.11
|
fabric_version=0.133.14+1.21.9
|
||||||
|
|
||||||
# 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=17.0.0-beta.2
|
modmenu_version=16.0.0-rc.1
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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-9.2.0-bin.zip
|
distributionUrl=https://services.gradle.org/distributions/gradle-9.1.0-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package xyz.thewhitedog9487.mixin.client;
|
package xyz.thewhitedog9487.mixin.client;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
@Mixin(Minecraft.class)
|
@Mixin(MinecraftClient.class)
|
||||||
public class ExampleClientMixin {
|
public class ExampleClientMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "run")
|
@Inject(at = @At("HEAD"), method = "run")
|
||||||
private void run(CallbackInfo info) {
|
private void run(CallbackInfo info) {
|
||||||
|
|||||||
@@ -3,30 +3,27 @@ package xyz.thewhitedog9487;
|
|||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.server.commands.TeleportCommand;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.server.permissions.PermissionCheck;
|
import net.minecraft.command.argument.EntityArgumentType;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.command.argument.Vec2ArgumentType;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.commands.arguments.EntityArgument;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.commands.arguments.coordinates.Vec2Argument;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.util.math.Vec2f;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.world.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.phys.Vec2;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
|
||||||
import org.jspecify.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SplittableRandom;
|
import java.util.SplittableRandom;
|
||||||
|
|
||||||
import static net.minecraft.commands.Commands.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.commands.Commands.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
import static net.minecraft.world.level.levelgen.Heightmap.Types.MOTION_BLOCKING_NO_LEAVES;
|
import static net.minecraft.world.Heightmap.Type.MOTION_BLOCKING_NO_LEAVES;
|
||||||
import static xyz.thewhitedog9487.ResourceReloaderListener.*;
|
import static xyz.thewhitedog9487.ResourceReloaderListener.*;
|
||||||
|
|
||||||
public class CommandRegister {
|
public class CommandRegister {
|
||||||
@@ -67,9 +64,9 @@ public class CommandRegister {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行命令所需权限等级
|
* 执行命令所需权限等级
|
||||||
* @see TeleportCommand
|
* @see net.minecraft.server.command.TeleportCommand
|
||||||
*/
|
*/
|
||||||
final static PermissionCheck PermissionLevel = Commands.LEVEL_GAMEMASTERS;
|
final static byte PermissionLevel = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用Fabric API向游戏内注册命令
|
* 使用Fabric API向游戏内注册命令
|
||||||
@@ -86,55 +83,47 @@ public class CommandRegister {
|
|||||||
.register((dispatcher, registryAccess, environment) ->{
|
.register((dispatcher, registryAccess, environment) ->{
|
||||||
dispatcher.register(literal(Name)
|
dispatcher.register(literal(Name)
|
||||||
// /rtp
|
// /rtp
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),null,null, null, null, null))
|
context.getSource(),null,null, null))
|
||||||
// /rtp <Radius(半径)>
|
// /rtp <Radius(半径)>
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null)))
|
null)))
|
||||||
// /rtp <PlayerID(被传送玩家名)>
|
// /rtp <被传送玩家名(PlayerID)>
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
null,
|
null,
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null)))
|
null)))
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)>
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null))))
|
null))))
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)>
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null))))
|
null))))
|
||||||
// // /rtp <Radius(半径)> <Origin(随机中心)>
|
// // /rtp <Radius(半径)> <Origin(随机中心)>
|
||||||
// .then(argument("Radius(半径)", LongArgumentType.longArg())
|
// .then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||||
// .then(argument("Origin(随机中心)",EntityArgumentType.player())
|
// .then(argument("Origin(随机中心)",EntityArgumentType.player())
|
||||||
// .requires(Commands.hasPermission(PermissionLevel))
|
// .requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
// .executes(context -> execute_command_origin(
|
// .executes(context -> execute_command_origin(
|
||||||
// context.getSource(),
|
// context.getSource(),
|
||||||
// LongArgumentType.getLong(context, "Radius(半径)"),
|
// LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
@@ -142,127 +131,55 @@ public class CommandRegister {
|
|||||||
// EntityArgumentType.getEntity(context,"Origin(随机中心)")))))
|
// EntityArgumentType.getEntity(context,"Origin(随机中心)")))))
|
||||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(argument(CommandArgumentName_OriginPosition,Vec2ArgumentType.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
null,
|
null,
|
||||||
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition),
|
Vec2ArgumentType.getVec2(context,CommandArgumentName_OriginPosition)))))
|
||||||
null,
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||||
null))))
|
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginEntity(随机中心,实体)>
|
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
.then(argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
.then(argument(CommandArgumentName_OriginEntity,EntityArgumentType.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().x,
|
new Vec2f( (float) EntityArgumentType.getEntity( context,CommandArgumentName_OriginEntity).getEntityPos().x,
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().z ),
|
(float) EntityArgumentType.getEntity( context,CommandArgumentName_OriginEntity).getEntityPos().z ))))))
|
||||||
null,
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||||
null)))))
|
|
||||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginPos(随机中心,坐标)>
|
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(argument(CommandArgumentName_OriginPosition,Vec2ArgumentType.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition),
|
Vec2ArgumentType.getVec2(context,CommandArgumentName_OriginPosition))))))
|
||||||
null,
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||||
null)))))
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
.then(argument(CommandArgumentName_OriginEntity,EntityArgumentType.entity())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().x,
|
new Vec2f( (float) EntityArgumentType.getEntity( context,CommandArgumentName_OriginEntity).getEntityPos().x,
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_OriginEntity).position().z ),
|
(float) EntityArgumentType.getEntity( context,CommandArgumentName_OriginEntity).getEntityPos().z ))))))
|
||||||
null,
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
null)))))
|
.then(argument(CommandArgumentName_Target, EntityArgumentType.entity())
|
||||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
.then(argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||||
.then(argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
.then(argument(CommandArgumentName_OriginPosition,Vec2ArgumentType.vec2())
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> ExecuteCommand(
|
.executes(context -> ExecuteCommand(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
IntegerArgumentType.getInteger(context, CommandArgumentName_Radius),
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
EntityArgumentType.getEntity(context,CommandArgumentName_Target),
|
||||||
Vec2Argument.getVec2(context,CommandArgumentName_OriginPosition),
|
Vec2ArgumentType.getVec2(context,CommandArgumentName_OriginPosition)))))) );});}
|
||||||
null,
|
|
||||||
null)))))
|
|
||||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
|
||||||
.then(argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
|
||||||
.then(argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
|
||||||
.executes(context -> ExecuteCommand(
|
|
||||||
context.getSource(),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionFromPosition),
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionToPosition)))))
|
|
||||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)> <PlayerID(被传送玩家名)>
|
|
||||||
.then(argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
|
||||||
.then(argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
|
||||||
.executes(context -> ExecuteCommand(
|
|
||||||
context.getSource(),
|
|
||||||
null,
|
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
|
||||||
null,
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionFromPosition),
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionToPosition))))))
|
|
||||||
// /rtp <PlayerID(被传送玩家名)> <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
|
||||||
.then(argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
|
||||||
.executes(context -> ExecuteCommand(
|
|
||||||
context.getSource(),
|
|
||||||
null,
|
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
|
||||||
null,
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionFromPosition),
|
|
||||||
Vec2Argument.getVec2(context, CommandArgumentName_RegionToPosition))))))
|
|
||||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)>
|
|
||||||
.then(argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
|
||||||
.executes(context -> ExecuteCommand(
|
|
||||||
context.getSource(),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_RegionFromEntity).position().x,
|
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_RegionFromEntity).position().z ),
|
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_RegionToEntity).position().x,
|
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_RegionToEntity).position().z ) ) )))
|
|
||||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)> <PlayerID(被传送玩家名)>
|
|
||||||
.then(argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
|
||||||
.then(argument(CommandArgumentName_Target, EntityArgument.entity())
|
|
||||||
.requires(Commands.hasPermission(PermissionLevel))
|
|
||||||
.executes(context -> ExecuteCommand(
|
|
||||||
context.getSource(),
|
|
||||||
null,
|
|
||||||
EntityArgument.getEntity(context,CommandArgumentName_Target),
|
|
||||||
null,
|
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_RegionFromEntity).position().x,
|
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_RegionFromEntity).position().z ),
|
|
||||||
new Vec2( (float) EntityArgument.getEntity( context,CommandArgumentName_RegionToEntity).position().x,
|
|
||||||
(float) EntityArgument.getEntity( context,CommandArgumentName_RegionToEntity).position().z )))))) );});}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向游戏内注册命令
|
* 向游戏内注册命令
|
||||||
@@ -281,11 +198,9 @@ public class CommandRegister {
|
|||||||
* @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离
|
* @param Radius 随机选择的目的坐标距离参数 {@code Origin} 的最大距离
|
||||||
* @param Entity 被传送的实体
|
* @param Entity 被传送的实体
|
||||||
* @param Origin 随机选择的目的坐标的中心
|
* @param Origin 随机选择的目的坐标的中心
|
||||||
* @param RegionFrom 选择随机坐标的范围的起始坐标
|
|
||||||
* @param RegionTo 选择随机坐标的范围的结束坐标
|
|
||||||
* @return 命令运行是否成功
|
* @return 命令运行是否成功
|
||||||
*/
|
*/
|
||||||
static int ExecuteCommand(CommandSourceStack Source, @Nullable Integer Radius, @Nullable Entity Entity, @Nullable Vec2 Origin, @Nullable Vec2 RegionFrom, @Nullable Vec2 RegionTo){
|
static int ExecuteCommand(ServerCommandSource Source, @Nullable Integer Radius, @Nullable Entity Entity, @Nullable Vec2f Origin){
|
||||||
Entity TargetEntity = Entity == null ? Source.getPlayer() : Entity;
|
Entity TargetEntity = Entity == null ? Source.getPlayer() : Entity;
|
||||||
/*
|
/*
|
||||||
↑
|
↑
|
||||||
@@ -296,13 +211,12 @@ public class CommandRegister {
|
|||||||
TargetEntity = Entity;}
|
TargetEntity = Entity;}
|
||||||
*/
|
*/
|
||||||
if (TargetEntity == null) {
|
if (TargetEntity == null) {
|
||||||
Source.sendSuccess(()->{ return Component.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true);
|
Source.sendFeedback(()->{ return Text.translatableWithFallback("error.no_target","不存在被传送目标,由非玩家物体执行命令时请显式指定被传送玩家ID"); }, true);
|
||||||
return -1;}
|
return -1;}
|
||||||
int Coordinate_X = 0;
|
|
||||||
int Coordinate_Z = 0;
|
|
||||||
if (RegionFrom == null || RegionTo == null) { // ← 按半径和中心取随机
|
|
||||||
if (Radius == null){Radius = (int) (WorldBorder - 1e4);}
|
if (Radius == null){Radius = (int) (WorldBorder - 1e4);}
|
||||||
// ↑ 远离世界边界
|
// ↑ 远离世界边界
|
||||||
|
int Coordinate_X = 0;
|
||||||
|
int Coordinate_Z = 0;
|
||||||
try {
|
try {
|
||||||
if (Origin == null){
|
if (Origin == null){
|
||||||
Coordinate_X = SR.nextInt(-Radius, Radius + 1);
|
Coordinate_X = SR.nextInt(-Radius, Radius + 1);
|
||||||
@@ -313,8 +227,7 @@ public class CommandRegister {
|
|||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
// 半径为零
|
// 半径为零
|
||||||
if (Origin == null) {
|
if (Origin == null) {
|
||||||
Source.sendSuccess(() -> {
|
Source.sendFeedback(()->{ return Text.translatableWithFallback("warning.radius_equal_zero_no_target", "由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生"); },true);
|
||||||
return Component.translatableWithFallback("warning.radius_equal_zero_no_target", "由于你设置的随机半径为0,并且未设置随机中心点坐标,因此什么都不会发生"); }, true);
|
|
||||||
return -1;}
|
return -1;}
|
||||||
else {
|
else {
|
||||||
Coordinate_X = (int) Origin.x;
|
Coordinate_X = (int) Origin.x;
|
||||||
@@ -322,23 +235,13 @@ public class CommandRegister {
|
|||||||
int finalCoordinate_X1 = Coordinate_X;
|
int finalCoordinate_X1 = Coordinate_X;
|
||||||
int finalCoordinate_Z1 = Coordinate_Z;
|
int finalCoordinate_Z1 = Coordinate_Z;
|
||||||
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
||||||
Source.sendSuccess(() -> {
|
Source.sendFeedback(()->{ return Text.translatableWithFallback("warning.radius_equal_zero", "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d", finalCoordinate_X1, finalCoordinate_Z1); },true);}}
|
||||||
return Component.translatableWithFallback("warning.radius_equal_zero", "警告:由于你设置的随机半径为0,因此在选择出合适高度之后将直接把你传送至%d %d", finalCoordinate_X1, finalCoordinate_Z1); }, true); } } }
|
World EntityWorld = TargetEntity.getEntityWorld();
|
||||||
else { // ← 按范围取随机
|
|
||||||
Coordinate_X = SR.nextInt( Math.min( (int)RegionFrom.x, (int)RegionTo.x ), Math.max( (int)RegionFrom.x, (int)RegionTo.x ) + 1 );
|
|
||||||
Coordinate_Z = SR.nextInt( Math.min( (int)RegionFrom.y, (int)RegionTo.y ), Math.max( (int)RegionFrom.y, (int)RegionTo.y ) + 1 ); }
|
|
||||||
if (Coordinate_X >= WorldBorder){ Coordinate_X = (int) (WorldBorder - 1e4); }
|
|
||||||
else if (Coordinate_X <= -WorldBorder){ Coordinate_X = (int) (-WorldBorder + 1e4); }
|
|
||||||
if (Coordinate_Z >= WorldBorder){ Coordinate_Z = (int) (WorldBorder - 1e4); }
|
|
||||||
else if (Coordinate_Z <= -WorldBorder){ Coordinate_Z = (int) (-WorldBorder + 1e4); }
|
|
||||||
// ↑ 远离世界边界
|
|
||||||
Level EntityWorld = TargetEntity.level();
|
|
||||||
EntityWorld.getChunk(Coordinate_X >> 4, Coordinate_Z >> 4, ChunkStatus.FULL, true);
|
EntityWorld.getChunk(Coordinate_X >> 4, Coordinate_Z >> 4, ChunkStatus.FULL, true);
|
||||||
// ↑ 加载目标区块,不然下面获取到的Coordinate_Y一定是-64
|
// ↑ 加载目标区块,不然下面获取到的Coordinate_Y一定是-64
|
||||||
// 按位右移4和除以16在被除数小于0时的结果不一致,一个是向上取整,一个是向下取整
|
// 必须是 >> 4 ,不能是 / 16
|
||||||
// 因此必须是 >> 4 ,不能是 / 16
|
int Coordinate_Y = EntityWorld.getTopY(MOTION_BLOCKING_NO_LEAVES, Coordinate_X, Coordinate_Z);
|
||||||
int Coordinate_Y = EntityWorld.getHeight(MOTION_BLOCKING_NO_LEAVES, Coordinate_X, Coordinate_Z);
|
BlockPos.Mutable BlockPos = new BlockPos.Mutable();
|
||||||
BlockPos.MutableBlockPos BlockPos = new BlockPos.MutableBlockPos();
|
|
||||||
for (int x = -1; x <= 1; x++) {
|
for (int x = -1; x <= 1; x++) {
|
||||||
for (int z = -1; z <= 1; z++) {
|
for (int z = -1; z <= 1; z++) {
|
||||||
// 如果传送到的位置周围一圈是ReplaceToTargetBlock的方块,将其替换为TargetBlock
|
// 如果传送到的位置周围一圈是ReplaceToTargetBlock的方块,将其替换为TargetBlock
|
||||||
@@ -346,14 +249,14 @@ public class CommandRegister {
|
|||||||
var CurrentBlock = EntityWorld.getBlockState(BlockPos).getBlock();
|
var CurrentBlock = EntityWorld.getBlockState(BlockPos).getBlock();
|
||||||
if ( ReplaceToTargetBlock.contains(CurrentBlock) ) {
|
if ( ReplaceToTargetBlock.contains(CurrentBlock) ) {
|
||||||
// 只替换ReplaceToTargetBlock内的方块,其余保留
|
// 只替换ReplaceToTargetBlock内的方块,其余保留
|
||||||
EntityWorld.setBlockAndUpdate(BlockPos, TargetBlock.defaultBlockState());}}}
|
EntityWorld.setBlockState(BlockPos, TargetBlock.getDefaultState());}}}
|
||||||
// if ( String.valueOf(TargetEntity.getWorld().getBiome(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getKey()).equals("minecraft:the_void") ) {
|
// if ( String.valueOf(TargetEntity.getWorld().getBiome(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getKey()).equals("minecraft:the_void") ) {
|
||||||
// Coordinate_Y++;}
|
// Coordinate_Y++;}
|
||||||
TargetEntity.teleportTo((ServerLevel) EntityWorld,Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), TargetEntity.getYRot(), TargetEntity.getXRot(), false);
|
TargetEntity.teleport((ServerWorld) EntityWorld,Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), TargetEntity.getYaw(), TargetEntity.getPitch(), false);
|
||||||
int finalCoordinate_X = Coordinate_X;
|
int finalCoordinate_X = Coordinate_X;
|
||||||
int finalCoordinate_Z = Coordinate_Z;
|
int finalCoordinate_Z = Coordinate_Z;
|
||||||
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
// ↑ "lambda 表达式中使用的变量应为 final 或有效 final"
|
||||||
final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", TargetEntity.getName().getString(), Coordinate_X, Coordinate_Y, Coordinate_Z);
|
final var FeedbackFallbackString = String.format("已将玩家%s传送到%d %d %d", TargetEntity.getName().getString(), Coordinate_X, Coordinate_Y, Coordinate_Z);
|
||||||
Source.sendSuccess(()->{ return Component.translatableWithFallback("info.success", FeedbackFallbackString, TargetEntity.getName(), finalCoordinate_X, Coordinate_Y, finalCoordinate_Z); },true);
|
Source.sendFeedback(()->{ return Text.translatableWithFallback("info.success", FeedbackFallbackString, TargetEntity.getName(), finalCoordinate_X, Coordinate_Y, finalCoordinate_Z); },true);
|
||||||
return Command.SINGLE_SUCCESS;}
|
return Command.SINGLE_SUCCESS;}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,10 @@ package xyz.thewhitedog9487;
|
|||||||
|
|
||||||
import net.fabricmc.fabric.api.resource.v1.ResourceLoader;
|
import net.fabricmc.fabric.api.resource.v1.ResourceLoader;
|
||||||
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleResourceReloader;
|
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleResourceReloader;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.resources.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.jspecify.annotations.NonNull;
|
|
||||||
|
|
||||||
import static net.minecraft.server.packs.PackType.CLIENT_RESOURCES;
|
import static net.minecraft.resource.ResourceType.CLIENT_RESOURCES;
|
||||||
import static xyz.thewhitedog9487.RandomTeleporter.MOD_ID;
|
import static xyz.thewhitedog9487.RandomTeleporter.MOD_ID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,30 +13,22 @@ import static xyz.thewhitedog9487.RandomTeleporter.MOD_ID;
|
|||||||
*/
|
*/
|
||||||
public class ResourceReloaderListener {
|
public class ResourceReloaderListener {
|
||||||
public static String CommandArgumentName_Radius = "Radius(半径)";
|
public static String CommandArgumentName_Radius = "Radius(半径)";
|
||||||
public static String CommandArgumentName_Target = "PlayerID(被传送玩家名)";
|
public static String CommandArgumentName_Target = "被传送玩家名(PlayerID)";
|
||||||
public static String CommandArgumentName_OriginPosition = "OriginPos(随机中心,坐标)";
|
public static String CommandArgumentName_OriginPosition = "OriginPos(随机中心,坐标)";
|
||||||
public static String CommandArgumentName_OriginEntity = "OriginEntity(随机中心,实体)";
|
public static String CommandArgumentName_OriginEntity = "OriginEntity(随机中心,实体)";
|
||||||
public static String CommandArgumentName_RegionFromPosition = "RegionFrom(随机范围起始位置,坐标)";
|
|
||||||
public static String CommandArgumentName_RegionToPosition = "RegionTo(随机范围结束位置,坐标)";
|
|
||||||
public static String CommandArgumentName_RegionFromEntity = "RegionFrom(随机范围起始位置,实体)";
|
|
||||||
public static String CommandArgumentName_RegionToEntity = "RegionTo(随机范围结束位置,实体)";
|
|
||||||
|
|
||||||
public static void Register(){
|
public static void Register(){
|
||||||
ResourceLoader.get(CLIENT_RESOURCES).registerReloader(Identifier.fromNamespaceAndPath(MOD_ID, "translate_text_apply"), new SimpleResourceReloader<Void>() {
|
ResourceLoader.get(CLIENT_RESOURCES).registerReloader(Identifier.of(MOD_ID, "translate_text_apply"), new SimpleResourceReloader<Void>() {
|
||||||
/**
|
/**
|
||||||
* 用不到,不用管
|
* 用不到,不用管
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Void prepare(@NonNull SharedState store) {
|
protected Void prepare(Store store) {
|
||||||
return null; }
|
return null; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void apply(Void prepared, @NonNull SharedState store) {
|
protected void apply(Void prepared, Store store) {
|
||||||
CommandArgumentName_Radius = Component.translatableWithFallback("command.argument.radius", "Radius(半径)").getString();
|
CommandArgumentName_Radius = Text.translatableWithFallback("command.argument.radius", "Radius(半径)").getString();
|
||||||
CommandArgumentName_Target = Component.translatableWithFallback("command.argument.target", "PlayerID(被传送玩家名)").getString();
|
CommandArgumentName_Target = Text.translatableWithFallback("command.argument.target", "被传送玩家名(PlayerID)").getString();
|
||||||
CommandArgumentName_OriginPosition = Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)").getString();
|
CommandArgumentName_OriginPosition = Text.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)").getString();
|
||||||
CommandArgumentName_OriginEntity = Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)").getString();
|
CommandArgumentName_OriginEntity = Text.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)").getString(); } } ); } }
|
||||||
CommandArgumentName_RegionFromPosition = Component.translatableWithFallback("command.argument.region_from_pos", "RegionFrom(随机范围起始位置,坐标)").getString();
|
|
||||||
CommandArgumentName_RegionToPosition = Component.translatableWithFallback("command.argument.region_to_pos", "RegionTo(随机范围结束位置,坐标)").getString();
|
|
||||||
CommandArgumentName_RegionFromEntity = Component.translatableWithFallback("command.argument.region_from_entity", "RegionFrom(随机范围起始位置,实体)").getString();
|
|
||||||
CommandArgumentName_RegionToEntity = Component.translatableWithFallback("command.argument.region_to_entity", "RegionTo(随机范围结束位置,实体)").getString(); } } ); } }
|
|
||||||
@@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
@Mixin(MinecraftServer.class)
|
||||||
public class ExampleMixin {
|
public class ExampleMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "loadLevel")
|
@Inject(at = @At("HEAD"), method = "loadWorld")
|
||||||
private void init(CallbackInfo info) {
|
private void init(CallbackInfo info) {
|
||||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,5 @@
|
|||||||
"command.argument.radius": "radius",
|
"command.argument.radius": "radius",
|
||||||
"command.argument.target": "teleported entity",
|
"command.argument.target": "teleported entity",
|
||||||
"command.argument.origin_pos": "origin(pos)",
|
"command.argument.origin_pos": "origin(pos)",
|
||||||
"command.argument.origin_entity": "origin(entity)",
|
"command.argument.origin_entity": "origin(entity)"
|
||||||
"command.argument.region_from_pos": "region start(pos)",
|
|
||||||
"command.argument.region_to_pos": "region end(pos)",
|
|
||||||
"command.argument.region_from_entity": "region start(entity)",
|
|
||||||
"command.argument.region_to_entity": "region end(entity)"
|
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,5 @@
|
|||||||
"command.argument.radius": "半径",
|
"command.argument.radius": "半径",
|
||||||
"command.argument.target": "被传送实体",
|
"command.argument.target": "被传送实体",
|
||||||
"command.argument.origin_pos": "随机中心(坐标)",
|
"command.argument.origin_pos": "随机中心(坐标)",
|
||||||
"command.argument.origin_entity": "随机中心(实体)",
|
"command.argument.origin_entity": "随机中心(实体)"
|
||||||
"command.argument.region_from_pos": "坐标选取区域起点(坐标)",
|
|
||||||
"command.argument.region_to_pos": "坐标选取区域终点(坐标)",
|
|
||||||
"command.argument.region_from_entity": "坐标选取区域起点(实体)",
|
|
||||||
"command.argument.region_to_entity": "坐标选取区域终点(实体)"
|
|
||||||
}
|
}
|
||||||
@@ -27,10 +27,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.18.2",
|
"fabricloader": ">=0.17.2",
|
||||||
"minecraft": "1.21.11",
|
"minecraft": "1.21.9",
|
||||||
"java": ">=21",
|
"java": ">=21",
|
||||||
"fabric-api": ">=0.139.4"
|
"fabric-api": ">=0.133.14"
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
"another-mod": "*"
|
"another-mod": "*"
|
||||||
|
|||||||
Reference in New Issue
Block a user