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

@ -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));