From 1af9cd275577c8a50892e07ced601b007a065b42 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Mon, 28 Nov 2022 16:01:50 -0500 Subject: [PATCH] Add writing table - initial commit --- api.lua | 498 ++++++++++++++++-- assets/x_enchanting_writing_table.xcf | Bin 0 -> 7746 bytes init.lua | 10 +- table.lua | 8 +- ...nchanting_gui_arrow_right_crossed_icon.png | Bin 0 -> 172 bytes .../x_enchanting_gui_arrow_right_icon.png | Bin 0 -> 121 bytes textures/x_enchanting_gui_paper_bg.png | Bin 0 -> 108 bytes textures/x_enchanting_gui_paper_scroll_bg.png | Bin 0 -> 163 bytes textures/x_enchanting_gui_paper_trade_bg.png | Bin 0 -> 164 bytes textures/x_enchanting_gui_plus_icon.png | Bin 0 -> 103 bytes textures/x_enchanting_scroll_item.png | Bin 0 -> 184 bytes .../x_enchanting_writing_table_bottom.png | Bin 0 -> 638 bytes textures/x_enchanting_writing_table_front.png | Bin 0 -> 711 bytes textures/x_enchanting_writing_table_side.png | Bin 0 -> 608 bytes textures/x_enchanting_writing_table_top.png | Bin 0 -> 779 bytes types/minetest.type.lua | 2 + types/node.type.lua | 1 + types/xenchanting.type.lua | 4 +- writing_table.lua | 329 ++++++++++++ 19 files changed, 811 insertions(+), 41 deletions(-) create mode 100644 assets/x_enchanting_writing_table.xcf create mode 100644 textures/x_enchanting_gui_arrow_right_crossed_icon.png create mode 100644 textures/x_enchanting_gui_arrow_right_icon.png create mode 100644 textures/x_enchanting_gui_paper_bg.png create mode 100644 textures/x_enchanting_gui_paper_scroll_bg.png create mode 100644 textures/x_enchanting_gui_paper_trade_bg.png create mode 100644 textures/x_enchanting_gui_plus_icon.png create mode 100644 textures/x_enchanting_scroll_item.png create mode 100644 textures/x_enchanting_writing_table_bottom.png create mode 100644 textures/x_enchanting_writing_table_front.png create mode 100644 textures/x_enchanting_writing_table_side.png create mode 100644 textures/x_enchanting_writing_table_top.png create mode 100644 writing_table.lua diff --git a/api.lua b/api.lua index 2150dab..3a80da5 100644 --- a/api.lua +++ b/api.lua @@ -62,8 +62,12 @@ XEnchanting = { }, weight = 10, groups = { - 'sword' - } + 'sword', + 'book', + 'scroll' + }, + multiplier_from_scroll = 1, + multiplier_from_item = 1 }, looting = { name = S('Looting'), @@ -81,8 +85,12 @@ XEnchanting = { }, weight = 2, groups = { - 'sword' - } + 'sword', + 'book', + 'scroll' + }, + multiplier_from_scroll = 2, + multiplier_from_item = 4 }, fortune = { name = S('Fortune'), @@ -102,9 +110,13 @@ XEnchanting = { groups = { 'pickaxe', 'shovel', - 'axe' + 'axe', + 'book', + 'scroll' }, - incompatible = { 'silk_touch' } + incompatible = { 'silk_touch' }, + multiplier_from_scroll = 2, + multiplier_from_item = 4 }, unbreaking = { name = S('Unbreaking'), @@ -122,7 +134,9 @@ XEnchanting = { }, weight = 5, -- all applicable - groups = nil + groups = nil, + multiplier_from_scroll = 1, + multiplier_from_item = 2 }, efficiency = { name = S('Efficiency'), @@ -132,7 +146,7 @@ XEnchanting = { [2] = { 11, 61 }, [3] = { 21, 71 }, [4] = { 31, 81 }, - [5] = { 41, 91 }, + -- [5] = { 41, 91 }, }, -- level definition, `level = percentage increase` level_def = { @@ -140,14 +154,18 @@ XEnchanting = { [2] = 30, [3] = 35, [4] = 40, - [5] = 45, + -- [5] = 45, }, weight = 10, groups = { 'pickaxe', 'shovel', - 'axe' - } + 'axe', + 'book', + 'scroll' + }, + multiplier_from_scroll = 1, + multiplier_from_item = 1 }, silk_touch = { name = S('Silk Touch'), @@ -162,9 +180,13 @@ XEnchanting = { groups = { 'pickaxe', 'shovel', - 'axe' + 'axe', + 'book', + 'scroll' }, - incompatible = { 'fortune' } + incompatible = { 'fortune' }, + multiplier_from_scroll = 4, + multiplier_from_item = 8 }, curse_of_vanishing = { name = S('Curse of Vanishing'), @@ -177,7 +199,9 @@ XEnchanting = { weight = 1, secondary = true, -- all applicable - groups = nil + groups = nil, + multiplier_from_scroll = 4, + multiplier_from_item = 8 }, knockback = { name = S('Knockback'), @@ -192,8 +216,12 @@ XEnchanting = { }, weight = 5, groups = { - 'sword' - } + 'sword', + 'book', + 'scroll' + }, + multiplier_from_scroll = 1, + multiplier_from_item = 2 }, power = { -- Increases arrow damage. @@ -216,8 +244,12 @@ XEnchanting = { }, weight = 10, groups = { - 'bow' - } + 'bow', + 'book', + 'scroll' + }, + multiplier_from_scroll = 1, + multiplier_from_item = 1 }, punch = { -- Increases arrow knockback. @@ -234,8 +266,12 @@ XEnchanting = { }, weight = 2, groups = { - 'bow' - } + 'bow', + 'book', + 'scroll' + }, + multiplier_from_scroll = 2, + multiplier_from_item = 4 }, infinity = { -- Prevents regular arrows from being consumed when shot. @@ -252,8 +288,12 @@ XEnchanting = { weight = 1, secondary = true, groups = { - 'bow' - } + 'bow', + 'book', + 'scroll' + }, + multiplier_from_scroll = 4, + multiplier_from_item = 8 }, }, form_context = {}, @@ -299,12 +339,14 @@ function XEnchanting.has_tool_group(self, name) return 'sword' elseif minetest.get_item_group(name, 'bow') > 0 then return 'bow' + elseif minetest.get_item_group(name, 'book') > 0 then + return 'book' end return false end -function XEnchanting.set_tool_enchantability(self, tool_def) +function XEnchanting.set_enchantability(self, tool_def) if minetest.get_item_group(tool_def.name, 'enchantability') > 0 then -- enchantability is already set, we dont need to override the item return @@ -485,40 +527,49 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name local data = self.form_context[player_name].data if not data then + minetest.log('warning', '[set_enchanted_tool] no data from form context found.') return end + local tool_def = minetest.registered_tools[itemstack:get_name()] + or minetest.registered_craftitems[itemstack:get_name()] + + if minetest.get_item_group(tool_def.name, 'book') > 0 then + itemstack = ItemStack({ name = 'x_enchanting:scroll_item' }) + end + local capabilities = data.slots[level].tool_cap_data local description = data.slots[level].descriptions.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()] local node_meta = minetest.get_meta(pos) if not tool_def then + minetest.log( + 'warning', + '[set_enchanted_tool] no tool definition found in registered_tools/registered_craftitems.' + ) return end local stack_meta = itemstack:get_meta() - ---@type table - local final_enchantments_meta = {} + if minetest.get_item_group(tool_def.name, 'book') == 0 then + for i, enchantment in ipairs(final_enchantments) do + stack_meta:set_float('is_' .. enchantment.id, enchantment.value) + end - for i, enchantment in ipairs(final_enchantments) do - stack_meta:set_float('is_' .. enchantment.id, enchantment.value) - -- store only necessary data, keeping the meta optimized - final_enchantments_meta[enchantment.id] = { - value = enchantment.value - } + stack_meta:set_tool_capabilities(capabilities) end - stack_meta:set_tool_capabilities(capabilities) 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(final_enchantments_meta)) + stack_meta:set_string('x_enchanting', minetest.serialize(final_enchantments)) + -- set new item ItemStack inv:set_stack('item', 1, itemstack) + -- set new trade ItemStack local trade_stack = inv:get_stack('trade', 1) trade_stack:take_item(level) inv:set_stack('trade', 1, trade_stack) @@ -526,9 +577,11 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name -- set new seed self.player_seeds[player_name] = self:get_randomseed() + -- update node formspec local formspec = self:get_formspec(pos, player_name) node_meta:set_string('formspec', formspec) + -- play sound minetest.sound_play('x_enchanting_enchant', { gain = 0.3, pos = pos, @@ -588,6 +641,48 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name minetest.add_particlespawner(particlespawner_def) end +function XEnchanting.get_enchantments_for_group(self, item_name, meta_enchantments) + local enchantment_defs = table.copy(self.enchantment_defs) + local group_enchantments = {} + local total_cost = 0 + + if meta_enchantments and #meta_enchantments > 0 then + enchantment_defs = {} + + for i, def in pairs(meta_enchantments) do + if self.enchantment_defs[def.id] then + enchantment_defs[def.id] = self.enchantment_defs[def.id] + end + end + end + + for enchantment_id, enchantment_def in pairs(enchantment_defs) do + local is_group_compatible = false + + if not enchantment_def.groups then + group_enchantments[enchantment_id] = enchantment_def + is_group_compatible = true + else + for i, group in ipairs(enchantment_def.groups) do + if minetest.get_item_group(item_name, group) > 0 then + group_enchantments[enchantment_id] = enchantment_def + is_group_compatible = true + break + end + end + end + + if not is_group_compatible then + total_cost = total_cost + 1 + end + end + + return { + group_enchantments = group_enchantments, + writing_table_cost = total_cost + } +end + function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_def) local p_name = player:get_player_name() local randomseed = self.player_seeds[p_name] or self:get_randomseed() @@ -907,3 +1002,338 @@ function XEnchanting.get_formspec(self, pos, player_name, data) return table.concat(formspec, '') end + +function XEnchanting.get_writing_table_total_data(self, props) + local inv = props.inv + -- item + local stack_item = inv:get_stack('item', 1) + local stack_item_meta = stack_item:get_meta() + local table_uses_item = stack_item_meta:get_int('x_enchanting_writing_table_uses') + print('table_uses_item', table_uses_item) + local prior_use_penalty_item = 2 ^ table_uses_item - 1 + local enchantments_item = minetest.deserialize(stack_item_meta:get_string('x_enchanting')) or {} + -- sacrifice + local stack_sacrifice = inv:get_stack('sacrifice', 1) + local stack_sacrifice_meta = stack_sacrifice:get_meta() + local table_uses_sacrifice = stack_sacrifice_meta:get_int('x_enchanting_writing_table_uses') + print('table_uses_sacrifice', table_uses_sacrifice) + local prior_use_penalty_sacrifice = 2 ^ table_uses_sacrifice - 1 + local enchantments_sacrifice = minetest.deserialize(stack_sacrifice_meta:get_string('x_enchanting')) or {} + local new_x_enchanting_writing_table_uses = table_uses_item + + if table_uses_sacrifice > new_x_enchanting_writing_table_uses then + new_x_enchanting_writing_table_uses = table_uses_sacrifice + end + + print('enchantments_sacrifice', dump(enchantments_sacrifice)) + + local result_data = { + -- Prior Work penalties of both target and sacrifice. + total_cost = prior_use_penalty_item + prior_use_penalty_sacrifice, + show_total_cost = true, + show_crossed_arrow = false + } + + if stack_sacrifice:is_empty() or stack_item:is_empty() then + result_data.show_total_cost = false + + if not (stack_sacrifice:is_empty() and stack_item:is_empty()) then + result_data.show_crossed_arrow = true + inv:set_stack('result', 1, ItemStack('')) + end + + return result_data + end + + -- total cost + -- If the sacrifice has enchantments, the enchantment cost. + -- get enchantment defs for item group + -- Add one level cost for every incompatible enchantment on the target + local enchantment_defs_for_group = self:get_enchantments_for_group(stack_item:get_name(), enchantments_sacrifice) + local possible_enchantments_defs = enchantment_defs_for_group.group_enchantments + + result_data.total_cost = result_data.total_cost + enchantment_defs_for_group.writing_table_cost + + -- remove incompatible enchantments + -- Add one level cost for every incompatible enchantment on the target + for enchanment_id, enchanment_def in pairs(table.copy(possible_enchantments_defs)) do + if enchanment_def.incompatible then + for _, enchantment in ipairs(enchantments_item) do + if table.indexof(enchanment_def.incompatible, enchantment.id) ~= -1 then + possible_enchantments_defs[enchanment_id] = nil + result_data.total_cost = result_data.total_cost + 1 + end + end + end + end + + -- reduce/sync current sacrifice enchantmets + local enchantments_sacrifice_copy = table.copy(enchantments_sacrifice) + enchantments_sacrifice = {} + + for i, enchantment in ipairs(enchantments_sacrifice_copy) do + if possible_enchantments_defs[enchantment.id] then + table.insert(enchantments_sacrifice, enchantment) + end + end + + print('enchantments_sacrifice', dump(enchantments_sacrifice)) + print('enchantments_item', dump(enchantments_item)) + local final_enchantments = {} + + -- If the enchantment is compatible with the existing enchantments on the target: + -- add the final level of the enchantment on the resulting item multiplied by the multiplier from the table + for i, enchantment_sacrifice in ipairs(enchantments_sacrifice) do + local enchantment_upgraded = false + local multiplier = possible_enchantments_defs[enchantment_sacrifice.id].multiplier_from_item + + if minetest.get_item_group(stack_sacrifice:get_name(), 'scroll') > 0 then + multiplier = possible_enchantments_defs[enchantment_sacrifice.id].multiplier_from_scroll + end + + print('multiplier', multiplier) + + for _, enchantment_item in ipairs(enchantments_item) do + print(enchantment_item.id .. ' == ' .. enchantment_sacrifice.id) + if enchantment_item.id == enchantment_sacrifice.id then + -- upgrade + print('--- upgrade') + print('enchantment_item', dump(enchantment_item)) + print('enchantment_sacrifice', dump(enchantment_sacrifice)) + + if enchantment_sacrifice.level == enchantment_item.level then + local new_level = enchantment_sacrifice.level + 1 + local max_level = #possible_enchantments_defs[enchantment_sacrifice.id].final_level_range + + if new_level > max_level then + -- maximum level reached, still add the cost though + new_level = max_level + end + + table.insert(final_enchantments, { + id = enchantment_sacrifice.id, + level = new_level, + value = possible_enchantments_defs[enchantment_sacrifice.id].level_def[new_level], + secondary = enchantment_sacrifice.secondary, + incompatible = enchantment_sacrifice.incompatible + }) + + -- upgrade 1 level up if not already on max level + print(enchantment_item.id, 'upgrade 1 level up') + result_data.total_cost = result_data.total_cost + multiplier * new_level + elseif enchantment_sacrifice.level > enchantment_item.level then + -- upgrade to sacrifice level + print(enchantment_item.id, 'upgrade to' .. enchantment_sacrifice.level .. ' levels up') + + table.insert(final_enchantments, { + id = enchantment_sacrifice.id, + level = enchantment_sacrifice.level, + value = + possible_enchantments_defs[enchantment_sacrifice.id].level_def[enchantment_sacrifice.level], + secondary = enchantment_sacrifice.secondary, + incompatible = enchantment_sacrifice.incompatible + }) + + result_data.total_cost = result_data.total_cost + multiplier * enchantment_sacrifice.level + else + -- dont change enchantment on item but add cost for it + table.insert(final_enchantments, enchantment_item) + result_data.total_cost = result_data.total_cost + multiplier * enchantment_item.level + end + + enchantment_upgraded = true + end + end + + if not enchantment_upgraded then + -- add + print('--- add') + print('enchantment_sacrifice', dump(enchantment_sacrifice)) + + table.insert(final_enchantments, enchantment_sacrifice) + result_data.total_cost = result_data.total_cost + multiplier * enchantment_sacrifice.level + end + end + + print('final_enchantments 1', dump(final_enchantments)) + + if #final_enchantments == 0 then + result_data.show_total_cost = false + result_data.show_crossed_arrow = true + inv:set_stack('result', 1, ItemStack('')) + + return result_data + end + + -- add remaining enchantments from the item + for i, enchantment_item in ipairs(enchantments_item) do + local has_item = false + for j, enchantment_sacrifice in ipairs(enchantments_sacrifice) do + if enchantment_item.id == enchantment_sacrifice.id then + has_item = true + end + end + + if not has_item then + table.insert(final_enchantments, enchantment_item) + end + end + + print('final_enchantments 2', dump(final_enchantments)) + + + if inv:is_empty('item') and not inv:is_empty('sacrifice') + or inv:is_empty('sacrifice') and not inv:is_empty('item') + or inv:is_empty('trade') + or #final_enchantments == 0 + then + result_data.show_crossed_arrow = true + inv:set_stack('result', 1, ItemStack('')) + end + + if inv:is_empty('item') or inv:is_empty('sacrifice') + or #final_enchantments == 0 + then + result_data.show_total_cost = false + end + + result_data.enchantments = final_enchantments + + print('result_data', dump(result_data)) + + local tool_cap_data = self:get_enchanted_tool_capabilities( + minetest.registered_tools[stack_item:get_name()] or minetest.registered_craftitems[stack_item:get_name()], + final_enchantments + ) + local descriptions = self:get_enchanted_descriptions(final_enchantments) + local stack_result = ItemStack(stack_item:to_table()) + local stack_result_meta = stack_result:get_meta() + + print('short_description', stack_result:get_short_description()) + + if not stack_item:is_empty() and minetest.get_item_group(stack_item:get_name(), 'scroll') == 0 then + -- for i, enchantment in ipairs(final_enchantments) do + -- stack_meta:set_float('is_' .. enchantment.id, enchantment.value) + -- end + + print('tool_cap_data', dump(tool_cap_data)) + print('stack_result', dump(stack_result:to_table())) + stack_result_meta:set_tool_capabilities(tool_cap_data) + end + + print('new_x_enchanting_writing_table_uses 1', new_x_enchanting_writing_table_uses) + stack_result_meta:set_int('x_enchanting_writing_table_uses', new_x_enchanting_writing_table_uses + 1) + print('new_x_enchanting_writing_table_uses 2', stack_result_meta:get_int('x_enchanting_writing_table_uses')) + stack_result_meta:set_string( + 'description', + stack_result:get_short_description() .. '\n' .. descriptions.enchantments_desc + ) + stack_result_meta:set_string('x_enchanting', minetest.serialize(final_enchantments)) + + inv:set_stack('result', 1, stack_result) + + return result_data +end + +function XEnchanting.get_formspec_writing_table(self, pos, props) + local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z + local inv = minetest.get_meta(pos):get_inventory() + ---@diagnostic disable-next-line: codestyle-check + local model_scroll_open = 'model[0,0;2,3;x_enchanting_table;x_enchanting_scroll.b3d;x_enchanting_scroll_mesh.png,x_enchanting_scroll_handles_mesh.png,x_enchanting_scroll_mesh.png;89,0;false;false;' .. self.scroll_animations.scroll_open_idle[1].x .. ',' .. self.scroll_animations.scroll_open_idle[1].y .. ';0]' + ---@diagnostic disable-next-line: codestyle-check + local model_scroll_closed = 'model[0,0;2,3;x_enchanting_table;x_enchanting_scroll.b3d;x_enchanting_scroll_mesh.png,x_enchanting_scroll_handles_mesh.png,x_enchanting_scroll_mesh.png;89,0;false;false;' .. self.scroll_animations.scroll_closed_idle[1].x .. ',' .. self.scroll_animations.scroll_closed_idle[1].y .. ';0]' + local model_scroll_is_open + + local player_name = props.player_name + local data = props.data or {} + local show_crossed_arrow = props.data.show_crossed_arrow + local show_total_cost = props.data.show_total_cost + + local formspec = { + 'size[8,9]', + 'bgcolor[#080808BB;true]', + 'listcolors[#FFFFFF00;#FFFFFF1A;#FFFFFF00;#30434C;#FFF]', + get_formspec_bg(player_name), + 'style_type[label;font=mono,bold]', + 'style[slot_1,slot_2,slot_3;font=mono,bold;textcolor=#4D413A]', + 'label[0, 0;' .. S('Enchant') .. ']', + -- item + 'list[nodemeta:' .. spos .. ';item;2.75, 0.5;1, 1;]', + 'image[2.75, 0.5;1,1;x_enchanting_gui_paper_bg.png]', + 'image[3.75, 0.5;1,1;x_enchanting_gui_plus_icon.png]', + -- sacrifice + 'list[nodemeta:' .. spos .. ';sacrifice;4.75, 0.5;1, 1;]', + 'image[4.75, 0.5;1,1;x_enchanting_gui_paper_scroll_bg.png]', + show_crossed_arrow and 'image[5.75, 0.5;1,1;x_enchanting_gui_arrow_right_crossed_icon.png]' + or 'image[5.75, 0.5;1,1;x_enchanting_gui_arrow_right_icon.png]', + -- result + 'list[nodemeta:' .. spos .. ';result;6.75, 0.5;1, 1;]', + 'image[6.75, 0.5;1,1;x_enchanting_gui_paper_bg.png]', + -- trade + 'list[nodemeta:' .. spos .. ';trade;6.75, 1.5;1, 1;]', + 'image[6.75, 1.5;1,1;x_enchanting_gui_paper_trade_bg.png]', + -- inventories + 'list[current_player;main;0, 4.85;8, 1;]', + 'list[current_player;main;0, 6.08;8, 3;8]', + 'listring[nodemeta:' .. spos .. ';trade]', + 'listring[current_player;main]', + 'listring[nodemeta:' .. spos .. ';sacrifice]', + 'listring[current_player;main]', + 'listring[nodemeta:' .. spos .. ';item]', + 'listring[current_player;main]', + } + + formspec[#formspec + 1] = get_hotbar_bg(0, 4.85) + formspec[#formspec + 1] = get_list_bg(0, 6.08) + + if show_total_cost then + formspec[#formspec + 1] = 'style_type[label;font=mono,bold;textcolor=#4D413A]' + formspec[#formspec + 1] = 'label[3.125, 1.5;' .. S('Cost') .. ': ' .. data.total_cost .. ']' + end + + -- -- data + -- if data then + -- for i, slot in ipairs(data.slots) do + -- if #slot.final_enchantments > 0 then + -- -- show buttons with content + + -- if inv:get_stack('trade', 1):get_count() >= i then + -- ---@diagnostic disable-next-line: codestyle-check + -- formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']' + -- else + -- ---@diagnostic disable-next-line: codestyle-check + -- formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';' .. slot.descriptions.enchantments_desc_masked .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']' + -- end + + -- formspec[#formspec + 1] = 'image[2.3,' .. -0.5 + i .. ';1,1;x_enchanting_image_trade_' .. i .. '.png;]' + -- else + -- -- disabled buttons + -- ---@diagnostic disable-next-line: codestyle-check + -- formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]' + -- end + -- end + + -- model_scroll_is_open = true + -- else + -- for i = 1, 3, 1 do + -- -- disabled buttons + -- ---@diagnostic disable-next-line: codestyle-check + -- formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]' + -- end + + -- model_scroll_is_open = false + -- end + + -- if model_scroll_is_open then + -- formspec[#formspec + 1] = model_scroll_open + -- else + -- formspec[#formspec + 1] = model_scroll_closed + -- end + + -- self.form_context[player_name] = { + -- data = data, + -- pos = pos + -- } + + return table.concat(formspec, '') +end diff --git a/assets/x_enchanting_writing_table.xcf b/assets/x_enchanting_writing_table.xcf new file mode 100644 index 0000000000000000000000000000000000000000..cb9b2684c26fe10cd7335d536f1a93c8b772e186 GIT binary patch literal 7746 zcmdrwdsI_ro;M#)q0~Hh#e^n6k{bewB)JJxhG2{YE@;uHA;uc+y@bfh!w7AWk(N1D z5n-&4RxEVvOnYjp0^uQb<~Xip_w3F&b38qJPNzHAnf^1UyY1=eUv9dqR=E57ZW0Bm+p@0wN4BG651n zcK~p9geI_E4!~^yJTRZ;^0)iBp0=(|K?E*>_$j~%QCbtlfP{f!1YopzV1*OK(eZMD zj_L%PC><{sV#aK6#F)*KbTnHQ;Qs;02*43q&vkWl_&a;B4zEeN<*=XW@wcd7YU??m zcGhic#2T?++Sb7Y{ObdU+gh*;TTke_dycgG)!kj~Z7oG<`qlu~)!ubjtryVx!vU62 zZxnuIMWAL^QJ1NOA6EBvA7Z$+&VagXBXCC^ZM%IPKF2URx5uvZE24^*q3%th! zLBIs{zzlz=N1;|{Lp>NlJrOa~1B74-^#B=(5Q!Fv{CGy8ifo~tWT+<I{5&)6`L;$Ho5}!sS@aX_)K&M9KSdZvF@x+0pabi4UKsC-22(-!LNbpGubwC_y*Od@#W+3PKc+CIu7SOF<%-;Z_A93TTsq5Cwb^gAgSsMDaotFGTS= z99}O(@j77Uy$KGH7ovbP$(!g{@)F(*hsq04K%4A^DBzRmg(zN%a1tWuG#)xA0Xj(p zI1xH213C{wjF0HSgWrk|MeNw%49;m5mW|2EbN5xmA6$Hxv!bjx1TxQY%$ zYw*L7FtUiH;qmdOh)2*w&>O2DI5oqG<2*FgqhW#=Pa1&U!`($>Ku<*!DXaO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L)%$k_4z@ zwfjxs-`F*Jx(>zmjK8;6;7jTs<=(R??)nE(fxqU*#uIym0)NGijhGI2#Y&8uO1*O@ zT|?IaIG=NFRBn9z!iL_VQ^!vY4ZUePaoOp-aOv8mYm-;5y}h}#wEW8c+Eed@rbCm{ zp?6EOvrB*3>^w0sa}(V~ z_OqpIxQRYBIdyAc;b!R4iOW=&chw!gg6(fkyfZi&{)%_er!IvsAG&t*XW@@|SIy9` zLcrb%O>yC`!o&OMp=&tbuS3^p{$u{_{q;ldgl0n1lc8UM^((WC^TOn%x3689ymsmL zKdt!qCab^vf$7Z;K6rm}`sVMctN*&q)v({YzxnxQAJfb>GqtXpX%c;DFvjpWYWx8`ol%#Dt0-JeqtHWu%CZFKI& zjhWHjJ?)AxUuxJsi0x<2y}XAFf6i|x-qkyb`O)Dp1mH$3>-aPO;)d9z2X60S3MKWhK# zQ1HmB^1v&414$X-CDv*ww^UfI8pF+mBuRFrG*bp3&6K1jq#8<7RQPZh3}vZW^V5>j zYFD+()8N|TC@b6a6S>q-$M~6jtxSDcPEJ|HI;q~>b{d^I-&R|e^Gum#U8bSlbLRB< zGy9&eDJ$D-%9R?b+s>RneTLbsF{Q2x=Vlgrm^0_kpJu8{H>HL7EE(B=?N58^N~!Q4 z_^iz0Y6kO+%TN-&$Y)6nP6pUB-1F-2AHo~unFbfm_iM(L#b4yh<(WlwEeDv^eT);V zwbcqq>E7xst_F{*nl_|gbSRR{m8oTwm78of2ffDPlt{($T=_crx^;?m3dOp}Tk-z` D=V&n` literal 0 HcmV?d00001 diff --git a/init.lua b/init.lua index 6d171bc..362e785 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ local mod_start_time = minetest.get_us_time() dofile(path .. '/api.lua') dofile(path .. '/table.lua') +dofile(path .. '/writing_table.lua') ---Check if string X starts with string Y ---@param str string @@ -19,7 +20,14 @@ minetest.register_on_mods_loaded(function() -- Tools override for name, tool_def in pairs(minetest.registered_tools) do if XEnchanting:has_tool_group(name) then - XEnchanting:set_tool_enchantability(tool_def) + XEnchanting:set_enchantability(tool_def) + end + end + + -- Craft items override + for name, tool_def in pairs(minetest.registered_craftitems) do + if XEnchanting:has_tool_group(name) then + XEnchanting:set_enchantability(tool_def) end end diff --git a/table.lua b/table.lua index 694fe78..4a26166 100644 --- a/table.lua +++ b/table.lua @@ -107,7 +107,7 @@ minetest.register_node('x_enchanting:table', { local data = XEnchanting:get_enchantment_data( clicker, #bookshelfs, - minetest.registered_tools[item_stack:get_name()] + minetest.registered_tools[item_stack:get_name()] or minetest.registered_craftitems[item_stack:get_name()] ) local formspec = XEnchanting:get_formspec(pos, p_name, data) @@ -352,7 +352,7 @@ minetest.register_node('x_enchanting:table', { local data = XEnchanting:get_enchantment_data( player, #bookshelfs, - minetest.registered_tools[item_stack:get_name()] + minetest.registered_tools[item_stack:get_name()] or minetest.registered_craftitems[item_stack:get_name()] ) local formspec = XEnchanting:get_formspec(pos, p_name, data) @@ -387,7 +387,7 @@ minetest.register_node('x_enchanting:table', { local data = XEnchanting:get_enchantment_data( player, #bookshelfs, - minetest.registered_tools[item_stack:get_name()] + minetest.registered_tools[item_stack:get_name()] or minetest.registered_craftitems[item_stack:get_name()] ) local formspec = XEnchanting:get_formspec(pos, p_name, data) @@ -455,7 +455,7 @@ minetest.register_node('x_enchanting:table', { }) ---- ---- Entity (Scroll) +--- Entity - Scroll ---- minetest.register_entity('x_enchanting:table_scroll', { diff --git a/textures/x_enchanting_gui_arrow_right_crossed_icon.png b/textures/x_enchanting_gui_arrow_right_crossed_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..019abbd49296a88cb87ec41bdf67be5306ff278a GIT binary patch literal 172 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!P=HT}t9yaZMg{JMaF^MI(X+(Z zmP&IxYkhbdD9cz9J z$>zK}mApJ3?ffTnwR*ZGoSWD(;riJbFE^f;uxQ@_#^Zm!e@wc)e0`ix%`@hWIgI|_ T_1K>P&1CR&^>bP0l+XkK@ZUZ| literal 0 HcmV?d00001 diff --git a/textures/x_enchanting_gui_arrow_right_icon.png b/textures/x_enchanting_gui_arrow_right_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..dd15d4aceb54160ec73ded51d370ca981251da18 GIT binary patch literal 121 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`4xTQKAr_~T6C_w!9G!QZt`|^S z(J_Isf>$YpdzYd_)<#VQw!^$LVkQ30m+47l(9?f#l_%I?P1>Zz6LWf%IT#p3ZodUN`I54PtJ1&$wY`qAi-_zC4Wt~$( F69Bp1AqW5f literal 0 HcmV?d00001 diff --git a/textures/x_enchanting_gui_paper_scroll_bg.png b/textures/x_enchanting_gui_paper_scroll_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..d1ad638ea228f4e104c7f55ab63f774ddb82c0e4 GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh-3?!F4n4ALQ1o(uw&Mu5@2zS{$tM|y_j@L() z+&Hpb{K-U5psbIli(^OyW0C`do1;U2VE~H)&jE)G3t0F&o98steaLUkG)|3=KEGqj zgqx8iU3X?0dwk=`IBR&byX9KXl)V~Z?dKnrn7wk@^?R*loqVsZtlX5iUAKYeGI+ZB KxvXQX_R0G|-o*@e*!;VzqJ^&VN=@%qS; z8%MT_KbhzWl=by=aSW-rm3#go*8v3{=fJJk|NnoQEA@!!*rUS>Z`{gzIrC%S+5qdz zEpG(!1zk@1av02&^Wk`SU6t?B)brhYTeQMrk3Y%u{Q1_<`0XV2A9l>@|2g#hfd(^p My85}Sb4q9e07|_;2><{9 literal 0 HcmV?d00001 diff --git a/textures/x_enchanting_gui_plus_icon.png b/textures/x_enchanting_gui_plus_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..74e91035c04265cd444b229f3e725c39091b858c GIT binary patch literal 103 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`dY&$hAr_~T6C|!IP`vZ>|C>WE z{x4<|$Yk&^G~+R1m~GL_Gm BAOQdX literal 0 HcmV?d00001 diff --git a/textures/x_enchanting_scroll_item.png b/textures/x_enchanting_scroll_item.png new file mode 100644 index 0000000000000000000000000000000000000000..50b758c10527f2919b48653aee4189452156e93b GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!bbwEYt9yaZo@MPFVdQ&MBb@0F+ZkHUIzs literal 0 HcmV?d00001 diff --git a/textures/x_enchanting_writing_table_bottom.png b/textures/x_enchanting_writing_table_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..24ed8e6de3b034203c63dc3c603212ed8a313066 GIT binary patch literal 638 zcmV-^0)hRBP)Eicmz5~v`xLP(@2C3o%n}LF=5#fj_clNd@PreW< z9S&}6(C9JDln^J}F*6E)2$uR6M^)J0>7&+kWK~JHFEJ5a+=X(bA_5{Bvs8r$P!njm z$ygSj*A6O;x#7+~<2kS2eQdy4&Ae_}jL0Ur?NYTVxYg_M$BWaJ%#6<$m%REq=kMeH zu+p${G0uinO%a9g1Wa(chIuoa(9YO zhw#9C4kU@Nv0C!v&wu&-q$ASfkkD?N@Xf+mUW6jdvLToK0f>om>kw{2v zG)T%qh|n~xw>s0lcV^yuEpBxP&g$NrbMN_`C+8;)_7-eDR78OSfeTCf{GWTHX;@8L zc!kJgHEnV2@OF|~%Ds2XB--+?$ScdKJ>3-ZA-A4?As;Hdz?a-OG(av6u+|`@EB=nYnSioimrJU?bQ&mbG0fUt; zs+TX&9ji?xS!R$zfCY(#JFmWytkn6T4XMr$)-pfyl+)wq89H%{*V8i$@7#)%&=vc9 zT3Y4)n?(>H&g?GRRA)qiA~SXqqHY-0n}#1cqcc(za~`b>JmpxVIwJ~|V-SUkr8P&Z zGZ38HS9T-)M$q>H9==^*dEEk*a!$1wEUg)aM)or_vLB_~-b_waDd$55d%LM#zCbaS zG_)b9*GcMiZr*;-X7DRY-36=xPkN5Q#25!o9Aj>JmXU!9QKVQ~ceS-zt<9j&*H6nB zUc8)VUw;Qm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(6c6y^&0Zz17qxeQ+kJ; zj@j>xNYj+|om-@7%5p716lewDJ(J-WT`w6QY~#!n6@=Jgj07R$LB_YYclqu6FS+>k zWj=Z9JnI*pAqWI9*0PXBq^%}LyF2uD|H5PgrrkD_7LyII<&-}@dx!6CT;0uvq@OzIb{(gw;9nzY5`lEu4S59M$V`uXQNfhv? zKSo`8q2;I6(W+Ol))NE@5jDTP2N8vL9tjlAfx@%j9g#)>{{rq$O>(pk<3Ioa002ov JPDHLkV1k~!Z4Uqd literal 0 HcmV?d00001 diff --git a/types/minetest.type.lua b/types/minetest.type.lua index 567da2a..d50d9ca 100644 --- a/types/minetest.type.lua +++ b/types/minetest.type.lua @@ -16,6 +16,7 @@ ---@field get_node fun(pos: Vector): NodeDef Returns the node at the given position as table in the format `{name="node_name", param1=0, param2=0}`, returns `{name="ignore", param1=0, param2=0}` for unloaded areas. ---@field registered_nodes table Map of registered node definitions, indexed by name ---@field registered_ores table Map of registered ore definitions, indexed by name +---@field registered_craftitems table Map of registered craft items, indexed by name ---@field after fun(time: number|integer, func: fun(...), ...): JobTable Call the function `func` after `time` seconds, may be fractional. Optional: Variable number of arguments that are passed to `func`. ---@field sound_play fun(spec: SimpleSoundSpec|string, parameters: SoundParamDef, ephemeral?: boolean): any Returns a `handle`. Ephemeral sounds will not return a handle and can't be stopped or faded. It is recommend to use this for short sounds that happen in response to player actions (e.g. door closing). ---@field add_particlespawner fun(particlespawner_definition: ParticlespawnerDef): number|integer Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds. Returns an `id`, and -1 if adding didn't succeed. @@ -93,6 +94,7 @@ ---@field handle_node_drops fun(pos: Vector, drops: string[], digger: ObjectRef) `drops`: list of itemstrings. Handles drops from nodes after digging: Default action is to put them into digger's inventory. Can be overridden to get different functionality (e.g. dropping items on ground) ---@field register_on_dieplayer fun(func: fun(player: ObjectRef, reason?: string)): nil Called when a player dies. `reason`: a PlayerHPChangeReason table, see register_on_player_hpchange ---@field register_on_player_hpchange fun(func: fun(player, hp_change, reason), modifier): number Called when the player gets damaged or healed. `player`: ObjectRef of the player. `hp_change`: the amount of change. Negative when it is damage.. `reason`: a PlayerHPChangeReason table.. The `type` field will have one of the following values: `set_hp`: A mod or the engine called `set_hp` without giving a type - use this for custom damage types.. `punch`: Was punched. `reason.object` will hold the puncher, or nil if none. `fall`, `node_damage`: `damage_per_second` from a neighbouring node. `reason.node` will hold the node name or nil. `drown` `respawn`. Any of the above types may have additional fields from mods. `reason.from` will be `mod` or `engine`. `modifier`: when true, the function should return the actual `hp_change`. Note: modifiers only get a temporary `hp_change` that can be modified by later modifiers. Modifiers can return true as a second argument to stop the execution of further functions. Non-modifiers receive the final HP change calculated by the modifiers. +---@field itemstring_with_palette fun(item: string | ItemStack, palette_index: integer): string returns an item string. Creates an item string which contains palette index information for hardware colorization. You can use the returned string as an output in a craft recipe. `item`: the item stack which becomes colored. Can be in string, table and native form. `palette_index`: this index is added to the item stack ---@field get_player_information fun(player_name: string): table Table containing information about a player ---Minetest settings diff --git a/types/node.type.lua b/types/node.type.lua index 3b39076..a702120 100644 --- a/types/node.type.lua +++ b/types/node.type.lua @@ -20,6 +20,7 @@ ---@field walkable boolean If true, objects collide with node. ---@field after_dig_node fun(pos: Vector, oldnode: NodeDef, oldmetadata: table, digger: ObjectRef): nil oldmetadata is in table format. Called after destructing node when node was dug using minetest.node_dig / minetest.dig_node., default: nil ---@field paramtype2 string +---@field palette string Image ---@field can_dig fun(pos: Vector, player?: ObjectRef): boolean | nil Returns true if node can be dug, or false if not.default: nil ---@field on_rotate fun(pos: Vector, node: table, user: ObjectRef, mode: table, new_param2: string): boolean Only for screwdriver mod. ---@field on_construct fun(pos: Vector): nil Node constructor; called after adding node. Can set up metadata and stuff like that. Not called for bulk node placement (i.e. schematics and VoxelManip). default: nil diff --git a/types/xenchanting.type.lua b/types/xenchanting.type.lua index d544062..4717426 100644 --- a/types/xenchanting.type.lua +++ b/types/xenchanting.type.lua @@ -6,7 +6,7 @@ ---@field roman_numbers table Convert Arabic numbers to Roman numbers ---@field enchantment_defs table<'sharpness' | 'fortune' | 'unbreaking' | 'efficiency' | 'silk_touch' | 'curse_of_vanishing' | 'knockback', EnchantmentDef> ---@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 set_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: Enchantment[]): ToolCapabilitiesDef Applies enchantments to item tool capabilities. ---@field set_enchanted_tool fun(self: XEnchanting, pos: Vector, 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, player: ObjectRef, nr_of_bookshelfs: number, tool_def: ItemDef): EnchantmentData Algoritm to get aplicable random enchantments. @@ -50,5 +50,5 @@ ---@class EnchantmentDataSlot ---@field level number ---@field final_enchantments Enchantment[] ----@field tool_cap_data ToolCapabilitiesDef +---@field tool_cap_data ToolCapabilitiesDef | nil ---@field descriptions {["enchantments_desc"]: string, ["enchantments_desc_masked"]: string } diff --git a/writing_table.lua b/writing_table.lua new file mode 100644 index 0000000..31cb209 --- /dev/null +++ b/writing_table.lua @@ -0,0 +1,329 @@ +screwdriver = minetest.global_exists('screwdriver') and screwdriver --[[@as MtgScrewdriver]] + +local S = minetest.get_translator(minetest.get_current_modname()) + +---- +--- Table Node +---- + +minetest.register_node('x_enchanting:writing_table', { + description = S('Writing Table'), + short_description = S('Writing Table'), + ---top, bottom, sides...front + tiles = { + 'x_enchanting_writing_table_top.png', + 'x_enchanting_writing_table_bottom.png', + 'x_enchanting_writing_table_side.png', + 'x_enchanting_writing_table_side.png', + 'x_enchanting_writing_table_side.png', + 'x_enchanting_writing_table_front.png' + }, + paramtype = 'light', + paramtype2 = 'facedir', + walkable = true, + wield_scale = { x = 2, y = 2, z = 2 }, + sounds = { + footstep = { + name = 'x_enchanting_scroll', + gain = 0.2 + }, + dug = { + name = 'x_enchanting_scroll', + gain = 1.0 + }, + place = { + name = 'x_enchanting_scroll', + gain = 1.0 + } + }, + is_ground_content = false, + groups = { choppy = 2, oddly_breakable_by_hand = 2, flammable = 2 }, + mod_origin = 'x_enchanting', + ---@param pos Vector + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + meta:set_string('infotext', S('Writing Table')) + meta:set_string('owner', '') + inv:set_size('item', 1) + inv:set_size('sacrifice', 1) + inv:set_size('result', 1) + inv:set_size('trade', 1) + end, + ---@param pos Vector + ---@param placer ObjectRef | nil + ---@param itemstack ItemStack + ---@param pointed_thing PointedThingDef + after_place_node = function(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + + if not placer then + return + end + + local player_name = placer:get_player_name() + + local props = { + player_name = player_name + } + + meta:set_string('owner', player_name) + meta:set_string('infotext', S('Writing Table') .. ' (' .. S('owned by') .. ' ' .. player_name .. ')') + + local formspec = XEnchanting:get_formspec_writing_table(pos, props) + meta:set_string('formspec', formspec) + end, + ---@param pos Vector + ---@param node NodeDef + ---@param clicker ObjectRef + ---@param itemstack ItemStack + ---@param pointed_thing? PointedThingDef + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local p_name = clicker:get_player_name() + local props = { + player_name = p_name, + inv = inv + } + + if minetest.is_protected(pos, p_name) then + return itemstack + end + + minetest.sound_play('x_enchanting_scroll', { + gain = 0.3, + pos = pos, + max_hear_distance = 10 + }, true) + + local data = XEnchanting:get_writing_table_total_data(props) + + props.data = data + + local formspec = XEnchanting:get_formspec_writing_table(pos, props) + meta:set_string('formspec', formspec) + + return itemstack + end, + ---@param pos Vector + ---@param intensity? number + ---@return table | nil + on_blast = function(pos, intensity) + if minetest.is_protected(pos, '') then + return + end + + local drops = {} + local inv = minetest.get_meta(pos):get_inventory() + local stack_item = inv:get_stack('item', 1) + local stack_sacrifice = inv:get_stack('sacrifice', 1) + local stack_result = inv:get_stack('result', 1) + local stack_trade = inv:get_stack('trade', 1) + + if not stack_item:is_empty() then + drops[#drops + 1] = stack_item:to_table() + end + + if not stack_sacrifice:is_empty() then + drops[#drops + 1] = stack_sacrifice:to_table() + end + + if not stack_result:is_empty() then + drops[#drops + 1] = stack_result:to_table() + end + + if not stack_trade:is_empty() then + drops[#drops + 1] = stack_trade:to_table() + end + + drops[#drops + 1] = 'x_enchanting:writing_table' + minetest.remove_node(pos) + + return drops + end, + ---@param pos Vector + ---@param player? ObjectRef + can_dig = function(pos, player) + if not player then + return false + end + + local inv = minetest.get_meta(pos):get_inventory() + + return inv:is_empty('item') + and inv:is_empty('sacrifice') + and inv:is_empty('result') + and inv:is_empty('trade') + and not minetest.is_protected(pos, player:get_player_name()) + end, + on_rotate = function(pos, node, user, mode, new_param2) + return false + end, + ---@param pos Vector + ---@param listname string + ---@param index number + ---@param stack ItemStack + ---@param player ObjectRef + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + print('allow_metadata_inventory_put') + local st_name = stack:get_name() + local st_meta = stack:get_meta() + + if listname == 'result' then + return 0 + end + + if listname == 'item' + and (st_meta:get_int('is_enchanted') > 0 or minetest.get_item_group(st_name, 'scroll') > 0) + then + return stack:get_count() + elseif listname == 'sacrifice' + and st_meta:get_int('is_enchanted') > 0 + and minetest.get_item_group(st_name, 'scroll') > 0 + then + return stack:get_count() + elseif listname == 'trade' + and ( + st_name == 'default:mese_crystal' + or minetest.get_item_group(st_name, 'enchanting_trade') > 0 + ) + then + return stack:get_count() + end + + return 0 + end, + ---@param pos Vector + ---@param listname string + ---@param index number + ---@param stack ItemStack + ---@param player ObjectRef + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + print('allow_metadata_inventory_take') + local st_name = stack:get_name() + + if listname == 'item' then + return stack:get_count() + elseif listname == 'sacrifice' then + return stack:get_count() + elseif listname == 'result' then + return stack:get_count() + elseif listname == 'trade' + and ( + st_name == 'default:mese_crystal' + or minetest.get_item_group(st_name, 'enchanting_trade') > 0 + ) + then + return stack:get_count() + end + + return 0 + end, + ---@param pos Vector + ---@param from_list string + ---@param from_index number + ---@param to_list string + ---@param to_index number + ---@param count number + ---@param player ObjectRef + allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + print('allow_metadata_inventory_move') + print('allow_metadata_inventory_move') + print('from_list', from_index, from_list) + print('to_list', to_index, to_list) + + if (to_list == 'item' or to_list == 'sacrifice') + and (from_list == 'item' or from_list == 'sacrifice') + then + return count + end + + return 0 + end, + ---@param pos Vector + ---@param listname string + ---@param index number + ---@param stack ItemStack + ---@param player ObjectRef + on_metadata_inventory_put = function(pos, listname, index, stack, player) + print('on_metadata_inventory_put') + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local props = { + player_name = player:get_player_name(), + inv = inv + } + + local data = XEnchanting:get_writing_table_total_data(props) + + props.data = data + + local formspec = XEnchanting:get_formspec_writing_table(pos, props) + meta:set_string('formspec', formspec) + end, + ---@param pos Vector + ---@param listname string + ---@param index number + ---@param stack ItemStack + ---@param player ObjectRef + on_metadata_inventory_take = function(pos, listname, index, stack, player) + print('on_metadata_inventory_take') + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + + if listname == 'result' then + inv:set_stack('item', 1, ItemStack('')) + inv:set_stack('sacrifice', 1, ItemStack('')) + inv:set_stack('result', 1, ItemStack('')) + return + end + + local props = { + player_name = player:get_player_name(), + inv = inv + } + + local data = XEnchanting:get_writing_table_total_data(props) + + props.data = data + + local formspec = XEnchanting:get_formspec_writing_table(pos, props) + meta:set_string('formspec', formspec) + end, + on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + print('on_metadata_inventory_move') + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local props = { + player_name = player:get_player_name(), + inv = inv + } + + local data = XEnchanting:get_writing_table_total_data(props) + + props.data = data + + local formspec = XEnchanting:get_formspec_writing_table(pos, props) + meta:set_string('formspec', formspec) + end, + -- form receive fields + ---@param pos Vector + ---@param formname string + ---@param fields table + ---@param sender ObjectRef + on_receive_fields = function(pos, formname, fields, sender) + + end +}) + +-- Scroll Item +minetest.register_craftitem('x_enchanting:scroll_item', { + description = S('Scroll'), + short_description = S('Scroll'), + inventory_image = 'x_enchanting_scroll_item.png^[colorize:#8F00FF:60', + wield_image = 'x_enchanting_scroll_item.png^[transformFXR90^[colorize:#8F00FF:60', + groups = { scroll = 1, flammable = 3 }, + stack_max = 1 +})