Search in sources :

Example 6 with StructurePhasePlacementResult

use of com.ldtteam.structurize.placement.StructurePhasePlacementResult in project minecolonies by Minecolonies.

the class WindowBuildDecoration method updateResources.

/**
 * Clears and resets/updates all resources.
 */
private void updateResources() {
    final World world = Minecraft.getInstance().level;
    resources.clear();
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, structurePos, structureName.toString(), new PlacementSettings(), true);
    final String md5 = Structures.getMD5(structureName.toString());
    if (!structure.hasBluePrint() || !structure.isCorrectMD5(md5)) {
        if (!structure.hasBluePrint()) {
            Log.getLogger().info("Template structure " + structureName + " missing");
        } else {
            Log.getLogger().info("structure " + structureName + " md5 error");
        }
        Log.getLogger().info("Request To Server for structure " + structureName);
        if (ServerLifecycleHooks.getCurrentServer() == null) {
            com.ldtteam.structurize.Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName.toString()));
            return;
        } else {
            Log.getLogger().error("WindowMinecoloniesBuildTool: Need to download schematic on a standalone client/server. This should never happen", new Exception());
        }
    }
    StructurePlacer placer = new StructurePlacer(structure);
    StructurePhasePlacementResult result;
    BlockPos progressPos = NULL_POS;
    do {
        result = placer.executeStructureStep(world, null, progressPos, StructurePlacer.Operation.GET_RES_REQUIREMENTS, () -> placer.getIterator().increment(), true);
        progressPos = result.getIteratorPos();
        for (final ItemStack stack : result.getBlockResult().getRequiredItems()) {
            addNeededResource(stack, stack.getCount());
        }
    } while (result.getBlockResult().getResult() != BlockPlacementResult.Result.FINISHED);
    window.findPaneOfTypeByID(LIST_RESOURCES, ScrollingList.class).refreshElementPanes();
    updateResourceList();
}
Also used : SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Example 7 with StructurePhasePlacementResult

use of com.ldtteam.structurize.placement.StructurePhasePlacementResult in project minecolonies by Minecolonies.

the class AbstractEntityAIStructure method structureStep.

/**
 * The Structure step to execute the actual placement actions etc.
 *
 * @return the next step to go to.
 */
protected IAIState structureStep() {
    if (structurePlacer.getB().getStage() == null) {
        return PICK_UP_RESIDUALS;
    }
    if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
        return INVENTORY_FULL;
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.building"));
    checkForExtraBuildingActions();
    // some things to do first! then we go to the actual phase!
    // Fill workFrom with the position from where the builder should build.
    // also ensure we are at that position.
    final BlockPos progress = getProgressPos() == null ? NULL_POS : getProgressPos().getA();
    final BlockPos worldPos = structurePlacer.getB().getProgressPosInWorld(progress);
    if (getProgressPos() != null) {
        structurePlacer.getB().setStage(getProgressPos().getB());
    }
    if (!progress.equals(NULL_POS) && !limitReached && (blockToMine == null ? !walkToConstructionSite(worldPos) : !walkToConstructionSite(blockToMine))) {
        return getState();
    }
    limitReached = false;
    final StructurePhasePlacementResult result;
    final StructurePlacer placer = structurePlacer.getA();
    switch(structurePlacer.getB().getStage()) {
        case BUILD_SOLID:
            // structure
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            break;
        case CLEAR_WATER:
            // water
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
            break;
        case CLEAR_NON_SOLIDS:
            // clear air
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !(info.getBlockInfo().getState().getBlock() instanceof AirBlock) || (handler.getWorld().isEmptyBlock(pos)))), false);
            break;
        case DECORATE:
            // not solid
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
            break;
        case SPAWN:
            // entities
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
            break;
        case REMOVE_WATER:
            // water
            placer.getIterator().setRemoving();
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> info.getBlockInfo().getState().getFluidState().isEmpty()), false);
            break;
        case REMOVE:
            placer.getIterator().setRemoving();
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() instanceof AirBlock || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSolidSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable), true);
            break;
        case CLEAR:
        default:
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable || handler.getWorld().getBlockState(pos).getBlock() == Blocks.BEDROCK || handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockFluidSubstitution.get() || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                building.checkOrRequestBucket(building.getRequiredResources(), worker.getCitizenData(), true);
            }
            break;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FAIL) {
        Log.getLogger().error("Failed placement at: " + result.getBlockResult().getWorldPos().toShortString());
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
        building.nextStage();
        if (!structurePlacer.getB().nextStage()) {
            building.setProgressPos(null, null);
            return COMPLETE_BUILD;
        }
    } else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.LIMIT_REACHED) {
        this.limitReached = true;
    }
    this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.MISSING_ITEMS) {
        if (hasListOfResInInvOrRequest(this, result.getBlockResult().getRequiredItems(), result.getBlockResult().getRequiredItems().size() > 1) == RECALC) {
            job.getWorkOrder().setRequested(false);
            return LOAD_STRUCTURE;
        }
        return NEEDS_ITEM;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.BREAK_BLOCK) {
        blockToMine = result.getBlockResult().getWorldPos();
        return MINE_BLOCK;
    } else {
        blockToMine = null;
    }
    if (MineColonies.getConfig().getServer().builderBuildBlockDelay.get() > 0) {
        final double decrease = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED);
        setDelay((int) ((MineColonies.getConfig().getServer().builderBuildBlockDelay.get() * PROGRESS_MULTIPLIER / (getPlaceSpeedLevel() / 2 + PROGRESS_MULTIPLIER)) * decrease));
    }
    return getState();
}
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) AirBlock(net.minecraft.block.AirBlock) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)

