mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 04:21:07 +01:00
Added Formspec to Bookshelf
This commit is contained in:
parent
6b7b2c74ed
commit
8bcf80422d
2 changed files with 99 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
|||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
local F = minetest.formspec_escape
|
||||
local C = minetest.colorize
|
||||
|
||||
local max_text_length = 4500 -- TODO: Increase to 12800 when scroll bar was added to written book
|
||||
local max_title_length = 64
|
||||
|
@ -331,6 +333,75 @@ if minetest.get_modpath("mcl_sounds") then
|
|||
wood_sound = mcl_sounds.node_sound_wood_defaults()
|
||||
end
|
||||
|
||||
-- Bookshelf GUI
|
||||
local drop_content = mcl_util.drop_items_from_meta_container("main")
|
||||
|
||||
local function on_blast(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
drop_content(pos, node)
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
|
||||
-- Simple protection checking functions
|
||||
local function protection_check_move(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local name = player:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return 0
|
||||
else
|
||||
return count
|
||||
end
|
||||
end
|
||||
|
||||
local function protection_check_put_take(pos, listname, index, stack, player)
|
||||
local name = player:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return 0
|
||||
elseif minetest.get_item_group(stack:get_name(), "book") ~= 0 or stack:get_name() == "mcl_enchanting:book_enchanted" then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
local function bookshelf_gui(pos, node, clicker)
|
||||
local name = minetest.get_meta(pos):get_string("name")
|
||||
|
||||
if name == "" then
|
||||
name = S("Bookshelf")
|
||||
end
|
||||
|
||||
local playername = clicker:get_player_name()
|
||||
|
||||
minetest.show_formspec(playername,
|
||||
"mcl_books:bookshelf_"..pos.x.."_"..pos.y.."_"..pos.z,
|
||||
table.concat({
|
||||
"size[9,8.75]",
|
||||
"label[0,0;"..F(C("#313131", name)).."]",
|
||||
"list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main;0,0.5;9,3;]",
|
||||
mcl_formspec.get_itemslot_bg(0, 0.5, 9, 3),
|
||||
"label[0,4.0;"..F(C("#313131", S("Inventory"))).."]",
|
||||
"list[current_player;main;0,4.5;9,3;9]",
|
||||
mcl_formspec.get_itemslot_bg(0, 4.5, 9, 3),
|
||||
"list[current_player;main;0,7.74;9,1;]",
|
||||
mcl_formspec.get_itemslot_bg(0, 7.74, 9, 1),
|
||||
"listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";main]",
|
||||
"listring[current_player;main]",
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
local function close_forms(pos)
|
||||
local players = minetest.get_connected_players()
|
||||
local formname = "mcl_books:bookshelf_"..pos.x.."_"..pos.y.."_"..pos.z
|
||||
for p = 1, #players do
|
||||
if vector.distance(players[p]:get_pos(), pos) <= 30 then
|
||||
minetest.close_formspec(players[p]:get_player_name(), formname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Bookshelf
|
||||
minetest.register_node("mcl_books:bookshelf", {
|
||||
description = S("Bookshelf"),
|
||||
|
@ -347,6 +418,33 @@ minetest.register_node("mcl_books:bookshelf", {
|
|||
_mcl_blast_resistance = 1.5,
|
||||
_mcl_hardness = 1.5,
|
||||
_mcl_silk_touch_drop = true,
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 9*3)
|
||||
end,
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
minetest.get_meta(pos):set_string("name", itemstack:get_meta():get_string("name"))
|
||||
end,
|
||||
allow_metadata_inventory_move = protection_check_move,
|
||||
allow_metadata_inventory_take = protection_check_put_take,
|
||||
allow_metadata_inventory_put = protection_check_put_take,
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff in bookshelf at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" moves stuff to bookshelf at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
minetest.log("action", player:get_player_name()..
|
||||
" takes stuff from bookshelf at "..minetest.pos_to_string(pos))
|
||||
end,
|
||||
after_dig_node = drop_content,
|
||||
on_blast = on_blast,
|
||||
on_rightclick = bookshelf_gui,
|
||||
on_destruct = close_gui,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
name = mcl_books
|
||||
author = celeron55
|
||||
description = Books mod for MCL2
|
||||
depends = mcl_util, mcl_formspec
|
||||
optional_depends = mcl_init, mcl_core, mcl_sounds, mcl_mobitems, mcl_dye, mcl_colors
|
||||
|
|
Loading…
Reference in a new issue