From 806c3be15d4781e7fe99bd955e4c51e3059adb33 Mon Sep 17 00:00:00 2001 From: tacigar Date: Tue, 13 Sep 2016 16:55:29 +0900 Subject: [PATCH] [UPDATE] Update method APIs --- maidroid/api.lua | 22 +++++++++++----------- maidroid/register.lua | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index a3dec53..9abc37b 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -34,9 +34,10 @@ end -- maidroid.maidroid represents a table that contains common methods -- for maidroid object. --- this table must be a metatable of maidroid self tables. +-- this table must be contains by a metatable.__index of maidroid self tables. +-- minetest.register_entity set initial properties as metatable, so +-- thie table's methods will be put there. maidroid.maidroid = {} -maidroid.maidroid.__index = maidroid -- maidroid.maidroid.get_inventory returns a inventory of a maidroid. function maidroid.maidroid.get_inventory(self) @@ -79,7 +80,6 @@ function maidroid.register_maidroid(product_name, def) -- create_inventory creates a new inventory, and returns it. function create_inventory(self) self.inventory_name = self.product_name .. tostring(self.manufacturing_number) - local inventory = minetest.create_detached_inventory(self.inventory_name, { on_put = function(inv, listname, index, stack, player) if listname == "core" then @@ -126,12 +126,7 @@ function maidroid.register_maidroid(product_name, def) -- on_activate is a callback function that is called when the object is created or recreated. function on_activate(self, staticdata) - -- first, set maidroid metatable to self table. - if getmetatable(self) == nil then - setmetatable(self, maidroid.maidroid) - end - - -- second, parse the staticdata, and compose a inventory. + -- parse the staticdata, and compose a inventory. if staticdata == "" then self.product_name = product_name self.manufacturing_number = 0 @@ -166,7 +161,7 @@ function maidroid.register_maidroid(product_name, def) -- get_staticdata is a callback function that is called when the object is destroyed. function get_staticdata(self) - local inventory = maidroid.get_inventory(self) + local inventory = self:get_inventory() local data = { ["product_name"] = self.product_name, ["manufacturing_number"] = self.manufacturing_number, @@ -247,10 +242,15 @@ function maidroid.register_maidroid(product_name, def) on_rightclick = on_rightclick, on_punch = on_punch, get_staticdata = get_staticdata, + + -- extra methods. + get_inventory = maidroid.maidroid.get_inventory, + get_core = maidroid.maidroid.get_core, + get_core_name = maidroid.maidroid.get_core_name, }) minetest.register_craftitem(product_name .. "_spawner", { - description = " Spawner", + description = product_name .. " spawner", inventory_image = def.inventory_image, stack_max = 1, on_use = function(item_stack, user, pointed_thing) diff --git a/maidroid/register.lua b/maidroid/register.lua index 236cbda..4ded476 100644 --- a/maidroid/register.lua +++ b/maidroid/register.lua @@ -7,19 +7,19 @@ maidroid.register_maidroid("maidroid:maidroid_mk1", { hp_max = 10, weight = 20, mesh = "maidroid.b3d", - textures = "maidroid_mk1.png", + textures = {"maidroid_mk1.png"}, }) maidroid.register_maidroid("maidroid:maidroid_mk2", { hp_max = 10, weight = 20, mesh = "maidroid.b3d", - textures = "maidroid_mk2.png", + textures = {"maidroid_mk2.png"}, }) maidroid.register_maidroid("maidroid:maidroid_mk3", { hp_max = 10, weight = 20, mesh = "maidroid.b3d", - textures = "maidroid_mk3.png", + textures = {"maidroid_mk3.png"}, })