2020-02-16 18:55:07 +01:00
|
|
|
local SIZE_SMALL = 20;
|
|
|
|
local SIZE_LARGE = 40;
|
2020-03-08 15:34:20 +01:00
|
|
|
local SCALE_SMALL = 1;
|
|
|
|
local SCALE_LARGE = 4;
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw background elements in the same arrangement as inventory slots
|
|
|
|
-- x: The x position of the inventory
|
|
|
|
-- y: The y position of the inventory
|
|
|
|
-- cols: The width of the inventory, in columns
|
|
|
|
-- rows: The height of the inventory, in rows
|
|
|
|
-- skin: A 9-slice background skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
local function inventory_bg(x, y, cols, rows, skin)
|
|
|
|
local data = "";
|
|
|
|
for i = 0,cols - 1 do
|
|
|
|
for j = 0,rows - 1 do
|
|
|
|
data = data .. string.format("background9[%f,%f;1,1;%s.png;false;%s]",
|
|
|
|
x + (i * 1.25), y + (j * 1.25),
|
|
|
|
skin.texture,
|
|
|
|
tostring(skin.radius));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
|
|
|
|
local function get_material_cost(size, detail)
|
2020-03-07 16:26:24 +01:00
|
|
|
local paper = 0;
|
2020-02-16 18:55:07 +01:00
|
|
|
local pigment = 0;
|
|
|
|
|
|
|
|
if size == SIZE_SMALL then
|
2020-03-07 16:26:24 +01:00
|
|
|
paper = paper + 4;
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment + 5;
|
|
|
|
elseif size == SIZE_LARGE then
|
2020-03-07 16:26:24 +01:00
|
|
|
paper = paper + 16;
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment + 20;
|
|
|
|
end
|
|
|
|
|
|
|
|
pigment = pigment + (detail * 5);
|
|
|
|
|
|
|
|
return {
|
2020-03-07 16:26:24 +01:00
|
|
|
paper = math.max(paper, 0),
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = math.max(pigment, 0),
|
|
|
|
};
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_full_material_cost(meta)
|
|
|
|
local cost = get_material_cost(meta:get_int("size") or SIZE_SMALL, meta:get_int("detail") or 0);
|
|
|
|
|
|
|
|
local stack = meta:get_inventory():get_stack("output", 1);
|
|
|
|
if stack:get_name() == "cartographer:map" then
|
|
|
|
|
|
|
|
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);
|
2020-03-07 16:26:24 +01:00
|
|
|
cost.paper = math.max(cost.paper - sub_cost.paper, 0);
|
2020-02-16 18:55:07 +01:00
|
|
|
cost.pigment = math.max(cost.pigment - sub_cost.pigment, 0);
|
|
|
|
end
|
|
|
|
|
|
|
|
return cost;
|
|
|
|
end
|
|
|
|
|
|
|
|
local fs = {};
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw a 1px thick horizontal separator formspec element
|
|
|
|
-- y: The y position of the separator
|
|
|
|
-- skin: A 9-slice background skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.separator(y, skin)
|
|
|
|
return string.format("background9[0.1,%f;10.05,0.01;%s.png;false;%s]", y, skin.texture, tostring(skin.radius))
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw all the essential formspec data (size, background, styles, tabs)
|
|
|
|
-- w: The width of the formspec
|
|
|
|
-- h: The height of the formspec
|
|
|
|
-- rank: An into defining the 'rank' of the table being displayed
|
|
|
|
-- tab: An int defining the index of the selected tab
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.header(w, h, rank, tab, skin)
|
|
|
|
local data = "formspec_version[3]"
|
|
|
|
.. string.format("size[%f,%f]", w, h)
|
|
|
|
.. string.format("background9[-0.1,0;1,1;%s.png;true;%s]", skin.background.texture, tostring(skin.background.radius))
|
|
|
|
.. string.format("style_type[button;noclip=true;border=false;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png;bgimg_middle=%s;textcolor=%s]", skin.tab.texture, skin.tab.hovered_texture, skin.tab.pressed_texture, tostring(skin.tab.radius), skin.tab.font_color)
|
|
|
|
.. string.format("style[tab%d;noclip=true;border=false;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png;bgimg_middle=%s;textcolor=%s]", tab, skin.tab.selected_texture, skin.tab.selected_texture, skin.tab.selected_texture, tostring(skin.tab.radius), skin.tab.font_color)
|
|
|
|
.. string.format("button[0.25,-0.375;1.5,0.55;tab1;Materials]", tab)
|
|
|
|
.. string.format("button[1.75,-0.375;1.5,0.55;tab2;Create Map]", tab);
|
|
|
|
|
|
|
|
if rank >= 2 then
|
|
|
|
data = data .. string.format("button[3.25,-0.375;1.5,0.55;tab3;Copy Map]", tab);
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
return data .. string.format("style_type[button;border=false;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png;bgimg_middle=%s;textcolor=%s]", skin.button.texture, skin.button.hovered_texture, skin.button.pressed_texture, tostring(skin.button.radius), skin.button.font_color);
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw material counters from a table's metadata
|
|
|
|
-- x: The x position of the labels
|
|
|
|
-- y: The y position of the labels
|
|
|
|
-- meta: A metadata object containing the material quantities
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.materials(x, y, meta, skin)
|
|
|
|
return string.format("container[%f,%f]", x, y)
|
|
|
|
.. "formspec_version[3]"
|
|
|
|
.. string.format("background9[0,0.125;1,0.25;%s.png;false;%s]", skin.label.texture, tostring(skin.label.radius))
|
|
|
|
.. string.format("image[0.125,0.125;0.25,0.25;%s.png]", skin.paper_texture)
|
|
|
|
.. string.format("label[0.375,0.25;%sx %d]", minetest.get_color_escape_sequence(skin.label.font_color), meta:get_int("paper"))
|
|
|
|
.. string.format("background9[1.25,0.125;1,0.25;%s.png;false;%s]", skin.label.texture, tostring(skin.label.radius))
|
|
|
|
.. string.format("image[1.375,0.125;0.25,0.25;%s.png]", skin.pigment_texture)
|
|
|
|
.. string.format("label[1.625,0.25;%sx %d]", minetest.get_color_escape_sequence(skin.label.font_color), meta:get_int("pigment"))
|
|
|
|
.. "container_end[]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-04-04 01:35:59 +02:00
|
|
|
-- Draw a label with material costs from a table
|
|
|
|
-- x: The x position of the interface
|
|
|
|
-- y: The y position of the interface
|
|
|
|
-- materials: A table of material costs, with string keys for the material
|
|
|
|
-- names and iteger values
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.cost(x, y, materials, skin)
|
2020-02-16 18:55:07 +01:00
|
|
|
local data = "";
|
|
|
|
local i = 0;
|
2020-04-04 01:35:59 +02:00
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
for name,value in pairs(materials) do
|
2020-04-04 01:35:59 +02:00
|
|
|
data = data .. string.format("label[%f,%f;%s%s x %d]", x, y + (i * 0.25), minetest.get_color_escape_sequence(skin.label.font_color), name, value);
|
2020-02-16 18:55:07 +01:00
|
|
|
i = i + 1;
|
|
|
|
end
|
|
|
|
|
|
|
|
return data;
|
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw the material conversion tab UI
|
|
|
|
-- x: The x position of the interface
|
|
|
|
-- y: The y position of the interface
|
|
|
|
-- pos: The table position (for displaying the inventory)
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.convert(x, y, pos, skin)
|
|
|
|
return string.format("container[%f,%f]", x, y)
|
|
|
|
.. "formspec_version[3]"
|
|
|
|
.. inventory_bg(0, 0, 1, 1, skin.slot)
|
|
|
|
.. string.format("list[nodemeta:%d,%d,%d;input;0,0;1,1;]", pos.x, pos.y, pos.z)
|
|
|
|
.. "button[1.25,0.5;2,0.5;convert;Convert Materials]"
|
2020-04-04 01:35:59 +02:00
|
|
|
.. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }, skin)
|
2020-04-02 13:06:50 +02:00
|
|
|
.. "container_end[]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw the map crafting tab UI
|
|
|
|
-- x: The x position of the interface
|
|
|
|
-- y: The y position of the interface
|
|
|
|
-- pos: The table position (for displaying the inventory)
|
|
|
|
-- meta: A metadata object containing the table settings and material
|
|
|
|
-- quantities
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.craft(x, y, pos, rank, meta, skin)
|
|
|
|
local data = string.format("container[%f,%f]", x, y)
|
|
|
|
.. "formspec_version[3]"
|
|
|
|
.. inventory_bg(0, 0.75, 1, 1, skin.slot)
|
|
|
|
.. string.format("list[nodemeta:%d,%d,%d;output;0,0.75;1,1;]", pos.x, pos.y, pos.z)
|
|
|
|
.. "button[1.25,1.25;2,0.5;craft;Craft Map]"
|
2020-04-04 01:35:59 +02:00
|
|
|
.. fs.cost(1.25, 0.875, get_full_material_cost(meta), skin);
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-03-07 16:26:24 +01:00
|
|
|
if rank > 1 then
|
2020-02-16 18:55:07 +01:00
|
|
|
local size = "s";
|
|
|
|
if meta:get_int("size") == SIZE_LARGE then
|
|
|
|
size = "l";
|
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
data = data .. string.format("style[%s;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", size, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
|
|
|
|
.. "button[0,0;0.5,0.5;s;S]"
|
|
|
|
.. "button[0.5,0;0.5,0.5;l;L]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-03-08 15:34:20 +01:00
|
|
|
if rank > 2 then
|
|
|
|
local scale = "1x";
|
|
|
|
if meta:get_int("scale") == SCALE_LARGE then
|
|
|
|
scale = "4x";
|
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
data = data .. string.format("style[%s;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", scale, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
|
|
|
|
.. "button[3.5,0;0.5,0.5;1x;1x]"
|
|
|
|
.. "button[4.0,0;0.5,0.5;4x;4x]";
|
2020-03-08 15:34:20 +01:00
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
data = data .. string.format("style[%d;bgimg=%s.png;bgimg_hovered=%s.png;bgimg_pressed=%s.png]", meta:get_int("detail") + 1, skin.button.selected_texture, skin.button.selected_texture, skin.button.selected_texture)
|
|
|
|
.. "button[1.25,0;0.5,0.5;1;1]"
|
|
|
|
.. "button[1.75,0;0.5,0.5;2;2]";
|
2020-02-16 18:55:07 +01:00
|
|
|
if rank > 1 then
|
|
|
|
data = data .. "button[2.25,0;0.5,0.5;3;3]";
|
|
|
|
if rank > 2 then
|
|
|
|
data = data .. "button[2.75,0;0.5,0.5;4;4]";
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
return data .. "container_end[]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw the map copying tab UI
|
|
|
|
-- x: The x position of the interface
|
|
|
|
-- y: The y position of the interface
|
|
|
|
-- pos: The table position (for displaying the inventory)
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.copy(x, y, pos, skin)
|
|
|
|
return string.format("container[%f,%f]", x, y)
|
|
|
|
.. "formspec_version[3]"
|
|
|
|
.. inventory_bg(0, 0, 1, 1, skin.slot)
|
|
|
|
.. string.format("list[nodemeta:%d,%d,%d;copy_input;0,0;1,1;]", pos.x, pos.y, pos.z)
|
|
|
|
.. "button[1.25,0.5;2,0.5;copy;Copy Map]"
|
2020-04-04 01:35:59 +02:00
|
|
|
.. fs.cost(1.25, 0.125, { Paper = 0, Pigment = 0, }, skin)
|
2020-04-02 13:06:50 +02:00
|
|
|
.. inventory_bg(8.75, 0, 1, 1, skin.slot)
|
|
|
|
.. string.format("list[nodemeta:%d,%d,%d;copy_output;8.75,0;1,1;]", pos.x, pos.y, pos.z)
|
|
|
|
.. "container_end[]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Draw the player's inventory
|
|
|
|
-- x: The x position of the inventory
|
|
|
|
-- y: The y position of the inventory
|
|
|
|
-- skin: A formspec skin table
|
|
|
|
--
|
|
|
|
-- Returns a formspec string
|
|
|
|
function fs.inv(x, y, skin)
|
|
|
|
return string.format("container[%f,%f]", x, y)
|
|
|
|
.. "formspec_version[3]"
|
|
|
|
.. inventory_bg(0, 0, 8, 4, skin.slot)
|
|
|
|
.. "list[current_player;main;0,0;8,4;]"
|
|
|
|
.. "container_end[]";
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local player_tables = {};
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Show the table formspec to the specified player
|
|
|
|
-- The player must be recorded in player_tables in order to receive
|
|
|
|
-- a formspec.
|
|
|
|
--
|
|
|
|
-- player: A string containing the player's name
|
|
|
|
-- tab: Which tab of the interface to display
|
2020-02-16 18:55:07 +01:00
|
|
|
local function table_formspec(player, tab)
|
|
|
|
local pos = player_tables[player];
|
2020-04-02 13:06:50 +02:00
|
|
|
|
|
|
|
if not pos then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
|
|
|
|
local rank = 1;
|
2020-04-02 13:06:50 +02:00
|
|
|
local skin = cartographer.skin.table_skins.simple_table;
|
2020-02-16 18:55:07 +01:00
|
|
|
local name = minetest.get_node(pos).name;
|
|
|
|
if name == "cartographer:standard_table" then
|
|
|
|
rank = 2;
|
2020-04-02 13:06:50 +02:00
|
|
|
skin = cartographer.skin.table_skins.standard_table;
|
2020-02-16 18:55:07 +01:00
|
|
|
elseif name == "cartographer:advanced_table" then
|
|
|
|
rank = 3;
|
2020-04-02 13:06:50 +02:00
|
|
|
skin = cartographer.skin.table_skins.advanced_table;
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if tab == 1 then
|
|
|
|
minetest.show_formspec(player, "simple_table",
|
2020-04-02 13:06:50 +02:00
|
|
|
fs.header(10.25, 7.375, rank, tab, skin) ..
|
|
|
|
fs.materials(0.25, 0.1875, meta, skin) ..
|
|
|
|
fs.separator(0.6875, skin.separator) ..
|
|
|
|
fs.convert(0.25, 0.875, pos, skin) ..
|
|
|
|
fs.separator(2.125, skin.separator) ..
|
|
|
|
fs.inv(0.25, 2.375, skin)
|
2020-02-16 18:55:07 +01:00
|
|
|
);
|
|
|
|
elseif tab == 2 then
|
|
|
|
minetest.show_formspec(player, "simple_table",
|
2020-04-02 13:06:50 +02:00
|
|
|
fs.header(10.25, 8.0, rank, tab, skin) ..
|
|
|
|
fs.materials(0.25, 0.1875, meta, skin) ..
|
|
|
|
fs.separator(0.6875, skin.separator) ..
|
|
|
|
fs.craft(0.25, 0.875, pos, rank, meta, skin) ..
|
|
|
|
fs.separator(2.75, skin.separator) ..
|
|
|
|
fs.inv(0.25, 3, skin)
|
2020-02-16 18:55:07 +01:00
|
|
|
);
|
|
|
|
elseif tab == 3 then
|
|
|
|
minetest.show_formspec(player, "simple_table",
|
2020-04-02 13:06:50 +02:00
|
|
|
fs.header(10.25, 7.375, rank, tab, skin) ..
|
|
|
|
fs.materials(0.25, 0.1875, meta, skin) ..
|
|
|
|
fs.separator(0.6875, skin.separator) ..
|
|
|
|
fs.copy(0.25, 0.875, pos, skin) ..
|
|
|
|
fs.separator(2.125, skin.separator) ..
|
|
|
|
fs.inv(0.25, 2.375, skin)
|
2020-02-16 18:55:07 +01:00
|
|
|
);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-02 13:06:50 +02:00
|
|
|
-- Called when a player sends input to the server from a formspec
|
|
|
|
-- This callback handles player input in the table formspec
|
|
|
|
-- player: The player who sent the input
|
|
|
|
-- name: The formspec name
|
|
|
|
-- fields: A table containing the input
|
2020-02-16 18:55:07 +01:00
|
|
|
minetest.register_on_player_receive_fields(function(player, name, fields)
|
|
|
|
if name == "simple_table" then
|
|
|
|
minetest.chat_send_all(name..": ");
|
|
|
|
for k,v in pairs(fields) do
|
|
|
|
minetest.chat_send_all(tostring(k).." - "..tostring(v));
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = minetest.get_meta(player_tables[player:get_player_name()]);
|
|
|
|
|
|
|
|
if fields["convert"] ~= nil then
|
|
|
|
local inv = meta:get_inventory();
|
|
|
|
local stack = inv:get_stack("input", 1);
|
|
|
|
|
2020-03-07 16:26:24 +01:00
|
|
|
local paper = meta:get_int("paper");
|
2020-02-16 18:55:07 +01:00
|
|
|
local pigment = meta:get_int("pigment");
|
|
|
|
|
|
|
|
local item_name = stack:get_name();
|
|
|
|
local item_count = stack:get_count();
|
|
|
|
local found_match = false;
|
|
|
|
|
|
|
|
for name,mats in pairs(_cartographer.materials_by_name) do
|
|
|
|
if name == item_name then
|
2020-03-07 16:26:24 +01:00
|
|
|
paper = paper + ((mats.paper or 0) * item_count);
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment + ((mats.pigment or 0) * item_count);
|
|
|
|
found_match = true;
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2020-03-07 16:26:24 +01:00
|
|
|
paper = paper + ((mats.paper or 0) * item_count);
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment + ((mats.pigment or 0) * item_count);
|
|
|
|
found_match = true;
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if found_match then
|
2020-03-07 16:26:24 +01:00
|
|
|
inv:set_stack("input", 1, ItemStack(nil));
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-03-07 16:26:24 +01:00
|
|
|
meta:set_int("paper", paper);
|
2020-02-16 18:55:07 +01:00
|
|
|
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");
|
2020-03-08 15:34:20 +01:00
|
|
|
local scale = meta:get_int("scale");
|
2020-03-07 16:26:24 +01:00
|
|
|
local paper = meta:get_int("paper");
|
2020-02-16 18:55:07 +01:00
|
|
|
local pigment = meta:get_int("pigment");
|
|
|
|
|
|
|
|
|
|
|
|
local inv = meta:get_inventory();
|
|
|
|
local stack = inv:get_stack("output", 1);
|
|
|
|
|
|
|
|
local cost = get_full_material_cost(meta);
|
|
|
|
|
|
|
|
if stack:is_empty() then
|
2020-03-07 16:26:24 +01:00
|
|
|
if paper >= cost.paper and pigment >= cost.pigment then
|
|
|
|
paper = paper - cost.paper;
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment - cost.pigment;
|
2020-03-07 16:26:24 +01:00
|
|
|
meta:set_int("paper", paper);
|
2020-02-16 18:55:07 +01:00
|
|
|
meta:set_int("pigment", pigment);
|
|
|
|
|
2020-03-08 15:34:20 +01:00
|
|
|
inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail, scale));
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
local smeta = stack:get_meta();
|
|
|
|
local old_size = smeta:get_int("cartographer:size");
|
|
|
|
local old_detail = smeta:get_int("cartographer:detail") - 1;
|
2020-03-07 16:26:24 +01:00
|
|
|
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;
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment - cost.pigment;
|
2020-03-07 16:26:24 +01:00
|
|
|
meta:set_int("paper", paper);
|
2020-02-16 18:55:07 +01:00
|
|
|
meta:set_int("pigment", pigment);
|
|
|
|
|
|
|
|
smeta:set_int("cartographer:detail", 1 + detail);
|
|
|
|
cartographer.resize_map_item(smeta, size);
|
|
|
|
|
|
|
|
local map = cartographer.get_map(smeta:get_int("cartographer:map_id"));
|
|
|
|
if map ~= nil then
|
|
|
|
map.detail = 1 + detail;
|
|
|
|
end
|
|
|
|
inv:set_stack("output", 1, stack);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["copy"] ~= nil then
|
2020-03-07 16:26:24 +01:00
|
|
|
local paper = meta:get_int("paper");
|
2020-02-16 18:55:07 +01:00
|
|
|
local pigment = meta:get_int("pigment");
|
|
|
|
|
|
|
|
local inv = meta:get_inventory();
|
|
|
|
local in_stack = inv:get_stack("copy_input", 1);
|
|
|
|
local out_stack = inv:get_stack("copy_output", 1);
|
|
|
|
|
|
|
|
|
|
|
|
if out_stack:is_empty() and in_stack:get_name() == "cartographer:map" then
|
|
|
|
local smeta = in_stack:get_meta();
|
|
|
|
local size = smeta:get_int("cartographer:size") or SIZE_SMALL;
|
|
|
|
local detail = smeta:get_int("cartographer:detail") or 1;
|
|
|
|
local cost = get_material_cost(size, detail - 1);
|
|
|
|
|
2020-03-07 16:26:24 +01:00
|
|
|
if paper >= cost.paper and pigment >= cost.pigment then
|
|
|
|
paper = paper - cost.paper;
|
2020-02-16 18:55:07 +01:00
|
|
|
pigment = pigment - cost.pigment;
|
2020-03-07 16:26:24 +01:00
|
|
|
meta:set_int("paper", paper);
|
2020-02-16 18:55:07 +01:00
|
|
|
meta:set_int("pigment", pigment);
|
|
|
|
|
|
|
|
inv:set_stack("copy_output", 1, cartographer.copy_map_item(in_stack));
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
table_formspec(player:get_player_name(), 3)
|
|
|
|
elseif fields["s"] ~= nil then
|
|
|
|
meta:set_int("size", SIZE_SMALL);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["l"] ~= nil then
|
|
|
|
meta:set_int("size", SIZE_LARGE);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["1"] ~= nil then
|
|
|
|
meta:set_int("detail", 0);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["2"] ~= nil then
|
|
|
|
meta:set_int("detail", 1);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["3"] ~= nil then
|
|
|
|
meta:set_int("detail", 2);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["4"] ~= nil then
|
|
|
|
meta:set_int("detail", 3);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
2020-03-08 15:34:20 +01:00
|
|
|
elseif fields["1x"] ~= nil then
|
|
|
|
meta:set_int("scale", SCALE_SMALL);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
|
|
|
elseif fields["4x"] ~= nil then
|
|
|
|
meta:set_int("scale", SCALE_LARGE);
|
|
|
|
table_formspec(player:get_player_name(), 2)
|
2020-04-02 13:06:50 +02:00
|
|
|
elseif fields["tab1"] ~= nil then
|
|
|
|
table_formspec(player:get_player_name(), 1);
|
|
|
|
elseif fields["tab2"] ~= nil then
|
|
|
|
table_formspec(player:get_player_name(), 2);
|
|
|
|
elseif fields["tab3"] ~= nil then
|
|
|
|
table_formspec(player:get_player_name(), 3);
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end);
|
|
|
|
|
2020-03-08 14:55:51 +01:00
|
|
|
local function setup_table_node(pos)
|
|
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
meta:get_inventory():set_size("input", 1);
|
|
|
|
meta:get_inventory():set_size("output", 1);
|
|
|
|
meta:get_inventory():set_size("copy_input", 1);
|
|
|
|
meta:get_inventory():set_size("copy_output", 1);
|
|
|
|
|
|
|
|
meta:set_int("size", SIZE_SMALL);
|
2020-03-08 15:34:20 +01:00
|
|
|
meta:set_int("scale", SCALE_SMALL);
|
2020-03-08 14:55:51 +01:00
|
|
|
meta:set_int("detail", 0);
|
|
|
|
end
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
minetest.register_node("cartographer:simple_table", {
|
|
|
|
description = "Shabby Cartographer's Table",
|
|
|
|
drawtype = "mesh",
|
2020-04-02 13:06:50 +02:00
|
|
|
mesh = cartographer.skin.table_skins.simple_table.node_mesh,
|
|
|
|
tiles = { cartographer.skin.table_skins.simple_table.node_texture },
|
2020-02-16 18:55:07 +01:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {
|
|
|
|
choppy = 2,
|
|
|
|
oddly_breakable_by_hand = 2,
|
|
|
|
},
|
2020-03-30 02:34:48 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
2020-02-16 18:55:07 +01:00
|
|
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
|
|
|
player_tables[player:get_player_name()] = minetest.get_pointed_thing_position(pointed_thing);
|
|
|
|
table_formspec(player:get_player_name(), 1)
|
|
|
|
end,
|
|
|
|
|
2020-03-08 14:55:51 +01:00
|
|
|
after_place_node = setup_table_node,
|
2020-02-16 18:55:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
minetest.register_node("cartographer:standard_table", {
|
2020-02-26 02:23:09 +01:00
|
|
|
description = "Simple Cartographer's Table",
|
|
|
|
drawtype = "mesh",
|
2020-04-02 13:06:50 +02:00
|
|
|
mesh = cartographer.skin.table_skins.standard_table.node_mesh,
|
|
|
|
tiles = { cartographer.skin.table_skins.standard_table.node_texture },
|
2020-02-26 02:23:09 +01:00
|
|
|
paramtype2 = "facedir",
|
2020-02-16 18:55:07 +01:00
|
|
|
groups = {
|
|
|
|
choppy = 2,
|
|
|
|
oddly_breakable_by_hand = 2,
|
|
|
|
},
|
2020-03-30 02:34:48 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
2020-02-16 18:55:07 +01:00
|
|
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
|
|
|
player_tables[player:get_player_name()] = minetest.get_pointed_thing_position(pointed_thing);
|
|
|
|
table_formspec(player:get_player_name(), 1)
|
|
|
|
end,
|
|
|
|
|
2020-03-08 14:55:51 +01:00
|
|
|
after_place_node = setup_table_node,
|
2020-02-16 18:55:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
minetest.register_node("cartographer:advanced_table", {
|
2020-03-08 14:55:51 +01:00
|
|
|
description = "Advanced Cartographer's Table",
|
2020-03-30 02:34:48 +02:00
|
|
|
drawtype = "mesh",
|
2020-04-02 13:06:50 +02:00
|
|
|
mesh = cartographer.skin.table_skins.advanced_table.node_mesh,
|
|
|
|
tiles = { cartographer.skin.table_skins.advanced_table.node_texture },
|
2020-03-08 14:55:51 +01:00
|
|
|
paramtype2 = "facedir",
|
2020-02-16 18:55:07 +01:00
|
|
|
groups = {
|
|
|
|
choppy = 2,
|
|
|
|
oddly_breakable_by_hand = 2,
|
|
|
|
},
|
2020-03-30 02:34:48 +02:00
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
collision_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.375, 0.5, 0.6875, 0.375},
|
|
|
|
},
|
|
|
|
},
|
2020-02-16 18:55:07 +01:00
|
|
|
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
|
|
|
player_tables[player:get_player_name()] = minetest.get_pointed_thing_position(pointed_thing);
|
|
|
|
table_formspec(player:get_player_name(), 1)
|
|
|
|
end,
|
|
|
|
|
2020-03-08 14:55:51 +01:00
|
|
|
after_place_node = setup_table_node,
|
2020-02-16 18:55:07 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
function cartographer.register_map_material_name(name, material, value)
|
|
|
|
if _cartographer.materials_by_name[name] == nil then
|
|
|
|
_cartographer.materials_by_name[name] = {
|
|
|
|
[material] = value or 1,
|
|
|
|
};
|
|
|
|
else
|
|
|
|
_cartographer.materials_by_name[name][material] = value;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function cartographer.register_map_material_group(name, material, value)
|
|
|
|
if _cartographer.materials_by_group[name] == nil then
|
|
|
|
_cartographer.materials_by_group[name] = {
|
|
|
|
[material] = value or 1,
|
|
|
|
};
|
|
|
|
else
|
|
|
|
_cartographer.materials_by_group[name][material] = value;
|
|
|
|
end
|
|
|
|
end
|