Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
48d215b08e | |||
f8f40d61a2 | |||
20b53db32d | |||
f891170e45 | |||
1771a773e5 | |||
92cd1dea01 | |||
4303c5f8bf | |||
1e5a76ed18 | |||
96b8369500 | |||
03ad38cfb3 | |||
cad216468a | |||
ab3cb43705 | |||
11fc35b049 | |||
27c35f551d | |||
b9e5fcb3fe | |||
b8a478c05b | |||
399f533731 | |||
210a213ad7 | |||
4ee4e17925 | |||
4b4d38801c | |||
1266b0db80 | |||
dd04f68777 |
15
.gitattributes
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Creating an archive
|
||||||
|
|
||||||
|
.* export-ignore
|
||||||
|
assets export-ignore
|
||||||
|
scripts export-ignore
|
||||||
|
bin export-ignore
|
||||||
|
docs export-ignore
|
||||||
|
types export-ignore
|
||||||
|
*.zip export-ignore
|
||||||
|
bitbucket-pipelines.yml export-ignore
|
||||||
|
package.json export-ignore
|
||||||
|
package-lock.json export-ignore
|
||||||
|
screenshot*.png export-ignore
|
||||||
|
i18n.py export-ignore
|
||||||
|
config.ld export-ignore
|
65
LICENSE.txt
@ -1,8 +1,7 @@
|
|||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
Version 2.1, February 1999
|
Version 2.1, February 1999
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ modified by someone else and passed on, the recipients should know
|
|||||||
that what they have is not the original version, so that the original
|
that what they have is not the original version, so that the original
|
||||||
author's reputation will not be affected by problems that might be
|
author's reputation will not be affected by problems that might be
|
||||||
introduced by others.
|
introduced by others.
|
||||||
|
|
||||||
Finally, software patents pose a constant threat to the existence of
|
Finally, software patents pose a constant threat to the existence of
|
||||||
any free program. We wish to make sure that a company cannot
|
any free program. We wish to make sure that a company cannot
|
||||||
effectively restrict the users of a free program by obtaining a
|
effectively restrict the users of a free program by obtaining a
|
||||||
@ -111,7 +110,7 @@ modification follow. Pay close attention to the difference between a
|
|||||||
"work based on the library" and a "work that uses the library". The
|
"work based on the library" and a "work that uses the library". The
|
||||||
former contains code derived from the library, whereas the latter must
|
former contains code derived from the library, whereas the latter must
|
||||||
be combined with the library in order to run.
|
be combined with the library in order to run.
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
@ -158,7 +157,7 @@ Library.
|
|||||||
You may charge a fee for the physical act of transferring a copy,
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
and you may at your option offer warranty protection in exchange for a
|
and you may at your option offer warranty protection in exchange for a
|
||||||
fee.
|
fee.
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
of it, thus forming a work based on the Library, and copy and
|
of it, thus forming a work based on the Library, and copy and
|
||||||
distribute such modifications or work under the terms of Section 1
|
distribute such modifications or work under the terms of Section 1
|
||||||
@ -216,7 +215,7 @@ instead of to this License. (If a newer version than version 2 of the
|
|||||||
ordinary GNU General Public License has appeared, then you can specify
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
that version instead if you wish.) Do not make any other change in
|
that version instead if you wish.) Do not make any other change in
|
||||||
these notices.
|
these notices.
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
Once this change is made in a given copy, it is irreversible for
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
subsequent copies and derivative works made from that copy.
|
subsequent copies and derivative works made from that copy.
|
||||||
@ -267,7 +266,7 @@ Library will still fall under Section 6.)
|
|||||||
distribute the object code for the work under the terms of Section 6.
|
distribute the object code for the work under the terms of Section 6.
|
||||||
Any executables containing that work also fall under Section 6,
|
Any executables containing that work also fall under Section 6,
|
||||||
whether or not they are linked directly with the Library itself.
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also combine or
|
6. As an exception to the Sections above, you may also combine or
|
||||||
link a "work that uses the Library" with the Library to produce a
|
link a "work that uses the Library" with the Library to produce a
|
||||||
work containing portions of the Library, and distribute that work
|
work containing portions of the Library, and distribute that work
|
||||||
@ -329,7 +328,7 @@ restrictions of other proprietary libraries that do not normally
|
|||||||
accompany the operating system. Such a contradiction means you cannot
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
use both them and the Library together in an executable that you
|
use both them and the Library together in an executable that you
|
||||||
distribute.
|
distribute.
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
7. You may place library facilities that are a work based on the
|
||||||
Library side-by-side in a single library together with other library
|
Library side-by-side in a single library together with other library
|
||||||
facilities not covered by this License, and distribute such a combined
|
facilities not covered by this License, and distribute such a combined
|
||||||
@ -370,7 +369,7 @@ subject to these terms and conditions. You may not impose any further
|
|||||||
restrictions on the recipients' exercise of the rights granted herein.
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
You are not responsible for enforcing compliance by third parties with
|
You are not responsible for enforcing compliance by third parties with
|
||||||
this License.
|
this License.
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
infringement or for any other reason (not limited to patent issues),
|
infringement or for any other reason (not limited to patent issues),
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
@ -422,7 +421,7 @@ conditions either of that version or of any later version published by
|
|||||||
the Free Software Foundation. If the Library does not specify a
|
the Free Software Foundation. If the Library does not specify a
|
||||||
license version number, you may choose any version ever published by
|
license version number, you may choose any version ever published by
|
||||||
the Free Software Foundation.
|
the Free Software Foundation.
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
programs whose distribution conditions are incompatible with these,
|
programs whose distribution conditions are incompatible with these,
|
||||||
write to the author to ask for permission. For software which is
|
write to the author to ask for permission. For software which is
|
||||||
@ -454,49 +453,3 @@ RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
|||||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
DAMAGES.
|
DAMAGES.
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Libraries
|
|
||||||
|
|
||||||
If you develop a new library, and you want it to be of the greatest
|
|
||||||
possible use to the public, we recommend making it free software that
|
|
||||||
everyone can redistribute and change. You can do so by permitting
|
|
||||||
redistribution under these terms (or, alternatively, under the terms of the
|
|
||||||
ordinary General Public License).
|
|
||||||
|
|
||||||
To apply these terms, attach the following notices to the library. It is
|
|
||||||
safest to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least the
|
|
||||||
"copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the library's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
|
||||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1990
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
That's all there is to it!
|
|
123
README.md
@ -6,8 +6,10 @@ Adds Enchanting Mechanics and API.
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
* does not add new tools/items, it's using MT API to change existing items instead
|
||||||
* adds enchanting table
|
* adds enchanting table
|
||||||
* supports all registered tools with known tool groups: pickaxe, shovel, axe, sword, e.g. `groups = {pickaxe = 1}`
|
* supports all registered tools with known tool groups: pickaxe, shovel, axe, sword, e.g. `groups = {pickaxe = 1}`
|
||||||
|
* supports all bows with group `{bow = 1}`
|
||||||
* supports `default:bookshelf` or anything with `group:bookshelf`
|
* supports `default:bookshelf` or anything with `group:bookshelf`
|
||||||
* enchanting trade is for `default:mese_crystal` or anything with `groups = {enchanting_trade = 1}`
|
* enchanting trade is for `default:mese_crystal` or anything with `groups = {enchanting_trade = 1}`
|
||||||
* adds enchantability for all MT default tools, for custom tools the enchantability can be set in the item group, e.g. `groups = {enchantability = 15}`
|
* adds enchantability for all MT default tools, for custom tools the enchantability can be set in the item group, e.g. `groups = {enchantability = 15}`
|
||||||
@ -50,22 +52,125 @@ Items enchantibility from worst to best:
|
|||||||
|
|
||||||
Increases melee damage.
|
Increases melee damage.
|
||||||
|
|
||||||
|
groups: sword
|
||||||
|
|
||||||
#### Fortune
|
#### Fortune
|
||||||
|
|
||||||
Increases the number and/or chances of specific item drops. This value is not used in the engine; it is the responsibility of the game/mod code to implement this.
|
Increases the number and/or chances of specific item drops. Works with groups: stone, soil, sand, snowy, slippery, tree, leaves and all registered ores.
|
||||||
|
|
||||||
|
Incompatible: Silk Touch
|
||||||
|
|
||||||
|
groups: pickaxe, shovel, axe
|
||||||
|
|
||||||
#### Unbreaking
|
#### Unbreaking
|
||||||
|
|
||||||
Increases the item's durability.
|
Increases the item's durability.
|
||||||
|
|
||||||
|
groups: any
|
||||||
|
|
||||||
#### Efficiency
|
#### Efficiency
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
groups: pickaxe, shovel, axe
|
||||||
|
|
||||||
#### Silk Touch
|
#### 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.
|
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.
|
||||||
|
|
||||||
|
Incompatible: Fortune
|
||||||
|
|
||||||
|
groups: pickaxe, shovel, axe
|
||||||
|
|
||||||
|
#### Curse of Vanishing
|
||||||
|
|
||||||
|
Causes the item to disappear on death.
|
||||||
|
|
||||||
|
groups: any
|
||||||
|
|
||||||
|
#### Knockback
|
||||||
|
|
||||||
|
Increases knockback (players only).
|
||||||
|
|
||||||
|
groups: sword
|
||||||
|
|
||||||
|
#### Looting
|
||||||
|
|
||||||
|
Cause mobs to drop more items. This value is not used in the engine; it is the responsibility of the game/mod code to implement this.
|
||||||
|
|
||||||
|
Supported: mobs_monster, mobs_animal, animalia
|
||||||
|
|
||||||
|
groups: sword
|
||||||
|
|
||||||
|
#### Power
|
||||||
|
|
||||||
|
Increases arrow damage.
|
||||||
|
Damage has to be calculated in the MOD where the bow comes from!
|
||||||
|
|
||||||
|
groups: bow
|
||||||
|
|
||||||
|
#### Punch
|
||||||
|
|
||||||
|
Increases arrow knockback.
|
||||||
|
Knockback has to be calculated in the MOD where the bow comes from!
|
||||||
|
|
||||||
|
This can be obtained from tool meta:
|
||||||
|
|
||||||
|
groups: bow
|
||||||
|
|
||||||
|
#### Infinity
|
||||||
|
|
||||||
|
Prevents regular arrows from being consumed when shot.
|
||||||
|
One arrow is needed INSIDE QUIVER to use a bow enchanted with Infinity.
|
||||||
|
Fired arrows cannot be retrieved even if they are not fired from Quiver.
|
||||||
|
Only set in item meta, logic for this has to be in the MOD where the bow comes from!
|
||||||
|
|
||||||
|
groups: bow
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
`ItemStackMetaRef`
|
||||||
|
|
||||||
|
* `get_float(key)`: Returns `0` if key not present. `key` can be enchantment id prefixed with `is_`,
|
||||||
|
e.g. enchantment `punch` would have stored meta as `is_punch`. If returned value is bigger than zero
|
||||||
|
then the value represents enchantment level bonus. See below fields for bow:
|
||||||
|
* `power` Increase percentage
|
||||||
|
* `punch` Multiplier
|
||||||
|
* `infinity` If `1` then it is infinity enchanted
|
||||||
|
* `get_string(key)`: Returns `""` if key not present. See below fields for all enchantments:
|
||||||
|
* `x_enchanting` Serialized table with key/value pairs where: `key` is enchantment `id` and `value` is `Enchantment` definition
|
||||||
|
|
||||||
|
`Enchantment` definition
|
||||||
|
|
||||||
|
* `value` number, Value of the enchantment based on level, e.g. multiplier, percentage/number increase...
|
||||||
|
|
||||||
|
example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
-- For simplicity assuming that all meta are present (biggger than zero or not "")
|
||||||
|
-- MODs have to add those checks individually
|
||||||
|
|
||||||
|
local itemstack_meta = itemstack:get_meta()
|
||||||
|
|
||||||
|
local power_value = itemstack_meta:get_float('is_power')
|
||||||
|
local punch_value = itemstack_meta:get_float('is_punch')
|
||||||
|
local infinity_value = itemstack_meta:get_float('is_infinity')
|
||||||
|
|
||||||
|
-- Or for list of all enchantments
|
||||||
|
local x_enchanting = minetest.deserialize(itemstack_meta:get_string('x_enchanting')) or {}
|
||||||
|
local power_enchantment = enchantments.power
|
||||||
|
local punch_enchantment = enchantments.punch
|
||||||
|
local infinity_enchantment = enchantments.infinity
|
||||||
|
|
||||||
|
-- Custom logic
|
||||||
|
local new_damage = damage + damage * (punch_enchantment.value / 100)
|
||||||
|
local new_knockback = knockback * punch_enchantment.value
|
||||||
|
|
||||||
|
if enchantments.infinity.value > 0 then
|
||||||
|
-- Some logic for infinity
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- none
|
- none
|
||||||
@ -82,7 +187,7 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
|
|||||||
|
|
||||||
### Textures
|
### Textures
|
||||||
|
|
||||||
**CC BY-SA 4.0, Pixel Perfection by XSSheep**, https://minecraft.curseforge.com/projects/pixel-perfection-freshly-updated
|
**CC-BY-SA-4.0, Pixel Perfection by XSSheep**, https://minecraft.curseforge.com/projects/pixel-perfection-freshly-updated
|
||||||
|
|
||||||
- x_enchanting_symbol_1.png
|
- x_enchanting_symbol_1.png
|
||||||
- x_enchanting_symbol_2.png
|
- x_enchanting_symbol_2.png
|
||||||
@ -111,7 +216,7 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
|
|||||||
- x_enchanting_symbol_25.png
|
- x_enchanting_symbol_25.png
|
||||||
- x_enchanting_symbol_26.png
|
- x_enchanting_symbol_26.png
|
||||||
|
|
||||||
**LGPL-2.1-or-later, by SaKeL**
|
**CC-BY-SA-4.0, by SaKeL**
|
||||||
|
|
||||||
- x_enchanting_image_button_disabled.png
|
- x_enchanting_image_button_disabled.png
|
||||||
- x_enchanting_image_button.png
|
- x_enchanting_image_button.png
|
||||||
@ -122,22 +227,26 @@ GNU Lesser General Public License v2.1 or later (see included LICENSE file)
|
|||||||
- x_enchanting_scroll_mesh.png -- Derived from a texture TumeniNodes (CC BY-SA 3.0)
|
- x_enchanting_scroll_mesh.png -- Derived from a texture TumeniNodes (CC BY-SA 3.0)
|
||||||
- x_enchanting_scroll_particle.png
|
- x_enchanting_scroll_particle.png
|
||||||
- x_enchanting_table.png
|
- x_enchanting_table.png
|
||||||
- x_enchanting_trade_slot.png
|
- x_enchanting_gui_slot_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC-BY-SA-4.0)
|
||||||
|
- x_enchanting_gui_cloth_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC-BY-SA-4.0)
|
||||||
|
- x_enchanting_gui_cloth_trade_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC-BY-SA-4.0)
|
||||||
|
- x_enchanting_gui_formbg.png -- Derived from texture Pixel Perfection by XSSheep (CC-BY-SA-4.0)
|
||||||
|
- x_enchanting_gui_hb_bg.png -- Derived from texture Pixel Perfection by XSSheep (CC-BY-SA-4.0)
|
||||||
|
|
||||||
### Models
|
### Models
|
||||||
|
|
||||||
**LGPL-2.1-or-later, by SaKeL**
|
**CC-BY-SA-4.0, by SaKeL**
|
||||||
|
|
||||||
- x_enchanting_scroll.b3d
|
- x_enchanting_scroll.b3d
|
||||||
- x_enchanting_table.obj
|
- x_enchanting_table.obj
|
||||||
|
|
||||||
### Sounds
|
### Sounds
|
||||||
|
|
||||||
**Creative Commons License, Kostas17**, https://freesound.org
|
**CC-BY-3.0, Kostas17**, https://freesound.org
|
||||||
|
|
||||||
- x_enchanting_enchant.ogg
|
- x_enchanting_enchant.ogg
|
||||||
|
|
||||||
**Creative Commons License, jammaj**, https://freesound.org
|
**CC0-1.0, Zeinel**, https://freesound.org
|
||||||
|
|
||||||
- x_enchanting_scroll.1.ogg
|
- x_enchanting_scroll.1.ogg
|
||||||
- x_enchanting_scroll.2.ogg
|
- x_enchanting_scroll.2.ogg
|
||||||
|
534
api.lua
@ -1,4 +1,20 @@
|
|||||||
default = minetest.global_exists('default') and default --[[@as MtgDefault]]
|
--[[
|
||||||
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
|
Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
|
--]]
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
@ -62,7 +78,29 @@ XEnchanting = {
|
|||||||
[4] = 5,
|
[4] = 5,
|
||||||
[5] = 6.25,
|
[5] = 6.25,
|
||||||
},
|
},
|
||||||
weight = 10
|
weight = 10,
|
||||||
|
groups = {
|
||||||
|
'sword'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
looting = {
|
||||||
|
name = S('Looting'),
|
||||||
|
-- what level should be taken, `level = min/max values`
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 15, 65 },
|
||||||
|
[2] = { 24, 74 },
|
||||||
|
[3] = { 33, 83 }
|
||||||
|
},
|
||||||
|
-- level definition, `level = number to add`
|
||||||
|
level_def = {
|
||||||
|
[1] = 1,
|
||||||
|
[2] = 2,
|
||||||
|
[3] = 3
|
||||||
|
},
|
||||||
|
weight = 2,
|
||||||
|
groups = {
|
||||||
|
'sword'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fortune = {
|
fortune = {
|
||||||
name = S('Fortune'),
|
name = S('Fortune'),
|
||||||
@ -78,7 +116,13 @@ XEnchanting = {
|
|||||||
[2] = 2,
|
[2] = 2,
|
||||||
[3] = 3
|
[3] = 3
|
||||||
},
|
},
|
||||||
weight = 2
|
weight = 2,
|
||||||
|
groups = {
|
||||||
|
'pickaxe',
|
||||||
|
'shovel',
|
||||||
|
'axe'
|
||||||
|
},
|
||||||
|
incompatible = { 'silk_touch' }
|
||||||
},
|
},
|
||||||
unbreaking = {
|
unbreaking = {
|
||||||
name = S('Unbreaking'),
|
name = S('Unbreaking'),
|
||||||
@ -94,7 +138,9 @@ XEnchanting = {
|
|||||||
[2] = 200,
|
[2] = 200,
|
||||||
[3] = 300
|
[3] = 300
|
||||||
},
|
},
|
||||||
weight = 5
|
weight = 5,
|
||||||
|
-- all applicable
|
||||||
|
groups = nil
|
||||||
},
|
},
|
||||||
efficiency = {
|
efficiency = {
|
||||||
name = S('Efficiency'),
|
name = S('Efficiency'),
|
||||||
@ -114,7 +160,12 @@ XEnchanting = {
|
|||||||
[4] = 40,
|
[4] = 40,
|
||||||
[5] = 45,
|
[5] = 45,
|
||||||
},
|
},
|
||||||
weight = 10
|
weight = 10,
|
||||||
|
groups = {
|
||||||
|
'pickaxe',
|
||||||
|
'shovel',
|
||||||
|
'axe'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
silk_touch = {
|
silk_touch = {
|
||||||
name = S('Silk Touch'),
|
name = S('Silk Touch'),
|
||||||
@ -122,19 +173,116 @@ XEnchanting = {
|
|||||||
[1] = { 15, 65 }
|
[1] = { 15, 65 }
|
||||||
},
|
},
|
||||||
level_def = {
|
level_def = {
|
||||||
[1] = 'silk_touch'
|
[1] = 1
|
||||||
},
|
},
|
||||||
weight = 1
|
weight = 1,
|
||||||
|
secondary = true,
|
||||||
|
groups = {
|
||||||
|
'pickaxe',
|
||||||
|
'shovel',
|
||||||
|
'axe'
|
||||||
|
},
|
||||||
|
incompatible = { 'fortune' }
|
||||||
|
},
|
||||||
|
curse_of_vanishing = {
|
||||||
|
name = S('Curse of Vanishing'),
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 25, 50 }
|
||||||
|
},
|
||||||
|
level_def = {
|
||||||
|
[1] = 1
|
||||||
|
},
|
||||||
|
weight = 1,
|
||||||
|
secondary = true,
|
||||||
|
-- all applicable
|
||||||
|
groups = nil
|
||||||
|
},
|
||||||
|
knockback = {
|
||||||
|
name = S('Knockback'),
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 5, 55 },
|
||||||
|
[2] = { 25, 75 }
|
||||||
|
},
|
||||||
|
-- increase %
|
||||||
|
level_def = {
|
||||||
|
[1] = 105,
|
||||||
|
[2] = 190
|
||||||
|
},
|
||||||
|
weight = 5,
|
||||||
|
groups = {
|
||||||
|
'sword'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
randomseed = os.time(),
|
power = {
|
||||||
|
-- Increases arrow damage.
|
||||||
|
-- Damage has to be calculated in the MOD where the bow comes from!
|
||||||
|
name = S('Power'),
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 1, 16 },
|
||||||
|
[2] = { 11, 26 },
|
||||||
|
[3] = { 21, 36 },
|
||||||
|
[4] = { 31, 46 },
|
||||||
|
[5] = { 41, 56 }
|
||||||
|
},
|
||||||
|
-- increase %
|
||||||
|
level_def = {
|
||||||
|
[1] = 50,
|
||||||
|
[2] = 75,
|
||||||
|
[3] = 100,
|
||||||
|
[4] = 125,
|
||||||
|
[5] = 150
|
||||||
|
},
|
||||||
|
weight = 10,
|
||||||
|
groups = {
|
||||||
|
'bow'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
punch = {
|
||||||
|
-- Increases arrow knockback.
|
||||||
|
-- Knockback has to be calculated in the MOD where the bow comes from!
|
||||||
|
name = S('Punch'),
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 12, 37 },
|
||||||
|
[2] = { 32, 57 }
|
||||||
|
},
|
||||||
|
-- multiplier
|
||||||
|
level_def = {
|
||||||
|
[1] = 3,
|
||||||
|
[2] = 6
|
||||||
|
},
|
||||||
|
weight = 2,
|
||||||
|
groups = {
|
||||||
|
'bow'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
infinity = {
|
||||||
|
-- Prevents regular arrows from being consumed when shot.
|
||||||
|
-- One arrow is needed to use a bow enchanted with Infinity.
|
||||||
|
-- Only set in item meta, logic for this has to be in the MOD where the bow comes from!
|
||||||
|
name = S('Infinity'),
|
||||||
|
final_level_range = {
|
||||||
|
[1] = { 20, 50 }
|
||||||
|
},
|
||||||
|
-- will be set in meta as float
|
||||||
|
level_def = {
|
||||||
|
[1] = 1
|
||||||
|
},
|
||||||
|
weight = 1,
|
||||||
|
secondary = true,
|
||||||
|
groups = {
|
||||||
|
'bow'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
form_context = {},
|
form_context = {},
|
||||||
|
player_seeds = {},
|
||||||
scroll_animations = {
|
scroll_animations = {
|
||||||
scroll_open = { { x = 1, y = 40 }, 80, 0, false },
|
scroll_open = { { x = 1, y = 40 }, 80, 0, false },
|
||||||
scroll_close = { { x = 45, y = 84 }, 80, 0, false },
|
scroll_close = { { x = 45, y = 84 }, 80, 0, false },
|
||||||
scroll_open_idle = { { x = 41, y = 42 }, 0, 0, false },
|
scroll_open_idle = { { x = 41, y = 42 }, 0, 0, false },
|
||||||
scroll_closed_idle = { { x = 43, y = 44 }, 0, 0, false }
|
scroll_closed_idle = { { x = 43, y = 44 }, 0, 0, false }
|
||||||
}
|
},
|
||||||
|
registered_ores = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
---Merge two tables with key/value pair
|
---Merge two tables with key/value pair
|
||||||
@ -146,6 +294,19 @@ local function mergeTables(t1, t2)
|
|||||||
return t1
|
return t1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Gets length of hashed table
|
||||||
|
---@param table any
|
||||||
|
---@return integer
|
||||||
|
local function get_table_length(table)
|
||||||
|
local length = 0
|
||||||
|
for _ in pairs(table) do
|
||||||
|
length = length + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
return length
|
||||||
|
end
|
||||||
|
|
||||||
|
---@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 minetest.get_item_group(name, 'pickaxe') > 0 then
|
||||||
return 'pickaxe'
|
return 'pickaxe'
|
||||||
@ -155,17 +316,22 @@ function XEnchanting.has_tool_group(self, name)
|
|||||||
return 'axe'
|
return 'axe'
|
||||||
elseif minetest.get_item_group(name, 'sword') > 0 then
|
elseif minetest.get_item_group(name, 'sword') > 0 then
|
||||||
return 'sword'
|
return 'sword'
|
||||||
|
elseif minetest.get_item_group(name, 'bow') > 0 then
|
||||||
|
return 'bow'
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
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
|
||||||
|
-- enchantability is already set, we dont need to override the item
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local _enchantability = 1
|
local _enchantability = 1
|
||||||
|
|
||||||
if minetest.get_item_group(tool_def.name, 'enchantability') > 0 then
|
if self.tools_enchantability[tool_def.name] then
|
||||||
_enchantability = minetest.get_item_group(tool_def.name, 'enchantability')
|
|
||||||
elseif self.tools_enchantability[tool_def.name] then
|
|
||||||
_enchantability = self.tools_enchantability[tool_def.name]
|
_enchantability = self.tools_enchantability[tool_def.name]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -174,12 +340,12 @@ function XEnchanting.set_tool_enchantability(self, tool_def)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantments)
|
function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantments)
|
||||||
local tool_stack = ItemStack({ name = tool_def.name })
|
local tool_stack = ItemStack({ name = tool_def.name })
|
||||||
local tool_capabilities = tool_stack:get_tool_capabilities()
|
local tool_capabilities = tool_stack:get_tool_capabilities()
|
||||||
local enchantments_desc = {}
|
|
||||||
local enchantments_desc_masked = {}
|
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
for i, enchantment in ipairs(enchantments) do
|
for i, enchantment in ipairs(enchantments) do
|
||||||
-- Efficiency
|
-- Efficiency
|
||||||
if enchantment.id == 'efficiency' then
|
if enchantment.id == 'efficiency' then
|
||||||
@ -246,18 +412,6 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
|
|||||||
|
|
||||||
tool_capabilities.full_punch_interval = new_fpi
|
tool_capabilities.full_punch_interval = new_fpi
|
||||||
end
|
end
|
||||||
|
|
||||||
if tool_capabilities.groupcaps or tool_capabilities.full_punch_interval then
|
|
||||||
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
|
|
||||||
if #enchantments_desc_masked == 0 then
|
|
||||||
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Unbreaking
|
-- Unbreaking
|
||||||
@ -282,18 +436,6 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
|
|||||||
|
|
||||||
tool_capabilities.punch_attack_uses = new_uses
|
tool_capabilities.punch_attack_uses = new_uses
|
||||||
end
|
end
|
||||||
|
|
||||||
if tool_capabilities.groupcaps or tool_capabilities.punch_attack_uses then
|
|
||||||
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
|
|
||||||
if #enchantments_desc_masked == 0 then
|
|
||||||
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Sharpness
|
-- Sharpness
|
||||||
@ -304,52 +446,59 @@ function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantment
|
|||||||
|
|
||||||
tool_capabilities.damage_groups[group_name] = new_damage
|
tool_capabilities.damage_groups[group_name] = new_damage
|
||||||
end
|
end
|
||||||
|
|
||||||
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
|
|
||||||
if #enchantments_desc_masked == 0 then
|
|
||||||
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fortune
|
-- Fortune
|
||||||
if enchantment.id == 'fortune' and tool_capabilities.max_drop_level then
|
if enchantment.id == 'fortune' or enchantment.id == 'looting' and tool_capabilities.max_drop_level then
|
||||||
local old_max_drop_level = tool_capabilities.max_drop_level
|
local old_max_drop_level = tool_capabilities.max_drop_level
|
||||||
local new_max_drop_level = old_max_drop_level + enchantment.value
|
local new_max_drop_level = old_max_drop_level + enchantment.value
|
||||||
|
|
||||||
tool_capabilities.max_drop_level = new_max_drop_level
|
tool_capabilities.max_drop_level = new_max_drop_level
|
||||||
|
|
||||||
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
|
|
||||||
if #enchantments_desc_masked == 0 then
|
|
||||||
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
.. ' '
|
|
||||||
.. self.roman_numbers[enchantment.level]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Silk Touch
|
return tool_capabilities
|
||||||
if enchantment.id == 'silk_touch' then
|
end
|
||||||
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
|
||||||
|
|
||||||
if #enchantments_desc_masked == 0 then
|
---@diagnostic disable-next-line: unused-local
|
||||||
|
function XEnchanting.get_randomseed(self)
|
||||||
|
return tonumber(tostring(os.time()):reverse():sub(1, 9)) --[[@as integer]]
|
||||||
|
end
|
||||||
|
|
||||||
|
function XEnchanting.get_enchanted_descriptions(self, enchantments)
|
||||||
|
local enchantments_desc = {}
|
||||||
|
local enchantments_desc_masked = {}
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
|
for i, enchantment in ipairs(enchantments) do
|
||||||
|
local add_roman_numbers = true
|
||||||
|
|
||||||
|
if get_table_length(self.enchantment_defs[enchantment.id].final_level_range) == 1 then
|
||||||
|
add_roman_numbers = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if add_roman_numbers then
|
||||||
|
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
||||||
|
.. ' '
|
||||||
|
.. self.roman_numbers[enchantment.level]
|
||||||
|
else
|
||||||
|
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
|
||||||
|
end
|
||||||
|
|
||||||
|
if #enchantments_desc_masked == 0 and not enchantment.secondary then
|
||||||
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
enchantments_desc_masked[#enchantments_desc_masked + 1] = self.enchantment_defs[enchantment.id].name
|
||||||
|
|
||||||
|
if add_roman_numbers then
|
||||||
|
enchantments_desc_masked[#enchantments_desc_masked + 1] = ' ' .. self.roman_numbers[enchantment.level]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
enchantments_desc = '\n' .. minetest.colorize('#AE81FF', S('Enchanted'))
|
enchantments_desc = '\n' .. minetest.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, '') .. '..?'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tool_capabilities = tool_capabilities,
|
|
||||||
enchantments_desc = enchantments_desc,
|
enchantments_desc = enchantments_desc,
|
||||||
enchantments_desc_masked = enchantments_desc_masked
|
enchantments_desc_masked = enchantments_desc_masked
|
||||||
}
|
}
|
||||||
@ -357,8 +506,13 @@ 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
|
||||||
local capabilities = data.slots[level].tool_cap_data.tool_capabilities
|
|
||||||
local description = data.slots[level].tool_cap_data.enchantments_desc
|
if not data then
|
||||||
|
return
|
||||||
|
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 final_enchantments = data.slots[level].final_enchantments
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
local tool_def = minetest.registered_tools[itemstack:get_name()]
|
local tool_def = minetest.registered_tools[itemstack:get_name()]
|
||||||
@ -369,24 +523,23 @@ 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
|
---@type table<string, {["value"]: number}>
|
||||||
|
local final_enchantments_meta = {}
|
||||||
|
|
||||||
for i, val in ipairs(final_enchantments) do
|
---@diagnostic disable-next-line: unused-local
|
||||||
if val.id == 'silk_touch' then
|
for i, enchantment in ipairs(final_enchantments) do
|
||||||
is_silk_touch = 1
|
stack_meta:set_float('is_' .. enchantment.id, enchantment.value)
|
||||||
break
|
-- store only necessary data, keeping the meta optimized
|
||||||
end
|
final_enchantments_meta[enchantment.id] = {
|
||||||
|
value = enchantment.value
|
||||||
|
}
|
||||||
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)
|
||||||
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({ enchantments = final_enchantments }))
|
stack_meta:set_string('x_enchanting', minetest.serialize(final_enchantments_meta))
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
@ -395,7 +548,7 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
inv:set_stack('trade', 1, trade_stack)
|
inv:set_stack('trade', 1, trade_stack)
|
||||||
|
|
||||||
-- set new seed
|
-- set new seed
|
||||||
self.randomseed = tonumber(tostring(os.time()):reverse():sub(1, 9)) --[[@as number]]
|
self.player_seeds[player_name] = self:get_randomseed()
|
||||||
|
|
||||||
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)
|
||||||
@ -405,9 +558,64 @@ function XEnchanting.set_enchanted_tool(self, pos, itemstack, level, player_name
|
|||||||
pos = pos,
|
pos = pos,
|
||||||
max_hear_distance = 10
|
max_hear_distance = 10
|
||||||
}, true)
|
}, true)
|
||||||
|
|
||||||
|
-- particles
|
||||||
|
local particlespawner_def = {
|
||||||
|
amount = 50,
|
||||||
|
time = 0.5,
|
||||||
|
minpos = { x = pos.x - 1, y = pos.y + 1, z = pos.z - 1 },
|
||||||
|
maxpos = { x = pos.x + 1, y = pos.y + 1.5, z = pos.z + 1 },
|
||||||
|
minvel = { x = -0.1, y = -0.5, z = -0.1 },
|
||||||
|
maxvel = { x = 0.1, y = -1.5, z = 0.1 },
|
||||||
|
minacc = { x = -0.1, y = -0.5, z = -0.1 },
|
||||||
|
maxacc = { x = 0.1, y = -1.5, z = 0.1 },
|
||||||
|
minexptime = 0.5,
|
||||||
|
maxexptime = 1,
|
||||||
|
minsize = 0.5,
|
||||||
|
maxsize = 1,
|
||||||
|
texture = 'x_enchanting_scroll_particle.png^[colorize:#A179E9:256',
|
||||||
|
glow = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if minetest.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
|
||||||
|
-- new syntax, after v5.6.0
|
||||||
|
particlespawner_def = {
|
||||||
|
amount = 50,
|
||||||
|
time = 0.5,
|
||||||
|
size = {
|
||||||
|
min = 0.5,
|
||||||
|
max = 1,
|
||||||
|
},
|
||||||
|
exptime = 2,
|
||||||
|
pos = {
|
||||||
|
min = vector.new({ x = pos.x - 1.5, y = pos.y + 1, z = pos.z - 1.5 }),
|
||||||
|
max = vector.new({ x = pos.x + 1.5, y = pos.y + 1.5, z = pos.z + 1.5 }),
|
||||||
|
},
|
||||||
|
attract = {
|
||||||
|
kind = 'point',
|
||||||
|
strength = 2,
|
||||||
|
origin = vector.new({ x = pos.x, y = pos.y + 0.65, z = pos.z }),
|
||||||
|
die_on_contact = true
|
||||||
|
},
|
||||||
|
texture = {
|
||||||
|
name = 'x_enchanting_scroll_particle.png^[colorize:#A179E9:256',
|
||||||
|
alpha_tween = {
|
||||||
|
0.5, 1,
|
||||||
|
style = 'fwd',
|
||||||
|
reps = 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
glow = 1
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
minetest.add_particlespawner(particlespawner_def)
|
||||||
|
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()
|
||||||
|
math.randomseed(randomseed)
|
||||||
local _nr_of_bookshelfs = nr_of_bookshelfs
|
local _nr_of_bookshelfs = nr_of_bookshelfs
|
||||||
local data = {
|
local data = {
|
||||||
slots = {}
|
slots = {}
|
||||||
@ -417,12 +625,31 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
_nr_of_bookshelfs = 15
|
_nr_of_bookshelfs = 15
|
||||||
end
|
end
|
||||||
|
|
||||||
|
----
|
||||||
|
-- Filter out enchantments compatible for this item group
|
||||||
|
----
|
||||||
|
|
||||||
|
local group_enchantments = {}
|
||||||
|
|
||||||
|
for enchantment_name, enchantment_def in pairs(self.enchantment_defs) do
|
||||||
|
if not enchantment_def.groups then
|
||||||
|
group_enchantments[enchantment_name] = enchantment_def
|
||||||
|
else
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
|
for i, group in ipairs(enchantment_def.groups) do
|
||||||
|
if minetest.get_item_group(tool_def.name, group) > 0 then
|
||||||
|
group_enchantments[enchantment_name] = enchantment_def
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
----
|
----
|
||||||
-- 0 Show slots in formspec
|
-- 0 Show slots in formspec
|
||||||
----
|
----
|
||||||
|
|
||||||
-- Base enchantment
|
-- Base enchantment
|
||||||
math.randomseed(self.randomseed)
|
|
||||||
local base = math.random(1, 8) + math.floor(_nr_of_bookshelfs / 2) + math.random(0, _nr_of_bookshelfs)
|
local base = math.random(1, 8) + math.floor(_nr_of_bookshelfs / 2) + math.random(0, _nr_of_bookshelfs)
|
||||||
local top_slot_base_level = math.floor(math.max(base / 3, 1))
|
local top_slot_base_level = math.floor(math.max(base / 3, 1))
|
||||||
local middle_slot_base_level = math.floor((base * 2) / 3 + 1)
|
local middle_slot_base_level = math.floor((base * 2) / 3 + 1)
|
||||||
@ -437,12 +664,10 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
-- Applying modifiers to the enchantment level
|
-- Applying modifiers to the enchantment level
|
||||||
local enchantability = minetest.get_item_group(tool_def.name, 'enchantability')
|
local enchantability = minetest.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
|
||||||
math.randomseed(self.randomseed)
|
|
||||||
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
|
||||||
local k = chosen_enchantment_level + rand_enchantability
|
local k = chosen_enchantment_level + rand_enchantability
|
||||||
-- A random bonus, between .85 and 1.15
|
-- A random bonus, between .85 and 1.15
|
||||||
math.randomseed(self.randomseed)
|
|
||||||
local rand_bonus_percent = 1 + ((math.random(0, 99) / 100) + (math.random(0, 99) / 100) - 1) * 0.15
|
local rand_bonus_percent = 1 + ((math.random(0, 99) / 100) + (math.random(0, 99) / 100) - 1) * 0.15
|
||||||
-- Finally, we calculate the level
|
-- Finally, we calculate the level
|
||||||
local final_level = math.round(k * rand_bonus_percent)
|
local final_level = math.round(k * rand_bonus_percent)
|
||||||
@ -455,14 +680,16 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
-- 2 Find possible enchantments
|
-- 2 Find possible enchantments
|
||||||
----
|
----
|
||||||
|
|
||||||
|
---@type Enchantment[]
|
||||||
local possible_enchantments = {}
|
local possible_enchantments = {}
|
||||||
|
|
||||||
-- Get level
|
-- Get level
|
||||||
-- If the modified level is within two overlapping ranges for the same
|
-- If the modified level is within two overlapping ranges for the same
|
||||||
-- enchantment type, the higher power value is used.
|
-- enchantment type, the higher power value is used.
|
||||||
for enchantment_name, enchantment_def in pairs(self.enchantment_defs) do
|
for enchantment_name, enchantment_def in pairs(group_enchantments) do
|
||||||
local levels = {}
|
local levels = {}
|
||||||
|
|
||||||
|
-- find matching levels
|
||||||
for level, final_level_range in ipairs(enchantment_def.final_level_range) do
|
for level, final_level_range in ipairs(enchantment_def.final_level_range) do
|
||||||
local min = final_level_range[1]
|
local min = final_level_range[1]
|
||||||
local max = final_level_range[2]
|
local max = final_level_range[2]
|
||||||
@ -472,13 +699,16 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- pick the highest level
|
||||||
local level = levels[#levels]
|
local level = levels[#levels]
|
||||||
|
|
||||||
if level then
|
if level then
|
||||||
table.insert(possible_enchantments, {
|
table.insert(possible_enchantments, {
|
||||||
id = enchantment_name,
|
id = enchantment_name,
|
||||||
value = enchantment_def.level_def[level],
|
value = enchantment_def.level_def[level],
|
||||||
level = level
|
level = level,
|
||||||
|
secondary = enchantment_def.secondary,
|
||||||
|
incompatible = enchantment_def.incompatible
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -487,27 +717,88 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
-- 3 Select a set of enchantments from the list
|
-- 3 Select a set of enchantments from the list
|
||||||
----
|
----
|
||||||
|
|
||||||
|
---@type Enchantment[]
|
||||||
local final_enchantments = {}
|
local final_enchantments = {}
|
||||||
local total_weight = 0
|
local total_weight = 0
|
||||||
|
|
||||||
-- calculate total weight
|
-- calculate total weight
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
for j, enchantment in ipairs(possible_enchantments) do
|
for j, enchantment in ipairs(possible_enchantments) do
|
||||||
total_weight = total_weight + self.enchantment_defs[enchantment.id].weight
|
total_weight = total_weight + self.enchantment_defs[enchantment.id].weight
|
||||||
end
|
end
|
||||||
|
|
||||||
math.randomseed(self.randomseed)
|
-- Pick a random integer in the half range [0; total_weight / 2] as a number `rand_weight`
|
||||||
local rand_weight = math.random(0, total_weight / 2)
|
local rand_weight = math.random(0, total_weight / 2)
|
||||||
|
-- local probability = (final_level + 1) / 50
|
||||||
|
local probability_level = final_level
|
||||||
|
---@type Enchantment[]
|
||||||
|
local possible_enchantments_excl_secodnary = {}
|
||||||
|
|
||||||
-- select final enchantments
|
for _, enchantment in pairs(possible_enchantments) do
|
||||||
|
if not enchantment.secondary then
|
||||||
|
table.insert(possible_enchantments_excl_secodnary, enchantment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Select final enchantments
|
||||||
|
-- Iterate through each enchantment in the list, subtracting its weight from `rand_weight`.
|
||||||
|
-- If `rand_weight` is now negative, select the current enchantment.
|
||||||
for j = 1, #possible_enchantments, 1 do
|
for j = 1, #possible_enchantments, 1 do
|
||||||
math.randomseed(self.randomseed)
|
|
||||||
local rand_ench_idx = math.random(1, #possible_enchantments)
|
local rand_ench_idx = math.random(1, #possible_enchantments)
|
||||||
local rand_ench = possible_enchantments[rand_ench_idx]
|
local rand_ench = possible_enchantments[rand_ench_idx]
|
||||||
|
|
||||||
table.remove(possible_enchantments, rand_ench_idx)
|
if j == 1 then
|
||||||
rand_weight = rand_weight - self.enchantment_defs[rand_ench.id].weight
|
-- First pick
|
||||||
|
-- Dont add cursed/secondary enchantment as first pick
|
||||||
|
rand_ench_idx = math.random(1, #possible_enchantments_excl_secodnary)
|
||||||
|
rand_ench = possible_enchantments_excl_secodnary[rand_ench_idx]
|
||||||
|
|
||||||
table.insert(final_enchantments, rand_ench)
|
table.insert(final_enchantments, rand_ench)
|
||||||
|
|
||||||
|
for idx, value in pairs(possible_enchantments) do
|
||||||
|
if rand_ench.id == value.id then
|
||||||
|
table.remove(possible_enchantments, idx)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove incomaptible enchantments
|
||||||
|
if rand_ench.incompatible
|
||||||
|
and table.indexof(rand_ench.incompatible, value.id) ~= -1
|
||||||
|
then
|
||||||
|
table.remove(possible_enchantments, idx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
local probability = (probability_level + 1) / 50
|
||||||
|
|
||||||
|
table.insert(final_enchantments, rand_ench)
|
||||||
|
table.remove(possible_enchantments, rand_ench_idx)
|
||||||
|
|
||||||
|
for idx, value in pairs(possible_enchantments) do
|
||||||
|
-- remove incomaptible enchantments
|
||||||
|
if rand_ench.incompatible
|
||||||
|
and table.indexof(rand_ench.incompatible, value.id) ~= -1
|
||||||
|
then
|
||||||
|
table.remove(possible_enchantments, idx)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- With probability (`final_level` + 1) / 50, keep going. Otherwise, stop picking bonus enchantments.
|
||||||
|
local rand_probability = math.random()
|
||||||
|
|
||||||
|
if rand_probability < probability then
|
||||||
|
-- Divide the `final_level` in half, rounded down
|
||||||
|
-- (this does not affect the possible enchantments themselves,
|
||||||
|
-- because they were all pre-calculated in Step Two).
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Repeat from the beginning.
|
||||||
|
probability_level = probability_level / 2
|
||||||
|
end
|
||||||
|
|
||||||
|
rand_weight = rand_weight - self.enchantment_defs[rand_ench.id].weight
|
||||||
|
|
||||||
-- If `rand_weight` is now negative, select the current enchantment and stop.
|
-- If `rand_weight` is now negative, select the current enchantment and stop.
|
||||||
if rand_weight < 0 then
|
if rand_weight < 0 then
|
||||||
break
|
break
|
||||||
@ -515,17 +806,52 @@ function XEnchanting.get_enchantment_data(self, nr_of_bookshelfs, tool_def)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local tool_cap_data = self:get_enchanted_tool_capabilities(tool_def, final_enchantments)
|
local tool_cap_data = self:get_enchanted_tool_capabilities(tool_def, final_enchantments)
|
||||||
|
local descriptions = self:get_enchanted_descriptions(final_enchantments)
|
||||||
|
|
||||||
table.insert(data.slots, i, {
|
table.insert(data.slots, i, {
|
||||||
level = slot_lvl,
|
level = slot_lvl,
|
||||||
final_enchantments = final_enchantments,
|
final_enchantments = final_enchantments,
|
||||||
tool_cap_data = tool_cap_data
|
tool_cap_data = tool_cap_data,
|
||||||
|
descriptions = descriptions
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_hotbar_bg(x, y)
|
||||||
|
local out = ''
|
||||||
|
|
||||||
|
for i = 0, 7, 1 do
|
||||||
|
out = out .. 'image[' .. x + i .. ',' .. y .. ';1,1;x_enchanting_gui_hb_bg.png]'
|
||||||
|
end
|
||||||
|
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_list_bg(x, y)
|
||||||
|
local out = ''
|
||||||
|
|
||||||
|
for row = 0, 2, 1 do
|
||||||
|
for i = 0, 7, 1 do
|
||||||
|
out = out .. 'image[' .. x + i .. ',' .. y + row .. ';1,1;x_enchanting_gui_slot_bg.png]'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_formspec_bg(player_name)
|
||||||
|
local info = minetest.get_player_information(player_name)
|
||||||
|
local bg = 'background[5,5;1,1;x_enchanting_gui_formbg.png;true]'
|
||||||
|
|
||||||
|
if info.formspec_version > 1 then
|
||||||
|
bg = 'background9[5,5;1,1;x_enchanting_gui_formbg.png;true;10]'
|
||||||
|
end
|
||||||
|
|
||||||
|
return bg
|
||||||
|
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 = minetest.get_meta(pos):get_inventory()
|
||||||
@ -537,21 +863,29 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
|||||||
|
|
||||||
local formspec = {
|
local formspec = {
|
||||||
'size[8,9]',
|
'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') .. ']',
|
'label[0, 0;' .. S('Enchant') .. ']',
|
||||||
|
-- item
|
||||||
'list[nodemeta:' .. spos .. ';item;0, 2.5;1, 1;]',
|
'list[nodemeta:' .. spos .. ';item;0, 2.5;1, 1;]',
|
||||||
'image[1,2.5;1,1;x_enchanting_trade_slot.png;]',
|
'image[0, 2.5;1,1;x_enchanting_gui_cloth_bg.png]',
|
||||||
|
-- trade
|
||||||
'list[nodemeta:' .. spos .. ';trade;1, 2.5;1, 1;]',
|
'list[nodemeta:' .. spos .. ';trade;1, 2.5;1, 1;]',
|
||||||
|
'image[1, 2.5;1,1;x_enchanting_gui_cloth_trade_bg.png]',
|
||||||
|
-- inventories
|
||||||
'list[current_player;main;0, 4.85;8, 1;]',
|
'list[current_player;main;0, 4.85;8, 1;]',
|
||||||
'list[current_player;main;0, 6.08;8, 3;8]',
|
'list[current_player;main;0, 6.08;8, 3;8]',
|
||||||
'listring[nodemeta:' .. spos .. ';trade]',
|
'listring[nodemeta:' .. spos .. ';trade]',
|
||||||
'listring[current_player;main]',
|
'listring[current_player;main]',
|
||||||
'listring[nodemeta:' .. spos .. ';item]',
|
'listring[nodemeta:' .. spos .. ';item]',
|
||||||
'listring[current_player;main]'
|
'listring[current_player;main]',
|
||||||
}
|
}
|
||||||
|
|
||||||
if default then
|
formspec[#formspec + 1] = get_hotbar_bg(0, 4.85)
|
||||||
formspec[#formspec + 1] = default.get_hotbar_bg(0, 4.85)
|
formspec[#formspec + 1] = get_list_bg(0, 6.08)
|
||||||
end
|
|
||||||
|
|
||||||
-- data
|
-- data
|
||||||
if data then
|
if data then
|
||||||
@ -561,17 +895,17 @@ 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[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button.png;slot_' .. i .. ';' .. slot.tool_cap_data.enchantments_desc_masked .. ' ' .. minetest.colorize('#FFFF00', S('level') .. ': ' .. 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 .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||||
else
|
else
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@diagnostic disable-next-line: codestyle-check
|
||||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';' .. slot.tool_cap_data.enchantments_desc_masked .. ' ' .. minetest.colorize('#FFFF00', S('level') .. ': ' .. 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 .. minetest.formspec_escape(' [' .. slot.level .. ']') .. ']'
|
||||||
end
|
end
|
||||||
|
|
||||||
formspec[#formspec + 1] = 'image[2.5,' .. -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;]'
|
||||||
else
|
else
|
||||||
-- disabled buttons
|
-- disabled buttons
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@diagnostic disable-next-line: codestyle-check
|
||||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
formspec[#formspec + 1] = 'image_button[3.125,' .. -0.5 + i .. ';5.125,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -580,7 +914,7 @@ function XEnchanting.get_formspec(self, pos, player_name, data)
|
|||||||
for i = 1, 3, 1 do
|
for i = 1, 3, 1 do
|
||||||
-- disabled buttons
|
-- disabled buttons
|
||||||
---@diagnostic disable-next-line: codestyle-check
|
---@diagnostic disable-next-line: codestyle-check
|
||||||
formspec[#formspec + 1] = 'image_button[2.5,' .. -0.5 + i .. ';5,1;x_enchanting_image_button_disabled.png;slot_' .. i .. ';]'
|
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 = false
|
model_scroll_is_open = false
|
||||||
|
@ -31,36 +31,6 @@ pipelines:
|
|||||||
script:
|
script:
|
||||||
- nvm use v17.2.0
|
- nvm use v17.2.0
|
||||||
- npm run lua-diagnostics
|
- npm run lua-diagnostics
|
||||||
branches:
|
|
||||||
master:
|
|
||||||
- step:
|
|
||||||
name: Install Node Dependencies
|
|
||||||
caches:
|
|
||||||
- node-modules
|
|
||||||
- npm
|
|
||||||
- nvm
|
|
||||||
script:
|
|
||||||
- nvm install v17.2.0
|
|
||||||
- npm i -g npm@8
|
|
||||||
- npm ci
|
|
||||||
- parallel:
|
|
||||||
- step:
|
|
||||||
name: Lua Check
|
|
||||||
script:
|
|
||||||
- apt-get update
|
|
||||||
- apt-get -y install lua5.1
|
|
||||||
- apt-get -y install luarocks
|
|
||||||
- luarocks install luacheck
|
|
||||||
- luacheck .
|
|
||||||
- step:
|
|
||||||
name: Lua Diagnostics
|
|
||||||
caches:
|
|
||||||
- node-modules
|
|
||||||
- npm
|
|
||||||
- nvm
|
|
||||||
script:
|
|
||||||
- nvm use v17.2.0
|
|
||||||
- npm run lua-diagnostics
|
|
||||||
tags:
|
tags:
|
||||||
"*":
|
"*":
|
||||||
- step:
|
- step:
|
||||||
|
284
init.lua
@ -1,5 +1,20 @@
|
|||||||
-- X Enchanting
|
--[[
|
||||||
-- by SaKeL
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
|
Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
|
--]]
|
||||||
|
|
||||||
local path = minetest.get_modpath('x_enchanting')
|
local path = minetest.get_modpath('x_enchanting')
|
||||||
local mod_start_time = minetest.get_us_time()
|
local mod_start_time = minetest.get_us_time()
|
||||||
@ -7,23 +22,169 @@ local mod_start_time = minetest.get_us_time()
|
|||||||
dofile(path .. '/api.lua')
|
dofile(path .. '/api.lua')
|
||||||
dofile(path .. '/table.lua')
|
dofile(path .. '/table.lua')
|
||||||
|
|
||||||
|
---Check if string X starts with string Y
|
||||||
|
---@param str string
|
||||||
|
---@param start string
|
||||||
|
---@return boolean
|
||||||
|
local function starts_with(str, start)
|
||||||
|
return str:sub(1, #start) == start
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(function()
|
minetest.register_on_mods_loaded(function()
|
||||||
|
-- Tools override
|
||||||
for name, tool_def in pairs(minetest.registered_tools) do
|
for name, tool_def in pairs(minetest.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
|
||||||
|
for _, def in pairs(minetest.registered_ores) do
|
||||||
|
if not XEnchanting.registered_ores[def.ore] then
|
||||||
|
XEnchanting.registered_ores[def.ore] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Entities override - Looting
|
||||||
|
for name, def in pairs(minetest.registered_entities) do
|
||||||
|
if starts_with(name, 'mobs_animal:')
|
||||||
|
or starts_with(name, 'mobs_monster:')
|
||||||
|
then
|
||||||
|
if def.on_punch and def.drops then
|
||||||
|
local prev_on_punch = def.on_punch
|
||||||
|
|
||||||
|
---@param self table
|
||||||
|
---@param puncher ObjectRef|nil
|
||||||
|
---@param time_from_last_punch number|integer|nil
|
||||||
|
---@param tool_capabilities ToolCapabilitiesDef|nil
|
||||||
|
---@param dir Vector
|
||||||
|
---@param damage number|integer
|
||||||
|
---@return boolean|nil
|
||||||
|
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
if not self
|
||||||
|
or not self.object
|
||||||
|
or not self.object:get_luaentity()
|
||||||
|
or not puncher
|
||||||
|
or not tool_capabilities
|
||||||
|
then
|
||||||
|
return prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
end
|
||||||
|
|
||||||
|
local wield_stack = puncher:get_wielded_item()
|
||||||
|
local wield_stack_meta = wield_stack:get_meta()
|
||||||
|
local looting = wield_stack_meta:get_float('is_looting')
|
||||||
|
|
||||||
|
if looting == 0 then
|
||||||
|
return prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
prev_on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
|
|
||||||
|
if self.health and self.health <= 0 then
|
||||||
|
local death_by_player = self.cause_of_death
|
||||||
|
and self.cause_of_death.puncher
|
||||||
|
and self.cause_of_death.puncher:is_player()
|
||||||
|
|
||||||
|
if death_by_player and pos then
|
||||||
|
for _, drop in ipairs(def.drops) do
|
||||||
|
if math.random(10, 100) / 100 < looting / (looting + 1) then
|
||||||
|
local drop_min = drop.min or 0
|
||||||
|
local drop_max = drop.max or 0
|
||||||
|
local count = math.random(drop_min, drop_max)
|
||||||
|
local stack = ItemStack({
|
||||||
|
name = drop.name,
|
||||||
|
count = count
|
||||||
|
})
|
||||||
|
local chance = math.random(1, tool_capabilities.max_drop_level)
|
||||||
|
|
||||||
|
stack:set_count(stack:get_count() * chance)
|
||||||
|
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
minetest.item_drop(stack, puncher, pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif starts_with(name, 'animalia:') then
|
||||||
|
if def.death_func and def.drops then
|
||||||
|
local prev_death_func = def.death_func
|
||||||
|
|
||||||
|
---@param self table
|
||||||
|
def.death_func = function(self)
|
||||||
|
local puncher = self._puncher
|
||||||
|
|
||||||
|
if not self
|
||||||
|
or not self.object
|
||||||
|
or not self.object:get_luaentity()
|
||||||
|
or not puncher
|
||||||
|
or not puncher:is_player()
|
||||||
|
or self._looting_dropped
|
||||||
|
then
|
||||||
|
return prev_death_func(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
local wield_stack = puncher:get_wielded_item()
|
||||||
|
local wield_stack_meta = wield_stack:get_meta()
|
||||||
|
local looting = wield_stack_meta:get_float('is_looting')
|
||||||
|
|
||||||
|
if looting == 0 then
|
||||||
|
return prev_death_func(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
prev_death_func(self)
|
||||||
|
|
||||||
|
local death_by_player = puncher and puncher:is_player()
|
||||||
|
|
||||||
|
if death_by_player and pos then
|
||||||
|
local tool_capabilities = wield_stack:get_tool_capabilities()
|
||||||
|
self._looting_dropped = true
|
||||||
|
|
||||||
|
for _, drop in ipairs(def.drops) do
|
||||||
|
if math.random(10, 100) / 100 < looting / (looting + 1) then
|
||||||
|
local drop_min = drop.min or 0
|
||||||
|
local drop_max = drop.max or 0
|
||||||
|
local count = math.random(drop_min, drop_max)
|
||||||
|
local stack = ItemStack({
|
||||||
|
name = drop.name,
|
||||||
|
count = count
|
||||||
|
})
|
||||||
|
local chance = math.random(1, tool_capabilities.max_drop_level)
|
||||||
|
|
||||||
|
stack:set_count(stack:get_count() * chance)
|
||||||
|
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
minetest.item_drop(stack, puncher, pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
minetest.register_on_joinplayer(function(player, last_login)
|
minetest.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
|
||||||
|
XEnchanting.player_seeds[player:get_player_name()] = XEnchanting.get_randomseed()
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
minetest.register_on_leaveplayer(function(player, timed_out)
|
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
|
local old_handle_node_drops = minetest.handle_node_drops
|
||||||
|
|
||||||
function minetest.handle_node_drops(pos, drops, digger)
|
function minetest.handle_node_drops(pos, drops, digger)
|
||||||
@ -33,37 +194,118 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
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 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()
|
||||||
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()
|
-- Fortune
|
||||||
local node = minetest.get_node(pos)
|
local fortune = wield_stack_meta:get_float('is_fortune')
|
||||||
local silk_touch_group
|
|
||||||
|
|
||||||
if minetest.get_item_group(wield_stack_name, 'pickaxe') > 0 then
|
if fortune > 0 then
|
||||||
silk_touch_group = 'cracky'
|
local new_drops = {}
|
||||||
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
|
for _, itemstring in ipairs(drops) do
|
||||||
or minetest.get_item_group(node.name, silk_touch_group) == 0
|
if XEnchanting.registered_ores[node.name]
|
||||||
or minetest.get_item_group(node.name, 'no_silktouch') == 1
|
or minetest.get_item_group(node.name, 'stone') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'soil') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'sand') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'snowy') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'slippery') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'tree') > 0
|
||||||
|
or minetest.get_item_group(node.name, 'leaves') > 0
|
||||||
then
|
then
|
||||||
|
local tool_capabilities = wield_stack:get_tool_capabilities()
|
||||||
|
local stack = ItemStack(itemstring)
|
||||||
|
local chance = math.random(1, tool_capabilities.max_drop_level)
|
||||||
|
|
||||||
|
stack:set_count(stack:get_count() * chance)
|
||||||
|
|
||||||
|
if stack:get_count() > 0 then
|
||||||
|
table.insert(new_drops, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #new_drops > 0 then
|
||||||
|
return old_handle_node_drops(pos, new_drops, digger)
|
||||||
|
end
|
||||||
|
|
||||||
return old_handle_node_drops(pos, drops, digger)
|
return old_handle_node_drops(pos, drops, digger)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Silk Touch
|
||||||
|
local silk_touch = wield_stack_meta:get_float('is_silk_touch')
|
||||||
|
|
||||||
|
if silk_touch > 0
|
||||||
|
and minetest.get_item_group(node.name, 'no_silktouch') == 0
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return old_handle_node_drops(pos, drops, digger)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||||
|
-- Curse of Vanishing
|
||||||
|
if (player:get_hp() + hp_change) <= 0 then
|
||||||
|
-- Going to die
|
||||||
|
local player_inv = player:get_inventory() --[[@as InvRef]]
|
||||||
|
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()
|
||||||
|
|
||||||
|
if stack_meta:get_float('is_curse_of_vanishing') > 0 then
|
||||||
|
player_inv:set_stack(list_name, i, ItemStack(''))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return hp_change
|
||||||
|
end, true)
|
||||||
|
|
||||||
|
-- Knockback (only for players)
|
||||||
|
local old_calculate_knockback = minetest.calculate_knockback
|
||||||
|
|
||||||
|
function minetest.calculate_knockback(player, hitter, time_from_last_punch,
|
||||||
|
tool_capabilities, dir, distance, damage)
|
||||||
|
if hitter and hitter:is_player() then
|
||||||
|
local hitter_wield_stack = hitter:get_wielded_item()
|
||||||
|
local hitter_wield_stack_meta = hitter_wield_stack:get_meta()
|
||||||
|
local ench_knockback = hitter_wield_stack_meta:get_float('is_knockback')
|
||||||
|
|
||||||
|
if ench_knockback > 0 then
|
||||||
|
local orig_knockback = old_calculate_knockback(
|
||||||
|
player,
|
||||||
|
hitter,
|
||||||
|
time_from_last_punch,
|
||||||
|
tool_capabilities,
|
||||||
|
dir,
|
||||||
|
distance,
|
||||||
|
damage
|
||||||
|
)
|
||||||
|
|
||||||
|
orig_knockback = orig_knockback + 1
|
||||||
|
|
||||||
|
local new_knockback = orig_knockback + (orig_knockback * (ench_knockback / 100))
|
||||||
|
|
||||||
|
player:add_velocity(vector.new(0, new_knockback, 0))
|
||||||
|
|
||||||
|
return new_knockback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return old_calculate_knockback(player, hitter, time_from_last_punch,
|
||||||
|
tool_capabilities, dir, distance, damage)
|
||||||
|
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]')
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
# textdomain: x_enchanting
|
# textdomain: x_enchanting
|
||||||
Sharpness=
|
Sharpness=
|
||||||
|
Looting=
|
||||||
Fortune=
|
Fortune=
|
||||||
Unbreaking=
|
Unbreaking=
|
||||||
Efficiency=
|
Efficiency=
|
||||||
|
Silk Touch=
|
||||||
|
Curse of Vanishing=
|
||||||
|
Knockback=
|
||||||
|
Power=
|
||||||
|
Punch=
|
||||||
|
Infinity=
|
||||||
Enchanted=
|
Enchanted=
|
||||||
Enchant=
|
Enchant=
|
||||||
level=
|
|
||||||
Enchanting Table=
|
Enchanting Table=
|
||||||
owned by=
|
owned by=
|
||||||
Scroll of Enchantments=
|
Scroll of Enchantments=
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
# textdomain: x_enchanting
|
# textdomain: x_enchanting
|
||||||
Sharpness=Ostrosť
|
Sharpness=Ostrosť
|
||||||
|
Looting=
|
||||||
Fortune=Šťastie
|
Fortune=Šťastie
|
||||||
Unbreaking=Nelámavosť
|
Unbreaking=Nelámavosť
|
||||||
Efficiency=Výkonnosť
|
Efficiency=Výkonnosť
|
||||||
|
Silk Touch=Hodvábny dotyk
|
||||||
|
Curse of Vanishing=Kliatba zmiznutia
|
||||||
|
Knockback=Spätný úder
|
||||||
|
Power=
|
||||||
|
Punch=
|
||||||
|
Infinity=
|
||||||
Enchanted=Očarený
|
Enchanted=Očarený
|
||||||
Enchant=Očarovať
|
Enchant=Očarovať
|
||||||
level=level
|
|
||||||
Enchanting Table=Čarovný stôl
|
Enchanting Table=Čarovný stôl
|
||||||
owned by=vlastník
|
owned by=vlastník
|
||||||
Scroll of Enchantments=Čarovný Zvitok
|
Scroll of Enchantments=Čarovný Zvitok
|
||||||
|
BIN
screenshot.3.png
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 385 KiB |
@ -1,3 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Deploy code to CDB
|
||||||
|
* Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch'
|
||||||
import yargs from 'yargs/yargs'
|
import yargs from 'yargs/yargs'
|
||||||
import {hideBin} from 'yargs/helpers'
|
import {hideBin} from 'yargs/helpers'
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Run LUA diagnostics in continuous integration
|
||||||
|
* Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
import * as path from 'node:path'
|
import * as path from 'node:path'
|
||||||
import * as fs from 'node:fs'
|
import * as fs from 'node:fs'
|
||||||
import {exec} from 'node:child_process'
|
import {exec} from 'node:child_process'
|
||||||
@ -60,6 +78,7 @@ extract.on('end', () => {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`${command} --logpath "${logPath}" --check "${cwd}"`)
|
||||||
console.log(`\n${stdout}`)
|
console.log(`\n${stdout}`)
|
||||||
|
|
||||||
if (fs.existsSync('./logs/check.json')) {
|
if (fs.existsSync('./logs/check.json')) {
|
||||||
|
72
table.lua
@ -1,3 +1,22 @@
|
|||||||
|
--[[
|
||||||
|
X Enchanting. Adds Enchanting Mechanics and API.
|
||||||
|
Copyright (C) 2022 SaKeL <juraj.vajda@gmail.com>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to juraj.vajda@gmail.com
|
||||||
|
--]]
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line
|
||||||
screwdriver = minetest.global_exists('screwdriver') and screwdriver --[[@as MtgScrewdriver]]
|
screwdriver = minetest.global_exists('screwdriver') and screwdriver --[[@as MtgScrewdriver]]
|
||||||
|
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
@ -59,6 +78,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param placer ObjectRef | nil
|
---@param placer ObjectRef | nil
|
||||||
---@param itemstack ItemStack
|
---@param itemstack ItemStack
|
||||||
---@param pointed_thing PointedThingDef
|
---@param pointed_thing PointedThingDef
|
||||||
|
---@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 = minetest.get_meta(pos)
|
||||||
|
|
||||||
@ -79,6 +99,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param clicker ObjectRef
|
---@param clicker ObjectRef
|
||||||
---@param itemstack ItemStack
|
---@param itemstack ItemStack
|
||||||
---@param pointed_thing? PointedThingDef
|
---@param pointed_thing? PointedThingDef
|
||||||
|
---@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 = minetest.get_meta(pos)
|
||||||
local p_name = clicker:get_player_name()
|
local p_name = clicker:get_player_name()
|
||||||
@ -102,9 +123,13 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
|
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
|
||||||
if not inv:is_empty('item') 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(#bookshelfs, minetest.registered_tools[item_stack:get_name()])
|
local data = XEnchanting:get_enchantment_data(
|
||||||
|
clicker,
|
||||||
|
#bookshelfs,
|
||||||
|
minetest.registered_tools[item_stack:get_name()]
|
||||||
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
meta:set_string('formspec', formspec)
|
meta:set_string('formspec', formspec)
|
||||||
@ -119,6 +144,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
---@param intensity? number
|
---@param intensity? number
|
||||||
---@return table | nil
|
---@return table | nil
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_blast = function(pos, intensity)
|
on_blast = function(pos, intensity)
|
||||||
if minetest.is_protected(pos, '') then
|
if minetest.is_protected(pos, '') then
|
||||||
return
|
return
|
||||||
@ -155,11 +181,13 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
and inv:is_empty('trade')
|
and inv:is_empty('trade')
|
||||||
and not minetest.is_protected(pos, player:get_player_name())
|
and not minetest.is_protected(pos, player:get_player_name())
|
||||||
end,
|
end,
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
---@param pos Vector
|
---@param pos Vector
|
||||||
---@param elapsed number
|
---@param elapsed number
|
||||||
|
---@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 = minetest.get_objects_inside_radius(pos, 0.9)
|
||||||
@ -230,6 +258,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- symbol particles
|
-- symbol particles
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
for i = 1, 10, 1 do
|
for i = 1, 10, 1 do
|
||||||
local pos_random = bookshelfs[math.random(1, #bookshelfs)]
|
local pos_random = bookshelfs[math.random(1, #bookshelfs)]
|
||||||
local x = pos.x - pos_random.x
|
local x = pos.x - pos_random.x
|
||||||
@ -271,6 +300,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param index number
|
---@param index number
|
||||||
---@param stack ItemStack
|
---@param stack ItemStack
|
||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
local st_meta = stack:get_meta()
|
local st_meta = stack:get_meta()
|
||||||
local st_name = stack:get_name()
|
local st_name = stack:get_name()
|
||||||
@ -298,6 +328,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param index number
|
---@param index number
|
||||||
---@param stack ItemStack
|
---@param stack ItemStack
|
||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
local st_name = stack:get_name()
|
local st_name = stack:get_name()
|
||||||
|
|
||||||
@ -321,6 +352,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param to_index number
|
---@param to_index number
|
||||||
---@param count number
|
---@param count number
|
||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
@ -329,12 +361,16 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param index number
|
---@param index number
|
||||||
---@param stack ItemStack
|
---@param stack ItemStack
|
||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
|
---@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 = minetest.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_meta = item_stack:get_meta()
|
||||||
|
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
||||||
|
|
||||||
if not inv:is_empty('item') then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = minetest.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 },
|
||||||
@ -342,8 +378,11 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
)
|
)
|
||||||
|
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local data = XEnchanting:get_enchantment_data(
|
||||||
local data = XEnchanting:get_enchantment_data(#bookshelfs, minetest.registered_tools[item_stack:get_name()])
|
player,
|
||||||
|
#bookshelfs,
|
||||||
|
minetest.registered_tools[item_stack:get_name()]
|
||||||
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
meta:set_string('formspec', formspec)
|
meta:set_string('formspec', formspec)
|
||||||
@ -358,12 +397,16 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param index number
|
---@param index number
|
||||||
---@param stack ItemStack
|
---@param stack ItemStack
|
||||||
---@param player ObjectRef
|
---@param player ObjectRef
|
||||||
|
---@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 = minetest.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_meta = item_stack:get_meta()
|
||||||
|
local is_enchanted = item_stack_meta:get_int('is_enchanted')
|
||||||
|
|
||||||
if not inv:is_empty('item') then
|
if not inv:is_empty('item') and is_enchanted == 0 then
|
||||||
-- bookshelfs
|
-- bookshelfs
|
||||||
local bookshelfs = minetest.find_nodes_in_area(
|
local bookshelfs = minetest.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 },
|
||||||
@ -371,8 +414,11 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
{ 'default:bookshelf', 'group:bookshelf' }
|
{ 'default:bookshelf', 'group:bookshelf' }
|
||||||
)
|
)
|
||||||
|
|
||||||
local item_stack = inv:get_stack('item', 1)
|
local data = XEnchanting:get_enchantment_data(
|
||||||
local data = XEnchanting:get_enchantment_data(#bookshelfs, minetest.registered_tools[item_stack:get_name()])
|
player,
|
||||||
|
#bookshelfs,
|
||||||
|
minetest.registered_tools[item_stack:get_name()]
|
||||||
|
)
|
||||||
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
local formspec = XEnchanting:get_formspec(pos, p_name, data)
|
||||||
|
|
||||||
meta:set_string('formspec', formspec)
|
meta:set_string('formspec', formspec)
|
||||||
@ -387,6 +433,7 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
---@param formname string
|
---@param formname string
|
||||||
---@param fields table
|
---@param fields table
|
||||||
---@param sender ObjectRef
|
---@param sender ObjectRef
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
on_receive_fields = function(pos, formname, fields, sender)
|
||||||
local p_name = sender:get_player_name()
|
local p_name = sender:get_player_name()
|
||||||
|
|
||||||
@ -416,9 +463,8 @@ minetest.register_node('x_enchanting:table', {
|
|||||||
end
|
end
|
||||||
|
|
||||||
local trade_stack = inv:get_stack('trade', 1)
|
local trade_stack = inv:get_stack('trade', 1)
|
||||||
local data = XEnchanting.form_context[p_name].data
|
|
||||||
|
|
||||||
if trade_stack:get_count() < selected_slot or not data then
|
if trade_stack:get_count() < selected_slot then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -466,12 +512,14 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
},
|
},
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param killer ObjectRef
|
---@param killer ObjectRef
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_death = function(self, killer)
|
on_death = function(self, killer)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end,
|
end,
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param staticdata StringAbstract
|
---@param staticdata StringAbstract
|
||||||
---@param dtime_s number
|
---@param dtime_s number
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
on_activate = function(self, staticdata, dtime_s)
|
||||||
self._scroll_closed = true
|
self._scroll_closed = true
|
||||||
self._tablechecktimer = 5
|
self._tablechecktimer = 5
|
||||||
@ -485,6 +533,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
---@param self table
|
---@param self table
|
||||||
---@param dtime number
|
---@param dtime number
|
||||||
---@param moveresult? table
|
---@param moveresult? table
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_step = function(self, dtime, moveresult)
|
on_step = function(self, dtime, moveresult)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
@ -513,6 +562,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
local found_player = false
|
local found_player = false
|
||||||
|
|
||||||
if #objects > 0 then
|
if #objects > 0 then
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
for i, obj in ipairs(objects) do
|
for i, obj in ipairs(objects) do
|
||||||
if obj:is_player() and obj:get_pos() then
|
if obj:is_player() and obj:get_pos() then
|
||||||
-- player
|
-- player
|
||||||
@ -520,6 +570,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
local distance = vector.distance(pos, obj:get_pos())
|
local distance = vector.distance(pos, obj:get_pos())
|
||||||
|
|
||||||
if distance < shortest_distance then
|
if distance < shortest_distance then
|
||||||
|
shortest_distance = distance
|
||||||
self._player = obj
|
self._player = obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -573,6 +624,7 @@ minetest.register_entity('x_enchanting:table_scroll', {
|
|||||||
---@param dir Vector
|
---@param dir Vector
|
||||||
---@param damage number
|
---@param damage number
|
||||||
---@return boolean | nil
|
---@return boolean | nil
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
BIN
textures/x_enchanting_gui_cloth_bg.png
Normal file
After Width: | Height: | Size: 112 B |
BIN
textures/x_enchanting_gui_cloth_trade_bg.png
Normal file
After Width: | Height: | Size: 165 B |
BIN
textures/x_enchanting_gui_formbg.png
Normal file
After Width: | Height: | Size: 935 B |
BIN
textures/x_enchanting_gui_hb_bg.png
Normal file
After Width: | Height: | Size: 117 B |
BIN
textures/x_enchanting_gui_slot_bg.png
Normal file
After Width: | Height: | Size: 118 B |
Before Width: | Height: | Size: 108 B After Width: | Height: | Size: 108 B |
Before Width: | Height: | Size: 109 B After Width: | Height: | Size: 109 B |
Before Width: | Height: | Size: 172 B After Width: | Height: | Size: 178 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 227 B |
Before Width: | Height: | Size: 109 B |
@ -14,3 +14,4 @@
|
|||||||
---@field on_detach_child fun(self: table, child: ObjectRef): nil Function receive a "luaentity" table as `self`. `child`: an `ObjectRef` of the child that detaches
|
---@field on_detach_child fun(self: table, child: ObjectRef): nil Function receive a "luaentity" table as `self`. `child`: an `ObjectRef` of the child that detaches
|
||||||
---@field on_detach fun(self: table, parent: ObjectRef|nil): nil Function receive a "luaentity" table as `self`. `parent`: an `ObjectRef` (can be `nil`) from where it got detached. This happens before the parent object is removed from the world.
|
---@field on_detach fun(self: table, parent: ObjectRef|nil): nil Function receive a "luaentity" table as `self`. `parent`: an `ObjectRef` (can be `nil`) from where it got detached. This happens before the parent object is removed from the world.
|
||||||
---@field get_staticdata fun(self: table) Function receive a "luaentity" table as `self`. Should return a string that will be passed to `on_activate` when the object is instantiated the next time.
|
---@field get_staticdata fun(self: table) Function receive a "luaentity" table as `self`. Should return a string that will be passed to `on_activate` when the object is instantiated the next time.
|
||||||
|
---@field drops table Custom for mob drops
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
---@field add_entity fun(pos: Vector, name: string, staticdata?: string): ObjectRef|nil Spawn Lua-defined entity at position. Returns `ObjectRef`, or `nil` if failed.
|
---@field add_entity fun(pos: Vector, name: string, staticdata?: string): ObjectRef|nil Spawn Lua-defined entity at position. Returns `ObjectRef`, or `nil` if failed.
|
||||||
---@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 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<string, NodeDef|ItemDef> Map of registered node definitions, indexed by name
|
---@field registered_nodes table<string, NodeDef|ItemDef> Map of registered node definitions, indexed by name
|
||||||
|
---@field registered_ores table<string, table> Map of registered ore definitions, indexed by name
|
||||||
|
---@field registered_craftitems table<string, 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 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 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.
|
---@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.
|
||||||
@ -87,8 +89,12 @@
|
|||||||
---@field place_node fun(pos: Vector, node: SetNodeTable): nil Place node with the same effects that a player would cause
|
---@field place_node fun(pos: Vector, node: SetNodeTable): nil Place node with the same effects that a player would cause
|
||||||
---@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 registered_entities table<string, EntityDef> Map of registered entity 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)
|
---@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 get_player_information fun(player_name: string): table Table containing information about a player
|
||||||
|
|
||||||
---Minetest settings
|
---Minetest settings
|
||||||
---@class MinetestSettings
|
---@class MinetestSettings
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
---@class MtgFarming
|
---@class MtgFarming
|
||||||
---@field hoe_on_use fun(itemstack: ItemStack, user: ObjectRef, pointed_thing: PointedThingDef, uses: number): ItemStack | nil
|
---@field hoe_on_use fun(itemstack: ItemStack, user: ObjectRef, pointed_thing: PointedThingDef, uses: number): ItemStack | nil
|
||||||
---@field place_seed fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef, plantname: string): ItemStack Seed placement
|
---@field place_seed fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef, plantname: string): ItemStack Seed placement
|
||||||
|
---@field grow_plant fun(pos: Vector, elapsed: number): nil
|
||||||
|
---@field register_plant fun(name: string, def: table): nil
|
||||||
|
|
||||||
----Node definition. Used by `minetest.register_node`.
|
----Node definition. Used by `minetest.register_node`.
|
||||||
---@class NodeDefMtgFarming
|
---@class NodeDefMtgFarming
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
---@field on_destruct fun(pos: Vector) Node destructor; called before removing node. Not called for bulk node placement. default: nil
|
---@field on_destruct fun(pos: Vector) Node destructor; called before removing node. Not called for bulk node placement. default: nil
|
||||||
---@field on_blast fun(pos: Vector, intensity?: number): nil intensity: 1.0 = mid range of regular TNT. If defined, called when an explosion touches the node, instead of removing the node.
|
---@field on_blast fun(pos: Vector, intensity?: number): nil intensity: 1.0 = mid range of regular TNT. If defined, called when an explosion touches the node, instead of removing the node.
|
||||||
---@field on_timer fun(pos: Vector, elapsed: number): boolean | nil default: nil, called by NodeTimers, see minetest.get_node_timer and NodeTimerRef. elapsed is the total time passed since the timer was started. return true to run the timer for another cycle with the same timeout value.
|
---@field on_timer fun(pos: Vector, elapsed: number): boolean | nil default: nil, called by NodeTimers, see minetest.get_node_timer and NodeTimerRef. elapsed is the total time passed since the timer was started. return true to run the timer for another cycle with the same timeout value.
|
||||||
|
---@field _next_state string Only for x_farming composter
|
||||||
|
|
||||||
---Textures of node; +Y, -Y, +X, -X, +Z, -Z. List can be shortened to needed length.
|
---Textures of node; +Y, -Y, +X, -X, +Z, -Z. List can be shortened to needed length.
|
||||||
---@class NodeTilesDef
|
---@class NodeTilesDef
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
---@field get_rotation fun(self: ObjectRef): Vector returns the rotation, a vector (radians)
|
---@field get_rotation fun(self: ObjectRef): Vector returns the rotation, a vector (radians)
|
||||||
---@field get_attach fun(self: ObjectRef): any Returns parent, bone, position, rotation, forced_visible, or nil if it isn't attached.
|
---@field get_attach fun(self: ObjectRef): any Returns parent, bone, position, rotation, forced_visible, or nil if it isn't attached.
|
||||||
---@field set_attach fun(self: ObjectRef, parent: ObjectRef, bone?: string, position?: Vector, rotation?: Vector, forced_visible?: boolean): any Returns parent, bone, position, rotation, forced_visible, or nil if it isn't attached.
|
---@field set_attach fun(self: ObjectRef, parent: ObjectRef, bone?: string, position?: Vector, rotation?: Vector, forced_visible?: boolean): any Returns parent, bone, position, rotation, forced_visible, or nil if it isn't attached.
|
||||||
|
---@field drops table Custom for mob drops
|
||||||
|
|
||||||
---`ObjectRef` armor groups
|
---`ObjectRef` armor groups
|
||||||
---@class ObjectRefArmorGroups
|
---@class ObjectRefArmorGroups
|
||||||
|
@ -6,3 +6,4 @@
|
|||||||
---Table helpers
|
---Table helpers
|
||||||
---@class TableAbstract
|
---@class TableAbstract
|
||||||
---@field copy fun(table: table): table returns a deep copy of `table`
|
---@field copy fun(table: table): table returns a deep copy of `table`
|
||||||
|
---@field indexof fun(list: table, value: any): number returns the smallest numerical index containing the value `val` in the table `list`. Non-numerical indices are ignored. If `val` could not be found, `-1` is returned. `list` must not have negative indices.
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
---@diagnostic disable: codestyle-check
|
|
||||||
---Base class Unified Inventory
|
|
||||||
---@class UnifiedInventory
|
|
||||||
---@field set_inventory_formspec fun(player: ObjectRef, formspecname: string): nil
|
|
||||||
---@field register_button fun(name: string, def: table): nil
|
|
||||||
---@field single_slot fun(x: number, y: number): nil
|
|
||||||
---@field register_page fun(name: string, def: table): nil
|
|
||||||
---@field style_full table
|
|
@ -4,55 +4,51 @@
|
|||||||
---@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' | 'silk_touch', EnchantmentDef>
|
---@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 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: 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 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, nr_of_bookshelfs: number, tool_def: ItemDef): EnchantmentData Algoritm to get aplicable random enchantments.
|
---@field get_enchantment_data fun(self: XEnchanting, player: ObjectRef, nr_of_bookshelfs: number, tool_def: ItemDef): EnchantmentData Algoritm to get aplicable random enchantments.
|
||||||
---@field get_formspec fun(self: XEnchanting, pos: Vector, player_name: string, data?: EnchantmentData): string Builds and returns `formspec` string
|
---@field get_formspec fun(self: XEnchanting, pos: Vector, player_name: string, data: EnchantmentData | nil): string Builds and returns `formspec` string
|
||||||
|
---@field form_context table<string, FormContextDef> Additional form data for player.
|
||||||
|
---@field scroll_animations table<string, table> Parameters for `ObjectRef` `set_animation` method
|
||||||
|
---@field player_seeds table<string, number | integer>
|
||||||
|
---@field registered_ores table<string, boolean> Table with registered ores, `key` ore name
|
||||||
|
---@field settings {["x_enchanting_small_formspec"]: boolean}
|
||||||
|
|
||||||
|
|
||||||
---Enchantment definition
|
---Enchantment definition
|
||||||
---@class EnchantmentDef
|
---@class EnchantmentDef
|
||||||
---@field name string Readable name of the enchantment
|
---@field name string Readable name of the enchantment
|
||||||
---@field final_level_range table<number, number[]> Level range
|
---@field final_level_range table<number, number[]> Level range
|
||||||
---@field level_def table<number, number> Level bonus
|
---@field level_def table<number, number> Level bonus. Value will be set in item meta as float.
|
||||||
---@field weight number Enchantment weight
|
---@field weight number Enchantment weight
|
||||||
---@field randomseed number Math random seed. Will change after item was enchanted.
|
---@field secondary boolean Will not appear in masked description and can be applied only as additional enchantment by probability chance.
|
||||||
---@field form_context table<string, FormContextDef> Additional form data for player.
|
---@field groups string[] | nil List of groups for items what are compatible with this enchantment. If `nil` then all groups are compatible.
|
||||||
---@field scroll_animations table<string, table> Parameters for `ObjectRef` `set_animation` method
|
---@field incompatible string[] | nil List of incompatible enchantments
|
||||||
|
|
||||||
|
|
||||||
---Form context
|
---Form context
|
||||||
---@class FormContextDef
|
---@class FormContextDef
|
||||||
---@field pos Vector Formspec/node form position
|
---@field pos Vector Formspec/node form position
|
||||||
---@field data EnchantmentDataSlot Enchantment data
|
---@field data EnchantmentData | nil Enchantment data
|
||||||
|
|
||||||
|
|
||||||
---@class GetEnchantedToolCapabilitiesReturn
|
|
||||||
---@field tool_capabilities ToolCapabilitiesDef
|
|
||||||
---@field enchantments_desc string
|
|
||||||
---@field enchantments_desc_masked string
|
|
||||||
|
|
||||||
|
|
||||||
---@class EnchantmentData
|
---@class EnchantmentData
|
||||||
---@field slots EnchantmentDataSlot[]
|
---@field slots EnchantmentDataSlot[]
|
||||||
|
|
||||||
|
|
||||||
---@class Enchantments
|
---@class Enchantment
|
||||||
---@field id string
|
---@field id string Unique ID of the enchantment
|
||||||
---@field value number
|
---@field value number Value of the enchantment based on level
|
||||||
---@field level number
|
---@field level number Level of the enchantment
|
||||||
|
---@field secondary boolean | nil Will not appear in masked description and can be applied only as additional enchantment by probability chance.
|
||||||
|
---@field incompatible string[] | nil List of incompatible enchantments
|
||||||
---@class ToolCapData
|
|
||||||
---@field enchantments_desc string Masket description before enchanting
|
|
||||||
---@field enchantments_desc_masked string Description added to item description definition after enchanting
|
|
||||||
---@field tool_capabilities ToolCapabilitiesDef Modified tool capabilities with applied enchantment
|
|
||||||
|
|
||||||
|
|
||||||
---@class EnchantmentDataSlot
|
---@class EnchantmentDataSlot
|
||||||
---@field final_enchantments Enchantments[]
|
|
||||||
---@field tool_cap_data ToolCapData
|
|
||||||
---@field level number
|
---@field level number
|
||||||
|
---@field final_enchantments Enchantment[]
|
||||||
|
---@field tool_cap_data ToolCapabilitiesDef | nil
|
||||||
|
---@field descriptions {["enchantments_desc"]: string, ["enchantments_desc_masked"]: string }
|
||||||
|