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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations