add silk touch enchant, switch sounds to OSI licensing

This commit is contained in:
Juraj Vajda 2022-11-10 15:26:14 -05:00
parent 55cb91917a
commit 769af761f1
21 changed files with 82 additions and 9 deletions

View File

@ -16,13 +16,14 @@ exclude_files = {
} }
globals = { globals = {
'minetest',
'XEnchanting' 'XEnchanting'
} }
read_globals = { read_globals = {
"DIR_DELIM", "INIT", "DIR_DELIM", "INIT",
"minetest", "core", "core",
"dump", "dump2", "dump", "dump2",
"Raycast", "Raycast",

View File

@ -62,6 +62,10 @@ Increases the item's durability.
Increases the player's mining speed. Also adds mining groupcaps to item, e.g. enchanted wood pickaxe can mine level 1 nodes (e.g. obsidian) after enchantment. Increases the player's mining speed. Also adds mining groupcaps to item, e.g. enchanted wood pickaxe can mine level 1 nodes (e.g. obsidian) after enchantment.
#### Silk Touch
Causes certain blocks to drop themselves as items instead of their usual drops when mined. Mods can prevent this behaviour with adding group `{ no_silktouch = 1 }` to the nodes.
## Dependencies ## Dependencies
- none - none
@ -129,11 +133,11 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
### Sounds ### Sounds
**Mixkit Sound Effects Free License**, Sound effects obtained from https://mixkit.co **Creative Commons License, Kostas17**, https://freesound.org
- x_enchanting_enchant.ogg - x_enchanting_enchant.ogg
**Standard License**, Sound effects obtained from https://mixkit.co **Creative Commons License, jammaj**, https://freesound.org
- x_enchanting_scroll.1.ogg - x_enchanting_scroll.1.ogg
- x_enchanting_scroll.2.ogg - x_enchanting_scroll.2.ogg
@ -144,11 +148,6 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
- x_enchanting_scroll.7.ogg - x_enchanting_scroll.7.ogg
- x_enchanting_scroll.8.ogg - x_enchanting_scroll.8.ogg
- x_enchanting_scroll.9.ogg - x_enchanting_scroll.9.ogg
- x_enchanting_scroll.10.ogg
- x_enchanting_scroll.11.ogg
- x_enchanting_scroll.12.ogg
- x_enchanting_scroll.13.ogg
- x_enchanting_scroll.14.ogg
## Installation ## Installation

31
api.lua
View File

@ -115,6 +115,16 @@ XEnchanting = {
[5] = 45, [5] = 45,
}, },
weight = 10 weight = 10
},
silk_touch = {
name = S('Silk Touch'),
final_level_range = {
[1] = { 15, 65 }
},
level_def = {
[1] = 'silk_touch'
},
weight = 1
} }
}, },
randomseed = os.time(), randomseed = os.time(),
@ -323,6 +333,15 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
.. self.roman_numbers[enchantment.level] .. self.roman_numbers[enchantment.level]
end end
end end
-- Silk Touch
if enchantment.id == 'silk_touch' then
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
if #enchantments_desc_masked == 0 then
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
end
end
end end
enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted')) enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted'))
@ -350,6 +369,14 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
end end
local stack_meta = itemstack:get_meta() local stack_meta = itemstack:get_meta()
local is_silk_touch = 0
for i, val in ipairs(final_enchantments) do
if val.id == 'silk_touch' then
is_silk_touch = 1
break
end
end
stack_meta:set_tool_capabilities(capabilities) stack_meta:set_tool_capabilities(capabilities)
stack_meta:set_string('description', itemstack:get_description() .. '\n' .. description) stack_meta:set_string('description', itemstack:get_description() .. '\n' .. description)
@ -357,6 +384,10 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
stack_meta:set_int('is_enchanted', 1) stack_meta:set_int('is_enchanted', 1)
stack_meta:set_string('x_enchanting', minetest.serialize({ enchantments = final_enchantments })) stack_meta:set_string('x_enchanting', minetest.serialize({ enchantments = final_enchantments }))
if is_silk_touch > 0 then
stack_meta:set_int('is_silk_touch', 1)
end
inv:set_stack('item', 1, itemstack) inv:set_stack('item', 1, itemstack)
local trade_stack = inv:get_stack('trade', 1) local trade_stack = inv:get_stack('trade', 1)

