mirror of
https://github.com/tacigar/maidroid.git
synced 2024-11-05 17:50:33 +01:00
Brush up code
This commit is contained in:
parent
0da2c5c9a9
commit
ff5aa10c4d
|
@ -264,7 +264,7 @@ do
|
|||
if maidroid.is_maidroid(luaentity.name) then
|
||||
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
|
||||
self.itemname = ""
|
||||
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"]
|
||||
|
||||
if core_name ~= "" then -- set a core
|
||||
core_stack = ItemStack(core_name)
|
||||
local core_stack = ItemStack(core_name)
|
||||
core_stack:set_count(1)
|
||||
inventory:add_item("core", core_stack)
|
||||
self.core_name = core_name
|
||||
|
@ -518,7 +518,7 @@ function maidroid.register_maidroid(product_name, def)
|
|||
end
|
||||
|
||||
-- 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 radius = 1.0
|
||||
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
|
||||
local itemstring = obj:get_luaentity().itemstring
|
||||
|
||||
if minetest.registered_nodes[itemstring] ~= nil or minetest.registered_items[itemstring] ~= nil
|
||||
or minetest.registered_tools[itemstring] ~= nil or minetest.registered_craftitems[itemstring] ~= nil then
|
||||
if minetest.registered_items[itemstring] ~= nil then
|
||||
local inv = self:get_inventory()
|
||||
local stack = ItemStack(itemstring)
|
||||
local leftover = inv:add_item("main", stack)
|
||||
|
|
|
@ -16,10 +16,6 @@ local function on_stop(self)
|
|||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
end
|
||||
|
||||
local on_resume = on_start
|
||||
|
||||
local on_pause = on_stop
|
||||
|
||||
local function on_step(self, dtime)
|
||||
local player = self:get_nearest_player(10)
|
||||
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 velocity.y == 0 and self.state == state.ACCOMPANY then
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
@ -62,7 +59,7 @@ maidroid.register_core("maidroid_core:basic", {
|
|||
inventory_image = "maidroid_core_basic.png",
|
||||
on_start = on_start,
|
||||
on_stop = on_stop,
|
||||
on_resume = on_resume,
|
||||
on_pause = on_pause,
|
||||
on_resume = on_start,
|
||||
on_pause = on_stop,
|
||||
on_step = on_step,
|
||||
})
|
||||
|
|
|
@ -113,8 +113,11 @@ walk_randomly = function(self, dtime)
|
|||
local velocity = self.object:getvelocity()
|
||||
if velocity.y == 0 then
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
@ -224,7 +227,8 @@ walk_to_plant_and_mow_common = function(self, dtime)
|
|||
local velocity = self.object:getvelocity()
|
||||
if velocity.y == 0 then
|
||||
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
|
||||
self.object:setvelocity{x = velocity.x, y = 6, z = velocity.z}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user