Search in sources :

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

Example 62 with ICitizenData

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;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) PublicCrafting(com.minecolonies.api.colony.requestsystem.requestable.crafting.PublicCrafting) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Tuple(net.minecraft.util.Tuple) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)

Example 63 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 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);
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) ICitizenData(com.minecolonies.api.colony.ICitizenData) StringTextComponent(net.minecraft.util.text.StringTextComponent) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull)

Example 64 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 : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) 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) StringTextComponent(net.minecraft.util.text.StringTextComponent) 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) 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 65 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(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);
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12