scrolls.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. --scrolls
  2. minetest.register_craftitem("witchcraft:scroll_day", {
  3. description = "Scroll of day",
  4. inventory_image = "witchcraft_scroll.png^witchcraft_sun_over.png",
  5. stack_max = 1,
  6. on_use = function(item)
  7. minetest.set_timeofday(0.5)
  8. item:take_item()
  9. return item
  10. end,
  11. })
  12. minetest.register_craftitem("witchcraft:scroll_night", {
  13. description = "Scroll of night",
  14. inventory_image = "witchcraft_scroll.png^witchcraft_moon_over.png",
  15. stack_max = 1,
  16. on_use = function(item)
  17. minetest.set_timeofday(0)
  18. item:take_item()
  19. return item
  20. end,
  21. })
  22. if minetest.get_modpath("pmobs")then
  23. minetest.register_craftitem("witchcraft:scroll_wild", {
  24. description = "Scroll of Wild",
  25. inventory_image = "witchcraft_scroll.png^witchcraft_dark_over.png",
  26. stack_max = 1,
  27. on_use = function(item, placer)
  28. local pos = placer:getpos();
  29. minetest.env:add_entity(pos, "pmobs:dog")
  30. item:take_item()
  31. return item
  32. end,
  33. })
  34. end
  35. minetest.register_craftitem("witchcraft:scroll_fireball", {
  36. description = "Scroll of fireball",
  37. inventory_image = "witchcraft_scroll.png^witchcraft_fire_over.png",
  38. stack_max = 1,
  39. on_use = function(item, placer, pos)
  40. local dir = placer:get_look_dir();
  41. local playerpos = placer:getpos();
  42. local obj = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:fireball")
  43. local obj2 = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:fireball")
  44. local obj3 = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:fireball")
  45. local obj4 = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:fireball")
  46. obj2:setvelocity({x=dir.x*7+0.5,y=dir.y*7,z=dir.z*7+0.5})
  47. obj3:setvelocity({x=dir.x*7-0.5,y=dir.y*7,z=dir.z*7-0.5})
  48. obj4:setvelocity({x=dir.x*7,y=dir.y*7-0.5,z=dir.z*7})
  49. obj:setvelocity({x=dir.x*7,y=dir.y*7+0.5,z=dir.z*7})
  50. item:take_item()
  51. return item
  52. end,
  53. })
  54. minetest.register_craftitem("witchcraft:scroll_icicle", {
  55. description = "Scroll of icicle",
  56. inventory_image = "witchcraft_scroll.png^witchcraft_ice_over.png",
  57. stack_max = 1,
  58. on_use = function(item, placer, pos)
  59. local dir = placer:get_look_dir();
  60. local playerpos = placer:getpos();
  61. local vec = {x=dir.x*7,y=dir.y*7,z=dir.z*7}
  62. local obj = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:ice")
  63. local obj2 = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+1+dir.z}, "witchcraft:ice")
  64. local obj3 = minetest.env:add_entity({x=playerpos.x+1+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:ice")
  65. obj:setvelocity(vec)
  66. obj2:setvelocity(vec)
  67. obj3:setvelocity(vec)
  68. item:take_item()
  69. return item
  70. end,
  71. })
  72. minetest.register_craftitem("witchcraft:scroll_nature", {
  73. description = "Scroll of nature",
  74. inventory_image = "witchcraft_scroll.png^witchcraft_leaf_over.png",
  75. stack_max = 1,
  76. on_use = function(item, placer, pos)
  77. local dir = placer:get_look_dir();
  78. local playerpos = placer:getpos();
  79. local vec = {x=dir.x*6,y=dir.y*6,z=dir.z*6}
  80. local obj = minetest.env:add_entity({x=playerpos.x+dir.x*1.5,y=playerpos.y+1.5+dir.y,z=playerpos.z+0+dir.z}, "witchcraft:tree")
  81. obj:setvelocity(vec)
  82. item:take_item()
  83. return item
  84. end,
  85. })
  86. minetest.register_craftitem("witchcraft:scroll", {
  87. description = "Blank Scroll",
  88. inventory_image = "witchcraft_scroll.png",
  89. })
  90. minetest.register_craftitem("witchcraft:scroll_recipe", {
  91. description = "Recipe Scroll",
  92. inventory_image = "witchcraft_scroll.png^witchcraft_writing_over.png",
  93. on_use = function(itemstack, user, pointed_thing)
  94. local formspec = "size[10,9]"..
  95. "background[-0.6,-0.5;11.5,10.4;witchcraft_recipes.png]";
  96. minetest.show_formspec(user:get_player_name(), "witchcraft:scroll", formspec);
  97. end,
  98. })
  99. if minetest.get_modpath("pmobs")then
  100. minetest.register_craft({
  101. output = 'witchcraft:scroll_wild',
  102. recipe = {
  103. {'mobs:meat_raw'},
  104. {'witchcraft:scroll'},
  105. }
  106. })
  107. end
  108. minetest.register_craft({
  109. output = 'witchcraft:scroll',
  110. recipe = {
  111. {'default:paper', 'default:paper', ''},
  112. {'default:paper', 'default:paper', ''},
  113. }
  114. })
  115. minetest.register_craft({
  116. output = 'witchcraft:scroll_recipe',
  117. recipe = {
  118. {'dye:black'},
  119. {'witchcraft:scroll'},
  120. }
  121. })
  122. minetest.register_craft({
  123. output = 'witchcraft:scroll_icicle',
  124. recipe = {
  125. {'default:ice'},
  126. {'default:diamond'},
  127. {'witchcraft:scroll'},
  128. }
  129. })
  130. minetest.register_craft({
  131. output = 'witchcraft:scroll_fireball',
  132. recipe = {
  133. {'default:obsidian_shard'},
  134. {'default:diamond'},
  135. {'witchcraft:scroll'},
  136. }
  137. })
  138. minetest.register_craft({
  139. output = 'witchcraft:scroll_nature',
  140. recipe = {
  141. {'default:leaves'},
  142. {'default:diamond'},
  143. {'witchcraft:scroll'},
  144. }
  145. })
  146. minetest.register_craft({
  147. output = 'witchcraft:scroll_day',
  148. recipe = {
  149. {'default:torch'},
  150. {'default:diamond'},
  151. {'witchcraft:scroll'},
  152. }
  153. })
  154. minetest.register_craft({
  155. output = 'witchcraft:scroll_night',
  156. recipe = {
  157. {'default:coal_lump'},
  158. {'default:diamond'},
  159. {'witchcraft:scroll'},
  160. }
  161. })
  162. --scroll powers
  163. minetest.register_entity("witchcraft:fireball", {
  164. textures = {"tnt_boom.png"},
  165. velocity = 0.1,
  166. damage = 2,
  167. collisionbox = {0, 0, 0, 0, 0, 0},
  168. on_step = function(self, obj, pos)
  169. local remove = minetest.after(2, function()
  170. self.object:remove()
  171. end)
  172. local pos = self.object:getpos()
  173. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  174. for k, obj in pairs(objs) do
  175. if obj:get_luaentity() ~= nil then
  176. if obj:get_luaentity().name ~= "witchcraft:fireball" and obj:get_luaentity().name ~= "__builtin:item" then
  177. obj:punch(self.object, 1.0, {
  178. full_punch_interval=1.0,
  179. damage_groups={fleshy=3},
  180. }, nil)
  181. self.object:remove()
  182. end
  183. end
  184. end
  185. for dx=0,1 do
  186. for dy=0,1 do
  187. for dz=0,1 do
  188. local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
  189. local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
  190. local n = minetest.env:get_node(p).name
  191. if n ~= "witchcraft:fireball" and n ~="default:dirt_with_grass" and n ~="default:dirt_with_dry_grass" and n ~="default:stone" then
  192. if minetest.registered_nodes[n].groups.flammable --[[or math.random(1, 100) <= 1]] then
  193. minetest.env:set_node(t, {name="fire:basic_flame"})
  194. self.object:remove()
  195. return
  196. end
  197. end
  198. end
  199. end
  200. end
  201. hit_node = function(self, pos, node)
  202. -- local pos = self.object:getpos()
  203. for dx=-4,4 do
  204. for dy=-4,4 do
  205. for dz=-4,4 do
  206. local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
  207. local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
  208. local n = minetest.env:get_node(pos).name
  209. if math.random(1, 50) <= 35 then
  210. minetest.env:remove_node(p)
  211. end
  212. if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <=5 then
  213. minetest.env:set_node(t, {name="fire:basic_flame"})
  214. end
  215. end
  216. end
  217. end
  218. end
  219. local apos = self.object:getpos()
  220. local vec = self.object:getvelocity()
  221. local part = minetest.add_particlespawner(
  222. 6, --amount
  223. 0.3, --time
  224. {x=apos.x-0.3, y=apos.y-0.3, z=apos.z-0.3}, --minpos
  225. {x=apos.x+0.3, y=apos.y+0.3, z=apos.z+0.3}, --maxpos
  226. {x=-0, y=-0, z=-0}, --minvel
  227. {x=0, y=0, z=0}, --maxvel
  228. {x=0,y=-0.5,z=0}, --minacc
  229. {x=-vec.x,y=-vec.y,z=-vec.z}, --maxacc
  230. 0.1, --minexptime
  231. 0.3, --maxexptime
  232. 1, --minsize
  233. 2, --maxsize
  234. false, --collisiondetection
  235. "witchcraft_flame.png" --texture
  236. )
  237. end,
  238. })
  239. minetest.register_entity("witchcraft:tree", {
  240. textures = {"witchcraft_skin.png"},
  241. velocity = 1,
  242. damage = 2,
  243. collisionbox = {0, 0, 0, 0, 0, 0},
  244. on_step = function(self, obj, pos)
  245. local remove = minetest.after(2, function()
  246. self.object:remove()
  247. end)
  248. local pos = self.object:getpos()
  249. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  250. for k, obj in pairs(objs) do
  251. if obj:get_luaentity() ~= nil then
  252. if obj:get_luaentity().name ~= "witchcraft:tree" and obj:get_luaentity().name ~= "__builtin:item" then
  253. obj:remove()
  254. local treepos = self.object:getpos()
  255. default.grow_new_jungle_tree(treepos)
  256. self.object:remove()
  257. end
  258. end
  259. end
  260. for dx=0,1 do
  261. for dy=0,1 do
  262. for dz=0,1 do
  263. local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
  264. local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
  265. local n = minetest.env:get_node(p).name
  266. if n ~= "witchcraft:tree" and n ~="air" then
  267. local treepos = self.object:getpos()
  268. default.grow_new_jungle_tree(treepos)
  269. self.object:remove()
  270. elseif n == "default:wood" or n =="default:tree" or n =="default:dirt_with_grass" or n =="default:dirt_with_dry_grass" then
  271. self.hit_node(self, pos, node)
  272. self.object:remove()
  273. return
  274. end
  275. end
  276. end
  277. end
  278. hit_node = function(self, pos, node)
  279. local treepos = self.object:getpos()
  280. default.grow_new_jungle_tree(treepos)
  281. end
  282. local apos = self.object:getpos()
  283. local part = minetest.add_particlespawner(
  284. 6, --amount
  285. 0.3, --time
  286. {x=apos.x-0.3, y=apos.y-0.3, z=apos.z-0.3}, --minpos
  287. {x=apos.x+0.3, y=apos.y+0.3, z=apos.z+0.3}, --maxpos
  288. {x=-0, y=-0, z=-0}, --minvel
  289. {x=0, y=0, z=0}, --maxvel
  290. {x=0,y=-0.5,z=0}, --minacc
  291. {x=0.5,y=0.5,z=0.5}, --maxacc
  292. 0.1, --minexptime
  293. 0.3, --maxexptime
  294. 1, --minsize
  295. 2, --maxsize
  296. false, --collisiondetection
  297. "witchcraft_leaf_over.png" --texture
  298. )
  299. end,
  300. })
  301. minetest.register_entity("witchcraft:ice", {
  302. visual="sprite",
  303. visual_size={x=1,y=1},
  304. physical=false,
  305. textures={"witchcraft_ice.png"},
  306. velocity = 1,
  307. rotate = 90,
  308. auto_rotate = true,
  309. damage = 2,
  310. collisionbox = {0, 0, 0, 0, 0, 0},
  311. on_step = function(self, obj, pos)
  312. local remove = minetest.after(10, function()
  313. self.object:remove()
  314. end)
  315. local pos = self.object:getpos()
  316. local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
  317. for k, obj in pairs(objs) do
  318. if obj:get_luaentity() ~= nil then
  319. if obj:get_luaentity().name ~= "witchcraft:ice" and obj:get_luaentity().name ~= "__builtin:item" then
  320. obj:punch(self.object, 1.0, {
  321. full_punch_interval=1.0,
  322. damage_groups={fleshy=1},
  323. }, nil)
  324. self.object:remove()
  325. end
  326. end
  327. for dx=0,1 do
  328. for dy=0,1 do
  329. for dz=0,1 do
  330. local p = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
  331. local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
  332. local n = minetest.env:get_node(p).name
  333. if n == "default:water_source" or n =="default:river_water_source" then
  334. local pos = self.object:getpos()
  335. minetest.set_node(pos, {name="default:ice"})
  336. self.object:remove()
  337. elseif n ~= "air" then
  338. local velo = self.object:getvelocity()
  339. self.object:setvelocity({x=velo.x*-1, y=velo.y*0, z=velo.z*1})
  340. --self.object:remove()
  341. return
  342. end
  343. end
  344. end
  345. end
  346. local apos = self.object:getpos()
  347. local part = minetest.add_particlespawner(
  348. 10, --amount
  349. 0.3, --time
  350. {x=apos.x-0.3, y=apos.y-0.3, z=apos.z-0.3}, --minpos
  351. {x=apos.x+0.3, y=apos.y+0.3, z=apos.z+0.3}, --maxpos
  352. {x=-0, y=-0, z=-0}, --minvel
  353. {x=0, y=0, z=0}, --maxvel
  354. {x=0,y=-0.5,z=0}, --minacc
  355. {x=0.5,y=0.5,z=0.5}, --maxacc
  356. 0.1, --minexptime
  357. 0.3, --maxexptime
  358. 0.2, --minsize
  359. 0.5, --maxsize
  360. false, --collisiondetection
  361. "witchcraft_light_over.png" --texture
  362. )
  363. end
  364. end
  365. })