Search in sources :

Example 26 with PlacementSettings

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

the class AbstractEntityAIStructure method loadStructure.

/**
 * Loads the structure given the name, rotation and position.
 *
 * @param name        the name to retrieve  it.
 * @param rotateTimes number of times to rotateWithMirror it.
 * @param position    the position to set it.
 * @param isMirrored  is the structure mirroed?
 * @param removal     if removal step.
 */
public void loadStructure(@NotNull final String name, final int rotateTimes, final BlockPos position, final boolean isMirrored, final boolean removal) {
    final BuildingStructureHandler<J, B> structure;
    IBuilding colonyBuilding = worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(position);
    final TileEntity entity = world.getBlockEntity(position);
    if (removal) {
        structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { REMOVE_WATER, REMOVE });
        building.setTotalStages(2);
    } else if ((colonyBuilding != null && (colonyBuilding.getBuildingLevel() > 0 || colonyBuilding.hasParent())) || (entity instanceof TileEntityDecorationController && ((TileEntityDecorationController) entity).getTier() > 0)) {
        structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
        building.setTotalStages(5);
    } else {
        structure = new BuildingStructureHandler<>(world, position, name, new PlacementSettings(isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, BlockPosUtil.getRotationFromRotations(rotateTimes)), this, new BuildingStructureHandler.Stage[] { CLEAR, BUILD_SOLID, CLEAR_WATER, CLEAR_NON_SOLIDS, DECORATE, SPAWN });
        building.setTotalStages(6);
    }
    if (!structure.hasBluePrint()) {
        handleSpecificCancelActions();
        Log.getLogger().warn("Couldn't find structure with name: " + name + " aborting loading procedure");
        return;
    }
    job.setBlueprint(structure.getBluePrint());
    job.getBlueprint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotateTimes), isMirrored ? Mirror.FRONT_BACK : Mirror.NONE, world);
    setStructurePlacer(structure);
    if (getProgressPos() != null) {
        structure.setStage(getProgressPos().getB());
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BuildingStructureHandler(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Stage(com.minecolonies.coremod.entity.ai.util.BuildingStructureHandler.Stage) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 27 with PlacementSettings

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

Example 28 with PlacementSettings

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

the class ConstructionTapeHelper method placeConstructionTape.

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

Example 29 with PlacementSettings

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

the class CreativeBuildingStructureHandler method loadAndPlaceStructureWithRotation.

/**
 * Load a structure into this world and place it in the right position and rotation.
 *
 * @param worldObj       the world to load it in
 * @param name           the structures name
 * @param pos            coordinates
 * @param rotation       the rotation.
 * @param mirror         the mirror used.
 * @param fancyPlacement if fancy or complete.
 * @param player         the placing player.
 * @return the placed blueprint.
 */
public static Blueprint loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final String name, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, @Nullable final ServerPlayerEntity player) {
    try {
        @NotNull final IStructureHandler structure = new CreativeBuildingStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement);
        if (structure.hasBluePrint()) {
            structure.getBluePrint().rotateWithMirror(rotation, mirror, worldObj);
            @NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
            Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
        }
        return structure.getBluePrint();
    } catch (final IllegalStateException e) {
        Log.getLogger().warn("Could not load structure!", e);
    }
    return null;
}
Also used : IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) StructurePlacer(com.ldtteam.structurize.placement.StructurePlacer) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Example 30 with PlacementSettings

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

the class ShipBasedRaiderUtils method canSpawnShipAt.

/**
 * Checks whether a pirate event is possible at this place.
 *
 * @param colony     the colony.
 * @param spawnPoint the spawn point.
 * @param raidLevel  the raid level.
 * @param rotation   the rotation.
 * @return true if successful.
 */
public static boolean canSpawnShipAt(final IColony colony, final BlockPos spawnPoint, final int raidLevel, final int rotation, final String shipName) {
    if (spawnPoint.equals(colony.getCenter()) || spawnPoint.getY() > MineColonies.getConfig().getServer().maxYForBarbarians.get()) {
        return false;
    }
    final World world = colony.getWorld();
    final String shipSize = ShipSize.getShipForRaiderAmount(raidLevel).schematicPrefix + shipName;
    final CreativeBuildingStructureHandler structure = new CreativeBuildingStructureHandler(colony.getWorld(), spawnPoint, Structures.SCHEMATICS_PREFIX + SHIP_FOLDER + shipSize, new PlacementSettings(), true);
    structure.getBluePrint().rotateWithMirror(BlockPosUtil.getRotationFromRotations(rotation), Mirror.NONE, colony.getWorld());
    return canPlaceShipAt(spawnPoint, structure.getBluePrint(), world) || canPlaceShipAt(spawnPoint.below(), structure.getBluePrint(), world);
}
Also used : CreativeBuildingStructureHandler(com.minecolonies.api.util.CreativeBuildingStructureHandler) World(net.minecraft.world.World) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

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