Search in sources :

Example 21 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class AbstractSchematicProvider method unsafeUpdateTEDataFromSchematic.

/**
 * Load the schematic data from the TE schematic name, if it's a reattempt, calculate the name from the building (backup).
 * Might throw exceptions if data is invalid.
 */
private void unsafeUpdateTEDataFromSchematic(final TileEntityColonyBuilding te) {
    final String structureName;
    if (te.getSchematicName().isEmpty()) {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel)).toString();
    } else {
        structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, te.getSchematicName()).toString();
    }
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName, new PlacementSettings(), true);
    final Blueprint blueprint = structure.getBluePrint();
    blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(getRotation()), isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, colony.getWorld());
    final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);
    if (info.getTileEntityData() != null) {
        te.readSchematicDataFromNBT(info.getTileEntityData());
    }
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureName(com.ldtteam.structurize.management.StructureName) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 22 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings 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 23 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class WorkManager method isWorkOrderWithinColony.

/**
 * Check if the workOrder is within a colony.
 *
 * @param order the workorder to check.
 * @return true if so.
 */
private boolean isWorkOrderWithinColony(final WorkOrderBuildDecoration order) {
    final World world = colony.getWorld();
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(order.getSchematicLocation(), world, new LoadOnlyStructureHandler(world, order.getSchematicLocation(), order.getStructureName(), new PlacementSettings(), true).getBluePrint(), order.getRotation(world), order.isMirrored());
    Set<ChunkPos> chunks = new HashSet<>();
    final int minX = Math.min(corners.getA().getX(), corners.getB().getX()) + 1;
    final int maxX = Math.max(corners.getA().getX(), corners.getB().getX());
    final int minZ = Math.min(corners.getA().getZ(), corners.getB().getZ()) + 1;
    final int maxZ = Math.max(corners.getA().getZ(), corners.getB().getZ());
    for (int x = minX; x < maxX; x += 16) {
        for (int z = minZ; z < maxZ; z += 16) {
            final int chunkX = x >> 4;
            final int chunkZ = z >> 4;
            final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
            if (!chunks.contains(pos)) {
                chunks.add(pos);
                final IColonyTagCapability colonyCap = world.getChunk(pos.x, pos.z).getCapability(CLOSE_COLONY_CAP, null).orElseGet(null);
                if (colonyCap == null || colonyCap.getOwningColony() != colony.getID()) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) World(net.minecraft.world.World) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) IColonyTagCapability(com.minecolonies.api.colony.IColonyTagCapability)

Example 24 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class ConstructionTapeHelper method removeConstructionTape.

/**
 * Calculates the borders for the workOrderBuildDecoration and sends it to the removal.
 *
 * @param workOrder the workOrder.
 * @param world     the world.
 */
public static void removeConstructionTape(@NotNull final WorkOrderBuildDecoration workOrder, @NotNull final World world) {
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, workOrder.getSchematicLocation(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (structure.hasBluePrint()) {
        final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(workOrder.getSchematicLocation(), world, structure.getBluePrint(), workOrder.getRotation(world), workOrder.isMirrored());
        removeConstructionTape(corners, world);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 25 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project minecolonies by Minecolonies.

the class ClientEventHandler method handleRenderScepterGuard.

/**
 * Renders the guard scepter objects into the world.
 *
 * @param event  The caught event
 * @param world  The world in which to render
 * @param player The player for which to render
 */
private static void handleRenderScepterGuard(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
    final PlacementSettings settings = new PlacementSettings(Settings.instance.getMirror(), BlockPosUtil.getRotationFromRotations(Settings.instance.getRotation()));
    final ItemStack stack = player.getMainHandItem();
    if (!stack.hasTag()) {
        return;
    }
    final CompoundNBT compound = stack.getTag();
    final IColonyView colony = IColonyManager.getInstance().getColonyView(compound.getInt(TAG_ID), player.level.dimension());
    if (colony == null) {
        return;
    }
    final BlockPos guardTower = BlockPosUtil.read(compound, TAG_POS);
    final IBuildingView hut = colony.getBuilding(guardTower);
    if (hut == null) {
        return;
    }
    if (partolPointTemplate == null) {
        partolPointTemplate = new LoadOnlyStructureHandler(world, hut.getPosition(), "schematics/infrastructure/patrolpoint", settings, true).getBluePrint();
    }
    if (hut instanceof AbstractBuildingGuards.View) {
        StructureClientHandler.renderStructureAtPosList(partolPointTemplate, event.getPartialTicks(), ((AbstractBuildingGuards.View) hut).getPatrolTargets().stream().map(BlockPos::above).collect(Collectors.toList()), event.getMatrixStack());
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) ItemStack(net.minecraft.item.ItemStack) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) IColonyView(com.minecolonies.api.colony.IColonyView) EmptyView(com.minecolonies.coremod.colony.buildings.views.EmptyView) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView)

Aggregations

PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)45 BlockPos (net.minecraft.util.math.BlockPos)29 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)21 NotNull (org.jetbrains.annotations.NotNull)15 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)12 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)12 World (net.minecraft.world.World)12 TileEntity (net.minecraft.tileentity.TileEntity)11 ItemStack (net.minecraft.item.ItemStack)10 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)9 StructureName (com.ldtteam.structurize.management.StructureName)9 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)8 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)7 TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)7 Mirror (net.minecraft.util.Mirror)7 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)6 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)6 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)6 IColonyView (com.minecolonies.api.colony.IColonyView)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6