Search in sources :

Example 1 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.

the class BuildingBuilder method searchWorkOrder.

@Override
public void searchWorkOrder() {
    final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
    if (citizen == null) {
        return;
    }
    final List<IWorkOrder> list = getColony().getWorkManager().getOrderedList(wo -> wo.canBeMadeBy(citizen.getJob()), getPosition());
    list.sort((a, b) -> {
        if (a.getWorkOrderType() == WorkOrderType.REMOVE) {
            return -1;
        }
        if (b.getWorkOrderType() == WorkOrderType.REMOVE) {
            return 1;
        }
        return 0;
    });
    final IWorkOrder order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
    if (order != null) {
        citizen.getJob(JobBuilder.class).setWorkOrder(order);
        order.setClaimedBy(citizen);
        return;
    }
    if (getManualMode()) {
        return;
    }
    for (final IWorkOrder wo : list) {
        double distanceToBuilder = Double.MAX_VALUE;
        if (wo instanceof WorkOrderBuilding && wo.getWorkOrderType() != WorkOrderType.REMOVE && !wo.canBuild(citizen)) {
            continue;
        }
        for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
            final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
            if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
                continue;
            }
            if (!job.hasWorkOrder() && wo instanceof WorkOrderBuilding && wo.canBuild(otherBuilder)) {
                final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getLocation());
                if (distance < distanceToBuilder) {
                    distanceToBuilder = distance;
                }
            }
        }
        if (citizen.getWorkBuilding().getID().distSqr(wo.getLocation()) < distanceToBuilder) {
            citizen.getJob(JobBuilder.class).setWorkOrder(wo);
            wo.setClaimedBy(citizen);
            return;
        }
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.

the class AbstractEntityAIStructureWithWorkOrder method loadRequirements.

/**
 * Takes the existing workorder, loads the structure and tests the worker order if it is valid.
 */
@Override
public IAIState loadRequirements() {
    if (!job.hasBlueprint() || structurePlacer == null) {
        loadStructure();
        final IWorkOrder wo = job.getWorkOrder();
        if (wo == null) {
            Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()), new Exception());
            job.setWorkOrder(null);
            return IDLE;
        }
        if (wo instanceof WorkOrderBuilding) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Starting and missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()), new Exception());
                return IDLE;
            }
            worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName());
            // Don't go through the CLEAR stage for repairs and upgrades
            if (building.getBuildingLevel() > 0) {
                wo.setCleared(true);
            }
        } else if (!(wo instanceof WorkOrderMiner)) {
            worker.getCitizenChatHandler().sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START, job.getWorkOrder().getDisplayName());
        }
        return getState();
    }
    if (job.getWorkOrder().isRequested()) {
        return afterStructureLoading();
    }
    // We need to deal with materials
    requestMaterialsState();
    return getState();
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 3 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.

the class AbstractEntityAIStructureWithWorkOrder method executeSpecificCompleteActions.

@Override
public void executeSpecificCompleteActions() {
    if (job.getBlueprint() == null && job.hasWorkOrder()) {
        // fix for bad structures
        job.complete();
    }
    if (job.getBlueprint() == null) {
        return;
    }
    final IWorkOrder wo = job.getWorkOrder();
    if (wo == null) {
        Log.getLogger().error(String.format("Worker (%d:%d) ERROR - Finished, but missing work order(%d)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
    } else {
        // TODO: Preferably want to use the display name of the building (in order to respect custom name) however this will require an event rework so it stores text components rather than strings
        String workOrderName = wo.getWorkOrderName();
        sendCompletionMessage(wo);
        switch(wo.getWorkOrderType()) {
            case BUILD:
                job.getColony().getEventDescriptionManager().addEventDescription(new BuildingBuiltEvent(wo.getLocation(), workOrderName));
                break;
            case UPGRADE:
                job.getColony().getEventDescriptionManager().addEventDescription(new BuildingUpgradedEvent(wo.getLocation(), workOrderName, wo.getTargetLevel()));
                break;
            case REPAIR:
                job.getColony().getEventDescriptionManager().addEventDescription(new BuildingRepairedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel()));
                break;
            case REMOVE:
                job.getColony().getEventDescriptionManager().addEventDescription(new BuildingDeconstructedEvent(wo.getLocation(), workOrderName, wo.getCurrentLevel()));
                break;
        }
        job.complete();
        if (wo instanceof WorkOrderBuilding) {
            final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
            switch(wo.getWorkOrderType()) {
                case BUILD:
                case UPGRADE:
                case REPAIR:
                    if (building == null) {
                        Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()));
                    } else {
                        // Normally levels are done through the schematic data, but in case it is missing we do it manually here.
                        final TileEntity te = worker.level.getBlockEntity(building.getID());
                        if (te instanceof AbstractTileEntityColonyBuilding && ((IBlueprintDataProvider) te).getSchematicName().isEmpty()) {
                            building.onUpgradeComplete(wo.getTargetLevel());
                            building.setBuildingLevel(wo.getTargetLevel());
                        }
                    }
                    break;
                case REMOVE:
                    if (building == null) {
                        Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Finished, but missing building(%s)", worker.getCitizenColonyHandler().getColony().getID(), worker.getCitizenData().getId(), wo.getLocation()));
                    } else {
                        building.setDeconstructed();
                    }
                    break;
            }
        }
    }
    building.resetNeededResources();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BuildingRepairedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingRepairedEvent) BuildingDeconstructedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingDeconstructedEvent) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) BuildingBuiltEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingBuiltEvent) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BuildingUpgradedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingUpgradedEvent) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 4 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method calculateCorners.

