Merge remote-tracking branch 'mcl2/master' into testing

This commit is contained in:
kay27 2021-12-09 03:07:00 +04:00
commit ea6d8f9e86
7 changed files with 183 additions and 157 deletions

View File

@ -58,26 +58,27 @@ function mcl_loot.get_loot(loot_definitions, pr)
end end
if item then if item then
local itemstring = item.itemstring local itemstring = item.itemstring
local itemstack = item.itemstack
if itemstring then if itemstring then
local stack = ItemStack(itemstring)
if item.amount_min and item.amount_max then if item.amount_min and item.amount_max then
itemstring = itemstring .. " " .. pr:next(item.amount_min, item.amount_max) stack:set_count(pr:next(item.amount_min, item.amount_max))
end end
if item.wear_min and item.wear_max then if item.wear_min and item.wear_max then
-- Sadly, PseudoRandom only allows very narrow ranges, so we set wear in steps of 10 -- 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_min = math.floor(item.wear_min / 10)
local wear_max = math.floor(item.wear_max / 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 stack:set_wear(pr:next(wear_min, wear_max) * 10)
itemstring = itemstring .. " 1"
end end
itemstring = itemstring .. " " .. tostring(wear) if item.func then
item.func(stack, pr)
end end
table.insert(items, itemstring)
elseif itemstack then table.insert(items, stack)
table.insert(items, itemstack)
else else
minetest.log("error", "[mcl_loot] INTERNAL ERROR! Failed to select random loot item!") minetest.log("error", "[mcl_loot] INTERNAL ERROR! Failed to select random loot item!")
end end

View File

@ -409,7 +409,7 @@ local init_trades = function(self, inv)
local offered_stack = ItemStack({name = offered_item, count = offered_count}) local offered_stack = ItemStack({name = offered_item, count = offered_count})
if mcl_enchanting.is_enchanted(offered_item) then if mcl_enchanting.is_enchanted(offered_item) then
if mcl_enchanting.is_book(offered_item) then if mcl_enchanting.is_book(offered_item) then
offered_stack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}) mcl_enchanting.enchant_uniform_randomly(offered_stack, {"soul_speed"})
else else
mcl_enchanting.enchant_randomly(offered_stack, math.random(5, 19), false, false, true) mcl_enchanting.enchant_randomly(offered_stack, math.random(5, 19), false, false, true)
mcl_enchanting.unload_enchantments(offered_stack) mcl_enchanting.unload_enchantments(offered_stack)

View File

