mirror of
https://github.com/tacigar/maidroid.git
synced 2025-01-10 16:20:19 +01:00
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(main_invname, main_invsize)
|
||||||
inv:set_size(module_invname, module_invsize)
|
inv:set_size(module_invname, module_invsize)
|
||||||
if self.module then self.module.initialize(self) end
|
|
||||||
-- process staticdata
|
-- process staticdata
|
||||||
if staticdata ~= "" then
|
if staticdata ~= "" then
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
local stack = ItemStack(data.inv.module)
|
if data.inv.module ~= "" then
|
||||||
stack:set_count(1)
|
module_stack = ItemStack(data.inv.module)
|
||||||
inv:add_item(module_invname, stack)
|
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
|
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
|
||||||
|
if self.module then self.module.initialize(self)
|
||||||
|
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
|
||||||
@ -119,7 +124,8 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
local inv = _aux.get_maidroid_inventory(self)
|
local inv = _aux.get_maidroid_inventory(self)
|
||||||
local staticdata = {}
|
local staticdata = {}
|
||||||
staticdata.inv = {}
|
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 = {}
|
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()
|
||||||
@ -140,20 +146,4 @@ function maidroid.register_maidroid(product_name, def)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
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
|
end
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
@ -45,9 +45,9 @@ function maidroid.modules._aux.get_upper_pos(vec)
|
|||||||
end
|
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 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)
|
local all_objects = minetest.get_objects_inside_radius(pos, radius)
|
||||||
for _, obj in ipairs(all_objects) do
|
for _, obj in ipairs(all_objects) do
|
||||||
if not obj:is_player() and obj:get_luaentity() then
|
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 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)
|
||||||
|
obj:get_luaentity().itemstring = ""
|
||||||
|
obj:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,6 +78,10 @@ maidroid.register_module("maidroid:farming_module", {
|
|||||||
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
|
||||||
|
-- 種を広い集める
|
||||||
|
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||||
|
return minetest.get_item_group(itemstring, "seed") > 0
|
||||||
|
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
|
||||||
|
@ -80,6 +80,10 @@ maidroid.register_module("maidroid:lumberjack", {
|
|||||||
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
|
||||||
|
-- 苗木を拾い集める
|
||||||
|
_aux.pickup_item(self, 1.5, function(itemstring)
|
||||||
|
return util.table_find_value(target_sapling_list, itemstring)
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user