forked from MineClone5/MineClone5
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:
parent
caac96b50e
commit
cc81b51128
|
@ -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()
|
||||
--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
|
||||
|
|
Loading…
Reference in New Issue