bobber.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. -----------------------------------------------------------------------------------------------
  2. -- Fishing - Mossmanikin's version - Bobber 0.1.7
  3. -- License (code & textures): WTFPL
  4. -- Contains code from: fishing (original), mobs, throwing, volcano
  5. -- Supports: 3d_armor, animal_clownfish, animal_fish_blue_white, animal_rat, flowers_plus, mobs, seaplants
  6. -----------------------------------------------------------------------------------------------
  7. local PoLeWeaR = (65535/(30-(math.random(15, 29))))
  8. local BooTSWear = (2000*(math.random(20, 29)))
  9. -- Here's what you can catch
  10. local CaTCH = {
  11. -- MoD iTeM WeaR MeSSaGe ("You caught "..) GeTBaiTBack NRMiN CHaNCe (../120)
  12. {"fishing", "fish_raw", 0, "a Fish.", false, 1, 60},
  13. {"animal_clownfish", "clownfish", 0, "a Clownfish.", false, 61, 10},
  14. {"animal_fish_blue_white", "fish_blue_white", 0, "a Blue white fish.", false, 71, 10},
  15. {"default", "stick", 0, "a Twig.", true, 81, 2},
  16. {"mobs", "rat", 0, "a Rat.", false, 83, 1},
  17. {"animal_rat", "rat", 0, "a Rat.", false, 84, 1},
  18. {"", "rat", 0, "a Rat.", false, 85, 1},
  19. {"flowers_plus", "seaweed", 0, "some Seaweed.", true, 86, 20},
  20. {"seaplants", "kelpgreen", 0, "a Green Kelp.", true, 106, 10},
  21. {"farming", "string", 0, "a String.", true, 116, 2},
  22. {"fishing", "pole", PoLeWeaR, "an old Fishing Pole.", true, 118, 2},
  23. {"3d_armor", "boots_wood", BooTSWear, "some very old Boots.", true, 120, 1},
  24. {"trunks", "twig_1", 0, "a Twig.", true, 121, 2},
  25. }
  26. minetest.register_alias("flowers_plus:seaweed", "flowers:seaweed") -- exception
  27. local PLaNTS = {
  28. -- MoD* iTeM MeSSaGe ("You caught "..)
  29. {"flowers", "waterlily", "a Waterlily." },
  30. {"flowers", "waterlily_225", "a Waterlily." },
  31. {"flowers", "waterlily_45", "a Waterlily." },
  32. {"flowers", "waterlily_675", "a Waterlily." },
  33. {"flowers", "waterlily_s1", "a Waterlily." },
  34. {"flowers", "waterlily_s2", "a Waterlily." },
  35. {"flowers", "waterlily_s3", "a Waterlily." },
  36. {"flowers", "waterlily_s4", "a Waterlily." },
  37. {"flowers", "seaweed", "some Seaweed."},
  38. {"flowers", "seaweed_2", "some Seaweed."},
  39. {"flowers", "seaweed_3", "some Seaweed."},
  40. {"flowers", "seaweed_4", "some Seaweed."},
  41. {"trunks", "twig_1", "a Twig." },
  42. {"trunks", "twig_2", "a Twig." },
  43. {"trunks", "twig_3", "a Twig." },
  44. {"trunks", "twig_4", "a Twig." },
  45. {"trunks", "twig_5", "a Twig." },
  46. {"trunks", "twig_7", "a Twig." },
  47. {"trunks", "twig_8", "a Twig." },
  48. {"trunks", "twig_9", "a Twig." },
  49. {"trunks", "twig_10", "a Twig." },
  50. {"trunks", "twig_11", "a Twig." },
  51. {"trunks", "twig_12", "a Twig." },
  52. {"trunks", "twig_13", "a Twig." },
  53. }
  54. -- *as used in the node name
  55. local MoBS = { -- not in use
  56. -- iTeM MeSSaGe ("You caught "..)
  57. {"animal_clownfish:clownfish", "a Clownfish." },
  58. {"animal_fish_blue_white:fish_blue_white", "a Blue white fish."},
  59. }
  60. minetest.register_node("fishing:bobber_box", {
  61. drawtype = "nodebox",
  62. node_box = {
  63. type = "fixed",
  64. fixed = {
  65. -- { left, bottom, front, right, top , back}
  66. {-8/16, -8/16, 0, 8/16, 8/16, 0}, -- feathers
  67. {-2/16, -8/16, -2/16, 2/16, -4/16, 2/16}, -- bobber
  68. }
  69. },
  70. tiles = {
  71. "fishing_bobber_top.png",
  72. "fishing_bobber_bottom.png",
  73. "fishing_bobber.png",
  74. "fishing_bobber.png",
  75. "fishing_bobber.png",
  76. "fishing_bobber.png^[transformFX"
  77. }, --
  78. groups = {not_in_creative_inventory=1},
  79. })
  80. local FISHING_BOBBER_ENTITY={
  81. hp_max = 605,
  82. water_damage = 1,
  83. physical = true,
  84. timer = 0,
  85. env_damage_timer = 0,
  86. visual = "wielditem",
  87. visual_size = {x=1/3, y=1/3, z=1/3},
  88. textures = {"fishing:bobber_box"},
  89. -- {left ,bottom, front, right, top , back}
  90. collisionbox = {-2/16, -4/16, -2/16, 2/16, 0/16, 2/16},
  91. view_range = 7,
  92. -- DESTROY BOBBER WHEN PUNCHING IT
  93. on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
  94. local player = puncher:get_player_name()
  95. local inv = puncher:get_inventory()
  96. if MESSAGES == true then minetest.chat_send_player(player, "You didn't catch anything.", false) end -- fish escaped
  97. if not minetest.setting_getbool("creative_mode") then
  98. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  99. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  100. if MESSAGES == true then minetest.chat_send_player(player, "The bait is still there.", false) end -- bait still there
  101. end
  102. end
  103. -- make sound and remove bobber
  104. minetest.sound_play("fishing_bobber1", {
  105. pos = self.object:getpos(),
  106. gain = 0.5,
  107. })
  108. self.object:remove()
  109. end,
  110. -- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
  111. on_rightclick = function (self, clicker)
  112. local item = clicker:get_wielded_item()
  113. local player = clicker:get_player_name()
  114. if item:get_name() == "fishing:pole" then
  115. local inv = clicker:get_inventory()
  116. local say = minetest.chat_send_player
  117. local pos = self.object:getpos()
  118. -- catch visible plant
  119. if minetest.get_node(pos).name ~= "air" then
  120. for i in ipairs(PLaNTS) do
  121. local PLaNT = PLaNTS[i][1]..":"..PLaNTS[i][2]
  122. local MeSSaGe = PLaNTS[i][3]
  123. local DRoP = minetest.registered_nodes[PLaNT].drop
  124. if minetest.get_node(pos).name == PLaNT then
  125. minetest.add_node({x=pos.x, y=pos.y, z=pos.z}, {name="air"})
  126. if inv:room_for_item("main", {name=DRoP, count=1, wear=0, metadata=""}) then
  127. inv:add_item("main", {name=DRoP, count=1, wear=0, metadata=""})
  128. if MESSAGES == true then say(player, "You caught "..MeSSaGe, false) end -- caught Plant
  129. end
  130. if not minetest.setting_getbool("creative_mode") then
  131. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  132. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  133. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there
  134. end
  135. end
  136. end
  137. end
  138. --end
  139. elseif minetest.get_node(pos).name == "air" then
  140. -- catch visible fish and invisible stuff
  141. if self.object:get_hp() <= 300 then
  142. if math.random(1, 100) < FISH_CHANCE then
  143. local chance = math.random(1, 122) -- ><((((º>
  144. for i in pairs(CaTCH) do
  145. local MoD = CaTCH[i][1]
  146. local iTeM = CaTCH[i][2]
  147. local WeaR = CaTCH[i][3]
  148. local MeSSaGe = CaTCH[i][4]
  149. local GeTBaiTBack = CaTCH[i][5]
  150. local NRMiN = CaTCH[i][6]
  151. local CHaNCe = CaTCH[i][7]
  152. local NRMaX = NRMiN + CHaNCe - 1
  153. if chance <= NRMaX and chance >= NRMiN then
  154. if minetest.get_modpath(MoD) ~= nil then
  155. -- remove visible fish, if there
  156. local find_fish = minetest.get_objects_inside_radius({x=pos.x,y=pos.y+0.5,z=pos.z}, 1)
  157. for k, obj in pairs(find_fish) do
  158. if obj:get_luaentity() ~= nil and obj:get_luaentity().name == "animal_fish_blue_white:fish_blue_white" then
  159. MoD = "animal_fish_blue_white"
  160. iTeM = "fish_blue_white"
  161. WeaR = 0
  162. MeSSaGe = "a Blue white fish."
  163. obj:remove()
  164. end
  165. end
  166. -- add (in)visible fish to inventory
  167. if inv:room_for_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""}) then
  168. inv:add_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""})
  169. if MESSAGES == true then say(player, "You caught "..MeSSaGe, false) end -- caught somethin'
  170. end
  171. if not minetest.setting_getbool("creative_mode") then
  172. if GeTBaiTBack == true then
  173. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  174. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  175. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there?
  176. end
  177. end
  178. end
  179. else
  180. if inv:room_for_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""}) then
  181. inv:add_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""})
  182. if MESSAGES == true then say(player, "You caught a Fish.", false) end -- caught Fish
  183. end
  184. end
  185. end
  186. end
  187. else --if math.random(1, 100) > FISH_CHANCE then
  188. if MESSAGES == true then say(player, "Your fish escaped.", false) end -- fish escaped
  189. end
  190. end
  191. if self.object:get_hp() > 300 and minetest.get_node(pos).name == "air" then
  192. if MESSAGES == true then say(player, "You didn't catch anything.", false) end -- fish escaped
  193. if not minetest.setting_getbool("creative_mode") then
  194. if math.random(1, 2) == 1 then
  195. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  196. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  197. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there
  198. end
  199. end
  200. end
  201. end
  202. end
  203. end
  204. -- weither player has fishing pole or not
  205. -- make sound and remove bobber
  206. minetest.sound_play("fishing_bobber1", {
  207. pos = self.object:getpos(),
  208. gain = 0.5,
  209. })
  210. self.object:remove()
  211. end,
  212. -- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
  213. on_step = function(self, dtime)
  214. local pos = self.object:getpos()
  215. if BOBBER_CHECK_RADIUS > 0 then
  216. local objs = minetest.get_objects_inside_radius(pos, BOBBER_CHECK_RADIUS)
  217. for k, obj in pairs(objs) do
  218. if obj:get_luaentity() ~= nil then
  219. if obj:get_luaentity().name == "fishing:bobber_entity" then
  220. if obj:get_luaentity() ~= self then
  221. self.object:remove()
  222. end
  223. end
  224. end
  225. end
  226. end
  227. if math.random(1, 4) == 1 then
  228. self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
  229. end
  230. for _,player in pairs(minetest.get_connected_players()) do
  231. local s = self.object:getpos()
  232. local p = player:getpos()
  233. local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
  234. if dist > self.view_range then
  235. -- make sound and remove bobber
  236. minetest.sound_play("fishing_bobber1", {
  237. pos = self.object:getpos(),
  238. gain = 0.5,
  239. })
  240. self.object:remove()
  241. end
  242. end
  243. if self.object:get_hp() > 310 then
  244. local find_fish = minetest.get_objects_inside_radius({x=pos.x,y=pos.y+0.5,z=pos.z}, 1)
  245. for k, obj in pairs(find_fish) do
  246. if obj:get_luaentity() ~= nil then
  247. if obj:get_luaentity().name == "animal_fish_blue_white:fish_blue_white" then
  248. if math.random(1, 30) == 1 then
  249. self.object:set_hp(310)
  250. end
  251. end
  252. end
  253. end
  254. end
  255. local do_env_damage = function(self)
  256. self.object:set_hp(self.object:get_hp()-self.water_damage)
  257. if self.object:get_hp() == 600 then
  258. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  259. elseif self.object:get_hp() == 595 then
  260. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  261. elseif self.object:get_hp() == 590 then
  262. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  263. elseif self.object:get_hp() == 585 then
  264. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  265. self.object:set_hp(self.object:get_hp()-(math.random(1, 275)))
  266. elseif self.object:get_hp() == 300 then
  267. minetest.sound_play("fishing_bobber1", {
  268. pos = self.object:getpos(),
  269. gain = 0.5,
  270. })
  271. minetest.add_particlespawner(30, 0.5, -- for how long (?) -- Particles on splash
  272. {x=pos.x,y=pos.y-0.0625,z=pos.z}, {x=pos.x,y=pos.y,z=pos.z}, -- position min, pos max
  273. {x=-2,y=-0.0625,z=-2}, {x=2,y=3,z=2}, -- velocity min, vel max
  274. {x=0,y=-9.8,z=0}, {x=0,y=-9.8,z=0},
  275. 0.3, 1.2,
  276. 0.25, 0.5, -- min size, max size
  277. false, "default_snow.png")
  278. self.object:moveto({x=pos.x,y=pos.y-0.0625,z=pos.z})
  279. elseif self.object:get_hp() == 295 then
  280. self.object:moveto({x=pos.x,y=pos.y+0.0625,z=pos.z})
  281. elseif self.object:get_hp() == 290 then
  282. self.object:moveto({x=pos.x,y=pos.y+0.0625,z=pos.z})
  283. elseif self.object:get_hp() == 285 then
  284. self.object:moveto({x=pos.x,y=pos.y-0.1,z=pos.z})
  285. elseif self.object:get_hp() < 284 then
  286. self.object:moveto({x=pos.x+(0.001*(math.random(-8, 8))),y=pos.y,z=pos.z+(0.001*(math.random(-8, 8)))})
  287. self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/1440*math.pi))
  288. elseif self.object:get_hp() == 0 then
  289. -- make sound and remove bobber
  290. minetest.sound_play("fishing_bobber1", {
  291. pos = self.object:getpos(),
  292. gain = 0.5,
  293. })
  294. self.object:remove()
  295. end
  296. end
  297. do_env_damage(self)
  298. end,
  299. }
  300. minetest.register_entity("fishing:bobber_entity", FISHING_BOBBER_ENTITY)