From e7f9ac069a55fd89f0247bf35d4896df4629af5a Mon Sep 17 00:00:00 2001 From: TheWhiteDog9487 <60037547+TheWhiteDog9487@users.noreply.github.com> Date: Sun, 5 Oct 2025 14:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20=E9=9A=8F=E6=9C=BA=E6=95=B0?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=99=A8=20=E9=9C=80=E8=A6=81=E8=A2=AB?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E7=9A=84=E6=96=B9=E5=9D=97=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20=E5=92=8C=20=E6=9B=BF=E6=8D=A2=E7=9B=AE=E6=A0=87=E6=96=B9?= =?UTF-8?q?=E5=9D=97=20=E6=8F=90=E5=8F=96=E5=88=B0=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=20=E5=B9=B6=E4=B8=94=E8=AE=A9=E9=9A=8F?= =?UTF-8?q?=E6=9C=BA=E6=95=B0=E7=9A=84=E4=B8=8A=E7=95=8C+1=E4=BB=A5?= =?UTF-8?q?=E4=BD=BF=E9=9A=8F=E6=9C=BA=E8=8C=83=E5=9B=B4=E6=88=90=E4=B8=BA?= =?UTF-8?q?=E5=AE=8C=E6=95=B4=E9=97=AD=E5=8C=BA=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/thewhitedog9487/CommandRegister.java | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/thewhitedog9487/CommandRegister.java b/src/main/java/xyz/thewhitedog9487/CommandRegister.java index b747d1e..46b61e3 100644 --- a/src/main/java/xyz/thewhitedog9487/CommandRegister.java +++ b/src/main/java/xyz/thewhitedog9487/CommandRegister.java @@ -14,6 +14,7 @@ import net.minecraft.util.math.Vec2f; import org.jetbrains.annotations.Nullable; import java.util.HashSet; +import java.util.Set; import java.util.SplittableRandom; import static net.minecraft.server.command.CommandManager.argument; @@ -21,6 +22,32 @@ import static net.minecraft.server.command.CommandManager.literal; public class CommandRegister { + /** + * 随机数生成器 + */ + final static SplittableRandom SR = new SplittableRandom(); + + /** + * 传送后用于生成保护平台的方块 + */ + final static Block TargetBlock = Blocks.GLASS; + + /** + * 传送后会被 {@link CommandRegister#TargetBlock} 替换掉的方块 + *
+ * 替换中心:被传送目标脚下方块 + *
+ * 替换范围:替换中心周围半径为一的正方形区域 + */ + final static Set ReplaceToTargetBlock = Set.of( + Blocks.AIR, + Blocks.VOID_AIR, + Blocks.CAVE_AIR, + Blocks.WATER, + Blocks.LAVA, + Blocks.SHORT_GRASS, + Blocks.VINE ); + /** * 世界边界 *
@@ -185,11 +212,11 @@ public class CommandRegister { int Coordinate_Z = 0; try { if (Origin == null){ - Coordinate_X = new SplittableRandom().nextInt(-Radius, Radius); - Coordinate_Z = new SplittableRandom().nextInt(-Radius, Radius);} + Coordinate_X = SR.nextInt(-Radius, Radius + 1); + Coordinate_Z = SR.nextInt(-Radius, Radius + 1); } else{ - 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);}} + Coordinate_X = SR.nextInt((int) Origin.x - Radius, (int) Origin.x + Radius + 1); + Coordinate_Z = SR.nextInt((int) Origin.y - Radius, (int) Origin.y + Radius + 1); } } catch (IllegalArgumentException e) { // 半径为零 if (Origin == null) { @@ -223,6 +250,9 @@ public class CommandRegister { // 只替换空气、水和岩浆,其余保留 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") ) { + if ( ReplaceToTargetBlock.contains(CurrentBlock) ) { + // 只替换ReplaceToTargetBlock内的方块,其余保留 + EntityWorld.setBlockState(BlockPos, TargetBlock.getDefaultState());}}} // Coordinate_Y++;} Coordinate_Y++; // ↑ 高一层,人别站在土里了