use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractAssignedCitizenModule method serializeToView.
@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
buf.writeInt(assignedCitizen.size());
for (@NotNull final ICitizenData citizen : assignedCitizen) {
buf.writeInt(citizen.getId());
}
buf.writeInt(hiringMode.ordinal());
buf.writeInt(getModuleMax());
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractCraftingBuildingModule method getPendingRequestQueue.
/**
* Get a list of all recipeStorages of the pending requests in the crafters queues.
* @return the list.
*/
private List<Tuple<IRecipeStorage, Integer>> getPendingRequestQueue() {
final List<Tuple<IRecipeStorage, Integer>> recipes = new ArrayList<>();
for (final ICitizenData citizen : building.getAllAssignedCitizen()) {
if (citizen.getJob() instanceof AbstractJobCrafter) {
final List<IToken<?>> assignedTasks = new ArrayList<>(citizen.getJob(AbstractJobCrafter.class).getAssignedTasks());
assignedTasks.addAll(citizen.getJob(AbstractJobCrafter.class).getTaskQueue());
for (final IToken<?> taskToken : assignedTasks) {
final IRequest<? extends PublicCrafting> request = (IRequest<? extends PublicCrafting>) building.getColony().getRequestManager().getRequestForToken(taskToken);
final IRecipeStorage recipeStorage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(request.getRequest().getRecipeID());
if (holdsRecipe(request.getRequest().getRecipeID()) && recipeStorage != null) {
recipes.add(new Tuple<>(recipeStorage, request.getRequest().getCount()));
}
}
}
}
return recipes;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class BuildingResourcesModule method serializeToView.
/**
* Method to serialize data to send it to the view.
*
* @param buf the used ByteBuffer.
*/
@Override
public void serializeToView(@NotNull final PacketBuffer buf) {
updateAvailableResources();
buf.writeInt(neededResources.size());
double qty = 0;
for (@NotNull final BuildingBuilderResource resource : neededResources.values()) {
buf.writeItem(resource.getItemStack());
buf.writeInt(resource.getAvailable());
buf.writeInt(resource.getAmount());
qty += resource.getAmount();
}
final Set<ICitizenData> set = building.getAllAssignedCitizen();
final ICitizenData data = set.isEmpty() ? null : set.iterator().next();
if (data != null && data.getJob() instanceof AbstractJobStructure) {
final AbstractJobStructure<?, ?> structureBuilderJob = (AbstractJobStructure<?, ?>) data.getJob();
final IWorkOrder workOrder = structureBuilderJob.getWorkOrder();
if (workOrder != null) {
buf.writeComponent(workOrder.getDisplayName());
buf.writeDouble(workOrder.getAmountOfResources() == 0 ? 0 : qty / workOrder.getAmountOfResources());
buf.writeInt(totalStages);
buf.writeInt(currentStage);
return;
}
}
buf.writeComponent(new StringTextComponent(""));
buf.writeDouble(0.0);
buf.writeInt(0);
buf.writeInt(0);
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class BuildingResourcesModule method updateAvailableResources.
/**
* Update the available resources.
* <p>
* which are needed for the build and in the structureBuilder's chest or inventory
*/
private void updateAvailableResources() {
final Set<ICitizenData> set = building.getAllAssignedCitizen();
final ICitizenData data = set.isEmpty() ? null : set.iterator().next();
if (data == null) {
return;
}
data.getEntity().ifPresent(structureBuilder -> {
final InventoryCitizen structureBuilderInventory = data.getInventory();
if (structureBuilderInventory == null) {
return;
}
for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
final BuildingBuilderResource resource = entry.getValue();
resource.setAvailable(0);
if (structureBuilderInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(structureBuilderInventory, stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
}
if (building.getTileEntity() != null) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(building.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
}
if (data.getJob() instanceof IJobWithExternalWorkStations) {
for (final IBuilding station : ((IJobWithExternalWorkStations) data.getJob()).getWorkStations()) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(station.getCapability(ITEM_HANDLER_CAPABILITY, null).orElseGet(null), stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, resource.getItemStack(), true, true)));
}
}
}
});
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CourierAssignmentModule method deserializeNBT.
@Override
public void deserializeNBT(final CompoundNBT compound) {
super.deserializeNBT(compound);
final CompoundNBT jobCompound = compound.getCompound(getModuleSerializationIdentifier());
final int[] residentIds = jobCompound.getIntArray(TAG_COURIERS);
for (final int citizenId : residentIds) {
final ICitizenData citizen = building.getColony().getCitizenManager().getCivilian(citizenId);
if (citizen != null) {
assignCitizen(citizen);
}
}
}
Aggregations