mirror of
https://bitbucket.org/minetest_gamers/x_enchanting.git
synced 2025-06-28 22:06:17 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
673922371c | |||
0d589e69b3 | |||
8935043ed4 | |||
e2cf02d026 | |||
0365b8043b | |||
ba1d30909b | |||
82973b6462 | |||
ecdf5a83d1 | |||
af26c6ed76 | |||
3ee6bb7b80 |
@ -13,5 +13,6 @@
|
|||||||
"media_license": "CC-BY-SA-4.0",
|
"media_license": "CC-BY-SA-4.0",
|
||||||
"repo": "https://bitbucket.org/minetest_gamers/x_enchanting/src/master/",
|
"repo": "https://bitbucket.org/minetest_gamers/x_enchanting/src/master/",
|
||||||
"issue_tracker": "https://bitbucket.org/minetest_gamers/x_enchanting/issues?status=new&status=open",
|
"issue_tracker": "https://bitbucket.org/minetest_gamers/x_enchanting/issues?status=new&status=open",
|
||||||
|
"video_url": "https://youtu.be/JXF-GrQ9Uxs?si=dsgxDMXtm90ovE3D",
|
||||||
"forums": 28861
|
"forums": 28861
|
||||||
}
|
}
|
||||||
|
25
.luacheckrc
25
.luacheckrc
@ -3,27 +3,26 @@ allow_defined_top = true
|
|||||||
max_line_length = false
|
max_line_length = false
|
||||||
|
|
||||||
exclude_files = {
|
exclude_files = {
|
||||||
'./scripts',
|
"./scripts",
|
||||||
'./bin',
|
"./bin",
|
||||||
'./logs',
|
"./logs",
|
||||||
'./node_modules',
|
"./node_modules",
|
||||||
'./sounds',
|
"./sounds",
|
||||||
'./textures',
|
"./textures",
|
||||||
'./models',
|
"./models",
|
||||||
'./docs',
|
"./docs",
|
||||||
'./locale',
|
"./locale",
|
||||||
'./types',
|
"./types",
|
||||||
}
|
}
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
'minetest',
|
"core",
|
||||||
'XEnchanting'
|
"XEnchanting"
|
||||||
}
|
}
|
||||||
|
|
||||||
read_globals = {
|
read_globals = {
|
||||||
"DIR_DELIM", "INIT",
|
"DIR_DELIM", "INIT",
|
||||||
|
|
||||||
"core",
|
|
||||||
"dump", "dump2",
|
"dump", "dump2",
|
||||||
|
|
||||||
"Raycast",
|
"Raycast",
|
||||||
|
@ -17,6 +17,8 @@ Adds Enchanting Mechanics and API.
|
|||||||
* enchanted items have detailed enchantments description/short description
|
* enchanted items have detailed enchantments description/short description
|
||||||
* mesh node model
|
* mesh node model
|
||||||
* mesh entity model and animations
|
* mesh entity model and animations
|
||||||
|
* tool texture will have enchanted glint
|
||||||
|
* adds grind stone to remove enchantments (excluding curses)
|
||||||
|
|
||||||
## How To
|
## How To
|
||||||
|
|
||||||
|
53
api.lua
53
api.lua
@ -1,7 +1,6 @@
|
|||||||
---@diagnostic disable
|
|
||||||
--[[
|
--[[
|
||||||
X Enchanting. Adds Enchanting Mechanics and API.
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
Copyright (C) 2025 SaKeL
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -17,7 +16,7 @@
|
|||||||
License along with this library; if not, write to juraj.vajda@gmail.com
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
---@type XEnchanting
|
---@type XEnchanting
|
||||||
XEnchanting = {
|
XEnchanting = {
|
||||||
@ -321,15 +320,15 @@ end
|
|||||||
|
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
function XEnchanting.has_tool_group(self, name)
|
function XEnchanting.has_tool_group(self, name)
|
||||||
if minetest.get_item_group(name, 'pickaxe') > 0 then
|
if core.get_item_group(name, 'pickaxe') > 0 then
|
||||||
return 'pickaxe'
|
return 'pickaxe'
|
||||||
elseif minetest.get_item_group(name, 'shovel') > 0 then
|
elseif core.get_item_group(name, 'shovel') > 0 then
|
||||||
return 'shovel'
|
return 'shovel'
|
||||||
elseif minetest.get_item_group(name, 'axe') > 0 then
|
elseif core.get_item_group(name, 'axe') > 0 then
|
||||||
return 'axe'
|
return 'axe'
|
||||||
elseif minetest.get_item_group(name, 'sword') > 0 then
|
elseif core.get_item_group(name, 'sword') > 0 then
|
||||||
return 'sword'
|
return 'sword'
|
||||||
elseif minetest.get_item_group(name, 'bow') > 0 then
|
elseif core.get_item_group(name, 'bow') > 0 then
|
||||||
return 'bow'
|
return 'bow'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -337,7 +336,7 @@ function XEnchanting.has_tool_group(self, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function XEnchanting.set_tool_enchantability(self, tool_def)
|
function XEnchanting.set_tool_enchantability(self, tool_def)
|
||||||
if minetest.get_item_group(tool_def.name, 'enchantability') > 0 then
|
if core.get_item_group(tool_def.name, 'enchantability') > 0 then
|
||||||
-- enchantability is already set, we dont need to override the item
|
-- enchantability is already set, we dont need to override the item
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -348,7 +347,7 @@ function XEnchanting.set_tool_enchantability(self, tool_def)
|
|||||||
_enchantability = self.tools_enchantability[tool_def.name]
|
_enchantability = self.tools_enchantability[tool_def.name]
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.override_item(tool_def.name, {
|
core.override_item(tool_def.name, {
|
||||||
groups = mergeTables(tool_def.groups, { enchantability = _enchantability })
|
groups = mergeTables(tool_def.groups, { enchantability = _enchantability })
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -507,7 +506,7 @@ function XEnchanting.get_enchanted_descriptions(self, enchantments)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted'))
|
enchantments_desc = '\n' .. core.colorize('#AE81FF', S('Enchanted'))
|
||||||
.. '\n' .. table.concat(enchantments_desc, '\n')
|
.. '\n' .. table.concat(enchantments_desc, '\n')
|
||||||
enchantments_desc_masked = table.concat(enchantments_desc_masked, '') .. '..?'
|
enchantments_desc_masked = table.concat(enchantments_desc_masked, '') .. '..?'
|
||||||
|
|
||||||
@ -517,6 +516,10 @@ function XEnchanting.get_enchanted_descriptions(self, enchantments)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function XEnchanting.get_glint_texture_modifier(self, image)
|
||||||
|
return image .. '^((' .. image .. '^[contrast:127:127)^[mask:x_enchanting_glint.png^[opacity:80)'
|
||||||
|
end
|
||||||
|
|
||||||
function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name)
|
function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name)
|
||||||
local data = self.form_context[player_name].data
|
local data = self.form_context[player_name].data
|
||||||
|
|
||||||
@ -527,9 +530,9 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
local capabilities = data.slots[level].tool_cap_data
|
local capabilities = data.slots[level].tool_cap_data
|
||||||
local description = data.slots[level].descriptions.enchantments_desc
|
local description = data.slots[level].descriptions.enchantments_desc
|
||||||
local final_enchantments = data.slots[level].final_enchantments
|
local final_enchantments = data.slots[level].final_enchantments
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
local tool_def = minetest.registered_tools[itemstack:get_name()]
|
local tool_def = core.registered_tools[itemstack:get_name()]
|
||||||
local node_meta = minetest.get_meta(pos)
|
local node_meta = core.get_meta(pos)
|
||||||
|
|
||||||
if not tool_def then
|
if not tool_def then
|
||||||
return
|
return
|
||||||
@ -552,7 +555,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
stack_meta:set_string('description', itemstack:get_description() .. '\n' .. description)
|
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_string('short_description', S('Enchanted') .. ' ' .. itemstack:get_short_description())
|
||||||
stack_meta:set_int('is_enchanted', 1)
|
stack_meta:set_int('is_enchanted', 1)
|
||||||
stack_meta:set_string('x_enchanting', minetest.serialize(final_enchantments_meta))
|
stack_meta:set_string('x_enchanting', core.serialize(final_enchantments_meta))
|
||||||
|
|
||||||
if tool_def and tool_def.inventory_image and tool_def.inventory_image ~= '' then
|
if tool_def and tool_def.inventory_image and tool_def.inventory_image ~= '' then
|
||||||
stack_meta:set_string('inventory_image', tool_def.inventory_image .. '^((' .. tool_def.inventory_image .. '^[contrast:127:127)^[mask:x_enchanting_glint.png^[opacity:80)')
|
stack_meta:set_string('inventory_image', tool_def.inventory_image .. '^((' .. tool_def.inventory_image .. '^[contrast:127:127)^[mask:x_enchanting_glint.png^[opacity:80)')
|
||||||
@ -582,7 +585,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
local formspec = self:get_formspec(pos, player_name)
|
local formspec = self:get_formspec(pos, player_name)
|
||||||
node_meta:set_string('formspec', formspec)
|
node_meta:set_string('formspec', formspec)
|
||||||
|
|
||||||
minetest.sound_play('x_enchanting_enchant', {
|
core.sound_play('x_enchanting_enchant', {
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
@ -606,7 +609,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
glow = 1
|
glow = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
if core.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
||||||
-- new syntax, after v5.6.0
|
-- new syntax, after v5.6.0
|
||||||
particlespawner_def = {
|
particlespawner_def = {
|
||||||
amount = 50,
|
amount = 50,
|
||||||
@ -638,7 +641,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.add_particlespawner(particlespawner_def)
|
core.add_particlespawner(particlespawner_def)
|
||||||
end
|
end
|
||||||
|
|
||||||
function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_def)
|
function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_def)
|
||||||
@ -666,7 +669,7 @@ function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_d
|
|||||||
else
|
else
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
for i, group in ipairs(enchantment_def.groups) do
|
for i, group in ipairs(enchantment_def.groups) do
|
||||||
if minetest.get_item_group(tool_def.name, group) > 0 then
|
if core.get_item_group(tool_def.name, group) > 0 then
|
||||||
group_enchantments[enchantment_name] = enchantment_def
|
group_enchantments[enchantment_name] = enchantment_def
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -691,7 +694,7 @@ function XEnchanting.get_enchantment_data(self, player, nr_of_bookshelfs, tool_d
|
|||||||
|
|
||||||
local chosen_enchantment_level = slot_lvl
|
local chosen_enchantment_level = slot_lvl
|
||||||
-- Applying modifiers to the enchantment level
|
-- Applying modifiers to the enchantment level
|
||||||
local enchantability = minetest.get_item_group(tool_def.name, 'enchantability')
|
local enchantability = core.get_item_group(tool_def.name, 'enchantability')
|
||||||
-- Generate a random number between 1 and 1+(enchantability/2), with a triangular distribution
|
-- Generate a random number between 1 and 1+(enchantability/2), with a triangular distribution
|
||||||
local rand_enchantability = 1 + math.random(enchantability / 4 + 1) + math.random(enchantability / 4 + 1)
|
local rand_enchantability = 1 + math.random(enchantability / 4 + 1) + math.random(enchantability / 4 + 1)
|
||||||
-- Choose the enchantment level
|
-- Choose the enchantment level
|
||||||
@ -878,7 +881,7 @@ end
|
|||||||
|
|
||||||
local function get_formspec_bg(player_name, bg_img)
|
local function get_formspec_bg(player_name, bg_img)
|
||||||
local bg_image = bg_img and bg_img or 'x_enchanting_gui_formbg.png'
|
local bg_image = bg_img and bg_img or 'x_enchanting_gui_formbg.png'
|
||||||
local info = minetest.get_player_information(player_name)
|
local info = core.get_player_information(player_name)
|
||||||
local bg = 'background[5,5;1,1;' .. bg_image .. ';true]'
|
local bg = 'background[5,5;1,1;' .. bg_image .. ';true]'
|
||||||
|
|
||||||
if info.formspec_version > 1 then
|
if info.formspec_version > 1 then
|
||||||
@ -890,7 +893,7 @@ end
|
|||||||
|
|
||||||
function XEnchanting.get_formspec(self, pos, player_name, data)
|
function XEnchanting.get_formspec(self, pos, player_name, data)
|
||||||
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@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]'
|
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
|
---@diagnostic disable-next-line: codestyle-check
|
||||||
@ -931,10 +934,10 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
|||||||
|
|
||||||
if inv:get_stack('trade', 1):get_count() >= i then
|
if inv:get_stack('trade', 1):get_count() >= i then
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@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 .. ']') .. ']'
|
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 .. core.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||||
else
|
else
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@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 .. ']') .. ']'
|
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 .. core.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||||
end
|
end
|
||||||
|
|
||||||
formspec[#formspec + 1] = 'image[2.3,' .. -0.5 + i .. ';1,1;x_enchanting_image_trade_' .. i .. '.png;]'
|
formspec[#formspec + 1] = 'image[2.3,' .. -0.5 + i .. ';1,1;x_enchanting_image_trade_' .. i .. '.png;]'
|
||||||
@ -1015,7 +1018,7 @@ function XEnchanting.has_all_cursed_ench(self, itemstack)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local item_stack_meta = itemstack:get_meta()
|
local item_stack_meta = itemstack:get_meta()
|
||||||
local stack_enchantment_data = minetest.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
local stack_enchantment_data = core.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
||||||
local stack_enchantment_data_length = get_table_length(stack_enchantment_data)
|
local stack_enchantment_data_length = get_table_length(stack_enchantment_data)
|
||||||
local cursed_ench = 0
|
local cursed_ench = 0
|
||||||
|
|
||||||
|
BIN
assets/promo_scene.blend
Normal file
BIN
assets/promo_scene.blend
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
---@diagnostic disable
|
---@diagnostic disable
|
||||||
--[[
|
--[[
|
||||||
X Enchanting. Adds Enchanting Mechanics and API.
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
Copyright (C) 2025 SaKeL
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -17,13 +17,13 @@
|
|||||||
License along with this library; if not, write to juraj.vajda@gmail.com
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
----
|
----
|
||||||
--- Grindstone Node
|
--- Grindstone Node
|
||||||
----
|
----
|
||||||
|
|
||||||
minetest.register_node('x_enchanting:grindstone', {
|
core.register_node('x_enchanting:grindstone', {
|
||||||
description = S('Grindstone'),
|
description = S('Grindstone'),
|
||||||
short_description = S('Grindstone'),
|
short_description = S('Grindstone'),
|
||||||
drawtype = 'mesh',
|
drawtype = 'mesh',
|
||||||
@ -50,7 +50,7 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
mod_origin = 'x_enchanting',
|
mod_origin = 'x_enchanting',
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
meta:set_string('infotext', S('Grindstone'))
|
meta:set_string('infotext', S('Grindstone'))
|
||||||
@ -64,7 +64,7 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
---@param pointed_thing PointedThingDef
|
---@param pointed_thing PointedThingDef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
if not placer then
|
if not placer then
|
||||||
return
|
return
|
||||||
@ -85,17 +85,17 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
---@param pointed_thing? PointedThingDef
|
---@param pointed_thing? PointedThingDef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = clicker:get_player_name()
|
local p_name = clicker:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
||||||
|
|
||||||
if minetest.is_protected(pos, p_name) then
|
if core.is_protected(pos, p_name) then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.sound_play('everness_wood_hit', {
|
core.sound_play('x_enchanting_wood_hit', {
|
||||||
gain = 0.5,
|
gain = 0.5,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
@ -111,12 +111,12 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
---@return table | nil
|
---@return table | nil
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_blast = function(pos, intensity)
|
on_blast = function(pos, intensity)
|
||||||
if minetest.is_protected(pos, '') then
|
if core.is_protected(pos, '') then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local drops = {}
|
local drops = {}
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
local stack_item = inv:get_stack('item', 1)
|
local stack_item = inv:get_stack('item', 1)
|
||||||
|
|
||||||
if not stack_item:is_empty() then
|
if not stack_item:is_empty() then
|
||||||
@ -124,7 +124,7 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
end
|
end
|
||||||
|
|
||||||
drops[#drops + 1] = 'x_enchanting:grindstone'
|
drops[#drops + 1] = 'x_enchanting:grindstone'
|
||||||
minetest.remove_node(pos)
|
core.remove_node(pos)
|
||||||
|
|
||||||
return drops
|
return drops
|
||||||
end,
|
end,
|
||||||
@ -135,11 +135,11 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
|
|
||||||
return inv:is_empty('item')
|
return inv:is_empty('item')
|
||||||
and inv:is_empty('result')
|
and inv:is_empty('result')
|
||||||
and not minetest.is_protected(pos, player:get_player_name())
|
and not core.is_protected(pos, player:get_player_name())
|
||||||
end,
|
end,
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
@ -191,13 +191,13 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
--
|
--
|
||||||
-- Create new itemstack with removed enchantments (excl. curses) and populate the result slot with this new item
|
-- Create new itemstack with removed enchantments (excl. curses) and populate the result slot with this new item
|
||||||
--
|
--
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
local item_stack_meta = item_stack:get_meta()
|
local item_stack_meta = item_stack:get_meta()
|
||||||
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
||||||
local stack_enchantment_data = minetest.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
local stack_enchantment_data = core.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
||||||
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
||||||
|
|
||||||
if not inv:is_empty('item') and is_enchanted == 1 and not has_all_cursed_ench then
|
if not inv:is_empty('item') and is_enchanted == 1 and not has_all_cursed_ench then
|
||||||
@ -253,12 +253,12 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
|
|
||||||
-- Upgrade description with remaining enchantments
|
-- Upgrade description with remaining enchantments
|
||||||
if #current_enchantments > 0 then
|
if #current_enchantments > 0 then
|
||||||
local item_stack_def = minetest.registered_tools[item_stack:get_name()]
|
local item_stack_def = core.registered_tools[item_stack:get_name()]
|
||||||
item_stack_meta:set_string('description', (item_stack_def and item_stack_def.description or '') .. '\n' .. descriptions.enchantments_desc)
|
item_stack_meta:set_string('description', (item_stack_def and item_stack_def.description or '') .. '\n' .. descriptions.enchantments_desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
item_stack_meta:set_tool_capabilities(nil)
|
item_stack_meta:set_tool_capabilities(nil)
|
||||||
item_stack_meta:set_string('x_enchanting', minetest.serialize(stack_enchantment_data))
|
item_stack_meta:set_string('x_enchanting', core.serialize(stack_enchantment_data))
|
||||||
|
|
||||||
inv:set_stack('result', 1, item_stack)
|
inv:set_stack('result', 1, item_stack)
|
||||||
end
|
end
|
||||||
@ -274,14 +274,14 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local result_stack = inv:get_stack('result', 1)
|
local result_stack = inv:get_stack('result', 1)
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
local item_stack_meta = item_stack:get_meta()
|
local item_stack_meta = item_stack:get_meta()
|
||||||
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
local has_all_cursed_ench = XEnchanting:has_all_cursed_ench(item_stack)
|
||||||
local stack_enchantment_data = minetest.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
local stack_enchantment_data = core.deserialize(item_stack_meta:get_string('x_enchanting')) or {}
|
||||||
local result_payment_stack = ItemStack({ name = 'default:mese_crystal_fragment' })
|
local result_payment_stack = ItemStack({ name = 'default:mese_crystal_fragment' })
|
||||||
|
|
||||||
if item_stack:is_empty() or has_all_cursed_ench then
|
if item_stack:is_empty() or has_all_cursed_ench then
|
||||||
@ -324,14 +324,16 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result_total = math.floor(result_total / 10)
|
||||||
|
|
||||||
result_payment_stack:set_count(result_total)
|
result_payment_stack:set_count(result_total)
|
||||||
|
|
||||||
if listname == 'result' and result_stack:is_empty() then
|
if listname == 'result' and result_stack:is_empty() then
|
||||||
-- Drop payment result
|
-- Drop payment result
|
||||||
inv:set_stack('item', 1, ItemStack(''))
|
inv:set_stack('item', 1, ItemStack(''))
|
||||||
minetest.item_drop(result_payment_stack, player, player:get_pos())
|
core.item_drop(result_payment_stack, player, player:get_pos())
|
||||||
|
|
||||||
minetest.sound_play('x_enchanting_disenchant', {
|
core.sound_play('x_enchanting_disenchant', {
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
@ -355,7 +357,7 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
glow = 1
|
glow = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.add_particlespawner(particlespawner_def)
|
core.add_particlespawner(particlespawner_def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -369,7 +371,7 @@ minetest.register_node('x_enchanting:grindstone', {
|
|||||||
-- Recipe
|
-- Recipe
|
||||||
---
|
---
|
||||||
|
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = 'x_enchanting:grindstone',
|
output = 'x_enchanting:grindstone',
|
||||||
recipe = {
|
recipe = {
|
||||||
{ 'group:stick', 'stairs:slab_stone', 'group:stick' },
|
{ 'group:stick', 'stairs:slab_stone', 'group:stick' },
|
||||||
|
52
init.lua
52
init.lua
@ -1,6 +1,6 @@
|
|||||||
--[[
|
--[[
|
||||||
X Enchanting. Adds Enchanting Mechanics and API.
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
Copyright (C) 2025 SaKeL
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -16,8 +16,8 @@
|
|||||||
License along with this library; if not, write to juraj.vajda@gmail.com
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local path = minetest.get_modpath('x_enchanting')
|
local path = core.get_modpath('x_enchanting')
|
||||||
local mod_start_time = minetest.get_us_time()
|
local mod_start_time = core.get_us_time()
|
||||||
|
|
||||||
dofile(path .. '/api.lua')
|
dofile(path .. '/api.lua')
|
||||||
dofile(path .. '/table.lua')
|
dofile(path .. '/table.lua')
|
||||||
@ -31,23 +31,23 @@ local function starts_with(str, start)
|
|||||||
return str:sub(1, #start) == start
|
return str:sub(1, #start) == start
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(function()
|
core.register_on_mods_loaded(function()
|
||||||
-- Tools override
|
-- Tools override
|
||||||
for name, tool_def in pairs(minetest.registered_tools) do
|
for name, tool_def in pairs(core.registered_tools) do
|
||||||
if XEnchanting:has_tool_group(name) then
|
if XEnchanting:has_tool_group(name) then
|
||||||
XEnchanting:set_tool_enchantability(tool_def)
|
XEnchanting:set_tool_enchantability(tool_def)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Ores override - Fortune
|
-- Ores override - Fortune
|
||||||
for _, def in pairs(minetest.registered_ores) do
|
for _, def in pairs(core.registered_ores) do
|
||||||
if not XEnchanting.registered_ores[def.ore] then
|
if not XEnchanting.registered_ores[def.ore] then
|
||||||
XEnchanting.registered_ores[def.ore] = true
|
XEnchanting.registered_ores[def.ore] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Entities override - Looting
|
-- Entities override - Looting
|
||||||
for name, def in pairs(minetest.registered_entities) do
|
for name, def in pairs(core.registered_entities) do
|
||||||
if starts_with(name, 'mobs_animal:')
|
if starts_with(name, 'mobs_animal:')
|
||||||
or starts_with(name, 'mobs_monster:')
|
or starts_with(name, 'mobs_monster:')
|
||||||
then
|
then
|
||||||
@ -103,7 +103,7 @@ minetest.register_on_mods_loaded(function()
|
|||||||
stack:set_count(stack:get_count() * chance)
|
stack:set_count(stack:get_count() * chance)
|
||||||
|
|
||||||
if stack:get_count() > 0 then
|
if stack:get_count() > 0 then
|
||||||
minetest.item_drop(stack, puncher, pos)
|
core.item_drop(stack, puncher, pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -161,7 +161,7 @@ minetest.register_on_mods_loaded(function()
|
|||||||
stack:set_count(stack:get_count() * chance)
|
stack:set_count(stack:get_count() * chance)
|
||||||
|
|
||||||
if stack:get_count() > 0 then
|
if stack:get_count() > 0 then
|
||||||
minetest.item_drop(stack, puncher, pos)
|
core.item_drop(stack, puncher, pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -173,7 +173,7 @@ minetest.register_on_mods_loaded(function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
minetest.register_on_joinplayer(function(player, last_login)
|
core.register_on_joinplayer(function(player, last_login)
|
||||||
XEnchanting.form_context[player:get_player_name()] = nil
|
XEnchanting.form_context[player:get_player_name()] = nil
|
||||||
|
|
||||||
if not XEnchanting.player_seeds[player:get_player_name()] then
|
if not XEnchanting.player_seeds[player:get_player_name()] then
|
||||||
@ -182,20 +182,20 @@ minetest.register_on_joinplayer(function(player, last_login)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
minetest.register_on_leaveplayer(function(player, timed_out)
|
core.register_on_leaveplayer(function(player, timed_out)
|
||||||
XEnchanting.form_context[player:get_player_name()] = nil
|
XEnchanting.form_context[player:get_player_name()] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local old_handle_node_drops = minetest.handle_node_drops
|
local old_handle_node_drops = core.handle_node_drops
|
||||||
|
|
||||||
function minetest.handle_node_drops(pos, drops, digger)
|
function core.handle_node_drops(pos, drops, digger)
|
||||||
if not digger
|
if not digger
|
||||||
or not digger:is_player()
|
or not digger:is_player()
|
||||||
then
|
then
|
||||||
return old_handle_node_drops(pos, drops, digger)
|
return old_handle_node_drops(pos, drops, digger)
|
||||||
end
|
end
|
||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
local wield_stack = digger:get_wielded_item()
|
local wield_stack = digger:get_wielded_item()
|
||||||
local wield_stack_meta = wield_stack:get_meta()
|
local wield_stack_meta = wield_stack:get_meta()
|
||||||
|
|
||||||
@ -207,13 +207,13 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
|
|
||||||
for _, itemstring in ipairs(drops) do
|
for _, itemstring in ipairs(drops) do
|
||||||
if XEnchanting.registered_ores[node.name]
|
if XEnchanting.registered_ores[node.name]
|
||||||
or minetest.get_item_group(node.name, 'stone') > 0
|
or core.get_item_group(node.name, 'stone') > 0
|
||||||
or minetest.get_item_group(node.name, 'soil') > 0
|
or core.get_item_group(node.name, 'soil') > 0
|
||||||
or minetest.get_item_group(node.name, 'sand') > 0
|
or core.get_item_group(node.name, 'sand') > 0
|
||||||
or minetest.get_item_group(node.name, 'snowy') > 0
|
or core.get_item_group(node.name, 'snowy') > 0
|
||||||
or minetest.get_item_group(node.name, 'slippery') > 0
|
or core.get_item_group(node.name, 'slippery') > 0
|
||||||
or minetest.get_item_group(node.name, 'tree') > 0
|
or core.get_item_group(node.name, 'tree') > 0
|
||||||
or minetest.get_item_group(node.name, 'leaves') > 0
|
or core.get_item_group(node.name, 'leaves') > 0
|
||||||
then
|
then
|
||||||
local tool_capabilities = wield_stack:get_tool_capabilities()
|
local tool_capabilities = wield_stack:get_tool_capabilities()
|
||||||
local stack = ItemStack(itemstring)
|
local stack = ItemStack(itemstring)
|
||||||
@ -238,7 +238,7 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
local silk_touch = wield_stack_meta:get_float('is_silk_touch')
|
local silk_touch = wield_stack_meta:get_float('is_silk_touch')
|
||||||
|
|
||||||
if silk_touch > 0
|
if silk_touch > 0
|
||||||
and minetest.get_item_group(node.name, 'no_silktouch') == 0
|
and core.get_item_group(node.name, 'no_silktouch') == 0
|
||||||
then
|
then
|
||||||
-- drop raw item/node
|
-- drop raw item/node
|
||||||
return old_handle_node_drops(pos, { ItemStack(node.name) }, digger)
|
return old_handle_node_drops(pos, { ItemStack(node.name) }, digger)
|
||||||
@ -248,7 +248,7 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
core.register_on_player_hpchange(function(player, hp_change, reason)
|
||||||
-- Curse of Vanishing
|
-- Curse of Vanishing
|
||||||
if (player:get_hp() + hp_change) <= 0 then
|
if (player:get_hp() + hp_change) <= 0 then
|
||||||
-- Going to die
|
-- Going to die
|
||||||
@ -273,9 +273,9 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
|||||||
end, true)
|
end, true)
|
||||||
|
|
||||||
-- Knockback (only for players)
|
-- Knockback (only for players)
|
||||||
local old_calculate_knockback = minetest.calculate_knockback
|
local old_calculate_knockback = core.calculate_knockback
|
||||||
|
|
||||||
function minetest.calculate_knockback(player, hitter, time_from_last_punch,
|
function core.calculate_knockback(player, hitter, time_from_last_punch,
|
||||||
tool_capabilities, dir, distance, damage)
|
tool_capabilities, dir, distance, damage)
|
||||||
if hitter and hitter:is_player() then
|
if hitter and hitter:is_player() then
|
||||||
local hitter_wield_stack = hitter:get_wielded_item()
|
local hitter_wield_stack = hitter:get_wielded_item()
|
||||||
@ -307,6 +307,6 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch,
|
|||||||
tool_capabilities, dir, distance, damage)
|
tool_capabilities, dir, distance, damage)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
|
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
||||||
|
|
||||||
print('[Mod] x_enchanting loaded.. [' .. mod_end_time .. 's]')
|
print('[Mod] x_enchanting loaded.. [' .. mod_end_time .. 's]')
|
||||||
|
2
mod.conf
2
mod.conf
@ -1,6 +1,6 @@
|
|||||||
name = x_enchanting
|
name = x_enchanting
|
||||||
description = Adds Enchanting Mechanics and API.
|
description = Adds Enchanting Mechanics and API.
|
||||||
depends =
|
depends =
|
||||||
optional_depends = xdecor, item_drop, stairs
|
optional_depends = xdecor, item_drop, stairs, enchanting
|
||||||
supported_games = minetest_game
|
supported_games = minetest_game
|
||||||
min_minetest_version = 5.4
|
min_minetest_version = 5.4
|
||||||
|
BIN
screenshot.2.png
BIN
screenshot.2.png
Binary file not shown.
Before Width: | Height: | Size: 226 KiB |
BIN
screenshot.3.png
BIN
screenshot.3.png
Binary file not shown.
Before Width: | Height: | Size: 385 KiB |
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 289 KiB After Width: | Height: | Size: 1.3 MiB |
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Deploy code to CDB
|
* Deploy code to CDB
|
||||||
* Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
* Copyright (C) 2025 SaKeL
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -29,7 +29,7 @@ try {
|
|||||||
ref: 'master'
|
ref: 'master'
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch('https://content.minetest.net/api/packages/SaKeL/x_enchanting/releases/new/', {
|
const response = await fetch('https://content.luanti.org/api/packages/SaKeL/x_enchanting/releases/new/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Run LUA diagnostics in continuous integration
|
* Run LUA diagnostics in continuous integration
|
||||||
* Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
* Copyright (C) 2025 SaKeL
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
92
table.lua
92
table.lua
@ -1,7 +1,7 @@
|
|||||||
---@diagnostic disable
|
---@diagnostic disable
|
||||||
--[[
|
--[[
|
||||||
X Enchanting. Adds Enchanting Mechanics and API.
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
Copyright (C) 2023 SaKeL <juraj.vajda@gmail.com>
|
Copyright (C) 2025 SaKeL
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
modify it under the terms of the GNU Lesser General Public
|
||||||
@ -17,13 +17,13 @@
|
|||||||
License along with this library; if not, write to juraj.vajda@gmail.com
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = core.get_translator(core.get_current_modname())
|
||||||
|
|
||||||
----
|
----
|
||||||
--- Table Node
|
--- Table Node
|
||||||
----
|
----
|
||||||
|
|
||||||
minetest.register_node('x_enchanting:table', {
|
core.register_node('x_enchanting:table', {
|
||||||
description = S('Enchanting Table'),
|
description = S('Enchanting Table'),
|
||||||
short_description = S('Enchanting Table'),
|
short_description = S('Enchanting Table'),
|
||||||
drawtype = 'mesh',
|
drawtype = 'mesh',
|
||||||
@ -63,15 +63,15 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
light_source = 6,
|
light_source = 6,
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
meta:set_string('infotext', S('Enchanting Table'))
|
meta:set_string('infotext', S('Enchanting Table'))
|
||||||
meta:set_string('owner', '')
|
meta:set_string('owner', '')
|
||||||
inv:set_size('item', 1)
|
inv:set_size('item', 1)
|
||||||
inv:set_size('trade', 1)
|
inv:set_size('trade', 1)
|
||||||
minetest.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
|
core.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
|
||||||
minetest.get_node_timer(pos):start(5)
|
core.get_node_timer(pos):start(5)
|
||||||
end,
|
end,
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
---@param placer ObjectRef | nil
|
---@param placer ObjectRef | nil
|
||||||
@ -79,7 +79,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param pointed_thing PointedThingDef
|
---@param pointed_thing PointedThingDef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
|
|
||||||
if not placer then
|
if not placer then
|
||||||
return
|
return
|
||||||
@ -100,34 +100,34 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param pointed_thing? PointedThingDef
|
---@param pointed_thing? PointedThingDef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = clicker:get_player_name()
|
local p_name = clicker:get_player_name()
|
||||||
|
|
||||||
if minetest.is_protected(pos, p_name) then
|
if core.is_protected(pos, p_name) then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.sound_play('x_enchanting_scroll', {
|
core.sound_play('x_enchanting_scroll', {
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
}, true)
|
}, true)
|
||||||
|
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = core.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
)
|
)
|
||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
|
|
||||||
if not inv:is_empty('item') and inv:get_stack('item', 1):get_meta():get_int('is_enchanted') ~= 1 then
|
if not inv:is_empty('item') and inv:get_stack('item', 1):get_meta():get_int('is_enchanted') ~= 1 then
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
local data = XEnchanting:get_enchantment_data(
|
local data = XEnchanting:get_enchantment_data(
|
||||||
clicker,
|
clicker,
|
||||||
#bookshelfs,
|
#bookshelfs,
|
||||||
minetest.registered_tools[item_stack:get_name()]
|
core.registered_tools[item_stack:get_name()]
|
||||||
)
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
@ -145,12 +145,12 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@return table | nil
|
---@return table | nil
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_blast = function(pos, intensity)
|
on_blast = function(pos, intensity)
|
||||||
if minetest.is_protected(pos, '') then
|
if core.is_protected(pos, '') then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local drops = {}
|
local drops = {}
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
local stack_item = inv:get_stack('item', 1)
|
local stack_item = inv:get_stack('item', 1)
|
||||||
local stack_trade = inv:get_stack('trade', 1)
|
local stack_trade = inv:get_stack('trade', 1)
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
end
|
end
|
||||||
|
|
||||||
drops[#drops + 1] = 'x_enchanting:table'
|
drops[#drops + 1] = 'x_enchanting:table'
|
||||||
minetest.remove_node(pos)
|
core.remove_node(pos)
|
||||||
|
|
||||||
return drops
|
return drops
|
||||||
end,
|
end,
|
||||||
@ -174,11 +174,11 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
|
|
||||||
return inv:is_empty('item')
|
return inv:is_empty('item')
|
||||||
and inv:is_empty('trade')
|
and inv:is_empty('trade')
|
||||||
and not minetest.is_protected(pos, player:get_player_name())
|
and not core.is_protected(pos, player:get_player_name())
|
||||||
end,
|
end,
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
@ -189,10 +189,10 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_timer = function(pos, elapsed)
|
on_timer = function(pos, elapsed)
|
||||||
-- entity
|
-- entity
|
||||||
local table_scroll = minetest.get_objects_inside_radius(pos, 0.9)
|
local table_scroll = core.get_objects_inside_radius(pos, 0.9)
|
||||||
|
|
||||||
if #table_scroll == 0 then
|
if #table_scroll == 0 then
|
||||||
minetest.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
|
core.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
|
||||||
end
|
end
|
||||||
|
|
||||||
local particlespawner_def = {
|
local particlespawner_def = {
|
||||||
@ -212,7 +212,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
glow = 1
|
glow = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
if core.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
||||||
-- new syntax, after v5.6.0
|
-- new syntax, after v5.6.0
|
||||||
particlespawner_def = {
|
particlespawner_def = {
|
||||||
amount = 50,
|
amount = 50,
|
||||||
@ -243,10 +243,10 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.add_particlespawner(particlespawner_def)
|
core.add_particlespawner(particlespawner_def)
|
||||||
|
|
||||||
---bookshelfs
|
---bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = core.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
@ -267,8 +267,8 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local rand2 = math.random(10, 500) / 100
|
local rand2 = math.random(10, 500) / 100
|
||||||
local rand3 = math.random(50, 200) / 100
|
local rand3 = math.random(50, 200) / 100
|
||||||
|
|
||||||
minetest.after(rand2, function()
|
core.after(rand2, function()
|
||||||
minetest.add_particle({
|
core.add_particle({
|
||||||
pos = pos_random,
|
pos = pos_random,
|
||||||
velocity = { x = x, y = 2 - y, z = z },
|
velocity = { x = x, y = 2 - y, z = z },
|
||||||
acceleration = { x = 0, y = rand1, z = 0 },
|
acceleration = { x = 0, y = rand1, z = 0 },
|
||||||
@ -284,7 +284,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
end,
|
end,
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 0.9)) do
|
for _, obj in ipairs(core.get_objects_inside_radius(pos, 0.9)) do
|
||||||
if obj
|
if obj
|
||||||
and obj:get_luaentity()
|
and obj:get_luaentity()
|
||||||
and obj:get_luaentity().name == 'x_enchanting:table_scroll'
|
and obj:get_luaentity().name == 'x_enchanting:table_scroll'
|
||||||
@ -306,14 +306,14 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local is_enchanted = st_meta:get_int('is_enchanted')
|
local is_enchanted = st_meta:get_int('is_enchanted')
|
||||||
|
|
||||||
if listname == 'item'
|
if listname == 'item'
|
||||||
and minetest.get_item_group(st_name, 'enchantability') > 0
|
and core.get_item_group(st_name, 'enchantability') > 0
|
||||||
and is_enchanted ~= 1
|
and is_enchanted ~= 1
|
||||||
then
|
then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
elseif listname == 'trade'
|
elseif listname == 'trade'
|
||||||
and (
|
and (
|
||||||
st_name == 'default:mese_crystal'
|
st_name == 'default:mese_crystal'
|
||||||
or minetest.get_item_group(st_name, 'enchanting_trade') > 0
|
or core.get_item_group(st_name, 'enchanting_trade') > 0
|
||||||
)
|
)
|
||||||
and is_enchanted ~= 1
|
and is_enchanted ~= 1
|
||||||
then
|
then
|
||||||
@ -336,7 +336,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
elseif listname == 'trade'
|
elseif listname == 'trade'
|
||||||
and (
|
and (
|
||||||
st_name == 'default:mese_crystal'
|
st_name == 'default:mese_crystal'
|
||||||
or minetest.get_item_group(st_name, 'enchanting_trade') > 0
|
or core.get_item_group(st_name, 'enchanting_trade') > 0
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
@ -362,7 +362,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
@ -371,7 +371,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
|
|
||||||
if not inv:is_empty('item') and is_enchanted == 0 then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = core.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
@ -380,7 +380,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local data = XEnchanting:get_enchantment_data(
|
local data = XEnchanting:get_enchantment_data(
|
||||||
player,
|
player,
|
||||||
#bookshelfs,
|
#bookshelfs,
|
||||||
minetest.registered_tools[item_stack:get_name()]
|
core.registered_tools[item_stack:get_name()]
|
||||||
)
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
@ -398,7 +398,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
local p_name = player:get_player_name()
|
local p_name = player:get_player_name()
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local item_stack = inv:get_stack('item', 1)
|
||||||
@ -407,7 +407,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
|
|
||||||
if not inv:is_empty('item') and is_enchanted == 0 then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = core.find_nodes_in_area(
|
||||||
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
{ x = pos.x - 2, y = pos.y, z = pos.z - 2 },
|
||||||
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
{ x = pos.x + 2, y = pos.y + 2, z = pos.z + 2 },
|
||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
@ -416,7 +416,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
local data = XEnchanting:get_enchantment_data(
|
local data = XEnchanting:get_enchantment_data(
|
||||||
player,
|
player,
|
||||||
#bookshelfs,
|
#bookshelfs,
|
||||||
minetest.registered_tools[item_stack:get_name()]
|
core.registered_tools[item_stack:get_name()]
|
||||||
)
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
@ -455,7 +455,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = core.get_meta(pos):get_inventory()
|
||||||
|
|
||||||
if inv:is_empty('trade') or inv:is_empty('item') then
|
if inv:is_empty('trade') or inv:is_empty('item') then
|
||||||
return
|
return
|
||||||
@ -488,7 +488,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
--- Entity (Scroll)
|
--- Entity (Scroll)
|
||||||
----
|
----
|
||||||
|
|
||||||
minetest.register_entity('x_enchanting:table_scroll', {
|
core.register_entity('x_enchanting:table_scroll', {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
visual = 'mesh',
|
visual = 'mesh',
|
||||||
mesh = 'x_enchanting_scroll.b3d',
|
mesh = 'x_enchanting_scroll.b3d',
|
||||||
@ -543,7 +543,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
-- table
|
-- table
|
||||||
if self._tablechecktimer <= 0 then
|
if self._tablechecktimer <= 0 then
|
||||||
self._tablechecktimer = 5
|
self._tablechecktimer = 5
|
||||||
local node = minetest.get_node({ x = pos.x, y = pos.y - 0.7, z = pos.z })
|
local node = core.get_node({ x = pos.x, y = pos.y - 0.7, z = pos.z })
|
||||||
|
|
||||||
if node.name ~= 'x_enchanting:table' then
|
if node.name ~= 'x_enchanting:table' then
|
||||||
-- remove entity when no table under it
|
-- remove entity when no table under it
|
||||||
@ -554,7 +554,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
-- player
|
-- player
|
||||||
if self._playerchecktimer <= 0 then
|
if self._playerchecktimer <= 0 then
|
||||||
self._playerchecktimer = 1
|
self._playerchecktimer = 1
|
||||||
local objects = minetest.get_objects_inside_radius(pos, 5)
|
local objects = core.get_objects_inside_radius(pos, 5)
|
||||||
|
|
||||||
-- inital value
|
-- inital value
|
||||||
local shortest_distance = 10
|
local shortest_distance = 10
|
||||||
@ -587,7 +587,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
self._scroll_closed = false
|
self._scroll_closed = false
|
||||||
self.object:set_animation(unpack(XEnchanting.scroll_animations.scroll_open))
|
self.object:set_animation(unpack(XEnchanting.scroll_animations.scroll_open))
|
||||||
|
|
||||||
minetest.sound_play('x_enchanting_scroll', {
|
core.sound_play('x_enchanting_scroll', {
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
@ -596,7 +596,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
self._scroll_closed = true
|
self._scroll_closed = true
|
||||||
self.object:set_animation(unpack(XEnchanting.scroll_animations.scroll_close))
|
self.object:set_animation(unpack(XEnchanting.scroll_animations.scroll_close))
|
||||||
|
|
||||||
minetest.sound_play('x_enchanting_scroll', {
|
core.sound_play('x_enchanting_scroll', {
|
||||||
gain = 0.3,
|
gain = 0.3,
|
||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
@ -607,7 +607,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
-- rotation
|
-- rotation
|
||||||
if self._player and self._player:get_pos() then
|
if self._player and self._player:get_pos() then
|
||||||
local direction = vector.direction(pos, self._player:get_pos())
|
local direction = vector.direction(pos, self._player:get_pos())
|
||||||
self.object:set_yaw(minetest.dir_to_yaw(direction))
|
self.object:set_yaw(core.dir_to_yaw(direction))
|
||||||
else
|
else
|
||||||
self.object:set_rotation({
|
self.object:set_rotation({
|
||||||
x = self._last_rotation.x,
|
x = self._last_rotation.x,
|
||||||
@ -633,17 +633,17 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
-- Recipe
|
-- Recipe
|
||||||
---
|
---
|
||||||
|
|
||||||
if minetest.get_modpath('xdecor') then
|
if core.get_modpath('xdecor') or core.get_modpath('enchanting') then
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = 'x_enchanting:table',
|
output = 'x_enchanting:table',
|
||||||
recipe = {
|
recipe = {
|
||||||
{ 'default:book', '', '' },
|
{ 'default:book', '', '' },
|
||||||
{ 'default:diamond', 'default:obsidian', 'default:diamond' },
|
{ 'default:diamond', 'xdecor:enchantment_table', 'default:diamond' },
|
||||||
{ 'default:obsidian', 'default:obsidian', 'default:obsidian' }
|
{ 'default:obsidian', 'default:obsidian', 'default:obsidian' }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
minetest.register_craft({
|
core.register_craft({
|
||||||
output = 'x_enchanting:table',
|
output = 'x_enchanting:table',
|
||||||
recipe = {
|
recipe = {
|
||||||
{ '', 'default:book', '' },
|
{ '', 'default:book', '' },
|
||||||
|
Reference in New Issue
Block a user