diff --git a/map_api.lua b/map_api.lua index 3f6a94c..f2a54e0 100644 --- a/map_api.lua +++ b/map_api.lua @@ -49,7 +49,7 @@ function cartographer.fill_local(id, x, z) local map = cartographer.get_map(id); if map ~= nil and x >= map.x - 2 and x <= map.x + map.w + 1 and z >= map.z - 2 and z <= map.z + map.h + 1 then - minetest.chat_send_all("[" .. tostring(x) .. ", " .. tostring(z) .. "] - [" .. tostring(map.x - 2) .. ", " .. tostring(map.z - 2) .. "], [" .. tostring(map.x + map.w + 1) .. ", " .. tostring(map.z + map.h + 1) .. "]"); + -- minetest.chat_send_all("[" .. tostring(x) .. ", " .. tostring(z) .. "] - [" .. tostring(map.x - 2) .. ", " .. tostring(map.z - 2) .. "], [" .. tostring(map.x + map.w + 1) .. ", " .. tostring(map.z + map.h + 1) .. "]"); cartographer.fill(map, x - 2, z - 2, 5, 5); end end @@ -65,23 +65,25 @@ minetest.register_globalstep(function(dt) for _,p in ipairs(minetest.get_connected_players()) do local inventory = p:get_inventory(); local pos = p:get_pos(); - local player_x = tochunk(pos.x); - local player_y = tochunk(pos.z); - for i = 1,inventory:get_size("main") do - local stack = inventory:get_stack("main", i); + if pos.y > -10 then + for i = 1,inventory:get_size("main") do + local stack = inventory:get_stack("main", i); - if stack:get_name() == "cartographer:map" then - cartographer.fill_local(stack:get_meta():get_int("cartographer:map_id"), player_x, player_y); + if stack:get_name() == "cartographer:map" then + local player_x = tochunk(pos.x); + local player_y = tochunk(pos.z); + cartographer.fill_local(stack:get_meta():get_int("cartographer:map_id"), player_x, player_y); + end end - end - for i = -2,2 do - for j = -2,2 do - local adjusted_pos = { - x = tochunk(pos.x + fromchunk(i)), - y = tochunk(pos.y), - z = tochunk(pos.z + fromchunk(j)), - } - cartographer.queue_region(adjusted_pos); + for i = -2,2 do + for j = -2,2 do + local adjusted_pos = { + x = tochunk(pos.x + fromchunk(i)), + y = tochunk(pos.y), + z = tochunk(pos.z + fromchunk(j)), + } + cartographer.queue_region(adjusted_pos); + end end end end @@ -113,7 +115,7 @@ function cartographer.is_filled(map, x, z) return false; end - minetest.chat_send_all(tostring(x).. ", " .. tostring(z) .. "(" .. tostring(x + (z * map.w)) .."): " .. tostring(map.fill[x + (z * map.w)])); + -- minetest.chat_send_all(tostring(x).. ", " .. tostring(z) .. "(" .. tostring(x + (z * map.w)) .."): " .. tostring(map.fill[x + (z * map.w)])); return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil; end diff --git a/map_formspec.lua b/map_formspec.lua index 1b7957f..1a7ba58 100644 --- a/map_formspec.lua +++ b/map_formspec.lua @@ -15,19 +15,19 @@ local map_formspec_prefix = [[ local tile = "image[%f,%f;%f,%f;%s]"; local marker = "animated_image[%f,%f;%f,%f;%s:%d,%d]"; -local function generate_map(data, x, y, w, h, player_x, player_y, spawn_x, spawn_y, death_x, death_y, detail, is_visible, user) +local function generate_map(data, x, y, w, h, player_x, player_y, spawn_x, spawn_y, death_x, death_y, detail, map_scale, is_visible, user) local str = ""; local random = PcgRandom(x + y + w + h); -- TODO: Better seed for i = x,x + w,1 do local fx = (i - x) * (scale - 0.01); - local column = data.generated[i]; + local column = data.generated[i * map_scale]; for j = y + h,y,-1 do local fy = (y + h - j) * (scale - 0.01); - if column == nil or column[j] == nil or (is_visible and not is_visible(user, i, j)) then + if column == nil or column[j * map_scale] == nil or (is_visible and not is_visible(user, i, j)) then str = str..tile:format(fx, fy, scale, scale, "cartographer_unknown_biome." .. tostring(get_variant(random)) .. ".png") else - local name = minetest.get_biome_name(column[j].biome); - local height = column[j].height; + local name = minetest.get_biome_name(column[j * map_scale].biome); + local height = column[j * map_scale].height; local biome = cartographer.get_biome_texture(name, math.floor(height + 0.5), detail); local depth = math.min(math.max(math.floor(height / 8), -8), 0) * -1 height = math.max(math.min(math.floor(height / 4), 8), 0) @@ -65,9 +65,9 @@ local function generate_map(data, x, y, w, h, player_x, player_y, spawn_x, spawn end function cartographer.get_map_formspec(data, x, y, w, h, spawn_x, spawn_y, death_x, death_y, detail) - return map_formspec_prefix:format(w * scale, h * scale)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, y, spawn_x, spawn_y, death_x, death_y, detail); + return map_formspec_prefix:format(w * scale, h * scale)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, y, spawn_x, spawn_y, death_x, death_y, detail, 4); end function cartographer.get_map_formspec_map(data, map, x, y, spawn_x, spawn_y, death_x, death_y) - return map_formspec_prefix:format(map.w * scale, map.h * scale)..generate_map(data, map.x, map.z, map.w, map.h, x, y, spawn_x, spawn_y, death_x, death_y, map.detail, cartographer.is_filled, map); + return map_formspec_prefix:format(map.w * scale, map.h * scale)..generate_map(data, map.x, map.z, map.w, map.h, x, y, spawn_x, spawn_y, death_x, death_y, map.detail, 1, cartographer.is_filled, map); end diff --git a/repixture.lua b/repixture.lua index 0836289..c264b03 100644 --- a/repixture.lua +++ b/repixture.lua @@ -90,7 +90,7 @@ cartographer.register_biome("Savanna Ocean", { }, 1); -- Materials -cartographer.register_map_material_name("default:paper", "fiber", 5); +cartographer.register_map_material_name("default:paper", "paper", 1); cartographer.register_map_material_name("default:lump_coal", "pigment"); cartographer.register_map_material_name("default:block_coal", "pigment", 9); @@ -103,3 +103,10 @@ crafting.register_craft({ "group:wood 6", }, }); +crafting.register_craft({ + output = "cartographer:standard_table", + items = { + "cartographer:simple_table", + "default:ingot_steel 6", + }, +}); diff --git a/scanner.lua b/scanner.lua index e8eb5b0..fb86b9e 100644 --- a/scanner.lua +++ b/scanner.lua @@ -8,7 +8,7 @@ local function register_mapchunk(x, y, biome, height) height = height, } }; - elseif not data.generated[x][y] then + elseif not data.generated[x][y] or data.generated[x][y].height < height then data.generated[x][y] = { biome = biome, height = height, diff --git a/table.lua b/table.lua index ce2f52c..454da92 100644 --- a/table.lua +++ b/table.lua @@ -7,21 +7,21 @@ local separator = [[ ]]; local function get_material_cost(size, detail) - local fiber = 0; + local paper = 0; local pigment = 0; if size == SIZE_SMALL then - fiber = fiber + 20; + paper = paper + 4; pigment = pigment + 5; elseif size == SIZE_LARGE then - fiber = fiber + 80; + paper = paper + 16; pigment = pigment + 20; end pigment = pigment + (detail * 5); return { - fiber = math.max(fiber, 0), + paper = math.max(paper, 0), pigment = math.max(pigment, 0), }; end @@ -35,7 +35,7 @@ local function get_full_material_cost(meta) local smeta = stack:get_meta(); local sub_cost = get_material_cost(smeta:get_int("cartographer:size") or SIZE_SMALL, (smeta:get_int("cartographer:detail") or 1) - 1); - cost.fiber = math.max(cost.fiber - sub_cost.fiber, 0); + cost.paper = math.max(cost.paper - sub_cost.paper, 0); cost.pigment = math.max(cost.pigment - sub_cost.pigment, 0); end @@ -63,25 +63,20 @@ function fs.header(w, h, rank, tab) end function fs.materials(x, y, rank, meta) - local fiber = meta:get_int("fiber"); + local paper = meta:get_int("paper"); local pigment = meta:get_int("pigment"); local data = [[ container[%f,%f] formspec_version[3] - label[0,0.25;Fiber x %d] + label[0,0.25;paper x %d] label[3,0.25;Pigment x %d] ]]; - data = data:format(x, y, fiber, pigment); + data = data:format(x, y, paper, pigment); if rank > 1 then data = data .. "label[6,0.25;Stuff x %d]"; data = data:format(0); - - if rank > 2 then - data = data .. "label[9,0.25;Things x %d]"; - data = data:format(0); - end end return data .. "container_end[]"; @@ -107,7 +102,7 @@ function fs.convert(x, y, pos) ]]; data = data:format(x, y, pos.x, pos.y, pos.z); data = data .. fs.cost(1.25, 0.25, { - Fiber = 0, + paper = 0, Pigment = 0, }) .. "container_end[]"; @@ -123,7 +118,7 @@ function fs.craft(x, y, pos, rank, meta) ]] .. separator:format(0.75); data = data:format(x, y, pos.x, pos.y, pos.z); - if rank > 2 then + if rank > 1 then local size = "s"; if meta:get_int("size") == SIZE_LARGE then size = "l"; @@ -164,7 +159,7 @@ function fs.copy(x, y, pos) ]]; data = data:format(x, y, pos.x, pos.y, pos.z, pos.x, pos.y, pos.z); data = data .. fs.cost(1.25, 0.25, { - Fiber = 0, + paper = 0, Pigment = 0, }) .. "container_end[]"; @@ -236,7 +231,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields) local inv = meta:get_inventory(); local stack = inv:get_stack("input", 1); - local fiber = meta:get_int("fiber"); + local paper = meta:get_int("paper"); local pigment = meta:get_int("pigment"); local item_name = stack:get_name(); @@ -245,7 +240,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields) for name,mats in pairs(_cartographer.materials_by_name) do if name == item_name then - fiber = fiber + ((mats.fiber or 0) * item_count); + paper = paper + ((mats.paper or 0) * item_count); pigment = pigment + ((mats.pigment or 0) * item_count); found_match = true; break; @@ -255,7 +250,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields) if not found_match then for group,mats in pairs(_cartographer.materials_by_group) do if minetest.get_item_group(item_name, group) ~= 0 then - fiber = fiber + ((mats.fiber or 0) * item_count); + paper = paper + ((mats.paper or 0) * item_count); pigment = pigment + ((mats.pigment or 0) * item_count); found_match = true; break; @@ -264,17 +259,17 @@ minetest.register_on_player_receive_fields(function(player, name, fields) end if found_match then - inv:set_stack("input", 1, ItemStack()); + inv:set_stack("input", 1, ItemStack(nil)); end - meta:set_int("fiber", fiber); + meta:set_int("paper", paper); meta:set_int("pigment", pigment); table_formspec(player:get_player_name(), 1) elseif fields["craft"] ~= nil then local size = meta:get_int("size"); local detail = meta:get_int("detail"); - local fiber = meta:get_int("fiber"); + local paper = meta:get_int("paper"); local pigment = meta:get_int("pigment"); @@ -284,10 +279,10 @@ minetest.register_on_player_receive_fields(function(player, name, fields) local cost = get_full_material_cost(meta); if stack:is_empty() then - if fiber >= cost.fiber and pigment >= cost.pigment then - fiber = fiber - cost.fiber; + if paper >= cost.paper and pigment >= cost.pigment then + paper = paper - cost.paper; pigment = pigment - cost.pigment; - meta:set_int("fiber", fiber); + meta:set_int("paper", paper); meta:set_int("pigment", pigment); inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail)); @@ -296,10 +291,10 @@ minetest.register_on_player_receive_fields(function(player, name, fields) local smeta = stack:get_meta(); local old_size = smeta:get_int("cartographer:size"); local old_detail = smeta:get_int("cartographer:detail") - 1; - if old_detail <= detail and old_size <= size and not (old_detail == detail and old_size == size) and fiber >= cost.fiber and pigment >= cost.pigment then - fiber = fiber - cost.fiber; + if old_detail <= detail and old_size <= size and not (old_detail == detail and old_size == size) and paper >= cost.paper and pigment >= cost.pigment then + paper = paper - cost.paper; pigment = pigment - cost.pigment; - meta:set_int("fiber", fiber); + meta:set_int("paper", paper); meta:set_int("pigment", pigment); smeta:set_int("cartographer:detail", 1 + detail); @@ -315,7 +310,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields) table_formspec(player:get_player_name(), 2) elseif fields["copy"] ~= nil then - local fiber = meta:get_int("fiber"); + local paper = meta:get_int("paper"); local pigment = meta:get_int("pigment"); local inv = meta:get_inventory(); @@ -329,10 +324,10 @@ minetest.register_on_player_receive_fields(function(player, name, fields) local detail = smeta:get_int("cartographer:detail") or 1; local cost = get_material_cost(size, detail - 1); - if fiber >= cost.fiber and pigment >= cost.pigment then - fiber = fiber - cost.fiber; + if paper >= cost.paper and pigment >= cost.pigment then + paper = paper - cost.paper; pigment = pigment - cost.pigment; - meta:set_int("fiber", fiber); + meta:set_int("paper", paper); meta:set_int("pigment", pigment); inv:set_stack("copy_output", 1, cartographer.copy_map_item(in_stack));