Search in sources :

Example 41 with PlacementSettings

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

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) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) 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)

Example 42 with PlacementSettings

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

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) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 43 with PlacementSettings

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

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 44 with PlacementSettings

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

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 45 with PlacementSettings

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

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)

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