diff --git a/maidroid/api.lua b/maidroid/api.lua index daf0293..d036da1 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -61,12 +61,13 @@ end -- maidroid.maidroid.get_core_name returns a name of a maidroid's current core. function maidroid.maidroid.get_core_name(self) - return self.core_name + local inv = self:get_inventory() + return inv:get_stack("core", 1):get_name() end -- maidroid.maidroid.get_core returns a maidroid's current core definition. function maidroid.maidroid.get_core(self) - local name = self:get_core_name(self) + local name = self:get_core_name() if name ~= "" then return maidroid.registered_cores[name] end @@ -342,14 +343,15 @@ function maidroid.register_maidroid(product_name, def) end local function update_infotext(self) - if self.core_name ~= "" then + local core_name = self:get_core_name() + if core_name ~= "" then local infotext = "" if self.pause then infotext = infotext .. "this maidroid is paused\n" else infotext = infotext .. "this maidroid is active\n" end - infotext = infotext .. "[Core] : " .. self.core_name + infotext = infotext .. "[Core] : " .. core_name self.object:set_properties{infotext = infotext} return @@ -366,7 +368,6 @@ function maidroid.register_maidroid(product_name, def) local core_name = stack:get_name() local core = maidroid.registered_cores[core_name] core.on_start(self) - self.core_name = core_name update_infotext(self) end @@ -386,8 +387,8 @@ function maidroid.register_maidroid(product_name, def) on_take = function(inv, listname, index, stack, player) if listname == "core" then - local core = maidroid.registered_cores[self.core_name] - self.core_name = "" + local core_name = stack:get_name() + local core = maidroid.registered_cores[core_name] core.on_stop(self) update_infotext(self) @@ -514,8 +515,8 @@ function maidroid.register_maidroid(product_name, def) pickup_item(self) -- do core method. - if (not self.pause) and self.core_name ~= "" then - local core = maidroid.registered_cores[self.core_name] + local core = self:get_core() + if (not self.pause) and core then core.on_step(self, dtime) end end @@ -531,16 +532,15 @@ function maidroid.register_maidroid(product_name, def) -- on_punch is a callback function that is called when a player punch then. local function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) + local core = self:get_core() if self.pause == true then self.pause = false - if self.core_name ~= "" then - local core = maidroid.registered_cores[self.core_name] + if core then core.on_resume(self) end else self.pause = true - if self.core_name ~= "" then - local core = maidroid.registered_cores[self.core_name] + if core then core.on_pause(self) end end @@ -569,7 +569,6 @@ function maidroid.register_maidroid(product_name, def) pause = false, product_name = "", manufacturing_number = -1, - core_name = "", -- callback methods. on_activate = on_activate,