From cc81b51128753de2f5ad0455c7871522a50104a8 Mon Sep 17 00:00:00 2001 From: 3raven Date: Tue, 31 May 2022 12:17:52 +0000 Subject: [PATCH] fix map in itemframes Fix the map in iteframes problem in newly created worlds but might not work in older ones+ add tga dependancy --- mods/ITEMS/mcl_maps/init.lua | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index b33e83d78..0c88fc1d6 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -57,7 +57,8 @@ function mcl_maps.create_map(pos) local map_y_start = 64 * dx local map_y_limit = 127 * dx - local pixels = "" + --local pixels = "" + local pixels = {} local last_heightmap for x = 1, 128 do local map_x = x + offset @@ -127,48 +128,51 @@ function mcl_maps.create_map(pos) height = map_y - map_z heightmap[z] = height or minp.y - - if not color then color = {0, 0, 0} end - pixels = pixels .. minetest.colorspec_to_bytes({r = color[1], g = color[2], b = color[3]}) + pixels[z] = pixels[z] or {} + pixels[z][x] = color or {0, 0, 0} + --if not color then color = {0, 0, 0} end + --pixels = pixels .. minetest.colorspec_to_bytes({r = color[1], g = color[2], b = color[3]}) end last_heightmap = heightmap end - local png = minetest.encode_png(128, 128, pixels) - local f = io.open(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".png", "wb") - if not f then return end - f:write(png) - f:close() - creating_maps[id] = nil + --local png = minetest.encode_png(128, 128, pixels) + --local f = io.open(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".png", "wb") + --if not f then return end + --f:write(png) + --f:close() + tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga") + creating_maps[id] = nil end) return itemstack end -local loading_maps = {} +--local loading_maps = {} function mcl_maps.load_map(id, callback) - if id == "" or creating_maps[id] or loading_maps[id] then + if id == "" or creating_maps[id] then--or loading_maps[id] then return end - local texture = "mcl_maps_map_texture_" .. id .. ".png" + --local texture = "mcl_maps_map_texture_" .. id .. ".png" + local texture = "mcl_maps_map_texture_" .. id .. ".tga" if not loaded_maps[id] then - loading_maps[id] = true + --loading_maps[id] = true if not minetest.features.dynamic_add_media_table then -- minetest.dynamic_add_media() blocks in -- Minetest 5.3 and 5.4 until media loads dynamic_add_media(map_textures_path .. texture, function(player_name) end) loaded_maps[id] = true if callback then callback(texture) end - loading_maps[id] = nil + --loading_maps[id] = nil else -- minetest.dynamic_add_media() never blocks -- in Minetest 5.5, callback runs after load dynamic_add_media(map_textures_path .. texture, function(player_name) loaded_maps[id] = true if callback then callback(texture) end - loading_maps[id] = nil + --loading_maps[id] = nil end) end end