修改了一下传送落地之后玻璃的放置规则。
- 以前只要脚下是水或岩浆就无条件替换,在极小概率之下可能出现一些麻烦,所以我给改掉了。
- 现在是落地就准备替换,但是只会替换水、岩浆和空气,其他所有都会保留不变。
当然最重要的是适配Minecraft 1.21.2

另外针对开发者侧,Gradle语法从Groovy换到了Kotlin,看起来舒服多了。
This commit is contained in:
2024-10-24 09:54:11 +08:00
parent 6d3af41b34
commit e7c99c2364
4 changed files with 49 additions and 33 deletions

View File

@@ -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 <Radius(半径)> <被传送玩家名(PlayerID)> <OriginPos(随机中心,坐标)>
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)> <Radius(半径)> <OriginPos(随机中心,坐标)>
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());}
}

View File

@@ -28,7 +28,7 @@
],
"depends": {
"fabricloader": ">=0.15.11",
"minecraft": "1.21.1",
"minecraft": "1.21.2",
"java": ">=21",
"fabric-api": "*"
},