mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 20:32:22 +01:00
Adding item display entities to the builder heads
This commit is contained in:
parent
ec1ee19893
commit
2b5dc41d50
37
entities.lua
37
entities.lua
@ -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,
|
||||||
|
})
|
||||||
|
@ -123,7 +123,13 @@ minetest.register_node("digtron:builder", {
|
|||||||
if build_facing and build_facing >= 0 and build_facing < 24 then
|
if build_facing and build_facing >= 0 and build_facing < 24 then
|
||||||
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.
|
||||||
|
28
util.lua
28
util.lua
@ -104,7 +104,11 @@ digtron.move_node = function(pos, newpos)
|
|||||||
newmeta:set_int("build_facing", oldmeta:get_int("build_facing"))
|
newmeta:set_int("build_facing", oldmeta:get_int("build_facing"))
|
||||||
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
|
||||||
@ -365,4 +369,26 @@ digtron.burn = function(fuelstore_positions, target, test)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
return current_burned
|
return current_burned
|
||||||
|
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
|
end
|
Loading…
Reference in New Issue
Block a user