Search in sources :

Example 1 with ModdedPacketHandler

use of net.modificationstation.stationapi.api.network.ModdedPacketHandler in project StationAPI by ModificationStation.

the class ServerRegistrySender method sendLevelRegistry.

@EventListener(priority = ListenerPriority.HIGH)
private static void sendLevelRegistry(PlayerPacketHandlerSetEvent event) {
    if (((ModdedPacketHandler) event.player.packetHandler).isModded()) {
        LOGGER.info("Sending level registries to \"" + event.player.name + "\"...");
        CompoundTag registries = new CompoundTag();
        LevelSerialRegistry.saveAll(registries);
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        NBTIO.writeGzipped(registries, byteOutputStream);
        Message message = new Message(of(MODID, "server_registry_sync"));
        message.bytes = byteOutputStream.toByteArray();
        PacketHelper.sendTo(event.player, message);
    }
}
Also used : Message(net.modificationstation.stationapi.api.packet.Message) ModdedPacketHandler(net.modificationstation.stationapi.api.network.ModdedPacketHandler) CompoundTag(net.minecraft.util.io.CompoundTag) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Aggregations

EventListener (net.mine_diver.unsafeevents.listener.EventListener)1 CompoundTag (net.minecraft.util.io.CompoundTag)1 ModdedPacketHandler (net.modificationstation.stationapi.api.network.ModdedPacketHandler)1 Message (net.modificationstation.stationapi.api.packet.Message)1