Initial Commit

master
Tre 2017-07-12 10:36:34 -05:00 committed by GitHub
parent 46baad832a
commit 2c0052ea80
9 changed files with 1702 additions and 0 deletions

198
api.lua Normal file
View File

@ -0,0 +1,198 @@
--[[
Infinite Chest for Minetest
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
Source Code: https://github.com/cornernote/minetest-infinite_chest
License: GPLv3
tweaked by me CalebDavis to fit my mod
API
]]--
sia_chest = {}
sia_chest.log = function(message)
minetest.log("action", message)
end
sia_chest.formspec = function(pos,page)
local formspec = "size[15,11]"
.."button[12,10;1,0.5;go;Go]"
if page=="main" then
local meta = minetest.env:get_meta(pos)
local pages = sia_chest.get_pages(meta)
local x,y = 0,0
local p
for i = #pages,1,-1 do
p = pages[i]
x = x+2
if x == 16 then
y = y+1
x = 2
end
formspec = formspec .."button["..(x-1.5)..","..(y+1)..";1.5,0.5;jump;"..p.."]"
end
if #pages == 0 then
formspec = formspec
.."label[4,3.5; --== SIA Chest ==--]"
.."label[4,4.5; Create one page per player reported in this catagory!]"
.."label[4,5.0; Simply enter the players name in the field]"
.."label[4,5.5; then click Go.]"
end
return formspec
.."field[10.5,10.1;2,1;page;;]"
.."label[0,0;SIA Chest]"
end
return formspec
.."field[10.5,10.1;2,1;page;;"..page.."]"
.."label[0,0;SIA Chest - page: " .. page .. "]"
.."button[13,10;2,0.5;back;Back]"
.."button[13,6.5;2,0.5;delete;Delete]"
.."list[current_name;"..page..";0,1;15,5;]"
.."list[current_player;main;0,7;8,4;]"
end
sia_chest.get_pages = function(meta)
local invs = meta:get_string("sia_chest_list")
local pages = {}
for p in string.gmatch(invs, "[^%s]+") do
table.insert(pages,p)
end
return pages
end
sia_chest.add_page = function(pos,page)
local meta = minetest.env:get_meta(pos)
local invs = meta:get_string("sia_chest_list")
local pages = {}
for p in string.gmatch(invs, "[^%s]+") do
if page ~= p then
table.insert(pages,p)
end
end
table.insert(pages,page)
invs = ""
for i,p in pairs(pages) do
invs = invs .." ".. p
end
meta:set_string("sia_chest_list",invs)
meta:get_inventory():set_size(page, 15*5)
end
sia_chest.remove_page = function(pos,page)
local meta = minetest.env:get_meta(pos)
local invs = meta:get_string("sia_chest_list")
local inv = meta:get_inventory()
if not inv:is_empty(page) then
return
end
local pages = {}
for p in string.gmatch(invs, "[^%s]+") do
if page ~= p then
table.insert(pages,p)
end
end
invs = ""
for i,p in pairs(pages) do
invs = invs .." ".. p
end
meta:set_string("sia_chest_list",invs)
return true
end
sia_chest.on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
local page
if fields.go ~= nil and fields.page ~= "" then
page = string.lower(string.gsub(fields.page, "%W", "_"))
end
if fields.jump ~= nil then
page = fields.jump
end
if page ~= nil then
sia_chest.add_page(pos,page)
meta:set_string("formspec", sia_chest.formspec(pos,page))
return
end
if fields.delete ~= nil then
if not sia_chest.remove_page(pos,fields.page) then
minetest.chat_send_player(sender:get_player_name(), "cannot delete \""..fields.page.."\" - page is not empty")
return
end
end
meta:set_string("formspec", sia_chest.formspec(pos,"main"))
end
sia_chest.on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", sia_chest.formspec(pos,"main"))
meta:set_string("infotext", "sia Chest")
end
sia_chest.can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local pages = sia_chest.get_pages(meta)
local inv = meta:get_inventory()
for i,page in pairs(pages) do
if not inv:is_empty(page) then
minetest.chat_send_player(player:get_player_name(), "cannot dig - page \""..page.."\" is not empty")
return false
end
end
return true
end
sia_chest.after_place_node = function(pos, placer)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "SIA Chest Top Secret")
end
sia_chest.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.env:get_meta(pos)
if not sia_chest.has_locked_chest_privilege(meta, player) then
sia_chest.log(player:get_player_name().." tried to access an sia chest at "..minetest.pos_to_string(pos))
return 0
end
return count
end
sia_chest.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not sia_chest.has_locked_chest_privilege(meta, player) then
sia_chest.log(player:get_player_name().." tried to access an sia chest belonging to at "..minetest.pos_to_string(pos))
return 0
end
return stack:get_count()
end
sia_chest.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not sia_chest.has_locked_chest_privilege(meta, player) then
sia_chest.log(player:get_player_name()..
" tried to access an sia chest at "..minetest.pos_to_string(pos))
return 0
end
return stack:get_count()
end
sia_chest.has_locked_chest_privilege = function(meta, player)
local name = player:get_player_name()
if minetest.check_player_privs(player, "SIA_member") then
return false
end
return true
end
sia_chest.on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
sia_chest.log(player:get_player_name().." moves stuff in sia chest at "..minetest.pos_to_string(pos))
end
sia_chest.on_metadata_inventory_put = function(pos, listname, index, stack, player)
sia_chest.log(player:get_player_name().." moves stuff to sia chest at "..minetest.pos_to_string(pos))
end
sia_chest.on_metadata_inventory_take = function(pos, listname, index, stack, player)
sia_chest.log(player:get_player_name().." takes stuff from sia chest at "..minetest.pos_to_string(pos))
end

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default