Example 8 with StructurePhasePlacementResult

use of com.ldtteam.structurize.placement.StructurePhasePlacementResult 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 = building;
        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()) {
                building.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()) {
                building.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) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) FluidState(net.minecraft.fluid.FluidState) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) Structures(com.ldtteam.structurize.management.Structures) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) Direction(net.minecraft.util.Direction) Mirror(net.minecraft.util.Mirror) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) RECALC(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult.RECALC) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) Fluids(net.minecraft.fluid.Fluids) JobQuarrier(com.minecolonies.coremod.colony.jobs.JobQuarrier) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) AbstractEntityAIStructureWithWorkOrder(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructureWithWorkOrder) IColonyManager(com.minecolonies.api.colony.IColonyManager) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) PROGRESS_MULTIPLIER(com.minecolonies.api.util.constant.CitizenConstants.PROGRESS_MULTIPLIER) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) FILL_BLOCK(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner.FILL_BLOCK) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) MineColonies(com.minecolonies.coremod.MineColonies) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NotNull(org.jetbrains.annotations.NotNull) 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 9 with StructurePhasePlacementResult

use of com.ldtteam.structurize.placement.StructurePhasePlacementResult in project minecolonies by Minecolonies.

the class EntityAIQuarrier method structureStep.

@Override
protected IAIState structureStep() {
    if (structurePlacer.getB().getStage() == null) {
        return PICK_UP_RESIDUALS;
    }
    if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
        return INVENTORY_FULL;
    }
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.building"));
    checkForExtraBuildingActions();
    // some things to do first! then we go to the actual phase!
    // Fill workFrom with the position from where the builder should build.
    // also ensure we are at that position.
    final BlockPos progress = getProgressPos() == null ? NULL_POS : getProgressPos().getA();
    final BlockPos worldPos = structurePlacer.getB().getProgressPosInWorld(progress);
    if (getProgressPos() != null) {
        structurePlacer.getB().setStage(getProgressPos().getB());
    }
    if (!progress.equals(NULL_POS) && !limitReached && (blockToMine == null ? !walkToConstructionSite(worldPos) : !walkToConstructionSite(blockToMine))) {
        return getState();
    }
    limitReached = false;
    final StructurePhasePlacementResult result;
    final StructurePlacer placer = structurePlacer.getA();
    switch(structurePlacer.getB().getStage()) {
        case BUILD_SOLID:
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> 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);
            if (progress.getY() != -1 && result.getIteratorPos().getY() < progress.getY()) {
                structurePlacer.getB().nextStage();
                this.storeProgressPos(new BlockPos(0, progress.getY() + 1, 0), structurePlacer.getB().getStage());
            } else {
                this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
            }
            break;
        case DECORATE:
            if (progress.getY() >= structurePlacer.getB().getBluePrint().getSizeY()) {
                structurePlacer.getB().nextStage();
                this.storeProgressPos(new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), progress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1), structurePlacer.getB().getStage());
                return getState();
            }
            // not solid
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> 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);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                structurePlacer.getB().nextStage();
                this.storeProgressPos(new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), progress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1), structurePlacer.getB().getStage());
            } else if (progress.getY() != -1 && result.getIteratorPos().getY() > progress.getY()) {
                structurePlacer.getB().nextStage();
                this.storeProgressPos(new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), progress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1), structurePlacer.getB().getStage());
            } else {
                this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
            }
            break;
        case CLEAR:
        default:
            result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable || handler.getWorld().getBlockState(pos).getBlock() == Blocks.BEDROCK || handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockFluidSubstitution.get() || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
            if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
                building.nextStage();
                building.setProgressPos(null, null);
                return COMPLETE_BUILD;
            } else if (progress.getY() != -1 && (result.getIteratorPos().getY() < progress.getY() || result.getBlockResult().getWorldPos().getY() < worldPos.getY())) {
                structurePlacer.getB().setStage(BUILD_SOLID);
                this.storeProgressPos(new BlockPos(structurePlacer.getB().getBluePrint().getSizeX(), progress.getY() - 1, structurePlacer.getB().getBluePrint().getSizeZ() - 1), structurePlacer.getB().getStage());
            } else {
                this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
            }
            break;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.LIMIT_REACHED) {
        this.limitReached = true;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.MISSING_ITEMS) {
        if (hasListOfResInInvOrRequest(this, result.getBlockResult().getRequiredItems(), result.getBlockResult().getRequiredItems().size() > 1) == RECALC) {
            job.getWorkOrder().setRequested(false);
            return LOAD_STRUCTURE;
        }
        return NEEDS_ITEM;
    }
    if (result.getBlockResult().getResult() == BlockPlacementResult.Result.BREAK_BLOCK) {
        final BlockPos currentWorldPos = result.getBlockResult().getWorldPos();
        if (currentWorldPos.getY() < 5) {
            building.setProgressPos(null, null);
            return COMPLETE_BUILD;
        }
        blockToMine = currentWorldPos;
        return MINE_BLOCK;
    }
    if (MineColonies.getConfig().getServer().builderBuildBlockDelay.get() > 0) {
        final double decrease = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED);
        setDelay((int) ((MineColonies.getConfig().getServer().builderBuildBlockDelay.get() * PROGRESS_MULTIPLIER / (getPlaceSpeedLevel() / 2 + PROGRESS_MULTIPLIER)) * decrease));
    }
    return getState();
}
Also used : StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) FluidState(net.minecraft.fluid.FluidState) BLOCK_PLACE_SPEED(com.minecolonies.api.research.util.ResearchConstants.BLOCK_PLACE_SPEED) SurfaceType(com.minecolonies.api.entity.pathfinding.SurfaceType) WorkerLoadOnlyStructureHandler(com.minecolonies.coremod.entity.ai.util.WorkerLoadOnlyStructureHandler) Structures(com.ldtteam.structurize.management.Structures) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) Direction(net.minecraft.util.Direction) Mirror(net.minecraft.util.Mirror) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) RECALC(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructure.ItemCheckResult.RECALC) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) net.minecraft.block(net.minecraft.block) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) Hand(net.minecraft.util.Hand) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) TICKS_SECOND(com.minecolonies.api.util.constant.Constants.TICKS_SECOND) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) Fluids(net.minecraft.fluid.Fluids) JobQuarrier(com.minecolonies.coremod.colony.jobs.JobQuarrier) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) BuildingMiner(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) AbstractEntityAIStructureWithWorkOrder(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIStructureWithWorkOrder) IColonyManager(com.minecolonies.api.colony.IColonyManager) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) NULL_POS(com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS) WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) Items(net.minecraft.item.Items) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) PROGRESS_MULTIPLIER(com.minecolonies.api.util.constant.CitizenConstants.PROGRESS_MULTIPLIER) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) FILL_BLOCK(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingMiner.FILL_BLOCK) BlockPlacementResult(com.ldtteam.structurize.placement.BlockPlacementResult) MineColonies(com.minecolonies.coremod.MineColonies) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NotNull(org.jetbrains.annotations.NotNull) QuarryModule(com.minecolonies.coremod.colony.buildings.modules.QuarryModule) StructurePhasePlacementResult(com.ldtteam.structurize.placement.StructurePhasePlacementResult) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)

