minetest fishing mod
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
8.3KB

  1. -----------------------------------------------------------------------------------------------
  2. -- Fishing - crabman77's version - Bobber
  3. -- Rewrited from original Fishing - Mossmanikin's version - Bobber 0.1.7
  4. -- License (code & textures): WTFPL
  5. -- Contains code from: fishing (original), mobs, throwing, volcano
  6. -- Supports: 3d_armor, animal_clownfish, animal_fish_blue_white, animal_rat, flowers_plus, mobs, seaplants
  7. -----------------------------------------------------------------------------------------------
  8. -- bobber
  9. minetest.register_node("fishing:bobber_box", {
  10. drawtype = "nodebox",
  11. node_box = {
  12. type = "fixed",
  13. fixed = {
  14. -- { left, bottom, front, right, top , back}
  15. {-8/16, -8/16, 0, 8/16, 8/16, 0}, -- feathers
  16. {-2/16, -8/16, -2/16, 2/16, -4/16, 2/16}, -- bobber
  17. },
  18. },
  19. tiles = {
  20. "fishing_bobber_top.png",
  21. "fishing_bobber_bottom.png",
  22. "fishing_bobber.png",
  23. "fishing_bobber.png",
  24. "fishing_bobber.png",
  25. "fishing_bobber.png^[transformFX"
  26. },
  27. groups = {not_in_creative_inventory=1},
  28. })
  29. local FISHING_BOBBER_ENTITY={
  30. physical = true,
  31. timer = 0,
  32. visual = "wielditem",
  33. visual_size = {x=1/3, y=1/3, z=1/3},
  34. textures = {"fishing:bobber_box"},
  35. -- {left ,bottom, front, right, top , back}
  36. collisionbox = {-2/16, -4/16, -2/16, 2/16, 2/16, 2/16},
  37. randomtime = 50,
  38. baitball = 0,
  39. prize = "",
  40. bait = "",
  41. owner = nil,
  42. old_pos = nil,
  43. old_pos2 = nil,
  44. -- DESTROY BOBBER WHEN PUNCHING IT
  45. on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
  46. if not puncher:is_player() then return end
  47. local player_name = puncher:get_player_name()
  48. if player_name ~= self.owner then return end
  49. if fishing_setting.settings["message"] == true then
  50. minetest.chat_send_player(player_name, fishing_setting.func.S("You didn't catch anything."), false)
  51. end
  52. if not fishing_setting.is_creative_mode then
  53. local inv = puncher:get_inventory()
  54. if inv:room_for_item("main", {name=self.bait, count=1, wear=0, metadata=""}) then
  55. inv:add_item("main", {name=self.bait, count=1, wear=0, metadata=""})
  56. if fishing_setting.settings["message"] == true then
  57. minetest.chat_send_player(player_name, fishing_setting.func.S("The bait is still there."), false)
  58. end
  59. end
  60. end
  61. -- make sound and remove bobber
  62. minetest.sound_play("fishing_bobber1", { pos = self.object:get_pos(), gain = 0.5, })
  63. self.object:remove()
  64. end,
  65. -- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
  66. on_rightclick = function (self, clicker)
  67. local item = clicker:get_wielded_item()
  68. local player_name = clicker:get_player_name()
  69. if not player_name or not self.owner then
  70. self.object:remove()
  71. return
  72. end
  73. local inv = clicker:get_inventory()
  74. local pos = self.object:get_pos()
  75. local item_name = item:get_name()
  76. if string.find(item_name, "fishing:pole_") ~= nil then
  77. if player_name ~= self.owner then return end
  78. if self.prize ~= "" then
  79. if math.random(1, 100) <= fishing_setting.settings["escape_chance"] then -- fish escaped
  80. if fishing_setting.settings["message"] == true then
  81. minetest.chat_send_player(player_name, fishing_setting.func.S("Your fish escaped."), false)
  82. end
  83. else
  84. local name = self.prize[1]..":"..self.prize[2]
  85. local desc = self.prize[4]
  86. if fishing_setting.settings["message"] == true then
  87. minetest.chat_send_player(player_name, fishing_setting.func.S("You caught "..desc), false)
  88. end
  89. fishing_setting.func.add_to_trophies(clicker, self.prize[2], desc)
  90. local wear_value = fishing_setting.func.wear_value(self.prize[3])
  91. if inv:room_for_item("main", {name=name, count=1, wear=wear_value, metadata=""}) then
  92. inv:add_item("main", {name=name, count=1, wear=wear_value, metadata=""})
  93. else
  94. minetest.spawn_item(clicker:get_pos(), {name=name, count=1, wear=wear_value, metadata=""})
  95. end
  96. end
  97. else
  98. if not fishing_setting.is_creative_mode then
  99. if inv:room_for_item("main", {name=self.bait, count=1, wear=0, metadata=""}) then
  100. inv:add_item("main", {name=self.bait, count=1, wear=0, metadata=""})
  101. end
  102. end
  103. end
  104. -- weither player has fishing pole or not
  105. minetest.sound_play("fishing_bobber1", { pos = self.object:get_pos(), gain = 0.5, })
  106. self.object:remove()
  107. elseif item_name == "fishing:baitball" then
  108. if not fishing_setting.is_creative_mode then
  109. inv:remove_item("main", "fishing:baitball")
  110. end
  111. self.baitball = 20
  112. --addparticle
  113. minetest.add_particlespawner(30, 0.5, -- for how long (?) -- Particles on splash
  114. {x=pos.x,y=pos.y-0.0625,z=pos.z}, {x=pos.x,y=pos.y,z=pos.z}, -- position min, pos max
  115. {x=-2,y=-0.0625,z=-2}, {x=2,y=3,z=2}, -- velocity min, vel max
  116. {x=0,y=-9.8,z=0}, {x=0,y=-9.8,z=0},
  117. 0.3, 1.2,
  118. 0.25, 0.5, -- min size, max size
  119. false, "fishing_particle_baitball.png")
  120. -- add sound
  121. minetest.sound_play("fishing_baitball", {pos = self.object:get_pos(), gain = 0.2, })
  122. end
  123. end,
  124. -- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
  125. on_step = function(self, dtime)
  126. local pos = self.object:get_pos()
  127. --remove if no owner, no player, owner no in bobber_view_range
  128. if self.owner == nil then self.object:remove(); return end
  129. --remove if not node water
  130. local node = minetest.get_node_or_nil({x=pos.x, y=pos.y-0.5, z=pos.z})
  131. if not node or string.find(node.name, "water_source") == nil then
  132. if fishing_setting.settings["message"] == true then
  133. minetest.chat_send_player(self.owner, fishing_setting.func.S("Haha, Fishing is prohibited outside water!"))
  134. end
  135. self.object:remove()
  136. return
  137. end
  138. local player = minetest.get_player_by_name(self.owner)
  139. if not player then self.object:remove(); return end
  140. local p = player:get_pos()
  141. local dist = ((p.x-pos.x)^2 + (p.y-pos.y)^2 + (p.z-pos.z)^2)^0.5
  142. if dist > fishing_setting.settings["bobber_view_range"] then
  143. minetest.sound_play("fishing_bobber1", {pos = self.object:get_pos(),gain = 0.5,})
  144. self.object:remove()
  145. return
  146. end
  147. --rotate bobber
  148. if math.random(1, 4) == 1 then
  149. self.object:set_yaw(self.object:get_yaw()+((math.random(0,360)-180)/2880*math.pi))
  150. end
  151. self.timer = self.timer + 1
  152. if self.timer < self.randomtime then
  153. -- if fish or others items, move bobber to simulate fish on the line
  154. if self.prize ~= "" and math.random(1,3) == 1 then
  155. if self.old_pos2 == true then
  156. pos.y = pos.y-0.0280
  157. self.object:move_to(pos, false)
  158. self.old_pos2 = false
  159. else
  160. pos.y = pos.y+0.0280
  161. self.object:move_to(pos, false)
  162. self.old_pos2 = true
  163. end
  164. end
  165. return
  166. end
  167. --change item on line
  168. self.timer = 0
  169. if self.prize ~= "" and fishing_setting.have_true_fish and fishing_setting.prizes["true_fish"]["little"][self.prize[1]..":"..self.prize[2]] then
  170. minetest.add_entity({x=pos.x, y=pos.y-1, z=pos.z}, self.prize[1]..":"..self.prize[2])
  171. end
  172. self.prize = ""
  173. self.object:move_to(self.old_pos, false)
  174. --Once the fish are not hungry :), baitball increase hungry + 20%
  175. if math.random(1, 100) > fishing_setting.baits[self.bait]["hungry"] + self.baitball then
  176. --Fish not hungry !(
  177. self.randomtime = math.random(20,60)*10
  178. return
  179. end
  180. self.randomtime = math.random(1,5)*10
  181. if math.random(1, 100) <= fishing_setting.settings["fish_chance"] then
  182. if self.water_type and self.water_type == "sea" then
  183. self.prize = fishing_setting.prizes["sea"]["little"][math.random(1,#fishing_setting.prizes["sea"]["little"])]
  184. else
  185. self.prize = fishing_setting.prizes["rivers"]["little"][math.random(1,#fishing_setting.prizes["rivers"]["little"])]
  186. end
  187. -- to mobs_fish modpack
  188. if fishing_setting.have_true_fish then
  189. local objs = minetest.get_objects_inside_radius({x=pos.x, y=pos.y-1, z=pos.z}, 1)
  190. for _, obj in pairs(objs) do
  191. if obj:get_luaentity() ~= nil then
  192. local name = obj:get_luaentity().name
  193. if fishing_setting.prizes["true_fish"]["little"][name] then
  194. self.prize = fishing_setting.prizes["true_fish"]["little"][name]
  195. obj:remove()
  196. self.randomtime = math.random(3,7)*10
  197. break
  198. end
  199. end
  200. end
  201. end
  202. elseif math.random(1, 100) <= 10 then
  203. self.prize = fishing_setting.func.get_loot()
  204. end
  205. if self.prize ~= "" then
  206. pos.y = self.old_pos.y-0.1
  207. self.object:move_to(pos, false)
  208. minetest.sound_play("fishing_bobber1", {pos=pos,gain = 0.5,})
  209. end
  210. end,
  211. }
  212. minetest.register_entity("fishing:bobber_fish_entity", FISHING_BOBBER_ENTITY)