2019-03-08 01:00:09 +02:00
local S = minetest.get_translator ( " mcl_fishing " )
2017-02-17 23:27:33 +02:00
local go_fishing = function ( itemstack , user , pointed_thing )
if pointed_thing and pointed_thing.under then
2017-03-02 17:09:13 +02:00
-- Use pointed node's on_rightclick function first, if present
2017-02-17 23:27:33 +02:00
local node = minetest.get_node ( pointed_thing.under )
2017-03-02 17:09:13 +02:00
if user and not user : get_player_control ( ) . sneak then
if minetest.registered_nodes [ node.name ] and minetest.registered_nodes [ node.name ] . on_rightclick then
return minetest.registered_nodes [ node.name ] . on_rightclick ( pointed_thing.under , node , user , itemstack ) or itemstack
end
end
2017-02-17 23:27:33 +02:00
if string.find ( node.name , " mcl_core:water " ) then
local itemname
local itemcount = 1
local itemwear = 0
2017-05-19 19:00:21 +03:00
-- FIXME: Maybe use a better seeding
local pr = PseudoRandom ( os.time ( ) * math.random ( 1 , 100 ) )
local r = pr : next ( 1 , 100 )
2017-02-17 23:27:33 +02:00
if r <= 85 then
-- Fish
2017-05-19 19:00:21 +03:00
items = mcl_loot.get_loot ( {
items = {
{ itemstring = " mcl_fishing:fish_raw " , weight = 60 } ,
{ itemstring = " mcl_fishing:salmon_raw " , weight = 25 } ,
{ itemstring = " mcl_fishing:clownfish_raw " , weight = 2 } ,
{ itemstring = " mcl_fishing:pufferfish_raw " , weight = 13 } ,
}
} , pr )
2017-02-17 23:27:33 +02:00
elseif r <= 95 then
-- Junk
2017-05-19 19:00:21 +03:00
items = mcl_loot.get_loot ( {
items = {
{ itemstring = " mcl_core:bowl " , weight = 10 } ,
{ itemstring = " mcl_fishing:fishing_rod " , weight = 2 , wear_min = 6554 , wear_max = 65535 } , -- 10%-100% damage
{ itemstring = " mcl_mobitems:leather " , weight = 10 } ,
{ itemstring = " 3d_armor:boots_leather " , weight = 10 , wear_min = 6554 , wear_max = 65535 } , -- 10%-100% damage
{ itemstring = " mcl_mobitems:rotten_flesh " , weight = 10 } ,
{ itemstring = " mcl_core:stick " , weight = 5 } ,
{ itemstring = " mcl_mobitems:string " , weight = 5 } ,
{ itemstring = " mcl_potions:potion_water " , weight = 10 } ,
{ itemstring = " mcl_mobitems:bone " , weight = 10 } ,
{ itemstring = " mcl_dye:black " , weight = 1 , amount_min = 10 , amount_max = 10 } ,
{ itemstring = " mcl_mobitems:string " , weight = 10 } , -- TODO: Tripwire Hook
}
} , pr )
2017-02-17 23:27:33 +02:00
else
-- Treasure
2017-05-19 19:00:21 +03:00
items = mcl_loot.get_loot ( {
items = {
-- TODO: Enchanted Bow
2018-05-08 00:10:49 +03:00
{ itemstring = " mcl_bows:bow " , wear_min = 49144 , wear_max = 65535 } , -- 75%-100% damage
2017-05-19 19:00:21 +03:00
-- TODO: Enchanted Book
{ itemstring = " mcl_books:book " } ,
-- TODO: Enchanted Fishing Rod
{ itemstring = " mcl_fishing:fishing_rod " , wear_min = 49144 , wear_max = 65535 } , -- 75%-100% damage
2018-05-31 19:32:26 +03:00
{ itemstring = " mcl_mobs:nametag " , } ,
2017-05-19 19:00:21 +03:00
{ itemstring = " mcl_mobitems:saddle " , } ,
{ itemstring = " mcl_flowers:waterlily " , } ,
}
} , pr )
end
local item
if # items >= 1 then
item = ItemStack ( items [ 1 ] )
else
item = ItemStack ( )
2017-02-01 16:20:28 +02:00
end
2017-02-17 23:27:33 +02:00
local inv = user : get_inventory ( )
if inv : room_for_item ( " main " , item ) then
inv : add_item ( " main " , item )
end
2017-08-09 17:17:00 +03:00
if not minetest.settings : get_bool ( " creative_mode " ) then
2017-02-19 21:23:33 +02:00
local idef = itemstack : get_definition ( )
2017-02-17 23:39:56 +02:00
itemstack : add_wear ( 65535 / 65 ) -- 65 uses
2017-02-19 21:23:33 +02:00
if itemstack : get_count ( ) == 0 and idef.sound and idef.sound . breaks then
minetest.sound_play ( idef.sound . breaks , { pos = pointed_thing.above , gain = 0.5 } )
end
2017-02-17 23:27:33 +02:00
end
return itemstack
2017-02-01 16:20:28 +02:00
end
2017-02-17 23:27:33 +02:00
end
return nil
end
-- Fishing Rod
minetest.register_tool ( " mcl_fishing:fishing_rod " , {
2019-03-08 01:00:09 +02:00
description = S ( " Fishing Rod " ) ,
_doc_items_longdesc = S ( " Fishing rods can be used to catch fish. " ) ,
_doc_items_usagehelp = S ( " Rightclick a water source to try to go fishing. Who knows what you're going to catch? " ) ,
2018-05-08 02:40:31 +03:00
-- This item is incomplete, hide it from creative inventory
groups = { tool = 1 , not_in_creative_inventory = 1 } ,
2017-02-17 23:27:33 +02:00
inventory_image = " mcl_fishing_fishing_rod.png " ,
stack_max = 1 ,
liquids_pointable = true ,
on_place = go_fishing ,
2017-02-19 21:23:33 +02:00
sound = { breaks = " default_tool_breaks " } ,
2017-02-01 16:20:28 +02:00
} )
2017-11-20 08:52:24 +02:00
--[[
Temporarily removed from crafting as the fishing rod is massively overpowered atm .
TODO : Re - enable crafting when fishing rod has been improved .
2017-02-01 16:20:28 +02:00
minetest.register_craft ( {
output = " mcl_fishing:fishing_rod " ,
recipe = {
{ ' ' , ' ' , ' mcl_core:stick ' } ,
2017-02-01 18:59:15 +02:00
{ ' ' , ' mcl_core:stick ' , ' mcl_mobitems:string ' } ,
{ ' mcl_core:stick ' , ' ' , ' mcl_mobitems:string ' } ,
2017-02-01 16:20:28 +02:00
}
} )
minetest.register_craft ( {
output = " mcl_fishing:fishing_rod " ,
recipe = {
{ ' mcl_core:stick ' , ' ' , ' ' } ,
2017-02-01 18:59:15 +02:00
{ ' mcl_mobitems:string ' , ' mcl_core:stick ' , ' ' } ,
{ ' mcl_mobitems:string ' , ' ' , ' mcl_core:stick ' } ,
2017-02-01 16:20:28 +02:00
}
} )
2017-11-20 08:52:24 +02:00
] ]
2017-02-01 16:20:28 +02:00
minetest.register_craft ( {
type = " fuel " ,
recipe = " mcl_fishing:fishing_rod " ,
burntime = 15 ,
} )
-- Fish
minetest.register_craftitem ( " mcl_fishing:fish_raw " , {
2019-03-08 01:00:09 +02:00
description = S ( " Raw Fish " ) ,
_doc_items_longdesc = S ( " Raw fish is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value. " ) ,
2017-02-01 16:20:28 +02:00
inventory_image = " mcl_fishing_fish_raw.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 2 ) ,
on_secondary_use = minetest.item_eat ( 2 ) ,
2017-02-01 16:20:28 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 2 } ,
2017-05-20 18:45:04 +03:00
_mcl_saturation = 0.4 ,
2017-02-01 16:20:28 +02:00
} )
minetest.register_craftitem ( " mcl_fishing:fish_cooked " , {
2019-03-08 01:00:09 +02:00
description = S ( " Cooked Fish " ) ,
_doc_items_longdesc = S ( " Mmh, fish! This is a healthy food item. " ) ,
2017-02-01 16:20:28 +02:00
inventory_image = " mcl_fishing_fish_cooked.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 5 ) ,
on_secondary_use = minetest.item_eat ( 5 ) ,
2017-02-01 16:20:28 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 5 } ,
2017-05-21 04:26:51 +03:00
_mcl_saturation = 6 ,
2017-02-01 16:20:28 +02:00
} )
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_fishing:fish_cooked " ,
recipe = " mcl_fishing:fish_raw " ,
cooktime = 10 ,
} )
2017-02-01 16:29:43 +02:00
-- Salmon
minetest.register_craftitem ( " mcl_fishing:salmon_raw " , {
2019-03-08 01:00:09 +02:00
description = S ( " Raw Salmon " ) ,
_doc_items_longdesc = S ( " Raw salmon is obtained by fishing and is a food item which can be eaten safely. Cooking it improves its nutritional value. " ) ,
2017-02-01 16:29:43 +02:00
inventory_image = " mcl_fishing_salmon_raw.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 2 ) ,
on_secondary_use = minetest.item_eat ( 2 ) ,
2017-02-01 16:29:43 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 2 } ,
2017-05-20 18:45:04 +03:00
_mcl_saturation = 0.4 ,
2017-02-01 16:29:43 +02:00
} )
minetest.register_craftitem ( " mcl_fishing:salmon_cooked " , {
2019-03-08 01:00:09 +02:00
description = S ( " Cooked Salmon " ) ,
_doc_items_longdesc = S ( " This is a healthy food item which can be eaten. " ) ,
2017-02-01 16:29:43 +02:00
inventory_image = " mcl_fishing_salmon_cooked.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 6 ) ,
on_secondary_use = minetest.item_eat ( 6 ) ,
2017-02-01 16:29:43 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 6 } ,
2017-05-20 18:45:04 +03:00
_mcl_saturation = 9.6 ,
2017-02-01 16:29:43 +02:00
} )
minetest.register_craft ( {
type = " cooking " ,
output = " mcl_fishing:salmon_cooked " ,
recipe = " mcl_fishing:salmon_raw " ,
cooktime = 10 ,
} )
-- Clownfish
minetest.register_craftitem ( " mcl_fishing:clownfish_raw " , {
2019-03-08 01:00:09 +02:00
description = S ( " Clownfish " ) ,
_doc_items_longdesc = S ( " Clownfish may be obtained by fishing (and luck) and is a food item which can be eaten safely. " ) ,
2017-02-01 16:29:43 +02:00
inventory_image = " mcl_fishing_clownfish_raw.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 1 ) ,
on_secondary_use = minetest.item_eat ( 1 ) ,
2017-02-01 16:29:43 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 1 } ,
2017-05-20 18:45:04 +03:00
_mcl_saturation = 0.2 ,
2017-02-01 16:29:43 +02:00
} )
-- Pufferfish
2017-05-21 01:43:30 +03:00
-- TODO: Add real status effect
2017-02-01 16:29:43 +02:00
minetest.register_craftitem ( " mcl_fishing:pufferfish_raw " , {
2019-03-08 01:00:09 +02:00
description = S ( " Pufferfish " ) ,
_doc_items_longdesc = S ( " 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). " ) ,
2017-02-01 16:29:43 +02:00
inventory_image = " mcl_fishing_pufferfish_raw.png " ,
2017-02-16 18:45:33 +02:00
on_place = minetest.item_eat ( 1 ) ,
on_secondary_use = minetest.item_eat ( 1 ) ,
2017-02-01 16:29:43 +02:00
stack_max = 64 ,
groups = { food = 2 , eatable = 1 } ,
2017-05-20 18:45:04 +03:00
_mcl_saturation = 0.2 ,
2017-02-01 16:29:43 +02:00
} )