forked from mtcontrib/maidroid
Update
This commit is contained in:
parent
e7e158052f
commit
bb590d0141
32
api.lua
32
api.lua
@ -87,19 +87,24 @@ function maidroid.register_maidroid(product_name, def)
|
||||
})
|
||||
inv:set_size(main_invname, main_invsize)
|
||||
inv:set_size(module_invname, module_invsize)
|
||||
if self.module then self.module.initialize(self) end
|
||||
-- process staticdata
|
||||
if staticdata ~= "" then
|
||||
local data = minetest.deserialize(staticdata)
|
||||
local stack = ItemStack(data.inv.module)
|
||||
stack:set_count(1)
|
||||
inv:add_item(module_invname, stack)
|
||||
if data.inv.module ~= "" then
|
||||
module_stack = ItemStack(data.inv.module)
|
||||
module_stack:set_count(1)
|
||||
inv:add_item(module_invname, module_stack)
|
||||
self.module = maidroid.registered_modules[data.inv.module]
|
||||
end
|
||||
for _, item in ipairs(data.inv.main) do
|
||||
local itemstack = ItemStack(item.name)
|
||||
itemstack:set_count(item.count)
|
||||
inv:add_item(main_invname, itemstack)
|
||||
end
|
||||
end
|
||||
-- initialize module
|
||||
if self.module then self.module.initialize(self)
|
||||
else self.object:setvelocity{x = 0, y = 0, z = 0} end
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
if self.module then self.module.on_step(self, dtime) end
|
||||
@ -119,7 +124,8 @@ function maidroid.register_maidroid(product_name, def)
|
||||
local inv = _aux.get_maidroid_inventory(self)
|
||||
local staticdata = {}
|
||||
staticdata.inv = {}
|
||||
staticdata.inv.module = inv:get_list(module_invname)[1]:get_name()
|
||||
local module_name = inv:get_list(module_invname)[1]:get_name()
|
||||
staticdata.inv.module = module_name or ""
|
||||
staticdata.inv.main = {}
|
||||
for _, item in ipairs(inv:get_list(main_invname)) do
|
||||
local count = item:get_count()
|
||||
@ -140,20 +146,4 @@ function maidroid.register_maidroid(product_name, def)
|
||||
return itemstack
|
||||
end
|
||||
})
|
||||
-- 野生のmaidroidのentityの登録
|
||||
minetest.register_entity(product_name.."_wild", {
|
||||
hp_max = def.hp_max or 1,
|
||||
physical = true,
|
||||
weight = def.weight or 5,
|
||||
on_activate = function(self, staticdata)
|
||||
end,
|
||||
on_step = function(self, dtime)
|
||||
end,
|
||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||
end,
|
||||
on_rightclick = function(self, clicker)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
|
@ -45,9 +45,9 @@ function maidroid.modules._aux.get_upper_pos(vec)
|
||||
end
|
||||
|
||||
-- 落ちているアイテムを拾う
|
||||
function maidroid.modules._aux.get_item(self, radius, target_pred)
|
||||
function maidroid.modules._aux.pickup_item(self, radius, target_pred)
|
||||
local pos = self.object:getpos()
|
||||
local pred = target_list or (function() return true end)
|
||||
local pred = target_list or (function(itemstring) return true end)
|
||||
local all_objects = minetest.get_objects_inside_radius(pos, radius)
|
||||
for _, obj in ipairs(all_objects) do
|
||||
if not obj:is_player() and obj:get_luaentity() then
|
||||
@ -57,6 +57,9 @@ function maidroid.modules._aux.get_item(self, radius, target_pred)
|
||||
local inv = maidroid._aux.get_maidroid_inventory(self)
|
||||
local stack = ItemStack(itemstring)
|
||||
local leftover = inv:add_item("main", stack)
|
||||
minetest.add_item(obj:getpos(), leftover)
|
||||
obj:get_luaentity().itemstring = ""
|
||||
obj:remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -78,6 +78,10 @@ maidroid.register_module("maidroid:farming_module", {
|
||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
end
|
||||
-- 種を広い集める
|
||||
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||
return minetest.get_item_group(itemstring, "seed") > 0
|
||||
end)
|
||||
elseif self.state == state.punch then
|
||||
if self.time_count >= max_punch_time then
|
||||
if maidroid.util.table_find_value(target_plants_list, forward_node.name) then
|
||||
|
@ -80,6 +80,10 @@ maidroid.register_module("maidroid:lumberjack", {
|
||||
self.object:set_animation(maidroid.animations.mine, 15, 0)
|
||||
self.object:setvelocity{x = 0, y = 0, z = 0}
|
||||
end
|
||||
-- 苗木を拾い集める
|
||||
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||
return util.table_find_value(target_sapling_list, itemstring)
|
||||
end)
|
||||
elseif self.state == state.punch then
|
||||
if self.time_count >= max_punch_time then
|
||||
local punch_flag, forward_upper_pos, forward_upper_node
|
||||
|
Loading…
Reference in New Issue
Block a user