Add basic validation for moving items into the table's slots
This commit is contained in:
parent
840c1b0105
commit
05a831d643
61
table.lua
61
table.lua
@ -459,16 +459,52 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
|||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
-- Called after a table is placed. Sets up the table's inventory and metadata.
|
||||||
|
-- pos: The node's position
|
||||||
local function setup_table_node(pos)
|
local function setup_table_node(pos)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
meta:get_inventory():set_size("input", 1);
|
meta:get_inventory():set_size("input", 1);
|
||||||
meta:get_inventory():set_size("output", 1);
|
meta:get_inventory():set_size("output", 1);
|
||||||
meta:get_inventory():set_size("copy_input", 1);
|
meta:get_inventory():set_size("copy_input", 1);
|
||||||
meta:get_inventory():set_size("copy_output", 1);
|
meta:get_inventory():set_size("copy_output", 1);
|
||||||
|
|
||||||
meta:set_int("size", SIZE_SMALL);
|
meta:set_int("size", SIZE_SMALL);
|
||||||
meta:set_int("scale", SCALE_SMALL);
|
meta:set_int("scale", SCALE_SMALL);
|
||||||
meta:set_int("detail", 0);
|
meta:set_int("detail", 0);
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Called when the player tries to put an item into one of the table's
|
||||||
|
-- inventories.
|
||||||
|
-- listname: The name of the inventory the item is being placed in.
|
||||||
|
-- stack: The itemstack
|
||||||
|
--
|
||||||
|
-- Returns 0 if the place is invalid; otherwise, returns the number of items
|
||||||
|
-- that can be placed.
|
||||||
|
local function table_can_put(_, listname, _, stack, _)
|
||||||
|
if listname == "copy_output" then
|
||||||
|
return 0;
|
||||||
|
end
|
||||||
|
|
||||||
|
if stack:get_name() ~= "cartographer:map" and (listname == "output" or listname == "copy_input") then
|
||||||
|
return 0;
|
||||||
|
end
|
||||||
|
|
||||||
|
return stack:get_count();
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Called when the player tries to move an item between two of the table's
|
||||||
|
-- inventories.
|
||||||
|
-- to_list: The name of the inventory the item is being placed in.
|
||||||
|
-- count: The number of items being moved
|
||||||
|
--
|
||||||
|
-- Returns 0 if the move is invalid; otherwise, returns the number of items
|
||||||
|
-- that can be moved.
|
||||||
|
local function table_can_move(_, _, _, to_list, _, count, _)
|
||||||
|
if to_list == "copy_output" then
|
||||||
|
return 0;
|
||||||
|
end
|
||||||
|
|
||||||
|
return count;
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("cartographer:simple_table", {
|
minetest.register_node("cartographer:simple_table", {
|
||||||
@ -501,6 +537,9 @@ minetest.register_node("cartographer:simple_table", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_place_node = setup_table_node,
|
after_place_node = setup_table_node,
|
||||||
|
|
||||||
|
allow_metadata_inventory_move = table_can_move,
|
||||||
|
allow_metadata_inventory_put = table_can_put,
|
||||||
});
|
});
|
||||||
|
|
||||||
minetest.register_node("cartographer:standard_table", {
|
minetest.register_node("cartographer:standard_table", {
|
||||||
@ -533,6 +572,9 @@ minetest.register_node("cartographer:standard_table", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_place_node = setup_table_node,
|
after_place_node = setup_table_node,
|
||||||
|
|
||||||
|
allow_metadata_inventory_move = table_can_move,
|
||||||
|
allow_metadata_inventory_put = table_can_put,
|
||||||
});
|
});
|
||||||
|
|
||||||
minetest.register_node("cartographer:advanced_table", {
|
minetest.register_node("cartographer:advanced_table", {
|
||||||
@ -565,6 +607,9 @@ minetest.register_node("cartographer:advanced_table", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
after_place_node = setup_table_node,
|
after_place_node = setup_table_node,
|
||||||
|
|
||||||
|
allow_metadata_inventory_move = table_can_move,
|
||||||
|
allow_metadata_inventory_put = table_can_put,
|
||||||
});
|
});
|
||||||
|
|
||||||
function cartographer.register_map_material_name(name, material, value)
|
function cartographer.register_map_material_name(name, material, value)
|
||||||
|
Loading…
Reference in New Issue
Block a user