Search in sources :

Example 6 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class EntityCitizen method getDesiredActivity.

@NotNull
public DesiredActivity getDesiredActivity() {
    if (this.getColonyJob() instanceof JobGuard) {
        return DesiredActivity.WORK;
    }
    if (!world.isDaytime()) {
        if (isDay && citizenData != null) {
            isDay = false;
            final AbstractBuildingWorker buildingWorker = getWorkBuilding();
            final double decreaseBy = buildingWorker == null || buildingWorker.getBuildingLevel() == 0 ? 0.1 : (SATURATION_DECREASE_FACTOR * Math.pow(2, buildingWorker.getBuildingLevel() - 1.0));
            citizenData.decreaseSaturation(decreaseBy);
            citizenData.markDirty();
        }
        return DesiredActivity.SLEEP;
    }
    isDay = true;
    if (world.isRaining() && !shouldWorkWhileRaining()) {
        return DesiredActivity.IDLE;
    } else {
        if (this.getNavigator() != null && (this.getNavigator().getPath() != null && this.getNavigator().getPath().getCurrentPathLength() == 0)) {
            this.getNavigator().clearPathEntity();
        }
        return DesiredActivity.WORK;
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class WalkToProxy method fillProxyList.

/**
     * Calculates a list of proxies to a certain target for a worker.
     *
     * @param target         the target.
     * @param distanceToPath the complete distance.
     * @return the first position to path to.
     */
@NotNull
private BlockPos fillProxyList(@NotNull final BlockPos target, final double distanceToPath) {
    final BlockPos proxyPoint;
    final AbstractBuildingWorker building = worker.getWorkBuilding();
    if (worker.getColonyJob() != null && worker.getColonyJob() instanceof JobMiner && building instanceof BuildingMiner) {
        proxyPoint = getMinerProxy(target, distanceToPath, (BuildingMiner) building);
    } else {
        proxyPoint = getProxy(target, worker.getPosition(), distanceToPath);
    }
    if (!proxyList.isEmpty()) {
        proxyList.remove(0);
    }
    return proxyPoint;
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) JobMiner(com.minecolonies.coremod.colony.jobs.JobMiner) BlockPos(net.minecraft.util.math.BlockPos) BuildingMiner(com.minecolonies.coremod.colony.buildings.BuildingMiner) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method goToBuilding.

/**
     * Goes back to the building and tries to take armour from it when he hasn't in his inventory.
     *
     * @return the next state to go to.
     */
protected AIState goToBuilding() {
    if (walkToBuilding()) {
        return AIState.GUARD_RESTOCK;
    }
    final AbstractBuildingWorker workBuilding = getOwnBuilding();
    if (workBuilding != null) {
        final TileEntityColonyBuilding chest = workBuilding.getTileEntity();
        for (int i = 0; i < workBuilding.getTileEntity().getSizeInventory(); i++) {
            final ItemStack stack = chest.getStackInSlot(i);
            if (InventoryUtils.isItemStackEmpty(stack)) {
                continue;
            }
            if (stack.getItem() instanceof ItemArmor && worker.getItemStackFromSlot(((ItemArmor) stack.getItem()).armorType) == null) {
                final int emptySlot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), InventoryUtils::isItemStackEmpty);
                if (emptySlot != -1) {
                    new InvWrapper(worker.getInventoryCitizen()).insertItem(emptySlot, stack, false);
                    chest.setInventorySlotContents(i, ItemStack.EMPTY);
                }
            }
            dumpAfterActions = DUMP_BASE * workBuilding.getBuildingLevel();
        }
    }
    attacksExecuted = 0;
    return AIState.GUARD_SEARCH_TARGET;
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) InventoryUtils(com.minecolonies.api.util.InventoryUtils) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ItemArmor(net.minecraft.item.ItemArmor) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 9 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class RecallCitizenMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final RecallCitizenMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        //Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final AbstractBuildingWorker building = colony.getBuilding(message.buildingId, AbstractBuildingWorker.class);
        if (building != null) {
            EntityCitizen citizen = building.getWorkerEntity();
            if (citizen == null) {
                final CitizenData citizenData = building.getWorker();
                if (citizenData != null) {
                    Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
                    colony.spawnCitizen(citizenData);
                    citizen = citizenData.getCitizenEntity();
                } else {
                    Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
                    return;
                }
            }
            final BlockPos loc = building.getLocation();
            if (!TeleportHelper.teleportCitizen(citizen, colony.getWorld(), loc)) {
                LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
            }
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with AbstractBuildingWorker

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method isInHut.

/**
     * Check all chests in the worker hut for a required item.
     *
     * @param is the type of item requested (amount is ignored)
     * @return true if a stack of that type was found
     */
public boolean isInHut(@Nullable final ItemStack is) {
    @Nullable final AbstractBuildingWorker building = getOwnBuilding();
    boolean hasItem;
    if (building != null) {
        hasItem = isInTileEntity(building.getTileEntity(), is);
        if (hasItem) {
            return true;
        }
        for (final BlockPos pos : building.getAdditionalCountainers()) {
            final TileEntity entity = world.getTileEntity(pos);
            if (entity instanceof TileEntityChest) {
                hasItem = isInTileEntity((TileEntityChest) entity, is);
                if (hasItem) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)10 Nullable (org.jetbrains.annotations.Nullable)6 BlockPos (net.minecraft.util.math.BlockPos)5 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 NotNull (org.jetbrains.annotations.NotNull)3 CitizenData (com.minecolonies.coremod.colony.CitizenData)2 Colony (com.minecolonies.coremod.colony.Colony)2 Block (net.minecraft.block.Block)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 com.minecolonies.api.util (com.minecolonies.api.util)1 InventoryUtils (com.minecolonies.api.util.InventoryUtils)1 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 BlockSolidSubstitution (com.minecolonies.coremod.blocks.BlockSolidSubstitution)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingMiner (com.minecolonies.coremod.colony.buildings.BuildingMiner)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 AbstractJob (com.minecolonies.coremod.colony.jobs.AbstractJob)1