init.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. -----------------------------------------------------------------------------------------------
  2. local title = "Fishing - Mossmanikin's version"
  3. local version = "0.2.2"
  4. local mname = "fishing"
  5. -----------------------------------------------------------------------------------------------
  6. -- original by wulfsdad (http://forum.minetest.net/viewtopic.php?id=4375)
  7. -- this version by Mossmanikin (https://forum.minetest.net/viewtopic.php?id=6480)
  8. -- License (code & textures): WTFPL
  9. -- Contains code from: animal_clownfish, animal_fish_blue_white, fishing (original), stoneage
  10. -- Looked at code from: default, farming
  11. -- Dependencies: default
  12. -- Supports: animal_clownfish, animal_fish_blue_white, animal_rat, mobs
  13. -----------------------------------------------------------------------------------------------
  14. -- todo: item wear done
  15. -- automatic re-baiting option done (but not optional)
  16. -- different types of fish, done, but not finished
  17. -- add sound done
  18. -- bobber done
  19. -- change rainworms filling inv & make 'em disappear done
  20. -- placable fishing rod for decoration done
  21. -- make bobber move slowly while fish on hook done
  22. -- catch bigger fish with smaller done, but not finished
  23. -- change color of bobber when fish on hook done
  24. -----------------------------------------------------------------------------------------------
  25. --------------------------------------------------------------------------------
  26. -- some additions made by 4aiman to make a pole be usable w/o clicking on a bobbler,
  27. -- to make bobblers "dissapear" other bobblers only of their "owner"
  28. -- also 1 man = 1 bobbler... or so it would seem ;)
  29. -- Moreover, I've fixed node_drops to be compatible with enchantments.
  30. --------------------------------------------------------------------------------
  31. dofile(minetest.get_modpath("fishing").."/settings.txt")
  32. dofile(minetest.get_modpath("fishing").."/bobber.lua")
  33. dofile(minetest.get_modpath("fishing").."/bobber_shark.lua")
  34. dofile(minetest.get_modpath("fishing").."/crafting.lua")
  35. dofile(minetest.get_modpath("fishing").."/fishes.lua")
  36. dofile(minetest.get_modpath("fishing").."/worm.lua")
  37. -----------------------------------------------------------------------------------------------
  38. -- Fishing Pole
  39. -----------------------------------------------------------------------------------------------
  40. local function rod_wear(itemstack, user, pointed_thing, uses)
  41. itemstack:add_wear(65535/(uses-1))
  42. return itemstack
  43. end
  44. pused = {}
  45. placed_bobbler = {}
  46. minetest.register_tool("fishing:pole", {
  47. description = "Fishing Pole",
  48. groups = {},
  49. inventory_image = "fishing_pole.png",
  50. wield_image = "fishing_pole.png^[transformFXR270",
  51. stack_max = 1,
  52. liquids_pointable = true,
  53. range = 7.5,
  54. on_place = function (itemstack, user, pointed_thing)
  55. if placed_bobbler[player]==true then return itemstack end
  56. if pointed_thing and pointed_thing.under then
  57. local pt = pointed_thing
  58. local node = minetest.get_node(pt.under)
  59. if string.find(node.name, "default:water") then
  60. local player = user:get_player_name()
  61. pused[player]=true
  62. local inv = user:get_inventory()
  63. if inv:get_stack("main", user:get_wield_index()+1):get_name() == "fishing:bait_worm" then
  64. if not minetest.setting_getbool("creative_mode") then
  65. inv:remove_item("main", "fishing:bait_worm")
  66. end
  67. minetest.sound_play("fishing_bobber2", {
  68. pos = pt.under,
  69. gain = 0.5,
  70. })
  71. local ent = minetest.add_entity({interval = 1,x=pt.under.x, y=pt.under.y+(45/64), z=pt.under.z}, "fishing:bobber_entity")
  72. ent:get_luaentity().owner=player
  73. placed_bobbler[player] = true
  74. if WEAR_OUT == true
  75. and not minetest.setting_getbool("creative_mode") then
  76. return rod_wear(itemstack, user, pointed_thing, 60)
  77. else
  78. return {name="fishing:pole", count=1, wear=0, metadata=""}
  79. end
  80. end
  81. if inv:get_stack("main", user:get_wield_index()+1):get_name() == "fishing:fish_raw" then
  82. if not minetest.setting_getbool("creative_mode") then
  83. inv:remove_item("main", "fishing:fish_raw")
  84. end
  85. minetest.sound_play("fishing_bobber2", {
  86. pos = pt.under,
  87. gain = 0.5,
  88. })
  89. minetest.add_entity({interval = 1,x=pt.under.x, y=pt.under.y+(45/64), z=pt.under.z}, "fishing:bobber_entity_shark")
  90. placed_bobbler[player] = true
  91. if WEAR_OUT == true
  92. and not minetest.setting_getbool("creative_mode") then
  93. return rod_wear(itemstack, user, pointed_thing, 60)
  94. else
  95. return {name="fishing:pole", count=1, wear=0, metadata=""}
  96. end
  97. end
  98. end
  99. end
  100. return nil
  101. end,
  102. on_use = function(itemstack, placer, pointed_thing)
  103. end,
  104. })
  105. minetest.register_globalstep(function(dtime)
  106. local players = minetest.get_connected_players()
  107. for i,player in ipairs(players) do
  108. local pll = player:get_player_name()
  109. local control = player:get_player_control()
  110. if not control.RMB then pused[pll]=nil end
  111. end
  112. end)