forked from mtcontrib/maidroid
Update maidroid's get_staticdata and on_activate
This commit is contained in:
parent
e238fe69f5
commit
02f4d13af0
@ -443,29 +443,9 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
self.nametag = data["nametag"]
|
self.nametag = data["nametag"]
|
||||||
|
|
||||||
local inventory = create_inventory(self)
|
local inventory = create_inventory(self)
|
||||||
local core_name = data["inventory"]["core"]
|
for list_name, list in pairs(data["inventory"]) do
|
||||||
local items = data["inventory"]["main"]
|
inventory:set_list(list_name, list)
|
||||||
local wield_item = data["inventory"]["wield_item"]
|
|
||||||
|
|
||||||
if core_name ~= "" then -- set a core
|
|
||||||
local core_stack = ItemStack(core_name)
|
|
||||||
core_stack:set_count(1)
|
|
||||||
inventory:add_item("core", core_stack)
|
|
||||||
self.core_name = core_name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(items) do -- set items
|
|
||||||
local item_stack = ItemStack(item["name"])
|
|
||||||
item_stack:set_count(item["count"])
|
|
||||||
inventory:add_item("main", item_stack)
|
|
||||||
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)
|
||||||
@ -490,30 +470,18 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
["product_name"] = self.product_name,
|
["product_name"] = self.product_name,
|
||||||
["manufacturing_number"] = self.manufacturing_number,
|
["manufacturing_number"] = self.manufacturing_number,
|
||||||
["nametag"] = self.nametag,
|
["nametag"] = self.nametag,
|
||||||
["inventory"] = {
|
["inventory"] = {},
|
||||||
["main"] = {},
|
|
||||||
["core"] = self.core_name,
|
|
||||||
["wield_item"] = nil,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- set main list.
|
-- set lists.
|
||||||
for _, item in ipairs(inventory:get_list("main")) do
|
for list_name, list in pairs(inventory:get_lists()) do
|
||||||
local count = item:get_count()
|
data["inventory"][list_name] = {}
|
||||||
local itemname = item:get_name()
|
|
||||||
if count ~= 0 then
|
for i, item in ipairs(list) do
|
||||||
local itemdata = {count = count, name = itemname}
|
data["inventory"][list_name][i] = item:to_string()
|
||||||
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user