Merge pull request #161 from chu-hai/dummy_item

Improve dummy_item
This commit is contained in:
tacigar 2017-01-10 20:00:27 +09:00 committed by GitHub
commit 9f1aabfc3a

View File

@ -267,24 +267,14 @@ do
wield_image = "maidroid_dummy_empty_craftitem.png", wield_image = "maidroid_dummy_empty_craftitem.png",
}) })
local remove_flag_word = "remove"
local function get_staticdata(self)
return remove_flag_word
end
local function on_activate(self, staticdata) local function on_activate(self, staticdata)
if staticdata == remove_flag_word then self.object:set_properties{textures={"maidroid:dummy_empty_craftitem"}}
self.object:remove()
end
end end
local function on_step(self, dtime) local function on_step(self, dtime)
local all_objects = minetest.get_objects_inside_radius(self.object:getpos(), 0.1) if self.maidroid_object then
for _, obj in ipairs(all_objects) do local luaentity = self.maidroid_object:get_luaentity()
local luaentity = obj:get_luaentity() if luaentity then
if maidroid.is_maidroid(luaentity.name) then
local stack = luaentity:get_wield_item_stack() local stack = luaentity:get_wield_item_stack()
if stack:get_name() ~= self.itemname then if stack:get_name() ~= self.itemname then
@ -299,6 +289,7 @@ do
return return
end end
end end
-- if cannot find maidroid, delete empty item. -- if cannot find maidroid, delete empty item.
self.object:remove() self.object:remove()
return return
@ -313,9 +304,8 @@ do
textures = {"air"}, textures = {"air"},
on_activate = on_activate, on_activate = on_activate,
on_step = on_step, on_step = on_step,
get_staticdata = get_staticdata, itemname = "",
itemname = itemname, maidroid_object = nil
is_initialized = false,
}) })
end end
@ -494,7 +484,7 @@ function maidroid.register_maidroid(product_name, def)
-- attach dummy item to new maidroid. -- attach dummy item to new maidroid.
local dummy_item = minetest.add_entity(self.object:getpos(), "maidroid:dummy_item") local dummy_item = minetest.add_entity(self.object:getpos(), "maidroid:dummy_item")
dummy_item:set_attach(self.object, "Arm_R", {x = 0.065, y = 0.50, z = -0.15}, {x = -45, y = 0, z = 0}) dummy_item:set_attach(self.object, "Arm_R", {x = 0.065, y = 0.50, z = -0.15}, {x = -45, y = 0, z = 0})
dummy_item:set_properties{textures={"maidroid:dummy_empty_craftitem"}} dummy_item:get_luaentity().maidroid_object = self.object
local core = self:get_core() local core = self:get_core()
if core ~= nil then if core ~= nil then