mirror of
https://github.com/tacigar/maidroid.git
synced 2025-01-10 08:10:17 +01:00
Add egg entity and moving system
This commit is contained in:
parent
e557b220f1
commit
3529295db1
@ -72,8 +72,10 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
local main_name = main_list[1]:get_name()
|
local main_name = main_list[1]:get_name()
|
||||||
|
|
||||||
if main_name == empty_itemname and (not fuel_list[1]:is_empty()) and (not dye_list[1]:is_empty()) then
|
if main_name == empty_itemname and (not fuel_list[1]:is_empty()) and (not dye_list[1]:is_empty()) then
|
||||||
|
local output = dye_item_map[dye_list[1]:get_name()]
|
||||||
|
|
||||||
meta:set_string("time", 0)
|
meta:set_string("time", 0)
|
||||||
meta:set_string("output", dye_item_map[dye_list[1]:get_name()])
|
meta:set_string("output", output)
|
||||||
|
|
||||||
local fuel_stack = fuel_list[1]
|
local fuel_stack = fuel_list[1]
|
||||||
fuel_stack:take_item()
|
fuel_stack:take_item()
|
||||||
@ -86,7 +88,7 @@ function maidroid_tool.register_writer(nodename, options)
|
|||||||
swap_node(pos, nodename .. "_active")
|
swap_node(pos, nodename .. "_active")
|
||||||
|
|
||||||
if on_activate ~= nil then -- call on_activate callback.
|
if on_activate ~= nil then -- call on_activate callback.
|
||||||
on_activate(pos)
|
on_activate(pos, output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,9 +100,10 @@ do -- register egg writer
|
|||||||
egg_entity:stop_move()
|
egg_entity:stop_move()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_activate(pos)
|
local function on_activate(pos, output)
|
||||||
local egg_entity = get_nearest_egg_entity(pos)
|
local egg_entity = get_nearest_egg_entity(pos)
|
||||||
egg_entity:start_move()
|
egg_entity.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
|
egg_entity:start_move(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_metadata_inventory_put_to_main(pos)
|
local function on_metadata_inventory_put_to_main(pos)
|
||||||
@ -139,56 +140,77 @@ end -- register egg writer
|
|||||||
do -- register a definition of an egg entity
|
do -- register a definition of an egg entity
|
||||||
local function on_activate(self, staticdata)
|
local function on_activate(self, staticdata)
|
||||||
self.object:set_properties{textures={"maidroid:empty_egg"}}
|
self.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
|
self.object:set_properties{automatic_rotate = 1}
|
||||||
|
|
||||||
if staticdata ~= "" then
|
if staticdata ~= "" then
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
|
|
||||||
self.is_moving = data["is_moving"]
|
self.is_moving = data["is_moving"]
|
||||||
|
self.center_position = data["center_position"]
|
||||||
|
self.output = data["output"]
|
||||||
|
self.current_egg = data["current_egg"]
|
||||||
|
|
||||||
|
self.object:set_properties{textures={self.current_egg}}
|
||||||
|
self:initialize(self.center_position)
|
||||||
|
|
||||||
if self.is_moving then
|
if self.is_moving then
|
||||||
self:start_move()
|
self:start_move()
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
self.object:set_properties{textures={"maidroid:empty_egg"}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_move(self)
|
local function start_move(self, output)
|
||||||
self.object:set_properties{automatic_rotate = 1}
|
self.is_moving = true
|
||||||
is_moving = true
|
self.output = output
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stop_move(self)
|
local function stop_move(self)
|
||||||
self.object:set_properties{automatic_rotate = 0}
|
self.object:set_properties{textures={self.output}}
|
||||||
is_moving = false
|
self.is_moving = false
|
||||||
|
self.current_egg = self.output
|
||||||
|
self.output = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_staticdata(self)
|
local function get_staticdata(self)
|
||||||
local data = {
|
local data = {
|
||||||
["is_moving"] = self.is_moving,
|
["is_moving"] = self.is_moving,
|
||||||
["center_position"] = self.center_position,
|
["center_position"] = self.center_position,
|
||||||
|
["output"] = self.output,
|
||||||
|
["current_egg"] = self.current_egg,
|
||||||
}
|
}
|
||||||
return minetest.serialize(data)
|
return minetest.serialize(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_step(self, dtime)
|
local function on_step(self, dtime)
|
||||||
if self.is_moving then
|
|
||||||
|
|
||||||
end
|
|
||||||
-- move up and down.
|
|
||||||
if self.angle >= 360 then
|
if self.angle >= 360 then
|
||||||
self.angle = 0
|
self.angle = 0
|
||||||
else
|
else
|
||||||
self.angle = self.angle + 3
|
self.angle = self.angle + 2
|
||||||
end
|
end
|
||||||
local current_pos = self.object:getpos()
|
|
||||||
|
if self.is_moving then
|
||||||
|
local length = 0.15
|
||||||
|
local new_position = vector.add(self.center_position, {
|
||||||
|
x = length * math.cos(self.angle * math.pi / 180.0),
|
||||||
|
y = math.sin(self.angle * math.pi / 180.0) * 0.035,
|
||||||
|
z = length * math.sin(self.angle * math.pi / 180.0),
|
||||||
|
})
|
||||||
|
self.object:setpos(new_position)
|
||||||
|
else
|
||||||
self.object:setpos(
|
self.object:setpos(
|
||||||
vector.add(current_pos, {
|
vector.add(self.center_position, {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = math.sin(self.angle * math.pi / 180.0) * 0.0025,
|
y = math.sin(self.angle * math.pi / 180.0) * 0.035,
|
||||||
z = 0
|
z = 0
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function initialize(self, pos)
|
local function initialize(self, pos)
|
||||||
|
self.angle = 0
|
||||||
self.center_position = pos
|
self.center_position = pos
|
||||||
local init_pos = vector.add(pos, {x = 0.15, y = 0, z = 0})
|
local init_pos = vector.add(pos, {x = 0.15, y = 0, z = 0})
|
||||||
self.object:setpos(init_pos)
|
self.object:setpos(init_pos)
|
||||||
@ -206,6 +228,8 @@ do -- register a definition of an egg entity
|
|||||||
get_staticdata = get_staticdata,
|
get_staticdata = get_staticdata,
|
||||||
on_step = on_step,
|
on_step = on_step,
|
||||||
initialize = initialize,
|
initialize = initialize,
|
||||||
|
output = "",
|
||||||
|
current_egg = "",
|
||||||
center_position = nil,
|
center_position = nil,
|
||||||
is_moving = false,
|
is_moving = false,
|
||||||
angle = 0,
|
angle = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user