Search in sources :

Example 1 with AbstractBuildingStructureBuilder

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

the class EntityAIQuarrier method requestMaterials.

@Override
public boolean requestMaterials() {
    StructurePhasePlacementResult result;
    final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
    job.getWorkOrder().setIteratorType("default");
    final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
    if (requestProgress == null) {
        final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
        buildingWorker.resetNeededResources();
        requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
        requestState = RequestStage.SOLID;
    }
    final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
    final RequestStage currState = requestState;
    switch(currState) {
        case SOLID:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
                requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
                requestState = RequestStage.DECO;
            } else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
                requestState = RequestStage.DECO;
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
        case DECO:
            if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
                return false;
            }
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
        case ENTITIES:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.SOLID;
                requestProgress = null;
                return true;
            } else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
                requestState = RequestStage.SOLID;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
    }
    return true;
}
Also used : AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) FluidState(net.minecraft.fluid.FluidState) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) Structures(com.ldtteam.structurize.management.Structures) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) BuildingBuilder(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder) Direction(net.minecraft.util.Direction) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) RECALC(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult.RECALC) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) ISettingsModule(com.minecolonies.api.colony.buildings.modules.ISettingsModule) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) MORE_ORES(com.minecolonies.api.research.util.ResearchConstants.MORE_ORES) Fluids(net.minecraft.fluid.Fluids) JobQuarrier(com.minecolonies.coremod.colony.jobs.JobQuarrier) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIStructureWithWorkOrder(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructureWithWorkOrder) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) FILL_BLOCK(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner.FILL_BLOCK) MineColonies(com.minecolonies.coremod.MineColonies) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) Mirror(net.minecraft.util.Mirror) ItemStack(net.minecraft.item.ItemStack) StructureIterators(com.ldtteam.structurize.placement.StructureIterators) net.minecraft.block(net.minecraft.block) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IColonyManager(com.minecolonies.api.colony.IColonyManager) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) PROGRESS_MULTIPLIER(com.minecolonies.api.util.constant.CitizenConstants.PROGRESS_MULTIPLIER) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack)

Example 2 with AbstractBuildingStructureBuilder

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

the class AbstractEntityAIStructure method hasListOfResInInvOrRequest.

/**
 * Check the placers inventory for the items in the itemList and remove it of the list if found.
 *
 * @param placer   the placer.
 * @param itemList the list to check.
 * @param force    if force insertion.
 * @return true if need to request.
 */
