2015-06-26 22:33:51 +02:00
-----------------------------------------------------------------------------------------------
-- Fishing - crabman77's version - Bobber
-- Rewrited from original Fishing - Mossmanikin's version - Bobber 0.1.7
-- License (code & textures): WTFPL
-- Contains code from: fishing (original), mobs, throwing, volcano
-- Supports: 3d_armor, animal_clownfish, animal_fish_blue_white, animal_rat, flowers_plus, mobs, seaplants
-----------------------------------------------------------------------------------------------
2015-04-16 21:33:56 +02:00
-- bobber
minetest.register_node ( " fishing:bobber_box " , {
drawtype = " nodebox " ,
node_box = {
type = " fixed " ,
fixed = {
-- { left, bottom, front, right, top , back}
{ - 8 / 16 , - 8 / 16 , 0 , 8 / 16 , 8 / 16 , 0 } , -- feathers
2015-06-26 22:33:51 +02:00
{ - 2 / 16 , - 8 / 16 , - 2 / 16 , 2 / 16 , - 4 / 16 , 2 / 16 } , -- bobber
} ,
2015-04-16 21:33:56 +02:00
} ,
tiles = {
" fishing_bobber_top.png " ,
" fishing_bobber_bottom.png " ,
" fishing_bobber.png " ,
" fishing_bobber.png " ,
" fishing_bobber.png " ,
" fishing_bobber.png^[transformFX "
2015-08-20 16:08:03 +02:00
} ,
2015-04-16 21:33:56 +02:00
groups = { not_in_creative_inventory = 1 } ,
} )
local FISHING_BOBBER_ENTITY = {
hp_max = 605 ,
water_damage = 1 ,
physical = true ,
timer = 0 ,
env_damage_timer = 0 ,
visual = " wielditem " ,
visual_size = { x = 1 / 3 , y = 1 / 3 , z = 1 / 3 } ,
textures = { " fishing:bobber_box " } ,
2015-07-16 00:01:19 +02:00
-- {left ,bottom, front, right, top , back}
2015-06-26 22:33:51 +02:00
collisionbox = { - 2 / 16 , - 4 / 16 , - 2 / 16 , 2 / 16 , 1 / 16 , 2 / 16 } ,
2015-04-16 21:33:56 +02:00
randomtime = 50 ,
2015-06-16 01:42:05 +02:00
baitball = 0 ,
2015-04-16 21:33:56 +02:00
prize = " " ,
2015-06-16 01:42:05 +02:00
bait = " " ,
2015-06-26 22:33:51 +02:00
2015-06-09 23:09:47 +02:00
-- DESTROY BOBBER WHEN PUNCHING IT
2015-04-16 21:33:56 +02:00
on_punch = function ( self , puncher , time_from_last_punch , tool_capabilities , dir )
if not puncher : is_player ( ) then return end
local player = puncher : get_player_name ( )
2015-06-26 22:33:51 +02:00
if playername ~= self.owner then return end
if fishing_setting.settings [ " message " ] == true then minetest.chat_send_player ( playername , fishing_setting.func . S ( " You didn't catch anything. " ) , false ) end
2015-04-16 21:33:56 +02:00
if not fishing_setting.is_creative_mode then
local inv = puncher : get_inventory ( )
2015-06-09 23:09:47 +02:00
if inv : room_for_item ( " main " , { name = self.bait , count = 1 , wear = 0 , metadata = " " } ) then
inv : add_item ( " main " , { name = self.bait , count = 1 , wear = 0 , metadata = " " } )
2015-06-26 22:33:51 +02:00
if fishing_setting.settings [ " message " ] == true then minetest.chat_send_player ( playername , fishing_setting.func . S ( " The bait is still there. " ) , false ) end
2015-04-16 21:33:56 +02:00
end
end
-- make sound and remove bobber
minetest.sound_play ( " fishing_bobber1 " , { pos = self.object : getpos ( ) , gain = 0.5 , } )
self.object : remove ( )
end ,
2015-06-26 22:33:51 +02:00
2015-07-16 00:01:19 +02:00
-- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
2015-04-16 21:33:56 +02:00
on_rightclick = function ( self , clicker )
local item = clicker : get_wielded_item ( )
2015-06-26 22:33:51 +02:00
local playername = clicker : get_player_name ( )
2015-04-16 21:33:56 +02:00
local inv = clicker : get_inventory ( )
local pos = self.object : getpos ( )
local item_name = item : get_name ( )
if string.find ( item_name , " fishing:pole_ " ) ~= nil then
2015-06-26 22:33:51 +02:00
if playername ~= self.owner then return end
2015-04-16 21:33:56 +02:00
if self.prize ~= " " then
2015-06-26 22:33:51 +02:00
if math.random ( 1 , 100 ) <= fishing_setting.settings [ " escape_chance " ] then
if fishing_setting.settings [ " message " ] == true then minetest.chat_send_player ( playername , fishing_setting.func . S ( " Your fish escaped. " ) , false ) end -- fish escaped
2015-04-16 21:33:56 +02:00
else
2015-06-26 22:33:51 +02:00
local name = self.prize [ 1 ] .. " : " .. self.prize [ 2 ]
local desc = self.prize [ 4 ]
if fishing_setting.settings [ " message " ] == true then minetest.chat_send_player ( playername , fishing_setting.func . S ( " You caught " .. desc ) , false ) end
2015-06-27 15:18:34 +02:00
fishing_setting.func . add_to_trophies ( clicker , self.prize [ 2 ] , desc )
2015-06-26 22:33:51 +02:00
local wear_value = fishing_setting.func . wear_value ( self.prize [ 3 ] )
if inv : room_for_item ( " main " , { name = name , count = 1 , wear = wear_value , metadata = " " } ) then
inv : add_item ( " main " , { name = name , count = 1 , wear = wear_value , metadata = " " } )
else
minetest.spawn_item ( clicker : getpos ( ) , { name = name , count = 1 , wear = wear_value , metadata = " " } )
end
2015-04-16 21:33:56 +02:00
end
end
-- weither player has fishing pole or not
minetest.sound_play ( " fishing_bobber1 " , { pos = self.object : getpos ( ) , gain = 0.5 , } )
self.object : remove ( )
2015-06-26 22:33:51 +02:00
elseif item_name == " fishing:baitball " then
2015-04-16 21:33:56 +02:00
if not fishing_setting.is_creative_mode then
2015-06-16 01:42:05 +02:00
inv : remove_item ( " main " , " fishing:baitball " )
2015-04-16 21:33:56 +02:00
end
2015-06-16 01:42:05 +02:00
self.baitball = 20
2015-04-16 21:33:56 +02:00
--addparticle
minetest.add_particlespawner ( 30 , 0.5 , -- for how long (?) -- Particles on splash
{ x = pos.x , y = pos.y - 0.0625 , z = pos.z } , { x = pos.x , y = pos.y , z = pos.z } , -- position min, pos max
{ x =- 2 , y =- 0.0625 , z =- 2 } , { x = 2 , y = 3 , z = 2 } , -- velocity min, vel max
{ x = 0 , y =- 9.8 , z = 0 } , { x = 0 , y =- 9.8 , z = 0 } ,
0.3 , 1.2 ,
0.25 , 0.5 , -- min size, max size
2015-06-16 01:42:05 +02:00
false , " fishing_particle_baitball.png " )
2015-04-16 21:33:56 +02:00
-- add sound
2015-07-04 19:24:25 +02:00
minetest.sound_play ( " fishing_baitball " , { pos = self.object : getpos ( ) , gain = 0.2 , } )
2015-04-16 21:33:56 +02:00
end
end ,
2015-06-26 22:33:51 +02:00
2015-04-16 21:33:56 +02:00
-- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
on_step = function ( self , dtime )
local pos = self.object : getpos ( )
2015-06-09 23:09:47 +02:00
--remove if no owner, no player, owner no in bobber_view_range
2015-04-16 21:33:56 +02:00
if self.owner == nil then self.object : remove ( ) ; return end
2015-06-17 02:18:12 +02:00
--remove if not node water
local node = minetest.get_node_or_nil ( { x = pos.x , y = pos.y - 0.5 , z = pos.z } )
if not node or string.find ( node.name , " water_source " ) == nil then
2015-06-26 22:33:51 +02:00
if fishing_setting.settings [ " message " ] == true then minetest.chat_send_player ( self.owner , " Haha, Fishing is prohibited outside water! " ) end
2015-06-17 02:18:12 +02:00
self.object : remove ( )
return
end
2015-04-16 21:33:56 +02:00
local player = minetest.get_player_by_name ( self.owner )
if not player then self.object : remove ( ) ; return end
local p = player : getpos ( )
2015-06-09 23:09:47 +02:00
local dist = ( ( p.x - pos.x ) ^ 2 + ( p.y - pos.y ) ^ 2 + ( p.z - pos.z ) ^ 2 ) ^ 0.5
if dist > fishing_setting.settings [ " bobber_view_range " ] then
2015-04-16 21:33:56 +02:00
minetest.sound_play ( " fishing_bobber1 " , { pos = self.object : getpos ( ) , gain = 0.5 , } )
self.object : remove ( )
return
end
2015-06-26 22:33:51 +02:00
2015-04-16 21:33:56 +02:00
--rotate bobber
if math.random ( 1 , 4 ) == 1 then
self.object : setyaw ( self.object : getyaw ( ) + ( ( math.random ( 0 , 360 ) - 180 ) / 2880 * math.pi ) )
end
2015-06-26 22:33:51 +02:00
2015-04-16 21:33:56 +02:00
self.timer = self.timer + 1
if self.timer < self.randomtime then
2015-06-09 23:09:47 +02:00
-- if fish or others items, move bobber to simulate fish on the line
if self.prize ~= " " and math.random ( 1 , 3 ) == 1 then
if self.old_pos2 == true then
2015-08-20 16:08:03 +02:00
pos.y = pos.y - 0.0280
2015-06-09 23:09:47 +02:00
self.object : moveto ( pos , false )
self.old_pos2 = false
else
2015-08-20 16:08:03 +02:00
pos.y = pos.y + 0.0280
2015-06-09 23:09:47 +02:00
self.object : moveto ( pos , false )
self.old_pos2 = true
2015-04-16 21:33:56 +02:00
end
end
2015-06-26 22:33:51 +02:00
return
2015-04-16 21:33:56 +02:00
end
2015-06-26 22:33:51 +02:00
2015-06-09 23:09:47 +02:00
--change item on line
2015-04-16 21:33:56 +02:00
self.timer = 0
2015-06-09 23:09:47 +02:00
self.prize = " "
2015-04-16 21:33:56 +02:00
self.object : moveto ( self.old_pos , false )
2015-06-16 01:42:05 +02:00
--Once the fish are not hungry :), baitball increase hungry + 20%
if math.random ( 1 , 100 ) > fishing_setting.baits [ self.bait ] [ " hungry " ] + self.baitball then
--Fish not hungry !(
self.randomtime = math.random ( 20 , 60 ) * 10
2015-04-16 21:33:56 +02:00
return
end
2015-06-26 22:33:51 +02:00
2015-06-16 01:42:05 +02:00
self.randomtime = math.random ( 1 , 5 ) * 10
2015-06-17 02:18:12 +02:00
if math.random ( 1 , 100 ) <= fishing_setting.settings [ " fish_chance " ] then
2015-06-16 01:42:05 +02:00
self.prize = fishing_setting.prizes [ " fish " ] [ math.random ( 1 , # fishing_setting.prizes [ " fish " ] ) ]
2015-06-09 23:09:47 +02:00
else
if math.random ( 1 , 100 ) <= 10 then
2015-08-20 16:08:03 +02:00
self.prize = fishing_setting.func . get_loot ( )
2015-06-09 23:09:47 +02:00
end
2015-04-16 21:33:56 +02:00
end
2015-06-26 22:33:51 +02:00
2015-06-16 01:42:05 +02:00
if self.prize ~= " " then
2015-04-16 21:33:56 +02:00
pos.y = self.old_pos . y - 0.1
self.object : moveto ( pos , false )
minetest.sound_play ( " fishing_bobber1 " , { pos = pos , gain = 0.5 , } )
2015-06-09 23:09:47 +02:00
end
2015-04-16 21:33:56 +02:00
end ,
}
2015-06-26 22:33:51 +02:00
minetest.register_entity ( " fishing:bobber_fish_entity " , FISHING_BOBBER_ENTITY )