Search in sources :

Example 96 with IBuilding

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

the class EntityAIQuarrier method loadRequirements.

@Override
public IAIState loadRequirements() {
    if (job.getWorkOrder() == null) {
        final IBuilding quarry = job.findQuarry();
        if (quarry == null || quarry.getFirstModuleOccurance(QuarryModule.class).isFinished()) {
            return IDLE;
        }
        final String name = Structures.SCHEMATICS_PREFIX + "/" + quarry.getStyle() + "/" + quarry.getSchematicName() + "shaft1";
        final WorkOrderMiner wo = new WorkOrderMiner(name, name, quarry.getRotation(), quarry.getPosition().below(2), false, building.getPosition());
        building.getColony().getWorkManager().addWorkOrder(wo, false);
        job.setWorkOrder(wo);
    }
    return super.loadRequirements();
}
Also used : WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) IBuilding(com.minecolonies.api.colony.buildings.IBuilding)

Example 97 with IBuilding

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

the class CombatUtils method notifyGuardsOfTarget.

/**
 * Actions on changing to a new target entity
 */
public static void notifyGuardsOfTarget(final AbstractEntityCitizen user, final LivingEntity target, final int callRange) {
    for (final ICitizenData citizen : user.getCitizenData().getWorkBuilding().getAllAssignedCitizen()) {
        if (citizen.getEntity().isPresent() && citizen.getEntity().get().getLastHurtByMob() == null) {
            ((EntityCitizen) citizen.getEntity().get()).getThreatTable().addThreat(target, 0);
        }
    }
    if (target instanceof AbstractEntityMinecoloniesMob) {
        for (final Map.Entry<BlockPos, IBuilding> entry : user.getCitizenColonyHandler().getColony().getBuildingManager().getBuildings().entrySet()) {
            if (entry.getValue() instanceof AbstractBuildingGuards && user.blockPosition().distSqr(entry.getKey()) < callRange) {
                final AbstractBuildingGuards building = (AbstractBuildingGuards) entry.getValue();
                building.setTempNextPatrolPoint(target.blockPosition());
            }
        }
    }
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) AbstractEntityMinecoloniesMob(com.minecolonies.api.entity.mobs.AbstractEntityMinecoloniesMob)

Example 98 with IBuilding

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

the class EntityAIStructureBuilder method checkForWorkOrder.

/**
 * Checks if we got a valid workorder.
 *
 * @return true if we got a workorder to work with
 */
private boolean checkForWorkOrder() {
    if (!job.hasWorkOrder()) {
        building.searchWorkOrder();
        building.setProgressPos(null, BuildingStructureHandler.Stage.CLEAR);
        return false;
    }
    final IWorkOrder wo = job.getWorkOrder();
    if (wo == null) {
        job.setWorkOrder(null);
        building.setProgressPos(null, null);
        return false;
    }
    final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
    if (building == null && wo instanceof WorkOrderBuilding && wo.getWorkOrderType() != WorkOrderType.REMOVE) {
        job.complete();
        return false;
    }
    return true;
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 99 with IBuilding

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

the class EntityAIStructureBuilder method killMobs.

/**
 * Kill all mobs at the building site.
 */
private void killMobs() {
    if (building.getBuildingLevel() >= LEVEL_TO_PURGE_MOBS && job.getWorkOrder().getWorkOrderType() == WorkOrderType.BUILD) {
        final BlockPos buildingPos = job.getWorkOrder().getLocation();
        final IBuilding building = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(buildingPos);
        if (building != null) {
            WorldUtil.getEntitiesWithinBuilding(world, MonsterEntity.class, building, null).forEach(Entity::remove);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 100 with IBuilding

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

the class EntityAIWorkDeliveryman method pickup.

/**
 * Pickup items from a hut that has requested a pickup.
 *
 * @return the next state to go to.
 */
private IAIState pickup() {
    final IRequest<? extends IDeliverymanRequestable> currentTask = job.getCurrentTask();
    if (!(currentTask instanceof PickupRequest)) {
        // The current task has changed since the Decision-state. Restart.
        return START_WORKING;
    }
    if (cannotHoldMoreItems()) {
        this.alreadyKept = new ArrayList<>();
        this.currentSlot = 0;
        return DUMPING;
    }
    worker.getCitizenData().setVisibleStatus(DELIVERING);
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.gathering"));
    final BlockPos pickupTarget = currentTask.getRequester().getLocation().getInDimensionLocation();
    if (pickupTarget != BlockPos.ZERO && !worker.isWorkerAtSiteWithMove(pickupTarget, MIN_DISTANCE_TO_WAREHOUSE)) {
        setDelay(WALK_DELAY);
        return PICKUP;
    }
    final IBuilding pickupBuilding = building.getColony().getBuildingManager().getBuilding(pickupTarget);
    if (pickupBuilding == null) {
        job.finishRequest(false);
        return START_WORKING;
    }
    if (pickupFromBuilding(pickupBuilding)) {
        this.alreadyKept = new ArrayList<>();
        this.currentSlot = 0;
        job.finishRequest(true);
        if (currentTask.getRequest().getPriority() >= PRIORITY_FORCING_DUMP) {
            return DUMPING;
        } else {
            return START_WORKING;
        }
    } else if (InventoryUtils.openSlotCount(worker.getInventoryCitizen()) <= 0) {
        this.alreadyKept = new ArrayList<>();
        this.currentSlot = 0;
        return DUMPING;
    }
    currentSlot++;
    return PICKUP;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) PickupRequest(com.minecolonies.coremod.colony.requestsystem.requests.StandardRequests.PickupRequest) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos)

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