From d820c35937f4b198b3324a7648ac532d235c3142 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 20 Dec 2020 17:33:24 +0100 Subject: [PATCH] Fishing & Mineshaft loot --- mods/CORE/mcl_loot/init.lua | 40 +++++++++++++++++----------- mods/ITEMS/mcl_enchanting/engine.lua | 17 ++++++++++++ mods/ITEMS/mcl_fishing/init.lua | 3 +-- mods/MAPGEN/mcl_dungeons/init.lua | 3 +-- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/mods/CORE/mcl_loot/init.lua b/mods/CORE/mcl_loot/init.lua index 35c72539d..cb371c284 100644 --- a/mods/CORE/mcl_loot/init.lua +++ b/mods/CORE/mcl_loot/init.lua @@ -11,12 +11,15 @@ Parameters: stacks_max = 3, -- Maximum number of item stacks to get. Default: 1 items = { -- Table of possible loot items. This function selects between stacks_min and stacks_max of these. { + weight = 5, -- Likelihood of this item being selected (see below). Optional (default: 1) + + itemstack = ItemStack("example:item1"), -- Itemstack to select + -- OR itemstring = "example:item1", -- Which item to select amount_min = 1, -- Minimum size of itemstack. Must not be larger than 6553. Optional (default: 1) amount_max = 10, -- Maximum size of item stack. Must not be larger than item definition's stack_max or 6553. Optional (default: 1) wear_min = 1, -- Minimum wear value. Must be at least 1. Optional (default: no wear) wear_max = 1, -- Maxiumum wear value. Must be at least 1. Optional (default: no wear) - weight = 5, -- Likelihood of this item being selected (see below). Optional (default: 1) }, { -- more tables like above, one table per item stack } } @@ -56,24 +59,29 @@ function mcl_loot.get_loot(loot_definitions, pr) end if item then local itemstring = item.itemstring - if item.amount_min and item.amount_max then - itemstring = itemstring .. " " .. pr:next(item.amount_min, item.amount_max) - end - if item.wear_min and item.wear_max then - -- Sadly, PseudoRandom only allows very narrow ranges, so we set wear in steps of 10 - local wear_min = math.floor(item.wear_min / 10) - local wear_max = math.floor(item.wear_max / 10) - local wear = pr:next(wear_min, wear_max) * 10 - - if not item.amount_min and not item.amount_max then - itemstring = itemstring .. " 1" + local itemstack = item.itemstack + if itemstring then + if item.amount_min and item.amount_max then + itemstring = itemstring .. " " .. pr:next(item.amount_min, item.amount_max) end + if item.wear_min and item.wear_max then + -- Sadly, PseudoRandom only allows very narrow ranges, so we set wear in steps of 10 + local wear_min = math.floor(item.wear_min / 10) + local wear_max = math.floor(item.wear_max / 10) + local wear = pr:next(wear_min, wear_max) * 10 + + if not item.amount_min and not item.amount_max then + itemstring = itemstring .. " 1" + end - itemstring = itemstring .. " " .. tostring(wear) + itemstring = itemstring .. " " .. tostring(wear) + end + table.insert(items, itemstring) + elseif itemstack then + table.insert(items, itemstack) + else + minetest.log("error", "[mcl_loot] INTERNAL ERROR! Failed to select random loot item!") end - table.insert(items, itemstring) - else - minetest.log("error", "[mcl_loot] INTERNAL ERROR! Failed to select random loot item!") end end diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 0746d211a..9956aca15 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -320,6 +320,23 @@ function mcl_enchanting.get_randomly_enchanted_book(enchantment_level, treasure, return mcl_enchanting.enchant_randomly(enchantment_level, treasure, no_reduced_bonus_chance) end +function mcl_enchanting.get_uniform_randomly_enchanted_book(except) + except = except or except + local stack = ItemStack("mcl_enchanting:book_enchanted") + local list = {} + for enchantment in pairs(mcl_enchanting.enchantments) do + if table.indexof(except, enchantment) == -1 then + table.insert(list, enchantment) + end + end + local index = math.random(#list) + local enchantment = list[index] + local enchantment_def = mcl_enchanting.enchantments[enchantment] + local level = math.random(enchantment_def.max_level) + mcl_enchanting.enchant(stack, enchantment, level) + return stack +end + function mcl_enchanting.get_random_glyph_row() local glyphs = "" local x = 1.3 diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 21f549169..bf63a3c5c 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -88,8 +88,7 @@ local fish = function(itemstack, player) items = { -- TODO: Enchanted Bow { itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage - -- TODO: Enchanted Book - { itemstring = "mcl_books:book" }, + { 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", }, diff --git a/mods/MAPGEN/mcl_dungeons/init.lua b/mods/MAPGEN/mcl_dungeons/init.lua index b270e6527..6661b1467 100644 --- a/mods/MAPGEN/mcl_dungeons/init.lua +++ b/mods/MAPGEN/mcl_dungeons/init.lua @@ -21,8 +21,7 @@ local get_loot = function() { itemstring = "mcl_jukebox:record_4", weight = 15 }, { itemstring = "mobs_mc:iron_horse_armor", weight = 15 }, { itemstring = "mcl_core:apple_gold", weight = 15 }, - -- TODO: Enchanted Book - { itemstring = "mcl_books:book", weight = 10 }, + { itemstack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}), weight = 10 }, { itemstring = "mobs_mc:gold_horse_armor", weight = 10 }, { itemstring = "mobs_mc:diamond_horse_armor", weight = 5 }, -- TODO: Enchanted Golden Apple