use of com.minecolonies.coremod.network.messages.SaveScanMessage in project minecolonies by Minecolonies.
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.
*/
private static void saveStructure(@Nullable final World world, @Nullable final BlockPos from, @Nullable final BlockPos to, @NotNull final EntityPlayer player) {
//todo if on clientSide check if isRemote and if it is -> don't seed message, execute right away.
if (world == null || from == null || to == null) {
throw new IllegalArgumentException("Invalid method call, arguments can't be null. Contact a developer.");
}
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).add(1, 1, 1);
final WorldServer worldserver = (WorldServer) world;
final MinecraftServer minecraftserver = world.getMinecraftServer();
final TemplateManager templatemanager = worldserver.getStructureTemplateManager();
final long currentMillis = System.currentTimeMillis();
final String currentMillisString = Long.toString(currentMillis);
final String fileName = "/minecolonies/scans/" + LanguageHandler.format("item.scepterSteel.scanFormat", "", currentMillisString + ".nbt");
final Template template = templatemanager.getTemplate(minecraftserver, new ResourceLocation(fileName));
template.takeBlocksFromWorld(world, blockpos, size, true, Blocks.STRUCTURE_VOID);
template.setAuthor(Constants.MOD_ID);
MineColonies.getNetwork().sendTo(new SaveScanMessage(template.writeToNBT(new NBTTagCompound()), currentMillis), (EntityPlayerMP) player);
}
Aggregations