mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2024-11-23 21:27:05 +08:00
0.3.3
适配Minecraft 1.21.3 ( 什么连夜OTA正式版 坐标类型由Vec3d改为Vec2f,高度一边凉快去根本用不到 修正上一个版本命令反馈消息的坐标显示错误,一路Ctrl V没发现问题,红豆泥私密马赛,已经修改好了 输出文件名改成首字母大写了
This commit is contained in:
parent
e7c99c2364
commit
c442f12de4
10
README.md
10
README.md
@ -31,21 +31,19 @@
|
|||||||
- /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作为随机半径的范围内的随机一点
|
||||||
提示:按照道理来说中心坐标是不需要高度(Y轴)的,但由于坐标的类型是Vec3d,所以还是要写高度的。
|
|
||||||
至于高度的具体数值,随便写,代码里也没用到过。
|
|
||||||
|
|
||||||
- /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作为随机半径的范围内的随机一点
|
||||||
|
|
||||||
### 特别提示
|
### 特别提示
|
||||||
|
@ -4,17 +4,17 @@ 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.2
|
minecraft_version=1.21.3
|
||||||
yarn_mappings=1.21.2+build.1
|
yarn_mappings=1.21.3+build.2
|
||||||
loader_version=0.16.7
|
loader_version=0.16.7
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=0.3.2
|
mod_version=0.3.3
|
||||||
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.2
|
fabric_version=0.106.1+1.21.3
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -4,12 +4,12 @@ import com.mojang.brigadier.arguments.LongArgumentType;
|
|||||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.command.argument.EntityArgumentType;
|
import net.minecraft.command.argument.EntityArgumentType;
|
||||||
import net.minecraft.command.argument.Vec3ArgumentType;
|
import net.minecraft.command.argument.Vec2ArgumentType;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec2f;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -20,7 +20,10 @@ import static net.minecraft.server.command.CommandManager.literal;
|
|||||||
|
|
||||||
public class CommandRegister {
|
public class CommandRegister {
|
||||||
final static long WorldBorder = (long) 2.9e7;
|
final static long WorldBorder = (long) 2.9e7;
|
||||||
static byte PermissionLevel = 2;
|
// ↑
|
||||||
|
// 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
|
||||||
|
final static byte PermissionLevel = 2;
|
||||||
public static void Register(String Name){
|
public static void Register(String Name){
|
||||||
// /rtp
|
// /rtp
|
||||||
CommandRegistrationCallback.EVENT
|
CommandRegistrationCallback.EVENT
|
||||||
@ -97,13 +100,13 @@ public class CommandRegister {
|
|||||||
.register((dispatcher, registryAccess, environment) -> {
|
.register((dispatcher, registryAccess, environment) -> {
|
||||||
dispatcher.register(literal(Name)
|
dispatcher.register(literal(Name)
|
||||||
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
|
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> execute_command(
|
.executes(context -> execute_command(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
LongArgumentType.getLong(context, "Radius(半径)"),
|
LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
null,
|
null,
|
||||||
Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)"))))));});
|
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)"))))));});
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginEntity(随机中心,实体)>
|
||||||
CommandRegistrationCallback.EVENT
|
CommandRegistrationCallback.EVENT
|
||||||
@ -117,7 +120,8 @@ public class CommandRegister {
|
|||||||
context.getSource(),
|
context.getSource(),
|
||||||
LongArgumentType.getLong(context, "Radius(半径)"),
|
LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||||
EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos()))))));});
|
new Vec2f( (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().x,
|
||||||
|
(float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().y)))))));});
|
||||||
|
|
||||||
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
// /rtp <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
|
||||||
CommandRegistrationCallback.EVENT
|
CommandRegistrationCallback.EVENT
|
||||||
@ -125,13 +129,13 @@ public class CommandRegister {
|
|||||||
dispatcher.register(literal(Name)
|
dispatcher.register(literal(Name)
|
||||||
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
|
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> execute_command(
|
.executes(context -> execute_command(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
LongArgumentType.getLong(context, "Radius(半径)"),
|
LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||||
Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)")))))));});
|
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||||
CommandRegistrationCallback.EVENT
|
CommandRegistrationCallback.EVENT
|
||||||
@ -145,7 +149,8 @@ public class CommandRegister {
|
|||||||
context.getSource(),
|
context.getSource(),
|
||||||
LongArgumentType.getLong(context, "Radius(半径)"),
|
LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||||
EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos()))))));});
|
new Vec2f( (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().x,
|
||||||
|
(float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().y)))))));});
|
||||||
|
|
||||||
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
// /rtp <被传送玩家名(PlayerID)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||||
CommandRegistrationCallback.EVENT
|
CommandRegistrationCallback.EVENT
|
||||||
@ -153,22 +158,23 @@ public class CommandRegister {
|
|||||||
dispatcher.register(literal(Name)
|
dispatcher.register(literal(Name)
|
||||||
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
.then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity())
|
||||||
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
.then(argument("Radius(半径)", LongArgumentType.longArg())
|
||||||
.then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3())
|
.then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2())
|
||||||
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
.requires(source -> source.hasPermissionLevel(PermissionLevel))
|
||||||
.executes(context -> execute_command(
|
.executes(context -> execute_command(
|
||||||
context.getSource(),
|
context.getSource(),
|
||||||
LongArgumentType.getLong(context, "Radius(半径)"),
|
LongArgumentType.getLong(context, "Radius(半径)"),
|
||||||
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"),
|
||||||
Vec3ArgumentType.getVec3(context,"OriginPos(随机中心,坐标)")))))));});}
|
Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});}
|
||||||
public static void Register(){
|
public static void Register(){
|
||||||
Register("随机传送");
|
Register("随机传送");
|
||||||
Register("rtp");}
|
Register("rtp");}
|
||||||
static int execute_command(ServerCommandSource Source, @Nullable Long Radius, @Nullable Entity Player, @Nullable Vec3d Origin){
|
static int execute_command(ServerCommandSource Source, @Nullable Long Radius, @Nullable Entity Player, @Nullable Vec2f Origin){
|
||||||
Entity entity = Player == null ? Source.getPlayer() : Player;
|
Entity entity = Player == null ? Source.getPlayer() : Player;
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
Source.sendFeedback(()->{ return Text.translatable("error.not_player"); }, true);
|
Source.sendFeedback(()->{ return Text.translatable("error.not_player"); }, true);
|
||||||
return -1;}
|
return -1;}
|
||||||
if (Radius == null){Radius = WorldBorder - (long) 1e4;}
|
if (Radius == null){Radius = WorldBorder - (long) 1e4;}
|
||||||
|
// ↑ 远离世界边界
|
||||||
Radius = Math.abs(Radius);
|
Radius = Math.abs(Radius);
|
||||||
long Coordinate_X;
|
long Coordinate_X;
|
||||||
long Coordinate_Z;
|
long Coordinate_Z;
|
||||||
@ -176,8 +182,8 @@ public class CommandRegister {
|
|||||||
Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius);
|
Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius);
|
||||||
Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);}
|
Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);}
|
||||||
else{
|
else{
|
||||||
Coordinate_X = new SplittableRandom().nextLong(Math.round(Origin.getX() - Radius), Math.round(Origin.getX() + Radius));
|
Coordinate_X = new SplittableRandom().nextLong(Math.round(Origin.x - Radius), Math.round(Origin.x + Radius));
|
||||||
Coordinate_Z = new SplittableRandom().nextLong(Math.round(Origin.getZ() - Radius), Math.round(Origin.getZ() + Radius));}
|
Coordinate_Z = new SplittableRandom().nextLong(Math.round(Origin.y - Radius), Math.round(Origin.y + Radius));}
|
||||||
int Coordinate_Y = 320;
|
int Coordinate_Y = 320;
|
||||||
for (var CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock();
|
for (var CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock();
|
||||||
// 从世界顶层往下找,直到遇到一个非空气方块
|
// 从世界顶层往下找,直到遇到一个非空气方块
|
||||||
@ -203,6 +209,7 @@ public class CommandRegister {
|
|||||||
Coordinate_Y++;
|
Coordinate_Y++;
|
||||||
// ↑ 高一层,人别站在土里了
|
// ↑ 高一层,人别站在土里了
|
||||||
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);
|
||||||
Source.sendFeedback(()->{ return Text.translatable("info.success", entity.getName(), Coordinate_Z, Coordinate_Z, Coordinate_Z); },true);
|
int finalCoordinate_Y = Coordinate_Y;
|
||||||
|
Source.sendFeedback(()->{ return Text.translatable("info.success", entity.getName(), Coordinate_X, finalCoordinate_Y, Coordinate_Z); },true);
|
||||||
return 0;}
|
return 0;}
|
||||||
}
|
}
|
@ -27,8 +27,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.15.11",
|
"fabricloader": ">=0.16.7",
|
||||||
"minecraft": "1.21.2",
|
"minecraft": "1.21.3",
|
||||||
"java": ">=21",
|
"java": ">=21",
|
||||||
"fabric-api": "*"
|
"fabric-api": "*"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user