fix map in itemframes

Fix the map in iteframes problem in newly created worlds but might not work in older ones+ add tga dependancy
This commit is contained in:
3raven 2022-05-31 12:17:52 +00:00
parent caac96b50e
commit cc81b51128
1 changed files with 20 additions and 16 deletions

View File

@ -57,7 +57,8 @@ function mcl_maps.create_map(pos)
local map_y_start = 64 * dx local map_y_start = 64 * dx
local map_y_limit = 127 * dx local map_y_limit = 127 * dx
local pixels = "" --local pixels = ""
local pixels = {}
local last_heightmap local last_heightmap
for x = 1, 128 do for x = 1, 128 do
local map_x = x + offset local map_x = x + offset
@ -127,48 +128,51 @@ function mcl_maps.create_map(pos)
height = map_y - map_z height = map_y - map_z
heightmap[z] = height or minp.y heightmap[z] = height or minp.y
pixels[z] = pixels[z] or {}
if not color then color = {0, 0, 0} end pixels[z][x] = color or {0, 0, 0}
pixels = pixels .. minetest.colorspec_to_bytes({r = color[1], g = color[2], b = color[3]}) --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 end
last_heightmap = heightmap last_heightmap = heightmap
end end
local png = minetest.encode_png(128, 128, pixels) --local png = minetest.encode_png(128, 128, pixels)
local f = io.open(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".png", "wb") --local f = io.open(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".png", "wb")
if not f then return end --if not f then return end
f:write(png) --f:write(png)
f:close() --f:close()
creating_maps[id] = nil tga_encoder.image(pixels):save(map_textures_path .. "mcl_maps_map_texture_" .. id .. ".tga")
creating_maps[id] = nil
end) end)
return itemstack return itemstack
end end
local loading_maps = {} --local loading_maps = {}
function mcl_maps.load_map(id, callback) 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 return
end 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 if not loaded_maps[id] then
loading_maps[id] = true --loading_maps[id] = true
if not minetest.features.dynamic_add_media_table then if not minetest.features.dynamic_add_media_table then
-- minetest.dynamic_add_media() blocks in -- minetest.dynamic_add_media() blocks in
-- Minetest 5.3 and 5.4 until media loads -- Minetest 5.3 and 5.4 until media loads
dynamic_add_media(map_textures_path .. texture, function(player_name) end) dynamic_add_media(map_textures_path .. texture, function(player_name) end)
loaded_maps[id] = true loaded_maps[id] = true
if callback then callback(texture) end if callback then callback(texture) end
loading_maps[id] = nil --loading_maps[id] = nil
else else
-- minetest.dynamic_add_media() never blocks -- minetest.dynamic_add_media() never blocks
-- in Minetest 5.5, callback runs after load -- in Minetest 5.5, callback runs after load
dynamic_add_media(map_textures_path .. texture, function(player_name) dynamic_add_media(map_textures_path .. texture, function(player_name)
loaded_maps[id] = true loaded_maps[id] = true
if callback then callback(texture) end if callback then callback(texture) end
loading_maps[id] = nil --loading_maps[id] = nil
end) end)
end end
end end