nssm/rainbow_staff.lua

64 lines
1.3 KiB
Lua
Raw Normal View History

2022-09-28 19:01:53 +01:00
-- rainbow!
2018-08-09 11:36:34 +01:00
2018-08-08 10:56:14 +01:00
minetest.register_entity("nssm:rainbow", {
textures = {"transparent.png"},
velocity = 10,
hp_max = 50,
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
on_step = function (self, pos, node, dtime)
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
self.timer = self.timer or os.time()
2018-08-08 12:20:07 +01:00
local pos = self.object:get_pos()
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
if minetest.is_protected(pos, "") then
return
end
if os.time() - self.timer > 10 then
2022-09-27 19:26:58 +01:00
minetest.set_node(pos, {name = "nyancat:nyancat"})
2018-08-08 10:56:14 +01:00
self.object:remove()
end
if minetest.get_node(pos) then
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
local n = minetest.get_node(pos).name
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
if n ~= "nyancat:nyancat_rainbow" then
2022-09-28 19:01:53 +01:00
2022-09-27 19:26:58 +01:00
if n == "air" then
minetest.set_node(pos, {name = "nyancat:nyancat_rainbow"})
2018-08-08 10:56:14 +01:00
else
2022-09-27 19:26:58 +01:00
minetest.chat_send_all("Nome:" .. n)
minetest.set_node(pos, {name = "nyancat:nyancat"})
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
self.object:remove()
end
end
end
end
})
minetest.register_tool("nssm:rainbow_staff", {
description = "Rainbow Staff",
inventory_image = "rainbow_staff.png",
2022-10-02 08:08:19 +01:00
groups = {not_in_creative_inventory = 1},
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
on_use = function(itemstack, placer, pointed_thing)
2022-09-28 19:01:53 +01:00
2022-09-27 19:26:58 +01:00
local dir = placer:get_look_dir()
local playerpos = placer:get_pos()
local obj = minetest.add_entity({
x = playerpos.x + dir.x,
y = playerpos.y + 2 + dir.y,
z = playerpos.z + dir.z
}, "nssm:rainbow")
2022-09-28 19:01:53 +01:00
2022-09-27 19:26:58 +01:00
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
2022-09-28 19:01:53 +01:00
2018-08-08 12:20:07 +01:00
obj:set_velocity(vec)
2022-09-28 19:01:53 +01:00
2018-08-08 10:56:14 +01:00
return itemstack
2022-09-28 19:01:53 +01:00
end
2018-08-08 10:56:14 +01:00
})