Search in sources :

Example 6 with IVisitorData

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

the class VisitorManager method read.

@Override
public void read(@NotNull final CompoundNBT compound) {
    if (compound.contains(TAG_VISIT_MANAGER)) {
        final CompoundNBT visitorManagerNBT = compound.getCompound(TAG_VISIT_MANAGER);
        final ListNBT citizenList = visitorManagerNBT.getList(TAG_VISITORS, Constants.NBT.TAG_COMPOUND);
        for (final INBT citizen : citizenList) {
            final IVisitorData data = VisitorData.loadVisitorFromNBT(colony, (CompoundNBT) citizen);
            visitorMap.put(data.getId(), data);
        }
        nextVisitorID = visitorManagerNBT.getInt(TAG_NEXTID);
    }
    markDirty();
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) INBT(net.minecraft.nbt.INBT) IVisitorData(com.minecolonies.api.colony.IVisitorData)

Example 7 with IVisitorData

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

the class VisitorManager method spawnOrCreateCivilian.

@Override
public IVisitorData spawnOrCreateCivilian(ICivilianData data, final World world, final BlockPos spawnPos, final boolean force) {
    if (!WorldUtil.isEntityBlockLoaded(world, spawnPos)) {
        return (IVisitorData) data;
    }
    if (data == null) {
        data = createAndRegisterCivilianData();
    }
    VisitorCitizen citizenEntity = (VisitorCitizen) ModEntities.VISITOR.create(colony.getWorld());
    if (citizenEntity == null) {
        return (IVisitorData) data;
    }
    citizenEntity.setPos(spawnPos.getX() + HALF_A_BLOCK, spawnPos.getY() + SLIGHTLY_UP, spawnPos.getZ() + HALF_A_BLOCK);
    world.addFreshEntity(citizenEntity);
    citizenEntity.getCitizenColonyHandler().registerWithColony(data.getColony().getID(), data.getId());
    return (IVisitorData) data;
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) VisitorCitizen(com.minecolonies.coremod.entity.citizen.VisitorCitizen)

Example 8 with IVisitorData

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

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 9 with IVisitorData

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

the class VisitorManager method createAndRegisterCivilianData.

@Override
public IVisitorData createAndRegisterCivilianData() {
    markDirty();
    final IVisitorData data = new VisitorData(nextVisitorID--, colony);
    data.initForNewCivilian();
    visitorMap.put(data.getId(), data);
    return data;
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) VisitorData(com.minecolonies.coremod.colony.VisitorData) IVisitorData(com.minecolonies.api.colony.IVisitorData)

Example 10 with IVisitorData

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

the class VisitorManager method write.

@Override
public void write(@NotNull final CompoundNBT compoundNBT) {
    final CompoundNBT visitorManagerNBT = new CompoundNBT();
    final ListNBT citizenList = new ListNBT();
    for (Map.Entry<Integer, IVisitorData> entry : visitorMap.entrySet()) {
        citizenList.add(entry.getValue().serializeNBT());
    }
    visitorManagerNBT.put(TAG_VISITORS, citizenList);
    visitorManagerNBT.putInt(TAG_NEXTID, nextVisitorID);
    compoundNBT.put(TAG_VISIT_MANAGER, visitorManagerNBT);
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) IVisitorData(com.minecolonies.api.colony.IVisitorData)

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