1
0
Fork 0

Fishing & Mineshaft loot

objects
Elias Fleckenstein 2020-12-20 17:33:24 +01:00
parent b91b587876
commit d820c35937
4 changed files with 43 additions and 20 deletions

View File

@ -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
itemstring = itemstring .. " " .. tostring(wear)
if not item.amount_min and not item.amount_max then
itemstring = itemstring .. " 1"
end
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

View File

@ -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

View File

@ -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", },

View File

@ -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