forked from mtcontrib/x_enchanting
cleanup and store final_enchantments to itemstack meta
This commit is contained in:
parent
c53e9f3e48
commit
f3b9efbbff
8
api.lua
8
api.lua
@ -343,7 +343,12 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
|
||||
}
|
||||
end
|
||||
|
||||
function XEnchanting.set_enchanted_tool(self, pos, itemstack, capabilities, description, level, player_name)
|
||||
function XEnchanting.set_enchanted_tool(self, itemstack, level, player_name)
|
||||
local data = self.form_context[player_name].data
|
||||
local pos = self.form_context[player_name].pos
|
||||
local capabilities = data.slots[level].tool_cap_data.tool_capabilities
|
||||
local description = data.slots[level].tool_cap_data.enchantments_desc
|
||||
local final_enchantments = data.slots[level].final_enchantments
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local tool_def = minetest.registered_tools[itemstack:get_name()]
|
||||
|
||||
@ -357,6 +362,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, capabilities, desc
|
||||
stack_meta:set_string('description', itemstack:get_description() .. '\n' .. description)
|
||||
stack_meta:set_string('short_description', S('Enchanted') .. ' ' .. itemstack:get_short_description())
|
||||
stack_meta:set_int('is_enchanted', 1)
|
||||
stack_meta:set_string('x_enchanting', minetest.serialize({ enchantments = final_enchantments }))
|
||||
|
||||
inv:set_stack('item', 1, itemstack)
|
||||
|
||||
|
@ -427,10 +427,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Enchant item
|
||||
XEnchanting:set_enchanted_tool(
|
||||
pos,
|
||||
item_stack,
|
||||
data.slots[selected_slot].tool_cap_data.tool_capabilities,
|
||||
data.slots[selected_slot].tool_cap_data.enchantments_desc,
|
||||
selected_slot,
|
||||
p_name
|
||||
)
|
||||
|
@ -8,7 +8,7 @@
|
||||
---@field has_tool_group fun(self: XEnchanting, name: string): string | boolean Check if tool has one of the known tool groups, returns `false` otherwise.
|
||||
---@field set_tool_enchantability fun(self: XEnchanting, tool_def: ItemDef): nil Sets `enchantibility` group and values from base table (`XEnchanting.tools_enchantability`) to all registered tools (atching known group names). If tool has already `enchantibility` group defined it will take the defined value insted.
|
||||
---@field get_enchanted_tool_capabilities fun(self: XEnchanting, tool_def: ItemDef, enchantments: Enchantments[]): GetEnchantedToolCapabilitiesReturn Applies enchantments to item tool capabilities.
|
||||
---@field set_enchanted_tool fun(self: XEnchanting, pos: Vector, itemstack: ItemStack, capabilities: ToolCapabilitiesDef, description: string, level: number, player_name: string): nil Set choosen enchantment and its modified tool capabilities to itemstack and `item` inventory. This will also get new `randomseed`.
|
||||
---@field set_enchanted_tool fun(self: XEnchanting, itemstack: ItemStack, level: number, player_name: string): nil Set choosen enchantment and its modified tool capabilities to itemstack and `item` inventory. This will also get new `randomseed`.
|
||||
---@field get_enchantment_data fun(self: XEnchanting, nr_of_bookshelfs: number, tool_def: ItemDef): EnchantmentData Algoritm to get aplicable random enchantments.
|
||||
---@field get_formspec fun(self: XEnchanting, pos: Vector, player_name: string, data?: EnchantmentData): string Builds and returns `formspec` string
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
---Form context
|
||||
---@class FormContextDef
|
||||
---@field pos Vector Formspec/node form position
|
||||
---@field data table Enchantment data
|
||||
---@field data EnchantmentDataSlot Enchantment data
|
||||
|
||||
|
||||
---@class GetEnchantedToolCapabilitiesReturn
|
||||
|
Loading…
x
Reference in New Issue
Block a user