Skip to content

Commit f5008e2

Browse files
davenonymousthraaawn
authored andcommitted
Prevent players from flying/being outside the hub
Just teleport them straight to the hub spawn point.
1 parent ba7783f commit f5008e2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/org/dave/compactmachines3/skyworld/SkyWorldEvents.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,33 @@
77
import net.minecraftforge.event.world.BlockEvent;
88
import net.minecraftforge.event.world.WorldEvent;
99
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
10+
import net.minecraftforge.fml.common.gameevent.TickEvent;
1011
import org.dave.compactmachines3.utility.Logz;
1112

1213
public class SkyWorldEvents {
14+
@SubscribeEvent
15+
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
16+
World world = event.player.world;
17+
if(world.isRemote || !(world instanceof WorldServer)) {
18+
return;
19+
}
20+
21+
if(event.player.isCreative() || event.player.isSpectator()) {
22+
return;
23+
}
24+
25+
WorldServer worldServer = (WorldServer)world;
26+
if(!(worldServer.getChunkProvider().chunkGenerator instanceof SkyChunkGenerator)) {
27+
return;
28+
}
29+
30+
if(event.player.posY > 49.0f || event.player.posY < 39.5f) {
31+
BlockPos spawnPoint = worldServer.getSpawnPoint();
32+
event.player.setPositionAndUpdate(spawnPoint.getX() + 0.5d, spawnPoint.getY() + 0.2d, spawnPoint.getZ() + 0.5d);
33+
return;
34+
}
35+
}
36+
1337
@SubscribeEvent
1438
public static void createSpawnPoint(WorldEvent.CreateSpawnPosition event) {
1539
World world = event.getWorld();

0 commit comments

Comments
 (0)