Search in sources :

Example 6 with BlockInfo

use of com.ldtteam.structurize.util.BlockInfo in project Structurize by ldtteam.

the class ItemScanTool method saveStructure.

/**
 * Scan the structure and save it to the disk.
 *
 * @param world        Current world.
 * @param from         First corner.
 * @param to           Second corner.
 * @param player       causing this action.
 * @param name         the name of it.
 * @param saveEntities whether to scan in entities
 */
public static void saveStructure(@NotNull final World world, @NotNull final BlockPos from, @NotNull final BlockPos to, @NotNull final PlayerEntity player, final String name, final boolean saveEntities, final Optional<BlockPos> anchorPos) {
    if (anchorPos.isPresent()) {
        if (!BlockPosUtil.isInbetween(anchorPos.get(), from, to)) {
            LanguageHandler.sendPlayerMessage(player, ANCHOR_POS_OUTSIDE_SCHEMATIC);
            return;
        }
    }
    final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
    final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
    final BlockPos size = blockpos1.subtract(blockpos).offset(1, 1, 1);
    if (size.getX() * size.getY() * size.getZ() > Structurize.getConfig().getServer().schematicBlockLimit.get()) {
        LanguageHandler.sendPlayerMessage(player, MAX_SCHEMATIC_SIZE_REACHED, Structurize.getConfig().getServer().schematicBlockLimit.get());
        return;
    }
    final long currentMillis = System.currentTimeMillis();
    final String currentMillisString = Long.toString(currentMillis);
    final String fileName;
    if (name == null || name.isEmpty()) {
        fileName = LanguageHandler.format("item.sceptersteel.scanformat", "", currentMillisString);
    } else {
        fileName = name;
    }
    final Blueprint bp = BlueprintUtil.createBlueprint(world, blockpos, saveEntities, (short) size.getX(), (short) size.getY(), (short) size.getZ(), fileName, anchorPos);
    if (!anchorPos.isPresent() && bp.getPrimaryBlockOffset().equals(new BlockPos(bp.getSizeX() / 2, 0, bp.getSizeZ() / 2))) {
        final List<BlockInfo> list = bp.getBlockInfoAsList().stream().filter(blockInfo -> blockInfo.hasTileEntityData() && blockInfo.getTileEntityData().contains(TAG_BLUEPRINTDATA)).collect(Collectors.toList());
        if (list.size() > 1) {
            player.sendMessage(new TranslationTextComponent("com.ldtteam.structurize.gui.scantool.scanbadanchor", fileName), player.getUUID());
        }
    }
    Network.getNetwork().sendToPlayer(new SaveScanMessage(BlueprintUtil.writeBlueprintToNBT(bp), fileName), (ServerPlayerEntity) player);
}
Also used : Network(com.ldtteam.structurize.Network) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) Item(net.minecraft.item.Item) Structures(com.ldtteam.structurize.management.Structures) WindowScan(com.ldtteam.structurize.client.gui.WindowScan) TAG_BLUEPRINTDATA(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider.TAG_BLUEPRINTDATA) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) ItemStack(net.minecraft.item.ItemStack) Structurize(com.ldtteam.structurize.Structurize) Utils(com.ldtteam.structurize.api.util.Utils) Rarity(net.minecraft.item.Rarity) Settings(com.ldtteam.structures.helpers.Settings) Log(com.ldtteam.structurize.api.util.Log) BlockState(net.minecraft.block.BlockState) IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureLoadingUtils(com.ldtteam.structurize.util.StructureLoadingUtils) OutputStream(java.io.OutputStream) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockPosUtil(com.ldtteam.structurize.api.util.BlockPosUtil) StructureName(com.ldtteam.structurize.management.StructureName) BlueprintUtil(com.ldtteam.structures.blueprints.v1.BlueprintUtil) World(net.minecraft.world.World) FileOutputStream(java.io.FileOutputStream) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) MAX_SCHEMATIC_SIZE_REACHED(com.ldtteam.structurize.api.util.constant.TranslationConstants.MAX_SCHEMATIC_SIZE_REACHED) ANCHOR_POS_OUTSIDE_SCHEMATIC(com.ldtteam.structurize.api.util.constant.TranslationConstants.ANCHOR_POS_OUTSIDE_SCHEMATIC) ItemGroup(net.minecraft.item.ItemGroup) CompressedStreamTools(net.minecraft.nbt.CompressedStreamTools) SaveScanMessage(com.ldtteam.structurize.network.messages.SaveScanMessage) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) NBTUtil(net.minecraft.nbt.NBTUtil) ActionResultType(net.minecraft.util.ActionResultType) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) SaveScanMessage(com.ldtteam.structurize.network.messages.SaveScanMessage)

Example 7 with BlockInfo

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

the class WorkerUtil method findFirstLevelSign.

/**
 * Find the first level in a structure and return it.
 *
 * @param structure the structure to scan.
 * @return the position of the sign.
 */
@Nullable
public static BlockPos findFirstLevelSign(final Blueprint structure, final BlockPos pos) {
    for (int j = 0; j < structure.getSizeY(); j++) {
        for (int k = 0; k < structure.getSizeZ(); k++) {
            for (int i = 0; i < structure.getSizeX(); i++) {
                @NotNull final BlockPos localPos = new BlockPos(i, j, k);
                final BlockInfo te = structure.getBlockInfoAsMap().get(localPos);
                if (te != null) {
                    final CompoundNBT teData = te.getTileEntityData();
                    if (teData != null && teData.getString(LEVEL_SIGN_FIRST_ROW).equals(LEVEL_SIGN_TEXT)) {
                        // try to make an anchor in 0,0,0 instead of the middle of the structure
                        return pos.subtract(structure.getPrimaryBlockOffset()).offset(localPos);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockInfo(com.ldtteam.structurize.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with BlockInfo

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

Aggregations

BlockInfo (com.ldtteam.structurize.util.BlockInfo)8 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)5 BlockPos (net.minecraft.util.math.BlockPos)5 StructureName (com.ldtteam.structurize.management.StructureName)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 BlockState (net.minecraft.block.BlockState)2 ItemStack (net.minecraft.item.ItemStack)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 BlueprintUtil (com.ldtteam.structures.blueprints.v1.BlueprintUtil)1 Settings (com.ldtteam.structures.helpers.Settings)1 Network (com.ldtteam.structurize.Network)1 Structurize (com.ldtteam.structurize.Structurize)1 BlockPosUtil (com.ldtteam.structurize.api.util.BlockPosUtil)1 Log (com.ldtteam.structurize.api.util.Log)1 Utils (com.ldtteam.structurize.api.util.Utils)1 ANCHOR_POS_OUTSIDE_SCHEMATIC (com.ldtteam.structurize.api.util.constant.TranslationConstants.ANCHOR_POS_OUTSIDE_SCHEMATIC)1 MAX_SCHEMATIC_SIZE_REACHED (com.ldtteam.structurize.api.util.constant.TranslationConstants.MAX_SCHEMATIC_SIZE_REACHED)1 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)1