mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Merge b005b62f0c61e8a2ad3717110a9a7276efda71ed into 9a1501ae89ffe79c38dbd6756c9e7ed647dd7dc1
This commit is contained in:
commit
ce1b0c8e82
53
games/devtest/mods/chest/chest_limited.lua
Normal file
53
games/devtest/mods/chest/chest_limited.lua
Normal file
@ -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,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")
|
||||
|
@ -3799,10 +3799,6 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text,
|
||||
|
||||
void GUIFormSpecMenu::updateSelectedItem()
|
||||
{
|
||||
// Don't update when dragging an item
|
||||
if (m_selected_item && (m_selected_dragging || m_left_dragging))
|
||||
return;
|
||||
|
||||
verifySelectedItem();
|
||||
|
||||
// If craftresult is not empty and nothing else is selected,
|
||||
@ -4474,7 +4470,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||
m_client->inhibit_inventory_revert = true;
|
||||
m_left_drag_stack = list_selected->getItem(m_selected_item->i);
|
||||
m_left_drag_amount = m_selected_amount;
|
||||
m_left_drag_stacks.emplace_back(s, list_s->getItem(s.i));
|
||||
m_left_drag_stacks.emplace_back(s, list_s->getItem(s.i).count);
|
||||
move_amount = 0;
|
||||
|
||||
} else if (identical) {
|
||||
@ -4535,7 +4531,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||
Inventory *inv_to = m_invmgr->getInventory(ds.first.inventoryloc);
|
||||
InventoryList *list_to = inv_to->getList(ds.first.listname);
|
||||
ItemStack stack_to = list_to->getItem(ds.first.i);
|
||||
u16 amount = stack_to.count - ds.second.count;
|
||||
u16 amount = stack_to.count - ds.second;
|
||||
|
||||
IMoveAction *a = new IMoveAction();
|
||||
a->count = amount;
|
||||
@ -4597,7 +4593,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
m_left_drag_stacks.emplace_back(s, list_s->getItem(s.i));
|
||||
m_left_drag_stacks.emplace_back(s, list_s->getItem(s.i).count);
|
||||
}
|
||||
|
||||
} else if (m_selected_dragging && matching && !identical) {
|
||||
@ -4726,7 +4722,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||
|
||||
} else {
|
||||
// Reset the stack to its original state
|
||||
list_to->changeItem(ds.first.i, ds.second);
|
||||
ItemStack orig_stack = list_to->getItem(ds.first.i);
|
||||
orig_stack.count = ds.second;
|
||||
list_to->changeItem(ds.first.i, orig_stack);
|
||||
|
||||
// Add the new split to the stack
|
||||
ItemStack add_stack = stack_from;
|
||||
@ -4785,7 +4783,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;
|
||||
@ -4820,7 +4818,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;
|
||||
@ -4855,7 +4853,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;
|
||||
@ -4879,7 +4877,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;
|
||||
|
@ -363,7 +363,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
||||
|
||||
u16 m_left_drag_amount = 0;
|
||||
ItemStack m_left_drag_stack;
|
||||
std::vector<std::pair<GUIInventoryList::ItemSpec, ItemStack>> m_left_drag_stacks;
|
||||
std::vector<std::pair<GUIInventoryList::ItemSpec, u16>> m_left_drag_stacks;
|
||||
bool m_left_dragging = false;
|
||||
|
||||
gui::IGUIStaticText *m_tooltip_element = nullptr;
|
||||
|
@ -460,7 +460,6 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
||||
if (from_inv.type == InventoryLocation::PLAYER)
|
||||
list_from->setModified();
|
||||
|
||||
if (to_inv.type == InventoryLocation::PLAYER)
|
||||
list_to->setModified();
|
||||
|
||||
infostream<<"IMoveAction::apply(): move was completely disallowed:"
|
||||
|
Loading…
Reference in New Issue
Block a user