init.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. -----------------------------------------------------------------------------------------------
  2. local title = "Fishing - Mossmanikin's version"
  3. local version = "0.1.2-LGN"
  4. local mname = "fishing"
  5. -----------------------------------------------------------------------------------------------
  6. -- original by wulfsdad (http://forum.minetest.net/viewtopic.php?id=4375)
  7. -- this version by Mossmanikin
  8. -- License (code & textures): WTFPL (exception below)
  9. -- except for: "fishing_fish_cooked.png" contributed by Tirifto,
  10. -- released into public domain under CC0.
  11. -- Contains code from: animal_clownfish, animal_fish_blue_white, fishing (original), stoneage
  12. -- Looked at code from: default, farming
  13. -- Dependencies: default
  14. -- Supports: animal_clownfish, animal_fish_blue_white, animal_rat, mobs
  15. -----------------------------------------------------------------------------------------------
  16. -- todo: item wear done
  17. -- automatic re-baiting option done
  18. -- different types of fish, sort of
  19. -- add sound done
  20. -- bobber done
  21. -- change rainworms filling inv & make 'em disappear done
  22. -- placable fishing rod for decoration done
  23. -- make bobber move slowly while fish on hook done
  24. -- catch bigger fish with smaller
  25. -- change color of bobber when fish on hook done
  26. -----------------------------------------------------------------------------------------------
  27. dofile(minetest.get_modpath("fishing").."/settings.txt")
  28. dofile(minetest.get_modpath("fishing").."/bobber.lua")
  29. dofile(minetest.get_modpath("fishing").."/crafting.lua")
  30. dofile(minetest.get_modpath("fishing").."/fishes.lua")
  31. dofile(minetest.get_modpath("fishing").."/worm.lua")
  32. -----------------------------------------------------------------------------------------------
  33. -- Fishing Pole
  34. -----------------------------------------------------------------------------------------------
  35. local function rod_wear(itemstack, user, pointed_thing, uses)
  36. itemstack:add_wear(65535/(uses-1))
  37. return itemstack
  38. end
  39. minetest.register_tool("fishing:pole", {
  40. description = "Fishing Pole",
  41. groups = {},
  42. inventory_image = "fishing_pole.png",
  43. wield_image = "fishing_pole.png^[transformFXR270",
  44. stack_max = 1,
  45. liquids_pointable = true,
  46. on_use = function (itemstack, user, pointed_thing)
  47. if pointed_thing and pointed_thing.under then
  48. local pt = pointed_thing
  49. local node = minetest.env:get_node(pt.under)
  50. if string.find(node.name, "default:water") then
  51. local player = user:get_player_name()
  52. local inv = user:get_inventory()
  53. if inv:get_stack("main", user:get_wield_index()+1):get_name() == "fishing:bait_worm" then
  54. inv:remove_item("main", "fishing:bait_worm")
  55. minetest.sound_play("fishing_bobber2", {
  56. pos = pt.under,
  57. gain = 0.5,
  58. })
  59. minetest.env:add_entity({interval = 1,x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, "fishing:bobber_entity")
  60. if WEAR_OUT == true then
  61. return rod_wear(itemstack, user, pointed_thing, 30)
  62. else
  63. return {name="fishing:pole", count=1, wear=0, metadata=""}
  64. end
  65. end
  66. end
  67. end
  68. return nil
  69. end,
  70. on_place = function(itemstack, placer, pointed_thing)
  71. local pt = pointed_thing
  72. if minetest.get_node(pt.under).name~="default:water_source" and minetest.get_node(pt.under).name~="default:water_flowing" then
  73. local wear = itemstack:get_wear()
  74. local direction = minetest.dir_to_facedir(placer:get_look_dir())
  75. local meta1 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y , z=pt.under.z})
  76. local meta2 = minetest.env:get_meta({x=pt.under.x, y=pt.under.y+1, z=pt.under.z})
  77. minetest.set_node({x=pt.under.x, y=pt.under.y+1, z=pt.under.z}, {name="fishing:pole_deco", param2=direction})
  78. meta1:set_int("wear", wear)
  79. meta2:set_int("wear", wear)
  80. itemstack:take_item()
  81. end
  82. return itemstack
  83. end,
  84. })
  85. if SIMPLE_DECO_FISHING_POLE == true then
  86. minetest.register_node("fishing:pole_deco", {
  87. description = "Fishing Pole",
  88. drawtype = "nodebox",
  89. paramtype = "light",
  90. paramtype2 = "facedir",
  91. tiles = {
  92. "fishing_pole_top.png", "fishing_pole_bottom.png", "fishing_pole.png", "fishing_pole.png^[transformFX", "fishing_pole_front.png", "fishing_pole_back.png",
  93. },
  94. groups = {
  95. snappy=3,
  96. flammable=2,
  97. not_in_creative_inventory=1
  98. },
  99. node_box = {
  100. type = "fixed",
  101. fixed = {
  102. {-0.5/3, -1.5/3, -1.5/3, 0.5/3, -0.5/3, -0.5/3},{-0.5/3, -0.5/3, -0.5/3, 0.5/3, 0.5/3, 0.5/3},{-0.5/3, 0.5/3, 0.5/3, 0.5/3, 1.5/3, 1.5/3},{-0.5/3, -1.5/3, 0.5/3, 0.5/3, 0.5/3, 1.5/3},
  103. }
  104. },
  105. selection_box = {
  106. type = "fixed",
  107. fixed = {
  108. {-0.5/3, -1.5/3, -1.5/3, 0.5/3, -0.5/3, -0.5/3},{-0.5/3, -0.5/3, -0.5/3, 0.5/3, 0.5/3, 0.5/3},{-0.5/3, 0.5/3, 0.5/3, 0.5/3, 1.5/3, 1.5/3},{-0.5/3, -1.5/3, 0.5/3, 0.5/3, 0.5/3, 1.5/3},
  109. }
  110. },
  111. sounds = default.node_sound_wood_defaults(),
  112. on_dig = function(pos, node, digger)
  113. if digger:is_player() and digger:get_inventory() then
  114. local meta = minetest.env:get_meta(pos)
  115. local wear_out = meta:get_int("wear")
  116. digger:get_inventory():add_item("main", {name="fishing:pole", count=1, wear=wear_out, metadata=""})
  117. end
  118. minetest.remove_node(pos)
  119. end,
  120. })
  121. else
  122. minetest.register_node("fishing:pole_deco", {
  123. description = "Fishing Pole",
  124. inventory_image = "fishing_pole.png",
  125. wield_image = "fishing_pole.png^[transformFXR270",
  126. drawtype = "nodebox",
  127. paramtype = "light",
  128. paramtype2 = "facedir",
  129. tiles = {
  130. "fishing_pole_top.png",
  131. "fishing_pole_bottom.png",
  132. "fishing_pole_deco.png", -- right
  133. "fishing_pole_deco.png^[transformFX", -- left
  134. "fishing_pole_back.png",
  135. "fishing_pole_front.png"
  136. },
  137. node_box = {
  138. type = "fixed",
  139. -- { left , bottom , front , right , top , back }
  140. fixed = {
  141. {-1/32 , -1/16 , 14/16 , 1/32 , 6/16 , 15/16},
  142. {-1/32 , -3/16 , 13/16 , 1/32 , -1/16 , 14/16},
  143. {-1/32 , -4/16 , 12/16 , 1/32 , -3/16 , 13/16},
  144. {-1/32 , -5/16 , 11/16 , 1/32 , -4/16 , 12/16},
  145. {-1/32 , -6/16 , 9/16 , 1/32 , -5/16 , 11/16},
  146. {-1/32 , -5/16 , 9/16 , 1/32 , -4/16 , 10/16},
  147. -- stick
  148. {-1/32 , 6/16 , 12/16 , 1/32 , 7/16 , 15/16}, -- top
  149. {-1/32 , 5/16 , 11/16 , 1/32 , 7/16 , 12/16},
  150. {-1/32 , 5/16 , 10/16 , 1/32 , 6/16 , 11/16},
  151. {-1/32 , 4/16 , 9/16 , 1/32 , 6/16 , 10/16},
  152. {-1/32 , 3/16 , 8/16 , 1/32 , 5/16 , 9/16},
  153. {-1/32 , 2/16 , 7/16 , 1/32 , 4/16 , 8/16},
  154. {-1/32 , 1/16 , 6/16 , 1/32 , 3/16 , 7/16},
  155. {-1/32 , 0 , 5/16 , 1/32 , 2/16 , 6/16},
  156. {-1/32 , -2/16 , 4/16 , 1/32 , 1/16 , 5/16},
  157. {-1/32 , -3/16 , 3/16 , 1/32 , 0 , 4/16},
  158. {-1/32 , -5/16 , 2/16 , 1/32 , -1/16 , 3/16},
  159. {-1/32 , -7/16 , 1/16 , 1/32 , -3/16 , 2/16},
  160. {-1/32 , -1/2 , 0 , 1/32 , -5/16 , 1/16}, -- bottom
  161. }
  162. },
  163. selection_box = {
  164. type = "fixed",
  165. fixed = {
  166. {-1/16 , -1/2 , 0 , 1/16 , 1/2 , 1 },
  167. }
  168. },
  169. groups = {
  170. snappy=3,
  171. flammable=2,
  172. not_in_creative_inventory=1
  173. },
  174. sounds = default.node_sound_wood_defaults(),
  175. on_dig = function(pos, node, digger)
  176. if digger:is_player() and digger:get_inventory() then
  177. local meta = minetest.env:get_meta(pos)
  178. local wear_out = meta:get_int("wear")
  179. digger:get_inventory():add_item("main", {name="fishing:pole", count=1, wear=wear_out, metadata=""})
  180. end
  181. minetest.remove_node(pos)
  182. end,
  183. })
  184. end
  185. -----------------------------------------------------------------------------------------------
  186. -- GETTING WORMS
  187. -----------------------------------------------------------------------------------------------
  188. -- get worms from digging in dirt:
  189. if NEW_WORM_SOURCE == false then
  190. minetest.register_node(":default:dirt", {
  191. description = "Dirt",
  192. tiles = {"default_dirt.png"},
  193. is_ground_content = true,
  194. groups = {crumbly=3},
  195. sounds = default.node_sound_dirt_defaults(),
  196. after_dig_node = function (pos, oldnode, oldmetadata, digger)
  197. if math.random(1, 100) < WORM_CHANCE then
  198. local tool_in_use = digger:get_wielded_item():get_name()
  199. if tool_in_use == "" or tool_in_use == "default:dirt" then
  200. minetest.env:add_entity({x = pos.x, y = pos.y+0.4, z = pos.z}, "fishing:bait_worm_entity")
  201. --local inv = digger:get_inventory()
  202. --if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  203. --inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  204. --end
  205. end
  206. end
  207. end,
  208. })
  209. else
  210. -- get worms from digging with hoes:
  211. -- turns nodes with group soil=1 into soil
  212. local function hoe_on_use(itemstack, user, pointed_thing, uses)
  213. local pt = pointed_thing
  214. -- check if pointing at a node
  215. if not pt then
  216. return
  217. end
  218. if pt.type ~= "node" then
  219. return
  220. end
  221. local under = minetest.get_node(pt.under)
  222. local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
  223. local above = minetest.get_node(p)
  224. -- return if any of the nodes is not registered
  225. if not minetest.registered_nodes[under.name] then
  226. return
  227. end
  228. if not minetest.registered_nodes[above.name] then
  229. return
  230. end
  231. -- check if the node above the pointed thing is air
  232. if above.name ~= "air" then
  233. return
  234. end
  235. -- check if pointing at dirt
  236. if minetest.get_item_group(under.name, "soil") ~= 1 then
  237. return
  238. end
  239. -- turn the node into soil, play sound, get worm and wear out item
  240. minetest.set_node(pt.under, {name="farming:soil"})
  241. minetest.sound_play("default_dig_crumbly", {
  242. pos = pt.under,
  243. gain = 0.5,
  244. })
  245. --local inv = user:get_inventory()
  246. if math.random(1, 100) < WORM_CHANCE then
  247. minetest.env:add_entity({x=pt.under.x, y=pt.under.y+0.4, z=pt.under.z}, "fishing:bait_worm_entity")
  248. --if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  249. --inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  250. --end
  251. end
  252. itemstack:add_wear(65535/(uses-1))
  253. return itemstack
  254. end
  255. -- didn't change the hoes, just here because hoe_on_use is local
  256. minetest.register_tool(":farming:hoe_wood", {
  257. description = "Wooden Hoe",
  258. inventory_image = "farming_tool_woodhoe.png",
  259. on_use = function(itemstack, user, pointed_thing)
  260. return hoe_on_use(itemstack, user, pointed_thing, 30)
  261. end,
  262. })
  263. minetest.register_tool(":farming:hoe_stone", {
  264. description = "Stone Hoe",
  265. inventory_image = "farming_tool_stonehoe.png",
  266. on_use = function(itemstack, user, pointed_thing)
  267. return hoe_on_use(itemstack, user, pointed_thing, 90)
  268. end,
  269. })
  270. minetest.register_tool(":farming:hoe_steel", {
  271. description = "Steel Hoe",
  272. inventory_image = "farming_tool_steelhoe.png",
  273. on_use = function(itemstack, user, pointed_thing)
  274. return hoe_on_use(itemstack, user, pointed_thing, 200)
  275. end,
  276. })
  277. minetest.register_tool(":farming:hoe_bronze", {
  278. description = "Bronze Hoe",
  279. inventory_image = "farming_tool_bronzehoe.png",
  280. on_use = function(itemstack, user, pointed_thing)
  281. return hoe_on_use(itemstack, user, pointed_thing, 220)
  282. end,
  283. })
  284. end
  285. -----------------------------------------------------------------------------------------------
  286. print("[Mod] "..title.." ["..version.."] ["..mname.."] Loaded...")
  287. -----------------------------------------------------------------------------------------------