Merge pull request #144 from tacigar/tacigar/farming_v0.4.15

Fix bug for farming in v0.4.15
Close #143
This commit is contained in:
tacigar 2017-01-07 17:46:43 +09:00 committed by GitHub
commit 9185079c8b
2 changed files with 42 additions and 22 deletions

View File

@ -211,6 +211,25 @@ function maidroid.maidroid.change_direction_randomly(self)
self:set_yaw_by_direction(direction) self:set_yaw_by_direction(direction)
end 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. -- 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( new_maidroid:get_luaentity():set_yaw_by_direction(
vector.subtract(user:getpos(), new_maidroid:getpos()) 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() itemstack:take_item()
return itemstack return itemstack
@ -342,23 +363,6 @@ function maidroid.register_maidroid(product_name, def)
maidroid.manufacturing_data[product_name] = 0 maidroid.manufacturing_data[product_name] = 0
end 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. -- create_inventory creates a new inventory, and returns it.
local function create_inventory(self) local function create_inventory(self)
self.inventory_name = self.product_name .. "_" .. tostring(self.manufacturing_number) 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] local core = maidroid.registered_cores[core_name]
core.on_start(self) core.on_start(self)
update_infotext(self) self:update_infotext()
end end
end, end,
@ -391,7 +395,7 @@ function maidroid.register_maidroid(product_name, def)
local core = maidroid.registered_cores[core_name] local core = maidroid.registered_cores[core_name]
core.on_stop(self) core.on_stop(self)
update_infotext(self) self:update_infotext()
end end
end, end,
@ -442,6 +446,7 @@ function maidroid.register_maidroid(product_name, def)
self.product_name = data["product_name"] self.product_name = data["product_name"]
self.manufacturing_number = data["manufacturing_number"] self.manufacturing_number = data["manufacturing_number"]
self.nametag = data["nametag"] self.nametag = data["nametag"]
self.owner_name = data["owner_name"]
local inventory = create_inventory(self) local inventory = create_inventory(self)
for list_name, list in pairs(data["inventory"]) do for list_name, list in pairs(data["inventory"]) do
@ -449,7 +454,7 @@ function maidroid.register_maidroid(product_name, def)
end end
end end
update_infotext(self) self:update_infotext()
self.object:set_nametag_attributes{ self.object:set_nametag_attributes{
text = self.nametag text = self.nametag
@ -471,6 +476,7 @@ 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,
["owner_name"] = self.owner_name,
["inventory"] = {}, ["inventory"] = {},
} }
@ -511,6 +517,11 @@ function maidroid.register_maidroid(product_name, def)
-- on_step is a callback function that is called every delta times. -- on_step is a callback function that is called every delta times.
local function on_step(self, dtime) 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 surrounding item.
pickup_item(self) pickup_item(self)
@ -545,7 +556,7 @@ function maidroid.register_maidroid(product_name, def)
end end
end end
update_infotext(self) self:update_infotext()
end end
-- register a definition of a new maidroid. -- register a definition of a new maidroid.
@ -569,6 +580,7 @@ function maidroid.register_maidroid(product_name, def)
pause = false, pause = false,
product_name = "", product_name = "",
manufacturing_number = -1, manufacturing_number = -1,
owner_name = "",
-- callback methods. -- callback methods.
on_activate = on_activate, on_activate = on_activate,
@ -594,6 +606,7 @@ function maidroid.register_maidroid(product_name, def)
has_item_in_main = maidroid.maidroid.has_item_in_main, has_item_in_main = maidroid.maidroid.has_item_in_main,
change_direction = maidroid.maidroid.change_direction, change_direction = maidroid.maidroid.change_direction,
change_direction_randomly = maidroid.maidroid.change_direction_randomly, change_direction_randomly = maidroid.maidroid.change_direction_randomly,
update_infotext = maidroid.maidroid.update_infotext,
}) })
-- register maidroid egg. -- register maidroid egg.

View File

@ -241,7 +241,14 @@ plant = function(self, dtime)
if is_plantable_place(self.destination) then if is_plantable_place(self.destination) then
local stack = self:get_wield_item_stack() local stack = self:get_wield_item_stack()
local itemname = stack:get_name() 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) stack:take_item(1)
self:set_wield_item_stack(stack) self:set_wield_item_stack(stack)
end end