Adding item display entities to the builder heads

This commit is contained in:
FaceDeer 2017-01-02 18:50:03 -07:00
parent ec1ee19893
commit 2b5dc41d50
3 changed files with 71 additions and 2 deletions

@ -49,3 +49,40 @@ minetest.register_entity("digtron:marker_vertical", {
self.object:remove() self.object:remove()
end, end,
}) })
minetest.register_entity("digtron:builder_item", {
initial_properties = {
hp_max = 1,
is_visible = true,
visual = "wielditem",
visual_size = {x=0.25, y=0.25},
collisionbox = {0,0,0,0,0,0},
physical = false,
textures = {""},
automatic_rotate = math.pi * 0.25,
},
on_activate = function(self, staticdata)
local props = self.object:get_properties()
if staticdata ~= nil and staticdata ~= "" then
props.textures = {staticdata}
self.object:set_properties(props)
elseif digtron.create_builder_item ~= nil then
minetest.debug("creating builder item", digtron.create_builder_item)
props.textures = {digtron.create_builder_item}
self.object:set_properties(props)
digtron.create_builder_item = nil
else
self.object:remove()
end
end,
get_staticdata = function(self)
local props = self.object:get_properties()
if props ~= nil and props.textures ~= nil and props.textures[1] ~= nil then
return props.textures[1]
end
return ""
end,
})

@ -124,6 +124,12 @@ minetest.register_node("digtron:builder", {
meta:set_int("build_facing", math.floor(build_facing)) meta:set_int("build_facing", math.floor(build_facing))
end end
end end
digtron.update_builder_item(pos)
end,
on_destruct = function(pos)
digtron.remove_builder_item(pos)
end, end,
-- "builder at pos, imagine that you're in test_pos. If you're willing and able to build from there, take the item you need from inventory. -- "builder at pos, imagine that you're in test_pos. If you're willing and able to build from there, take the item you need from inventory.

@ -105,6 +105,10 @@ digtron.move_node = function(pos, newpos)
newmeta:set_float("fuel_burning", oldmeta:get_float("fuel_burning")) newmeta:set_float("fuel_burning", oldmeta:get_float("fuel_burning"))
newmeta:set_string("infotext", oldmeta:get_string("infotext")) newmeta:set_string("infotext", oldmeta:get_string("infotext"))
if minetest.get_item_group(node.name, "digtron") == 4 then
digtron.update_builder_item(newpos)
end
-- remove node from old position -- remove node from old position
minetest.remove_node(pos) minetest.remove_node(pos)
end end
@ -366,3 +370,25 @@ digtron.burn = function(fuelstore_positions, target, test)
end end
return current_burned return current_burned
end end
digtron.remove_builder_item = function(pos)
minetest.debug("removing builder item")
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
if objects ~= nil then
for _, obj in ipairs(objects) do
if obj and obj:get_luaentity() and obj:get_luaentity().name == "digtron:builder_item" then
obj:remove()
end
end
end
end
digtron.update_builder_item = function(pos)
digtron.remove_builder_item(pos)
local inv = minetest.get_inventory({type="node", pos=pos})
local item_stack = inv:get_stack("main", 1)
if not item_stack:is_empty() then
digtron.create_builder_item = item_stack:get_name()
minetest.add_entity(pos,"digtron:builder_item")
end
end