135
init.lua Normal file
View File

@ -0,0 +1,135 @@
local sia = {}
screwdriver = screwdriver or {}
local cbox = {
type = "fixed",
fixed = { -6/16, -8/16, -8/16, 6/16, 3/16, 8/16 }
}
dofile(minetest.get_modpath("sia").."/api.lua")
minetest.register_privilege("SIA_member", {
description = "Is a member of the Server Intelegence Agency",
give_to_singleplayer = false
})
minetest.register_alias("SIA_Mailbox","sia:mailbox")
minetest.register_node("sia:mailbox", {
paramtype = "light",
drawtype = "mesh",
mesh = "sia_mailbox.obj",
description = "SIA mailbox",
tiles = {
"sia_mailbox.png",
},
inventory_image = "sia_mailbox_inv.png",
selection_box = cbox,
collision_box = cbox,
paramtype2 = "facedir",
groups = {choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.rotate_simple,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
local owner = placer:get_player_name()
meta:set_string("infotext","SIA Mailbox place books inside to let the server admins know something about another player")
local inv = meta:get_inventory()
inv:set_size("main", 16*5)
inv:set_size("drop", 1)
end,
on_rightclick = function(pos, node, clicker, itemstack)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
if minetest.check_player_privs(player, "SIA_member") or
minetest.check_player_privs(player, "protection_bypass") and
clicker:get_player_control().aux1 then
minetest.show_formspec(
clicker:get_player_name(),
"default:chest_locked",
sia.get_formspec(pos))
else
minetest.show_formspec(
clicker:get_player_name(),
"default:chest_locked",
sia.get_insert_formspec(pos))
end
return itemstack
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local name = player and player:get_player_name()
local inv = meta:get_inventory()
return minetest.check_player_privs(player, "SIA_member") and inv:is_empty("main")
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local playerinv = player:get_inventory()
if listname == "drop" and inv:room_for_item("main", stack) then
inv:remove_item("drop", stack)
inv:add_item("main", stack)
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "main" then
return 0
end
if listname == "drop" then
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) and stack:get_name() == "default:book_written" then
return -1
else
return 0
end
end
end,
})
minetest.register_node("sia:chest", {
description = "SIA Chest",
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", "default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.rotate_simple,
on_construct = sia_chest.on_construct,
on_receive_fields = sia_chest.on_receive_fields,
can_dig = sia_chest.can_dig,
after_place_node = sia_chest.after_place_node,
allow_metadata_inventory_move = sia_chest.allow_metadata_inventory_move,
allow_metadata_inventory_put = sia_chest.allow_metadata_inventory_put,
allow_metadata_inventory_take = sia_chest.allow_metadata_inventory_take,
on_metadata_inventory_move = sia_chest.on_metadata_inventory_move,
on_metadata_inventory_put = sia_chest.on_metadata_inventory_put,
on_metadata_inventory_take = sia_chest.on_metadata_inventory_take,
})
function sia.get_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec =
"size[16,10]"..
"list[nodemeta:".. spos .. ";main;0,0;16,5;]"..
"list[current_player;main;4,6;8,4;]" ..
"listring[]"
return formspec
end
function sia.get_insert_formspec(pos)
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
local formspec =
"size[8,9]"..
"label[0,0; Set the topic of the book to the players name]"..
"label[1,0.5; that you are reporting and the date that you]"..
"label[1,1; are reporting it on.]"..
"label[0,2; Set the body of the book to the reason that you]"..
"label[1,2.5; are reporting him/her be it good or bad]"..
"list[nodemeta:".. spos .. ";drop;5,3;1,1;]"..
"label[0,3.25; Then put the book here]"..
"image[4,3;1,1;sia_arrow.png]"..
"list[current_player;main;0,5;8,4;]"..
"listring[]"
return formspec
end

Binary file not shown.

Binary file not shown.

1368
models/sia_mailbox.obj Normal file

File diff suppressed because it is too large Load Diff

BIN
textures/sia_arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

BIN
textures/sia_mailbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB