1
0
mirror of https://bitbucket.org/minetest_gamers/x_enchanting.git synced 2025-04-21 17:50:21 +02:00

Add Curse of Vanishing enchantment

This commit is contained in:
Juraj Vajda 2022-11-10 21:42:28 -05:00
parent dd04f68777
commit 1266b0db80
6 changed files with 59 additions and 9 deletions

View File

@ -66,6 +66,10 @@ Increases the player's mining speed. Also adds mining groupcaps to item, e.g. en
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.
#### Curse of Vanishing
Causes the item to disappear on death.
## Dependencies
- none

29
api.lua
View File

@ -125,6 +125,16 @@ XEnchanting = {
[1] = 'silk_touch'
},
weight = 1
},
curse_of_vanishing = {
name = S('Curse of Vanishing'),
final_level_range = {
[1] = { 25, 50 }
},
level_def = {
[1] = 'curse_of_vanishing'
},
weight = 1
}
},
randomseed = os.time(),
@ -342,6 +352,15 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
end
end
-- Curse of Vanishing
if enchantment.id == 'curse_of_vanishing' 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
enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted'))
@ -369,13 +388,9 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
end
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
stack_meta:set_int('is_' .. val.id, 1)
end
stack_meta:set_tool_capabilities(capabilities)
@ -384,10 +399,6 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
stack_meta:set_int('is_enchanted', 1)
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)
local trade_stack = inv:get_stack('trade', 1)

View File

@ -64,6 +64,35 @@ function minetest.handle_node_drops(pos, drops, digger)
return old_handle_node_drops(pos, { ItemStack(node.name) }, digger)
end
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if (player:get_hp() + hp_change) <= 0 then
-- Going to die
local player_inv = player:get_inventory() --[[@as InvRef]]
-- Curse of Vanishing
local player_inventory_lists = { 'main', 'craft' }
for _, list_name in ipairs(player_inventory_lists) do
if not player_inv:is_empty(list_name) then
for i = 1, player_inv:get_size(list_name) do
local stack = player_inv:get_stack(list_name, i)
local stack_meta = stack:get_meta()
local is_curse_of_vanishing = stack_meta:get_int('is_curse_of_vanishing')
if is_curse_of_vanishing > 0 then
player_inv:set_stack(list_name, i, ItemStack(''))
end
end
player_inv:set_list(list_name, {})
end
end
end
return hp_change
end, true)
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
print('[Mod] x_enchanting loaded.. [' .. mod_end_time .. 's]')

View File

@ -3,6 +3,8 @@ Sharpness=
Fortune=
Unbreaking=
Efficiency=
Silk Touch=
Curse of Vanishing=
Enchanted=
Enchant=
level=

View File

@ -3,6 +3,8 @@ Sharpness=Ostrosť
Fortune=Šťastie
Unbreaking=Nelámavosť
Efficiency=Výkonnosť
Silk Touch=Hodvábny dotyk
Curse of Vanishing=Kliatba zmiznutia
Enchanted=Očarený
Enchant=Očarovať
level=level

View File

@ -89,6 +89,8 @@
---@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 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.
---Minetest settings
---@class MinetestSettings