From 7376393f37888e9847e5cf1614a1b0214946a8c9 Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Fri, 25 Oct 2024 14:53:42 +0800 Subject: [PATCH] =?UTF-8?q?0.3.4=20=E5=81=B6=E7=84=B6=E9=97=B4=E8=A7=82?= =?UTF-8?q?=E6=B5=8B=E5=88=B0=E4=B8=80=E4=B8=AA=E5=9C=A8=E6=9E=81=E7=AB=AF?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=B8=8B=E5=87=BA=E7=8E=B0=E7=9A=84Bug?= =?UTF-8?q?=EF=BC=8C=E7=94=B1=E4=B8=8A=E4=B8=80=E4=B8=AA=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=20Vec3d=20=E2=86=92=20Vec2f=20?= =?UTF-8?q?=E5=BC=95=E5=85=A5=EF=BC=8C=E8=B5=B6=E7=B4=A7=E7=BB=99=E5=AE=83?= =?UTF-8?q?=E4=BF=AE=E4=BA=86=20=E8=BF=99=E6=98=AF=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=A4=8D=E7=8E=B0=E7=9A=84=E4=BE=8B=E5=AD=90?= =?UTF-8?q?=EF=BC=9A/rtp=20@s=201=20-23604356.50=2023511080.50=20=E8=BF=99?= =?UTF-8?q?=E4=B8=AA=E7=89=88=E6=9C=AC=E5=B7=B2=E7=BB=8F=E6=B2=A1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../xyz/thewhitedog9487/CommandRegister.java | 67 ++++++++++--------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9d9cee2..24019ac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.21.3+build.2 loader_version=0.16.7 # Mod Properties -mod_version=0.3.3 +mod_version=0.3.4 maven_group=xyz.thewhitedog9487 archives_base_name=RandomTeleporter diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index 31ae307..8d6892c 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -1,6 +1,6 @@ package xyz.thewhitedog9487; -import com.mojang.brigadier.arguments.LongArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.block.Blocks; import net.minecraft.command.argument.EntityArgumentType; @@ -19,7 +19,7 @@ import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class CommandRegister { - final static long WorldBorder = (long) 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 @@ -37,11 +37,11 @@ public class CommandRegister { CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), null, null))));}); @@ -61,12 +61,12 @@ public class CommandRegister { CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), null)))));}); @@ -75,11 +75,11 @@ public class CommandRegister { .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), null)))));}); @@ -99,12 +99,12 @@ public class CommandRegister { CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), null, Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)"))))));}); @@ -112,28 +112,28 @@ public class CommandRegister { CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), - new Vec2f( (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().x, - (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().y)))))));}); + new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, + (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));}); @@ -142,60 +142,61 @@ public class CommandRegister { .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), - new Vec2f( (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().x, - (float) EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos().y)))))));}); + new Vec2f( (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().x, + (float) EntityArgumentType.getEntity( context,"OriginEntity(随机中心,实体)").getPos().y )))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT .register((dispatcher, registryAccess, environment) -> { dispatcher.register(literal(Name) .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) - .then(argument("Radius(半径)", LongArgumentType.longArg()) + .then(argument("Radius(半径)", IntegerArgumentType.integer()) .then(argument("OriginPos(随机中心,坐标)",Vec2ArgumentType.vec2()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) .executes(context -> execute_command( context.getSource(), - LongArgumentType.getLong(context, "Radius(半径)"), + IntegerArgumentType.getInteger(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), Vec2ArgumentType.getVec2(context,"OriginPos(随机中心,坐标)")))))));});} + public static void Register(){ Register("随机传送"); Register("rtp");} - static int execute_command(ServerCommandSource Source, @Nullable Long 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; if (entity == null) { Source.sendFeedback(()->{ return Text.translatable("error.not_player"); }, true); return -1;} - if (Radius == null){Radius = WorldBorder - (long) 1e4;} + if (Radius == null){Radius = (int) (WorldBorder - 1e4);} // ↑ 远离世界边界 Radius = Math.abs(Radius); - long Coordinate_X; - long Coordinate_Z; + int Coordinate_X; + int Coordinate_Z; if (Origin == null){ - Coordinate_X = new SplittableRandom().nextLong(-Radius, Radius); - Coordinate_Z = new SplittableRandom().nextLong(-Radius, Radius);} + Coordinate_X = new SplittableRandom().nextInt(-Radius, Radius); + Coordinate_Z = new SplittableRandom().nextInt(-Radius, Radius);} else{ - Coordinate_X = new SplittableRandom().nextLong(Math.round(Origin.x - Radius), Math.round(Origin.x + Radius)); - Coordinate_Z = new SplittableRandom().nextLong(Math.round(Origin.y - Radius), Math.round(Origin.y + Radius));} + Coordinate_X = new SplittableRandom().nextInt((int) Origin.x - Radius, (int) Origin.x + Radius); + Coordinate_Z = new SplittableRandom().nextInt((int) Origin.y - Radius, (int) Origin.y + Radius);} 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(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock(); // 从世界顶层往下找,直到遇到一个非空气方块 Blocks.AIR == CurrentBlock || Blocks.VOID_AIR == CurrentBlock || Blocks.CAVE_AIR == CurrentBlock - ;CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock()){ + ;CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Coordinate_X, Coordinate_Y, Coordinate_Z)).getBlock()){ Coordinate_Y--;} for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { // 如果传送到的位置周围一圈是空气、水或岩浆,将其替换为玻璃 - var BlockPos = new BlockPos(Math.toIntExact(Coordinate_X - x), Coordinate_Y, Math.toIntExact(Coordinate_Z - z)); + var BlockPos = new BlockPos(Coordinate_X - x, Coordinate_Y, Coordinate_Z - z); var CurrentBlock = Source.getWorld().getBlockState(BlockPos).getBlock(); if ( CurrentBlock == Blocks.AIR || CurrentBlock == Blocks.VOID_AIR ||