public static <J extends AbstractJobStructure<?, J>, B extends AbstractBuildingStructureBuilder> ItemCheckResult hasListOfResInInvOrRequest(@NotNull final AbstractEntityAIStructure<J, B> placer, final List<ItemStack> itemList, final boolean force) {
    for (final ItemStack stack : itemList) {
        if (!InventoryUtils.hasItemInItemHandler(placer.getInventory(), stack1 -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, stack1)) && !placer.getOwnBuilding().hasResourceInBucket(stack)) {
            return RECALC;
        }
    }
    final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(placer.getWorker().getInventoryCitizen(), itemStack -> itemList.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(targetStack, itemStack)));
    if (force) {
        for (final ItemStack foundStack : new ArrayList<>(foundStacks)) {
            final Optional<ItemStack> opt = itemList.stream().filter(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(targetStack, foundStack)).findFirst();
            if (opt.isPresent()) {
                final ItemStack stack = opt.get();
                itemList.remove(stack);
                if (stack.getCount() > foundStack.getCount()) {
                    stack.setCount(stack.getCount() - foundStack.getCount());
                    itemList.add(stack);
                }
            }
        }
    } else {
        itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(target -> ItemStackUtils.compareItemStacksIgnoreStackSize(target, itemStack)));
    }
    itemList.removeIf(itemstack -> itemstack.getItem() instanceof BlockItem && isBlockFree(((BlockItem) itemstack.getItem()).getBlock()));
    final Map<ItemStorage, Integer> list = new HashMap<>();
    for (final ItemStack stack : itemList) {
        ItemStorage tempStorage = new ItemStorage(stack.copy());
        if (list.containsKey(tempStorage)) {
            final int oldSize = list.get(tempStorage);
            tempStorage.setAmount(tempStorage.getAmount() + oldSize);
        }
        list.put(tempStorage, placer.getTotalAmount(tempStorage.getItemStack()).getCount());
    }
    for (final Map.Entry<ItemStorage, Integer> placedStack : list.entrySet()) {
        if (ItemStackUtils.isEmpty(placedStack.getKey().getItemStack())) {
            return FAIL;
        }
        final ImmutableList<IRequest<? extends IDeliverable>> requests = placer.getOwnBuilding().getOpenRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack.getKey().getItemStack()));
        final ImmutableList<IRequest<? extends IDeliverable>> completedRequests = placer.getOwnBuilding().getCompletedRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack.getKey().getItemStack()));
        if (requests.isEmpty() && completedRequests.isEmpty()) {
            final com.minecolonies.api.colony.requestsystem.requestable.Stack stackRequest = new Stack(placedStack.getKey().getItemStack(), placedStack.getValue(), 1);
            placer.getWorker().getCitizenData().createRequest(stackRequest);
            placer.registerBlockAsNeeded(placedStack.getKey().getItemStack());
            return FAIL;
        } else {
            for (final IRequest<? extends IDeliverable> request : requests) {
                if (placer.worker.getCitizenJobHandler().getColonyJob().getAsyncRequests().contains(request.getId())) {
                    placer.worker.getCitizenJobHandler().getColonyJob().markRequestSync(request.getId());
                }
            }
            for (final IRequest<? extends IDeliverable> request : completedRequests) {
                if (placer.worker.getCitizenJobHandler().getColonyJob().getAsyncRequests().contains(request.getId())) {
                    placer.worker.getCitizenJobHandler().getColonyJob().markRequestSync(request.getId());
                }
            }
        }
        return FAIL;
    }
    return SUCCESS;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) AirBlock(net.minecraft.block.AirBlock) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) TriPredicate(net.minecraftforge.common.util.TriPredicate) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) Block(net.minecraft.block.Block) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) BlockTags(net.minecraft.tags.BlockTags) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) BlockState(net.minecraft.block.BlockState) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) AIEventTarget(com.minecolonies.api.entity.ai.statemachine.AIEventTarget) Predicate(java.util.function.Predicate) BlueprintPositionInfo(com.ldtteam.structurize.util.BlueprintPositionInfo) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) BlockItem(net.minecraft.item.BlockItem) MineColonies(com.minecolonies.coremod.MineColonies) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) BuilderBucket(com.minecolonies.coremod.colony.buildings.utils.BuilderBucket) java.util(java.util) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ModBlocks(com.minecolonies.api.blocks.ModBlocks) Mirror(net.minecraft.util.Mirror) ItemStack(net.minecraft.item.ItemStack) BuildingResourcesModule(com.minecolonies.coremod.colony.buildings.modules.BuildingResourcesModule) ImmutableList(com.google.common.collect.ImmutableList) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) ModTags(com.minecolonies.api.items.ModTags) AIBlockingEventType(com.minecolonies.api.entity.ai.statemachine.states.AIBlockingEventType) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) Blocks(net.minecraft.block.Blocks) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) BlockUtils(com.ldtteam.structurize.util.BlockUtils) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockFluidSubstitution(com.ldtteam.structurize.blocks.schematic.BlockFluidSubstitution) TileEntity(net.minecraft.tileentity.TileEntity) ItemCheckResult(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult) BlockItem(net.minecraft.item.BlockItem) ItemStorage(com.minecolonies.api.crafting.ItemStorage) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) ItemStack(net.minecraft.item.ItemStack) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) Stack(com.minecolonies.api.colony.requestsystem.requestable.Stack)

