From 81861596536d79a1dd58dae07db21555795c500c Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Sun, 18 Feb 2024 20:39:47 +0800 Subject: [PATCH] =?UTF-8?q?0.2.5=20=E7=AA=81=E7=84=B6=E5=8F=91=E7=8E=B0Ved?= =?UTF-8?q?3d=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=96=B9=E6=B3=95=E9=87=8C?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=B8=AA=E8=AE=A1=E7=AE=97=E4=B8=A4=E7=82=B9?= =?UTF-8?q?=E9=97=B4=E8=B7=9D=E7=A6=BB=E7=9A=84=EF=BC=8C=E9=82=A3=E6=88=91?= =?UTF-8?q?=E5=B0=B1=E6=8A=8A=E6=88=91=E8=87=AA=E5=B7=B1=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=BA=93=E6=92=A4=E4=BA=86=E3=80=82=20=E7=84=B6?= =?UTF-8?q?=E5=90=8E=E6=88=91=E6=8A=8A=E5=91=BD=E4=BB=A4=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=E4=BB=8E4=E4=B8=8B=E9=99=8D=E5=88=B0?= =?UTF-8?q?=E4=BA=862=EF=BC=8C=E5=92=8C=E5=8E=9F=E7=89=88=E7=9A=84/tp?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E3=80=82=20=EF=BC=88=E6=88=91=E8=AE=B0?= =?UTF-8?q?=E5=BE=97=E5=8E=9F=E7=89=88=E7=9A=84tp=E6=98=AF4=E7=BA=A7?= =?UTF-8?q?=E5=95=8A=EF=BC=9F=E6=88=91=E6=9C=80=E6=97=A9=E8=BF=98=E5=8E=BB?= =?UTF-8?q?=E6=BA=90=E4=BB=A3=E7=A0=81=E9=87=8C=E7=9C=8B=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E7=9C=BC=EF=BC=8C=E5=92=8B=E5=9B=9E=E4=BA=8B=E5=91=A2=EF=BC=9F?= =?UTF-8?q?=20=E4=BC=A0=E9=80=81=E8=BF=87=E5=8E=BB=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E4=BF=9D=E6=8A=A4=E5=B9=B3=E5=8F=B0=EF=BC=8C=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E6=98=AF3x3=E7=9A=84=E7=8E=BB=E7=92=83=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AF1x1=E7=9A=84=E7=9F=B3=E5=A4=B4=EF=BC=8C?= =?UTF-8?q?=E8=80=8C=E4=B8=94=E7=8E=A9=E5=AE=B6=E4=BC=9A=E7=AB=99=E5=9C=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9A=84=E6=AD=A3=E4=B8=AD=E5=BF=83=E3=80=82?= =?UTF-8?q?=20=E4=BE=8B=E8=A1=8C=E6=9B=B4=E6=96=B0Fabric=20API=E5=92=8CFab?= =?UTF-8?q?ric=20Loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++--- gradle.properties | 6 ++-- .../xyz/thewhitedog9487/CommandRegister.java | 36 ++++++++++--------- .../java/xyz/thewhitedog9487/Toolbox.java | 10 ------ 4 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/xyz/thewhitedog9487/Toolbox.java diff --git a/README.md b/README.md index 86b6903..519f0a9 100644 --- a/README.md +++ b/README.md @@ -15,14 +15,15 @@ ## 命令示例 - /rtp -将执行命令的玩家随机传送到以(0,0)为中心点,2.9e7作为随机半径的范围内的随机一点 +将执行命令的玩家随机传送到以(0,0)为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点 2.9e+7 = 2.9 x 10^7 = 29000000 = 两千九百万 +1e4 = 10^4 = 10000 = 一万 - /rtp 1000 将执行命令的玩家随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点 - /rtp TheWhiteDog9487 -将TheWhiteDog9487随机传送到以(0,0)为中心点,2.9e7作为随机半径的范围内的随机一点 +将TheWhiteDog9487随机传送到以(0,0)为中心点,2.9e7 - 1e4作为随机半径的范围内的随机一点 - /rtp TheWhiteDog9487 1000 将TheWhiteDog9487随机传送到以(0,0)为中心点,1000作为随机半径的范围内的随机一点 @@ -56,7 +57,7 @@ 由于我使用了fabric.api.command.v2中的CommandRegistrationCallback.EVENT来向游戏注册命令,所以这个模组需要依赖Fabric API # 关于玩家权限 -我参照原版的 /tp 命令,给 /rtp 设置了4级的权限要求。 +我参照原版的 /tp 命令,给 /rtp 设置了2级的权限要求。 如果是原版或者类原版,你只需要让玩家有作弊的权限就可以用。 插件服务器方面那些具体的权限分配,因为我自己没玩过所以我也没法给出参考意见。 @@ -80,4 +81,4 @@ - /随机传送 TheWhiteDog9487 1000 这两个命令的效果没有任何差别 -玩家权限限制和 /rtp 当然也是一样的,都是4级 \ No newline at end of file +玩家权限限制和 /rtp 当然也是一样的,都是2级 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 0915104..f8db583 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,15 +6,15 @@ org.gradle.parallel=true # check these on https://fabricmc.net/develop minecraft_version=1.20.4 yarn_mappings=1.20.4+build.3 -loader_version=0.15.6 +loader_version=0.15.7 # Mod Properties -mod_version=0.2.4 +mod_version=0.2.5 maven_group=xyz.thewhitedog9487 archives_base_name=randomteleporter # Dependencies -fabric_version=0.95.4+1.20.4 +fabric_version=0.96.1+1.20.4 loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ loom_resources_base=https://bmclapi2.bangbang93.com/assets/ diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index 8a934dc..0c0dfb7 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -16,17 +16,17 @@ import java.util.SplittableRandom; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; -import static xyz.thewhitedog9487.Toolbox.Distance; public class CommandRegister { final static long WorldBorder = (long) 2.9e7; static byte Retry = 0; + static byte PermissionLevel = 2; public static void Register(String Name){ // /rtp CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) ->{ dispatcher.register(literal(Name) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(),null,null, null)));}); @@ -35,7 +35,7 @@ public class CommandRegister { .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) .then(argument("Radius(半径)", LongArgumentType.longArg()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -47,7 +47,7 @@ public class CommandRegister { .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), null, @@ -60,7 +60,7 @@ public class CommandRegister { dispatcher.register(literal(Name) .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -73,7 +73,7 @@ public class CommandRegister { dispatcher.register(literal(Name) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("Radius(半径)", LongArgumentType.longArg()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -86,7 +86,7 @@ public class CommandRegister { // dispatcher.register(literal(Name) // .then(argument("Radius(半径)", LongArgumentType.longArg()) // .then(argument("Origin(随机中心)",EntityArgumentType.player()) -// .requires(source -> source.hasPermissionLevel(4)) +// .requires(source -> source.hasPermissionLevel(PermissionLevel)) // .executes(context -> execute_command_origin( // context.getSource(), // LongArgumentType.getLong(context, "Radius(半径)"), @@ -98,7 +98,7 @@ public class CommandRegister { dispatcher.register(literal(Name) .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -112,7 +112,7 @@ public class CommandRegister { .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command_origin( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -126,7 +126,7 @@ public class CommandRegister { .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -140,7 +140,7 @@ public class CommandRegister { .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command_origin( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -154,7 +154,7 @@ public class CommandRegister { .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("OriginPos(随机中心,坐标)",Vec3ArgumentType.vec3()) - .requires(source -> source.hasPermissionLevel(4)) + .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), @@ -186,20 +186,24 @@ public class CommandRegister { ;Coordinate_Y--){} if (Blocks.WATER == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock() || Blocks.LAVA == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock()){ - Source.getWorld().setBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z)), Blocks.STONE.getDefaultState());} + for (int x = -1; x <= 1; x++) { + for (int z = -1; z <= 1; z++) { + Source.getWorld().setBlockState(new BlockPos(Math.toIntExact(Coordinate_X - x), Coordinate_Y, Math.toIntExact(Coordinate_Z - z)), Blocks.GLASS.getDefaultState());}}} // if ( String.valueOf(entity.getWorld().getBiome(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getKey()).equals("minecraft:the_void") ) { // Coordinate_Y++;} Coordinate_Y++; Vec3d Coordinate = new Vec3d(Coordinate_X, Coordinate_Y, Coordinate_Z); - if (Radius == WorldBorder && Retry < 126 && Distance(entity.getPos(), Coordinate) < 1e5){ + if (Radius == WorldBorder && Retry < 126 && entity.getPos().distanceTo(Coordinate) < 1e5){ Retry++; execute_command(Source, Radius,null, Origin); return 0;} if (Retry >= 126){ Source.sendFeedback(()->{ return Text.translatable("warning.twd.rtp.retry"); }, true);} - entity.teleport(Coordinate_X, Coordinate_Y, Coordinate_Z); + entity.teleport(Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5); + final long FinalCoordinate_X = Coordinate_X; final int FinalCoordinate_Y = Coordinate_Y; - Source.sendFeedback(()->{ return Text.translatable("info.twd.rtp.success", entity.getName(), Coordinate_X, FinalCoordinate_Y, Coordinate_Z); },true); + final long FinalCoordinate_Z = Coordinate_Z; + Source.sendFeedback(()->{ return Text.translatable("info.twd.rtp.success", entity.getName(), FinalCoordinate_X, FinalCoordinate_Y, FinalCoordinate_Z); },true); return 0;} static int execute_command_origin(ServerCommandSource Source, @Nullable Long Radius, @Nullable Entity Player, Entity Origin){ return execute_command(Source, Radius, Player, Origin.getPos());} diff --git a/src/main/java/xyz/thewhitedog9487/Toolbox.java b/src/main/java/xyz/thewhitedog9487/Toolbox.java deleted file mode 100644 index 615d658..0000000 --- a/src/main/java/xyz/thewhitedog9487/Toolbox.java +++ /dev/null @@ -1,10 +0,0 @@ -package xyz.thewhitedog9487; - -import net.minecraft.util.math.Vec3d; - -public class Toolbox { - static public double Distance(Vec3d A, Vec3d B){ - return Math.sqrt( - Math.pow(A.getX() - B.getX(), 2) + - Math.pow(A.getY() - B.getY(), 2));} -} \ No newline at end of file