Various changes

This commit is contained in:
Hugues Ross 2020-03-07 10:26:24 -05:00
parent bce0db5e7a
commit 950414baf2
5 changed files with 62 additions and 58 deletions

View File

@ -49,7 +49,7 @@ function cartographer.fill_local(id, x, z)
local map = cartographer.get_map(id); 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 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); cartographer.fill(map, x - 2, z - 2, 5, 5);
end end
end end
@ -65,23 +65,25 @@ minetest.register_globalstep(function(dt)
for _,p in ipairs(minetest.get_connected_players()) do for _,p in ipairs(minetest.get_connected_players()) do
local inventory = p:get_inventory(); local inventory = p:get_inventory();
local pos = p:get_pos(); local pos = p:get_pos();
local player_x = tochunk(pos.x); if pos.y > -10 then
local player_y = tochunk(pos.z); for i = 1,inventory:get_size("main") do
for i = 1,inventory:get_size("main") do local stack = inventory:get_stack("main", i);
local stack = inventory:get_stack("main", i);
if stack:get_name() == "cartographer:map" then if stack:get_name() == "cartographer:map" then
cartographer.fill_local(stack:get_meta():get_int("cartographer:map_id"), player_x, player_y); 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
end for i = -2,2 do
for i = -2,2 do for j = -2,2 do
for j = -2,2 do local adjusted_pos = {
local adjusted_pos = { x = tochunk(pos.x + fromchunk(i)),
x = tochunk(pos.x + fromchunk(i)), y = tochunk(pos.y),
y = tochunk(pos.y), z = tochunk(pos.z + fromchunk(j)),
z = tochunk(pos.z + fromchunk(j)), }
} cartographer.queue_region(adjusted_pos);
cartographer.queue_region(adjusted_pos); end
end end
end end
end end
@ -113,7 +115,7 @@ function cartographer.is_filled(map, x, z)
return false; return false;
end 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; return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil;
end end

View File

@ -15,19 +15,19 @@ local map_formspec_prefix = [[
local tile = "image[%f,%f;%f,%f;%s]"; local tile = "image[%f,%f;%f,%f;%s]";
local marker = "animated_image[%f,%f;%f,%f;%s:%d,%d]"; 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 str = "";
local random = PcgRandom(x + y + w + h); -- TODO: Better seed local random = PcgRandom(x + y + w + h); -- TODO: Better seed
for i = x,x + w,1 do for i = x,x + w,1 do
local fx = (i - x) * (scale - 0.01); 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 for j = y + h,y,-1 do
local fy = (y + h - j) * (scale - 0.01); 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") str = str..tile:format(fx, fy, scale, scale, "cartographer_unknown_biome." .. tostring(get_variant(random)) .. ".png")
else else
local name = minetest.get_biome_name(column[j].biome); local name = minetest.get_biome_name(column[j * map_scale].biome);
local height = column[j].height; local height = column[j * map_scale].height;
local biome = cartographer.get_biome_texture(name, math.floor(height + 0.5), detail); 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 local depth = math.min(math.max(math.floor(height / 8), -8), 0) * -1
height = math.max(math.min(math.floor(height / 4), 8), 0) 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 end
function cartographer.get_map_formspec(data, x, y, w, h, spawn_x, spawn_y, death_x, death_y, detail) 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 end
function cartographer.get_map_formspec_map(data, map, x, y, spawn_x, spawn_y, death_x, death_y) 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 end

View File

@ -90,7 +90,7 @@ cartographer.register_biome("Savanna Ocean", {
}, 1); }, 1);
-- Materials -- 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:lump_coal", "pigment");
cartographer.register_map_material_name("default:block_coal", "pigment", 9); cartographer.register_map_material_name("default:block_coal", "pigment", 9);
@ -103,3 +103,10 @@ crafting.register_craft({
"group:wood 6", "group:wood 6",
}, },
}); });
crafting.register_craft({
output = "cartographer:standard_table",
items = {
"cartographer:simple_table",
"default:ingot_steel 6",
},
});

View File

