forked from VoxeLibre/VoxeLibre
[mcl_fishing] fix warnings
This commit is contained in:
parent
82396bd994
commit
a1acf6d3c1
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
local S = minetest.get_translator("mcl_fishing")
|
local S = minetest.get_translator("mcl_fishing")
|
||||||
|
|
||||||
|
local math = math
|
||||||
|
|
||||||
local bobber_ENTITY={
|
local bobber_ENTITY={
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer=0,
|
||||||
|
@ -31,143 +33,141 @@ local fish = function(itemstack, player, pointed_thing)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 125)
|
local objs = minetest.get_objects_inside_radius(pos, 125)
|
||||||
local num = 0
|
local ent
|
||||||
local ent = nil
|
local noent = false
|
||||||
local noent = true
|
|
||||||
|
|
||||||
local durability = 65
|
|
||||||
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
|
|
||||||
if unbreaking > 0 then
|
|
||||||
durability = durability * (unbreaking + 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
--Check for bobber if so handle.
|
local durability = 65
|
||||||
for n = 1, #objs do
|
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
|
||||||
ent = objs[n]:get_luaentity()
|
if unbreaking > 0 then
|
||||||
if ent then
|
durability = durability * (unbreaking + 1)
|
||||||
if ent.player and ent.objtype=="fishing" then
|
end
|
||||||
if (player:get_player_name() == ent.player) then
|
|
||||||
noent = false
|
|
||||||
if ent._dive == true then
|
|
||||||
local itemname
|
|
||||||
local items
|
|
||||||
local itemcount = 1
|
|
||||||
local pr = PseudoRandom(os.time() * math.random(1, 100))
|
|
||||||
local r = pr:next(1, 100)
|
|
||||||
local fish_values = {85, 84.8, 84.7, 84.5}
|
|
||||||
local junk_values = {10, 8.1, 6.1, 4.2}
|
|
||||||
local luck_of_the_sea = math.min(mcl_enchanting.get_enchantment(itemstack, "luck_of_the_sea"), 3)
|
|
||||||
local index = luck_of_the_sea + 1
|
|
||||||
local fish_value = fish_values[index]
|
|
||||||
local junk_value = junk_values[index] + fish_value
|
|
||||||
if r <= fish_value then
|
|
||||||
-- Fish
|
|
||||||
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)
|
|
||||||
elseif r <= junk_value then
|
|
||||||
-- Junk
|
|
||||||
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 = "mcl_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: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)
|
|
||||||
else
|
|
||||||
-- Treasure
|
|
||||||
items = mcl_loot.get_loot({
|
|
||||||
items = {
|
|
||||||
-- TODO: Enchanted Bow
|
|
||||||
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
|
||||||
{ itemstack = mcl_enchanting.get_randomly_enchanted_book(30, true, true)},
|
|
||||||
-- TODO: Enchanted Fishing Rod
|
|
||||||
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
|
||||||
{ itemstring = "mcl_mobs:nametag", },
|
|
||||||
{ itemstring = "mcl_mobitems:saddle", },
|
|
||||||
{ itemstring = "mcl_flowers:waterlily", },
|
|
||||||
}
|
|
||||||
}, pr)
|
|
||||||
end
|
|
||||||
local item
|
|
||||||
if #items >= 1 then
|
|
||||||
item = ItemStack(items[1])
|
|
||||||
else
|
|
||||||
item = ItemStack()
|
|
||||||
end
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
if inv:room_for_item("main", item) then
|
|
||||||
inv:add_item("main", item)
|
|
||||||
else
|
|
||||||
minetest.add_item(pos, item)
|
|
||||||
end
|
|
||||||
if mcl_experience.throw_experience then
|
|
||||||
mcl_experience.throw_experience(pos, math.random(1,6))
|
|
||||||
end
|
|
||||||
|
|
||||||
if not minetest.is_creative_enabled(player:get_player_name()) then
|
--Check for bobber if so handle.
|
||||||
local idef = itemstack:get_definition()
|
for n = 1, #objs do
|
||||||
itemstack:add_wear(65535/durability) -- 65 uses
|
ent = objs[n]:get_luaentity()
|
||||||
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
|
if ent then
|
||||||
minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true)
|
if ent.player and ent.objtype=="fishing" then
|
||||||
end
|
if (player:get_player_name() == ent.player) then
|
||||||
|
if ent._dive == true then
|
||||||
|
local items
|
||||||
|
local pr = PseudoRandom(os.time() * math.random(1, 100))
|
||||||
|
local r = pr:next(1, 100)
|
||||||
|
local fish_values = {85, 84.8, 84.7, 84.5}
|
||||||
|
local junk_values = {10, 8.1, 6.1, 4.2}
|
||||||
|
local luck_of_the_sea = math.min(mcl_enchanting.get_enchantment(itemstack, "luck_of_the_sea"), 3)
|
||||||
|
local index = luck_of_the_sea + 1
|
||||||
|
local fish_value = fish_values[index]
|
||||||
|
local junk_value = junk_values[index] + fish_value
|
||||||
|
if r <= fish_value then
|
||||||
|
-- Fish
|
||||||
|
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)
|
||||||
|
elseif r <= junk_value then
|
||||||
|
-- Junk
|
||||||
|
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 = "mcl_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: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)
|
||||||
|
else
|
||||||
|
-- Treasure
|
||||||
|
items = mcl_loot.get_loot({
|
||||||
|
items = {
|
||||||
|
-- TODO: Enchanted Bow
|
||||||
|
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
||||||
|
{ itemstack = mcl_enchanting.get_randomly_enchanted_book(30, true, true)},
|
||||||
|
-- TODO: Enchanted Fishing Rod
|
||||||
|
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
||||||
|
{ itemstring = "mcl_mobs:nametag", },
|
||||||
|
{ itemstring = "mcl_mobitems:saddle", },
|
||||||
|
{ itemstring = "mcl_flowers:waterlily", },
|
||||||
|
}
|
||||||
|
}, pr)
|
||||||
|
end
|
||||||
|
local item
|
||||||
|
if #items >= 1 then
|
||||||
|
item = ItemStack(items[1])
|
||||||
|
else
|
||||||
|
item = ItemStack()
|
||||||
|
end
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
if inv:room_for_item("main", item) then
|
||||||
|
inv:add_item("main", item)
|
||||||
|
else
|
||||||
|
minetest.add_item(pos, item)
|
||||||
|
end
|
||||||
|
if mcl_experience.throw_experience then
|
||||||
|
mcl_experience.throw_experience(pos, math.random(1,6))
|
||||||
|
end
|
||||||
|
|
||||||
|
if not minetest.is_creative_enabled(player:get_player_name()) then
|
||||||
|
local idef = itemstack:get_definition()
|
||||||
|
itemstack:add_wear(65535/durability) -- 65 uses
|
||||||
|
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
|
||||||
|
minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Check if object is on land.
|
|
||||||
local epos = ent.object:get_pos()
|
|
||||||
epos.y = math.floor(epos.y)
|
|
||||||
local node = minetest.get_node(epos)
|
|
||||||
local def = minetest.registered_nodes[node.name]
|
|
||||||
if def.walkable then
|
|
||||||
if not minetest.is_creative_enabled(player:get_player_name()) then
|
|
||||||
local idef = itemstack:get_definition()
|
|
||||||
itemstack:add_wear((65535/durability)*2) -- if so and not creative then wear double like in MC.
|
|
||||||
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
|
|
||||||
minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--Destroy bobber.
|
|
||||||
ent.object:remove()
|
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
|
--Check if object is on land.
|
||||||
|
local epos = ent.object:get_pos()
|
||||||
|
epos.y = math.floor(epos.y)
|
||||||
|
local node = minetest.get_node(epos)
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
if def.walkable then
|
||||||
|
if not minetest.is_creative_enabled(player:get_player_name()) then
|
||||||
|
local idef = itemstack:get_definition()
|
||||||
|
itemstack:add_wear((65535/durability)*2) -- if so and not creative then wear double like in MC.
|
||||||
|
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
|
||||||
|
minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--Destroy bobber.
|
||||||
|
ent.object:remove()
|
||||||
|
noent = false
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Check for flying bobber.
|
end
|
||||||
for n = 1, #objs do
|
--Check for flying bobber.
|
||||||
ent = objs[n]:get_luaentity()
|
for n = 1, #objs do
|
||||||
if ent then
|
ent = objs[n]:get_luaentity()
|
||||||
if ent._thrower and ent.objtype=="fishing" then
|
if ent then
|
||||||
if player:get_player_name() == ent._thrower then
|
if ent._thrower and ent.objtype=="fishing" then
|
||||||
noent = false
|
if player:get_player_name() == ent._thrower then
|
||||||
break
|
noent = false
|
||||||
end
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--If no bobber or flying_bobber exists then throw bobber.
|
end
|
||||||
if noent == true then
|
--If no bobber or flying_bobber exists then throw bobber.
|
||||||
local playerpos = player:get_pos()
|
if noent then
|
||||||
local dir = player:get_look_dir()
|
local playerpos = player:get_pos()
|
||||||
mcl_throwing.throw("mcl_fishing:flying_bobber", {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, 15, player:get_player_name())
|
local dir = player:get_look_dir()
|
||||||
end
|
mcl_throwing.throw("mcl_fishing:flying_bobber", {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, 15, player:get_player_name())
|
||||||
|
end
|
||||||
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Movement function of bobber
|
-- Movement function of bobber
|
||||||
|
@ -334,13 +334,11 @@ minetest.register_entity("mcl_fishing:flying_bobber_entity", flying_bobber_ENTIT
|
||||||
|
|
||||||
mcl_throwing.register_throwable_object("mcl_fishing:flying_bobber", "mcl_fishing:flying_bobber_entity", 5)
|
mcl_throwing.register_throwable_object("mcl_fishing:flying_bobber", "mcl_fishing:flying_bobber_entity", 5)
|
||||||
|
|
||||||
-- If player leaves area, remove bobber.
|
local function remove_bobber(player)
|
||||||
minetest.register_on_leaveplayer(function(player)
|
|
||||||
local objs = minetest.get_objects_inside_radius(player:get_pos(), 250)
|
local objs = minetest.get_objects_inside_radius(player:get_pos(), 250)
|
||||||
local ent = nil
|
|
||||||
local noent = true
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
ent = objs[n]:get_luaentity()
|
local ent = objs[n]:get_luaentity()
|
||||||
if ent then
|
if ent then
|
||||||
if ent.player and ent.objtype=="fishing" then
|
if ent.player and ent.objtype=="fishing" then
|
||||||
ent.object:remove()
|
ent.object:remove()
|
||||||
|
@ -349,26 +347,13 @@ minetest.register_on_leaveplayer(function(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
-- If player leaves area, remove bobber.
|
||||||
|
minetest.register_on_leaveplayer(remove_bobber)
|
||||||
|
|
||||||
-- If player dies, remove bobber.
|
-- If player dies, remove bobber.
|
||||||
minetest.register_on_dieplayer(function(player)
|
minetest.register_on_dieplayer(remove_bobber)
|
||||||
local objs = minetest.get_objects_inside_radius(player:get_pos(), 250)
|
|
||||||
local num = 0
|
|
||||||
local ent = nil
|
|
||||||
local noent = true
|
|
||||||
|
|
||||||
for n = 1, #objs do
|
|
||||||
ent = objs[n]:get_luaentity()
|
|
||||||
if ent then
|
|
||||||
if ent.player and ent.objtype=="fishing" then
|
|
||||||
ent.object:remove()
|
|
||||||
elseif ent._thrower and ent.objtype=="fishing" then
|
|
||||||
ent.object:remove()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Fishing Rod
|
-- Fishing Rod
|
||||||
minetest.register_tool("mcl_fishing:fishing_rod", {
|
minetest.register_tool("mcl_fishing:fishing_rod", {
|
||||||
|
|
Loading…
Reference in New Issue