lb_special.lua 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. local S = lucky_block.intllib
  2. -- custom function (punches player with 5 damage)
  3. local function punchy(pos, player)
  4. player:punch(player, 1.0, {
  5. full_punch_interval = 1.0,
  6. damage_groups = {fleshy = 5}
  7. }, nil)
  8. minetest.sound_play("player_damage", {pos = pos, gain = 1.0}, true)
  9. minetest.chat_send_player(player:get_player_name(),
  10. lucky_block.green .. S("Stop hitting yourself!"))
  11. end
  12. -- custom function (pint sized player) and potion with recipe
  13. local function pint(pos, player)
  14. player:set_properties({
  15. visual_size = {x = 0.5, y = 0.5},
  16. collisionbox = {-0.15, 0.0, -0.15, 0.15, .85, 0.15},
  17. eye_height = 0.73,
  18. stepheight = 0.3
  19. })
  20. minetest.chat_send_player(player:get_player_name(),
  21. lucky_block.green .. S("Pint Sized Player!"))
  22. minetest.sound_play(lucky_block.snd_pop2, {pos = pos, gain = 1.0}, true)
  23. minetest.after (180, function(player, pos) -- 3 minutes
  24. if player and player:is_player() then
  25. player:set_properties({
  26. visual_size = {x = 1.0, y = 1.0},
  27. collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
  28. eye_height = 1.47,
  29. stepheight = 0.6
  30. })
  31. minetest.sound_play(lucky_block.snd_pop2, {
  32. pos = player:get_pos(), gain = 1.0}, true)
  33. end
  34. end, player)
  35. end
  36. -- pint sized potion item
  37. minetest.register_craftitem("lucky_block:pint_sized_potion", {
  38. description = S("Pint Sized Potion (DRINK ME)"),
  39. inventory_image = "lucky_pint_sized_potion.png",
  40. groups = {vessel = 1},
  41. on_use = function(itemstack, user, pointed_thing)
  42. itemstack:take_item()
  43. local pos = user:get_pos()
  44. local inv = user:get_inventory()
  45. local item = "vessels:glass_bottle"
  46. if inv:room_for_item("main", {name = item}) then
  47. inv:add_item("main", item)
  48. else
  49. minetest.add_item(pos, {name = item})
  50. end
  51. pint(pos, user)
  52. return itemstack
  53. end
  54. })
  55. -- pint sized potion recipe (default)
  56. if lucky_block.mod_def then
  57. minetest.register_craft({
  58. output = "lucky_block:pint_sized_potion",
  59. recipe = {
  60. {"default:bush_sapling", "flowers:tulip", "default:acacia_bush_sapling"},
  61. {"dye:blue", "default:apple", "dye:cyan"},
  62. {"", "vessels:glass_bottle", ""}
  63. }
  64. })
  65. end
  66. -- custom function (slender player) and potion with recipe
  67. local function slender(pos, player)
  68. player:set_properties({
  69. visual_size = {x = 1.0, y = 1.5},
  70. collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7 + .85, 0.3},
  71. eye_height = 1.47 + 0.73,
  72. stepheight = 0.9
  73. })
  74. minetest.chat_send_player(player:get_player_name(),
  75. lucky_block.green .. S("Slender Player!"))
  76. minetest.sound_play(lucky_block.snd_pop2, {pos = pos, gain = 1.0}, true)
  77. minetest.after (180, function(player, pos) -- 3 minutes
  78. if player and player:is_player() then
  79. player:set_properties({
  80. visual_size = {x = 1.0, y = 1.0},
  81. collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
  82. eye_height = 1.47,
  83. stepheight = 0.6
  84. })
  85. minetest.sound_play(lucky_block.snd_pop2, {
  86. pos = player:get_pos(), gain = 1.0}, true)
  87. end
  88. end, player)
  89. end
  90. -- slender player potion item
  91. minetest.register_craftitem("lucky_block:slender_player_potion", {
  92. description = S("Slender Player Potion (DRINK ME)"),
  93. inventory_image = "lucky_slender_potion.png",
  94. groups = {vessel = 1},
  95. on_use = function(itemstack, user, pointed_thing)
  96. itemstack:take_item()
  97. local pos = user:get_pos()
  98. local inv = user:get_inventory()
  99. local item = "vessels:glass_bottle"
  100. if inv:room_for_item("main", {name = item}) then
  101. inv:add_item("main", item)
  102. else
  103. minetest.add_item(pos, {name = item})
  104. end
  105. slender(pos, user)
  106. return itemstack
  107. end
  108. })
  109. -- slender player potion recipe
  110. if lucky_block.mod_def then
  111. minetest.register_craft({
  112. output = "lucky_block:slender_player_potion",
  113. recipe = {
  114. {"default:bush_sapling", "flowers:rose", "default:pine_bush_sapling"},
  115. {"dye:red", "default:apple", "dye:orange"},
  116. {"", "vessels:glass_bottle", ""}
  117. }
  118. })
  119. end
  120. -- lightning staff
  121. minetest.register_tool("lucky_block:lightning_staff", {
  122. description = S("Lightning Staff"),
  123. inventory_image = "lucky_lightning_staff.png",
  124. range = 10,
  125. groups = {not_in_creative_inventory = 1},
  126. on_use = function(itemstack, user, pointed_thing)
  127. local pos = user:get_pos()
  128. if pointed_thing.type == "object" then
  129. pos = pointed_thing.ref:get_pos()
  130. elseif pointed_thing.type == "node" then
  131. pos = pointed_thing.above
  132. end
  133. if not pos then return end
  134. local bnod = pos and minetest.get_node_or_nil(pos)
  135. local bref = bnod and minetest.registered_items[bnod.name]
  136. if bref and bref.buildable_to == true then
  137. minetest.set_node(pos, {name = "fire:basic_flame"})
  138. end
  139. local radius = 4
  140. local objs = minetest.get_objects_inside_radius(pos, radius)
  141. local obj_pos, dist
  142. -- add temp entity to cause damage
  143. local tmp_ent = minetest.add_entity(pos, "lucky_block:temp")
  144. for n = 1, #objs do
  145. obj_pos = objs[n]:get_pos()
  146. dist = vector.distance(pos, obj_pos)
  147. if dist < 1 then dist = 1 end
  148. local damage = math.floor((4 / dist) * radius)
  149. local ent = objs[n]:get_luaentity()
  150. -- if you blast yourself then delay hurt for bones mod if dead
  151. if objs[n] == user then
  152. minetest.after(0.1, function()
  153. objs[n]:punch(tmp_ent, 1.0, {
  154. full_punch_interval = 1.0,
  155. damage_groups = {fleshy = damage, fire = 1}
  156. }, pos)
  157. end)
  158. else
  159. objs[n]:punch(tmp_ent, 1.0, {
  160. full_punch_interval = 1.0,
  161. damage_groups = {fleshy = damage, fire = 1}
  162. }, pos)
  163. end
  164. end
  165. minetest.add_particle({
  166. pos = {x = pos.x, y = pos.y + 4, z = pos.z},
  167. velocity = {x = 0, y = 0, z = 0},
  168. acceleration = {x = 0, y = 0, z = 0},
  169. expirationtime = 1.0,
  170. collisiondetection = false,
  171. texture = "lucky_lightning.png",
  172. size = 100,
  173. glow = 15
  174. })
  175. minetest.sound_play("lightning", {
  176. pos = pos, gain = 1.0, max_hear_distance = 25}, true)
  177. itemstack:add_wear(65535 / 50) -- 50 uses
  178. return itemstack
  179. end
  180. })
  181. -- custom function (drop player inventory and replace with items and show msg)
  182. local function dropsy(pos, player, def)
  183. local player_inv = player:get_inventory()
  184. pos = player:get_pos() or pos
  185. for i = 1, player_inv:get_size("main") do
  186. local obj = minetest.add_item(pos, player_inv:get_stack("main", i))
  187. if obj then
  188. obj:set_velocity({
  189. x = math.random(-10, 10) / 9,
  190. y = 5,
  191. z = math.random(-10, 10) / 9
  192. })
  193. end
  194. player_inv:set_stack("main", i, def.item)
  195. end
  196. minetest.chat_send_player(player:get_player_name(), lucky_block.green .. S(def.msg))
  197. end
  198. local tex = lucky_block.mod_mcl and "default_glass.png" or "default_obsidian_glass.png^[brighten"
  199. -- void mirror block (place to see through solid walls)
  200. minetest.register_node("lucky_block:void_mirror", {
  201. description = S("Void Mirror (Place to see through solid walls during daytime)"),
  202. drawtype = "normal",
  203. tiles = {tex},
  204. use_texture_alpha = "clip",
  205. groups = {handy = 1, snappy = 3, not_in_creative_inventory = 1},
  206. sounds = lucky_block.snd_glass,
  207. _mcl_hardness = 0.6
  208. })
  209. -- Troll item drop
  210. local function fake_items(pos, player, def)
  211. for n = 1, 25 do
  212. minetest.add_particle({
  213. time = 15,
  214. pos = {
  215. x = pos.x + math.random(-20, 20) / 10,
  216. y = pos.y,
  217. z = pos.z + math.random(-20, 20) / 10
  218. },
  219. velocity = {x = 0, y = 2, z = 0},
  220. acceleration = {x = 0, y = -10, z = 0},
  221. expirationtime = 4,
  222. maxsize = 4,
  223. texture = def.tex,
  224. glow = 2,
  225. size = 5,
  226. collisiondetection = true,
  227. vertical = true
  228. })
  229. end
  230. minetest.chat_send_player(player:get_player_name(),
  231. lucky_block.green .. S("Wow! So many faux " .. def.txt .. "!"))
  232. end
  233. -- Void Pick (disable for mineclone since it has silk touch tools)
  234. if not lucky_block.mod_mcl then
  235. local old_handle_node_drops = minetest.handle_node_drops
  236. function minetest.handle_node_drops(pos, drops, digger)
  237. -- are we holding Crystal Shovel?
  238. if not digger
  239. or digger:get_wielded_item():get_name() ~= "lucky_block:pick_void" then
  240. return old_handle_node_drops(pos, drops, digger)
  241. end
  242. local nn = minetest.get_node(pos).name
  243. if nn == "default:furnace_active"
  244. or nn:find("xpanes:")
  245. or nn:find("door")
  246. or minetest.get_item_group(nn, "cracky") == 0
  247. or minetest.get_item_group(nn, "no_silktouch") == 1 then
  248. return old_handle_node_drops(pos, drops, digger)
  249. end
  250. return old_handle_node_drops(pos, {ItemStack(nn)}, digger)
  251. end
  252. minetest.register_tool("lucky_block:pick_void", {
  253. description = "Void pick (Silk Touch)",
  254. inventory_image = "lucky_void_pick.png",
  255. wield_image = "lucky_void_pick.png^[transformR90",
  256. tool_capabilities = {
  257. full_punch_interval = 1.2,
  258. max_drop_level = 3,
  259. groupcaps = {
  260. cracky = {
  261. times = {[1] = 2.4, [2] = 1.2, [3] = 0.60},
  262. uses = 20,
  263. maxlevel = 3
  264. }
  265. },
  266. damage_groups = {fleshy = 5},
  267. },
  268. groups = {pickaxe = 1, not_in_creative_inventory = 1},
  269. sound = {breaks = "default_tool_breaks"}
  270. })
  271. end
  272. -- add custom functions and special drops
  273. lucky_block:add_blocks({
  274. {"cus", pint},
  275. {"cus", punchy},
  276. {"cus", slender},
  277. {"dro", {"lucky_block:pint_sized_potion"}, 1},
  278. {"dro", {"lucky_block:slender_player_potion"}, 1},
  279. {"dro", {"lucky_block:void_mirror"}}
  280. })
  281. -- custom items for default mod
  282. if lucky_block.mod_def then
  283. lucky_block:add_blocks({
  284. {"cus", dropsy, {item = "default:dry_shrub", msg = "Dry shrub takeover!"} },
  285. {"cus", fake_items, {tex = "default_diamond.png", txt = "diamonds"} },
  286. {"cus", fake_items, {tex = "default_gold_ingot.png", txt = "ingots"} },
  287. {"cus", fake_items, {tex = "default_mese_crystal.png", txt = "crystals"} },
  288. {"nod", "default:chest", 0, {
  289. {name = "lucky_block:pick_void", max = 1, chance = 7},
  290. {name = "default:stone_with_coal", max = 5},
  291. {name = "default:stone_with_iron", max = 5},
  292. {name = "default:stone_with_copper", max = 5},
  293. {name = "default:stone_with_mese", max = 5},
  294. {name = "default:stone_with_gold", max = 5},
  295. {name = "default:stone_with_diamond", max = 5}
  296. }},
  297. {"nod", "default:chest", 0, {
  298. {name = "default:stick", max = 10},
  299. {name = "default:acacia_bush_stem", max = 10},
  300. {name = "default:bush_stem", max = 10},
  301. {name = "default:pine_bush_stem", max = 10},
  302. {name = "default:grass_1", max = 10},
  303. {name = "default:dry_grass_1", max = 10},
  304. {name = "lucky_block:lightning_staff", max = 1, chance = 10}
  305. }}
  306. })
  307. end