mirror of
https://github.com/MinetestForFun/fishing.git
synced 2025-07-23 02:20:25 +02:00
finished rewriting
This commit is contained in:
73
bobber.lua
73
bobber.lua
@ -1,3 +1,10 @@
|
||||
-----------------------------------------------------------------------------------------------
|
||||
-- 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
|
||||
-----------------------------------------------------------------------------------------------
|
||||
|
||||
-- bobber
|
||||
minetest.register_node("fishing:bobber_box", {
|
||||
@ -7,8 +14,8 @@ minetest.register_node("fishing:bobber_box", {
|
||||
fixed = {
|
||||
-- { left, bottom, front, right, top , back}
|
||||
{-8/16, -8/16, 0, 8/16, 8/16, 0}, -- feathers
|
||||
{-2/16, -8/16, -2/16, 2/16, -4/16, 2/16}, -- bobber
|
||||
}
|
||||
{-2/16, -8/16, -2/16, 2/16, -4/16, 2/16}, -- bobber
|
||||
},
|
||||
},
|
||||
tiles = {
|
||||
"fishing_bobber_top.png",
|
||||
@ -32,57 +39,61 @@ local FISHING_BOBBER_ENTITY={
|
||||
visual_size = {x=1/3, y=1/3, z=1/3},
|
||||
textures = {"fishing:bobber_box"},
|
||||
-- {left ,bottom, front, right, top , back}
|
||||
collisionbox = {-2/16, -4/16, -2/16, 2/16, 0/16, 2/16},
|
||||
collisionbox = {-2/16, -4/16, -2/16, 2/16, 1/16, 2/16},
|
||||
randomtime = 50,
|
||||
baitball = 0,
|
||||
prize = "",
|
||||
bait = "",
|
||||
|
||||
|
||||
-- DESTROY BOBBER WHEN PUNCHING IT
|
||||
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()
|
||||
if player ~= self.owner then return end
|
||||
if fishing_setting.settings["message"] == true then minetest.chat_send_player(player, fishing_setting.func.S("You didn't prizes anything."), false) end
|
||||
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
|
||||
if not fishing_setting.is_creative_mode then
|
||||
local inv = puncher:get_inventory()
|
||||
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=""})
|
||||
if fishing_setting.settings["message"] == true then minetest.chat_send_player(player, fishing_setting.func.S("The bait is still there."), false) end
|
||||
if fishing_setting.settings["message"] == true then minetest.chat_send_player(playername, fishing_setting.func.S("The bait is still there."), false) end
|
||||
end
|
||||
end
|
||||
-- make sound and remove bobber
|
||||
minetest.sound_play("fishing_bobber1", { pos = self.object:getpos(), gain = 0.5, })
|
||||
self.object:remove()
|
||||
end,
|
||||
|
||||
|
||||
|
||||
|
||||
-- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
|
||||
on_rightclick = function (self, clicker)
|
||||
local item = clicker:get_wielded_item()
|
||||
local player = clicker:get_player_name()
|
||||
local playername = clicker:get_player_name()
|
||||
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
|
||||
if player ~= self.owner then return end
|
||||
if playername ~= self.owner then return end
|
||||
if self.prize ~= "" then
|
||||
local name = self.prize[1]..":"..self.prize[2]
|
||||
local desc = self.prize[4]
|
||||
minetest.chat_send_player(player, "You caught "..desc, false)
|
||||
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=""})
|
||||
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
|
||||
else
|
||||
minetest.spawn_item(clicker:getpos(), {name=name, count=1, wear=wear_value, metadata=""})
|
||||
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
|
||||
fishing_setting.func.add_to_trophies(clicker, self.prize[2])
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
-- weither player has fishing pole or not
|
||||
minetest.sound_play("fishing_bobber1", { pos = self.object:getpos(), gain = 0.5, })
|
||||
self.object:remove()
|
||||
|
||||
elseif item:get_name() == "fishing:baitball" then
|
||||
|
||||
elseif item_name == "fishing:baitball" then
|
||||
if not fishing_setting.is_creative_mode then
|
||||
inv:remove_item("main", "fishing:baitball")
|
||||
end
|
||||
@ -99,8 +110,8 @@ local FISHING_BOBBER_ENTITY={
|
||||
minetest.sound_play("fishing_bobber1", {pos = self.object:getpos(), gain = 0.2, })
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
|
||||
|
||||
-- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
|
||||
on_step = function(self, dtime)
|
||||
local pos = self.object:getpos()
|
||||
@ -109,7 +120,7 @@ local FISHING_BOBBER_ENTITY={
|
||||
--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
|
||||
minetest.chat_send_player(self.owner, "Haha, Fishing is prohibited outside water!")
|
||||
if fishing_setting.settings["message"] == true then minetest.chat_send_player(self.owner, "Haha, Fishing is prohibited outside water!") end
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
@ -122,12 +133,12 @@ local FISHING_BOBBER_ENTITY={
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--rotate bobber
|
||||
if math.random(1, 4) == 1 then
|
||||
self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
|
||||
end
|
||||
|
||||
|
||||
self.timer = self.timer + 1
|
||||
if self.timer < self.randomtime then
|
||||
-- if fish or others items, move bobber to simulate fish on the line
|
||||
@ -142,9 +153,9 @@ local FISHING_BOBBER_ENTITY={
|
||||
self.old_pos2 = true
|
||||
end
|
||||
end
|
||||
return
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--change item on line
|
||||
self.timer = 0
|
||||
self.prize = ""
|
||||
@ -155,7 +166,7 @@ local FISHING_BOBBER_ENTITY={
|
||||
self.randomtime = math.random(20,60)*10
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
self.randomtime = math.random(1,5)*10
|
||||
if math.random(1, 100) <= fishing_setting.settings["fish_chance"] then
|
||||
self.prize = fishing_setting.prizes["fish"][math.random(1,#fishing_setting.prizes["fish"])]
|
||||
@ -164,7 +175,7 @@ local FISHING_BOBBER_ENTITY={
|
||||
self.prize = fishing_setting.prizes["plants"][math.random(1,#fishing_setting.prizes["plants"])]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if self.prize ~= "" then
|
||||
pos.y = self.old_pos.y-0.1
|
||||
self.object:moveto(pos, false)
|
||||
@ -173,4 +184,4 @@ local FISHING_BOBBER_ENTITY={
|
||||
end,
|
||||
}
|
||||
|
||||
minetest.register_entity("fishing:bobber_entity", FISHING_BOBBER_ENTITY)
|
||||
minetest.register_entity("fishing:bobber_fish_entity", FISHING_BOBBER_ENTITY)
|
||||
|
Reference in New Issue
Block a user