Search in sources :

Example 6 with WorkOrderBuilding

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

the class AbstractBuilding method removeWorkOrder.

/**
 * Remove the work order for the building.
 * <p>
 * Remove either the upgrade or repair work order
 */
@Override
public void removeWorkOrder() {
    for (@NotNull final WorkOrderBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuilding.class)) {
        if (o.getLocation().equals(getID())) {
            colony.getWorkManager().removeWorkOrder(o.getID());
            markDirty();
            final BlockPos buildingPos = o.getClaimedBy();
            final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
            if (building != null) {
                for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
                    for (final ICitizenData citizen : module.getAssignedCitizen()) {
                        building.cancelAllRequestsOfCitizen(citizen);
                    }
                }
            }
            return;
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with WorkOrderBuilding

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding 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 8 with WorkOrderBuilding

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

the class AbstractBuilding method requestWorkOrder.

/**
 * Adds work orders to the {@link Colony#getWorkManager()}.
 *
 * @param type    what to do with the work order
 * @param builder the assigned builder.
 */
protected void requestWorkOrder(WorkOrderType type, final BlockPos builder) {
    for (@NotNull final WorkOrderBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuilding.class)) {
        if (o.getLocation().equals(getID())) {
            return;
        }
    }
    WorkOrderBuilding workOrder = WorkOrderBuilding.create(type, this);
    if (type == WorkOrderType.REMOVE && !canDeconstruct()) {
        MessageUtils.format(BUILDER_CANNOT_DECONSTRUCT).sendTo(colony).forAllPlayers();
        return;
    }
    if (type == WorkOrderType.REMOVE && !canBeBuiltByBuilder(workOrder.getTargetLevel()) && !workOrder.canBeResolved(colony, workOrder.getTargetLevel())) {
        MessageUtils.format(BUILDER_NECESSARY, Integer.toString(workOrder.getTargetLevel())).sendTo(colony).forAllPlayers();
        return;
    }
    if (workOrder.tooFarFromAnyBuilder(colony, workOrder.getTargetLevel()) && builder.equals(BlockPos.ZERO)) {
        MessageUtils.format(BUILDER_TOO_FAR_AWAY).sendTo(colony).forAllPlayers();
        return;
    }
    if (getCorners().getA().getY() >= MAX_BUILD_HEIGHT || getCorners().getB().getY() >= MAX_BUILD_HEIGHT) {
        MessageUtils.format(BUILDER_BUILDING_TOO_HIGH).sendTo(colony).forAllPlayers();
        return;
    } else if (getPosition().getY() <= MIN_BUILD_HEIGHT) {
        MessageUtils.format(BUILDER_BUILDING_TOO_LOW).sendTo(colony).forAllPlayers();
        return;
    }
    if (!builder.equals(BlockPos.ZERO)) {
        final IBuilding building = colony.getBuildingManager().getBuilding(builder);
        if (building instanceof AbstractBuildingStructureBuilder && (building.getBuildingLevel() >= workOrder.getTargetLevel() || canBeBuiltByBuilder(workOrder.getTargetLevel()))) {
            workOrder.setClaimedBy(builder);
        } else {
            MessageUtils.format(BUILDER_NECESSARY, Integer.toString(workOrder.getTargetLevel())).sendTo(colony).forAllPlayers();
            return;
        }
    }
    colony.getWorkManager().addWorkOrder(workOrder, false);
    colony.getProgressManager().progressWorkOrderPlacement(workOrder);
    if (workOrder.getID() != 0) {
        MessageUtils.format(WORK_ORDER_CREATED, workOrder.getDisplayName(), colony.getName(), workOrder.getLocation().getX(), workOrder.getLocation().getY(), workOrder.getLocation().getZ()).sendTo(colony).forAllPlayers();
    }
    markDirty();
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with WorkOrderBuilding

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

the class AbstractEntityAIStructureWithWorkOrder method loadStructure.

/**
 * Load the structure into the AI.
 */
private void loadStructure() {
    final IWorkOrder workOrder = job.getWorkOrder();
    if (workOrder == null) {
        return;
    }
    final BlockPos pos = workOrder.getLocation();
    if (workOrder instanceof WorkOrderBuilding && worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(pos) == null) {
        Log.getLogger().warn("AbstractBuilding does not exist - removing build request");
        worker.getCitizenColonyHandler().getColony().getWorkManager().removeWorkOrder(workOrder);
        return;
    }
    final int tempRotation = workOrder.getRotation();
    final boolean removal = workOrder.getWorkOrderType() == WorkOrderType.REMOVE;
    loadStructure(workOrder.getStructureName(), tempRotation, pos, workOrder.isMirrored(), removal);
    workOrder.setCleared(false);
    workOrder.setRequested(removal);
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) BlockPos(net.minecraft.util.math.BlockPos) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding)

Example 10 with WorkOrderBuilding

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

the class BuildToolPasteMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final StructureName sn = new StructureName(structureName);
    final ServerPlayerEntity player = ctxIn.getSender();
    if (!Structures.hasMD5(sn)) {
        MessageUtils.format(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!")).sendTo(player);
        return;
    }
    if (player.isCreative()) {
        if (isHut) {
            handleHut(CompatibilityUtils.getWorldFromEntity(player), player, sn, rotation, pos, mirror, state, complete);
            CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
            @Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(CompatibilityUtils.getWorldFromEntity(player), pos);
            if (building != null) {
                final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, building);
                ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorldFromEntity(player));
            }
        } else {
            StructurePlacementUtils.loadAndPlaceStructureWithRotation(ctxIn.getSender().level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, ctxIn.getSender());
        }
    } else if (structureName.contains("supply")) {
        if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) > 0 && !MineColonies.getConfig().getServer().allowInfiniteSupplyChests.get() && !isFreeInstantPlacementMH(player)) {
            MessageUtils.format(WARNING_SUPPLY_CHEST_ALREADY_PLACED).sendTo(player);
            return;
        }
        Predicate<ItemStack> searchPredicate = stack -> !stack.isEmpty();
        if (structureName.contains("supplyship")) {
            searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyChest), true, false));
        }
        if (structureName.contains("supplycamp")) {
            searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyCamp), true, false));
        }
        if (isFreeInstantPlacementMH(player)) {
            searchPredicate = searchPredicate.and(stack -> stack.hasTag() && stack.getTag().get(PLACEMENT_NBT) != null && stack.getTag().getString(PLACEMENT_NBT).equals(INSTANT_PLACEMENT));
        }
        final int slot = InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(new InvWrapper(player.inventory), searchPredicate);
        if (slot != -1 && !ItemStackUtils.isEmpty(player.inventory.removeItemNoUpdate(slot))) {
            if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) < 1) {
                MessageUtils.format(PROGRESS_SUPPLY_CHEST_PLACED).sendTo(player);
                player.awardStat(Stats.ITEM_USED.get(ModItems.supplyChest), 1);
                AdvancementTriggers.PLACE_SUPPLY.trigger(player);
            }
            CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
        } else {
            MessageUtils.format(WARNING_REMOVING_SUPPLY_CHEST).sendTo(player);
        }
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.ldtteam.structurize.management.StructureName) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Predicate(java.util.function.Predicate)

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