2017-03-31 23:09:32 +02:00
|
|
|
local S = function(s) return s end
|
|
|
|
if minetest.global_exists("intllib") then
|
|
|
|
S = intllib.Getter()
|
|
|
|
end
|
2016-04-03 21:15:40 +02:00
|
|
|
local armor_stand_formspec = "size[8,7]" ..
|
|
|
|
default.gui_bg ..
|
|
|
|
default.gui_bg_img ..
|
|
|
|
default.gui_slots ..
|
|
|
|
default.get_hotbar_bg(0,3) ..
|
|
|
|
"list[current_name;armor_head;3,0.5;1,1;]" ..
|
|
|
|
"list[current_name;armor_torso;4,0.5;1,1;]" ..
|
|
|
|
"list[current_name;armor_legs;3,1.5;1,1;]" ..
|
|
|
|
"list[current_name;armor_feet;4,1.5;1,1;]" ..
|
|
|
|
"image[3,0.5;1,1;3d_armor_stand_head.png]" ..
|
|
|
|
"image[4,0.5;1,1;3d_armor_stand_torso.png]" ..
|
|
|
|
"image[3,1.5;1,1;3d_armor_stand_legs.png]" ..
|
|
|
|
"image[4,1.5;1,1;3d_armor_stand_feet.png]" ..
|
|
|
|
"list[current_player;main;0,3;8,1;]" ..
|
|
|
|
"list[current_player;main;0,4.25;8,3;8]"
|
|
|
|
|
|
|
|
local elements = {"head", "torso", "legs", "feet"}
|
|
|
|
|
2017-03-08 20:36:30 +01:00
|
|
|
local function drop_armor(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for _, element in pairs(elements) do
|
|
|
|
local stack = inv:get_stack("armor_"..element, 1)
|
|
|
|
if stack and stack:get_count() > 0 then
|
|
|
|
armor.drop_armor(pos, stack)
|
|
|
|
inv:set_stack("armor_"..element, 1, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-22 19:53:25 +02:00
|
|
|
local function get_stand_object(pos)
|
2016-04-03 21:15:40 +02:00
|
|
|
local object = nil
|
2016-04-22 19:53:25 +02:00
|
|
|
local objects = minetest.get_objects_inside_radius(pos, 0.5) or {}
|
2016-04-03 21:15:40 +02:00
|
|
|
for _, obj in pairs(objects) do
|
2016-04-22 19:53:25 +02:00
|
|
|
local ent = obj:get_luaentity()
|
|
|
|
if ent then
|
|
|
|
if ent.name == "3d_armor_stand:armor_entity" then
|
|
|
|
-- Remove duplicates
|
|
|
|
if object then
|
|
|
|
obj:remove()
|
|
|
|
else
|
|
|
|
object = obj
|
2016-04-03 21:15:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-04-22 19:53:25 +02:00
|
|
|
return object
|
|
|
|
end
|
|
|
|
|
|
|
|
local function update_entity(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local object = get_stand_object(pos)
|
2016-04-03 21:15:40 +02:00
|
|
|
if object then
|
2016-04-20 19:54:15 +02:00
|
|
|
if not string.find(node.name, "3d_armor_stand:") then
|
2016-04-03 21:15:40 +02:00
|
|
|
object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
object = minetest.add_entity(pos, "3d_armor_stand:armor_entity")
|
|
|
|
end
|
|
|
|
if object then
|
|
|
|
local texture = "3d_armor_trans.png"
|
|
|
|
local textures = {}
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local yaw = 0
|
|
|
|
if inv then
|
|
|
|
for _, element in pairs(elements) do
|
|
|
|
local stack = inv:get_stack("armor_"..element, 1)
|
|
|
|
if stack:get_count() == 1 then
|
|
|
|
local item = stack:get_name() or ""
|
|
|
|
local def = stack:get_definition() or {}
|
2016-05-04 19:26:24 +02:00
|
|
|
local groups = def.groups or {}
|
|
|
|
if groups["armor_"..element] then
|
|
|
|
local texture = def.texture or item:gsub("%:", "_")
|
|
|
|
table.insert(textures, texture..".png")
|
|
|
|
end
|
2016-04-03 21:15:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #textures > 0 then
|
|
|
|
texture = table.concat(textures, "^")
|
|
|
|
end
|
|
|
|
if node.param2 then
|
|
|
|
local rot = node.param2 % 4
|
|
|
|
if rot == 1 then
|
|
|
|
yaw = 3 * math.pi / 2
|
|
|
|
elseif rot == 2 then
|
|
|
|
yaw = math.pi
|
|
|
|
elseif rot == 3 then
|
|
|
|
yaw = math.pi / 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
object:setyaw(yaw)
|
|
|
|
object:set_properties({textures={texture}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-04 19:26:24 +02:00
|
|
|
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
|
|
|
|
|
2017-02-08 21:57:42 +01:00
|
|
|
local function add_hidden_node(pos, player)
|
2017-02-08 20:32:42 +01:00
|
|
|
local p = {x=pos.x, y=pos.y + 1, z=pos.z}
|
2017-02-08 21:57:42 +01:00
|
|
|
local name = player:get_player_name()
|
2017-02-08 20:32:42 +01:00
|
|
|
local node = minetest.get_node(p)
|
2017-02-08 21:57:42 +01:00
|
|
|
if node.name == "air" and not minetest.is_protected(pos, name) then
|
2017-02-08 20:32:42 +01:00
|
|
|
minetest.set_node(p, {name="3d_armor_stand:top"})
|
2017-02-08 19:26:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function remove_hidden_node(pos)
|
2017-02-08 20:32:42 +01:00
|
|
|
local p = {x=pos.x, y=pos.y + 1, z=pos.z}
|
|
|
|
local node = minetest.get_node(p)
|
2017-02-08 19:26:15 +01:00
|
|
|
if node.name == "3d_armor_stand:top" then
|
2017-02-08 20:32:42 +01:00
|
|
|
minetest.remove_node(p)
|
2017-02-08 19:26:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("3d_armor_stand:top", {
|
2017-03-31 23:09:32 +02:00
|
|
|
description = S("Armor stand top"),
|
2017-02-08 19:26:15 +01:00
|
|
|
paramtype = "light",
|
|
|
|
drawtype = "plantlike",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = true,
|
|
|
|
pointable = false,
|
|
|
|
diggable = false,
|
|
|
|
buildable_to = false,
|
|
|
|
drop = "",
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
|
|
|
on_blast = function() end,
|
|
|
|
tiles = {"3d_armor_trans.png"},
|
|
|
|
})
|
|
|
|
|
2016-04-03 21:15:40 +02:00
|
|
|
minetest.register_node("3d_armor_stand:armor_stand", {
|
2017-03-31 23:09:32 +02:00
|
|
|
description = S("Armor stand"),
|
2016-04-03 21:15:40 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "3d_armor_stand.obj",
|
2017-01-22 17:31:39 +01:00
|
|
|
tiles = {"3d_armor_stand.png"},
|
2016-04-03 21:15:40 +02:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
walkable = false,
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2017-02-15 19:25:49 +01:00
|
|
|
fixed = {
|
|
|
|
{-0.25, -0.4375, -0.25, 0.25, 1.4, 0.25},
|
|
|
|
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
|
|
|
|
},
|
2016-04-03 21:15:40 +02:00
|
|
|
},
|
|
|
|
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")
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for _, element in pairs(elements) do
|
|
|
|
inv:set_size("armor_"..element, 1)
|
|
|
|
end
|
|
|
|
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,
|
2017-02-08 21:57:42 +01:00
|
|
|
after_place_node = function(pos, placer)
|
2016-04-03 21:15:40 +02:00
|
|
|
minetest.add_entity(pos, "3d_armor_stand:armor_entity")
|
2017-02-08 21:57:42 +01:00
|
|
|
add_hidden_node(pos, placer)
|
2016-04-03 21:15:40 +02:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack)
|
|
|
|
local def = stack:get_definition() or {}
|
|
|
|
local groups = def.groups or {}
|
|
|
|
if groups[listname] then
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_move = function(pos)
|
|
|
|
return 0
|
|
|
|
end,
|
2016-04-09 02:19:32 +02:00
|
|
|
on_metadata_inventory_put = function(pos)
|
2016-04-03 21:15:40 +02:00
|
|
|
update_entity(pos)
|
|
|
|
end,
|
2016-04-09 02:19:32 +02:00
|
|
|
on_metadata_inventory_take = function(pos)
|
2016-04-03 21:15:40 +02:00
|
|
|
update_entity(pos)
|
|
|
|
end,
|
|
|
|
after_destruct = function(pos)
|
|
|
|
update_entity(pos)
|
2017-02-08 19:26:15 +01:00
|
|
|
remove_hidden_node(pos)
|
2016-04-03 21:15:40 +02:00
|
|
|
end,
|
2016-04-22 19:53:25 +02:00
|
|
|
on_blast = function(pos)
|
2017-03-08 20:36:30 +01:00
|
|
|
drop_armor(pos)
|
|
|
|
armor.drop_armor(pos, "3d_armor_stand:armor_stand")
|
|
|
|
minetest.remove_node(pos)
|
2016-04-22 19:53:25 +02:00
|
|
|
end,
|
2016-04-03 21:15:40 +02:00
|
|
|
})
|
|
|
|
|
2016-05-04 19:26:24 +02:00
|
|
|
minetest.register_node("3d_armor_stand:locked_armor_stand", {
|
2017-03-31 23:09:32 +02:00
|
|
|
description = S("Locked Armor stand"),
|
2016-05-04 19:26:24 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "3d_armor_stand.obj",
|
2017-01-22 17:31:39 +01:00
|
|
|
tiles = {"3d_armor_stand_locked.png"},
|
2016-05-04 19:26:24 +02:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
walkable = false,
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2017-02-15 19:25:49 +01:00
|
|
|
fixed = {
|
|
|
|
{-0.25, -0.4375, -0.25, 0.25, 1.4, 0.25},
|
|
|
|
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
|
|
|
|
},
|
2016-05-04 19:26:24 +02:00
|
|
|
},
|
|
|
|
groups = {choppy=2, oddly_breakable_by_hand=2},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
on_construct = function(pos)
|
2016-04-10 20:11:53 +02:00
|
|
|
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
|
2016-05-04 19:26:24 +02:00
|
|
|
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,
|
2016-05-11 23:19:13 +02:00
|
|
|
after_place_node = function(pos, placer)
|
2016-05-04 19:26:24 +02:00
|
|
|
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") .. ")")
|
2017-02-08 21:57:42 +01:00
|
|
|
add_hidden_node(pos, placer)
|
2016-05-04 19:26:24 +02:00
|
|
|
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)
|
2017-02-08 19:26:15 +01:00
|
|
|
remove_hidden_node(pos)
|
2016-05-04 19:26:24 +02:00
|
|
|
end,
|
|
|
|
on_blast = function(pos)
|
2017-03-08 20:36:30 +01:00
|
|
|
-- Not affected by TNT
|
2016-05-04 19:26:24 +02:00
|
|
|
end,
|
|
|
|
})
|
2016-04-10 20:11:53 +02:00
|
|
|
|
2016-04-03 21:15:40 +02:00
|
|
|
minetest.register_entity("3d_armor_stand:armor_entity", {
|
|
|
|
physical = true,
|
|
|
|
visual = "mesh",
|
|
|
|
mesh = "3d_armor_entity.obj",
|
|
|
|
visual_size = {x=1, y=1},
|
2017-02-15 19:25:49 +01:00
|
|
|
collisionbox = {0,0,0,0,0,0},
|
2016-04-03 21:15:40 +02:00
|
|
|
textures = {"3d_armor_trans.png"},
|
2016-04-27 19:48:06 +02:00
|
|
|
pos = nil,
|
|
|
|
timer = 0,
|
2016-04-03 21:15:40 +02:00
|
|
|
on_activate = function(self)
|
2016-04-22 19:53:25 +02:00
|
|
|
local pos = self.object:getpos()
|
2016-04-27 19:48:06 +02:00
|
|
|
if pos then
|
|
|
|
self.pos = vector.round(pos)
|
|
|
|
update_entity(pos)
|
|
|
|
end
|
|
|
|
end,
|
2017-03-08 20:36:30 +01:00
|
|
|
on_blast = function(self, damage)
|
|
|
|
local drops = {}
|
|
|
|
local node = minetest.get_node(self.pos)
|
|
|
|
if node.name == "3d_armor_stand:armor_stand" then
|
|
|
|
drop_armor(self.pos)
|
2016-04-27 19:48:06 +02:00
|
|
|
self.object:remove()
|
|
|
|
end
|
2017-03-08 20:36:30 +01:00
|
|
|
return false, false, drops
|
2016-04-20 19:54:15 +02:00
|
|
|
end,
|
2016-04-03 21:15:40 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "3d_armor_stand:armor_stand",
|
|
|
|
recipe = {
|
|
|
|
{"", "default:fence_wood", ""},
|
|
|
|
{"", "default:fence_wood", ""},
|
|
|
|
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-04-10 20:11:53 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "3d_armor_stand:locked_armor_stand",
|
|
|
|
recipe = {
|
|
|
|
{"3d_armor_stand:armor_stand", "default:steel_ingot"},
|
|
|
|
}
|
|
|
|
})
|
2016-04-20 19:54:15 +02:00
|
|
|
|