Example 10 with StructurePhasePlacementResult

use of com.ldtteam.structurize.placement.StructurePhasePlacementResult in project minecolonies by Minecolonies.

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()) {
        final String mode = BuilderModeSetting.getActualValue(building);
        job.getWorkOrder().setIteratorType(mode);
    }
    final StructurePlacer placer = new StructurePlacer(structure, job.getWorkOrder().getIteratorType());
    if (requestProgress == null) {
        final AbstractBuildingStructureBuilder buildingWorker = building;
        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()) {
                building.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()) {
                building.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()) {
                building.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) IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) 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) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) ItemStack(net.minecraft.item.ItemStack) Tuple(com.minecolonies.api.util.Tuple) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) WorkOrderType(com.minecolonies.api.colony.workorders.WorkOrderType) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) AbstractBuildingStructureBuilder(com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder) 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) WorkOrderMiner(com.minecolonies.coremod.colony.workorders.WorkOrderMiner) 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) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuilderModeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.BuilderModeSetting) 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) COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START(com.minecolonies.api.util.constant.TranslationConstants.COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILD_START) BuildingRepairedEvent(com.minecolonies.coremod.colony.colonyEvents.buildingEvents.BuildingRepairedEvent) 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)

Aggregations

StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)13 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)12 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)12 ItemStack (net.minecraft.item.ItemStack)12 BlockPos (net.minecraft.util.math.BlockPos)12 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)10 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)10 NotNull (org.jetbrains.annotations.NotNull)10 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)8 IBuilderUndestroyable (com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable)8 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)8 AbstractBuildingStructureBuilder (com.minecolonies.coremod.colony.buildings.AbstractBuildingStructureBuilder)8 BuildingStructureHandler (com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler)8 TileEntity (net.minecraft.tileentity.TileEntity)8 Mirror (net.minecraft.util.Mirror)8 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)8 Structures (com.ldtteam.structurize.management.Structures)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)6 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)6 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)6