Search in sources :

Example 1 with TAG_BLUEPRINTDATA

use of com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider.TAG_BLUEPRINTDATA 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)

Aggregations

Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)1 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 TAG_BLUEPRINTDATA (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider.TAG_BLUEPRINTDATA)1 WindowScan (com.ldtteam.structurize.client.gui.WindowScan)1 StructureName (com.ldtteam.structurize.management.StructureName)1 Structures (com.ldtteam.structurize.management.Structures)1 SaveScanMessage (com.ldtteam.structurize.network.messages.SaveScanMessage)1 BlockInfo (com.ldtteam.structurize.util.BlockInfo)1 LanguageHandler (com.ldtteam.structurize.util.LanguageHandler)1 StructureLoadingUtils (com.ldtteam.structurize.util.StructureLoadingUtils)1 File (java.io.File)1