From 7e588aae92ac42d5e5c5894ac34f7c99a4a3fc0c Mon Sep 17 00:00:00 2001 From: jimchen5209 Date: Sun, 10 Nov 2024 23:14:29 +0800 Subject: [PATCH] fix: update /home and /spawn --- .../one/oktw/galaxy/command/commands/Home.kt | 49 +++++++++---------- .../one/oktw/galaxy/command/commands/Spawn.kt | 2 +- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt index 9b2289e15..c77157563 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt @@ -21,6 +21,7 @@ package one.oktw.galaxy.command.commands import com.mojang.brigadier.CommandDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import net.minecraft.block.Blocks import net.minecraft.block.RespawnAnchorBlock import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket import net.minecraft.server.command.CommandManager @@ -54,6 +55,7 @@ class Home : Command { lock += player.uuid + // Check Stage val spawnPointPosition = player.spawnPointPosition if (spawnPointPosition == null) { player.sendMessage(Text.translatable("block.minecraft.spawn.not_valid").styled { it.withColor(Formatting.RED) }, false) @@ -61,8 +63,6 @@ class Home : Command { return com.mojang.brigadier.Command.SINGLE_SUCCESS } - val world = source.server.getWorld(player.spawnPointDimension) - val teleportTarget = player.getRespawnTarget(player.notInAnyWorld, TeleportTarget.NO_OP) if (teleportTarget.missingRespawnBlock()) { player.sendMessage(Text.translatable("block.minecraft.spawn.not_valid").styled { it.withColor(Formatting.RED) }, false) @@ -70,6 +70,7 @@ class Home : Command { } else { main?.launch { // Add back charge in countdown stage + val world = source.server.getWorld(player.spawnPointDimension) if (world != null) { val blockState = world.getBlockState(spawnPointPosition) if (blockState.block is RespawnAnchorBlock) { @@ -86,43 +87,37 @@ class Home : Command { } player.sendMessage(Text.translatable("Respond.TeleportStart").styled { it.withColor(Formatting.GREEN) }, true) - // Check Again - val teleportTargetDoubleCheck = player.getRespawnTarget(player.notInAnyWorld, TeleportTarget.NO_OP) - - if (teleportTargetDoubleCheck.missingRespawnBlock()) { + // Check Again (Actual Teleport Stage) + val realTeleportTarget = player.getRespawnTarget(player.notInAnyWorld, TeleportTarget.NO_OP) + if (realTeleportTarget.missingRespawnBlock()) { player.sendMessage(Text.translatable("block.minecraft.spawn.not_valid").styled { it.withColor(Formatting.RED) }, false) lock -= player.uuid return@launch } - val world2 = if (world != null && !teleportTargetDoubleCheck.missingRespawnBlock()) world else source.server.overworld - val position = teleportTarget.pos() - player.teleport( - world2, - position.x, - position.y, - position.z, - player.yaw, - player.pitch - ) + player.teleportTo(realTeleportTarget) - val blockState = world2.getBlockState(spawnPointPosition) - if (!player.notInAnyWorld && blockState.block is RespawnAnchorBlock) { - player.networkHandler.sendPacket( - PlaySoundS2CPacket( + val realSpawnPointPosition = player.spawnPointPosition + val realWorld = source.server.getWorld(player.spawnPointDimension) + if (realWorld != null && realSpawnPointPosition != null) { + val blockState = realWorld.getBlockState(realSpawnPointPosition) + if (!player.notInAnyWorld && blockState.isOf(Blocks.RESPAWN_ANCHOR)) { + player.networkHandler.sendPacket( + PlaySoundS2CPacket( SoundEvents.BLOCK_RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, - spawnPointPosition.x.toDouble(), - spawnPointPosition.y.toDouble(), - spawnPointPosition.z.toDouble(), + realSpawnPointPosition.x.toDouble(), + realSpawnPointPosition.y.toDouble(), + realSpawnPointPosition.z.toDouble(), 1.0f, 1.0f, - world2.getRandom().nextLong() + realWorld.getRandom().nextLong() ) - ) - } + ) + } - lock -= player.uuid + lock -= player.uuid + } } } return com.mojang.brigadier.Command.SINGLE_SUCCESS diff --git a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt index 1bf4d61af..d06b3f52f 100644 --- a/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt +++ b/src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt @@ -94,7 +94,7 @@ class Spawn : Command { player.refreshPositionAndAngles(spawnPosition, 0.0f, 0.0f) } - while (!world.isSpaceEmpty(player) && player.y < world.topY) { + while (!world.isSpaceEmpty(player) && player.y < world.topYInclusive) { player.updatePosition(player.x, player.y + 1, player.z) } player.networkHandler.requestTeleport(player.x, player.y, player.z, player.yaw, player.pitch)