Initial commit

This commit is contained in:
Juraj Vajda 2022-11-08 10:43:16 -05:00
commit 1e4d8d0663
79 changed files with 4270 additions and 0 deletions

12
.editorconfig Normal file
View File

@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.DS_Store
docs/build
*.blend1
*.blend2
*.old
node_modules
*.log
logs

70
.luacheckrc Normal file
View File

@ -0,0 +1,70 @@
unused_args = false
allow_defined_top = true
max_line_length = false
exclude_files = {
'./scripts',
'./bin',
'./logs',
'./node_modules',
'./sounds',
'./textures',
'./models',
'./docs',
'./locale',
'./types',
}
globals = {
'XEnchanting'
}
read_globals = {
"DIR_DELIM", "INIT",
"minetest", "core",
"dump", "dump2",
"Raycast",
"Settings",
"PseudoRandom",
"PerlinNoise",
"VoxelManip",
"SecureRandom",
"VoxelArea",
"PerlinNoiseMap",
"PcgRandom",
"ItemStack",
"AreaStore",
"unpack",
"vector",
table = {
fields = {
"copy",
"indexof",
"insert_all",
"key_value_swap",
"shuffle",
}
},
string = {
fields = {
"split",
"trim",
}
},
math = {
fields = {
"hypot",
"sign",
"factorial",
"round",
}
},
"default"
}

502
LICENSE.txt Normal file
View File

@ -0,0 +1,502 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
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
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
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
fee.
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
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
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
that version instead if you wish.) Do not make any other change in
these notices.
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
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
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
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
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
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
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
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!

207
README.md Normal file
View File

@ -0,0 +1,207 @@
# Enchanting Table and API [x_enchanting]
Adds bow and arrows to Minetest. The goal of this Mod is to make most complete single bow with arrow what will work with MTG damage system, time from last punch as simple as possible. Eventually due to the damage tiers in MTG additional arrows were added.
![screenshot](screenshot.1.png)
Video: https://youtu.be/pItpltmUoa8
## Features
* bow will force you sneak when loaded (optional dep. playerphysics)
* loaded bow will slightly adjust the player FOV
* bow uses minetest tool capabilities - if the bow is not loaded for long enough (time from last puch) the arrow will fly shorter range
* charged bow in inventory will discharge and give back the arrow when not selected
* arrow uses raycast
* arrow has chance of critical shots/hits (only on full punch interval)
* arrow uses minetest damage calculation (including 3d_armor) for making damage (no hardcoded values)
* arrows stick to nodes, players and entitites
* arrows remove them self from the world after some time
* arrows remove them self if there are already too many arrows attached to node, player, entity
* arrow continues to fly downwards when attached node is dug
* arrow flies under water for short period of time and then sinks
* arrows adjusts pitch when flying
* arrows can be picked up again after stuck in solid nodes
* registers only one entity reused for all arrows
* target block reduces fall damage by -30
* quiver for more arrow storage (can hold only arrows)
* quiver perks when in inventory (faster arrows, more arrow damage...)
* quiver shows temporarily its inventory in HUD overlay when loading or shooting (quickview)
* quiver item shows its content in infotext (hover over the item)
* X Bows API for creating custom shooters and projectiles
* 3d quiver shown in 3rd person view (compatible with 3d armor)
## How To
### Bow
With the bow selected in hotbar and in your hand, press right click on mouse (PC) or the same action as when placing blocks, to load the bow.
For bow to be loaded you have to have arrows in the arrow/quiver inventory - there should be extra tab in your inventory MOD to show arrow and quiver inventory slots.
Arrows and quivers in the players main inventory don't count and will not be used.
You have to have arrows and/or quiver in dedicated arrow/quiver inventory slots in order to charge the bow.
Charging bow will have slight sound effect and can be fired at any time with left click (PC)
or the same action as when you are digging a block. Waiting for full charge of the bow is recommended
as it will give the arrow full speed (maximum shooting distance) and chance for critical arrow (double damage).
There are few indications on how to know when the bow is fully charged:
* there is a distinct "click" sound
* each arrow has "charge time" in the description
* after shooting, arrow will have particle trail
There are few indications on how to know when the arrow is a critical arrow:
* there is a distinct arrow flying sound
* after shooting, arrow will have red particle trail
If you shoot the arrow before the bow is fully charged the speed/distance will be lower and no arrow particle trail will be shown (also no chance for critical arrow).
Changing the selection in hotbar will unload the bow and give you back arrow from the unloaded bow - this applies also when login in to the game (bow will be discharged and arrow will be returned to inventory) and also when you drop the charged arrow (discharged bow will be dropped with arrow item).
If you have `playerphysics` or `player_monoids` mod installed, charged bow will slow you down until you release the arrow.
### Quiver
Quiver item can hold inventory of arrows. When player has quiver in his/hers quiver inventory slot - there should be extra tab in your inventory MOD to show arrow and quiver inventory slots, bow can take arrows from quiver, otherwise arrows outside of the quiver are used to load the bow.
Though, if arrows from quiver are used to load the bow, the arrows have additional speed and damage.
If we are loading/shooting arrows from quiver, there is temporary quickview HUD overlay shown, peeking in to the quivers inventory from which the arrow was taken. Arrows used from quiver will be faster only when the bow is fully charged - see "How To - Bow" for more information on how to know when bow is fully charged.
There are few indications on how to know when the bow shot arrow from quiver:
* there is temporary HUD overview shown peeking in to the quiver inventory
* after shooting, arrow will have blue/purple particle trail (if bow was fully charged)
## Dependencies
- none
## Optional Dependencies
- default (recipes)
- farming (bow and target recipes)
- 3d_armor (calculates damage including the armor)
- mesecons (target can be used to trigger mesecon signal)
- playerphysics (force sneak when holding charged bow)
- player_monoids (force sneak when holding charged bow)
- wool (quiver recipe)
- i3
- unified_inventory
- simple_skins
- u_skins
- wardrobe
- sfinv
- skinsdb
- player_api (shows 3d quiver)
## License:
### Code
GNU Lesser General Public License v2.1 or later (see included LICENSE file)
### Textures
**CC BY-SA 4.0, Pixel Perfection by XSSheep**, https://minecraft.curseforge.com/projects/pixel-perfection-freshly-updated
- x_bows_bow_wood.png
- x_bows_bow_wood_charged.png
- x_bows_arrow_wood.png
- x_bows_arrow_particle.png
- x_bows_bubble.png
- x_bows_target.png
Modified by SaKeL:
- x_bows_arrow_stone.png
- x_bows_arrow_bronze.png
- x_bows_arrow_steel.png
- x_bows_arrow_mese.png
- x_bows_arrow_diamond.png
**CC-BY-SA-3.0, by paramat**
- x_bows_hotbar_selected.png
- x_bows_quiver_hotbar.png
- x_bows_single_hotbar.png
**LGPL-2.1-or-later, by SaKeL**
- x_bows_quiver.png
- x_bows_quiver_open.png
- x_bows_arrow_slot.png
- x_bows_arrow_mesh.png
- x_bows_quiver_mesh.png
- x_bows_quiver_empty_mesh.png
- x_bows_quiver_blank_mesh.png
- x_bows_quiver_slot.png
- x_bows_dmg_0.png
- x_bows_dmg_1.png
- x_bows_dmg_2.png
- x_bows_dmg_3.png
- x_bows_dmg_4.png
- x_bows_dmg_5.png
- x_bows_dmg_6.png
- x_bows_dmg_7.png
- x_bows_dmg_8.png
- x_bows_dmg_9.png
### Sounds
**Creative Commons License, EminYILDIRIM**, https://freesound.org
- x_bows_bow_load.1.ogg
- x_bows_bow_load.2.ogg
- x_bows_bow_load.3.ogg
**Creative Commons License, bay_area_bob**, https://freesound.org
- x_bows_bow_loaded.ogg
**Creative Commons License**, https://freesound.org
- x_bows_bow_shoot_crit.ogg
**Creative Commons License, robinhood76**, https://freesound.org
- x_bows_arrow_hit.1.ogg
- x_bows_arrow_hit.2.ogg
- x_bows_arrow_hit.3.ogg
**Creative Commons License, brendan89**, https://freesound.org
- x_bows_bow_shoot.1.ogg
**Creative Commons License, natty23**, https://freesound.org
- x_bows_arrow_successful_hit.ogg
**Creative Commons License, Shamewap**, https://freesound.org
- x_bows_quiver.1.ogg
- x_bows_quiver.2.ogg
- x_bows_quiver.3.ogg
- x_bows_quiver.4.ogg
- x_bows_quiver.5.ogg
- x_bows_quiver.6.ogg
- x_bows_quiver.7.ogg
- x_bows_quiver.8.ogg
- x_bows_quiver.9.ogg
### Models
**LGPL-2.1-or-later, by SaKeL**
- x_bows_arrow.obj
- x_bows_arrow.blend
**Original model by MirceaKitsune (CC BY-SA 3.0).**
**Various alterations and fixes by kilbith, sofar, xunto, Rogier-5, TeTpaAka, Desour, stujones11, An0n3m0us (CC BY-SA 3.0):**
Modified by SaKeL (added quiver):
- x_bows_3d_armor_character.b3d
- x_bows_3d_armor_character.blend
- x_bows_character.b3d
- x_bows_character.blend
## Installation
see: https://wiki.minetest.net/Installing_Mods

410
api.lua Normal file
View File

