-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
65 lines (59 loc) · 2.13 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-- Load config parameters
local modpath = minetest.get_modpath(minetest.get_current_modname())
minetest.debug("PrisonPearl initialised.")
minetest.register_craft({
output = "prisonpearl:pearl",
recipe = {
{"", "default:cobble", ""},
{"", "", ""},
{"", "default:cobble", ""},
}
})
local function pearl_on_use(itemstack, user)
-- Let's make sure this pearl is used
local meta = itemstack:get_meta()
if meta:contains("prisoner") then
local name = meta:get_string("prisoner")
if pp.manager:is_imprisoned(name) and pp.manager:free_pearl(name) then
minetest.chat_send_player(user:get_player_name(), "Player " .. name .. " has been freed.")
local meta = itemstack:get_meta()
meta:set_string("prisoner", "")
meta:set_string("description", "Prison Pearl")
return itemstack
else
minetest.chat_send_player(user:get_player_name(), "Player is not imprisoned.")
end
end
end
minetest.register_craftitem("prisonpearl:pearl", {
description = "Prison Pearl",
inventory_image = "default_stick.png",
groups = {pearl = 1},
stack_max = 1,
on_secondary_use = pearl_on_use,
on_drop = function(itemstack, dropper, pos)
local meta = itemstack:get_meta()
if meta:contains("prisoner") then
local name = meta:get_string("prisoner")
pearl = pp.manager:get_pearl_by_name(name)
if pearl == nil then
minetest.debug("Faulty pearl detected with name: " .. name .. " deleting.")
local meta = itemstack:get_meta()
meta:set_string("prisoner", "")
meta:set_string("description", "Prison Pearl")
else
local location = {type="ground", pos=pos}
pp.manager:update_pearl_location(pearl, location)
end
end
minetest.item_drop(itemstack, dropper, pos)
return itemstack
end,
})
-- Lets handle all situations when a prisonshard is moved
pp = {}
pp.manager = {}
pp.tracker = {}
dofile(modpath .. "/manager.lua")
dofile(modpath .. "/tracking.lua")
return pp