@@ -13,8 +13,11 @@ import com.mairwunnx.projectessentials.spawn.commands.SetSpawnCommand
13
13
import com.mairwunnx.projectessentials.spawn.commands.SpawnCommand
14
14
import com.mairwunnx.projectessentials.spawn.configurations.SpawnConfiguration
15
15
import net.minecraft.entity.player.ServerPlayerEntity
16
+ import net.minecraft.util.math.BlockPos
16
17
import net.minecraft.world.dimension.DimensionType
17
18
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
19
+ import net.minecraftforge.event.entity.player.PlayerEvent
20
+ import net.minecraftforge.eventbus.api.EventPriority
18
21
import net.minecraftforge.eventbus.api.SubscribeEvent
19
22
import net.minecraftforge.fml.InterModComms
20
23
import net.minecraftforge.fml.common.Mod
@@ -56,6 +59,25 @@ class ModuleObject : IModule {
56
59
firstSessionSpawnPoint(event)
57
60
}
58
61
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
+
59
81
private fun firstSessionSpawnPoint (event : FMLServerStartingEvent ) {
60
82
val world = event.server.getWorld(DimensionType .OVERWORLD )
61
83
if (firstLaunch) {
0 commit comments