forked from VoxeLibre/VoxeLibre
Fix #1152
This commit is contained in:
parent
37ef792c9d
commit
95b0a495bc
|
@ -412,6 +412,7 @@ local init_trades = function(self, inv)
|
|||
offered_stack = mcl_enchanting.get_uniform_randomly_enchanted_book({"soul_speed"})
|
||||
else
|
||||
mcl_enchanting.enchant_randomly(offered_stack, math.random(5, 19), false, false, true)
|
||||
mcl_enchanting.unload_enchantments(offered_stack)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -457,7 +458,9 @@ local set_trade = function(trader, player, inv, concrete_tradenum)
|
|||
player_tradenum[name] = concrete_tradenum
|
||||
local trade = trades[concrete_tradenum]
|
||||
inv:set_stack("wanted", 1, ItemStack(trade.wanted[1]))
|
||||
inv:set_stack("offered", 1, ItemStack(trade.offered))
|
||||
local offered = ItemStack(trade.offered)
|
||||
mcl_enchanting.load_enchantments(offered)
|
||||
inv:set_stack("offered", 1, offered)
|
||||
if trade.wanted[2] then
|
||||
local wanted2 = ItemStack(trade.wanted[2])
|
||||
inv:set_stack("wanted", 2, wanted2)
|
||||
|
|
|
@ -9,14 +9,21 @@ function mcl_enchanting.get_enchantments(itemstack)
|
|||
return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {}
|
||||
end
|
||||
|
||||
function mcl_enchanting.set_enchantments(itemstack, enchantments)
|
||||
itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
|
||||
function mcl_enchanting.unload_enchantments(itemstack)
|
||||
local itemdef = itemstack:get_definition()
|
||||
if itemdef.tool_capabilities then
|
||||
itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities)
|
||||
end
|
||||
local meta = itemstack:get_meta()
|
||||
if meta:get_string("name") == "" then
|
||||
meta:set_string("description", "")
|
||||
end
|
||||
end
|
||||
|
||||
function mcl_enchanting.load_enchantments(itemstack, enchantments)
|
||||
if not mcl_enchanting.is_book(itemstack:get_name()) then
|
||||
if itemdef.tool_capabilities then
|
||||
itemstack:get_meta():set_tool_capabilities(itemdef.tool_capabilities)
|
||||
end
|
||||
for enchantment, level in pairs(enchantments) do
|
||||
mcl_enchanting.unload_enchantments(itemstack)
|
||||
for enchantment, level in pairs(enchantments or mcl_enchanting.get_enchantments(itemstack)) do
|
||||
local enchantment_def = mcl_enchanting.enchantments[enchantment]
|
||||
if enchantment_def.on_enchant then
|
||||
enchantment_def.on_enchant(itemstack, level)
|
||||
|
@ -26,6 +33,11 @@ function mcl_enchanting.set_enchantments(itemstack, enchantments)
|
|||
tt.reload_itemstack_description(itemstack)
|
||||
end
|
||||
|
||||
function mcl_enchanting.set_enchantments(itemstack, enchantments)
|
||||
itemstack:get_meta():set_string("mcl_enchanting:enchantments", minetest.serialize(enchantments))
|
||||
mcl_enchanting.load_enchantments(itemstack)
|
||||
end
|
||||
|
||||
function mcl_enchanting.get_enchantment(itemstack, enchantment)
|
||||
return mcl_enchanting.get_enchantments(itemstack)[enchantment] or 0
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue