Search in sources :

Example 11 with IVisitorData

use of com.minecolonies.api.colony.IVisitorData in project minecolonies by ldtteam.

the class VisitorManager method sendPackets.

@Override
public void sendPackets(@NotNull final Set<ServerPlayerEntity> closeSubscribers, @NotNull final Set<ServerPlayerEntity> newSubscribers) {
    Set<ServerPlayerEntity> players = new HashSet<>(newSubscribers);
    players.addAll(closeSubscribers);
    Set<IVisitorData> toSend = new HashSet<>();
    boolean refresh = !newSubscribers.isEmpty() || this.isDirty;
    if (refresh) {
        toSend = new HashSet<>(visitorMap.values());
        for (final IVisitorData data : visitorMap.values()) {
            data.clearDirty();
        }
        this.clearDirty();
    } else {
        for (final IVisitorData data : visitorMap.values()) {
            if (data.isDirty()) {
                toSend.add(data);
            }
            data.clearDirty();
        }
    }
    if (toSend.isEmpty()) {
        return;
    }
    final ColonyVisitorViewDataMessage message = new ColonyVisitorViewDataMessage(colony, toSend, refresh);
    for (final ServerPlayerEntity player : players) {
        Network.getNetwork().sendToPlayer(message, player);
    }
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyVisitorViewDataMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage)

Example 12 with IVisitorData

use of com.minecolonies.api.colony.IVisitorData in project minecolonies by ldtteam.

the class VisitorData method loadVisitorFromNBT.

/**
 * Loads this citizen data from nbt
 *
 * @param colony colony to load for
 * @param nbt    nbt compound to read from
 * @return new CitizenData
 */
public static IVisitorData loadVisitorFromNBT(final IColony colony, final CompoundNBT nbt) {
    final IVisitorData data = new VisitorData(nbt.getInt(TAG_ID), colony);
    data.deserializeNBT(nbt);
    return data;
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) IVisitorData(com.minecolonies.api.colony.IVisitorData)

Example 13 with IVisitorData

use of com.minecolonies.api.colony.IVisitorData in project AdvancedPeripherals by Seniorendi.

the class ColonyPeripheral method getVisitors.

@LuaFunction(mainThread = true)
public final Object getVisitors() throws LuaException {
    IColony colony = getColony();
    List<Object> list = new ArrayList<>();
    for (ICivilianData civilian : colony.getVisitorManager().getCivilianDataMap().values()) {
        if (!(civilian instanceof IVisitorData))
            continue;
        list.add(MineColonies.visitorToObject((IVisitorData) civilian));
    }
    return list;
}
Also used : ICivilianData(com.minecolonies.api.colony.ICivilianData) IVisitorData(com.minecolonies.api.colony.IVisitorData) IColony(com.minecolonies.api.colony.IColony) LuaFunction(dan200.computercraft.api.lua.LuaFunction)

Aggregations

IVisitorData (com.minecolonies.api.colony.IVisitorData)13 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 VisitorData (com.minecolonies.coremod.colony.VisitorData)2 VisitorCitizen (com.minecolonies.coremod.entity.citizen.VisitorCitizen)2 ColonyVisitorViewDataMessage (com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 INBT (net.minecraft.nbt.INBT)2 ICivilianData (com.minecolonies.api.colony.ICivilianData)1 IColony (com.minecolonies.api.colony.IColony)1 LuaFunction (dan200.computercraft.api.lua.LuaFunction)1