forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevTest: Move detached inv tests to chest mod
- Loading branch information
Showing
9 changed files
with
107 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,2 @@ | ||
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}, | ||
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, | ||
}) | ||
dofile(minetest.get_modpath("chest").."/chest.lua") | ||
dofile(minetest.get_modpath("chest").."/detached.lua") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
name = chest | ||
description = A simple chest to store items | ||
description = A simple chest to store items. Also adds a detached inventory test |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters