butterfly.lua 1.27 KB
Newer Older
1 2 3 4

--butterflies

minetest.register_abm({
5 6 7
	nodenames = {"flowers:flower_rose", "flowers:flower_tulip",
		"flowers:flower_dandelion_yellow", "flowers:flower_viola",
		"flowers:flower_dandelion_white", "flowers:flower_geranium"},
8 9 10
	interval = 10.0,
	chance = 10,
	action = function(pos, node, active_object_count, active_object_count_wider)
11
		minetest.add_entity({x=pos.x,y=pos.y+0.3,z=pos.z}, "dmobs:butterfly")
12 13 14 15
	end
})

minetest.register_entity("dmobs:butterfly", {
16 17
	visual = "mesh",
	mesh = "butterfly.b3d",
18 19
	physical = true,
	textures = {"dmobs_butterfly.png",},
20
	visual_size = {x=0.3, y=0.3},
21 22 23
	on_activate = function(self)
		num = math.random(1,4)
		self.object:set_properties({textures = {"dmobs_butterfly"..num..".png",},})
24
		self.object:set_animation({x=1, y=10}, 20, 0)
25
		self.object:set_yaw(math.pi+num)
26
		minetest.after(10, function()
27 28 29 30
		self.object:remove()
		end)
	end,
	on_step = function(self)
31 32
		local pos = self.object:get_pos()
		local vec = self.object:get_velocity()
33
		local num = math.random(-math.pi, math.pi)
34 35 36
		self.object:set_yaw(math.pi+num)
		self.object:set_velocity({x=-math.sin(12*pos.y), y=math.cos(12*pos.x), z=-math.sin(12*pos.y)})
		self.object:set_acceleration({x=-math.sin(6*vec.y), y=math.cos(6*vec.x), z=-math.sin(6*vec.y)})
37 38 39
	end,
	collisionbox = {0,0,0,0,0.1,0},
})