mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
[mcl_fishing] fix warnings
This commit is contained in:
parent
82396bd994
commit
a1acf6d3c1
1 changed files with 133 additions and 148 deletions
|
@ -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 durability = 65
|
||||||
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
|
local unbreaking = mcl_enchanting.get_enchantment(itemstack, "unbreaking")
|
||||||
if unbreaking > 0 then
|
if unbreaking > 0 then
|
||||||
durability = durability * (unbreaking + 1)
|
durability = durability * (unbreaking + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Check for bobber if so handle.
|
--Check for bobber if so handle.
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
ent = objs[n]:get_luaentity()
|
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
|
||||||
if (player:get_player_name() == ent.player) then
|
if (player:get_player_name() == ent.player) then
|
||||||
noent = false
|
if ent._dive == true then
|
||||||
if ent._dive == true then
|
local items
|
||||||
local itemname
|
local pr = PseudoRandom(os.time() * math.random(1, 100))
|
||||||
local items
|
local r = pr:next(1, 100)
|
||||||
local itemcount = 1
|
local fish_values = {85, 84.8, 84.7, 84.5}
|
||||||
local pr = PseudoRandom(os.time() * math.random(1, 100))
|
local junk_values = {10, 8.1, 6.1, 4.2}
|
||||||
local r = pr:next(1, 100)
|
local luck_of_the_sea = math.min(mcl_enchanting.get_enchantment(itemstack, "luck_of_the_sea"), 3)
|
||||||
local fish_values = {85, 84.8, 84.7, 84.5}
|
local index = luck_of_the_sea + 1
|
||||||
local junk_values = {10, 8.1, 6.1, 4.2}
|
local fish_value = fish_values[index]
|
||||||
local luck_of_the_sea = math.min(mcl_enchanting.get_enchantment(itemstack, "luck_of_the_sea"), 3)
|
local junk_value = junk_values[index] + fish_value
|
||||||
local index = luck_of_the_sea + 1
|
if r <= fish_value then
|
||||||
local fish_value = fish_values[index]
|
-- Fish
|
||||||
local junk_value = junk_values[index] + fish_value
|
items = mcl_loot.get_loot({
|
||||||
if r <= fish_value then
|
items = {
|
||||||
-- Fish
|
{ itemstring = "mcl_fishing:fish_raw", weight = 60 },
|
||||||
items = mcl_loot.get_loot({
|
{ itemstring = "mcl_fishing:salmon_raw", weight = 25 },
|
||||||
items = {
|
{ itemstring = "mcl_fishing:clownfish_raw", weight = 2 },
|
||||||
{ itemstring = "mcl_fishing:fish_raw", weight = 60 },
|
{ itemstring = "mcl_fishing:pufferfish_raw", weight = 13 },
|
||||||
{ itemstring = "mcl_fishing:salmon_raw", weight = 25 },
|
}
|
||||||
{ itemstring = "mcl_fishing:clownfish_raw", weight = 2 },
|
}, pr)
|
||||||
{ itemstring = "mcl_fishing:pufferfish_raw", weight = 13 },
|
elseif r <= junk_value then
|
||||||
}
|
-- Junk
|
||||||
}, pr)
|
items = mcl_loot.get_loot({
|
||||||
elseif r <= junk_value then
|
items = {
|
||||||
-- Junk
|
{ itemstring = "mcl_core:bowl", weight = 10 },
|
||||||
items = mcl_loot.get_loot({
|
{ itemstring = "mcl_fishing:fishing_rod", weight = 2, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
|
||||||
items = {
|
{ itemstring = "mcl_mobitems:leather", weight = 10 },
|
||||||
{ itemstring = "mcl_core:bowl", weight = 10 },
|
{ itemstring = "mcl_armor:boots_leather", weight = 10, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
|
||||||
{ itemstring = "mcl_fishing:fishing_rod", weight = 2, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
|
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10 },
|
||||||
{ itemstring = "mcl_mobitems:leather", weight = 10 },
|
{ itemstring = "mcl_core:stick", weight = 5 },
|
||||||
{ itemstring = "mcl_armor:boots_leather", weight = 10, wear_min = 6554, wear_max = 65535 }, -- 10%-100% damage
|
{ itemstring = "mcl_mobitems:string", weight = 5 },
|
||||||
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10 },
|
{ itemstring = "mcl_potions:water", weight = 10 },
|
||||||
{ itemstring = "mcl_core:stick", weight = 5 },
|
{ itemstring = "mcl_mobitems:bone", weight = 10 },
|
||||||
{ itemstring = "mcl_mobitems:string", weight = 5 },
|
{ itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 },
|
||||||
{ itemstring = "mcl_potions:water", weight = 10 },
|
{ itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook
|
||||||
{ itemstring = "mcl_mobitems:bone", weight = 10 },
|
}
|
||||||
{ itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 },
|
}, pr)
|
||||||
{ itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook
|
else
|
||||||
}
|
-- Treasure
|
||||||
}, pr)
|
items = mcl_loot.get_loot({
|
||||||
else
|
items = {
|
||||||
-- Treasure
|
-- TODO: Enchanted Bow
|
||||||
items = mcl_loot.get_loot({
|
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
||||||
items = {
|
{ itemstack = mcl_enchanting.get_randomly_enchanted_book(30, true, true)},
|
||||||
-- TODO: Enchanted Bow
|
-- TODO: Enchanted Fishing Rod
|
||||||
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
||||||
{ itemstack = mcl_enchanting.get_randomly_enchanted_book(30, true, true)},
|
{ itemstring = "mcl_mobs:nametag", },
|
||||||
-- TODO: Enchanted Fishing Rod
|
{ itemstring = "mcl_mobitems:saddle", },
|
||||||
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage
|
{ itemstring = "mcl_flowers:waterlily", },
|
||||||
{ itemstring = "mcl_mobs:nametag", },
|
}
|
||||||
{ itemstring = "mcl_mobitems:saddle", },
|
}, pr)
|
||||||
{ itemstring = "mcl_flowers:waterlily", },
|
end
|
||||||
}
|
local item
|
||||||
}, pr)
|
if #items >= 1 then
|
||||||
end
|
item = ItemStack(items[1])
|
||||||
local item
|
else
|
||||||
if #items >= 1 then
|
item = ItemStack()
|
||||||
item = ItemStack(items[1])
|
end
|
||||||
else
|
local inv = player:get_inventory()
|
||||||
item = ItemStack()
|
if inv:room_for_item("main", item) then
|
||||||
end
|
inv:add_item("main", item)
|
||||||
local inv = player:get_inventory()
|
else
|
||||||
if inv:room_for_item("main", item) then
|
minetest.add_item(pos, item)
|
||||||
inv:add_item("main", item)
|
end
|
||||||
else
|
if mcl_experience.throw_experience then
|
||||||
minetest.add_item(pos, item)
|
mcl_experience.throw_experience(pos, math.random(1,6))
|
||||||
end
|
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
|
if not minetest.is_creative_enabled(player:get_player_name()) then
|
||||||
local idef = itemstack:get_definition()
|
local idef = itemstack:get_definition()
|
||||||
itemstack:add_wear(65535/durability) -- 65 uses
|
itemstack:add_wear(65535/durability) -- 65 uses
|
||||||
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
|
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)
|
minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true)
|
||||||
end
|
|
||||||
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 a new issue