Add basic validation for moving items into the table's slots
This commit is contained in:
parent
840c1b0105
commit
05a831d643
45
table.lua
45
table.lua
@ -459,6 +459,8 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
||||
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 meta = minetest.get_meta(pos);
|
||||
meta:get_inventory():set_size("input", 1);
|
||||
@ -471,6 +473,40 @@ local function setup_table_node(pos)
|
||||
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
|
||||
|
||||
minetest.register_node("cartographer:simple_table", {
|
||||
description = "Shabby Cartographer's Table",
|
||||
drawtype = "mesh",
|
||||
@ -501,6 +537,9 @@ minetest.register_node("cartographer:simple_table", {
|
||||
end,
|
||||
|
||||
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", {
|
||||
@ -533,6 +572,9 @@ minetest.register_node("cartographer:standard_table", {
|
||||
end,
|
||||
|
||||
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", {
|
||||
@ -565,6 +607,9 @@ minetest.register_node("cartographer:advanced_table", {
|
||||
end,
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user