@Override
public void calculateCorners() {
    final AbstractTileEntityColonyBuilding te = getTileEntity();
    if (te != null && !te.getSchematicName().isEmpty()) {
        setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
        return;
    }
    final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, this);
    final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (!wrapper.hasBluePrint()) {
        setCorners(getPosition(), getPosition());
        return;
    }
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(), workOrder.isMirrored());
    this.setCorners(corners.getA(), corners.getB());
}
Also used : AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) BlockPos(net.minecraft.util.math.BlockPos) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 5 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method setCustomBuildingName.

/**
 * Set the custom building name of the building.
 *
 * @param name the name to set.
 */
@Override
public void setCustomBuildingName(final String name) {
    this.customName = name;
    this.markDirty();
    this.colony.getWorkManager().getWorkOrders().values().stream().filter(f -> f instanceof WorkOrderBuilding).map(m -> (WorkOrderBuilding) m).filter(f -> f.getLocation().equals(this.getID()) || this.getChildren().contains(f.getLocation())).forEach(f -> {
        IBuilding building = this.colony.getBuildingManager().getBuilding(f.getLocation());
        if (building != null) {
            f.setCustomName(building);
            this.colony.getWorkManager().setDirty(true);
        }
    });
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) ChunkDataHelper(com.minecolonies.coremod.util.ChunkDataHelper) IItemHandler(net.minecraftforge.items.IItemHandler) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BuildingRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.BuildingRequestResolver) ISchematicProvider(com.minecolonies.api.colony.buildings.ISchematicProvider) UNCHECKED(com.minecolonies.api.util.constant.Suppression.UNCHECKED) SettingKey(com.minecolonies.coremod.colony.buildings.modules.settings.SettingKey) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AirBlock(net.minecraft.block.AirBlock) ImmutableCollection(com.google.common.collect.ImmutableCollection) CompoundNBT(net.minecraft.nbt.CompoundNBT) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractJobCrafter(com.minecolonies.coremod.colony.jobs.AbstractJobCrafter) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) Block(net.minecraft.block.Block) WorkOrderType(com.minecolonies.api.colony.workorders.WorkOrderType) StringTextComponent(net.minecraft.util.text.StringTextComponent) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) BlockState(net.minecraft.block.BlockState) Constants(com.minecolonies.api.util.constant.Constants) ListNBT(net.minecraft.nbt.ListNBT) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ISetting(com.minecolonies.api.colony.buildings.modules.settings.ISetting) Predicate(java.util.function.Predicate) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) BoolSetting(com.minecolonies.coremod.colony.buildings.modules.settings.BoolSetting) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) NO_WORK_ORDER(com.minecolonies.api.util.constant.BuildingConstants.NO_WORK_ORDER) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) StandardRequests(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests) GENERIC_WILDCARD(com.minecolonies.api.util.constant.Suppression.GENERIC_WILDCARD) com.minecolonies.api.colony.buildings.modules(com.minecolonies.api.colony.buildings.modules) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) Pickup(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Pickup) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) AbstractDeliverymanRequestable.getPlayerActionPriority(com.minecolonies.api.colony.requestsystem.requestable.deliveryman.AbstractDeliverymanRequestable.getPlayerActionPriority) ISettingKey(com.minecolonies.api.colony.buildings.modules.settings.ISettingKey) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ICitizenData(com.minecolonies.api.colony.ICitizenData) EntityAIWorkDeliveryman(com.minecolonies.coremod.entity.ai.citizen.deliveryman.EntityAIWorkDeliveryman) TypeToken(com.google.common.reflect.TypeToken) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) RequestSystemTranslationConstants(com.minecolonies.api.util.constant.translation.RequestSystemTranslationConstants) BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) MOD_ID(com.minecolonies.api.util.constant.Constants.MOD_ID) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) com.minecolonies.api.util(com.minecolonies.api.util) IRetryingRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.retrying.IRetryingRequestResolver) MinecoloniesTileEntities(com.minecolonies.api.tileentities.MinecoloniesTileEntities) IStandardRequestManager(com.minecolonies.coremod.colony.requestsystem.management.IStandardRequestManager) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) CONST_DEFAULT_MAX_BUILDING_LEVEL(com.minecolonies.api.util.constant.BuildingConstants.CONST_DEFAULT_MAX_BUILDING_LEVEL) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) RequestBasedInteraction(com.minecolonies.coremod.colony.interactionhandling.RequestBasedInteraction) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) Tuple(net.minecraft.util.Tuple) BlockPos(net.minecraft.util.math.BlockPos) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) IPlayerRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.player.IPlayerRequestResolver) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) TileEntity(net.minecraft.tileentity.TileEntity) IRequestSystemBuildingDataStore(com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore) PacketBuffer(net.minecraft.network.PacketBuffer) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Aggregations

WorkOrderBuilding (com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)10 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)7 IWorkOrder (com.minecolonies.api.colony.workorders.IWorkOrder)6 BlockPos (net.minecraft.util.math.BlockPos)4 NotNull (org.jetbrains.annotations.NotNull)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)3 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)3 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)2 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 TypeToken (com.google.common.reflect.TypeToken)1 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)1 StructureName (com.ldtteam.structurize.management.StructureName)1 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)1 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)1 IColony (com.minecolonies.api.colony.IColony)1