@@ -4,16 +4,35 @@ package com.mairwunnx.projectessentials.spawn
4
4
5
5
import com.mairwunnx.projectessentials.core.api.v1.IMCLocalizationMessage
6
6
import com.mairwunnx.projectessentials.core.api.v1.IMCProvidersMessage
7
+ import com.mairwunnx.projectessentials.core.api.v1.configuration.ConfigurationAPI.getConfigurationByName
7
8
import com.mairwunnx.projectessentials.core.api.v1.events.ModuleEventAPI.subscribeOn
8
9
import com.mairwunnx.projectessentials.core.api.v1.events.forge.ForgeEventType
9
10
import com.mairwunnx.projectessentials.core.api.v1.events.forge.InterModEnqueueEventData
10
11
import com.mairwunnx.projectessentials.core.api.v1.module.IModule
11
12
import com.mairwunnx.projectessentials.spawn.commands.SetSpawnCommand
12
13
import com.mairwunnx.projectessentials.spawn.commands.SpawnCommand
13
14
import com.mairwunnx.projectessentials.spawn.configurations.SpawnConfiguration
15
+ import net.minecraft.entity.player.ServerPlayerEntity
16
+ import net.minecraft.world.dimension.DimensionType
14
17
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
18
+ import net.minecraftforge.eventbus.api.SubscribeEvent
15
19
import net.minecraftforge.fml.InterModComms
16
20
import net.minecraftforge.fml.common.Mod
21
+ import net.minecraftforge.fml.event.server.FMLServerStartingEvent
22
+
23
+ var firstLaunch = false
24
+ val spawnConfiguration by lazy {
25
+ getConfigurationByName<SpawnConfiguration >(" spawn" )
26
+ }
27
+
28
+ fun forceTeleportToSpawn (player : ServerPlayerEntity ) {
29
+ val targetWorld = player.server.getWorld(
30
+ DimensionType .getById(spawnConfiguration.take().dimensionId) ? : DimensionType .OVERWORLD
31
+ )
32
+ with (spawnConfiguration.take()) {
33
+ player.teleport(targetWorld, xPos + 0.5 , yPos + 0.5 , zPos + 0.5 , yaw, pitch)
34
+ }
35
+ }
17
36
18
37
@Mod(" project_essentials_spawn" )
19
38
class ModuleObject : IModule {
@@ -32,6 +51,20 @@ class ModuleObject : IModule {
32
51
}
33
52
}
34
53
54
+ @SubscribeEvent
55
+ fun onServerStarting (event : FMLServerStartingEvent ) {
56
+ firstSessionSpawnPoint(event)
57
+ }
58
+
59
+ private fun firstSessionSpawnPoint (event : FMLServerStartingEvent ) {
60
+ val world = event.server.getWorld(DimensionType .OVERWORLD )
61
+ if (firstLaunch) {
62
+ spawnConfiguration.take().xPos = world.spawnPoint.x
63
+ spawnConfiguration.take().yPos = world.spawnPoint.y
64
+ spawnConfiguration.take().zPos = world.spawnPoint.z
65
+ }
66
+ }
67
+
35
68
private fun sendLocalizationRequest () {
36
69
InterModComms .sendTo(
37
70
" project_essentials_core" ,
0 commit comments