Search in sources :

Example 71 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding 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 72 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding 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 73 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method destroy.

/**
 * Destroys the block. Calls {@link #onDestroyed()}.
 */
@Override
public final void destroy() {
    onDestroyed();
    colony.getBuildingManager().removeBuilding(this, colony.getPackageManager().getCloseSubscribers());
    colony.getRequestManager().getDataStoreManager().remove(this.rsDataStoreToken);
    for (final BlockPos childpos : getChildren()) {
        final IBuilding building = colony.getBuildingManager().getBuilding(childpos);
        if (building != null) {
            building.destroy();
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockPos(net.minecraft.util.math.BlockPos)

Example 74 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding 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)

Example 75 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method requestUpgrade.

/**
 * Requests an upgrade for the current building.
 *
 * @param player  the requesting player.
 * @param builder the assigned builder.
 */
@Override
public void requestUpgrade(final PlayerEntity player, final BlockPos builder) {
    final ResourceLocation hutResearch = colony.getResearchManager().getResearchEffectIdFrom(this.getBuildingType().getBuildingBlock());
    if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(hutResearch) && colony.getResearchManager().getResearchEffects().getEffectStrength(hutResearch) < 1) {
        MessageUtils.format(WARNING_BUILDING_REQUIRES_RESEARCH_UNLOCK).sendTo(player);
        return;
    }
    if (MinecoloniesAPIProxy.getInstance().getGlobalResearchTree().hasResearchEffect(hutResearch) && (colony.getResearchManager().getResearchEffects().getEffectStrength(hutResearch) <= getBuildingLevel())) {
        MessageUtils.format(WARNING_BUILDING_REQUIRES_RESEARCH_UPGRADE).sendTo(player);
        return;
    }
    final IBuilding parentBuilding = colony.getBuildingManager().getBuilding(getParent());
    if (getBuildingLevel() == 0 && (parentBuilding == null || parentBuilding.getBuildingLevel() > 0)) {
        requestWorkOrder(WorkOrderType.BUILD, builder);
    } else if (getBuildingLevel() < getMaxBuildingLevel() && (parentBuilding == null || getBuildingLevel() < parentBuilding.getBuildingLevel())) {
        requestWorkOrder(WorkOrderType.UPGRADE, builder);
    } else {
        MessageUtils.format(WARNING_NO_UPGRADE).sendTo(player);
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)187 BlockPos (net.minecraft.util.math.BlockPos)71 NotNull (org.jetbrains.annotations.NotNull)45 IColony (com.minecolonies.api.colony.IColony)37 Nullable (org.jetbrains.annotations.Nullable)26 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)24 ICitizenData (com.minecolonies.api.colony.ICitizenData)22 World (net.minecraft.world.World)20 ItemStack (net.minecraft.item.ItemStack)19 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 TileEntity (net.minecraft.tileentity.TileEntity)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)15 ArrayList (java.util.ArrayList)14 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)9 ResourceLocation (net.minecraft.util.ResourceLocation)9 IItemHandler (net.minecraftforge.items.IItemHandler)9 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8