Search in sources :

Example 1 with SaveScanMessage

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);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) SaveScanMessage(com.minecolonies.coremod.network.messages.SaveScanMessage) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

SaveScanMessage (com.minecolonies.coremod.network.messages.SaveScanMessage)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldServer (net.minecraft.world.WorldServer)1 Template (net.minecraft.world.gen.structure.template.Template)1 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)1