Insta-drop minecart when its rail is destroyed
[MineClone/MineClone2.git] / mods / ITEMS / mcl_fishing / init.lua
blobab2519b9fd800942670cfd5902ed873967e1b528
1 local go_fishing = function(itemstack, user, pointed_thing)
2 if pointed_thing and pointed_thing.under then
3 -- Use pointed node's on_rightclick function first, if present
4 local node = minetest.get_node(pointed_thing.under)
5 if user and not user:get_player_control().sneak then
6 if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
7 return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
8 end
9 end
11 if string.find(node.name, "mcl_core:water") then
12 local itemname
13 local itemcount = 1
14 local itemwear = 0
15 -- FIXME: Maybe use a better seeding
16 local pr = PseudoRandom(os.time() * math.random(1, 100))
17 local r = pr:next(1, 100)
18 if r <= 85 then
19 -- Fish
20 items = mcl_loot.get_loot({
21 items = {
22 { itemstring = "mcl_fishing:fish_raw", weight = 60 },
23 { itemstring = "mcl_fishing:salmon_raw", weight = 25 },
24 { itemstring = "mcl_fishing:clownfish_raw", weight = 2 },
25 { itemstring = "mcl_fishing:pufferfish_raw", weight = 13 },
27 }, pr)
28 elseif r <= 95 then
29 -- Junk
30 items = mcl_loot.get_loot({
31 items = {
32 { itemstring = "mcl_core:bowl", weight = 10 },
33 { itemstring = "mcl_fishing:fishing_rod", weight = 2, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
34 { itemstring = "mcl_mobitems:leather", weight = 10 },
35 { itemstring = "3d_armor:boots_leather", weight = 10, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
36 { itemstring = "mcl_mobitems:rotten_flesh", weight = 10 },
37 { itemstring = "mcl_core:stick", weight = 5 },
38 { itemstring = "mcl_mobitems:string", weight = 5 },
39 { itemstring = "mcl_potions:potion_water", weight = 10 },
40 { itemstring = "mcl_mobitems:bone", weight = 10 },
41 { itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 },
42 { itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook
44 }, pr)
45 else
46 -- Treasure
47 items = mcl_loot.get_loot({
48 items = {
49 -- TODO: Enchanted Bow
50 { itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
51 -- TODO: Enchanted Book
52 { itemstring = "mcl_books:book" },
53 -- TODO: Enchanted Fishing Rod
54 { itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
55 { itemstring = "mcl_mobs:nametag", },
56 { itemstring = "mcl_mobitems:saddle", },
57 { itemstring = "mcl_flowers:waterlily", },
59 }, pr)
60 end
61 local item
62 if #items >= 1 then
63 item = ItemStack(items[1])
64 else
65 item = ItemStack()
66 end
67 local inv = user:get_inventory()
68 if inv:room_for_item("main", item) then
69 inv:add_item("main", item)
70 end
71 if not minetest.settings:get_bool("creative_mode") then
72 local idef = itemstack:get_definition()
73 itemstack:add_wear(65535/65) -- 65 uses
74 if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
75 minetest.sound_play(idef.sound.breaks, {pos=pointed_thing.above, gain=0.5})
76 end
77 end
78 return itemstack
79 end
80 end
81 return nil
82 end
84 -- Fishing Rod
85 minetest.register_tool("mcl_fishing:fishing_rod", {
86 description = "Fishing Rod",
87 _doc_items_longdesc = "Fishing rods can be used to catch fish.",
88 _doc_items_usagehelp = "Rightclick a water source to try to go fishing. Who knows what you're going to catch?",
89 -- This item is incomplete, hide it from creative inventory
90 groups = { tool=1, not_in_creative_inventory=1 },
91 inventory_image = "mcl_fishing_fishing_rod.png",
92 stack_max = 1,
93 liquids_pointable = true,
94 on_place = go_fishing,
95 sound = { breaks = "default_tool_breaks" },
98 --[[
100 Temporarily removed from crafting as the fishing rod is massively overpowered atm.
102 TODO: Re-enable crafting when fishing rod has been improved.
104 minetest.register_craft({
105 output = "mcl_fishing:fishing_rod",
106 recipe = {
107 {'','','mcl_core:stick'},
108 {'','mcl_core:stick','mcl_mobitems:string'},
109 {'mcl_core:stick','','mcl_mobitems:string'},
112 minetest.register_craft({
113 output = "mcl_fishing:fishing_rod",
114 recipe = {
115 {'mcl_core:stick', '', ''},
116 {'mcl_mobitems:string', 'mcl_core:stick', ''},
117 {'mcl_mobitems:string','','mcl_core:stick'},
122 minetest.register_craft({
123 type = "fuel",
124 recipe = "mcl_fishing:fishing_rod",
125 burntime = 15,
129 -- Fish
130 minetest.register_craftitem("mcl_fishing:fish_raw", {
131 description = "Raw Fish",
132 _doc_items_longdesc = "Raw fish is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value.",
133 inventory_image = "mcl_fishing_fish_raw.png",
134 on_place = minetest.item_eat(2),
135 on_secondary_use = minetest.item_eat(2),
136 stack_max = 64,
137 groups = { food=2, eatable = 2 },
138 _mcl_saturation = 0.4,
141 minetest.register_craftitem("mcl_fishing:fish_cooked", {
142 description = "Cooked Fish",
143 _doc_items_longdesc = "Mmh, fish! This is a healthy food item.",
144 inventory_image = "mcl_fishing_fish_cooked.png",
145 on_place = minetest.item_eat(5),
146 on_secondary_use = minetest.item_eat(5),
147 stack_max = 64,
148 groups = { food=2, eatable=5 },
149 _mcl_saturation = 6,
152 minetest.register_craft({
153 type = "cooking",
154 output = "mcl_fishing:fish_cooked",
155 recipe = "mcl_fishing:fish_raw",
156 cooktime = 10,
159 -- Salmon
160 minetest.register_craftitem("mcl_fishing:salmon_raw", {
161 description = "Raw Salmon",
162 _doc_items_longdesc = "Raw salmon is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value.",
163 inventory_image = "mcl_fishing_salmon_raw.png",
164 on_place = minetest.item_eat(2),
165 on_secondary_use = minetest.item_eat(2),
166 stack_max = 64,
167 groups = { food=2, eatable = 2 },
168 _mcl_saturation = 0.4,
171 minetest.register_craftitem("mcl_fishing:salmon_cooked", {
172 description = "Cooked Salmon",
173 _doc_items_longdesc = "This is a healthy food item which can be eaten.",
174 inventory_image = "mcl_fishing_salmon_cooked.png",
175 on_place = minetest.item_eat(6),
176 on_secondary_use = minetest.item_eat(6),
177 stack_max = 64,
178 groups = { food=2, eatable=6 },
179 _mcl_saturation = 9.6,
182 minetest.register_craft({
183 type = "cooking",
184 output = "mcl_fishing:salmon_cooked",
185 recipe = "mcl_fishing:salmon_raw",
186 cooktime = 10,
189 -- Clownfish
190 minetest.register_craftitem("mcl_fishing:clownfish_raw", {
191 description = "Clownfish",
192 _doc_items_longdesc = "Clownfish may be obtained by fishing (and luck) and is a food item which can be eaten safely.",
193 inventory_image = "mcl_fishing_clownfish_raw.png",
194 on_place = minetest.item_eat(1),
195 on_secondary_use = minetest.item_eat(1),
196 stack_max = 64,
197 groups = { food=2, eatable = 1 },
198 _mcl_saturation = 0.2,
201 -- Pufferfish
202 -- TODO: Add real status effect
203 minetest.register_craftitem("mcl_fishing:pufferfish_raw", {
204 description = "Pufferfish",
205 _doc_items_longdesc = "Pufferfish are a common species of fish and can be obtained by fishing. They can technically be eaten, but they are very bad for humans. Eating a pufferfish only restores 1 hunger point and will poison you very badly (which drains your health non-fatally) and causes serious food poisoning (which increases your hunger).",
206 inventory_image = "mcl_fishing_pufferfish_raw.png",
207 on_place = minetest.item_eat(1),
208 on_secondary_use = minetest.item_eat(1),
209 stack_max = 64,
210 groups = { food=2, eatable=1 },
211 _mcl_saturation = 0.2,