Search in sources :

Example 1 with IVisitorData

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

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

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

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

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

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

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

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

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

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