From 641e7e7613d6055e8275dd59abb5ab7b1029c3eb Mon Sep 17 00:00:00 2001 From: tacigar Date: Tue, 3 Jan 2017 23:16:21 +0900 Subject: [PATCH 1/3] Add owner's info --- maidroid/api.lua | 50 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index 35c29ca..1c294cc 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -211,6 +211,25 @@ function maidroid.maidroid.change_direction_randomly(self) self:set_yaw_by_direction(direction) end +-- maidroid.maidroid.update_infotext updates the infotext of the maidroid. +function maidroid.maidroid.update_infotext(self) + local infotext = "" + local core_name = self:get_core_name() + + if core_name ~= "" then + if self.pause then + infotext = infotext .. "this maidroid is paused\n" + else + infotext = infotext .. "this maidroid is active\n" + end + infotext = infotext .. "[Core] : " .. core_name .. "\n" + else + infotext = infotext .. "this maidroid is inactive\n[Core] : None\n" + end + infotext = infotext .. "[Owner] : " .. self.owner_name + self.object:set_properties{infotext = infotext} +end + --------------------------------------------------------------------- -- maidroid.manufacturing_data represents a table that contains manufacturing data. @@ -324,6 +343,8 @@ function maidroid.register_egg(egg_name, def) new_maidroid:get_luaentity():set_yaw_by_direction( vector.subtract(user:getpos(), new_maidroid:getpos()) ) + new_maidroid:get_luaentity().owner_name = user:get_player_name() + new_maidroid:get_luaentity():update_infotext() itemstack:take_item() return itemstack @@ -342,23 +363,6 @@ function maidroid.register_maidroid(product_name, def) maidroid.manufacturing_data[product_name] = 0 end - local function update_infotext(self) - 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] : " .. core_name - - self.object:set_properties{infotext = infotext} - return - end - self.object:set_properties{infotext = "this maidroid is inactive"} - end - -- create_inventory creates a new inventory, and returns it. local function create_inventory(self) self.inventory_name = self.product_name .. "_" .. tostring(self.manufacturing_number) @@ -369,7 +373,7 @@ function maidroid.register_maidroid(product_name, def) local core = maidroid.registered_cores[core_name] core.on_start(self) - update_infotext(self) + self:update_infotext() end end, @@ -391,7 +395,7 @@ function maidroid.register_maidroid(product_name, def) local core = maidroid.registered_cores[core_name] core.on_stop(self) - update_infotext(self) + self:update_infotext() end end, @@ -442,6 +446,7 @@ function maidroid.register_maidroid(product_name, def) self.product_name = data["product_name"] self.manufacturing_number = data["manufacturing_number"] self.nametag = data["nametag"] + self.owner_name = data["owner_name"] local inventory = create_inventory(self) for list_name, list in pairs(data["inventory"]) do @@ -449,7 +454,7 @@ function maidroid.register_maidroid(product_name, def) end end - update_infotext(self) + self:update_infotext() self.object:set_nametag_attributes{ text = self.nametag @@ -471,6 +476,7 @@ function maidroid.register_maidroid(product_name, def) ["product_name"] = self.product_name, ["manufacturing_number"] = self.manufacturing_number, ["nametag"] = self.nametag, + ["owner_name"] = self.owner_name, ["inventory"] = {}, } @@ -545,7 +551,7 @@ function maidroid.register_maidroid(product_name, def) end end - update_infotext(self) + self:update_infotext() end -- register a definition of a new maidroid. @@ -569,6 +575,7 @@ function maidroid.register_maidroid(product_name, def) pause = false, product_name = "", manufacturing_number = -1, + owner_name = "", -- callback methods. on_activate = on_activate, @@ -594,6 +601,7 @@ function maidroid.register_maidroid(product_name, def) has_item_in_main = maidroid.maidroid.has_item_in_main, change_direction = maidroid.maidroid.change_direction, change_direction_randomly = maidroid.maidroid.change_direction_randomly, + update_infotext = maidroid.maidroid.update_infotext, }) -- register maidroid egg. From 7ed8b8172a71754994404f965a4d7e4167352bc4 Mon Sep 17 00:00:00 2001 From: tacigar Date: Tue, 3 Jan 2017 23:48:54 +0900 Subject: [PATCH 2/3] Use farming.place_seed api for v0.4.15 --- maidroid_core/cores/farming.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/maidroid_core/cores/farming.lua b/maidroid_core/cores/farming.lua index 2a5e3b7..88a7107 100644 --- a/maidroid_core/cores/farming.lua +++ b/maidroid_core/cores/farming.lua @@ -241,7 +241,14 @@ plant = function(self, dtime) if is_plantable_place(self.destination) then local stack = self:get_wield_item_stack() local itemname = stack:get_name() - minetest.add_node(self.destination, {name = itemname, param2 = 1}) + + local pointed_thing = { + type = "node", + under = vector.add(self.destination, {x = 0, y = -1, z = 0}), + above = self.destination, + } + farming.place_seed(stack, minetest.get_player_by_name(self.owner_name), pointed_thing, stack:get_name()) + stack:take_item(1) self:set_wield_item_stack(stack) end From 4ee3ef55dd3d6a27eb4f39a831dd6e5d779ae115 Mon Sep 17 00:00:00 2001 From: tacigar Date: Sat, 7 Jan 2017 17:38:49 +0900 Subject: [PATCH 3/3] Update on_step --- maidroid/api.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/maidroid/api.lua b/maidroid/api.lua index 1c294cc..93e9250 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -517,6 +517,11 @@ function maidroid.register_maidroid(product_name, def) -- on_step is a callback function that is called every delta times. local function on_step(self, dtime) + -- if owner didn't login, the maidroid does nothing. + if not minetest.get_player_by_name(self.owner_name) then + return + end + -- pickup surrounding item. pickup_item(self)