creative check

This commit is contained in:
BuckarooBanzay 2020-06-16 09:00:56 +02:00
parent 4d189f01e5
commit 6c4b5295f0
4 changed files with 30 additions and 15 deletions

@ -101,15 +101,19 @@ function digibuilder.digiline_effector(pos, _, channel, msg)
return
end
-- check if node is in inventory
local is_creative = meta:get_int("creative") == 1
local inv = meta:get_inventory()
if not inv:contains_item("main", msg.name) then
digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, {
pos = msg.pos,
error = true,
message = "Item not in inventory: " .. msg.name
})
return
if not is_creative then
-- check if node is in inventory
if not inv:contains_item("main", msg.name) then
digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, {
pos = msg.pos,
error = true,
message = "Item not in inventory: " .. msg.name
})
return
end
end
-- get and validate place node definition
@ -133,8 +137,10 @@ function digibuilder.digiline_effector(pos, _, channel, msg)
return
end
-- remove item
inv:remove_item("main", msg.name)
if not is_creative then
-- remove item
inv:remove_item("main", msg.name)
end
local param2 = tonumber(msg.param2)
local enable_param2 = place_node_def.paramtype2 == "facedir" and param2 and param2 > 0 and param2 <= 255

@ -1,3 +1,3 @@
name = digibuilder
depends = digilines
optional_depends = default
optional_depends = default, pipeworks

@ -45,7 +45,19 @@ minetest.register_node("digibuilder:digibuilder", {
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
-- set owner
local owner = placer:get_player_name() or ""
meta:set_string("owner", owner)
-- creative flag
local has_give = minetest.check_player_privs(owner, "give")
local has_creative = minetest.check_player_privs(owner, "creative")
if has_give or has_creative then
meta:set_int("creative", 1)
else
meta:set_int("creative", 0)
end
end,
on_construct = function(pos)

@ -52,10 +52,7 @@ For code examples for the `luacontroller` see the "examples" directory
# Open issues
* [ ] creative mode
* [ ] `after_place_node(pos, placer, itemstack, pointed_thing)` compat (digtron mod?)
further issues:
* [ ] Storage of read schematics/buildings