@ -0,0 +1,410 @@
XEnchanting = {
-- add enchantability to default tools
tools_enchantability = {
-- picks
['default:pick_wood'] = 15,
['default:pick_stone'] = 5,
['default:pick_bronze'] = 22,
['default:pick_steel'] = 14,
['default:pick_mese'] = 15,
['default:pick_diamond'] = 10,
-- shovels
['default:shovel_wood'] = 15,
['default:shovel_stone'] = 5,
['default:shovel_bronze'] = 22,
['default:shovel_steel'] = 14,
['default:shovel_mese'] = 15,
['default:shovel_diamond'] = 10,
-- axes
['default:axe_wood'] = 15,
['default:axe_stone'] = 5,
['default:axe_bronze'] = 22,
['default:axe_steel'] = 14,
['default:axe_mese'] = 15,
['default:axe_diamond'] = 10,
-- swords
['default:sword_wood'] = 15,
['default:sword_stone'] = 5,
['default:sword_bronze'] = 22,
['default:sword_steel'] = 14,
['default:sword_mese'] = 15,
['default:sword_diamond'] = 10,
-- hoes
['farming:hoe_wood'] = 15,
['farming:hoe_stone'] = 5,
['farming:hoe_steel'] = 14,
['farming:hoe_bronze'] = 22,
['farming:hoe_mese'] = 15,
['farming:hoe_diamond'] = 10,
},
roman_numbers = {
[1] = 'I',
[2] = 'II',
[3] = 'III',
[4] = 'IV',
[5] = 'V',
},
enchantment_defs = {
-- Living things like animals and the player. This could imply
-- some blood effects when hitting
sharpness = {
name = 'Sharpness',
-- what level should be taken, `level = min/max values`
final_level_range = {
[1] = { 1, 21 },
[2] = { 12, 32 },
[3] = { 23, 43 },
[4] = { 34, 54 },
[5] = { 45, 65 },
},
-- level definition, `level = added value`
level_def = {
[1] = 1.25,
[2] = 2.5,
[3] = 3.75,
[4] = 5,
[5] = 6.25,
},
weight = 10
},
fortune = {
name = 'Fortune',
-- 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
},
unbreaking = {
name = 'Unbreaking',
-- what level should be taken, `level = min/max values`
final_level_range = {
[1] = { 5, 55 },
[2] = { 13, 63 },
[3] = { 21, 71 }
},
-- level definition, `level = percentage increase`
level_def = {
[1] = 100,
[2] = 200,
[3] = 300
},
weight = 5
},
efficiency = {
name = 'Efficiency',
-- what level should be taken, `level = min/max values`
final_level_range = {
[1] = { 1, 51 },
[2] = { 11, 61 },
[3] = { 21, 71 },
[4] = { 31, 81 },
[5] = { 41, 91 },
},
-- level definition, `level = percentage increase`
level_def = {
[1] = 25,
[2] = 30,
[3] = 35,
[4] = 40,
[5] = 45,
},
weight = 10
}
}
}
---Merge two tables with key/value pair
---@param t1 table
---@param t2 table
---@return table
local function mergeTables(t1, t2)
for k, v in pairs(t2) do t1[k] = v end
return t1
end
function XEnchanting.has_tool_group(self, name)
if minetest.get_item_group(name, 'pickaxe') > 0 then
return 'pickaxe'
elseif minetest.get_item_group(name, 'shovel') > 0 then
return 'shovel'
elseif minetest.get_item_group(name, 'axe') > 0 then
return 'axe'
elseif minetest.get_item_group(name, 'sword') > 0 then
return 'sword'
end
return false
end
function XEnchanting.set_tool_enchantability(self, tool_def)
local _enchantability = 1
if minetest.get_item_group(tool_def.name, 'enchantability') > 0 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]
end
minetest.override_item(tool_def.name, {
groups = mergeTables(tool_def.groups, { enchantability = _enchantability })
})
end
function XEnchanting.get_enchanted_tool_capabilities(self, tool_def, enchantments)
local tool_stack = ItemStack({ name = tool_def.name })
local tool_capabilities = tool_stack:get_tool_capabilities()
local enchantments_desc = {}
-- print('tool_capabilities #1', dump(tool_capabilities))
for i, enchantment in ipairs(enchantments) do
-- Efficiency
if enchantment.id == 'efficiency' then
if tool_capabilities.groupcaps then
-- groupcaps
for group_name, def in pairs(tool_capabilities.groupcaps) do
-- times
if def.times then
local old_times = def.times
local new_times = {}
for lvl, old_time in ipairs(old_times) do
local new_time = old_time - (old_time * (enchantment.value / 100))
if new_time < 0.15 then
new_time = 0.15
end
table.insert(new_times, lvl, new_time)
end
tool_capabilities.groupcaps[group_name].times = new_times
end
-- maxlevel
if def.maxlevel and def.maxlevel < enchantment.level then
tool_capabilities.groupcaps[group_name].maxlevel = enchantment.level
end
end
end
if tool_capabilities.full_punch_interval then
-- full_punch_interval
local old_fpi = tool_capabilities.full_punch_interval
local new_fpi = old_fpi - (old_fpi * (enchantment.value / 100))
if new_fpi < 0.15 then
new_fpi = 0.15
end
tool_capabilities.full_punch_interval = new_fpi
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]
end
end
-- Unbreaking
if enchantment.id == 'unbreaking' then
if tool_capabilities.groupcaps then
-- groupcaps
for group_name, def in pairs(tool_capabilities.groupcaps) do
-- uses
if def.uses then
local old_uses = def.uses
local new_uses = old_uses + (old_uses * (enchantment.value / 100))
tool_capabilities.groupcaps[group_name].uses = new_uses
end
end
end
if tool_capabilities.punch_attack_uses then
-- punch_attack_uses
local old_uses = tool_capabilities.punch_attack_uses
local new_uses = old_uses + (old_uses * (enchantment.value / 100))
tool_capabilities.punch_attack_uses = new_uses
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]
end
end
-- Sharpness
if enchantment.id == 'sharpness' and tool_capabilities.damage_groups then
for group_name, val in pairs(tool_capabilities.damage_groups) do
local old_damage = val
local new_damage = old_damage + enchantment.value
tool_capabilities.damage_groups[group_name] = new_damage
end
enchantments_desc[#enchantments_desc + 1] = self.enchantment_defs[enchantment.id].name
.. ' '
.. self.roman_numbers[enchantment.level]
end
-- Fortune
if enchantment.id == 'fortune' and tool_capabilities.max_drop_level then
local old_max_drop_level = tool_capabilities.max_drop_level
local new_max_drop_level = old_max_drop_level + enchantment.value
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]
end
end
enchantments_desc = minetest.colorize('#C70039', '\nEnchanted\n') .. table.concat(enchantments_desc, '\n')
-- print('tool_capabilities #2', dump(tool_capabilities))
-- print('enchantments_desc', enchantments_desc)
-- return {
-- tool_capabilities = tool_capabilities,
-- enchantments_desc = enchantments_desc
-- }
end
function XEnchanting.set_enchanted_tool_capabilities(self, itemstack, capabilities, description)
-- local tool_def = minetest.registered_tools[itemstack:get_name()]
-- minetest.override_item(tool_def.name, {
-- groups = mergeTables(tool_def.groups, { enchantability = 0 }),
-- tool_capabilities = tool_capabilities
-- })
end
function XEnchanting.get_base_enchantment_level(self, nr_of_bookshelfs, tool_def)
local _nr_of_bookshelfs = nr_of_bookshelfs
if _nr_of_bookshelfs > 15 then
_nr_of_bookshelfs = 15
end
----
-- 0 Show slots in formspec
----
-- Base enchantment
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 middle_slot_base_level = math.floor((base * 2) / 3 + 1)
local bottom_slot_base_level = math.floor(math.max(base, _nr_of_bookshelfs * 2))
-- print('top_slot_base_level', top_slot_base_level)
-- print('middle_slot_base_level', middle_slot_base_level)
-- print('bottom_slot_base_level', bottom_slot_base_level)
----
-- 1 Applying modifiers to the enchantment level
----
-- Just for testing, this has to come from formspec
local chosen_enchantment_level = 30
-- Applying modifiers to the enchantment level
local enchantability = minetest.get_item_group(tool_def.name, 'enchantability')
-- Generate a random number between 1 and 1+(enchantability/2), with a triangular distribution
-- print('-------------------')
-- print('enchantability', enchantability)
local rand_enchantability = 1 + math.random(enchantability / 4 + 1) + math.random(enchantability / 4 + 1)
-- print('rand_enchantability', rand_enchantability)
-- Choose the enchantment level
local k = chosen_enchantment_level + rand_enchantability
-- print('k', k)
-- A random bonus, between .85 and 1.15
local rand_bonus_percent = 1 + ((math.random(0, 99) / 100) + (math.random(0, 99) / 100) - 1) * 0.15
-- print('rand_bonus_percent', rand_bonus_percent)
-- Finally, we calculate the level
local final_level = math.round(k * rand_bonus_percent)
if final_level < 1 then
final_level = 1
end
-- print('final_level', final_level)
----
-- 2 Find possible enchantments
----
local possible_enchantments = {}
-- Get level
-- If the modified level is within two overlapping ranges for the same
-- enchantment type, the higher power value is used.
for enchantment_name, enchantment_def in pairs(self.enchantment_defs) do
local levels = {}
for level, final_level_range in ipairs(enchantment_def.final_level_range) do
local min = final_level_range[1]
local max = final_level_range[2]
if final_level >= min and final_level <= max then
table.insert(levels, level)
end
end
local level = levels[#levels]
-- print('levels', enchantment_name, dump(levels))
-- print('level', enchantment_name, level)
table.insert(possible_enchantments, {
id = enchantment_name,
value = enchantment_def.level_def[level],
level = level
})
end
-- print('possible_enchantments', dump(possible_enchantments))
----
-- 3 Select a set of enchantments from the list
----
local final_enchantments = {}
local total_weight = 0
-- calculate total weight
for i, enchantment in ipairs(possible_enchantments) do
total_weight = total_weight + self.enchantment_defs[enchantment.id].weight
end
local rand_weight = math.random(0, total_weight / 2)
-- print('total_weight', total_weight)
-- print('rand_weight', rand_weight)
-- select final enchantments
for i = 1, #possible_enchantments, 1 do
local rand_ench_idx = math.random(1, #possible_enchantments)
local rand_ench = possible_enchantments[rand_ench_idx]
table.remove(possible_enchantments, rand_ench_idx)
rand_weight = rand_weight - self.enchantment_defs[rand_ench.id].weight
table.insert(final_enchantments, rand_ench)
if rand_weight < 0 then
break
end
end
-- print('final_enchantments', dump(final_enchantments))
self:get_enchanted_tool_capabilities(tool_def, final_enchantments)
end

22
init.lua Normal file
View File

@ -0,0 +1,22 @@
-- X Enchanting
-- by SaKeL
local path = minetest.get_modpath('x_enchanting')
local mod_start_time = minetest.get_us_time()
dofile(path .. '/api.lua')
dofile(path .. '/table.lua')
minetest.register_on_mods_loaded(function()
for name, tool_def in pairs(minetest.registered_tools) do
if XEnchanting:has_tool_group(name) then
XEnchanting:set_tool_enchantability(tool_def)
-- print(name, dump(minetest.registered_tools[name]._x_enchanting))
-- print(name, dump(minetest.registered_tools[name].groups))
end
end
end)
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
print('[Mod] x_enchanting loaded.. [' .. mod_end_time .. 's]')

6
mod.conf Normal file
View File

@ -0,0 +1,6 @@
name = x_enchanting
description = Adds Enchanting Table and API.
depends =
optional_depends =
supported_games = minetest_game
min_minetest_version = 5.4

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

406
table.lua Normal file
View File

@ -0,0 +1,406 @@
screwdriver = minetest.global_exists('screwdriver') and screwdriver --[[@as MtgScrewdriver]]
local scroll_animations = {
scroll_open = { { x = 1, y = 40 }, 80, 0, false },
scroll_close = { { x = 45, y = 84 }, 80, 0, false },
scroll_open_idle = { { x = 41, y = 42 }, 0, 0, false },
scroll_closed_idle = { { x = 43, y = 43 }, 0, 0, false }
}
local function get_formspec(pos)
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
local formspec =
'size[8,9]' ..
'label[0, 0;Enchant]' ..
---@diagnostic disable-next-line: codestyle-check
'model[0,0;2,3;x_enchanting_table;x_enchanting_scroll.b3d;x_enchanting_scroll_mesh.png,x_enchanting_scroll_handles_mesh.png,x_enchanting_scroll_mesh.png;89,0;false;false;' .. scroll_animations.scroll_open_idle[1].x .. ',' .. scroll_animations.scroll_open_idle[1].y .. ';0]' ..
'list[nodemeta:' .. spos .. ';item;0, 2.5;1, 1;]' ..
'image[1,2.5;1,1;x_enchanting_trade_slot.png;]' ..
'list[nodemeta:' .. spos .. ';trade;1, 2.5;1, 1;]' ..
'list[current_player;main;0, 4.85;8, 1;]' ..
'list[current_player;main;0, 6.08;8, 3;8]' ..
'listring[nodemeta:' .. spos .. ';item]' ..
'listring[nodemeta:' .. spos .. ';trade]' ..
'listring[current_player;main]' ..
default.get_hotbar_bg(0, 4.85)
return formspec
end
---Table Node
minetest.register_node('x_enchanting:table', {
description = 'Enchating Table',
short_description = 'Enchating Table',
drawtype = 'mesh',
mesh = 'x_enchanting_table.obj',
tiles = { 'x_enchanting_table.png' },
paramtype = 'light',
paramtype2 = 'facedir',
walkable = true,
wield_scale = { x = 2, y = 2, z = 2 },
selection_box = {
type = 'fixed',
fixed = { -1 / 2, -1 / 2, -1 / 2, 1 / 2, 1 / 2 - 4 / 16, 1 / 2 }
},
collision_box = {
type = 'fixed',
fixed = { -1 / 2, -1 / 2, -1 / 2, 1 / 2, 1 / 2 - 4 / 16, 1 / 2 }
},
sounds = {
footstep = {
name = 'x_enchanting_table_hard_footstep',
gain = 0.2
},
dug = {
name = 'x_enchanting_table_hard_footstep',
gain = 1.0
},
place = {
name = 'x_enchanting_table_place_node_hard',
gain = 1.0
}
},
is_ground_content = false,
groups = { cracky = 1, level = 2 },
stack_max = 1,
mod_origin = 'x_enchanting',
light_source = 6,
---@param pos Vector
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string('infotext', 'Enchating Table')
meta:set_string('owner', '')
inv:set_size('item', 1)
inv:set_size('trade', 1)
minetest.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
minetest.get_node_timer(pos):start(5)
end,
---@param pos Vector
---@param placer ObjectRef | nil
---@param itemstack ItemStack
---@param pointed_thing PointedThingDef
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
if not placer then
return
end
local player_name = placer:get_player_name()
meta:set_string('owner', player_name)
meta:set_string('infotext', 'Enchating Table (owned by ' .. player_name .. ')')
end,
---@param pos Vector
---@param node NodeDef
---@param clicker ObjectRef
---@param itemstack ItemStack
---@param pointed_thing? PointedThingDef
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local p_name = clicker:get_player_name()
if minetest.is_protected(pos, p_name) then
return itemstack
end
minetest.sound_play('default_dig_choppy', {
gain = 0.3,
pos = pos,
max_hear_distance = 10
}, true)
local formspec = get_formspec(pos)
minetest.show_formspec(clicker:get_player_name(), 'x_enchanting:table', formspec)
end,
---@param pos Vector
---@param intensity? number
---@return table | nil
on_blast = function(pos, intensity)
if minetest.is_protected(pos, '') then
return
end
local drops = {}
local inv = minetest.get_meta(pos):get_inventory()
local stack_item = inv:get_stack('item', 1)
local stack_trade = inv:get_stack('trade', 1)
if not stack_item:is_empty() then
drops[#drops + 1] = stack_item:to_table()
end
if not stack_trade:is_empty() then
drops[#drops + 1] = stack_trade:to_table()
end
drops[#drops + 1] = 'x_enchanting:table'
minetest.remove_node(pos)
return drops
end,
---@param pos Vector
---@param player? ObjectRef
can_dig = function(pos, player)
if not player then
return false
end
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty('item')
and inv:is_empty('trade')
and not minetest.is_protected(pos, player:get_player_name())
end,
on_rotate = function(pos, node, user, mode, new_param2)
return false
end,
---@param pos Vector
---@param elapsed number
on_timer = function(pos, elapsed)
-- entity
local table_scroll = minetest.get_objects_inside_radius(pos, 0.9)
if #table_scroll == 0 then
minetest.add_entity({ x = pos.x, y = pos.y + 0.7, z = pos.z }, 'x_enchanting:table_scroll')
end
local particlespawner_def = {
amount = 30,
time = 5,
minpos = { x = pos.x - 0.1, y = pos.y + 0.2, z = pos.z - 0.1 },
maxpos = { x = pos.x + 0.1, y = pos.y + 0.3, z = pos.z + 0.1 },
minvel = { x = -0.1, y = 0.1, z = -0.1 },
maxvel = { x = 0.1, y = 0.2, z = 0.1 },
minacc = { x = -0.1, y = 0.1, z = -0.1 },
maxacc = { x = 0.1, y = 0.2, z = 0.1 },
minexptime = 1.5,
maxexptime = 2.5,
minsize = 0.1,
maxsize = 0.3,
texture = 'x_enchanting_scroll_particle.png',
glow = 1
}
if minetest.has_feature({ dynamic_add_media_table = true, particlespawner_tweenable = true }) then
-- new syntax, after v5.6.0
particlespawner_def = {
amount = 30,
time = 5,
size = {
min = 0.1,
max = 0.3,
},
exptime = 2,
pos = {
min = vector.new({ x = pos.x - 0.5, y = pos.y, z = pos.z - 0.5 }),
max = vector.new({ x = pos.x + 0.5, y = pos.y, z = pos.z + 0.5 }),
},
attract = {
kind = 'point',
strength = 0.5,
origin = vector.new({ x = pos.x, y = pos.y + 0.65, z = pos.z })
},
texture = {
name = 'x_enchanting_scroll_particle.png',
alpha_tween = {
0, 1,
style = 'fwd',
reps = 1
}
},
glow = 1
}
end
minetest.add_particlespawner(particlespawner_def)
---bookshelfs
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 + 2, z = pos.z + 2 },
{ 'default:bookshelf' }
)
if #bookshelfs == 0 then
return true
end
-- just for testing
XEnchanting:get_base_enchantment_level(#bookshelfs, minetest.registered_tools['default:pick_mese'])
-- symbol particles
for i = 1, 10, 1 do
local pos_random = bookshelfs[math.random(1, #bookshelfs)]
local x = pos.x - pos_random.x
local y = pos_random.y - pos.y
local z = pos.z - pos_random.z
local rand1 = (math.random(150, 250) / 100) * -1
local rand2 = math.random(10, 500) / 100
local rand3 = math.random(50, 200) / 100
minetest.after(rand2, function()
minetest.add_particle({
pos = pos_random,
velocity = { x = x, y = 2 - y, z = z },
acceleration = { x = 0, y = rand1, z = 0 },
expirationtime = 1,
size = rand3,
texture = 'x_enchanting_symbol_' .. math.random(1, 26) .. '.png',
glow = 6
})
end)
end
return true
end,
---@param pos Vector
on_destruct = function(pos)
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 0.9)) do
if obj
and obj:get_luaentity()
and obj:get_luaentity().name == 'x_enchanting:table_scroll'
then
obj:remove()
break
end
end
end,
-- on_receive_fields = enchanting.fields,
-- on_metadata_inventory_put = enchanting.on_put,
-- on_metadata_inventory_take = enchanting.on_take,
-- allow_metadata_inventory_put = enchanting.put,
-- allow_metadata_inventory_take = enchanting.take,
-- allow_metadata_inventory_move = function() return 0 end,
})
---Scroll Entity
minetest.register_entity('x_enchanting:table_scroll', {
initial_properties = {
visual = 'mesh',
mesh = 'x_enchanting_scroll.b3d',
textures = {
--- back
'x_enchanting_scroll_mesh.png',
-- handles
'x_enchanting_scroll_handles_mesh.png',
--- front
'x_enchanting_scroll_mesh.png',
},
collisionbox = { 0, 0, 0, 0, 0, 0 },
selectionbox = { 0, 0, 0, 0, 0, 0 },
physical = false,
hp_max = 1,
visual_size = { x = 1, y = 1, z = 1 },
glow = 1,
pointable = false,
infotext = 'Scroll of Enchantments',
},
---@param self table
---@param killer ObjectRef
on_death = function(self, killer)
self.object:remove()
end,
---@param self table
---@param staticdata StringAbstract
---@param dtime_s number
on_activate = function(self, staticdata, dtime_s)
self._scroll_closed = true
self._tablechecktimer = 5
self._playerchecktimer = 1
self._bouncetimer = 3
self._player = nil
self._last_rotation = nil
self._bounce_up = false
self._bounce_init = false
self.object:set_armor_groups({ immortal = 1 })
self.object:set_animation({ x = 0, y = 0 }, 0, 0, false)
end,
---@param self table
---@param dtime number
---@param moveresult? table
on_step = function(self, dtime, moveresult)
local pos = self.object:get_pos()
self._last_rotation = self.object:get_rotation()
self._tablechecktimer = self._tablechecktimer - dtime
self._playerchecktimer = self._playerchecktimer - dtime
self._bouncetimer = self._bouncetimer - dtime
-- table
if self._tablechecktimer <= 0 then
self._tablechecktimer = 5
local node = minetest.get_node({ x = pos.x, y = pos.y - 0.7, z = pos.z })
if node.name ~= 'x_enchanting:table' then
-- remove entity when no table under it
self.object:remove()
end
end
-- player
if self._playerchecktimer <= 0 then
self._playerchecktimer = 1
local objects = minetest.get_objects_inside_radius(pos, 5)
-- inital value
local shortest_distance = 10
local found_player = false
if #objects > 0 then
for i, obj in ipairs(objects) do
if obj:is_player() and obj:get_pos() then
-- player
found_player = true
local distance = vector.distance(pos, obj:get_pos())
if distance < shortest_distance then
self._player = obj
end
end
end
else
self._player = nil
end
if not found_player then
self._player = nil
end
-- scroll open/close animation
if self._player and self._scroll_closed then
self._scroll_closed = false
self.object:set_animation(unpack(scroll_animations.scroll_open))
elseif not self._player and not self._scroll_closed then
self._scroll_closed = true
self.object:set_animation(unpack(scroll_animations.scroll_close))
end
end
-- rotation
if self._player and self._player:get_pos() then
local direction = vector.direction(pos, self._player:get_pos())
self.object:set_yaw(minetest.dir_to_yaw(direction))
else
self.object:set_rotation({
x = self._last_rotation.x,
y = self._last_rotation.y + (math.pi / -50),
z = self._last_rotation.z
})
end
end,
---@param self table
---@param puncher ObjectRef
---@param time_from_last_punch number | nil
---@param tool_capabilities ToolCapabilitiesDef | nil
---@param dir Vector
---@param damage number
---@return boolean | nil
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
return true
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

12
types/colors.type.lua Normal file
View File

@ -0,0 +1,12 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---@alias ColorSpec string|ColorSpecTable A ColorSpec specifies a 32-bit color. It can be written in any of the following forms: `colorspec = {a=255, r=0, g=255, b=0}`, numerical form: The raw integer value of an ARGB8 quad: `colorspec = 0xFF00FF00`, string form: A ColorString (defined above): `colorspec = "green"`
---@alias ColorString string `#RGB` defines a color in hexadecimal format. `#RGBA` defines a color in hexadecimal format and alpha channel. `#RRGGBB` defines a color in hexadecimal format. `#RRGGBBAA` defines a color in hexadecimal format and alpha channel. Named colors are also supported and are equivalent to [CSS Color Module Level 4](https://www.w3.org/TR/css-color-4/#named-color). To specify the value of the alpha channel, append `#A` or `#AA` to the end of the color name (e.g. `colorname#08`).
---A ColorSpec table form: Each element ranging from 0..255 (a, if absent, defaults to 255):
---@class ColorSpecTable
---@field a number
---@field r number
---@field g number
---@field b number

View File

@ -0,0 +1,12 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Crafting recipes
---@class CraftRecipeDef
---@field type string (optional) specifies recipe type as shaped, e.g. "shaped", "shapeless", "toolrepair", "cooking", "fuel", default: "shaped"
---@field output string Itemstring of output itemstack (item counts >= 1 are allowed)
---@field recipe table<integer|number, string>[]|string A 2-dimensional matrix of items, with a width *w* and height *h*. *w* and *h* are chosen by you, they don't have to be equal but must be at least 1. The matrix is specified as a table containing tables containing itemnames. The inner tables are the rows. There must be *h* tables, specified from the top to the bottom row. Values inside of the inner table are the columns. Each inner table must contain a list of *w* items, specified from left to right. Empty slots *must* be filled with the empty string.
---@field replacements string[] (optional) Allows you to replace input items with some other items when something is crafted. Provided as a list of item pairs of the form `{ old_item, new_item }` where `old_item` is the input item to replace (same syntax as for a regular input slot; groups are allowed) and `new_item` is an itemstring for the item stack it will become. When the output is crafted, Minetest iterates through the list of input items if the crafting grid. For each input item stack, it checks if it matches with an `old_item` in the item pair list. If it matches, the item will be replaced. Also, this item pair will *not* be applied again for the remaining items. If it does not match, the item is consumed (reduced by 1) normally. The `new_item` will appear in one of 3 places: Crafting grid, if the input stack size was exactly 1, Player inventory, if input stack size was larger, Drops as item entity, if it fits neither in craft grid or inventory.
---@field additional_wear number|integer For `{type = "toolrepair"}` only. Adds a shapeless recipe for *every* tool that doesn't have the `disable_repair=1` group. If this recipe is used, repairing is possible with any crafting grid with at least 2 slots. The player can put 2 equal tools in the craft grid to get one "repaired" tool back. The wear of the output is determined by the wear of both tools, plus a 'repair bonus' given by `additional_wear`. To reduce the wear (i.e. 'repair'), you want `additional_wear` to be negative. The formula used to calculate the resulting wear is: 65536 * (1 - ( (1 - tool_1_wear) + (1 - tool_2_wear) + additional_wear )) The result is rounded and can't be lower than 0. If the result is 65536 or higher, no crafting is possible.
---@field cooktime number|integer For `{type = "cooking"}` only. (optional) Time it takes to cook this item, in seconds. A floating-point number. (default: 3.0)
---@field burntime number|integer For `{type = "fuel"}` only. (optional) Burning time this item provides, in seconds. A floating-point number. (default: 1.0)

View File

@ -0,0 +1,9 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---The varying types of decorations that can be placed.
---@class DecorationDef
---@field deco_type 'simple'|'schematic' `simple`: Creates a 1 times `H` times 1 column of a specified node (or a random node from a list, if a decoration list is specified). Can specify a certain node it must spawn next to, such as water or lava, for example. Can also generate a decoration of random height between a specified lower and upper bound. This type of decoration is intended for placement of grass, flowers, cacti, papyri, waterlilies and so on. `schematic`: Copies a box of `MapNodes` from a specified schematic file (or raw description). Can specify a probability of a node randomly appearing when placed. This decoration type is intended to be used for multi-node sized discrete structures, such as trees, cave spikes, rocks, and so on.
---@field biomes any List of biomes in which this decoration occurs. Occurs in all biomes if this is omitted, and ignored if the Mapgen being used does not support biomes. Can be a list of (or a single) biome names, IDs, or definitions.
---@field decoration string| string[] The node name used as the decoration. If instead a list of strings, a randomly selected node from the list is placed as the decoration.
---@field place_on string| string[] Node (or list of nodes) that the decoration can be placed on

16
types/entity.type.lua Normal file
View File

@ -0,0 +1,16 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Entity definition
---@class EntityDef
---@field initial_properties ObjectProperties A table of object properties. The properties in this table are applied to the object once when it is spawned. `dtime_s` is the time passed since the object was unloaded, which can be used for updating the entity state.
---@field on_activate fun(self: table, staticdata: string, dtime_s: integer|number): nil Function receive a "luaentity" table as `self`. Called when the object is instantiated.
---@field on_deactivate fun(self: table, removal: boolean): nil Function receive a "luaentity" table as `self`. Called when the object is about to get removed or unloaded. `removal`: boolean indicating whether the object is about to get removed. Calling `object:remove()` on an active object will call this with `removal=true`. The mapblock the entity resides in being unloaded will call this with `removal=false`. Note that this won't be called if the object hasn't been activated in the first place. In particular, `minetest.clear_objects({mode = "full"})` won't call this, whereas `minetest.clear_objects({mode = "quick"})` might call this.
---@field on_step fun(self: table, dtime: integer|number, moveresult?: table): nil Function receive a "luaentity" table as `self`. Called on every server tick, after movement and collision processing. `dtime`: elapsed time since last call. `moveresult`: table with collision info (only available if physical=true).
---@field on_punch fun(self: table, puncher: ObjectRef|nil, time_from_last_punch: number|integer|nil, tool_capabilities: ToolCapabilitiesDef|nil, dir: Vector, damage: number|integer): boolean|nil Function receive a "luaentity" table as `self`. Called when somebody punches the object. Note that you probably want to handle most punches using the automatic armor group system. Can return `true` to prevent the default damage mechanism.
---@field on_death fun(self: table, killer: ObjectRef|nil): nil Function receive a "luaentity" table as `self`. Called when the object dies.
---@field on_rightclick fun(self: table, clicker: ObjectRef): nil Function receive a "luaentity" table as `self`. Called when `clicker` pressed the 'place/use' key while pointing to the object (not neccessarily an actual rightclick). `clicker`: an `ObjectRef` (may or may not be a player)
---@field on_attach_child fun(self: table, child: ObjectRef): nil Function receive a "luaentity" table as `self`. `child`: an `ObjectRef` of the child that attaches
---@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 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.

4
types/generic.type.lua Normal file
View File

@ -0,0 +1,4 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---@alias Dump fun(obj: any, dumped?: any): string returns a string which makes `obj` human-readable, `obj`: arbitrary variable, `dumped`: table, default: `{}`

21
types/inventory.type.lua Normal file
View File

@ -0,0 +1,21 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
--An `InvRef` is a reference to an inventory.
---@class InvRef
---@field add_item fun(self: InvRef, listname: string, stack: string|ItemStack): ItemStack Add item somewhere in list, returns leftover `ItemStack`.
---@field contains_item fun(self: InvRef, listname: string, stack: string|ItemStack, match_meta?: boolean): boolean Returns `true` if the stack of items can be fully taken from the list. If `match_meta` is false, only the items' names are compared, default: `false`
---@field get_list fun(self: InvRef, listname: string): ItemStack[] Return full list, list of `ItemStack`s
---@field room_for_item fun(self: InvRef, listname: string, stack: string|ItemStack): boolean Returns `true` if the stack of items can be fully added to the list
---@field set_stack fun(self: InvRef, listname: string, i: integer, stack: string|ItemStack): nil Copy `stack` to index `i` in list
---@field is_empty fun(self: InvRef, listname: string): boolean Return `true` if list is empty
---@field get_size fun(self: InvRef, listname: string): integer Get size of a list
---@field set_size fun(self: InvRef, listname: string, size: integer): boolean Set size of a list, returns `false` on error, e.g. invalid `listname` or `size`
---@field get_width fun(self: InvRef, listname: string): boolean Get width of a list
---@field set_width fun(self: InvRef, listname: string, width: integer): nil Set width of list; currently used for crafting
---@field get_stack fun(self: InvRef, listname: string, i: integer): ItemStack Get a copy of stack index `i` in list
---@field set_list fun(self: InvRef, listname: string, list: ItemStack[]): nil Set full list, size will not change
---@field get_lists fun(): table Returns table that maps listnames to inventory lists
---@field set_lists fun(self: InvRef, lists: table): nil Sets inventory lists, size will not change
---@field remove_item fun(self: InvRef, listname: string, stack: string|ItemStack): nil Take as many items as specified from the list, returns the items that were actually removed, as an `ItemStack`, note that any item metadata is ignored, so attempting to remove a specific unique item this way will likely remove the wrong one, to do that use `set_stack` with an empty `ItemStack`.
---@field get_location fun(self: InvRef): {['type']: 'player'|'node'|'detached'|'undefined', ['name']: string|nil, ['pos']: Vector|nil} returns a location compatible to `minetest.get_inventory(location)`. returns `{type="undefined"}` in case location is not known

55
types/item.type.lua Normal file
View File

@ -0,0 +1,55 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest item definition. Used by `minetest.register_node`, `minetest.register_craftitem`, and `minetest.register_tool`.
---Add your own custom fields. By convention, all custom field names. Should start with `_` to avoid naming collisions with future engine usage.
---@class ItemDef
---@field description string Can contain new lines. "\n" has to be used as new line character.
---@field short_description string|nil Must not contain new lines. Defaults to nil.
---@field groups table<string, string|number|integer|boolean> key = name, value = rating; rating = <number>. If rating not applicable, use 1. e.g. `{wool = 1, fluffy = 3}` `{soil = 2, outerspace = 1, crumbly = 1}` `{bendy = 2, snappy = 1}` {hard = 1, metal = 1, spikes = 1}
---@field inventory_image string Texture shown in the inventory GUI. Defaults to a 3D rendering of the node if left empty.
---@field inventory_overlay string An overlay texture which is not affected by colorization
---@field wield_image string Texture shown when item is held in hand. Defaults to a 3D rendering of the node if left empty.
---@field wield_overlay string Like inventory_overlay but only used in the same situation as wield_image
---@field wield_scale table<string, number|integer> Scale for the item when held in hand
---@field palette string An image file containing the palette of a node. You can set the currently used color as the "palette_index" field of the item stack metadata. The palette is always stretched to fit indices between 0 and 255, to ensure compatibility with "colorfacedir" (and similar) nodes.
---@field color string Color the item is colorized with. The palette overrides this.
---@field stack_max integer|number Maximum amount of items that can be in a single stack.
---@field range integer|number Range of node and object pointing that is possible with this item held.
---@field liquids_pointable boolean If true, item can point to all liquid nodes (`liquidtype ~= "none"`), even those for which `pointable = false`
---@field light_source integer|number When used for nodes: Defines amount of light emitted by node. Otherwise: Defines texture glow when viewed as a dropped item. To set the maximum (14), use the value 'minetest.LIGHT_MAX'. A value outside the range 0 to minetest.LIGHT_MAX causes undefined behavior.
---@field tool_capabilities ToolCapabilitiesDef
---@field node_placement_prediction string|nil If nil and item is node, prediction is made automatically. If nil and item is not a node, no prediction is made. If "" and item is anything, no prediction is made. Otherwise should be name of node which the client immediately places on ground when the player places the item. Server will always update with actual result shortly.
---@field node_dig_prediction string if "", no prediction is made. if "air", node is removed. Otherwise should be name of node which the client immediately places upon digging. Server will always update with actual result shortly.
---@field sound ItemSoundDef
---@field on_place fun(itemstack: ItemStack, placer: ObjectRef|nil, pointed_thing: PointedThingDef): ItemStack|nil When the 'place' key was pressed with the item in hand and a node was pointed at. Shall place item and return the leftover itemstack or nil to not modify the inventory. The placer may be any ObjectRef or nil. default: minetest.item_place
---@field on_secondary_use fun(itemstack: ItemStack, user: ObjectRef|nil, pointed_thing: PointedThingDef): ItemStack|nil Same as on_place but called when not pointing at a node. Function must return either nil if inventory shall not be modified, or an itemstack to replace the original itemstack. The user may be any ObjectRef or nil. default: nil
---@field on_drop fun(itemstack: ItemStack, dropper: ObjectRef|nil, pos: Vector): ItemStack|nil Shall drop item and return the leftover itemstack. The dropper may be any ObjectRef or nil. default: minetest.item_drop
---@field on_pickup fun(itemstack: ItemStack, picker: ObjectRef|nil, pointed_thing?: PointedThingDef, time_from_last_punch?: number|integer, rest?: any): ItemStack|nil Called when a dropped item is punched by a player. Shall pick-up the item and return the leftover itemstack or nil to not modify the dropped item. `rest` are other parameters from `luaentity:on_punch`. default: `minetest.item_pickup`
---@field on_use fun(itemstack: ItemStack, user: ObjectRef|nil, pointed_thing: PointedThingDef): ItemStack|nil default: nil. When user pressed the 'punch/mine' key with the item in hand. Function must return either nil if inventory shall not be modified, or an itemstack to replace the original itemstack. e.g. itemstack:take_item(); return itemstack. Otherwise, the function is free to do what it wants. The user may be any ObjectRef or nil. The default functions handle regular use cases.
---@field after_use fun(itemstack: ItemStack, user: ObjectRef|nil, node: NodeDef, digparams: DigParamsDef): ItemStack|nil default: nil. If defined, should return an itemstack and will be called instead of wearing out the item (if tool). If returns nil, does nothing.
---@field soil table Only for farming
---Tool capabilities definition
---@class ToolCapabilitiesDef
---@field full_punch_interval number|integer
---@field max_drop_level number|integer
---@field groupcaps GroupCapsDef
---@field damage_groups table<string, number|integer> Damage values must be between -32768 and 32767 (2^15)
---@field punch_attack_uses number|integer|nil Amount of uses this tool has for attacking players and entities by punching them (0 = infinite uses). For compatibility, this is automatically set from the first suitable groupcap using the forumla "uses * 3^(maxlevel - 1)". It is recommend to set this explicitly instead of relying on the fallback behavior.
---Known damage and digging time defining groups
---@class GroupCapsDef
---@field crumbly number|GroupCapsItemDef dirt, sand
---@field cracky number|GroupCapsItemDef tough but crackable stuff like stone.
---@field snappy number|GroupCapsItemDef something that can be cut using things like scissors, shears, bolt cutters and the like, e.g. leaves, small plants, wire, sheets of metal
---@field choppy number|GroupCapsItemDef something that can be cut using force; e.g. trees, wooden planks
---@field fleshy number|GroupCapsItemDef Living things like animals and the player. This could imply some blood effects when hitting.
---@field explody number|GroupCapsItemDef Especially prone to explosions
---@field oddly_breakable_by_hand number|GroupCapsItemDef Can be added to nodes that shouldn't logically be breakable by the hand but are. Somewhat similar to `dig_immediate`, but times are more like `{[1]=3.50,[2]=2.00,[3]=0.70}` and this does not override the digging speed of an item if it can dig at a faster speed than this suggests for the hand.
---Known damage and digging time defining groups
---@class GroupCapsItemDef
---@field maxlevel number|integer Tells what is the maximum level of a node of this group that the item will be able to dig.
---@field uses number|integer Tools only. Determines how many uses the tool has when it is used for digging a node, of this group, of the maximum level. The maximum supported number of uses is 65535. The special number 0 is used for infinite uses. For lower leveled nodes, the use count is multiplied by `3^leveldiff`. `leveldiff` is the difference of the tool's `maxlevel` `groupcaps` and the node's `level` group. The node cannot be dug if `leveldiff` is less than zero.
---@field times table<number|integer, number|integer> List of digging times for different ratings of the group, for nodes of the maximum level. For example, as a Lua table, `times={[2]=2.00, [3]=0.70}`. This would result in the item to be able to dig nodes that have a rating of `2` or `3` for this group, and unable to dig the rating `1`, which is the toughest. Unless there is a matching group that enables digging otherwise. If the result digging time is 0, a delay of 0.15 seconds is added between digging nodes; If the player releases LMB after digging, this delay is set to 0, i.e. players can more quickly click the nodes away instead of holding LMB.

36
types/itemstack.type.lua Normal file
View File

@ -0,0 +1,36 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---A native C++ format with many helper methods. Useful for converting between formats.
---An `ItemStack` is a stack of items.
---It can be created via `ItemStack(x)`, where x is an `ItemStack`, an itemstring, a table or `nil`.
---@class ItemStack
---@field is_empty fun(): boolean Returns `true` if stack is empty.
---@field get_name fun(): string returns item name (e.g. `"default:stone"`).
---@field set_name fun(self: ItemStack, item_name: string): boolean Returns a boolean indicating whether the item was cleared.
---@field get_count fun(): integer Returns number of items on the stack.
---@field set_count fun(self: ItemStack, count: integer): boolean Returns a boolean indicating whether the item was cleared
---@field get_wear fun(): integer Returns tool wear (`0`-`65535`), `0` for non-tools.
---@field set_wear fun(self: ItemStack, wear: integer): boolean Returns boolean indicating whether item was cleared
---@field get_meta fun(): ItemStackMetaRef Returns `ItemStackMetaRef`.
---@field get_description fun(): string Returns the description shown in inventory list tooltips. The engine uses this when showing item descriptions in tooltips. Fields for finding the description, in order: `description` in item metadata.
---@field get_short_description fun(): string|nil Returns the short description or nil. Unlike the description, this does not include new lines. Fields for finding the short description, in order: `short_description` in item metadata. Returns nil if none of the above are set.
---@field clear fun(): nil Removes all items from the stack, making it empty.
---@field replace fun(self: ItemStack, item: string|table)`: replace the contents of this stack. `item` can also be an itemstring or table.
---@field to_string fun(): string Returns the stack in itemstring form.
---@field to_table fun(): table Returns the stack in Lua table form.
---@field get_stack_max fun(): integer Returns the maximum size of the stack (depends on the item).
---@field get_free_space fun(): integer Returns `get_stack_max() - get_count()`.
---@field is_known fun(): boolean Returns `true` if the item name refers to a defined item type.
---@field get_definition fun(): table Returns the item definition table.
---@field get_tool_capabilities fun(): table Returns the digging properties of the item, or those of the hand if none are defined for this item type
---@field add_wear fun(self: ItemStack, amount: integer|number): nil Increases wear by `amount` if the item is a tool, otherwise does nothing. Valid `amount` range is [0,65536] `amount`: number, integer
---@field add_wear_by_uses fun(self: ItemStack, max_uses: integer|number): nil Increases wear in such a way that, if only this function is called, the item breaks after `max_uses` times. Valid `max_uses` range is [0,65536] Does nothing if item is not a tool or if `max_uses` is 0
---@field add_item fun(self: ItemStack, item: string|table): ItemStack Returns leftover `ItemStack` Put some item or stack onto this stack
---@field item_fits fun(self: ItemStack, item: string|table): boolean Returns `true` if item or stack can be fully added to this one.
---@field take_item fun(self: ItemStack, n?: integer|number): ItemStack Returns taken `ItemStack` Take (and remove) up to `n` items from this stack `n`: number, default: `1`
---@field peek_item fun(self: ItemStack, n: integer|number): ItemStack Returns taken `ItemStack` Copy (don't remove) up to `n` items from this stack `n`: number, default: `1`
---@field name string
---@field count integer
---@field wear string
---@field metadata string

View File

@ -0,0 +1,39 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
--- In a game, a certain number of these must be set to tell core mapgens which of the game's nodes are to be used for core mapgen generation.
---@alias MapgenAliasesNonV6
---| '"mapgen_stone"'
---| '"mapgen_water_source"'
---| '"mapgen_river_water_source"'
---| '"mapgen_river_water_source"' # is required for mapgens with sloping rivers where it is necessary to have a river liquid node with a short `liquid_range` and `liquid_renewable = false` to avoid flooding.
---| '"mapgen_lava_source"' # Optional, Fallback lava node used if cave liquids are not defined in biome definitions. Deprecated, define cave liquids in biome definitions instead.
---| '"mapgen_cobble"' # Optional, Fallback node used if dungeon nodes are not defined in biome definitions. Deprecated, define dungeon nodes in biome definitions instead.
--- In a game, a certain number of these must be set to tell core mapgens which of the game's nodes are to be used for core mapgen generation.
---@alias MapgenAliasesV6
---| '"mapgen_stone"'
---| '"mapgen_water_source"'
---| '"mapgen_lava_source"'
---| '"mapgen_dirt"'
---| '"mapgen_dirt_with_grass"'
---| '"mapgen_sand"'
---| '"mapgen_tree"'
---| '"mapgen_leaves"'
---| '"mapgen_apple"'
---| '"mapgen_cobble"'
---| '"mapgen_gravel"' # Optional, (falls back to stone)
---| '"mapgen_desert_stone"' # Optional, (falls back to stone)
---| '"mapgen_desert_sand"' # Optional, (falls back to sand)
---| '"mapgen_dirt_with_snow"' # Optional, (falls back to dirt_with_grass)
---| '"mapgen_snowblock"' # Optional, (falls back to dirt_with_grass)
---| '"mapgen_snow"' # Optional, (not placed if missing)
---| '"mapgen_ice"' # Optional, (falls back to water_source)
---| '"mapgen_jungletree"' # Optional, (falls back to tree)
---| '"mapgen_jungleleaves"' # Optional, (falls back to leaves)
---| '"mapgen_junglegrass"' # Optional, (not placed if missing)
---| '"mapgen_pine_tree"' # Optional, (falls back to tree)
---| '"mapgen_pine_needles"' # Optional, (falls back to leaves)
---| '"mapgen_stair_cobble"' # Optional, (falls back to cobble)
---| '"mapgen_mossycobble"' # Optional, (falls back to cobble)
---| '"mapgen_stair_desert_stone"' # Optional, (falls backto desert_stone)

8
types/math.type.lua Normal file
View File

@ -0,0 +1,8 @@
---@diagnostic disable: codestyle-check, duplicate-doc-alias
---https://github.com/sumneko/lua-language-server/wiki
---@alias mathlib mathlib|MathAbstract
---Math helpers
---@class MathAbstract
---@field round fun(x: number): number Returns `x` rounded to the nearest integer. At a multiple of 0.5, rounds away from zero.

36
types/meta.type.lua Normal file
View File

@ -0,0 +1,36 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---@alias ItemStackMetaRef MetaDataRef|ItemStackMetaRefAbstract
---@alias NodeMetaRef MetaDataRef|NodeMetaRefAbstract
---@alias PlayerMetaRef MetaDataRef|PlayerMetaRefAbstract
---@alias StorageRef MetaDataRef|StorageRefAbstract
---Base class used by [`StorageRef`], [`NodeMetaRef`], [`ItemStackMetaRef`], and [`PlayerMetaRef`].
---@class MetaDataRef
---@field contains fun(self: MetaDataRef, key: string): boolean|nil Returns true if key present, otherwise false. Returns `nil` when the MetaData is inexistent.
---@field get fun(self: MetaDataRef, key: string): string|nil Returns `nil` if key not present, else the stored string.
---@field set_string fun(self: MetaDataRef, key: string, value: string): string Value of `""` will delete the key.
---@field get_string fun(self: MetaDataRef, key: string): string Returns `""` if key not present.
---@field set_int fun(self: MetaDataRef, key: string, value: integer): nil
---@field get_int fun(self: MetaDataRef, key: string): integer|number Returns `0` if key not present.
---@field set_float fun(self: MetaDataRef, key: string, value: number): nil
---@field get_float fun(self: MetaDataRef, key): integer|number Returns `0` if key not present.
---@field to_table fun(): nil Returns `nil` or a table with keys: `fields`: key-value storage `inventory`: `{list1 = {}, ...}}` (NodeMetaRef only)
---@field from_table fun(self: MetaDataRef, t: nil|table): boolean Any non-table value will clear the metadata. Returns `true` on success
---@field equals fun(self: MetaDataRef, other: any): boolean Returns `true` if this metadata has the same key-value pairs as `other`
---ItemStack metadata: reference extra data and functionality stored in a stack. Can be obtained via `item:get_meta()`.
---@class ItemStackMetaRefAbstract
---@field set_tool_capabilities fun(self: ItemStackMetaRef, tool_capabilities?: table): nil Overrides the item's tool capabilities. A nil value will clear the override data and restore the original behavior.
---Node metadata: reference extra data and functionality stored in a node. Can be obtained via `minetest.get_meta(pos)`.
---@class NodeMetaRefAbstract
---@field get_inventory fun(self: NodeMetaRef): InvRef
---@field mark_as_private fun(self: NodeMetaRef, name: string | table<string[]>) Mark specific vars as private This will prevent them from being sent to the client. Note that the "private" status will only be remembered if an associated key-value pair exists, meaning it's best to call this when initializing all other meta (e.g. `on_construct`).
---Player metadata. Uses the same method of storage as the deprecated player attribute API, so data there will also be in player meta. Can be obtained using `player:get_meta()`.
---@class PlayerMetaRefAbstract
---Mod metadata: per mod metadata, saved automatically. Can be obtained via `minetest.get_mod_storage()` during load time. WARNING: This storage backend is incapable of saving raw binary data due to restrictions of JSON.
---@class StorageRefAbstract

170
types/minetest.type.lua Normal file
View File

@ -0,0 +1,170 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest globals
---@class Minetest
---@field item_drop fun(itemstack: string|ItemStack, dropper: ObjectRef, pos: Vector): ItemStack Drop the item, returns the leftover itemstack
---@field get_us_time fun(): integer|number Returns time with microsecond precision. May not return wall time.
---@field get_modpath fun(modname: string): string|nil Returns the directory path for a mod, e.g. `"/home/user/.minetest/usermods/modname"`. Returns nil if the mod is not enabled or does not exist (not installed). Works regardless of whether the mod has been loaded yet. Useful for loading additional `.lua` modules or static data from a mod, or checking if a mod is enabled.
---@field check_player_privs fun(player_or_name: ObjectRef|string, privs: table|string[]): boolean Returns `bool, missing_privs`. A quickhand for checking privileges. `player_or_name`: Either a Player object or the name of a player. `privs` is either a list of strings, e.g. `"priva", "privb"` or a table, e.g. `{ priva = true, privb = true }`.
---@field register_on_joinplayer fun(f: fun(player: ObjectRef, last_login: number|integer|nil)): nil Called when a player joins the game. `last_login`: The timestamp of the previous login, or nil if player is new
---@field register_tool fun(name: string, item_definition: ItemDef): nil Registers the item in the engine
---@field colorize fun(color: string, message: string): nil
---@field register_craft fun(recipe: CraftRecipeDef): nil
---@field register_craftitem fun(name: string, item_definition: ItemDef): nil
---@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 registered_nodes table<string, NodeDef|ItemDef> Map of registered node definitions, indexed by name
---@field after fun(time: number|integer, func: fun(...), ...): JobTable Call the function `func` after `time` seconds, may be fractional. Optional: Variable number of arguments that are passed to `func`.
---@field sound_play fun(spec: SimpleSoundSpec|string, parameters: SoundParamDef, ephemeral?: boolean): any Returns a `handle`. Ephemeral sounds will not return a handle and can't be stopped or faded. It is recommend to use this for short sounds that happen in response to player actions (e.g. door closing).
---@field add_particlespawner fun(particlespawner_definition: ParticlespawnerDef): number|integer Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds. Returns an `id`, and -1 if adding didn't succeed.
---@field register_globalstep fun(func: fun(dtime: number|integer)): nil Called every server step, usually interval of 0.1s
---@field get_connected_players fun(): ObjectRef[] Returns list of `ObjectRefs`
---@field serialize fun(t: table): string Convert a table containing tables, strings, numbers, booleans and `nil`s into string form readable by `minetest.deserialize`. Example: `serialize({foo="bar"})`, returns `'return { ["foo"] = "bar" }'`.
---@field dir_to_yaw fun(dir: Vector): number|integer Convert a vector into a yaw (angle)
---@field settings MinetestSettings Settings object containing all of the settings from the main config file (`minetest.conf`).
---@field register_entity fun(name: string, entity_definition: EntityDef): nil
---@field deserialize fun(s: string, safe?: boolean): table Returns a table. Convert a string returned by `minetest.serialize` into a table `string` is loaded in an empty sandbox environment. Will load functions if safe is false or omitted. Although these functions cannot directly access the global environment, they could bypass this restriction with maliciously crafted Lua bytecode if mod security is disabled. This function should not be used on untrusted data, regardless of the value of `safe`. It is fine to serialize then deserialize user-provided data, but directly providing user input to deserialize is always unsafe.
---@field raycast fun(pos1: Vector, pos2: Vector, objects: boolean, liquids: boolean): Raycast `pos1`: start of the ray, `pos2`: end of the ray, `objects`: if false, only nodes will be returned. Default is true. `liquids`: if false, liquid nodes (`liquidtype ~= "none"`) won't be returned. Default is false.
---@field calculate_knockback fun(player: ObjectRef, hitter: ObjectRef, time_from_last_punch: number|integer, tool_capabilities: ToolCapabilitiesDef, dir: Vector, distance: number|integer, damage: number|integer): integer|number Returns the amount of knockback applied on the punched player. Arguments are equivalent to `register_on_punchplayer`, except the following: `distance`: distance between puncher and punched player. This function can be overriden by mods that wish to modify this behaviour. You may want to cache and call the old function to allow multiple mods to change knockback behaviour.
---@field get_player_by_name fun(name: string): ObjectRef Get an `ObjectRef` to a player
---@field get_node_timer fun(pos: Vector): NodeTimerRef Get `NodeTimerRef`
---@field get_objects_inside_radius fun(pos: Vector, radius: number|integer): ObjectRef[] Returns a list of ObjectRefs. `radius`: using an euclidean metric.
---@field register_node fun(name: string, node_definition: NodeDef): nil
---@field get_meta fun(pos: Vector): NodeMetaRef Get a `NodeMetaRef` at that position
---@field pos_to_string fun(pos: Vector, decimal_places?: number|integer): string returns string `"(X,Y,Z)"`, `pos`: table {x=X, y=Y, z=Z}. Converts the position `pos` to a human-readable, printable string. `decimal_places`: number, if specified, the x, y and z values of the position are rounded to the given decimal place.
---@field get_node_light fun(pos: Vector, timeofday: number|integer|nil): number|integer|nil Gets the light value at the given position. Note that the light value "inside" the node at the given position is returned, so you usually want to get the light value of a neighbor. `pos`: The position where to measure the light. `timeofday`: `nil` for current time, `0` for night, `0.5` for day. Returns a number between `0` and `15` or `nil`. `nil` is returned e.g. when the map isn't loaded at `pos`.
---@field set_node fun(pos: Vector, node: SetNodeTable): nil Set node at position `pos`, `node`: table `{name=string, param1=number, param2=number}`, If param1 or param2 is omitted, it's set to `0`. e.g. `minetest.set_node({x=0, y=10, z=0}, {name="default:wood"})`
---@field place_schematic fun(pos: Vector, schematic, rotation?: '0'|'90'|'180'|'270'|'random', replacements?: table<string, string>, force_placement?: boolean, flags?: string): nil Place the schematic specified by schematic at `pos`. `rotation` can equal `"0"`, `"90"`, `"180"`, `"270"`, or `"random"`. If the `rotation` parameter is omitted, the schematic is not rotated. `replacements` = `{["old_name"] = "convert_to", ...}`. `force_placement` is a boolean indicating whether nodes other than `air` and `ignore` are replaced by the schematic. Returns nil if the schematic could not be loaded. **Warning**: Once you have loaded a schematic from a file, it will be cached. Future calls will always use the cached version and the replacement list defined for it, regardless of whether the file or the replacement list parameter have changed. The only way to load the file anew is to restart the server. `flags` is a flag field with the available flags: place_center_x, place_center_y, place_center_z
---@field log fun(level?: 'none'|'error'|'warning'|'action'|'info'|'verbose', text: string): nil
---@field get_item_group fun(name: string, group): any returns a rating. Get rating of a group of an item. (`0` means: not in group)
---@field get_biome_data fun(pos: Vector): BiomeData|nil
---@field get_biome_name fun(biome_id: string|number|integer): string|nil Returns the biome name string for the provided biome id, or `nil` on failure. If no biomes have been registered, such as in mgv6, returns `default`.
---@field find_nodes_in_area fun(pos1: Vector, pos2: Vector, nodenames: string|string[], grouped?: boolean): Vector[] `pos1` and `pos2` are the min and max positions of the area to search. `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"` If `grouped` is true the return value is a table indexed by node name which contains lists of positions. If `grouped` is false or absent the return values are as follows: first value: Table with all node positions, second value: Table with the count of each node with the node name as index, Area volume is limited to 4,096,000 nodes
---@field find_nodes_in_area_under_air fun(pos1: Vector, pos2: Vector, nodenames: string|string[]): table returns a list of positions. `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`. Return value: Table with all node positions with a node air above. Area volume is limited to 4,096,000 nodes.
---@field registered_decorations table<any, DecorationDef> Map of registered decoration definitions, indexed by the `name` field. If `name` is nil, the key is the object handle returned by `minetest.register_schematic`.
---@field swap_node fun(pos: Vector, node: NodeDef): nil Set node at position, but don't remove metadata
---@field item_eat fun(hp_change: number, replace_with_item?: string): fun(itemstack: ItemStack, user: ObjectRef, pointed_thing: PointedThingDef) Returns `function(itemstack, user, pointed_thing)` as a function wrapper for `minetest.do_item_eat`. `replace_with_item` is the itemstring which is added to the inventory. If the player is eating a stack, then replace_with_item goes to a different spot.
---@field override_item fun(name: string, redefinition: ItemDef|NodeDef): nil Overrides fields of an item registered with register_node/tool/craftitem. Note: Item must already be defined, (opt)depend on the mod defining it. Example: `minetest.override_item("default:mese", {light_source=minetest.LIGHT_MAX})`
---@field register_decoration fun(decoration_definition: DecorationDef): number|integer Returns an integer object handle uniquely identifying the registered decoration on success. To get the decoration ID, use `minetest.get_decoration_id`. The order of decoration registrations determines the order of decoration generation.
---@field find_node_near fun(pos: Vector, radius: number, nodenames: string[], search_center?: boolean): Vector|nil returns pos or `nil`. `radius`: using a maximum metric, `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`, `search_center` is an optional boolean (default: `false`) If true `pos` is also checked for the nodes
---@field remove_node fun(pos: Vector): nil By default it does the same as `minetest.set_node(pos, {name="air"})`
---@field get_node_or_nil fun(pos: Vector): NodeDef|nil Same as `get_node` but returns `nil` for unloaded areas.
---@field facedir_to_dir fun(facedir: number): Vector Convert a facedir back into a vector aimed directly out the "back" of a node.
---@field record_protection_violation fun(pos: Vector, name: string): nil This function calls functions registered with `minetest.register_on_protection_violation`.
---@field dir_to_facedir fun(dir: Vector, is6d?: any): number Convert a vector to a facedir value, used in `param2` for `paramtype2="facedir"`. passing something non-`nil`/`false` for the optional second parameter causes it to take the y component into account.
---@field register_lbm fun(lbm_definition: LbmDef): nil
---@field rotate_node fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef): nil calls `rotate_and_place()` with `infinitestacks` set according to the state of the creative mode setting, checks for "sneak" to set the `invert_wall` parameter and `prevent_after_place` set to `true`.
---@field global_exists fun(name: string): nil Checks if a global variable has been set, without triggering a warning.
---@field register_alias fun(alias: string|MapgenAliasesV6|MapgenAliasesNonV6, original_name: string): nil Also use this to set the 'mapgen aliases' needed in a game for the core mapgens. See [Mapgen aliases] section above.
---@field register_alias_force fun(alias: string|MapgenAliasesV6|MapgenAliasesNonV6, original_name: string): nil
---@field add_item fun(pos: Vector, item: ItemStack): ObjectRef|nil Spawn item. Returns `ObjectRef`, or `nil` if failed.
---@field registered_items table<string, ItemDef> Map of registered items, indexed by name
---@field add_node fun(pos: Vector, node: SetNodeTable): nil alias to `minetest.set_node`, Set node at position `pos`, `node`: table `{name=string, param1=number, param2=number}`, If param1 or param2 is omitted, it's set to `0`. e.g. `minetest.set_node({x=0, y=10, z=0}, {name="default:wood"})`
---@field string_to_pos fun(string: string): Vector|nil If the string can't be parsed to a position, nothing is returned.
---@field chat_send_player fun(name: string, text: string): nil
---@field create_detached_inventory fun(name: string, callbacks: DetachedInventoryCallbacks, player_name?: string): InvRef Creates a detached inventory. If it already exists, it is cleared. `callbacks`: See [Detached inventory callbacks], `player_name`: Make detached inventory available to one player exclusively, by default they will be sent to every player (even if not used). Note that this parameter is mostly just a workaround and will be removed in future releases.
---@field get_mod_storage fun(): StorageRef Mod metadata: per mod metadata, saved automatically. Can be obtained via `minetest.get_mod_storage()` during load time.
---@field show_formspec fun(playername: string, formname: string, formspec: string): nil `playername`: name of player to show formspec, `formname`: name passed to `on_player_receive_fields` callbacks. It should follow the `"modname:<whatever>"` naming convention. `formspec`: formspec to display
---@field register_on_player_receive_fields fun(func: fun(player: ObjectRef, formname: string, fields: table)): nil Called when the server received input from `player` in a formspec with the given `formname`. Specifically, this is called on any of the following events: a button was pressed, Enter was pressed while the focus was on a text field, a checkbox was toggled, something was selected in a dropdown list, a different tab was selected, selection was changed in a textlist or table, an entry was double-clicked in a textlist or table, a scrollbar was moved, or the form was actively closed by the player.
---@field get_inventory fun(location: {['"type"']: 'player'|'node'|'detached', ['"name"']: string|nil, ['"pos"']: Vector|nil}): InvRef
---@field dir_to_wallmounted fun(dir: Vector): number Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
---@field item_place_node fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef, param2?: string , prevent_after_place?: boolean): Vector|nil Place item as a node, `param2` overrides `facedir` and wallmounted `param2`, `prevent_after_place`: if set to `true`, `after_place_node` is not called or the newly placed node to prevent a callback and placement loop. returns `itemstack, position`, `position`: the location the node was placed to. `nil` if nothing was placed.
---@field unregister_item fun(name: string): nil Unregisters the item from the engine, and deletes the entry with key `name` from `minetest.registered_items` and from the associated item table according to its nature: `minetest.registered_nodes`, etc.
---@field register_allow_player_inventory_action fun(func: fun(player: ObjectRef, action: string, inventory: InvRef, inventory_info: {["from_list"]: string, ["to_list"]: string, ["from_index"]: number, ["to_index"]: number, ["count"]: number} | {["listname"]: string, ["index"]: number, ["stack"]: ItemStack}): number): nil Determines how much of a stack may be taken, put or moved to a player inventory. `player` (type `ObjectRef`) is the player who modified the inventory, `inventory` (type `InvRef`). List of possible `action` (string) values and their `inventory_info` (table) contents: `move`: `{from_list=string, to_list=string, from_index=number, to_index=number, count=number}`, `put`: `{listname=string, index=number, stack=ItemStack}`, `take`: Same as `put`. Return a numeric value to limit the amount of items to be taken, put or moved. A value of `-1` for `take` will make the source stack infinite.
---@field register_on_player_inventory_action fun(func: fun(player: ObjectRef, action: string, inventory: InvRef, inventory_info: {["from_list"]: string, ["to_list"]: string, ["from_index"]: number, ["to_index"]: number, ["count"]: number} | {["listname"]: string, ["index"]: number, ["stack"]: ItemStack}): nil): nil Called after a take, put or move event from/to/in a player inventory. Function arguments: see `minetest.register_allow_player_inventory_action`. Does not accept or handle any return value.
---@field formspec_escape fun(str: string): string returns a string, escapes the characters "[", "]", "\", "," and ";", which can not be used in formspecs.
---@field get_translator fun(textdomain: string): any
---@field get_current_modname fun(): string returns the currently loading mod's name, when loading a mod.
---@field get_pointed_thing_position fun(pointed_thing: PointedThingDef, above?: boolean): Vector | nil Returns the position of a `pointed_thing` or `nil` if the `pointed_thing` does not refer to a node or entity. If the optional `above` parameter is true and the `pointed_thing` refers to a node, then it will return the `above` position of the `pointed_thing`.
---@field item_place fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef, param2?: string|number): ItemStack Wrapper that calls `minetest.item_place_node` if appropriate. Calls `on_rightclick` of `pointed_thing.under` if defined instead **Note**: is not called when wielded item overrides `on_place`, `param2` overrides facedir and wallmounted `param2`, returns `itemstack, position`, `position`: the location the node was placed to. `nil` if nothing was placed.
---@field node_dig fun(pos: Vector, node: NodeDef, digger: ObjectRef): nil Checks if node can be dug, puts item into inventory, removes node. Calls functions registered by `minetest.registered_on_dignodes()`
---@field delete_particlespawner fun(id: number, player?: ObjectRef): nil Delete `ParticleSpawner` with `id` (return value from `minetest.add_particlespawner`). If playername is specified, only deletes on the player's client, otherwise on all clients.
---@field is_area_protected fun(pos1: Vector, pos2: Vector, player_name: ObjectRef, interval: number): Vector | boolean Returns the position of the first node that `player_name` may not modify in the specified cuboid between `pos1` and `pos2`. Returns `false` if no protections were found. Applies `is_protected()` to a 3D lattice of points in the defined volume. The points are spaced evenly throughout the volume and have a spacing similar to, but no larger than, `interval`. All corners and edges of the defined volume are checked. `interval` defaults to 4. `interval` should be carefully chosen and maximised to avoid an excessive number of points being checked. Like `minetest.is_protected`, this function may be extended or overwritten by mods to provide a faster implementation to check the cuboid for intersections.
---@field is_protected fun(pos: Vector, name: string): boolean Returning `true` restricts the player `name` from modifying (i.e. digging, placing) the node at position `pos`. `name` will be `""` for non-players or unknown players. This function should be overridden by protection mods. It is highly recommended to grant access to players with the `protection_bypass` privilege. Cache and call the old version of this function if the position is not protected by the mod. This will allow using multiple protection mods.
---@field register_on_mods_loaded fun(func: fun(): nil): nil Called after mods have finished loading and before the media is cached or the aliases handled.
---@field register_on_leaveplayer fun(func: fun(player: ObjectRef, timed_out: number): nil): nil Called when a player leaves the game `timed_out`: True for timeout, false for other reasons.
---@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 registered_tools table<string, ItemDef> Map of registered tool definitions, indexed by name
---@field has_feature fun(args: table<string, boolean> | string): boolean | table returns `boolean, missing_features`, `arg`: string or table in format `{foo=true, bar=true}`, `missing_features`: `{foo=true, bar=true}`
---Minetest settings
---@class MinetestSettings
---@field get fun(self: MinetestSettings, key: string): string|number|integer Returns a value
---@field get_bool fun(self: MinetestSettings, key: string, default?: boolean): boolean|nil Returns a boolean. `default` is the value returned if `key` is not found. Returns `nil` if `key` is not found and `default` not specified.
---@field get_np_group fun(self: MinetestSettings, key: string): table Returns a NoiseParams table
---@field get_flags fun(self: MinetestSettings, key: string): table Returns `{flag = true/false, ...}` according to the set flags. Is currently limited to mapgen flags `mg_flags` and mapgen-specific flags like `mgv5_spflags`.
---@field set fun(self: MinetestSettings, key: string, value: string|integer|number): nil Setting names can't contain whitespace or any of `="{}#`. Setting values can't contain the sequence `\n"""`. Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`).
---@field set_bool fun(self: MinetestSettings, key: string, value: boolean): nil Setting names can't contain whitespace or any of `="{}#`. Setting values can't contain the sequence `\n"""`. Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`).
---@field set_np_group fun(self: MinetestSettings, key: string, value: table): nil `value` is a NoiseParams table.
---@field remove fun(self: MinetestSettings, key: string): boolean Returns a boolean (`true` for success)
---@field get_names fun(): table Returns `{key1,...}`
---@field write fun(): boolean Returns a boolean (`true` for success). Writes changes to file.
---@field to_table fun(): table Returns `{[key1]=value1,...}`
--- Set node table
---@class SetNodeTable
---@field name string
---@field param1 number
---@field param2 number
--- Detached inventory callbacks
---@class DetachedInventoryCallbacks
---@field allow_move fun(inv: InvRef, from_list: string, from_index: number, to_list: string, to_index: number, count: number, player: ObjectRef): number Called when a player wants to move items inside the inventory. Return value: number of items allowed to move.
---@field allow_put fun(inv: InvRef, listname: string, index: number, stack: ItemStack, player: ObjectRef): number Called when a player wants to put something into the inventory. Return value: number of items allowed to put. Return value -1: Allow and don't modify item count in inventory.
---@field allow_take fun(inv: InvRef, listname: string, index: number, stack: ItemStack, player: ObjectRef): number Called when a player wants to take something out of the inventory. Return value: number of items allowed to take. Return value -1: Allow and don't modify item count in inventory.
---@field on_move fun(inv: InvRef, from_list: string, from_index: number, to_list: string, to_index: number, count: number, player: ObjectRef): nil
---@field on_put fun(inv: InvRef, listname: string, index: number, stack: ItemStack, player: ObjectRef): nil
---@field on_take fun(inv: InvRef, listname: string, index: number, stack: ItemStack, player: ObjectRef): nil Called after the actual action has happened, according to what was allowed. No return value.
--- Job table
---@class JobTable
---@field cancel fun(self: JobTable) Cancels the job function from being called
--- Biome data
---@class BiomeData
---@field biome string|number|integer the biome id of the biome at that position
---@field heat string|number|integer the heat at the position
---@field humidity string|number|integer the humidity at the position
--- LBM (LoadingBlockModifier) definition. A loading block modifier (LBM) is used to define a function that is called for specific nodes (defined by `nodenames`) when a mapblock which contains such nodes gets activated (not loaded!)
---@class LbmDef
---@field label string Descriptive label for profiling purposes (optional). Definitions with identical labels will be listed as one.
---@field name string Identifier of the LBM, should follow the modname:<whatever> convention
---@field nodenames string[] List of node names to trigger the LBM on. Names of non-registered nodes and groups (as group:groupname) will work as well.
---@field run_at_every_load boolean Whether to run the LBM's action every time a block gets activated, and not only the first time the block gets activated after the LBM was introduced.
---@field action fun(pos: Vector, node: NodeDef): nil Function triggered for each qualifying node.
--- Sound parameters.
--- Looped sounds must either be connected to an object or played locationless to one player using `to_player = name`. A positional sound will only be heard by players that are within `max_hear_distance` of the sound position, at the start of the sound. `exclude_player = name` can be applied to locationless, positional and object-bound sounds to exclude a single player from hearing them.
---@class SoundParamDef
---@field to_player string Name
---@field gain number|integer
---@field fade number|integer Change to a value > 0 to fade the sound in
---@field pitch number|integer
---@field loop boolean
---@field pos Vector
---@field max_hear_distance number|integer
---@field object ObjectRef
---@field exclude_player string Name
---Partcile definition
---@class ParticleDef
---@field pos Vector
---@field velocity Vector
---@field acceleration Vector Spawn particle at pos with velocity and acceleration
---@field expirationtime number Disappears after expirationtime seconds
---@field size number Scales the visual size of the particle texture. If `node` is set, size can be set to 0 to spawn a randomly-sized particle (just like actual node dig particles).
---@field collisiondetection boolean If true collides with `walkable` nodes and, depending on the `object_collision` field, objects too.
---@field collision_removal boolean If true particle is removed when it collides. Requires collisiondetection = true to have any effect.
---@field object_collision boolean If true particle collides with objects that are defined as `physical = true,` and `collide_with_objects = true,`. Requires collisiondetection = true to have any effect.
---@field vertical boolean If true faces player using y axis only
---@field texture string The texture of the particle v5.6.0 and later: also supports the table format described in the following section
---@field playername string | nil Optional, if specified spawns particle only on the player's client
---@field animation TileAnimationDef | nil Optional, specifies how to animate the particle texture
---@field glow number | nil Optional, specify particle self-luminescence in darkness. Values 0-14.
---@field node {["name"]: string, ["param2"]: number} | nil Optional, if specified the particle will have the same appearance as node dig particles for the given node. `texture` and `animation` will be ignored if this is set.
---@field node_tile number | nil Optional, only valid in combination with `node` If set to a valid number 1-6, specifies the tile from which the particle texture is picked. Otherwise, the default behavior is used. (currently: any random tile)
---@field drag Vector | nil v5.6.0 and later: Optional drag value, consult the following section
---@field bounce {["min"]: number, ["max"]: number, ["bias"]: number} | nil v5.6.0 and later: Optional bounce range, consult the following section

View File

@ -0,0 +1,6 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game creative mod
---@class MtgCreative
---@field is_enabled_for fun(name: string): boolean Returning `true` means that Creative Mode is enabled for player `name`. `name` will be `""` for non-players or if the player is unknown. By default, this function returns `true` if the setting `creative_mode` is `true` and `false` otherwise.

View File

@ -0,0 +1,40 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game default mod
---@class MtgDefault
---@field LIGHT_MAX number|integer The maximum light level. Maximum light to grow.
---@field can_grow fun(pos: Vector): boolean Grow trees from saplings
---@field grow_new_apple_tree fun(pos: Vector): nil
---@field grow_new_jungle_tree fun(pos: Vector): nil
---@field grow_new_emergent_jungle_tree fun(pos: Vector): nil
---@field grow_new_acacia_tree fun(pos: Vector): nil
---@field grow_new_aspen_tree fun(pos: Vector): nil
---@field grow_new_snowy_pine_tree fun(pos: Vector): nil
---@field grow_new_pine_tree fun(pos: Vector): nil
---@field grow_bush fun(pos: Vector): nil
---@field grow_acacia_bush fun(pos: Vector): nil
---@field grow_pine_bush fun(pos: Vector): nil
---@field grow_blueberry_bush fun(pos: Vector): nil
---@field grow_papyrus fun(pos: Vector, node: NodeDef): nil
---@field grow_large_cactus fun(pos: Vector, node: NodeDef): nil
---@field sapling_on_place fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: PointedThingDef, sapling_name: string, minp_relative: Vector, maxp_relative: Vector, interval: number): nil Sapling 'on place' function to check protection of node and resulting tree volume
---@field register_leafdecay fun(def: RegisterLeafdecayDef): nil
---@field after_place_leaves fun(pos: Vector, placer: ObjectRef, itemstack?: ItemStack, pointed_thing?: PointedThingDef): nil Prevent decay of placed leaves
---@field node_sound_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_stone_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_dirt_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_sand_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_wood_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_leaves_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_glass_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_metal_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_ice_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field node_sound_gravel_defaults fun(table?: NodeSoundDef): NodeSoundDef
---@field get_hotbar_bg fun(x: number, y: number): nil Get the hotbar background as string, containing the formspec elements. x: Horizontal position in the formspec, y: Vertical position in the formspec.
--- Leaf decay definition
---@class RegisterLeafdecayDef
---@field trunks string[]
---@field leaves string[]
---@field radius number

View File

@ -0,0 +1,15 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game dungeon loot mod API
---@class MtgDungeonLoot
---@field register fun(loot_definition: MtgDungeonLootDef): nil Registers one or more loot items, `def` Can be a single loot_definition or a list of them.
---@field registered_loot table Table of all registered loot, not to be modified manually
---Loot definition
---@class MtgDungeonLootDef
---@field name string
---@field chance number chance value from 0.0 to 1.0 that the item will appear in the chest when chosen, Due to an extra step in the selection process, 0.5 does not(!) mean that on average every second chest will have this item
---@field count number[]|nil table with minimum and maximum amounts of this item, optional, defaults to always single item
---@field y number[]|nil table with minimum and maximum heights this item can be found at, optional, defaults to no height restrictions
---@field types string[]|nil table with types of dungeons this item can be found in supported types: "normal" (the cobble/mossycobble one), "sandstone", "desert" and "ice", optional, defaults to no type restrictions

View File

@ -0,0 +1,15 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game farming mod
---@class MtgFarming
---@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
----Node definition. Used by `minetest.register_node`.
---@class NodeDefMtgFarming
---@field fertility string[]|nil Used in default farming mod, defines biome name list where plants can grow
---@field steps number How many steps the plant has to grow, until it can be harvested
---@field minlight number Minimum light to grow
---@field maxlight number Maximum light to grow
---@field on_timer fun(pos: Vector, elapsed: number): boolean 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.

View File

@ -0,0 +1,33 @@
---@diagnostic disable: codestyle-check
---The player API can register player models and update the player's appearance.
---@class MtgPlayerApi
---@field globalstep fun(dtime: number, ...): nil The function called by the globalstep that controls player animations. You can override this to replace the globalstep with your own implementation. Receives all args that minetest.register_globalstep() passes
---@field register_model fun(name: string, def: MtgPlayerApiModelDef): nil Register a new model to be used by players, `name`: model filename such as "character.x", "foo.b3d", etc., `def`: see [#Model definition] Saved to player_api.registered_models
---@field registered_models string[] Get a model's definition, `name`: model filename See [#Model definition]
---@field set_model fun(player: ObjectRef, model_name: string): nil Change a player's model, `player`: PlayerRef, `model_name`: model registered with `player_api.register_model`
---@field set_animation fun(player: ObjectRef, anim_name: string, speed: number): nil Applies an animation to a player if speed or anim_name differ from the currently playing animation, `player`: PlayerRef, `anim_name`: name of the animation, `speed`: keyframes per second. If nil, the default from the model def is used
---@field set_textures fun(player: ObjectRef, textures: string[]): nil Sets player textures `player`: PlayerRef, `textures`: array of textures. If nil, the default from the model def is used
---@field set_texture fun(player: ObjectRef, index: number, texture: string): nil Sets one of the player textures, `player`: PlayerRef, `index`: Index into array of all textures, `texture`: the texture string
---@field get_textures fun(player: ObjectRef): string[] Returns player textures table
---@field get_animation fun(player: ObjectRef): {["model"]: string | nil, ["textures"]: string[] | nil, ["animation"]: table | nil} Returns a table containing fields `model`, `textures` and `animation`. Any of the fields of the returned table may be nil, `player`: PlayerRef
---@field player_attached table<string, boolean> A table that maps a player name to a boolean. If the value for a given player is set to true, the default player animations (walking, digging, ...) will no longer be updated, and knockback from damage is prevented for that player. Example of usage: A mod sets a player's value to true when attached to a vehicle.
---Model Definition
---@class MtgPlayerApiModelDef
---@field animation_speed number Default: 30, animation speed, in keyframes per second
---@field textures string[] Default `{"character.png"}`, array of textures
---@field animations table<string, MtgPlayerApiAnimationDef>
---@field visual_size {["x"]: number, ["y"]: number}
---@field collisionbox number[]
---@field stepheight number
---@field eye_height number
---Model Animation definition
---@class MtgPlayerApiAnimationDef
---@field x number start frame
---@field y number end frame
---@field collisionbox number[] | nil
---@field eye_height number | nil model eye height
---@field override_local boolean | nil suspend client side animations while this one is active (optional)

View File

@ -0,0 +1,6 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game screwdriver mod
---@class MtgScrewdriver
---@field disallow fun(): boolean Returns `false`

26
types/mtg-sfinv.lua Normal file
View File

@ -0,0 +1,26 @@
---@diagnostic disable: codestyle-check
---Sfinv API
---@class Sfinv
---@field register_page fun(name: string, def: SfinvDef): nil Register a page
---@field make_formspec fun(player: ObjectRef, contex: SfinvContext, content: string, show_inv?: boolean, size?: string): nil Adds a theme to a formspec show_inv, defaults to false. Whether to show the player's main inventory size, defaults to `size[8,8.6]` if not specified
---@field get_or_create_context fun(player: ObjectRef): SfinvContext Gets the player's context
---@field set_context fun(player: ObjectRef, context: SfinvContext): nil
---@field get_formspec fun(player: ObjectRef, context: SfinvContext): string Builds current page's formspec
---@field set_player_inventory_formspec fun(player: ObjectRef): string (re)builds page formspec and calls set_inventory_formspec().
---Sfinv Definition
---@class SfinvDef
---@field title string Human readable page name (required)
---@field get fun(self: Sfinv, player: ObjectRef, context: SfinvContext): string Returns a formspec string. See formspec variables. (required)
---@field is_in_nav fun(self: Sfinv, player: ObjectRef, context: SfinvContext): boolean Return true to show in the navigation (the tab header, by default)
---@field on_player_receive_fields fun(self: Sfinv, player: ObjectRef, context: SfinvContext, fields: table): nil On formspec submit.
---@field on_enter fun(self: Sfinv, player: ObjectRef, context: SfinvContext): nil Called when the player changes pages, usually using the tabs.
---@field on_leave fun(self: Sfinv, player: ObjectRef, context: SfinvContext): nil When leaving this page to go to another, called before other's on_enter
---Sfinv Context, including: any thing you want to store, sfinv will clear the stored data on log out / log in
---@class SfinvContext
---@field page string Current page name
---@field nav string[] A list of page names
---@field nav_titles string[] A list of page titles
---@field nav_idx number Current nav index (in nav and nav_titles)

View File

@ -0,0 +1,6 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Minetest game stairs mod
---@class MtgStairs
---@field register_stair_and_slab fun(subname: string, recipeitem?: string, groups: GroupCapsDef, images: NodeTilesDef, desc_stair: string, desc_slab: string, sounds: NodeSoundDef, worldaligntex?: boolean, desc_stair_inner?: string, desc_stair_outer?: string): nil `subname`: Basically the material name (e.g. cobble) used for the stair name. Nodename pattern: "stairs:stair_subname", `recipeitem`: Item used in the craft recipe, e.g. "default:cobble", may be `nil`, `groups`: damage and digging time defining groups, `worldaligntex`: A bool to set all textures world-aligned. Default false.

59
types/node.type.lua Normal file
View File

@ -0,0 +1,59 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---@alias NodeDef NodeDefAbstract | NodeDefMtgFarming
---Node definition. Used by `minetest.register_node`.
---@class NodeDefAbstract
---@field name string
---@field next_plant string|nil
---@field liquidtype 'none'|'source'|'flowing' specifies liquid flowing physics, "none": no liquid flowing physics, "source": spawns flowing liquid nodes at all 4 sides and below; recommended drawtype: "liquid". "flowing": spawned from source, spawns more flowing liquid nodes around it until `liquid_range` is reached; will drain out without a source; recommended drawtype: "flowingliquid". If it's "source" or "flowing" and `liquid_range > 0`, then both `liquid_alternative_*` fields must be specified
---@field on_rightclick fun(pos: Vector, node: NodeDef, clicker: ObjectRef, itemstack: ItemStack, pointed_thing?: PointedThingDef): ItemStack default: nil, Called when clicker (an ObjectRef) used the 'place/build' key not neccessarily an actual rightclick) while pointing at the node at pos with 'node' being the node table. itemstack will hold clicker's wielded item. Shall return the leftover itemstack. Note: pointed_thing can be nil, if a mod calls this function. This function does not get triggered by clients <=0.4.16 if the "formspec" node metadata field is set.
---@field place_param2 number Value for param2 that is set when player places node
---@field param2 number Value for param2 that is set when player places node
---@field buildable_to boolean If true, placed nodes can replace this node. default: `false`
---@field tiles string|NodeTilesDef Textures of node; +Y, -Y, +X, -X, +Z, -Z. List can be shortened to needed length.
---@field sound NodeSoundDef Definition of node sounds to be played at various events.
---@field drawtype NodeDrawTypes
---@field liquid_viscosity number|integer Controls speed at which the liquid spreads/flows (max. 7).
-- 0 is fastest, 7 is slowest. By default, this also slows down movement of players inside the node (can be overridden using `move_resistance`)
---@field walkable boolean If true, objects collide with node.
---@field after_dig_node fun(pos: Vector, oldnode: NodeDef, oldmetadata: table, digger: ObjectRef): nil oldmetadata is in table format. Called after destructing node when node was dug using minetest.node_dig / minetest.dig_node., default: nil
---@field paramtype2 string
---@field can_dig fun(pos: Vector, player?: ObjectRef): boolean | nil Returns true if node can be dug, or false if not.default: nil
---@field on_rotate fun(pos: Vector, node: table, user: ObjectRef, mode: table, new_param2: string): boolean Only for screwdriver mod.
---@field on_construct fun(pos: Vector): nil Node constructor; called after adding node. Can set up metadata and stuff like that. Not called for bulk node placement (i.e. schematics and VoxelManip). default: nil
---@field after_place_node fun(pos: Vector, placer: ObjectRef | nil, itemstack: ItemStack, pointed_thing: PointedThingDef): boolean | nil Called after constructing node when node was placed using minetest.item_place_node / minetest.place_node. If return true no item is taken from itemstack. `placer` may be any valid ObjectRef or nil. 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_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.
---Textures of node; +Y, -Y, +X, -X, +Z, -Z. List can be shortened to needed length.
---@class NodeTilesDef
---@field name string
---@field animation TileAnimationDef
---@field backface_culling boolean backface culling enabled by default for most nodes
---@field align_style 'node'|'world'|'user' align style determines whether the texture will be rotated with the node or kept aligned with its surroundings. "user" means that client setting will be used, similar to `glasslike_framed_optional`. Note: supported by solid nodes and nodeboxes only.
---@field scale number|integer scale is used to make texture span several (exactly `scale`) nodes, instead of just one, in each direction. Works for world-aligned textures only. Note that as the effect is applied on per-mapblock basis, `16` should be equally divisible by `scale` or you may get wrong results.
---@field color ColorSpec the texture's color will be multiplied with this color. the tile's color overrides the owning node's color in all cases.
---There are a bunch of different looking node types. `*_optional` drawtypes need less rendering time if deactivated (always client-side).
---@alias NodeDrawTypes
---| '"normal"' # A node-sized cube.
---| '"airlike"' # Invisible, uses no texture.
---| '"liquid"' # The cubic source node for a liquid. Faces bordering to the same node are never rendered. Connects to node specified in `liquid_alternative_flowing`. Use `backface_culling = false` for the tiles you want to make visible when inside the node.
---| '"flowingliquid"' # The flowing version of a liquid, appears with various heights and slopes. Faces bordering to the same node are never rendered. Connects to node specified in `liquid_alternative_source`. Node textures are defined with `special_tiles` where the first tile is for the top and bottom faces and the second tile is for the side faces. `tiles` is used for the item/inventory/wield image rendering. Use `backface_culling = false` for the special tiles you want to make visible when inside the node
---| '"glasslike"' # Often used for partially-transparent nodes. Only external sides of textures are visible.
---| '"glasslike_framed"' # All face-connected nodes are drawn as one volume within a surrounding frame. The frame appearance is generated from the edges of the first texture specified in `tiles`. The width of the edges used are 1/16th of texture size: 1 pixel for 16x16, 2 pixels for 32x32 etc. The glass 'shine' (or other desired detail) on each node face is supplied by the second texture specified in `tiles`.
---| '"glasslike_framed_optional"' # This switches between the above 2 drawtypes according to the menu setting 'Connected Glass'.
---| '"allfaces"' # Often used for partially-transparent nodes. External and internal sides of textures are visible.
---| '"allfaces_optional"' # Often used for leaves nodes. This switches between `normal`, `glasslike` and `allfaces` according to the menu setting: Opaque Leaves / Simple Leaves / Fancy Leaves. With 'Simple Leaves' selected, the texture specified in `special_tiles` is used instead, if present. This allows a visually thicker texture to be used to compensate for how `glasslike` reduces visual thickness.
---| '"torchlike"' # A single vertical texture. If `paramtype2="[color]wallmounted"`: If placed on top of a node, uses the first texture specified in `tiles`. If placed against the underside of a node, uses the second texture specified in `tiles`. If placed on the side of a node, uses the third texture specified in `tiles` and is perpendicular to that node. If `paramtype2="none"`: Will be rendered as if placed on top of a node (see above) and only the first texture is used.
---| '"signlike"' # A single texture parallel to, and mounted against, the top, underside or side of a node. If `paramtype2="[color]wallmounted"`, it rotates according to `param2` If `par
---| '"plantlike"' # Two vertical and diagonal textures at right-angles to each other. See `paramtype2 = "meshoptions"` above for other options.
---| '"firelike"' # When above a flat surface, appears as 6 textures, the central 2 as `plantlike` plus 4 more surrounding those. If not above a surface the central 2 do not appear, but the texture appears against the faces of surrounding nodes if they are present.
---| '"fencelike"' # A 3D model suitable for a wooden fence. One placed node appears as a single vertical post. Adjacently-placed nodes cause horizontal bars to appear between them.
---| '"raillike"' # Often used for tracks for mining carts. Requires 4 textures to be specified in `tiles`, in order: Straight, curved, t-junction, crossing. Each placed node automatically switches to a suitable rotated texture determined by the adjacent `raillike` nodes, in order to create a continuous track network. Becomes a sloping node if placed against stepped nodes.
---| '"nodebox"' # Often used for stairs and slabs. Allows defining nodes consisting of an arbitrary number of boxes. See [Node boxes] below for more information.
---| '"mesh"' # Uses models for nodes. Tiles should hold model materials textures. Only static meshes are implemented. For supported model formats see Irrlicht engine documentation.
---| '"plantlike_rooted"' # Enables underwater `plantlike` without air bubbles around the nodes. Consists of a base cube at the co-ordinates of the node plus a `plantlike` extension above If `paramtype2="leveled", the `plantlike` extension has a height of `param2 / 16` nodes, otherwise it's the height of 1 node If `paramtype2="wallmounted"`, the `plantlike` extension will be at one of the corresponding 6 sides of the base cube. Also, the base cube rotates like a `normal` cube would The `plantlike` extension visually passes through any nodes above the base cube without affecting them. The base cube texture tiles are defined as normal, the `plantlike` extension uses the defined special tile, for example: `special_tiles = {{name = "default_papyrus.png"}},`

12
types/nodetimer.type.lua Normal file
View File

@ -0,0 +1,12 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Node Timers: a high resolution persistent per-node timer. Can be gotten via `minetest.get_node_timer(pos)`.
---@class NodeTimerRef
---@field set fun(self: NodeTimerRef, timeout: integer|number, elapsed: integer|number): nil Set a timer's state. `timeout` is in seconds, and supports fractional values (0.1 etc). `elapsed` is in seconds, and supports fractional values (0.1 etc). Will trigger the node's `on_timer` function after `(timeout - elapsed)` seconds.
---@field start fun(self: NodeTimerRef, timeout: integer|number): nil Start a timer. Equivalent to `set(timeout,0)`.
---@field stop fun(): nil Stops the timer
---@field get_timeout fun(): number|integer Returns current timeout in seconds.
---@field get_elapsed fun(): number|integer Returns current elapsed time in seconds.
---@field is_started fun(): boolean Returns boolean state of timer. Returns `true` if timer is started, otherwise `false`.
---@field get_meta fun(pos: Vector): MetaDataRef Get a `NodeMetaRef` at that position

89
types/object.type.lua Normal file
View File

@ -0,0 +1,89 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---@alias ObjectRef ObjectRefAbstract | ObjectRefLuaEntityRef
---Moving things in the game are generally these.
---This is basically a reference to a C++ `ServerActiveObject`.
---@class ObjectRefAbstract
---@field get_pos fun(): Vector Position of player
---@field get_inventory fun(): InvRef|nil Returns an `InvRef` for players, otherwise returns `nil`
---@field get_wield_index fun(): integer Returns the index of the wielded item
---@field get_wielded_item fun(): ItemStack Returns an `ItemStack`
---@field set_acceleration fun(self: ObjectRef, acc: Vector): nil
---@field set_yaw fun(self: ObjectRef, yaw: integer|number): nil Sets the yaw in radians (heading).
---@field get_player_name fun(self: ObjectRef): string Returns `""` if is not a player.
---@field set_fov fun(self: ObjectRef, fov: number|integer, is_multiplier: boolean, transition_time: number|integer): nil Sets player's FOV. `fov`: FOV value. `is_multiplier`: Set to `true` if the FOV value is a multiplier. Defaults to `false`. `transition_time`: If defined, enables smooth FOV transition. Interpreted as the time (in seconds) to reach target FOV. If set to 0, FOV change is instantaneous. Defaults to 0. Set `fov` to 0 to clear FOV override.
---@field get_hp fun(self: ObjectRef): number|integer Returns number of health points
---@field is_player fun(self: ObjectRef): boolean returns true for players, false otherwise
---@field get_luaentity fun(self: ObjectRef): table
---@field get_armor_groups fun(self: ObjectRef): ObjectRefArmorGroups returns a table with the armor group ratings
---@field punch fun(self: ObjectRef, puncher: ObjectRef, time_from_last_punch: integer|number, tool_capabilities: ToolCapabilitiesDef, direction: Vector|nil): nil
---@field add_velocity fun(self: ObjectRef, vel: Vector): nil `vel` is a vector, e.g. `{x=0.0, y=2.3, z=1.0}`. In comparison to using get_velocity, adding the velocity and then using set_velocity, add_velocity is supposed to avoid synchronization problems. Additionally, players also do not support set_velocity. If a player: Does not apply during free_move. Note that since the player speed is normalized at each move step, increasing e.g. Y velocity beyond what would usually be achieved (see: physics overrides) will cause existing X/Z velocity to be reduced. Example: `add_velocity({x=0, y=6.5, z=0})` is equivalent to pressing the jump key (assuming default settings)
---@field get_properties fun(self: ObjectRef): table Returns object property table
---@field get_children fun(self: ObjectRef): ObjectRef[] Returns a list of ObjectRefs that are attached to the object.
---@field set_properties fun(self: ObjectRef, object_properties: ObjectProperties): nil For entities; disables the regular damage mechanism for players punching it by hand or a non-tool item, so that it can do something else than take damage.
---@field get_look_dir fun(self: ObjectRef): Vector get camera direction as a unit vector
---@field get_meta fun(self: ObjectRef): MetaDataRef returns a PlayerMetaRef.
---@field hud_add fun(self: ObjectRef, hud_definition: table): number|integer|nil add a HUD element described by HUD def, returns ID number on success
---@field hud_remove fun(self: ObjectRef, id: number|integer): nil remove the HUD element of the specified id
---@field hud_change fun(self: ObjectRef, id: number|integer, stat: string, value: any): nil change a value of a previously added HUD element. `stat` supports the same keys as in the hud definition table except for `"hud_elem_type"`.
---@field set_wielded_item fun(self: ObjectRef, item: ItemStack): boolean replaces the wielded item, returns `true` if successful.
---@field move_to fun(self: ObjectRef, pos: Vector, continuous?: boolean): nil Does an interpolated move for Lua entities for visually smooth transitions. If `continuous` is true, the Lua entity will not be moved to the current position before starting the interpolated move. For players this does the same as `set_pos`,`continuous` is ignored.
---@field set_hp fun(self: ObjectRef, hp: number, reason: table): nil set number of health points See reason in register_on_player_hpchange Is limited to the range of 0 ... 65535 (2^16 - 1) For players: HP are also limited by `hp_max` specified in object properties
---@field set_animation fun(self: ObjectRef, frame_range?: {["x"]: number, ["y"]: number}, frame_speed?: number, frame_blend?: number, frame_loop?: boolean): nil `frame_range`: table {x=num, y=num}, default: `{x=1, y=1}`, `frame_speed`: number, default: `15.0`, `frame_blend`: number, default: `0.0`, `frame_loop`: boolean, default: `true`
---@field get_velocity fun(self: ObjectRef): Vector returns the velocity, a vector.
---@field set_rotation fun(self: ObjectRef, rot: Vector): nil `rot` is a vector (radians). X is pitch (elevation), Y is yaw (heading) and Z is roll (bank).
---@field set_pos fun(self: ObjectRef, pos: Vector): nil
---Moving things in the game are generally these.
---This is basically a reference to a C++ `ServerActiveObject`.
---@class ObjectRefLuaEntityRef
---@field set_velocity fun(self: ObjectRef, vel: Vector): nil `vel` is a vector, e.g. `{x=0.0, y=2.3, z=1.0}`
---@field remove fun(): nil remove object, The object is removed after returning from Lua. However the `ObjectRef` itself instantly becomes unusable with all further method calls having no effect and returning `nil`.
---@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 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.
---`ObjectRef` armor groups
---@class ObjectRefArmorGroups
---@field immortal number|integer Skips all damage and breath handling for an object. This group will also hide the integrated HUD status bars for players. It is automatically set to all players when damage is disabled on the server and cannot be reset (subject to change).
---@field fall_damage_add_percent number|integer Modifies the fall damage suffered by players when they hit the ground. It is analog to the node group with the same name. See the node group above for the exact calculation.
---@field punch_operable number|integer For entities; disables the regular damage mechanism for players punching it by hand or a non-tool item, so that it can do something else than take damage.
---Used by `ObjectRef` methods. Part of an Entity definition. These properties are not persistent, but are applied automatically to the corresponding Lua entity using the given registration fields. Player properties need to be saved manually.
---@class ObjectProperties
---@field hp_max integer Defines the maximum and default HP of the entity. For Lua entities the maximum is not enforced. For players this defaults to `minetest.PLAYER_MAX_HP_DEFAULT`.
---@field breath_max integer For players only. Defaults to `minetest.PLAYER_MAX_BREATH_DEFAULT`.
---@field zoom_fov number For players only. Zoom FOV in degrees. Note that zoom loads and/or generates world beyond the server's maximum send and generate distances, so acts like a telescope. Smaller zoom_fov values increase the distance loaded/generated. Defaults to 15 in creative mode, 0 in survival mode. zoom_fov = 0 disables zooming for the player.
---@field eye_height number For players only. Camera height above feet position in nodes.
---@field physical boolean Collide with `walkable` nodes.
---@field collide_with_objects boolean Collide with other objects if physical = true
---@field collisionbox number[]|integer[]
---@field selectionbox number[]|integer[] Selection box uses collision box dimensions when not set. For both boxes: {xmin, ymin, zmin, xmax, ymax, zmax} in nodes from object position.
---@field pointable boolean Whether the object can be pointed at
---@field visual 'cube'|'sprite'|'upright_sprite'|'mesh'|'wielditem'|'item' "cube" is a node-sized cube. "sprite" is a flat texture always facing the player. "upright_sprite" is a vertical flat texture. "mesh" uses the defined mesh model. "wielditem" is used for dropped items. (see builtin/game/item_entity.lua). For this use 'wield_item = itemname' (Deprecated: 'textures = {itemname}'). If the item has a 'wield_image' the object will be an extrusion of that, otherwise: If 'itemname' is a cubic node or nodebox the object will appear identical to 'itemname'. If 'itemname' is a plantlike node the object will be an extrusion of its texture. Otherwise for non-node items, the object will be an extrusion of 'inventory_image'. If 'itemname' contains a ColorString or palette index (e.g. from `minetest.itemstring_with_palette()`), the entity will inherit the color. "item" is similar to "wielditem" but ignores the 'wield_image' parameter.
---@field visual_size {['x']: integer|number, ['y']: integer|number, ['z']: integer|number} Multipliers for the visual size. If `z` is not specified, `x` will be used to scale the entity along both horizontal axes.
---@field mesh string File name of mesh when using "mesh" visual
---@field textures table Number of required textures depends on visual. "cube" uses 6 textures just like a node, but all 6 must be defined. "sprite" uses 1 texture. "upright_sprite" uses 2 textures: {front, back}. "wielditem" expects 'textures = {itemname}'. "mesh" requires one texture for each mesh buffer/material (in order)
---@field colors table Number of required colors depends on visual
---@field use_texture_alpha boolean Use texture's alpha channel. Excludes "upright_sprite" and "wielditem". Note: currently causes visual issues when viewed through other semi-transparent materials such as water.
---@field spritediv {['x']: integer|number, ['y']: integer|number} Used with spritesheet textures for animation and/or frame selection according to position relative to player. Defines the number of columns and rows in the spritesheet: {columns, rows}.
---@field initial_sprite_basepos {['x']: integer|number, ['y']: integer|number} Used with spritesheet textures. Defines the {column, row} position of the initially used frame in the spritesheet.
---@field is_visible boolean If false, object is invisible and can't be pointed.
---@field makes_footstep_sound boolean If true, is able to make footstep sounds of nodes
---@field automatic_rotate number|integer Set constant rotation in radians per second, positive or negative. Object rotates along the local Y-axis, and works with set_rotation. Set to 0 to disable constant rotation.
---@field stepheight number|integer If positive number, object will climb upwards when it moves horizontally against a `walkable` node, if the height difference is within `stepheight`.
---@field automatic_face_movement_dir number|integer Automatically set yaw to movement direction, offset in degrees. 'false' to disable.
---@field automatic_face_movement_max_rotation_per_sec number|integer Limit automatic rotation to this value in degrees per second. No limit if value <= 0.
---@field backface_culling boolean Set to false to disable backface_culling for model
---@field glow number|integer Add this much extra lighting when calculating texture color. Value < 0 disables light's effect on texture color. For faking self-lighting, UI style entities, or programmatic coloring in mods.
---@field nametag string The name to display on the head of the object. By default empty. If the object is a player, a nil or empty nametag is replaced by the player's name. For all other objects, a nil or empty string removes the nametag. To hide a nametag, set its color alpha to zero. That will disable it entirely.
---@field nametag_color ColorSpec Sets text color of nametag
---@field nametag_bgcolor ColorSpec Sets background color of nametag `false` will cause the background to be set automatically based on user settings. Default: false
---@field infotext string Same as infotext for nodes. Empty by default
---@field static_save boolean If false, never save this object statically. It will simply be deleted when the block gets unloaded. The get_staticdata() callback is never called then. Defaults to 'true'.
---@field damage_texture_modifier string Texture modifier to be applied for a short duration when object is hit
---@field shaded boolean Setting this to 'false' disables diffuse lighting of entity
---@field show_on_minimap boolean Defaults to true for players, false for other entities. If set to true the entity will show as a marker on the minimap.

View File

@ -0,0 +1,50 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
--- ParticleSpawner definition
---@class ParticlespawnerDef
---@field amount number|integer Number of particles spawned over the time period `time`.
---@field time number|integer Lifespan of spawner in seconds. If time is 0 spawner has infinite lifespan and spawns the `amount` on a per-second basis.
---@field collisiondetection boolean If true collide with `walkable` nodes and, depending on the `object_collision` field, objects too.
---@field collision_removal boolean If true particles are removed when they collide. Requires collisiondetection = true to have any effect.
---@field object_collision boolean If true particles collide with objects that are defined as `physical = true,` and `collide_with_objects = true,`. Requires collisiondetection = true to have any effect.
---@field attached ObjectRef If defined, particle positions, velocities and accelerations are relative to this object's position and yaw
---@field vertical boolean If true face player using y axis only
---@field texture string The texture of the particle. e,g, `"image.png"`
---@field playername string Optional, if specified spawns particles only on the player's client
---@field animation TileAnimationDef Optional, specifies how to animate the particles' texture. v5.6.0 and later: set length to -1 to sychronize the length of the animation with the expiration time of individual particles. (-2 causes the animation to be played twice, and so on)
---@field glow number|integer Optional, specify particle self-luminescence in darkness. Values 0-14.
---@field node table<string, string|number|integer> e.g. `{name = "ignore", param2 = 0}`. Optional, if specified the particles will have the same appearance as node dig particles for the given node. Texture` and `animation` will be ignored if this is set.
---@field node_tile number|integer Optional, only valid in combination with `node`. If set to a valid number 1-6, specifies the tile from which the particle texture is picked. Otherwise, the default behavior is used. (currently: any random tile)
---@field minpos Vector Legacy definition field
---@field maxpos Vector Legacy definition field
---@field minvel Vector Legacy definition field
---@field maxvel Vector Legacy definition field
---@field minacc Vector Legacy definition field
---@field maxacc Vector Legacy definition field
---@field minexptime number|integer Legacy definition field
---@field maxexptime number|integer Legacy definition field
---@field minsize number|integer Legacy definition field
---@field maxsize number|integer Legacy definition field
---@field pos number|integer|Vector|ParticlespawnerPosDef As `number`: absolute value - all components of every particle's position vector will be set to this. As `Vector`: vec3 - all particles will appear at this exact position throughout the lifetime of the particlespawner. As `ParticlespawnerPosDef`: vec3 range - the particle will appear at a position that is picked at random from within a cubic range.
--- ParticleSpawner pos definition
---@class ParticlespawnerPosDef
---@field min Vector The minimum value this property will be set to in particles spawned by the generator.
---@field max Vector The maximum value this property will be set to in particles spawned by the generator.
---@field bias number|integer When `bias` is 0, all random values are exactly as likely as any other. When it is positive, the higher it is, the more likely values will appear towards the minimum end of the allowed spectrum. When it is negative, the lower it is, the more likely values will appear towards the maximum end of the allowed spectrum. The curve is exponential and there is no particular maximum or minimum value.
---@field pos_tween ParticlespawnerPosTweenDef A tween table should consist of a list of frames in the same form as the untweened pos property above, which the engine will interpolate between, and optionally a number of properties that control how the interpolation takes place. Currently **only two frames**, the first and the last, are used, but extra frames are accepted for the sake of forward compatibility. Any of the above definition styles can be used here as well in any combination supported by the property type.
--- ParticleSpawner pos_tween definition
---@class ParticlespawnerPosTweenDef
---@field style string e.g. "fwd": linear animation from first to last frame (default), "rev": linear animation from last to first frame, "pulse": linear animation from first to last then back to first again, "flicker": like "pulse", but slightly randomized to add a bit of stutter
---@field reps number|integer Number of times the animation is played over the particle's lifespan
---@field start number|integer Point in the spawner's lifespan at which the animation begins. 0 is the very beginning, 1 is the very end.
---@field frames number|integer|Vector|ParticlespawnerPosDef Frames can be defined in a number of different ways, depending on the underlying type of the property. For now, all but the first and last frame are ignored.
--- Tile animation definition
---@class TileAnimationDef
---@field type string e.g. "vertical_frames", "sheet_2d"
---@field aspect_w number|integer Width of a frame in pixels
---@field aspect_h number|integer Height of a frame in pixels
---@field length number|integer e.g. 3.0 Full loop length, 0.5 Length of a single frame

View File

@ -0,0 +1,12 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Pointed thing definition
---@class PointedThingDef
---@field type string e.g. `{type="nothing"}` `{type="node"}` `{type="object"}`
---@field under Vector Refers to the node position behind the pointed face.
---@field above Vector Refers to the node position in front of the pointed face.
---@field ref ObjectRef e.g. `{type="object", ref=ObjectRef}`
---@field intersection_point Vector Exact pointing location (currently only `Raycast` supports these field). The absolute world coordinates of the point on the selection box which is pointed at. May be in the selection box if the pointer is in the box too.
---@field box_id number|integer Exact pointing location (currently only `Raycast` supports these field). The ID of the pointed selection box (counting starts from 1).
---@field intersection_normal Vector Exact pointing location (currently only `Raycast` supports these field). Unit vector, points outwards of the selected selection box. This specifies which face is pointed at. Is a null vector `vector.zero()` when the pointer is inside the selection box.

6
types/raycast.type.lua Normal file
View File

@ -0,0 +1,6 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---A raycast on the map. It works with selection boxes. The map is loaded as the ray advances. If the map is modified after the `Raycast` is created, the changes may or may not have an effect on the object.
---@class Raycast
---@field next fun(): PointedThingDef Returns a `pointed_thing` with exact pointing location. Returns the next thing pointed by the ray or nil.

28
types/sound.type.lua Normal file
View File

@ -0,0 +1,28 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
---Specifies a sound name, gain (=volume) and pitch. This is either a string or a table. In string form, you just specify the sound name or the empty string for no sound.
---@class SimpleSoundSpec
---@field name string Sound name.
---@field gain number|integer Volume (`1.0` = 100%). Optional and default to `1.0`.
---@field pitch number|integer Pitch (`1.0` = 100%). Optional and default to `1.0`.
--- Definition of node sounds to be played at various events.
---@class NodeSoundDef
---@field name string Sound name.
---@field footstep SimpleSoundSpec If walkable, played when object walks on it. If node is climbable or a liquid, played when object moves through it
---@field dig SimpleSoundSpec|'__group' While digging node. If `"__group"`, then the sound will be `default_dig_<groupname>`, where `<groupname>` is the name of the item's digging group with the fastest digging time. In case of a tie, one of the sounds will be played (but we cannot predict which one) Default value: `"__group"`
---@field dug SimpleSoundSpec Node was dug
---@field place SimpleSoundSpec Node was placed. Also played after falling
---@field place_failed SimpleSoundSpec When node placement failed. Note: This happens if the _built-in_ node placement failed. This sound will still be played if the node is placed in the `on_place` callback manually.
---@field fall SimpleSoundSpec When node starts to fall or is detached
---Definition of item sounds to be played at various events. All fields in this table are optional.
---@class ItemSoundDef
---@field breaks SimpleSoundSpec|string When tool breaks due to wear. Ignored for non-tools
---@field eat SimpleSoundSpec|string When item is eaten with `minetest.do_item_eat`
---@field punch_use SimpleSoundSpec|string When item is used with the 'punch/mine' key pointing at a node or entity
---@field punch_use_air SimpleSoundSpec|string When item is used with the 'punch/mine' key pointing at nothing (air)
---Dig params definition.
---@class DigParamsDef

8
types/string.type.lua Normal file
View File

@ -0,0 +1,8 @@
---@diagnostic disable: codestyle-check, duplicate-doc-alias
---https://github.com/sumneko/lua-language-server/wiki
---@alias string string|StringAbstract
---String helpers
---@class StringAbstract
---@field split fun(self: string, str: string, separator?: string, include_empty?: boolean, max_splits?: number, sep_is_pattern?: boolean): table `separator`: string, default: `","`, `include_empty`: boolean, default: `false`, `max_splits`: number, if it's negative, splits aren't limited, default: `-1`, `sep_is_pattern`: boolean, it specifies whether separator is a plain string or a pattern (regex), default: `false`. e.g. `"a,b":split","` returns `{"a","b"}`

8
types/table.type.lua Normal file
View File

@ -0,0 +1,8 @@
---@diagnostic disable: codestyle-check, duplicate-doc-alias
---https://github.com/sumneko/lua-language-server/wiki
---@alias tablelib tablelib|TableAbstract
---Table helpers
---@class TableAbstract
---@field copy fun(table: table): table returns a deep copy of `table`

View File

@ -0,0 +1,8 @@
---@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

17
types/vector.type.lua Normal file
View File

@ -0,0 +1,17 @@
---@diagnostic disable: codestyle-check
---https://github.com/sumneko/lua-language-server/wiki
------All `vector.*` functions allow vectors `{x = X, y = Y, z = Z}` without metatables. Returned vectors always have a metatable set.
---@class Vector
---@field x integer|number Pitch
---@field y integer|number Yaw
---@field z integer|number Roll
---@field multiply fun(v: Vector, s: number|integer): Vector Returns a scaled vector. Deprecated: If `s` is a vector: Returns the Schur product.
---@field subtract fun(v: Vector, x: number|integer|Vector): Vector Returns a vector. If `x` is a vector: Returns the difference of `v` subtracted by `x`. If `x` is a number: Subtracts `x` from each component of `v`.
---@field add fun(v: Vector, x: number|integer|Vector): Vector Returns a vector. If `x` is a vector: Returns the sum of `v` and `x`. If `x` is a number: Adds `x` to each component of `v`.
---@field normalize fun(v: Vector): Vector Returns a vector of length 1 with direction of vector `v`. If `v` has zero length, returns `(0, 0, 0)`.
---@field distance fun(p1: Vector, p2: Vector): number|integer Returns zero or a positive number, the distance between `p1` and `p2`.
---@field round fun(v: Vector): Vector Returns a vector, each dimension rounded to nearest integer. At a multiple of 0.5, rounds away from zero.
---@field new fun(a, b?, c?): Vector Returns a new vector `(a, b, c)`.
---@field direction fun(p1: Vector, p2: Vector): Vector Returns a vector of length 1 with direction `p1` to `p2`. If `p1` and `p2` are identical, returns `(0, 0, 0)`.
---@field divide fun(v: Vector, s: Vector | number): Vector Returns a scaled vector. Deprecated: If `s` is a vector: Returns the Schur quotient.

View File

@ -0,0 +1,3 @@
---@diagnostic disable: codestyle-check
---Base class XBows
---@class XEnchanting