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);
}
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;
}
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());
}
}
Aggregations