View File

@ -23,6 +23,47 @@ minetest.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)
-- Silk Touch
local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger)
if not digger
or not digger:is_player()
then
return old_handle_node_drops(pos, drops, digger)
end
local wield_stack = digger:get_wielded_item()
local wield_stack_meta = wield_stack:get_meta()
if wield_stack_meta:get_int('is_silk_touch') == 0 then
return old_handle_node_drops(pos, drops, digger)
end
local wield_stack_name = wield_stack:get_name()
local node = minetest.get_node(pos)
local silk_touch_group
if minetest.get_item_group(wield_stack_name, 'pickaxe') > 0 then
silk_touch_group = 'cracky'
elseif minetest.get_item_group(wield_stack_name, 'shovel') > 0 then
silk_touch_group = 'crumbly'
elseif minetest.get_item_group(wield_stack_name, 'axe') > 0 then
silk_touch_group = 'choppy'
elseif minetest.get_item_group(wield_stack_name, 'sword') > 0 then
silk_touch_group = 'snappy'
end
if not silk_touch_group
or minetest.get_item_group(node.name, silk_touch_group) == 0
or minetest.get_item_group(node.name, 'no_silktouch') == 1
then
return old_handle_node_drops(pos, drops, digger)
end
-- drop raw item/node
return old_handle_node_drops(pos, { ItemStack(node.name) }, digger)
end
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000 local mod_end_time = (minetest.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]')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -88,6 +88,7 @@
---@field add_particle fun(def: ParticleDef): nil ---@field add_particle fun(def: ParticleDef): nil
---@field registered_tools table<string, ItemDef> Map of registered tool definitions, indexed by name ---@field registered_tools table<string, ItemDef> Map of registered tool definitions, indexed by name
---@field has_feature fun(args: table<string, boolean> | string): boolean | table returns `boolean, missing_features`, `arg`: string or table in format `{foo=true, bar=true}`, `missing_features`: `{foo=true, bar=true}` ---@field has_feature fun(args: table<string, boolean> | string): boolean | table returns `boolean, missing_features`, `arg`: string or table in format `{foo=true, bar=true}`, `missing_features`: `{foo=true, bar=true}`
---@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)
---Minetest settings ---Minetest settings
---@class MinetestSettings ---@class MinetestSettings

View File

@ -4,7 +4,7 @@
---@class XEnchanting ---@class XEnchanting
---@field tools_enchantability table<string, number> Add enchantability to default tools. key/value = tool_name/enchantibility value ---@field tools_enchantability table<string, number> Add enchantability to default tools. key/value = tool_name/enchantibility value
---@field roman_numbers table<number, string> Convert Arabic numbers to Roman numbers ---@field roman_numbers table<number, string> Convert Arabic numbers to Roman numbers
---@field enchantment_defs table<'sharpness' | 'fortune' | 'unbreaking' | 'efficiency', EnchantmentDef> ---@field enchantment_defs table<'sharpness' | 'fortune' | 'unbreaking' | 'efficiency' | 'silk_touch', 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 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_tool_enchantability fun(self: XEnchanting, tool_def: ItemDef): nil Sets `enchantibility` group and values from base table (`XEnchanting.tools_enchantability`) to all registered tools (atching known group names). If tool has already `enchantibility` group defined it will take the defined value insted.
---@field get_enchanted_tool_capabilities fun(self: XEnchanting, tool_def: ItemDef, enchantments: Enchantments[]): GetEnchantedToolCapabilitiesReturn Applies enchantments to item tool capabilities. ---@field get_enchanted_tool_capabilities fun(self: XEnchanting, tool_def: ItemDef, enchantments: Enchantments[]): GetEnchantedToolCapabilitiesReturn Applies enchantments to item tool capabilities.