mirror of
https://github.com/minetest-mods/3d_armor.git
synced 2024-12-28 02:57:30 +01:00
More armor stand fixes
This commit is contained in:
parent
d322a0f110
commit
32e87ee543
@ -58,8 +58,11 @@ local function update_entity(pos)
|
||||
if stack:get_count() == 1 then
|
||||
local item = stack:get_name() or ""
|
||||
local def = stack:get_definition() or {}
|
||||
local texture = def.texture or item:gsub("%:", "_")
|
||||
table.insert(textures, texture..".png")
|
||||
local groups = def.groups or {}
|
||||
if groups["armor_"..element] then
|
||||
local texture = def.texture or item:gsub("%:", "_")
|
||||
table.insert(textures, texture..".png")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -81,6 +84,20 @@ local function update_entity(pos)
|
||||
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", {
|
||||
description = "Armor stand",
|
||||
drawtype = "mesh",
|
||||
@ -148,45 +165,21 @@ minetest.register_node("3d_armor_stand:armor_stand", {
|
||||
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
|
||||
|
||||
local node = {}
|
||||
for k,v in pairs(minetest.registered_nodes["3d_armor_stand:armor_stand"]) do
|
||||
node[k] = v
|
||||
end
|
||||
node.description = "Locked " .. node.description
|
||||
node.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not has_locked_armor_stand_privilege(meta, player) then
|
||||
return 0
|
||||
end
|
||||
local def = stack:get_definition() or {}
|
||||
local groups = def.groups or {}
|
||||
if groups[listname] then
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
end
|
||||
node.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not has_locked_armor_stand_privilege(meta, player) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end
|
||||
node.on_construct = function(pos)
|
||||
minetest.register_node("3d_armor_stand:locked_armor_stand", {
|
||||
description = "Locked Armor stand",
|
||||
drawtype = "mesh",
|
||||
mesh = "3d_armor_stand.obj",
|
||||
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")
|
||||
@ -195,15 +188,65 @@ node.on_construct = function(pos)
|
||||
for _, element in pairs(elements) do
|
||||
inv:set_size("armor_"..element, 1)
|
||||
end
|
||||
end
|
||||
node.after_place_node = function(pos, placer)
|
||||
minetest.add_entity(pos, "3d_armor_stand:armor_entity")
|
||||
local meta = minetest.get_meta(pos)
|
||||
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)
|
||||
end,
|
||||
can_dig = function(pos, player)
|
||||
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
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
after_place_node = function(pos)
|
||||
minetest.add_entity(pos, "3d_armor_stand:armor_entity")
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
meta:set_string("infotext", "Armor Stand (owned by " ..
|
||||
meta:get_string("owner") .. ")")
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not has_locked_armor_stand_privilege(meta, player) then
|
||||
return 0
|
||||
end
|
||||
local def = stack:get_definition() or {}
|
||||
local groups = def.groups or {}
|
||||
if groups[listname] then
|
||||
return 1
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if not has_locked_armor_stand_privilege(meta, player) then
|
||||
return 0
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos)
|
||||
return 0
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos)
|
||||
update_entity(pos)
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos)
|
||||
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
|
||||
minetest.after(1, function(pos)
|
||||
update_entity(pos)
|
||||
end, pos)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity("3d_armor_stand:armor_entity", {
|
||||
physical = true,
|
||||
|
Loading…
Reference in New Issue
Block a user