mirror of
https://github.com/tacigar/maidroid.git
synced 2025-03-29 15:10:25 +01:00
Fix indent
This commit is contained in:
parent
d1db40559b
commit
605612a2b3
112
api.lua
112
api.lua
@ -7,7 +7,7 @@ local _aux = maidroid._aux
|
|||||||
|
|
||||||
-- aux function to generate serialnumber for inventories
|
-- aux function to generate serialnumber for inventories
|
||||||
local gen_inv_serialnumber = (function ()
|
local gen_inv_serialnumber = (function ()
|
||||||
local serialnumber = 0
|
local serialnumber = 0
|
||||||
return function ()
|
return function ()
|
||||||
serialnumber = serialnumber + 1
|
serialnumber = serialnumber + 1
|
||||||
return serialnumber - 1
|
return serialnumber - 1
|
||||||
@ -55,75 +55,75 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
makes_footstep_sound = true,
|
makes_footstep_sound = true,
|
||||||
module = nil,
|
module = nil,
|
||||||
invname = "",
|
invname = "",
|
||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
self.invname = "maidroid"..tostring(gen_inv_serialnumber())
|
self.invname = "maidroid"..tostring(gen_inv_serialnumber())
|
||||||
local inv = minetest.create_detached_inventory(self.invname, {
|
local inv = minetest.create_detached_inventory(self.invname, {
|
||||||
on_put = function(inv, listname, index, stack, player)
|
on_put = function(inv, listname, index, stack, player)
|
||||||
if listname == module_invname then
|
if listname == module_invname then
|
||||||
local module_name = stack:get_name()
|
local module_name = stack:get_name()
|
||||||
local module_def = maidroid.registered_modules[module_name]
|
local module_def = maidroid.registered_modules[module_name]
|
||||||
self.module = module_def
|
self.module = module_def
|
||||||
module_def.initialize(self)
|
module_def.initialize(self)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
allow_put = function(inv, listname, index, stack, player)
|
allow_put = function(inv, listname, index, stack, player)
|
||||||
local item_name = stack:get_name()
|
local item_name = stack:get_name()
|
||||||
local is_module = maidroid.registered_modules[item_name]
|
local is_module = maidroid.registered_modules[item_name]
|
||||||
if listname == main_invname
|
if listname == main_invname
|
||||||
or (listname == module_invname and is_module) then
|
or (listname == module_invname and is_module) then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
on_take = function(inv, listname, index, stack, player)
|
on_take = function(inv, listname, index, stack, player)
|
||||||
if listname == module_invname then
|
if listname == module_invname then
|
||||||
local module_name = stack:get_name()
|
local module_name = stack:get_name()
|
||||||
local module_def = maidroid.registered_modules[module_name]
|
local module_def = maidroid.registered_modules[module_name]
|
||||||
self.module = nil
|
self.module = nil
|
||||||
module_def.finalize(self)
|
module_def.finalize(self)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
inv:set_size(main_invname, main_invsize)
|
inv:set_size(main_invname, main_invsize)
|
||||||
inv:set_size(module_invname, module_invsize)
|
inv:set_size(module_invname, module_invsize)
|
||||||
-- process staticdata
|
-- process staticdata
|
||||||
if staticdata ~= "" then
|
if staticdata ~= "" then
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
if data.inv.module ~= "" then
|
if data.inv.module ~= "" then
|
||||||
module_stack = ItemStack(data.inv.module)
|
module_stack = ItemStack(data.inv.module)
|
||||||
module_stack:set_count(1)
|
module_stack:set_count(1)
|
||||||
inv:add_item(module_invname, module_stack)
|
inv:add_item(module_invname, module_stack)
|
||||||
self.module = maidroid.registered_modules[data.inv.module]
|
self.module = maidroid.registered_modules[data.inv.module]
|
||||||
end
|
end
|
||||||
for _, item in ipairs(data.inv.main) do
|
for _, item in ipairs(data.inv.main) do
|
||||||
local itemstack = ItemStack(item.name)
|
local itemstack = ItemStack(item.name)
|
||||||
itemstack:set_count(item.count)
|
itemstack:set_count(item.count)
|
||||||
inv:add_item(main_invname, itemstack)
|
inv:add_item(main_invname, itemstack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- initialize module
|
-- initialize module
|
||||||
if self.module then self.module.initialize(self)
|
if self.module then self.module.initialize(self)
|
||||||
else self.object:setvelocity{x = 0, y = 0, z = 0} end
|
else self.object:setvelocity{x = 0, y = 0, z = 0} end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
if self.module then self.module.on_step(self, dtime) end
|
if self.module then self.module.on_step(self, dtime) end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
local formspec = "size[8,9]"
|
local formspec = "size[8,9]"
|
||||||
.."list[detached:"..self.invname..";"..main_invname..";0,0;4,4;]"
|
.."list[detached:"..self.invname..";"..main_invname..";0,0;4,4;]"
|
||||||
.."label[5,0;MODULE]"
|
.."label[5,0;MODULE]"
|
||||||
.."list[detached:"..self.invname..";"..module_invname..";6,0;1,1;]"
|
.."list[detached:"..self.invname..";"..module_invname..";6,0;1,1;]"
|
||||||
.."list[current_player;"..main_invname..";0,5;8,1;]"
|
.."list[current_player;"..main_invname..";0,5;8,1;]"
|
||||||
.."list[current_player;"..main_invname..";0,6.2;8,3;8]"
|
.."list[current_player;"..main_invname..";0,6.2;8,3;8]"
|
||||||
minetest.show_formspec(clicker:get_player_name(), self.invname, formspec)
|
minetest.show_formspec(clicker:get_player_name(), self.invname, formspec)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
local inv = _aux.get_maidroid_inventory(self)
|
local inv = _aux.get_maidroid_inventory(self)
|
||||||
local staticdata = {}
|
local staticdata = {}
|
||||||
@ -132,17 +132,17 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
staticdata.inv.module = module_name or ""
|
staticdata.inv.module = module_name or ""
|
||||||
staticdata.inv.main = {}
|
staticdata.inv.main = {}
|
||||||
for _, item in ipairs(inv:get_list(main_invname)) do
|
for _, item in ipairs(inv:get_list(main_invname)) do
|
||||||
local count = item:get_count()
|
local count = item:get_count()
|
||||||
local itemname = item:get_name()
|
local itemname = item:get_name()
|
||||||
if count ~= 0 then
|
if count ~= 0 then
|
||||||
local itemdata = { count = count, name = itemname }
|
local itemdata = { count = count, name = itemname }
|
||||||
table.insert(staticdata.inv.main, itemdata)
|
table.insert(staticdata.inv.main, itemdata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return minetest.serialize(staticdata)
|
return minetest.serialize(staticdata)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- register spawn egg
|
-- register spawn egg
|
||||||
minetest.register_craftitem(product_name.."_spawn_egg", {
|
minetest.register_craftitem(product_name.."_spawn_egg", {
|
||||||
description = def.description.." Spawn Egg",
|
description = def.description.." Spawn Egg",
|
||||||
@ -151,8 +151,8 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
print(pointed_thing.under, pointed_thing.above)
|
print(pointed_thing.under, pointed_thing.above)
|
||||||
if pointed_thing.above ~= nil then
|
if pointed_thing.above ~= nil then
|
||||||
minetest.add_entity(pointed_thing.above, product_name)
|
minetest.add_entity(pointed_thing.above, product_name)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -50,14 +50,14 @@ function maidroid.modules._aux.pickup_item(self, radius, target_pred)
|
|||||||
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 itemstring then
|
if itemstring then
|
||||||
if pred(itemstring) then
|
if pred(itemstring) then
|
||||||
local inv = maidroid._aux.get_maidroid_inventory(self)
|
local inv = maidroid._aux.get_maidroid_inventory(self)
|
||||||
local stack = ItemStack(itemstring)
|
local stack = ItemStack(itemstring)
|
||||||
local leftover = inv:add_item("main", stack)
|
local leftover = inv:add_item("main", stack)
|
||||||
minetest.add_item(obj:getpos(), leftover)
|
minetest.add_item(obj:getpos(), leftover)
|
||||||
obj:get_luaentity().itemstring = ""
|
obj:get_luaentity().itemstring = ""
|
||||||
obj:remove()
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,24 +7,24 @@ local util = maidroid.util
|
|||||||
local _aux = maidroid.modules._aux
|
local _aux = maidroid.modules._aux
|
||||||
|
|
||||||
local state = { idle = 0, chase = 1}
|
local state = { idle = 0, chase = 1}
|
||||||
local view_of_range = 7
|
local view_of_range = 7
|
||||||
local stop_of_range = 2
|
local stop_of_range = 2
|
||||||
|
|
||||||
maidroid.register_module("maidroid:chasing_player_module", {
|
maidroid.register_module("maidroid:chasing_player_module", {
|
||||||
description = "Maidroid Module : Chasing Player",
|
description = "Maidroid Module : Chasing Player",
|
||||||
inventory_image = "maidroid_chasing_player_module.png",
|
inventory_image = "maidroid_chasing_player_module.png",
|
||||||
|
|
||||||
initialize = function(self)
|
initialize = function(self)
|
||||||
self.state = state.idle
|
self.state = state.idle
|
||||||
self.object:setacceleration{x = 0, y = -10, z = 0}
|
self.object:setacceleration{x = 0, y = -10, z = 0}
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
finalize = function(self)
|
finalize = function(self)
|
||||||
self.state = nil
|
self.state = nil
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local all_objects = minetest.get_objects_inside_radius(pos, view_of_range)
|
local all_objects = minetest.get_objects_inside_radius(pos, view_of_range)
|
||||||
@ -42,33 +42,33 @@ maidroid.register_module("maidroid:chasing_player_module", {
|
|||||||
local vel = self.object:getvelocity()
|
local vel = self.object:getvelocity()
|
||||||
if (vector.length(dir) < stop_of_range) then
|
if (vector.length(dir) < stop_of_range) then
|
||||||
if self.state == state.chase then
|
if self.state == state.chase then
|
||||||
self.object:set_animation(maidroid.animations.stand, 15, 0)
|
self.object:set_animation(maidroid.animations.stand, 15, 0)
|
||||||
self.state = state.idle
|
self.state = state.idle
|
||||||
self.object:setvelocity({x = 0, y = vel.y, z = 0})
|
self.object:setvelocity({x = 0, y = vel.y, z = 0})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self.state == state.idle then
|
if self.state == state.idle then
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
self.state = state.chase
|
self.state = state.chase
|
||||||
end
|
end
|
||||||
self.object:setvelocity({x = dir.x, y = vel.y, z = dir.z})
|
self.object:setvelocity({x = dir.x, y = vel.y, z = dir.z})
|
||||||
end
|
end
|
||||||
local yaw = math.atan2(dir.z, dir.x) + math.pi/2
|
local yaw = math.atan2(dir.z, dir.x) + math.pi/2
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
|
|
||||||
-- jump process
|
-- jump process
|
||||||
if vel.y == 0 and self.state == state.chase then
|
if vel.y == 0 and self.state == state.chase then
|
||||||
local rdir = vector.round(dir)
|
local rdir = vector.round(dir)
|
||||||
local front_vec = { x = 0, y = 0, z = 0 }
|
local front_vec = { x = 0, y = 0, z = 0 }
|
||||||
if math.abs((rdir.x / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
|
if math.abs((rdir.x / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
|
||||||
if rdir.x > 0 then front_vec.x = 1 else front_vec.x = -1 end
|
if rdir.x > 0 then front_vec.x = 1 else front_vec.x = -1 end
|
||||||
end
|
end
|
||||||
if math.abs((rdir.z / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
|
if math.abs((rdir.z / (math.abs(rdir.x) + math.abs(rdir.z)))) > 0.5 then
|
||||||
if rdir.z > 0 then front_vec.z = 1 else front_vec.z = -1 end
|
if rdir.z > 0 then front_vec.z = 1 else front_vec.z = -1 end
|
||||||
end
|
end
|
||||||
local front_pos = vector.add(vector.round(pos), front_vec)
|
local front_pos = vector.add(vector.round(pos), front_vec)
|
||||||
if minetest.get_node(front_pos).name ~= "air" then
|
if minetest.get_node(front_pos).name ~= "air" then
|
||||||
self.object:setvelocity({x = dir.x, y = 5, z = dir.z})
|
self.object:setvelocity({x = dir.x, y = 5, z = dir.z})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -40,7 +40,7 @@ end
|
|||||||
maidroid.register_module("maidroid:farming_module", {
|
maidroid.register_module("maidroid:farming_module", {
|
||||||
description = "Maidroid Module : Farming",
|
description = "Maidroid Module : Farming",
|
||||||
inventory_image = "maidroid_farming_module.png",
|
inventory_image = "maidroid_farming_module.png",
|
||||||
|
|
||||||
initialize = function(self)
|
initialize = function(self)
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
self.object:setacceleration{x = 0, y = -10, z = 0}
|
self.object:setacceleration{x = 0, y = -10, z = 0}
|
||||||
@ -49,14 +49,14 @@ maidroid.register_module("maidroid:farming_module", {
|
|||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
finalize = function(self)
|
finalize = function(self)
|
||||||
self.state = nil
|
self.state = nil
|
||||||
self.preposition = nil
|
self.preposition = nil
|
||||||
self.time_count = nil
|
self.time_count = nil
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local rpos = vector.round(pos)
|
local rpos = vector.round(pos)
|
||||||
@ -66,70 +66,70 @@ maidroid.register_module("maidroid:farming_module", {
|
|||||||
local forward_pos = vector.add(rpos, forward_vec2)
|
local forward_pos = vector.add(rpos, forward_vec2)
|
||||||
local forward_node = minetest.get_node(forward_pos)
|
local forward_node = minetest.get_node(forward_pos)
|
||||||
local forward_under_pos = vector.subtract(forward_pos, {x = 0, y = 1, z = 0})
|
local forward_under_pos = vector.subtract(forward_pos, {x = 0, y = 1, z = 0})
|
||||||
|
|
||||||
if self.state == state.walk then -- searching plants or spaces
|
if self.state == state.walk then -- searching plants or spaces
|
||||||
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
|
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
|
||||||
self.state = state.punch
|
self.state = state.punch
|
||||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
|
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
elseif forward_node.name == "air"
|
elseif forward_node.name == "air"
|
||||||
and minetest.get_item_group(minetest.get_node(forward_under_pos).name, "wet") > 0
|
and minetest.get_item_group(minetest.get_node(forward_under_pos).name, "wet") > 0
|
||||||
and has_seed_item(self) then
|
and has_seed_item(self) then
|
||||||
self.state = state.plant
|
self.state = state.plant
|
||||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end
|
end
|
||||||
-- pickup droped seed items
|
-- pickup droped seed items
|
||||||
_aux.pickup_item(self, 1.5, function(itemstring)
|
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||||
return minetest.get_item_group(itemstring, "seed") > 0
|
return minetest.get_item_group(itemstring, "seed") > 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
elseif self.state == state.punch then
|
elseif self.state == state.punch then
|
||||||
if self.time_count >= max_punch_time then
|
if self.time_count >= max_punch_time then
|
||||||
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
|
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
|
||||||
minetest.remove_node(forward_pos)
|
minetest.remove_node(forward_pos)
|
||||||
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
||||||
local stacks = minetest.get_node_drops(forward_node.name)
|
local stacks = minetest.get_node_drops(forward_node.name)
|
||||||
for _, stack in ipairs(stacks) do
|
for _, stack in ipairs(stacks) do
|
||||||
local leftover = inv:add_item("main", stack)
|
local leftover = inv:add_item("main", stack)
|
||||||
minetest.add_item(forward_pos, leftover)
|
minetest.add_item(forward_pos, leftover)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.state = state.walk
|
self.state = state.walk
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
else
|
else
|
||||||
self.time_count = self.time_count + 1
|
self.time_count = self.time_count + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif self.state == state.plant then
|
elseif self.state == state.plant then
|
||||||
if self.time_count >= max_plant_time then
|
if self.time_count >= max_plant_time then
|
||||||
if forward_node.name == "air" and minetest.get_item_group(
|
if forward_node.name == "air" and minetest.get_item_group(
|
||||||
minetest.get_node(forward_under_pos).name, "soil") > 0 then
|
minetest.get_node(forward_under_pos).name, "soil") > 0 then
|
||||||
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
||||||
local stacks = inv:get_list("main")
|
local stacks = inv:get_list("main")
|
||||||
for idx, stack in ipairs(stacks) do
|
for idx, stack in ipairs(stacks) do
|
||||||
local item_name = stack:get_name()
|
local item_name = stack:get_name()
|
||||||
if minetest.get_item_group(item_name, "seed") > 0 then
|
if minetest.get_item_group(item_name, "seed") > 0 then
|
||||||
minetest.add_node(forward_pos, {name = item_name, param2 = 1})
|
minetest.add_node(forward_pos, {name = item_name, param2 = 1})
|
||||||
stack:take_item(1)
|
stack:take_item(1)
|
||||||
inv:set_stack("main", idx, stack)
|
inv:set_stack("main", idx, stack)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.state = state.walk
|
self.state = state.walk
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
else
|
else
|
||||||
self.time_count = self.time_count + 1
|
self.time_count = self.time_count + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
self.preposition = pos
|
||||||
|
return
|
||||||
end
|
end
|
||||||
self.preposition = pos
|
})
|
||||||
return
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
@ -41,7 +41,7 @@ end
|
|||||||
maidroid.register_module("maidroid:lumberjack_module", {
|
maidroid.register_module("maidroid:lumberjack_module", {
|
||||||
description = "Maidroid Module : Lumberjack",
|
description = "Maidroid Module : Lumberjack",
|
||||||
inventory_image = "maidroid_lumberjack_module.png",
|
inventory_image = "maidroid_lumberjack_module.png",
|
||||||
|
|
||||||
initialize = function(self)
|
initialize = function(self)
|
||||||
self.state = state.walk
|
self.state = state.walk
|
||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
@ -50,14 +50,14 @@ maidroid.register_module("maidroid:lumberjack_module", {
|
|||||||
self.preposition = self.object:getpos()
|
self.preposition = self.object:getpos()
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
finalize = function(self)
|
finalize = function(self)
|
||||||
self.state = nil
|
self.state = nil
|
||||||
self.time_count = nil
|
self.time_count = nil
|
||||||
self.preposition = nil
|
self.preposition = nil
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local rpos = vector.round(pos)
|
local rpos = vector.round(pos)
|
||||||
@ -68,74 +68,74 @@ maidroid.register_module("maidroid:lumberjack_module", {
|
|||||||
local forward_node = minetest.get_node(forward_pos)
|
local forward_node = minetest.get_node(forward_pos)
|
||||||
local forward_under_pos = _aux.get_under_pos(forward_pos)
|
local forward_under_pos = _aux.get_under_pos(forward_pos)
|
||||||
local forward_under_node = minetest.get_node(forward_under_pos)
|
local forward_under_node = minetest.get_node(forward_under_pos)
|
||||||
|
|
||||||
if self.state == state.walk then
|
if self.state == state.walk then
|
||||||
if check_punch_flag(forward_pos) then -- punch tree node
|
if check_punch_flag(forward_pos) then -- punch tree node
|
||||||
self.state = state.punch
|
self.state = state.punch
|
||||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
|
elseif pos.x == self.preposition.x or pos.z == self.preposition.z then
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
elseif forward_node.name == "air"
|
elseif forward_node.name == "air"
|
||||||
and minetest.get_item_group(forward_under_node.name, "soil") > 0
|
and minetest.get_item_group(forward_under_node.name, "soil") > 0
|
||||||
and has_sapling_item(self) then
|
and has_sapling_item(self) then
|
||||||
self.state = state.plant
|
self.state = state.plant
|
||||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||||
end
|
end
|
||||||
-- pickup sapling items
|
-- pickup sapling items
|
||||||
_aux.pickup_item(self, 1.5, function(itemstring)
|
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||||
return util.table_find_value(target_sapling_list, itemstring)
|
return util.table_find_value(target_sapling_list, itemstring)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
elseif self.state == state.punch then
|
elseif self.state == state.punch then
|
||||||
if self.time_count >= max_punch_time then
|
if self.time_count >= max_punch_time then
|
||||||
local punch_flag, forward_upper_pos, forward_upper_node
|
local punch_flag, forward_upper_pos, forward_upper_node
|
||||||
= check_punch_flag(forward_pos)
|
= check_punch_flag(forward_pos)
|
||||||
if punch_flag then
|
if punch_flag then
|
||||||
minetest.remove_node(forward_upper_pos)
|
minetest.remove_node(forward_upper_pos)
|
||||||
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
||||||
local stacks = minetest.get_node_drops(forward_upper_node.name)
|
local stacks = minetest.get_node_drops(forward_upper_node.name)
|
||||||
for _, stack in ipairs(stacks) do
|
for _, stack in ipairs(stacks) do
|
||||||
local leftover = inv:add_item("main", stack)
|
local leftover = inv:add_item("main", stack)
|
||||||
minetest.add_item(forward_pos, leftover)
|
minetest.add_item(forward_pos, leftover)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if (not forward_upper_pos) or (forward_upper_pos and
|
if (not forward_upper_pos) or (forward_upper_pos and
|
||||||
not check_punch_flag(_aux.get_upper_pos(forward_upper_pos))) then
|
not check_punch_flag(_aux.get_upper_pos(forward_upper_pos))) then
|
||||||
self.state = state.walk
|
self.state = state.walk
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
end
|
end
|
||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
else
|
else
|
||||||
self.time_count = self.time_count + 1
|
self.time_count = self.time_count + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif self.state == state.plant then
|
elseif self.state == state.plant then
|
||||||
if self.time_count > max_plant_time then
|
if self.time_count > max_plant_time then
|
||||||
if forward_node.name == "air"
|
if forward_node.name == "air"
|
||||||
and minetest.get_item_group(forward_under_node.name, "soil") > 0 then
|
and minetest.get_item_group(forward_under_node.name, "soil") > 0 then
|
||||||
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
local inv = minetest.get_inventory{type = "detached", name = self.invname}
|
||||||
local stacks = inv:get_list("main")
|
local stacks = inv:get_list("main")
|
||||||
for i, stack in ipairs(stacks) do
|
for i, stack in ipairs(stacks) do
|
||||||
local itemname = stack:get_name()
|
local itemname = stack:get_name()
|
||||||
if util.table_find_value(target_sapling_list, itemname) then
|
if util.table_find_value(target_sapling_list, itemname) then
|
||||||
minetest.add_node(forward_pos, {name = itemname, param2 = 1})
|
minetest.add_node(forward_pos, {name = itemname, param2 = 1})
|
||||||
stack:take_item(1)
|
stack:take_item(1)
|
||||||
inv:set_stack("main", i, stack)
|
inv:set_stack("main", i, stack)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.state = state.walk
|
self.state = state.walk
|
||||||
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
self.object:set_animation(maidroid.animations.walk, 15, 0)
|
||||||
self.time_count = 0
|
self.time_count = 0
|
||||||
_aux.change_dir(self)
|
_aux.change_dir(self)
|
||||||
else
|
else
|
||||||
self.time_count = self.time_count + 1
|
self.time_count = self.time_count + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
self.preposition = pos
|
||||||
end
|
end
|
||||||
self.preposition = pos
|
})
|
||||||
end
|
|
||||||
})
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user