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());
}
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 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 WorkOrderBuildDecoration workOrderBuildDecoration = structureBuilderJob.getWorkOrder();
if (workOrderBuildDecoration != null) {
final String name = workOrderBuildDecoration.getDisplayName();
buf.writeUtf(name);
buf.writeDouble(workOrderBuildDecoration.getAmountOfRes() == 0 ? 0 : qty / workOrderBuildDecoration.getAmountOfRes());
buf.writeInt(totalStages);
buf.writeInt(currentStage);
return;
}
}
buf.writeUtf("");
buf.writeDouble(0.0);
buf.writeInt(0);
buf.writeInt(0);
}
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("warehouse");
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);
}
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class PublicWorkerCraftingProductionResolver method removeRequestFromTaskList.
private void removeRequestFromTaskList(@NotNull final IRequest<? extends PublicCrafting> completedRequest, final IColony colony) {
final ICitizenData holdingCrafter = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof AbstractJobCrafter && (((AbstractJobCrafter<?, ?>) c.getJob()).getTaskQueue().contains(completedRequest.getId()) || ((AbstractJobCrafter<?, ?>) c.getJob()).getAssignedTasks().contains(completedRequest.getId()))).findFirst().orElse(null);
if (holdingCrafter != null) {
final AbstractJobCrafter<?, ?> job = (AbstractJobCrafter<?, ?>) holdingCrafter.getJob();
job.onTaskDeletion(completedRequest.getId());
}
}
Aggregations