diff options
author | FaceDeer <derksenmobile@gmail.com> | 2017-01-02 18:50:03 -0700 |
---|---|---|
committer | FaceDeer <derksenmobile@gmail.com> | 2017-01-02 18:50:03 -0700 |
commit | 2b5dc41d50965a2190ae7c16cc18129061fa74ab (patch) | |
tree | 50ccc92fb37e0779d63b46880216ed3a5e1ab66d | |
parent | ec1ee19893c3e645b34607e9df069f164be7f31c (diff) |
Adding item display entities to the builder heads
-rw-r--r-- | entities.lua | 37 | ||||
-rw-r--r-- | node_builders.lua | 8 | ||||
-rw-r--r-- | util.lua | 28 |
3 files changed, 71 insertions, 2 deletions
diff --git a/entities.lua b/entities.lua index b3d12cb..deb1ec6 100644 --- a/entities.lua +++ b/entities.lua @@ -49,3 +49,40 @@ minetest.register_entity("digtron:marker_vertical", { self.object:remove() 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, +}) diff --git a/node_builders.lua b/node_builders.lua index 04431fc..7a8cd00 100644 --- a/node_builders.lua +++ b/node_builders.lua @@ -123,7 +123,13 @@ minetest.register_node("digtron:builder", { if build_facing and build_facing >= 0 and build_facing < 24 then meta:set_int("build_facing", math.floor(build_facing)) end - end + end + + digtron.update_builder_item(pos) + end, + + on_destruct = function(pos) + digtron.remove_builder_item(pos) 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. @@ -104,7 +104,11 @@ digtron.move_node = function(pos, newpos) newmeta:set_int("build_facing", oldmeta:get_int("build_facing")) newmeta:set_float("fuel_burning", oldmeta:get_float("fuel_burning")) 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 minetest.remove_node(pos) end @@ -365,4 +369,26 @@ digtron.burn = function(fuelstore_positions, target, test) end end 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
\ No newline at end of file |