Search in sources :

Example 1 with TinkerNetwork

use of slimeknights.tconstruct.common.network.TinkerNetwork in project TinkersConstruct by SlimeKnights.

the class MaterialRegistry method sendPackets.

/**
 * Sends all relevant packets to the given player
 */
private void sendPackets(ServerPlayer player, ISimplePacket[] packets) {
    // this event is not fired when connecting to a server
    if (player.connection.getConnection().isMemoryConnection()) {
        // if the packet is being sent to ourself, skip sending, prevents recreating all material instances in the registry a second time on dedicated servers
        // note it will still send the packet if another client connects in LAN
        fullyLoaded = true;
        MinecraftForge.EVENT_BUS.post(new MaterialsLoadedEvent());
    } else {
        TinkerNetwork network = TinkerNetwork.getInstance();
        PacketTarget target = PacketDistributor.PLAYER.with(() -> player);
        for (ISimplePacket packet : packets) {
            network.send(target, packet);
        }
    }
}
Also used : PacketTarget(net.minecraftforge.network.PacketDistributor.PacketTarget) MaterialsLoadedEvent(slimeknights.tconstruct.library.events.MaterialsLoadedEvent) ISimplePacket(slimeknights.mantle.network.packet.ISimplePacket) TinkerNetwork(slimeknights.tconstruct.common.network.TinkerNetwork)

Aggregations

PacketTarget (net.minecraftforge.network.PacketDistributor.PacketTarget)1 ISimplePacket (slimeknights.mantle.network.packet.ISimplePacket)1 TinkerNetwork (slimeknights.tconstruct.common.network.TinkerNetwork)1 MaterialsLoadedEvent (slimeknights.tconstruct.library.events.MaterialsLoadedEvent)1