More armor stand fixes

This commit is contained in:
stujones11 2016-05-04 18:26:24 +01:00
parent d322a0f110
commit 32e87ee543

View File

@ -58,11 +58,14 @@ local function update_entity(pos)
if stack:get_count() == 1 then if stack:get_count() == 1 then
local item = stack:get_name() or "" local item = stack:get_name() or ""
local def = stack:get_definition() or {} local def = stack:get_definition() or {}
local groups = def.groups or {}
if groups["armor_"..element] then
local texture = def.texture or item:gsub("%:", "_") local texture = def.texture or item:gsub("%:", "_")
table.insert(textures, texture..".png") table.insert(textures, texture..".png")
end end
end end
end end
end
if #textures > 0 then if #textures > 0 then
texture = table.concat(textures, "^") texture = table.concat(textures, "^")
end end
@ -81,6 +84,20 @@ local function update_entity(pos)
end end
end end
local function has_locked_armor_stand_privilege(meta, player)
local name = ""
if player then
if minetest.check_player_privs(player, "protection_bypass") then
return true
end
name = player:get_player_name()
end
if name ~= meta:get_string("owner") then
return false
end
return true
end
minetest.register_node("3d_armor_stand:armor_stand", { minetest.register_node("3d_armor_stand:armor_stand", {
description = "Armor stand", description = "Armor stand",
drawtype = "mesh", drawtype = "mesh",
@ -148,26 +165,48 @@ minetest.register_node("3d_armor_stand:armor_stand", {
end, end,
}) })
local function has_locked_armor_stand_privilege(meta, player) minetest.register_node("3d_armor_stand:locked_armor_stand", {
local name = "" description = "Locked Armor stand",
if player then drawtype = "mesh",
if minetest.check_player_privs(player, "protection_bypass") then mesh = "3d_armor_stand.obj",
return true tiles = {"default_wood.png", "default_steel_block.png"},
paramtype = "light",
paramtype2 = "facedir",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5,-0.5,-0.5, 0.5,1.4,0.5}
},
groups = {choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", armor_stand_formspec)
meta:set_string("infotext", "Armor Stand")
meta:set_string("owner", "")
local inv = meta:get_inventory()
for _, element in pairs(elements) do
inv:set_size("armor_"..element, 1)
end end
name = player:get_player_name() end,
end can_dig = function(pos, player)
if name ~= meta:get_string("owner") then local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for _, element in pairs(elements) do
if not inv:is_empty("armor_"..element) then
return false return false
end end
end
return true return true
end end,
after_place_node = function(pos)
local node = {} minetest.add_entity(pos, "3d_armor_stand:armor_entity")
for k,v in pairs(minetest.registered_nodes["3d_armor_stand:armor_stand"]) do local meta = minetest.get_meta(pos)
node[k] = v meta:set_string("owner", placer:get_player_name() or "")
end meta:set_string("infotext", "Armor Stand (owned by " ..
node.description = "Locked " .. node.description meta:get_string("owner") .. ")")
node.allow_metadata_inventory_put = function(pos, listname, index, stack, player) end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if not has_locked_armor_stand_privilege(meta, player) then if not has_locked_armor_stand_privilege(meta, player) then
return 0 return 0
@ -178,32 +217,36 @@ node.allow_metadata_inventory_put = function(pos, listname, index, stack, player
return 1 return 1
end end
return 0 return 0
end end,
node.allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if not has_locked_armor_stand_privilege(meta, player) then if not has_locked_armor_stand_privilege(meta, player) then
return 0 return 0
end end
return stack:get_count() return stack:get_count()
end end,
node.on_construct = function(pos) allow_metadata_inventory_move = function(pos)
local meta = minetest.get_meta(pos) return 0
meta:set_string("formspec", armor_stand_formspec) end,
meta:set_string("infotext", "Armor Stand") on_metadata_inventory_put = function(pos)
meta:set_string("owner", "") update_entity(pos)
local inv = meta:get_inventory() end,
for _, element in pairs(elements) do on_metadata_inventory_take = function(pos)
inv:set_size("armor_"..element, 1) update_entity(pos)
end,
after_destruct = function(pos)
update_entity(pos)
end,
on_blast = function(pos)
local object = get_stand_object(pos)
if object then
object:remove()
end end
end minetest.after(1, function(pos)
node.after_place_node = function(pos, placer) update_entity(pos)
minetest.add_entity(pos, "3d_armor_stand:armor_entity") end, pos)
local meta = minetest.get_meta(pos) end,
meta:set_string("owner", placer:get_player_name() or "") })
meta:set_string("infotext", "Armor Stand (owned by " ..
meta:get_string("owner") .. ")")
end
minetest.register_node("3d_armor_stand:locked_armor_stand", node)
minetest.register_entity("3d_armor_stand:armor_entity", { minetest.register_entity("3d_armor_stand:armor_entity", {
physical = true, physical = true,