Example 3 with AbstractBuildingStructureBuilder

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder in project minecolonies by ldtteam.

the class AbstractEntityAIStructureWithWorkOrder method getTotalAmount.

/**
 * Check how much of a certain stuck is actually required.
 *
 * @param stack the stack to check.
 * @return the new stack with the correct amount.
 */
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
    if (ItemStackUtils.isEmpty(stack)) {
        return null;
    }
    final int hashCode = stack.hasTag() ? stack.getTag().hashCode() : 0;
    final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
    BuildingBuilderResource resource = buildingWorker.getNeededResources().get(stack.getDescriptionId() + "-" + hashCode);
    if (resource == null) {
        requestMaterials();
        resource = buildingWorker.getNeededResources().get(stack.getDescriptionId() + "-" + hashCode);
    }
    if (resource == null) {
        return stack;
    }
    final ItemStack resStack = new ItemStack(resource.getItem(), Math.min(STACKSIZE, resource.getAmount()));
    resStack.setTag(resource.getItemStack().getTag());
    return resStack;
}
Also used : AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AbstractBuildingStructureBuilder

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder in project minecolonies by ldtteam.

the class AbstractEntityAIStructureWithWorkOrder method requestMaterials.

@Override
public boolean requestMaterials() {
    StructurePhasePlacementResult result;
    final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
    if (job.getWorkOrder().getIteratorType().isEmpty() && getOwnBuilding().hasModule(ISettingsModule.class) && getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE) != null) {
        job.getWorkOrder().setIteratorType(getOwnBuilding().getSetting(BuildingBuilder.BUILDING_MODE).getValue());
    }
    final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
    if (requestProgress == null) {
        final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
        buildingWorker.resetNeededResources();
        requestProgress = NULL_POS;
        requestState = RequestStage.SOLID;
    }
    final RequestStage currState = requestState;
    switch(currState) {
        case SOLID:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            requestProgress = result.getIteratorPos();
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.DECO;
            }
            return false;
        case DECO:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            requestProgress = result.getIteratorPos();
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.ENTITIES;
            }
            return false;
        case ENTITIES:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
            requestProgress = result.getIteratorPos();
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.SOLID;
                requestProgress = null;
                return true;
            }
            return false;
        default:
            return true;
    }
}
Also used : AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) PICK_UP_RESIDUALS(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.PICK_UP_RESIDUALS) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) BuildingBuilder(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder) COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_DECONSTRUCTION_COMPLETE) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) ISettingsModule(com.minecolonies.api.colony.buildings.modules.ISettingsModule) Log(com.minecolonies.api.util.Log) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) Constants(com.minecolonies.api.util.constant.Constants) BuildingBuiltEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingBuiltEvent) BuildingDeconstructedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingDeconstructedEvent) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) STACKSIZE(com.minecolonies.api.util.constant.Constants.STACKSIZE) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) IDLE(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.IDLE) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) BuildingUpgradedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingUpgradedEvent) Nullable(org.jetbrains.annotations.Nullable) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) com.minecolonies.coremod.colony.workorders(com.minecolonies.coremod.colony.workorders) AbstractJobStructure(com.minecolonies.coremod.colony.jobs.AbstractJobStructure) TileEntity(net.minecraft.tileentity.TileEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage) WorldUtil(com.minecolonies.api.util.WorldUtil) NotNull(org.jetbrains.annotations.NotNull) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack)

Example 5 with AbstractBuildingStructureBuilder

use of com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder in project minecolonies by ldtteam.

the class EntityAIQuarrier method requestMaterials.

