1
0
mirror of https://github.com/tacigar/maidroid.git synced 2024-11-11 04:30:26 +01:00

Merge pull request #114 from tacigar/tacigar/brushup

Brush up code
Close #111
This commit is contained in:
tacigar 2016-12-24 09:24:14 +09:00 committed by GitHub
commit 8ab37c1ce6
3 changed files with 15 additions and 15 deletions

View File

@ -264,7 +264,7 @@ do
if maidroid.is_maidroid(luaentity.name) then if maidroid.is_maidroid(luaentity.name) then
local stack = luaentity:get_wield_item_stack() local stack = luaentity:get_wield_item_stack()
if stack:get_name() ~= itemname then if stack:get_name() ~= self.itemname then
if stack:is_empty() then if stack:is_empty() then
self.itemname = "" self.itemname = ""
self.object:set_properties{textures={"maidroid:dummy_empty_craftitem"}} self.object:set_properties{textures={"maidroid:dummy_empty_craftitem"}}
@ -448,7 +448,7 @@ function maidroid.register_maidroid(product_name, def)
local wield_item = data["inventory"]["wield_item"] local wield_item = data["inventory"]["wield_item"]
if core_name ~= "" then -- set a core if core_name ~= "" then -- set a core
core_stack = ItemStack(core_name) local core_stack = ItemStack(core_name)
core_stack:set_count(1) core_stack:set_count(1)
inventory:add_item("core", core_stack) inventory:add_item("core", core_stack)
self.core_name = core_name self.core_name = core_name
@ -518,7 +518,7 @@ function maidroid.register_maidroid(product_name, def)
end end
-- maidroid.maidroid.pickup_item pickup items placed and put it to main slot. -- maidroid.maidroid.pickup_item pickup items placed and put it to main slot.
function pickup_item(self) local function pickup_item(self)
local pos = self.object:getpos() local pos = self.object:getpos()
local radius = 1.0 local radius = 1.0
local all_objects = minetest.get_objects_inside_radius(pos, radius) local all_objects = minetest.get_objects_inside_radius(pos, radius)
@ -527,8 +527,7 @@ function maidroid.register_maidroid(product_name, def)
if not obj:is_player() and obj:get_luaentity() then if not obj:is_player() and obj:get_luaentity() then
local itemstring = obj:get_luaentity().itemstring local itemstring = obj:get_luaentity().itemstring
if minetest.registered_nodes[itemstring] ~= nil or minetest.registered_items[itemstring] ~= nil if minetest.registered_items[itemstring] ~= nil then
or minetest.registered_tools[itemstring] ~= nil or minetest.registered_craftitems[itemstring] ~= nil then
local inv = self:get_inventory() local inv = self:get_inventory()
local stack = ItemStack(itemstring) local stack = ItemStack(itemstring)
local leftover = inv:add_item("main", stack) local leftover = inv:add_item("main", stack)

View File

@ -16,10 +16,6 @@ local function on_stop(self)
self.object:setvelocity{x = 0, y = 0, z = 0} self.object:setvelocity{x = 0, y = 0, z = 0}
end end
local on_resume = on_start
local on_pause = on_stop
local function on_step(self, dtime) local function on_step(self, dtime)
local player = self:get_nearest_player(10) local player = self:get_nearest_player(10)
if player == nil then if player == nil then
@ -50,7 +46,8 @@ local function on_step(self, dtime)
-- if maidroid is stoped by obstacle, the maidroid must jump. -- if maidroid is stoped by obstacle, the maidroid must jump.
if velocity.y == 0 and self.state == state.ACCOMPANY then if velocity.y == 0 and self.state == state.ACCOMPANY then
local front_node = self:get_front_node() local front_node = self:get_front_node()
if front_node.name ~= "air" then if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable then
self.object:setvelocity{x = direction.x, y = 5, z = direction.z} self.object:setvelocity{x = direction.x, y = 5, z = direction.z}
end end
end end
@ -62,7 +59,7 @@ maidroid.register_core("maidroid_core:basic", {
inventory_image = "maidroid_core_basic.png", inventory_image = "maidroid_core_basic.png",
on_start = on_start, on_start = on_start,
on_stop = on_stop, on_stop = on_stop,
on_resume = on_resume, on_resume = on_start,
on_pause = on_pause, on_pause = on_stop,
on_step = on_step, on_step = on_step,
}) })

View File

@ -113,8 +113,11 @@ walk_randomly = function(self, dtime)
local velocity = self.object:getvelocity() local velocity = self.object:getvelocity()
if velocity.y == 0 then if velocity.y == 0 then
local front_node = self:get_front_node() local front_node = self:get_front_node()
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name].walkable
and not (minetest.get_item_group(front_node.name, "fence") > 0) then if minetest.get_item_group(front_node.name, "fence") > 0 then
self:change_direction_randomly()
elseif front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable then
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z} self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
end end
end end
@ -224,7 +227,8 @@ walk_to_plant_and_mow_common = function(self, dtime)
local velocity = self.object:getvelocity() local velocity = self.object:getvelocity()
if velocity.y == 0 then if velocity.y == 0 then
local front_node = self:get_front_node() local front_node = self:get_front_node()
if front_node.name ~= "air" and minetest.registered_nodes[front_node.name].walkable if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil
and minetest.registered_nodes[front_node.name].walkable
and not (minetest.get_item_group(front_node.name, "fence") > 0) then and not (minetest.get_item_group(front_node.name, "fence") > 0) then
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z} self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
end end