1 package com.irtimaled.bbor.common.interop;
3 import com.irtimaled.bbor.common.EventBus;
4 import com.irtimaled.bbor.common.events.*;
5 import com.irtimaled.bbor.common.models.ServerPlayer;
6 import net.minecraft.entity.player.ServerPlayerEntity;
7 import net.minecraft.network.NetworkManager;
8 import net.minecraft.network.play.ServerPlayNetHandler;
9 import net.minecraft.world.ServerWorld;
10 import net.minecraft.world.chunk.Chunk;
11 import net.minecraft.world.gen.feature.structure.StructureStart;
13 import java.util.Collection;
16 public class CommonInterop {
17 public static void chunkLoaded(Chunk chunk) {
18 int dimensionId = chunk.getWorld().getDimension().getType().getId();
19 Map<String, StructureStart> structures = chunk.getStructureStarts();
20 if(structures.size() > 0) EventBus.publish(new StructuresLoaded(structures, dimensionId));
23 public static void loadWorlds(Collection<ServerWorld> worlds) {
24 for (ServerWorld world : worlds) {
29 public static void loadWorld(ServerWorld world) {
30 EventBus.publish(new WorldLoaded(world));
33 public static void tick() {
34 EventBus.publish(new ServerTick());
37 public static void playerLoggedIn(ServerPlayerEntity player) {
38 ServerPlayNetHandler connection = player.connection;
39 if (connection == null) return;
41 NetworkManager networkManager = connection.netManager;
42 if (networkManager.isLocalChannel()) return;
44 EventBus.publish(new PlayerLoggedIn(new ServerPlayer(player)));
47 public static void playerLoggedOut(ServerPlayerEntity player) {
48 EventBus.publish(new PlayerLoggedOut(player.getEntityId()));
51 public static void playerSubscribed(ServerPlayerEntity player) {
52 EventBus.publish(new PlayerSubscribed(player.getEntityId(), new ServerPlayer(player)));