@Override
public boolean requestMaterials() {
    StructurePhasePlacementResult result;
    final WorkerLoadOnlyStructureHandler structure = new WorkerLoadOnlyStructureHandler(world, structurePlacer.getB().getWorldPos(), structurePlacer.getB().getBluePrint(), new PlacementSettings(), true, this);
    job.getWorkOrder().setIteratorType("default");
    final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
    if (requestProgress == null) {
        final AbstractBuildingStructureBuilder buildingWorker = getOwnBuilding();
        buildingWorker.resetNeededResources();
        requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), structurePlacer.getB().getBluePrint().getSizeY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
        requestState = RequestStage.SOLID;
    }
    final BlockPos worldPos = structure.getProgressPosInWorld(requestProgress);
    final RequestStage currState = requestState;
    switch(currState) {
        case SOLID:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() < worldPos.getY())), false);
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (requestProgress.getY() != -1 && result.getIteratorPos().getY() < requestProgress.getY()) {
                requestProgress = new BlockPos(0, requestProgress.getY() + 1, 0);
                requestState = RequestStage.DECO;
            } else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestProgress = new BlockPos(0, structurePlacer.getB().getBluePrint().getSizeY() - 2, 0);
                requestState = RequestStage.DECO;
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
        case DECO:
            if (requestProgress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
                return false;
            }
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()) || pos.getY() > worldPos.getY())), false);
            for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
                getOwnBuilding().addNeededResource(stack, stack.getCount());
            }
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else if (requestProgress.getY() != -1 && result.getIteratorPos().getY() > requestProgress.getY()) {
                requestState = RequestStage.ENTITIES;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
        case ENTITIES:
            result = placer.executeStructureStep(world, null, requestProgress, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0 || pos.getY() < worldPos.getY())), true);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                requestState = RequestStage.SOLID;
                requestProgress = null;
                return true;
            } else if (requestProgress.getY() != -1 && (result.getIteratorPos().getY() < requestProgress.getY())) {
                requestState = RequestStage.SOLID;
                requestProgress = new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), requestProgress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1);
            } else {
                requestProgress = result.getIteratorPos();
            }
            return false;
    }
    return true;
}
Also used : AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) FluidState(net.minecraft.fluid.FluidState) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) Structures(com.ldtteam.structurize.management.Structures) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) BuildingBuilder(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBuilder) Direction(net.minecraft.util.Direction) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) RECALC(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult.RECALC) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) ISettingsModule(com.minecolonies.api.colony.buildings.modules.ISettingsModule) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) Constants(com.minecolonies.api.util.constant.Constants) MORE_ORES(com.minecolonies.api.research.util.ResearchConstants.MORE_ORES) Fluids(net.minecraft.fluid.Fluids) JobQuarrier(com.minecolonies.coremod.colony.jobs.JobQuarrier) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) AbstractEntityAIStructureWithWorkOrder(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructureWithWorkOrder) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) FILL_BLOCK(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner.FILL_BLOCK) MineColonies(com.minecolonies.coremod.MineColonies) NotNull(org.jetbrains.annotations.NotNull) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) Mirror(net.minecraft.util.Mirror) ItemStack(net.minecraft.item.ItemStack) StructureIterators(com.ldtteam.structurize.placement.StructureIterators) net.minecraft.block(net.minecraft.block) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) com.minecolonies.api.util(com.minecolonies.api.util) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IColonyManager(com.minecolonies.api.colony.IColonyManager) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) PROGRESS_MULTIPLIER(com.minecolonies.api.util.constant.CitizenConstants.PROGRESS_MULTIPLIER) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack)

Aggregations

AbstractBuildingStructureBuilder (com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder)10 ItemStack (net.minecraft.item.ItemStack)8 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)6 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)6 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)6 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)6 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)6 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)6 BuildingStructureHandler (com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler)6 TileEntity (net.minecraft.tileentity.TileEntity)6 BlockPos (net.minecraft.util.math.BlockPos)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ISettingsModule (com.minecolonies.api.colony.buildings.modules.ISettingsModule)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 IBuilderUndestroyable (com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)4 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)4 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)4