forked from Mirrorlandia_minetest/minetest
DevTest: Move detached inv tests to chest mod
This commit is contained in:
parent
c1e732448c
commit
a23701b5e6
45
games/devtest/mods/chest/chest.lua
Normal file
45
games/devtest/mods/chest/chest.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
local function print_to_everything(msg)
|
||||||
|
minetest.log("action", "[chest] " .. msg)
|
||||||
|
minetest.chat_send_all(msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node("chest:chest", {
|
||||||
|
description = "Chest" .. "\n" ..
|
||||||
|
"32 inventory slots",
|
||||||
|
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 = "facedir",
|
||||||
|
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")
|
||||||
|
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: ".. player:get_player_name() .. " triggered 'allow put' event for " .. stack:to_string())
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
print_to_everything("Chest: ".. player:get_player_name() .. " triggered 'allow take' event for " .. stack:to_string())
|
||||||
|
return stack:get_count()
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
print_to_everything("Chest: ".. player:get_player_name() .. " put " .. stack:to_string())
|
||||||
|
end,
|
||||||
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
print_to_everything("Chest: ".. player:get_player_name() .. " took " .. stack:to_string())
|
||||||
|
end,
|
||||||
|
})
|
58
games/devtest/mods/chest/detached.lua
Normal file
58
games/devtest/mods/chest/detached.lua
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
local ALLOW_PUT_MAX = 1
|
||||||
|
local ALLOW_TAKE_MAX = 4
|
||||||
|
|
||||||
|
local function print_to_everything(msg)
|
||||||
|
minetest.log("action", "[chest] " .. msg)
|
||||||
|
minetest.chat_send_all(msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create a detached inventory
|
||||||
|
local inv = minetest.create_detached_inventory("detached_inventory", {
|
||||||
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_move")
|
||||||
|
return count -- Allow all
|
||||||
|
end,
|
||||||
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
|
print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_put for "..stack:to_string().." (max. allowed: "..ALLOW_PUT_MAX..")")
|
||||||
|
return ALLOW_PUT_MAX -- Allow to put a limited amount of items
|
||||||
|
end,
|
||||||
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
|
print_to_everything("Detached inventory: "..player:get_player_name().." triggered allow_take for "..stack:to_string().." (max. allowed: "..ALLOW_TAKE_MAX..")")
|
||||||
|
return ALLOW_TAKE_MAX -- Allow to take a limited amount of items
|
||||||
|
end,
|
||||||
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
print_to_everything("Detached inventory: " .. player:get_player_name().." moved item(s)")
|
||||||
|
end,
|
||||||
|
on_put = function(inv, listname, index, stack, player)
|
||||||
|
print_to_everything("Detached inventory: " .. player:get_player_name().." put "..stack:to_string())
|
||||||
|
end,
|
||||||
|
on_take = function(inv, listname, index, stack, player)
|
||||||
|
print_to_everything("Detached inventory: " .. player:get_player_name().." took "..stack:to_string())
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
inv:set_size("main", 8*3)
|
||||||
|
|
||||||
|
|
||||||
|
-- Add a special chest to grant access to this inventory
|
||||||
|
minetest.register_node("chest:detached_chest", {
|
||||||
|
description = "Detached Chest" .. "\n" ..
|
||||||
|
"Grants access to a shared detached inventory" .."\n" ..
|
||||||
|
"Max. item put count: "..ALLOW_PUT_MAX .."\n"..
|
||||||
|
"Max. item take count: "..ALLOW_TAKE_MAX,
|
||||||
|
tiles = {"chest_detached_chest.png^[sheet:2x2:0,0", "chest_detached_chest.png^[sheet:2x2:0,0",
|
||||||
|
"chest_detached_chest.png^[sheet:2x2:1,0", "chest_detached_chest.png^[sheet:2x2:1,0",
|
||||||
|
"chest_detached_chest.png^[sheet:2x2:1,0", "chest_detached_chest.png^[sheet:2x2:0,1"},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
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[detached:detached_inventory;main;0,0;8,3;0]"..
|
||||||
|
"list[current_player;main;0,5;8,4;]"..
|
||||||
|
"listring[]")
|
||||||
|
meta:set_string("infotext", "Detached Chest")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
@ -1,40 +1,2 @@
|
|||||||
minetest.register_node("chest:chest", {
|
dofile(minetest.get_modpath("chest").."/chest.lua")
|
||||||
description = "Chest" .. "\n" ..
|
dofile(minetest.get_modpath("chest").."/detached.lua")
|
||||||
"32 inventory slots",
|
|
||||||
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 = "facedir",
|
|
||||||
groups = {dig_immediate=2,choppy=3},
|
|
||||||
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")
|
|
||||||
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)
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "Allow put: " .. stack:to_string())
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "Allow take: " .. stack:to_string())
|
|
||||||
return stack:get_count()
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "On put: " .. stack:to_string())
|
|
||||||
end,
|
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
minetest.chat_send_player(player:get_player_name(), "On take: " .. stack:to_string())
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
name = chest
|
name = chest
|
||||||
description = A simple chest to store items
|
description = A simple chest to store items. Also adds a detached inventory test
|
||||||
|
BIN
games/devtest/mods/chest/textures/chest_detached_chest.png
Normal file
BIN
games/devtest/mods/chest/textures/chest_detached_chest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 240 B |
@ -1,24 +1,3 @@
|
|||||||
minetest.register_chatcommand("test_inv", {
|
|
||||||
params = "",
|
|
||||||
description = "Test: Modify player's inventory formspec",
|
|
||||||
func = function(name, param)
|
|
||||||
local player = minetest.get_player_by_name(name)
|
|
||||||
if not player then
|
|
||||||
return false, "No player."
|
|
||||||
end
|
|
||||||
player:set_inventory_formspec(
|
|
||||||
"size[13,7.5]"..
|
|
||||||
"image[6,0.6;1,2;player.png]"..
|
|
||||||
"list[current_player;main;5,3.5;8,4;]"..
|
|
||||||
"list[current_player;craft;8,0;3,3;]"..
|
|
||||||
"list[current_player;craftpreview;12,1;1,1;]"..
|
|
||||||
"list[detached:test_inventory;main;0,0;4,6;0]"..
|
|
||||||
"button[0.5,7;2,1;button1;Button 1]"..
|
|
||||||
"button_exit[2.5,7;2,1;button2;Exit Button]")
|
|
||||||
return true, "Done."
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_chatcommand("test_bulk_set_node", {
|
minetest.register_chatcommand("test_bulk_set_node", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Test: Bulk-set 9×9×9 stone nodes",
|
description = "Test: Bulk-set 9×9×9 stone nodes",
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
-- Create a detached inventory
|
|
||||||
local inv = minetest.create_detached_inventory("test_inventory", {
|
|
||||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
experimental.print_to_everything("allow move asked")
|
|
||||||
return count -- Allow all
|
|
||||||
end,
|
|
||||||
allow_put = function(inv, listname, index, stack, player)
|
|
||||||
experimental.print_to_everything("allow put asked")
|
|
||||||
return 1 -- Allow only 1
|
|
||||||
end,
|
|
||||||
allow_take = function(inv, listname, index, stack, player)
|
|
||||||
experimental.print_to_everything("allow take asked")
|
|
||||||
return 4 -- Allow 4 at max
|
|
||||||
end,
|
|
||||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
||||||
experimental.print_to_everything(player:get_player_name().." moved items")
|
|
||||||
end,
|
|
||||||
on_put = function(inv, listname, index, stack, player)
|
|
||||||
experimental.print_to_everything(player:get_player_name().." put items")
|
|
||||||
end,
|
|
||||||
on_take = function(inv, listname, index, stack, player)
|
|
||||||
experimental.print_to_everything(player:get_player_name().." took items")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
inv:set_size("main", 4*6)
|
|
||||||
inv:add_item("main", "experimental:callback_node")
|
|
||||||
inv:add_item("main", "experimental:particle_spawner")
|
|
||||||
|
|
||||||
|
|
@ -2,14 +2,5 @@
|
|||||||
-- Experimental things
|
-- Experimental things
|
||||||
--
|
--
|
||||||
|
|
||||||
experimental = {}
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("experimental").."/detached.lua")
|
|
||||||
dofile(minetest.get_modpath("experimental").."/commands.lua")
|
dofile(minetest.get_modpath("experimental").."/commands.lua")
|
||||||
|
|
||||||
function experimental.print_to_everything(msg)
|
|
||||||
minetest.log("action", msg)
|
|
||||||
minetest.chat_send_all(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ minetest.register_tool("testtools:privatizer", {
|
|||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
if node.name == "chest:chest" then
|
if minetest.get_item_group(node.name, "meta_is_privatizable") == 1 then
|
||||||
local p = pointed_thing.under
|
local p = pointed_thing.under
|
||||||
minetest.log("action", "[testtools] Privatizer used at "..minetest.pos_to_string(p))
|
minetest.log("action", "[testtools] Privatizer used at "..minetest.pos_to_string(p))
|
||||||
minetest.get_meta(p):mark_as_private({"infotext", "formspec"})
|
minetest.get_meta(p):mark_as_private({"infotext", "formspec"})
|
||||||
|
Loading…
Reference in New Issue
Block a user