@ -123,7 +123,7 @@ function mcl_enchanting.can_enchant(itemstack, enchantment, level)
if itemname == "" then if itemname == "" then
return false, "item missing" return false, "item missing"
end end
local supported, primary = mcl_enchanting.item_supports_enchantment(itemstack:get_name(), enchantment) local supported, primary = mcl_enchanting.item_supports_enchantment(itemname, enchantment)
if not supported then if not supported then
return false, "item not supported" return false, "item not supported"
end end
@ -295,50 +295,73 @@ function mcl_enchanting.initialize()
end end
end end
function mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure) function mcl_enchanting.random(pr, ...)
local possible_enchantments, weights, accum_weight = {}, {}, 0 local r = pr and pr:next(...) or math.random(...)
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local _, _, _, primary = mcl_enchanting.can_enchant(itemstack, enchantment, 1) if pr and not ({...})[1] then
if primary or treasure then r = r / 32767
table.insert(possible_enchantments, enchantment)
accum_weight = accum_weight + enchantment_def.weight
weights[enchantment] = accum_weight
end
end
return possible_enchantments, weights, accum_weight
end end
function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted) return r
end
function mcl_enchanting.get_random_enchantment(itemstack, treasure, weighted, exclude, pr)
local possible = {}
for enchantment, enchantment_def in pairs(mcl_enchanting.enchantments) do
local can_enchant, _, _, primary = mcl_enchanting.can_enchant(itemstack, enchantment, 1)
if can_enchant and (primary or treasure) and (not exclude or table.indexof(exclude, enchantment) == -1) then
local weight = weighted and enchantment_def.weight or 1
for i = 1, weight do
table.insert(possible, enchantment)
end
end
end
return #possible > 0 and possible[mcl_enchanting.random(pr, 1, #possible)]
end
function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr)
local itemname = itemstack:get_name() local itemname = itemstack:get_name()
if not mcl_enchanting.can_enchant_freshly(itemname) and not ignore_already_enchanted then if not mcl_enchanting.can_enchant_freshly(itemname) and not ignore_already_enchanted then
return return
end end
itemstack = ItemStack(itemstack) itemstack = ItemStack(itemstack)
local enchantability = minetest.get_item_group(itemname, "enchantability") local enchantability = minetest.get_item_group(itemname, "enchantability")
enchantability = 1 + math.random(0, math.floor(enchantability / 4)) + math.random(0, math.floor(enchantability / 4)) enchantability = 1 + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4)) + mcl_enchanting.random(pr, 0, math.floor(enchantability / 4))
enchantment_level = enchantment_level + enchantability enchantment_level = enchantment_level + enchantability
enchantment_level = enchantment_level + enchantment_level * (math.random() + math.random() - 1) * 0.15 enchantment_level = enchantment_level + enchantment_level * (mcl_enchanting.random(pr) + mcl_enchanting.random(pr) - 1) * 0.15
enchantment_level = math.max(math.floor(enchantment_level + 0.5), 1) enchantment_level = math.max(math.floor(enchantment_level + 0.5), 1)
local enchantments = {} local enchantments = {}
local description local description
enchantment_level = enchantment_level * 2 enchantment_level = enchantment_level * 2
repeat repeat
enchantment_level = math.floor(enchantment_level / 2) enchantment_level = math.floor(enchantment_level / 2)
if enchantment_level == 0 then if enchantment_level == 0 then
break break
end end
local possible, weights, accum_weight = mcl_enchanting.get_possible_enchantments(itemstack, enchantment_level, treasure)
local selected_enchantment, enchantment_power local selected_enchantment = mcl_enchanting.get_random_enchantment(itemstack, treasure, true, nil, pr)
if #possible > 0 then
local r = math.random(accum_weight) if not selected_enchantment then
for _, enchantment in ipairs(possible) do
if weights[enchantment] >= r then
selected_enchantment = enchantment
break break
end end
end
local enchantment_def = mcl_enchanting.enchantments[selected_enchantment] local enchantment_def = mcl_enchanting.enchantments[selected_enchantment]
local power_range_table = enchantment_def.power_range_table local power_range_table = enchantment_def.power_range_table
local enchantment_power
for i = enchantment_def.max_level, 1, -1 do for i = enchantment_def.max_level, 1, -1 do
local power_range = power_range_table[i] local power_range = power_range_table[i]
if enchantment_level >= power_range[1] and enchantment_level <= power_range[2] then if enchantment_level >= power_range[1] and enchantment_level <= power_range[2] then
@ -346,64 +369,51 @@ function mcl_enchanting.generate_random_enchantments(itemstack, enchantment_leve
break break
end end
end end
if not description then if not description then
if not enchantment_power then if not enchantment_power then
return return
end end
description = mcl_enchanting.get_enchantment_description(selected_enchantment, enchantment_power) description = mcl_enchanting.get_enchantment_description(selected_enchantment, enchantment_power)
end end
if enchantment_power then if enchantment_power then
enchantments[selected_enchantment] = enchantment_power enchantments[selected_enchantment] = enchantment_power
mcl_enchanting.enchant(itemstack, selected_enchantment, enchantment_power) mcl_enchanting.enchant(itemstack, selected_enchantment, enchantment_power)
end end
else
break until not no_reduced_bonus_chance and mcl_enchanting.random(pr) >= (enchantment_level + 1) / 50
end
until not no_reduced_bonus_chance and math.random() >= (enchantment_level + 1) / 50
return enchantments, description return enchantments, description
end end
function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted) function mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr)
local enchantments local enchantments
repeat repeat
enchantments = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted) enchantments = mcl_enchanting.generate_random_enchantments(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr)
until enchantments until enchantments
return enchantments return enchantments
end end
function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted) function mcl_enchanting.enchant_randomly(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr)
local enchantments = mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted, pr)
mcl_enchanting.set_enchanted_itemstring(itemstack) mcl_enchanting.set_enchanted_itemstring(itemstack)
mcl_enchanting.set_enchantments(itemstack, mcl_enchanting.generate_random_enchantments_reliable(itemstack, enchantment_level, treasure, no_reduced_bonus_chance, ignore_already_enchanted)) mcl_enchanting.set_enchantments(itemstack, enchantments)
return itemstack return itemstack
end end
function mcl_enchanting.get_randomly_enchanted_book(enchantment_level, treasure, no_reduced_bonus_chance) function mcl_enchanting.enchant_uniform_randomly(stack, exclude, pr)
return mcl_enchanting.enchant_randomly(ItemStack("mcl_books:book"), enchantment_level, treasure, no_reduced_bonus_chance, true) local enchantment = mcl_enchanting.get_random_enchantment(stack, true, false, exclude, pr)
if enchantment then
mcl_enchanting.enchant(stack, enchantment, mcl_enchanting.random(pr, 1, mcl_enchanting.enchantments[enchantment].max_level))
end end
function mcl_enchanting.get_uniform_randomly_enchanted_book(except, pr)
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, level
if pr then
index = pr:next(1,#list)
else
index = math.random(#list)
end
local enchantment = list[index]
local enchantment_def = mcl_enchanting.enchantments[enchantment]
if pr then
level = pr:next(1, enchantment_def.max_level)
else
level = math.random(enchantment_def.max_level)
end
mcl_enchanting.enchant(stack, enchantment, level)
return stack return stack
end end

View File

@ -71,7 +71,9 @@ local fish = function(itemstack, player, pointed_thing)
{ itemstring = "mcl_fishing:salmon_raw", weight = 25 }, { itemstring = "mcl_fishing:salmon_raw", weight = 25 },
{ itemstring = "mcl_fishing:clownfish_raw", weight = 2 }, { itemstring = "mcl_fishing:clownfish_raw", weight = 2 },
{ itemstring = "mcl_fishing:pufferfish_raw", weight = 13 }, { itemstring = "mcl_fishing:pufferfish_raw", weight = 13 },
} },
stacks_min = 1,
stacks_max = 1,
}, pr) }, pr)
elseif r <= junk_value then elseif r <= junk_value then
-- Junk -- Junk
@ -88,21 +90,29 @@ local fish = function(itemstack, player, pointed_thing)
{ itemstring = "mcl_mobitems:bone", weight = 10 }, { itemstring = "mcl_mobitems:bone", weight = 10 },
{ itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 }, { itemstring = "mcl_dye:black", weight = 1, amount_min = 10, amount_max = 10 },
{ itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook { itemstring = "mcl_mobitems:string", weight = 10 }, -- TODO: Tripwire Hook
} },
stacks_min = 1,
stacks_max = 1,
}, pr) }, pr)
else else
-- Treasure -- Treasure
items = mcl_loot.get_loot({ items = mcl_loot.get_loot({
items = { items = {
-- TODO: Enchanted Bow { itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535, func = function(stack, pr)
{ itemstring = "mcl_bows:bow", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage mcl_enchanting.enchant_randomly(stack, 30, true, false, false, pr)
{ itemstack = mcl_enchanting.get_randomly_enchanted_book(30, true, true)}, end }, -- 75%-100% damage
-- TODO: Enchanted Fishing Rod { itemstring = "mcl_books:book", func = function(stack, pr)
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535 }, -- 75%-100% damage mcl_enchanting.enchant_randomly(stack, 30, true, true, false, pr)
end },
{ itemstring = "mcl_fishing:fishing_rod", wear_min = 49144, wear_max = 65535, func = function(stack, pr)
mcl_enchanting.enchant_randomly(stack, 30, true, false, false, pr)
end }, -- 75%-100% damage
{ itemstring = "mcl_mobs:nametag", }, { itemstring = "mcl_mobs:nametag", },
{ itemstring = "mcl_mobitems:saddle", }, { itemstring = "mcl_mobitems:saddle", },
{ itemstring = "mcl_flowers:waterlily", }, { itemstring = "mcl_flowers:waterlily", },
} },
stacks_min = 1,
stacks_max = 1,
}, pr) }, pr)
end end
local item local item

