Skip to content

Commit

Permalink
fix: update /home and /spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchen5209 committed Nov 10, 2024
1 parent 04fe2a3 commit 7e588aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 28 deletions.
49 changes: 22 additions & 27 deletions src/main/kotlin/one/oktw/galaxy/command/commands/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,22 +55,22 @@ 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)
lock -= player.uuid
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)
lock -= player.uuid
} 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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/one/oktw/galaxy/command/commands/Spawn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7e588aa

Please sign in to comment.