Skip to content

Commit

Permalink
Add chest with limited access for testing, update some debug prints.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfence committed Jun 25, 2024
1 parent fb6ceb2 commit ba651c3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
53 changes: 53 additions & 0 deletions games/devtest/mods/chest/chest_limited.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local function print_to_everything(msg)
minetest.log("action", "[chest] " .. msg)
minetest.chat_send_all(msg)
end

minetest.register_node("chest:chest_limited", {
description = "Chest Limited" .. "\n" ..
"32 inventory slots" .. "\n" ..
"Allowed items for put/take/move quals to slot index.",
tiles ={"chest_chest.png^[sheet:2x2:0,0", "chest_chest.png^[sheet:2x2:0,0",
"chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:1,0",
"chest_chest.png^[sheet:2x2:1,0", "chest_chest.png^[sheet:2x2:0,1"},
paramtype2 = "4dir",
groups = {dig_immediate=2,choppy=3,meta_is_privatizable=1},
is_ground_content = false,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,9]"..
"list[current_name;main;0,0;8,4;]"..
"list[current_player;main;0,5;8,4;]" ..
"listring[]")
meta:set_string("infotext", "Chest Limited")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " triggered 'allow put' ("..index..") event for " .. stack:to_string())
return index
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " triggered 'allow take' ("..index..") event for " .. stack:to_string())
return index
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " triggered 'allow move' ("..from_index..") event")
return from_index
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " put " .. stack:to_string())
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " took " .. stack:to_string())
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
print_to_everything("Chest Limited: ".. player:get_player_name() .. " moved " .. count)
end,
})
1 change: 1 addition & 0 deletions games/devtest/mods/chest/init.lua
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dofile(minetest.get_modpath("chest").."/chest.lua")
dofile(minetest.get_modpath("chest").."/chest_limited.lua")
dofile(minetest.get_modpath("chest").."/detached.lua")
8 changes: 4 additions & 4 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4785,7 +4785,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
}

if (move_amount > 0) {
infostream << "Handing IAction::Move to manager" << std::endl;
infostream << "Handing IAction::Move to manager (move)" << std::endl;
IMoveAction *a = new IMoveAction();
a->count = move_amount;
a->from_inv = m_selected_item->inventoryloc;
Expand Down Expand Up @@ -4820,7 +4820,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (pickup_amount > 0) {
m_selected_amount += pickup_amount;

infostream << "Handing IAction::Move to manager" << std::endl;
infostream << "Handing IAction::Move to manager (pickup)" << std::endl;
IMoveAction *a = new IMoveAction();
a->count = pickup_amount;
a->from_inv = s.inventoryloc;
Expand Down Expand Up @@ -4855,7 +4855,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
if (shift_move_amount == 0)
break;

infostream << "Handing IAction::Move to manager" << std::endl;
infostream << "Handing IAction::Move to manager (shift-move)" << std::endl;
IMoveAction *a = new IMoveAction();
a->count = shift_move_amount;
a->from_inv = s.inventoryloc;
Expand All @@ -4879,7 +4879,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
assert(drop_amount > 0 && drop_amount <= m_selected_amount);
m_selected_amount -= drop_amount;

infostream << "Handing IAction::Drop to manager" << std::endl;
infostream << "Handing IAction::Drop to manager (drop)" << std::endl;
IDropAction *a = new IDropAction();
a->count = drop_amount;
a->from_inv = m_selected_item->inventoryloc;
Expand Down

0 comments on commit ba651c3

Please sign in to comment.