Search in sources :

Example 16 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 IWorkOrder order) {
    final World world = colony.getWorld();
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(order.getLocation(), world, new LoadOnlyStructureHandler(world, order.getLocation(), order.getStructureName(), new PlacementSettings(), true).getBluePrint(), order.getRotation(), 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 17 with PlacementSettings

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

the class CreativeRaiderStructureHandler 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 colonyId       the colony id.
 * @param event          the raid event.
 * @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, final int colonyId, final IColonyRaidEvent event, @Nullable final ServerPlayerEntity player) {
    try {
        @NotNull final IStructureHandler structure = new CreativeRaiderStructureHandler(worldObj, pos, name, new PlacementSettings(mirror, rotation), fancyPlacement, event, colonyId);
        if (structure.hasBluePrint()) {
            @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 18 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 IWorkOrder workOrder, @NotNull final World world) {
    final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(world, workOrder.getLocation(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (structure.hasBluePrint()) {
        final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(workOrder.getLocation(), world, structure.getBluePrint(), workOrder.getRotation(), 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 19 with PlacementSettings

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

the class AbstractBuilding method calculateCorners.

@Override
public void calculateCorners() {
    final AbstractTileEntityColonyBuilding te = getTileEntity();
    if (te != null && !te.getSchematicName().isEmpty()) {
        setCorners(te.getInWorldCorners().getA(), te.getInWorldCorners().getB());
        return;
    }
    final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, this);
    final LoadOnlyStructureHandler wrapper = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), workOrder.getStructureName(), new PlacementSettings(), true);
    if (!wrapper.hasBluePrint()) {
        setCorners(getPosition(), getPosition());
        return;
    }
    final Tuple<BlockPos, BlockPos> corners = ColonyUtils.calculateCorners(this.getPosition(), colony.getWorld(), wrapper.getBluePrint(), workOrder.getRotation(), workOrder.isMirrored());
    this.setCorners(corners.getA(), corners.getB());
}
Also used : AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) BlockPos(net.minecraft.util.math.BlockPos) WorkOrderBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuilding) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 20 with PlacementSettings

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

the class AbstractSchematicProvider method getRotation.

@Override
public int getRotation() {
    if (cachedRotation != -1) {
        return cachedRotation;
    }
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel));
    try {
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName.toString(), new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof AbstractBlockHut) || !(colony.getWorld().getBlockState(this.location).getBlock() instanceof AbstractBlockHut)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", structureName.toString()));
                    return 0;
                }
                final int structureRotation = structureState.getValue(AbstractBlockHut.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.location).getValue(AbstractBlockHut.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    cachedRotation = worldRotation - structureRotation;
                } else {
                    cachedRotation = 4 + worldRotation - structureRotation;
                }
                return cachedRotation;
            }
        }
    } catch (Exception e) {
        Log.getLogger().error(String.format("Failed to get rotation for %s: ", structureName.toString()), e);
        return 0;
    }
    return 0;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) IAltersBuildingFootprint(com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

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