Search in sources :

Example 16 with ICitizenData

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());
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with ICitizenData

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)));
                }
            }
        }
    });
}
Also used : AbstractBuildingModule(com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData) TypeToken(com.google.common.reflect.TypeToken) ItemStack(net.minecraft.item.ItemStack) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ImmutableList(com.google.common.collect.ImmutableList) TAG_CURR_STAGE(com.minecolonies.api.util.constant.NbtTagConstants.TAG_CURR_STAGE) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) TAG_TOTAL_STAGES(com.minecolonies.api.util.constant.NbtTagConstants.TAG_TOTAL_STAGES) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IPersistentModule(com.minecolonies.api.colony.buildings.modules.IPersistentModule) Nullable(org.jetbrains.annotations.Nullable) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryUtils(com.minecolonies.api.util.InventoryUtils) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) IJobWithExternalWorkStations(com.minecolonies.api.colony.jobs.IJobWithExternalWorkStations) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with ICitizenData

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);
}
Also used : AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ICitizenData(com.minecolonies.api.colony.ICitizenData) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 19 with ICitizenData

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);
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 20 with ICitizenData

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());
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)175 NotNull (org.jetbrains.annotations.NotNull)47 IColony (com.minecolonies.api.colony.IColony)45 BlockPos (net.minecraft.util.math.BlockPos)45 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)30 ItemStack (net.minecraft.item.ItemStack)28 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)27 PlayerEntity (net.minecraft.entity.player.PlayerEntity)26 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)17 ArrayList (java.util.ArrayList)16 Colony (com.minecolonies.coremod.colony.Colony)15 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12