• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blockexchange / blockexchange / 13331571900

14 Feb 2025 02:48PM UTC coverage: 52.251% (+0.4%) from 51.84%
13331571900

push

github

BuckarooBanzay
deduplicate schemapart code

12 of 13 new or added lines in 5 files covered. (92.31%)

48 existing lines in 8 files now uncovered.

975 of 1866 relevant lines covered (52.25%)

1898.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.93
/commands/load_local.lua
1

2
function blockexchange.load_local(playername, origin, schemaname)
2✔
3
    local ctx = {
1✔
4
        hud_icon = "blockexchange_download.png",
5
                hud_text = "Local download '" .. schemaname .. "' starting"
1✔
6
        }
7

8
    local current_part = 0
1✔
9
    local zip
10

11
    local promise = Promise.async(function(await)
2✔
12

13
        local err
14
        local filename = blockexchange.get_local_filename(schemaname)
1✔
15
        local zipfile = io.open(filename, "rb")
1✔
16
        if not zipfile then
1✔
17
            error("file not found: " .. filename, 0)
×
18
        end
19
        zip, err = mtzip.unzip(zipfile)
2✔
20
        if err then
1✔
21
            error("unzip error: " .. err, 0)
×
22
        end
23

24
        local schema_str
25
        schema_str, err = zip:get("schema.json", true)
2✔
26
        if err then
1✔
27
            error("schema.json error: " .. err, 0)
×
28
        end
29
        local schema = minetest.parse_json(schema_str)
1✔
30

31
        local pos2 = vector.add(origin, blockexchange.get_schema_size(schema))
2✔
32
        pos2 = vector.subtract(pos2, 1)
2✔
33
        blockexchange.set_pos(2, playername, pos2)
1✔
34
        local total_parts = blockexchange.count_schemaparts(origin, pos2)
1✔
35

36
                for current_pos in blockexchange.iterator(origin, origin, pos2) do
19✔
37
            -- TODO: maybe iterate over files instead of map-parts
38
                        local relative_pos = vector.subtract(current_pos, origin)
8✔
39
                        local entry_filename = "schemapart_" .. relative_pos.x .. "_" .. relative_pos.y .. "_" .. relative_pos.z .. ".json"
8✔
40
                        local entry = zip:get_entry(entry_filename)
8✔
41
                        if entry then
8✔
42
                                -- non-air part
43
                local schemapart_str
44
                                schemapart_str, err = zip:get(entry_filename, true)
16✔
45
                                if err then
8✔
46
                                        error("schemapart error: " .. err, 0)
×
47
                                end
48
                                local schemapart = minetest.parse_json(schemapart_str)
8✔
49

50
                                -- increment stats
51
                                current_part = current_part + 1
8✔
52
                                local progress_percent = math.floor(current_part / total_parts * 100 * 10) / 10
8✔
53
                ctx.hud_text = "Local download '" .. schemaname ..
8✔
54
                                    "', progress: " .. progress_percent .. " %"
8✔
55

56
                                blockexchange.place_schemapart(schemapart, origin)
8✔
57
                                minetest.log("action", "[blockexchange] Extraction of part " .. minetest.pos_to_string(current_pos) .. " completed")
16✔
58
                        end
59

60
                        if ctx.cancel then
8✔
61
                                error("canceled", 0)
×
62
                        end
63
                        await(Promise.after(blockexchange.min_delay))
16✔
64
                end
65

66
                return {
1✔
67
            total_parts = total_parts
1✔
68
        }
1✔
69
        end)
70

71
    blockexchange.set_job_context(playername, ctx, promise)
1✔
72
    return promise
1✔
73
end
74

75

76
Promise.register_chatcommand("bx_load_local", {
2✔
77
    params = "<schemaname>",
78
    description = "loads a local schema to the selected pos1",
79
    privs = {blockexchange = true},
1✔
80
    func = function(name, schemaname)
UNCOV
81
        if blockexchange.get_job_context(name) then
×
82
            return true, "There is a job already running"
×
83
        end
84

85
        if not schemaname or schemaname == "" then
×
UNCOV
86
            return false, "Usage: /bx_load <username> <schemaname>"
×
87
        end
88

89
        local pos1 = blockexchange.get_pos(1, name)
×
90

UNCOV
91
        if not pos1 then return false, "you need to set /bx_pos1 first!" end
×
92

UNCOV
93
        return blockexchange.load_local(name, pos1, schemaname):next(function(result)
×
94
            return "Local extraction complete with " .. result.total_parts .. " parts"
×
95
        end)
96
    end
97
})
1✔
98

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc