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