Fix wield item in get_staticdata and on_activate

This commit is contained in:
tacigar 2016-12-23 13:45:00 +09:00
parent 7c32c4fb34
commit 0d66568a21

View File

@ -445,6 +445,7 @@ function maidroid.register_maidroid(product_name, def)
local inventory = create_inventory(self) local inventory = create_inventory(self)
local core_name = data["inventory"]["core"] local core_name = data["inventory"]["core"]
local items = data["inventory"]["main"] local items = data["inventory"]["main"]
local wield_item = data["inventory"]["wield_item"]
if core_name ~= "" then -- set a core if core_name ~= "" then -- set a core
core_stack = ItemStack(core_name) core_stack = ItemStack(core_name)
@ -458,6 +459,13 @@ function maidroid.register_maidroid(product_name, def)
item_stack:set_count(item["count"]) item_stack:set_count(item["count"])
inventory:add_item("main", item_stack) inventory:add_item("main", item_stack)
end end
if wield_item["name"] ~= "" then
local item_stack = ItemStack(wield_item["name"])
item_stack:set_count(wield_item["count"])
inventory:add_item("wield_item", item_stack)
end
end end
update_infotext(self) update_infotext(self)
@ -485,9 +493,11 @@ function maidroid.register_maidroid(product_name, def)
["inventory"] = { ["inventory"] = {
["main"] = {}, ["main"] = {},
["core"] = self.core_name, ["core"] = self.core_name,
["wield_item"] = nil,
}, },
} }
-- set main list.
for _, item in ipairs(inventory:get_list("main")) do for _, item in ipairs(inventory:get_list("main")) do
local count = item:get_count() local count = item:get_count()
local itemname = item:get_name() local itemname = item:get_name()
@ -496,6 +506,14 @@ function maidroid.register_maidroid(product_name, def)
table.insert(data["inventory"]["main"], itemdata) table.insert(data["inventory"]["main"], itemdata)
end end
end end
do -- set wield_item list.
local item = self:get_wield_item_stack()
local count = item:get_count()
local itemname = item:get_name()
local itemdata = {count = count, name = itemname}
data["inventory"]["wield_item"] = itemdata
end
return minetest.serialize(data) return minetest.serialize(data)
end end