From 929e202aeb11bb3147c873dbd989776d1636fed4 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 12 Apr 2023 13:50:50 +0100 Subject: [PATCH] fishing rods have 65 uses, add new items to catch, some with item wear --- api.txt | 4 ++++ fishing.lua | 46 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/api.txt b/api.txt index 5b1c96b..370e600 100644 --- a/api.txt +++ b/api.txt @@ -28,6 +28,10 @@ You may also use a table that not only adds an item but the biome it can be foun ethereal.add_item("", "", {"ethereal:crystal_spike", "frost"}) +.. add special item with wear level: + + ethereal.add_item("", "", "default:sword_steel 15000") + Please note that only Ethereal biome names can be used for specific finds, unless mod specifically adds ethereal as an optional dependency. diff --git a/fishing.lua b/fishing.lua index 0fcfe6e..72cbced 100644 --- a/fishing.lua +++ b/fishing.lua @@ -34,22 +34,38 @@ local fish_items = { -- sandstone_desert_ocean, plains_ocean, savanna_ocean, fiery_ocean, swamp_ocean, -- glacier_ocean, tundra_ocean +local mod_bonemeal = minetest.get_modpath("bonemeal") +local mod_armor = minetest.get_modpath("3d_armor") +local mod_mobs = minetest.get_modpath("mobs") + local junk_items = { "ethereal:bowl", "default:stick", "farming:string", "default:papyrus", "dye:black", - {"ethereal:bamboo", "bamboo"} + "flowers:waterlily", + "default:paper", + "flowers:mushroom_red", + "vessels:glass_bottle", + {"ethereal:bamboo", "bamboo"}, + mod_bonemeal and "bonemeal:bone" or "default:stick", + mod_armor and "3d_armor:boots_wood 6000" or "default:stick" } local bonus_items = { - "mobs:nametag", - "mobs:saddle", - "flowers:waterlily", + mod_mobs and "mobs:nametag" or "fireflies:bug_net", + mod_mobs and "mobs:net" or "default:sapling", + "fireflies:firefly_bottle", + mod_mobs and "mobs:saddle" or "farming:cotton_wild", "default:book", + {"ethereal:firethorn", "glacier"}, {"ethereal:crystal_spike", "frost"}, - {"ethereal:banana_bunch", "grove"} + {"ethereal:banana_bunch", "grove"}, + "tnt:tnt_stick", + "bucket:bucket_empty", + "default:sword_steel 12000", + "ethereal:fishing_rod 9000" } local default_item = "default:dirt" @@ -287,7 +303,6 @@ local find_item = function(list, pos) table.insert(items, item[1]) end end - end --print("==biome: " .. biome, dump(items)) @@ -338,14 +353,23 @@ local use_rod = function(itemstack, player, pointed_thing) item = find_item(bonus_items, pos) end + -- split into name and number (wear level or number of items) + local item_name = item:split(" ")[1] + local item_wear = item:split(" ")[2] + -- make sure item exists, if not replace with default item - if not minetest.registered_items[item] then + if not minetest.registered_items[item_name] then item = default_item end --print ("---caught", item, r) - item = ItemStack(item) + item = ItemStack(item) -- convert into itemstack + + -- if tool then add wear + if item_wear and minetest.registered_tools[item_name] then + item:set_wear(65535 - item_wear) + end local inv = player:get_inventory() @@ -394,6 +418,12 @@ local use_rod = function(itemstack, player, pointed_thing) obj:set_acceleration({x = dir.x * -3, y = -9.8, z = dir.z * -3}) obj:get_luaentity().fisher = player and player:get_player_name() end + + -- Add wear to fishing rod (65 uses) + local item = player:get_wielded_item() + + item:add_wear(65535 / 65) + player:set_wielded_item(item) end