@ -8,7 +8,7 @@ local function register_mapchunk(x, y, biome, height)
height = 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] = { data.generated[x][y] = {
biome = biome, biome = biome,
height = height, height = height,

View File

@ -7,21 +7,21 @@ local separator = [[
]]; ]];
local function get_material_cost(size, detail) local function get_material_cost(size, detail)
local fiber = 0; local paper = 0;
local pigment = 0; local pigment = 0;
if size == SIZE_SMALL then if size == SIZE_SMALL then
fiber = fiber + 20; paper = paper + 4;
pigment = pigment + 5; pigment = pigment + 5;
elseif size == SIZE_LARGE then elseif size == SIZE_LARGE then
fiber = fiber + 80; paper = paper + 16;
pigment = pigment + 20; pigment = pigment + 20;
end end
pigment = pigment + (detail * 5); pigment = pigment + (detail * 5);
return { return {
fiber = math.max(fiber, 0), paper = math.max(paper, 0),
pigment = math.max(pigment, 0), pigment = math.max(pigment, 0),
}; };
end end
@ -35,7 +35,7 @@ local function get_full_material_cost(meta)
local smeta = stack:get_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); 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); cost.pigment = math.max(cost.pigment - sub_cost.pigment, 0);
end end
@ -63,25 +63,20 @@ function fs.header(w, h, rank, tab)
end end
function fs.materials(x, y, rank, meta) 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 pigment = meta:get_int("pigment");
local data = [[ local data = [[
container[%f,%f] container[%f,%f]
formspec_version[3] formspec_version[3]
label[0,0.25;Fiber x %d] label[0,0.25;paper x %d]
label[3,0.25;Pigment 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 if rank > 1 then
data = data .. "label[6,0.25;Stuff x %d]"; data = data .. "label[6,0.25;Stuff x %d]";
data = data:format(0); data = data:format(0);
if rank > 2 then
data = data .. "label[9,0.25;Things x %d]";
data = data:format(0);
end
end end
return data .. "container_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:format(x, y, pos.x, pos.y, pos.z);
data = data .. fs.cost(1.25, 0.25, { data = data .. fs.cost(1.25, 0.25, {
Fiber = 0, paper = 0,
Pigment = 0, Pigment = 0,
}) .. "container_end[]"; }) .. "container_end[]";
@ -123,7 +118,7 @@ function fs.craft(x, y, pos, rank, meta)
]] .. separator:format(0.75); ]] .. separator:format(0.75);
data = data:format(x, y, pos.x, pos.y, pos.z); data = data:format(x, y, pos.x, pos.y, pos.z);
if rank > 2 then if rank > 1 then
local size = "s"; local size = "s";
if meta:get_int("size") == SIZE_LARGE then if meta:get_int("size") == SIZE_LARGE then
size = "l"; 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:format(x, y, pos.x, pos.y, pos.z, pos.x, pos.y, pos.z);
data = data .. fs.cost(1.25, 0.25, { data = data .. fs.cost(1.25, 0.25, {
Fiber = 0, paper = 0,
Pigment = 0, Pigment = 0,
}) .. "container_end[]"; }) .. "container_end[]";
@ -236,7 +231,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
local inv = meta:get_inventory(); local inv = meta:get_inventory();
local stack = inv:get_stack("input", 1); 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 pigment = meta:get_int("pigment");
local item_name = stack:get_name(); 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 for name,mats in pairs(_cartographer.materials_by_name) do
if name == item_name then 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); pigment = pigment + ((mats.pigment or 0) * item_count);
found_match = true; found_match = true;
break; break;
@ -255,7 +250,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
if not found_match then if not found_match then
for group,mats in pairs(_cartographer.materials_by_group) do for group,mats in pairs(_cartographer.materials_by_group) do
if minetest.get_item_group(item_name, group) ~= 0 then 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); pigment = pigment + ((mats.pigment or 0) * item_count);
found_match = true; found_match = true;
break; break;
@ -264,17 +259,17 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
end end
if found_match then if found_match then
inv:set_stack("input", 1, ItemStack()); inv:set_stack("input", 1, ItemStack(nil));
end end
meta:set_int("fiber", fiber); meta:set_int("paper", paper);
meta:set_int("pigment", pigment); meta:set_int("pigment", pigment);
table_formspec(player:get_player_name(), 1) table_formspec(player:get_player_name(), 1)
elseif fields["craft"] ~= nil then elseif fields["craft"] ~= nil then
local size = meta:get_int("size"); local size = meta:get_int("size");
local detail = meta:get_int("detail"); local detail = meta:get_int("detail");
local fiber = meta:get_int("fiber"); local paper = meta:get_int("paper");
local pigment = meta:get_int("pigment"); 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); local cost = get_full_material_cost(meta);
if stack:is_empty() then if stack:is_empty() then
if fiber >= cost.fiber and pigment >= cost.pigment then if paper >= cost.paper and pigment >= cost.pigment then
fiber = fiber - cost.fiber; paper = paper - cost.paper;
pigment = pigment - cost.pigment; pigment = pigment - cost.pigment;
meta:set_int("fiber", fiber); meta:set_int("paper", paper);
meta:set_int("pigment", pigment); meta:set_int("pigment", pigment);
inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail)); 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 smeta = stack:get_meta();
local old_size = smeta:get_int("cartographer:size"); local old_size = smeta:get_int("cartographer:size");
local old_detail = smeta:get_int("cartographer:detail") - 1; 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 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
fiber = fiber - cost.fiber; paper = paper - cost.paper;
pigment = pigment - cost.pigment; pigment = pigment - cost.pigment;
meta:set_int("fiber", fiber); meta:set_int("paper", paper);
meta:set_int("pigment", pigment); meta:set_int("pigment", pigment);
smeta:set_int("cartographer:detail", 1 + detail); 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) table_formspec(player:get_player_name(), 2)
elseif fields["copy"] ~= nil then elseif fields["copy"] ~= nil then
local fiber = meta:get_int("fiber"); local paper = meta:get_int("paper");
local pigment = meta:get_int("pigment"); local pigment = meta:get_int("pigment");
local inv = meta:get_inventory(); 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 detail = smeta:get_int("cartographer:detail") or 1;
local cost = get_material_cost(size, detail - 1); local cost = get_material_cost(size, detail - 1);
if fiber >= cost.fiber and pigment >= cost.pigment then if paper >= cost.paper and pigment >= cost.pigment then
fiber = fiber - cost.fiber; paper = paper - cost.paper;
pigment = pigment - cost.pigment; pigment = pigment - cost.pigment;
meta:set_int("fiber", fiber); meta:set_int("paper", paper);
meta:set_int("pigment", pigment); meta:set_int("pigment", pigment);
inv:set_stack("copy_output", 1, cartographer.copy_map_item(in_stack)); inv:set_stack("copy_output", 1, cartographer.copy_map_item(in_stack));