@@ -13,8 +13,11 @@ import com.mairwunnx.projectessentials.spawn.commands.SetSpawnCommand
1313import com.mairwunnx.projectessentials.spawn.commands.SpawnCommand
1414import com.mairwunnx.projectessentials.spawn.configurations.SpawnConfiguration
1515import net.minecraft.entity.player.ServerPlayerEntity
16+ import net.minecraft.util.math.BlockPos
1617import net.minecraft.world.dimension.DimensionType
1718import net.minecraftforge.common.MinecraftForge.EVENT_BUS
19+ import net.minecraftforge.event.entity.player.PlayerEvent
20+ import net.minecraftforge.eventbus.api.EventPriority
1821import net.minecraftforge.eventbus.api.SubscribeEvent
1922import net.minecraftforge.fml.InterModComms
2023import net.minecraftforge.fml.common.Mod
@@ -56,6 +59,25 @@ class ModuleObject : IModule {
5659 firstSessionSpawnPoint(event)
5760 }
5861
62+ @SubscribeEvent(priority = EventPriority .HIGHEST )
63+ fun onPlayerRespawn (event : PlayerEvent .PlayerRespawnEvent ) {
64+ val player = event.player as ServerPlayerEntity
65+ if (player.bedPosition.isPresent) {
66+ player.server.worlds.forEach {
67+ val pos = player.getBedLocation(it.dimension.type) as BlockPos ?
68+ if (pos != null ) {
69+ player.teleport(
70+ it,
71+ pos.x.toDouble() + 0.5 , pos.y.toDouble() + 0.5 , pos.z.toDouble() + 0.5 ,
72+ player.rotationYaw, player.rotationPitch
73+ )
74+ }
75+ }
76+ } else {
77+ forceTeleportToSpawn(player)
78+ }
79+ }
80+
5981 private fun firstSessionSpawnPoint (event : FMLServerStartingEvent ) {
6082 val world = event.server.getWorld(DimensionType .OVERWORLD )
6183 if (firstLaunch) {
0 commit comments