View File

@ -63,6 +63,67 @@ local surround_vectors = {
{ x=0, y=0, z=1 }, { x=0, y=0, z=1 },
} }
local loottable =
{
{
stacks_min = 1,
stacks_max = 3,
items = {
{ itemstring = "mcl_mobs:nametag", weight = 20 },
{ itemstring = "mcl_mobitems:saddle", weight = 20 },
{ itemstring = "mcl_jukebox:record_1", weight = 15 },
{ itemstring = "mcl_jukebox:record_4", weight = 15 },
{ itemstring = "mobs_mc:iron_horse_armor", weight = 15 },
{ itemstring = "mcl_core:apple_gold", weight = 15 },
{ itemstring = "mcl_books:book", weight = 10, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
end },
{ itemstring = "mobs_mc:gold_horse_armor", weight = 10 },
{ itemstring = "mobs_mc:diamond_horse_armor", weight = 5 },
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2 },
}
},
{
stacks_min = 1,
stacks_max = 4,
items = {
{ itemstring = "mcl_farming:wheat_item", weight = 20, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:bread", weight = 20 },
{ itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mesecons:redstone", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:beetroot_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:melon_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:pumpkin_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_buckets:bucket_empty", weight = 10 },
{ itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 4 },
},
},
{
stacks_min = 3,
stacks_max = 3,
items = {
{ itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
},
}
}
-- Bonus loot for v6 mapgen: Otherwise unobtainable saplings.
if mg_name == "v6" then
table.insert(loottable, {
stacks_min = 1,
stacks_max = 3,
items = {
{ itemstring = "mcl_core:birchsapling", weight = 1, amount_min = 1, amount_max = 2 },
{ itemstring = "mcl_core:acaciasapling", weight = 1, amount_min = 1, amount_max = 2 },
{ itemstring = "", weight = 6 },
},
})
end
local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param) local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param)
if calls_remaining >= 1 then return end if calls_remaining >= 1 then return end
@ -310,66 +371,6 @@ local function ecb_spawn_dungeon(blockpos, action, calls_remaining, param)
set_node(pos, {name="mcl_chests:chest", param2=facedir}) set_node(pos, {name="mcl_chests:chest", param2=facedir})
local meta = get_meta(pos) local meta = get_meta(pos)
local loottable =
{
{
stacks_min = 1,
stacks_max = 3,
items = {
{ itemstring = "mcl_mobs:nametag", weight = 20 },
{ itemstring = "mcl_mobitems:saddle", weight = 20 },
{ itemstring = "mcl_jukebox:record_1", weight = 15 },
{ itemstring = "mcl_jukebox:record_4", weight = 15 },
{ itemstring = "mobs_mc:iron_horse_armor", weight = 15 },
{ itemstring = "mcl_core:apple_gold", weight = 15 },
{ itemstack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}, pr), weight = 10 },
{ itemstring = "mobs_mc:gold_horse_armor", weight = 10 },
{ itemstring = "mobs_mc:diamond_horse_armor", weight = 5 },
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 2 },
}
},
{
stacks_min = 1,
stacks_max = 4,
items = {
{ itemstring = "mcl_farming:wheat_item", weight = 20, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:bread", weight = 20 },
{ itemstring = "mcl_core:coal_lump", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mesecons:redstone", weight = 15, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_farming:beetroot_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:melon_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_farming:pumpkin_seeds", weight = 10, amount_min = 2, amount_max = 4 },
{ itemstring = "mcl_core:iron_ingot", weight = 10, amount_min = 1, amount_max = 4 },
{ itemstring = "mcl_buckets:bucket_empty", weight = 10 },
{ itemstring = "mcl_core:gold_ingot", weight = 5, amount_min = 1, amount_max = 4 },
},
},
{
stacks_min = 3,
stacks_max = 3,
items = {
{ itemstring = "mcl_mobitems:bone", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:gunpowder", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 10, amount_min = 1, amount_max = 8 },
{ itemstring = "mcl_mobitems:string", weight = 10, amount_min = 1, amount_max = 8 },
},
}
}
-- Bonus loot for v6 mapgen: Otherwise unobtainable saplings.
if mg_name == "v6" then
table_insert(loottable, {
stacks_min = 1,
stacks_max = 3,
items = {
{ itemstring = "mcl_core:birchsapling", weight = 1, amount_min = 1, amount_max = 2 },
{ itemstring = "mcl_core:acaciasapling", weight = 1, amount_min = 1, amount_max = 2 },
{ itemstring = "", weight = 6 },
},
})
end
minetest.log("action", "[mcl_dungeons] Filling chest " .. tostring(c) .. " at " .. minetest.pos_to_string(pos)) minetest.log("action", "[mcl_dungeons] Filling chest " .. tostring(c) .. " at " .. minetest.pos_to_string(pos))
mcl_loot.fill_inventory(meta:get_inventory(), "main", mcl_loot.get_multi_loot(loottable, pr), pr) mcl_loot.fill_inventory(meta:get_inventory(), "main", mcl_loot.get_multi_loot(loottable, pr), pr)
end end

View File

@ -454,7 +454,9 @@ local function temple_placement_callback(p1, p2, size, rotation, pr)
{ itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 }, { itemstring = "mcl_mobitems:bone", weight = 25, amount_min = 4, amount_max=6 },
{ itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 }, { itemstring = "mcl_mobitems:rotten_flesh", weight = 25, amount_min = 3, amount_max=7 },
{ itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 }, { itemstring = "mcl_mobitems:spider_eye", weight = 25, amount_min = 1, amount_max=3 },
{ itemstack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}, pr), weight = 20, }, { itemstring = "mcl_books:book", weight = 20, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
end },
{ itemstring = "mcl_mobitems:saddle", weight = 20, }, { itemstring = "mcl_mobitems:saddle", weight = 20, },
{ itemstring = "mcl_core:apple_gold", weight = 20, }, { itemstring = "mcl_core:apple_gold", weight = 20, },
{ itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 }, { itemstring = "mcl_core:gold_ingot", weight = 15, amount_min = 2, amount_max = 7 },

View File

@ -66,7 +66,9 @@ function tsm_railcorridors.get_treasures(pr)
items = { items = {
{ itemstring = "mcl_mobs:nametag", weight = 30 }, { itemstring = "mcl_mobs:nametag", weight = 30 },
{ itemstring = "mcl_core:apple_gold", weight = 20 }, { itemstring = "mcl_core:apple_gold", weight = 20 },
{ itemstack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"}, pr), weight = 10 }, { itemstring = "mcl_books:book", weight = 10, func = function(stack, pr)
mcl_enchanting.enchant_uniform_randomly(stack, {"soul_speed"}, pr)
end },
{ itemstring = "", weight = 5}, { itemstring = "", weight = 5},
{ itemstring = "mcl_core:pick_iron", weight = 5 }, { itemstring = "mcl_core:pick_iron", weight = 5 },
{ itemstring = "mcl_core:apple_gold_enchanted", weight = 1 }, { itemstring = "mcl_core:apple_gold_enchanted", weight = 1 },