From e7c99c23645cc1b0556126f03afbf843b455ab42 Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 Date: Thu, 24 Oct 2024 09:54:11 +0800 Subject: [PATCH] =?UTF-8?q?0.3.2=20=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=E4=BC=A0=E9=80=81=E8=90=BD=E5=9C=B0=E4=B9=8B=E5=90=8E?= =?UTF-8?q?=E7=8E=BB=E7=92=83=E7=9A=84=E6=94=BE=E7=BD=AE=E8=A7=84=E5=88=99?= =?UTF-8?q?=E3=80=82=20-=20=E4=BB=A5=E5=89=8D=E5=8F=AA=E8=A6=81=E8=84=9A?= =?UTF-8?q?=E4=B8=8B=E6=98=AF=E6=B0=B4=E6=88=96=E5=B2=A9=E6=B5=86=E5=B0=B1?= =?UTF-8?q?=E6=97=A0=E6=9D=A1=E4=BB=B6=E6=9B=BF=E6=8D=A2=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=9E=81=E5=B0=8F=E6=A6=82=E7=8E=87=E4=B9=8B=E4=B8=8B=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=87=BA=E7=8E=B0=E4=B8=80=E4=BA=9B=E9=BA=BB=E7=83=A6?= =?UTF-8?q?=EF=BC=8C=E6=89=80=E4=BB=A5=E6=88=91=E7=BB=99=E6=94=B9=E6=8E=89?= =?UTF-8?q?=E4=BA=86=E3=80=82=20-=20=E7=8E=B0=E5=9C=A8=E6=98=AF=E8=90=BD?= =?UTF-8?q?=E5=9C=B0=E5=B0=B1=E5=87=86=E5=A4=87=E6=9B=BF=E6=8D=A2=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E5=8F=AA=E4=BC=9A=E6=9B=BF=E6=8D=A2=E6=B0=B4?= =?UTF-8?q?=E3=80=81=E5=B2=A9=E6=B5=86=E5=92=8C=E7=A9=BA=E6=B0=94=EF=BC=8C?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E6=89=80=E6=9C=89=E9=83=BD=E4=BC=9A=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E4=B8=8D=E5=8F=98=E3=80=82=20=E5=BD=93=E7=84=B6?= =?UTF-8?q?=E6=9C=80=E9=87=8D=E8=A6=81=E7=9A=84=E6=98=AF=E9=80=82=E9=85=8D?= =?UTF-8?q?Minecraft=201.21.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 另外针对开发者侧,Gradle语法从Groovy换到了Kotlin,看起来舒服多了。 --- build.gradle.kts | 15 +++++-- gradle.properties | 22 ++++++---- .../xyz/thewhitedog9487/CommandRegister.java | 43 +++++++++++-------- src/main/resources/fabric.mod.json | 2 +- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7ced6b9..8532aeb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -44,7 +44,9 @@ dependencies { // Uncomment the following line to enable the deprecated Fabric API modules. // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. // "modImplementation"("net.fabricmc.fabric-api:fabric-api-deprecated:${project.extra["fabric_version"]}") - testImplementation("com.terraformersmc:modmenu:${project.extra["modmenu_version"]}") + + // ↓ 开发测试用 + modRuntimeOnly("com.terraformersmc:modmenu:${project.extra["modmenu_version"]}") } tasks.processResources { @@ -72,11 +74,16 @@ java { tasks.jar { from("LICENSE") { rename { "${it}_${project.base.archivesName.get()}" } } - - // https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveFileName - archiveFileName = "${project.base.archivesName.get()}-${project.version} mc${project.extra["minecraft_version"]}.jar" } +tasks.remapJar{ + // https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:archiveFileName + // 用这个属性设置jar包的文件名格式 + // 别用上面那个Jar任务的配置,会被remapJar覆盖掉 + archiveFileName = "${project.base.archivesName.get()}-${project.version} mc${project.extra["minecraft_version"]}.jar"} +tasks.remapSourcesJar{ + archiveFileName = "${project.base.archivesName.get()}-${project.version} mc${project.extra["minecraft_version"]}-sources.jar"} + // configure the maven publication publishing { publications { diff --git a/gradle.properties b/gradle.properties index 4bbe499..2a0315d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,20 +4,24 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.1 -yarn_mappings=1.21.1+build.3 -loader_version=0.15.11 +minecraft_version=1.21.2 +yarn_mappings=1.21.2+build.1 +loader_version=0.16.7 # Mod Properties -mod_version=0.3.1 +mod_version=0.3.2 maven_group=xyz.thewhitedog9487 archives_base_name=randomteleporter # Dependencies -fabric_version=0.102.0+1.21.1 +fabric_version=0.106.1+1.21.2 -loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ -loom_resources_base=https://bmclapi2.bangbang93.com/assets/ -loom_version_manifests=https://bmclapi2.bangbang93.com/mc/game/version_manifest.json -loom_experimental_versions=https://maven.fabricmc.net/net/minecraft/experimental_versions.json +# https://modrinth.com/mod/modmenu/versions +# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu +modmenu_version=12.0.0-beta.1 + +# loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ +# loom_resources_base=https://bmclapi2.bangbang93.com/assets/ +# loom_version_manifests=https://bmclapi2.bangbang93.com/mc/game/version_manifest.json +# loom_experimental_versions=https://maven.fabricmc.net/net/minecraft/experimental_versions.json # loom_fabric_repository=https://repository.hanbings.io/proxy/ \ No newline at end of file diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index 94b51be..63fc067 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -113,11 +113,11 @@ public class CommandRegister { .then(argument("被传送玩家名(PlayerID)", EntityArgumentType.entity()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) - .executes(context -> execute_command_origin( + .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), - EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)")))))));}); + EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos()))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT @@ -141,11 +141,11 @@ public class CommandRegister { .then(argument("Radius(半径)", LongArgumentType.longArg()) .then(argument("OriginEntity(随机中心,实体)",EntityArgumentType.entity()) .requires(source -> source.hasPermissionLevel(PermissionLevel)) - .executes(context -> execute_command_origin( + .executes(context -> execute_command( context.getSource(), LongArgumentType.getLong(context, "Radius(半径)"), EntityArgumentType.getEntity(context,"被传送玩家名(PlayerID)"), - EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)")))))));}); + EntityArgumentType.getEntity(context,"OriginEntity(随机中心,实体)").getPos()))))));}); // /rtp <被传送玩家名(PlayerID)> CommandRegistrationCallback.EVENT @@ -179,25 +179,30 @@ public class CommandRegister { Coordinate_X = new SplittableRandom().nextLong(Math.round(Origin.getX() - Radius), Math.round(Origin.getX() + Radius)); Coordinate_Z = new SplittableRandom().nextLong(Math.round(Origin.getZ() - Radius), Math.round(Origin.getZ() + Radius));} int Coordinate_Y = 320; - for (; - Blocks.AIR == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock() || - Blocks.VOID_AIR == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock() || - Blocks.CAVE_AIR == Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(Coordinate_Z))).getBlock() - ;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()){ + for (var CurrentBlock = Source.getWorld().getBlockState(new BlockPos(Math.toIntExact(Coordinate_X), Coordinate_Y, Math.toIntExact(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()){ + Coordinate_Y--;} 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());}}} + // 如果传送到的位置周围一圈是空气、水或岩浆,将其替换为玻璃 + var BlockPos = new BlockPos(Math.toIntExact(Coordinate_X - x), Coordinate_Y, Math.toIntExact(Coordinate_Z - z)); + var CurrentBlock = Source.getWorld().getBlockState(BlockPos).getBlock(); + if ( CurrentBlock == Blocks.AIR || + CurrentBlock == Blocks.VOID_AIR || + CurrentBlock == Blocks.CAVE_AIR || + CurrentBlock == Blocks.WATER || + CurrentBlock == Blocks.LAVA ){ + // 只替换空气、水和岩浆,其余保留 + Source.getWorld().setBlockState(BlockPos, 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++; - entity.teleport(Source.getWorld(),Coordinate_X + 0.5, Coordinate_Y, Coordinate_Z + 0.5, new HashSet<>(), entity.getYaw(), entity.getPitch()); - final long FinalCoordinate_X = Coordinate_X; - final int FinalCoordinate_Y = Coordinate_Y; - final long FinalCoordinate_Z = Coordinate_Z; - Source.sendFeedback(()->{ return Text.translatable("info.success", entity.getName(), FinalCoordinate_X, FinalCoordinate_Y, FinalCoordinate_Z); },true); + // ↑ 高一层,人别站在土里了 + 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); 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());} } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6ed78f8..47b9670 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ ], "depends": { "fabricloader": ">=0.15.11", - "minecraft": "1.21.1", + "minecraft": "1.21.2", "java": ">=21", "fabric-api": "*" },