use of com.ldtteam.structurize.api.util.constant.TranslationConstants.ANCHOR_POS_OUTSIDE_SCHEMATIC 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);
}
Aggregations