commit 479b0b2b233e4eaa8b0daeb13ea85c64b768b2b7 Author: Joachim Stolberg Date: Sun May 31 22:31:18 2020 +0200 built on 31/05/2020 22:31:18 diff --git a/autobahn/COPYING.txt b/autobahn/COPYING.txt new file mode 100644 index 0000000..5448574 --- /dev/null +++ b/autobahn/COPYING.txt @@ -0,0 +1,28 @@ +The autobahn mod for Minetest is + +Copyright (C) 2019-2020 Joachim Stolberg + +License of source code +---------------------- + +This mod is free software; you can redistribute and/or +modify it under the terms of the GNU General Public License version 3 or later +published by the Free Software Foundation. + +This mod 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 +General Public License for more details. + +You should have received a copy of the GNU General Public +License along with this mod; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301, USA. + + +License of media (textures, sounds and documentation) +----------------------------------------------------- + +All textures, sounds and documentation files are licensed under the +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/autobahn/LICENSE.txt b/autobahn/LICENSE.txt new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/autobahn/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, 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 +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/autobahn/README.md b/autobahn/README.md new file mode 100644 index 0000000..7cdeb1d --- /dev/null +++ b/autobahn/README.md @@ -0,0 +1,17 @@ +# Autobahn Mod + +Street blocks with stripes and slope blocks. Allows faster traveling. +For the recipe bitumen or tar is needed from the mods techage or moreblocks. + +![autobahn](https://github.com/joe7575/autobahn/blob/master/screenshot.png) + +## Dependencies +default +Optional: moreblocks, techage, minecart + +# License +Copyright (C) 2017-2020 Joachim Stolberg +Code: Licensed under the GNU GPL version 3 or later. See LICENSE.txt +Textures: CC BY-SA 3.0 + + diff --git a/autobahn/depends.txt b/autobahn/depends.txt new file mode 100644 index 0000000..f626f1b --- /dev/null +++ b/autobahn/depends.txt @@ -0,0 +1,4 @@ +default +moreblocks? +techage? +minecart? diff --git a/autobahn/description.txt b/autobahn/description.txt new file mode 100644 index 0000000..c4df034 --- /dev/null +++ b/autobahn/description.txt @@ -0,0 +1 @@ +Street mod for faster travelling. diff --git a/autobahn/init.lua b/autobahn/init.lua new file mode 100644 index 0000000..95c3962 --- /dev/null +++ b/autobahn/init.lua @@ -0,0 +1,376 @@ +--[[ + + Autobahn + + Copyright (C) 2017-2020 Joachim Stolberg + GPL v3 + See LICENSE.txt for more information + + History: + 2017-11-11 v0.01 first version + 2019-09-13 v0.02 adapted to 5.0.0 + 2020-03-19 v0.03 recipe added for techage bitumen + +]]-- + +autobahn = {} + +local Facedir2Dir = {[0] = + {x=0, y=0, z=1}, + {x=1, y=0, z=0}, + {x=0, y=0, z=-1}, + {x=-1, y=0, z=0}, +} + +-- To prevent race condition crashes +local Currently_left_the_game = {} + +local function is_active(player) + local pl_meta = player:get_meta() + if not pl_meta or pl_meta:get_int("autobahn_isactive") ~= 1 then + return false + end + return true +end + +local function set_player_privs(player) + local physics = player:get_physics_override() + local meta = player:get_meta() + if meta and physics then + -- store the player privs default values + meta:set_int("autobahn_speed", physics.speed) + -- set operator privs + meta:set_int("autobahn_isactive", 1) + physics.speed = 3.5 + minetest.sound_play("autobahn_motor", { + pos = player:get_pos(), + gain = 0.5, + max_hear_distance = 5, + }) + -- write back + player:set_physics_override(physics) + end +end + +local function reset_player_privs(player) + local physics = player:get_physics_override() + local meta = player:get_meta() + if meta and physics then + -- restore the player privs default values + meta:set_int("autobahn_isactive", 0) + physics.speed = meta:get_int("autobahn_speed") + if physics.speed == 0 then physics.speed = 1 end + -- delete stored default values + meta:set_string("autobahn_speed", "") + -- write back + player:set_physics_override(physics) + end +end + +minetest.register_on_joinplayer(function(player) + if is_active(player) then + reset_player_privs(player) + end +end) + +minetest.register_on_leaveplayer(function(player) + if is_active(player) then + Currently_left_the_game[player:get_player_name()] = true + end +end) + + +local function control_player(player) + local player_name = player:get_player_name() + if Currently_left_the_game[player_name] then + Currently_left_the_game[player_name] = nil + return + end + if player then + local pos = player:get_pos() + if pos then + --pos.y = math.floor(pos.y) + local node = minetest.get_node(pos) + if string.sub(node.name,1,13) == "autobahn:node" then + minetest.after(0.5, control_player, player) + else + pos.y = pos.y - 1 + node = minetest.get_node(pos) + if string.sub(node.name,1,13) == "autobahn:node" then + minetest.after(0.5, control_player, player) + else + reset_player_privs(player) + end + end + end + end +end + + +local NodeTbl1 = { + ["autobahn:node1"] = true, + ["autobahn:node2"] = true, + ["autobahn:node3"] = true, + ["autobahn:node4"] = true, + ["autobahn:node12"] = true, + ["autobahn:node22"] = true, + ["autobahn:node32"] = true, + ["autobahn:node42"] = true, +} +local NodeTbl2 = { + ["autobahn:node11"] = true, + ["autobahn:node21"] = true, + ["autobahn:node31"] = true, + ["autobahn:node41"] = true, +} + +-- 1) _o_ +-- /\ [?] ==> 1 +-- [T][T][S][S][S] T..tar +-- [S][S][S][S][S] S..sand +-- +-- +-- 2) _o_ +-- /\ [1][?] ==> 2 +-- [T][T][S][S][S] +-- [S][S][S][S][S] +-- +-- +-- 3) _o_ +-- /\ [?] ==> 1 +-- [S][S][S][T][T] +-- [S][S][S][S][S] +-- +-- +-- 4) _o_ +-- /\ [?][1] ==> 2 +-- [S][S][S][T][T] +-- [S][S][S][S][S] + +local function update_node(pos) + local node = minetest.get_node(pos) + local nnode + local npos + -- check case 1 + facedir = (2 + node.param2) % 4 + npos = vector.add(pos, Facedir2Dir[facedir]) + npos.y = npos.y - 1 + nnode = minetest.get_node(npos) + if NodeTbl1[nnode.name] then + node.name = node.name .. "1" + minetest.swap_node(pos, node) + return + end + -- check case 2 + npos.y = npos.y + 1 + nnode = minetest.get_node(npos) + if NodeTbl2[nnode.name] then + node.name = string.sub(node.name,1,-1) .. "2" + minetest.swap_node(pos, node) + return + end + -- check case 3 + facedir = (0 + node.param2) % 4 + npos = vector.add(pos, Facedir2Dir[facedir]) + npos.y = npos.y - 1 + nnode = minetest.get_node(npos) + if NodeTbl1[nnode.name] then + node.name = node.name .. "1" + node.param2 = 3 + minetest.swap_node(pos, node) + return + end + -- check case 4 + npos.y = npos.y + 1 + nnode = minetest.get_node(npos) + if NodeTbl2[nnode.name] then + node.name = string.sub(node.name,1,-1) .. "2" + node.param2 = 3 + minetest.swap_node(pos, node) + return + end +end + + +local function register_node(name, tiles, drawtype, mesh, box, drop) + minetest.register_node("autobahn:"..name, { + description = "Autobahn", + tiles = tiles, + drawtype = drawtype, + mesh = mesh, + selection_box = box, + collision_box = box, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + sounds = default.node_sound_stone_defaults(), + is_ground_content = false, + groups = {cracky=2, crumbly=2, not_in_creative_inventory=(mesh==nil) and 0 or 1}, + drop = "autobahn:"..drop, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + update_node(pos) + end, + + on_rightclick = function(pos, node, clicker) + if is_active(clicker) then + reset_player_privs(clicker) + else + set_player_privs(clicker) + minetest.after(0.5, control_player, clicker) + end + end, + }) +end + +local sb1 = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5}, + {-0.5, -0.375, -0.25, 0.5, -0.25, 0.5}, + {-0.5, -0.25, 0, 0.5, -0.125, 0.5}, + {-0.5, -0.125, 0.25, 0.5, 0, 0.5}, + } +} +local sb2 = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.125, 0.5}, + {-0.5, 0.125, -0.25, 0.5, 0.25, 0.5}, + {-0.5, 0.25, 0, 0.5, 0.375, 0.5}, + {-0.5, 0.375, 0.25, 0.5, 0.5, 0.5}, + } +} + +local Nodes = { + {name="node1", tiles={"autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node1"}, + {name="node2", tiles={"autobahn2.png","autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node2"}, + {name="node3", tiles={"autobahn3.png","autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node3"}, + {name="node4", tiles={"autobahn2.png^[transformR180]","autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node4"}, + {name="node5", tiles={"autobahn4.png^[transformR90]","autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node5"}, + {name="node6", tiles={"autobahn5.png^[transformR90]","autobahn1.png"}, drawtype="normal", mesh=nil, box=nil, drop="node6"}, + + {name="node11", tiles={"autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp1.obj", box=sb1, drop="node1"}, + {name="node21", tiles={"autobahn2.png","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp1.obj", box=sb1, drop="node2"}, + {name="node31", tiles={"autobahn3.png","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp1.obj", box=sb1, drop="node3"}, + {name="node41", tiles={"autobahn2.png^[transformR180]","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp1.obj", box=sb1, drop="node4"}, + + {name="node12", tiles={"autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp2.obj", box=sb2, drop="node1"}, + {name="node22", tiles={"autobahn2.png","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp2.obj", box=sb2, drop="node2"}, + {name="node32", tiles={"autobahn3.png","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp2.obj", box=sb2, drop="node3"}, + {name="node42", tiles={"autobahn2.png^[transformR180]","autobahn1.png"}, drawtype="mesh", mesh="autobahn_ramp2.obj", box=sb2, drop="node4"}, +} + +for _,item in ipairs(Nodes) do + register_node(item.name, item.tiles, item.drawtype, item.mesh, item.box, item.drop) +end + + +minetest.register_craftitem("autobahn:stripes", { + description = "Autobahn Stripe", + inventory_image = 'autobahn_stripes.png', +}) + + +if minetest.global_exists("techage") then + minetest.register_craft({ + output = "autobahn:node1 9", + recipe = { + {"techage:sieved_basalt_gravel", "techage:sieved_basalt_gravel", "techage:sieved_basalt_gravel"}, + {"techage:sieved_basalt_gravel", "techage:ta3_barrel_bitumen", "techage:sieved_basalt_gravel"}, + {"techage:sieved_basalt_gravel", "techage:sieved_basalt_gravel", "techage:sieved_basalt_gravel"}, + }, + replacements = {{"techage:ta3_barrel_bitumen", "techage:ta3_barrel_empty"}}, + }) + minetest.register_craft({ + output = "autobahn:node1 9", + recipe = { + {"techage:sieved_gravel", "techage:sieved_gravel", "techage:sieved_gravel"}, + {"techage:sieved_gravel", "techage:ta3_barrel_bitumen", "techage:sieved_gravel"}, + {"techage:sieved_gravel", "techage:sieved_gravel", "techage:sieved_gravel"}, + }, + replacements = {{"techage:ta3_barrel_bitumen", "techage:ta3_barrel_empty"}}, + }) +elseif minetest.global_exists("moreblocks") then + minetest.register_craft({ + output = "autobahn:node1 4", + recipe = { + {"moreblocks:tar", "moreblocks:tar"}, + {"default:cobble", "default:cobble"}, + }, + }) +end + +minetest.register_craft({ + output = "autobahn:stripes 8", + recipe = { + {"dye:white"}, + } +}) + + +minetest.register_craft({ + output = "autobahn:node2", + recipe = { + {"", "", "autobahn:stripes"}, + {"", "autobahn:node1", ""}, + } +}) + +minetest.register_craft({ + output = "autobahn:node3", + recipe = { + {"", "autobahn:stripes", ""}, + {"", "autobahn:node1", ""}, + } +}) + +minetest.register_craft({ + output = "autobahn:node4", + recipe = { + {"autobahn:stripes", "", ""}, + {"", "autobahn:node1", ""}, + } +}) + +minetest.register_craft({ + output = "autobahn:node5", + recipe = { + {"", "", ""}, + {"autobahn:stripes", "autobahn:node1", ""}, + } +}) + +minetest.register_craft({ + output = "autobahn:node6", + recipe = { + {"", "autobahn:stripes", ""}, + {"autobahn:stripes", "autobahn:node1", ""}, + } +}) + +if minetest.global_exists("minecart") then + minecart.register_protected_node("autobahn:node1") + minecart.register_protected_node("autobahn:node2") + minecart.register_protected_node("autobahn:node3") + minecart.register_protected_node("autobahn:node4") + minecart.register_protected_node("autobahn:node5") + minecart.register_protected_node("autobahn:node6") + minecart.register_protected_node("autobahn:node11") + minecart.register_protected_node("autobahn:node21") + minecart.register_protected_node("autobahn:node31") + minecart.register_protected_node("autobahn:node41") + minecart.register_protected_node("autobahn:node12") + minecart.register_protected_node("autobahn:node22") + minecart.register_protected_node("autobahn:node32") + minecart.register_protected_node("autobahn:node42") +end + + +------------------------------------------------------------------------------- +-- External API functions +------------------------------------------------------------------------------- + +-- Returns true if player is "driving" on the autobahn +-- func autobahn.is_driving(player) +autobahn.is_driving = is_active \ No newline at end of file diff --git a/autobahn/mod.conf b/autobahn/mod.conf new file mode 100644 index 0000000..9a48fb3 --- /dev/null +++ b/autobahn/mod.conf @@ -0,0 +1 @@ +name=autobahn diff --git a/autobahn/models/autobahn_ramp1.obj b/autobahn/models/autobahn_ramp1.obj new file mode 100644 index 0000000..1fa631c --- /dev/null +++ b/autobahn/models/autobahn_ramp1.obj @@ -0,0 +1,56 @@ +g top +v 0.500000 -0.000000 0.500000 +v -0.500000 -0.000000 0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 0.0000 0.8944 -0.4472 +s off +f 2/1/1 1/2/1 4/3/1 3/4/1 +g bottom +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 -0.500000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vn 0.0000 -1.0000 -0.0000 +s off +f 6/5/2 5/6/2 7/7/2 8/8/2 +g right +v -0.500000 -0.000000 0.500000 +v -0.500000 -0.500000 0.500000 +v -0.500000 -0.500000 -0.500000 +vt 1.0000 0.5000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn -1.0000 0.0000 0.0000 +s off +f 9/9/3 11/10/3 10/11/3 +g left +v 0.500000 -0.000000 0.500000 +v 0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 -0.500000 +vt 0.0000 0.5000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 1.0000 0.0000 0.0000 +s off +f 12/12/4 13/13/4 14/14/4 +g back +v 0.500000 -0.000000 0.500000 +v -0.500000 -0.000000 0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +vt 1.0000 0.5000 +vt 0.0000 0.5000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 0.0000 -0.0000 1.0000 +s off +f 15/15/5 16/16/5 17/17/5 18/18/5 diff --git a/autobahn/models/autobahn_ramp2.obj b/autobahn/models/autobahn_ramp2.obj new file mode 100644 index 0000000..86139d7 --- /dev/null +++ b/autobahn/models/autobahn_ramp2.obj @@ -0,0 +1,72 @@ +g top +v -0.500000 0.500000 0.500000 +v -0.500000 0.000000 -0.500000 +v 0.500000 0.000000 -0.500000 +v 0.500000 0.500000 0.500000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vn 0.0000 0.8944 -0.4472 +s off +f 2/1/1 1/2/1 4/3/1 3/4/1 +g bottom +v -0.500000 -0.500000 -0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 -0.500000 -0.500000 +v 0.500000 -0.500000 0.500000 +vt 1.0000 0.0000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vn 0.0000 -1.0000 -0.0000 +s off +f 6/5/2 5/6/2 7/7/2 8/8/2 +g right +v -0.500000 0.500000 0.500000 +v -0.500000 0.000000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v -0.500000 -0.500000 0.500000 +vt 1.0000 1.0000 +vt 0.0000 0.5000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn -1.0000 0.0000 0.0000 +s off +f 9/9/3 10/10/3 11/11/3 12/12/3 +g left +v 0.500000 0.000000 -0.500000 +v 0.500000 -0.500000 -0.500000 +v 0.500000 0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +vt 1.0000 0.5000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 1.0000 0.0000 0.0000 +s off +f 13/13/4 15/14/4 16/15/4 14/16/4 +g back +v -0.500000 0.500000 0.500000 +v -0.500000 -0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v 0.500000 -0.500000 0.500000 +vt 1.0000 1.0000 +vt 0.0000 1.0000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 0.0000 -0.0000 1.0000 +s off +f 19/17/5 17/18/5 18/19/5 20/20/5 +g front +v -0.500000 0.000000 -0.500000 +v -0.500000 -0.500000 -0.500000 +v 0.500000 0.000000 -0.500000 +v 0.500000 -0.500000 -0.500000 +vt 1.0000 0.5000 +vt 0.0000 0.5000 +vt 0.0000 0.0000 +vt 1.0000 0.0000 +vn 0.0000 0.0000 -1.0000 +s off +f 21/21/6 23/22/6 24/23/6 22/24/6 diff --git a/autobahn/screenshot.png b/autobahn/screenshot.png new file mode 100644 index 0000000..db4c3d2 Binary files /dev/null and b/autobahn/screenshot.png differ diff --git a/autobahn/sounds/autobahn_motor.ogg b/autobahn/sounds/autobahn_motor.ogg new file mode 100644 index 0000000..498304f Binary files /dev/null and b/autobahn/sounds/autobahn_motor.ogg differ diff --git a/autobahn/textures/autobahn1.png b/autobahn/textures/autobahn1.png new file mode 100644 index 0000000..0d5e4fb Binary files /dev/null and b/autobahn/textures/autobahn1.png differ diff --git a/autobahn/textures/autobahn2.png b/autobahn/textures/autobahn2.png new file mode 100644 index 0000000..8591ed9 Binary files /dev/null and b/autobahn/textures/autobahn2.png differ diff --git a/autobahn/textures/autobahn3.png b/autobahn/textures/autobahn3.png new file mode 100644 index 0000000..12e7037 Binary files /dev/null and b/autobahn/textures/autobahn3.png differ diff --git a/autobahn/textures/autobahn4.png b/autobahn/textures/autobahn4.png new file mode 100644 index 0000000..d2a1c8a Binary files /dev/null and b/autobahn/textures/autobahn4.png differ diff --git a/autobahn/textures/autobahn5.png b/autobahn/textures/autobahn5.png new file mode 100644 index 0000000..b794ace Binary files /dev/null and b/autobahn/textures/autobahn5.png differ diff --git a/autobahn/textures/autobahn_stripes.png b/autobahn/textures/autobahn_stripes.png new file mode 100644 index 0000000..03e3b48 Binary files /dev/null and b/autobahn/textures/autobahn_stripes.png differ diff --git a/basic_materials/LICENSE b/basic_materials/LICENSE new file mode 100644 index 0000000..c5885ae --- /dev/null +++ b/basic_materials/LICENSE @@ -0,0 +1,600 @@ +License for code: LGPL 3.0 +License for media and all other assets: CC-by-SA 4.0 + +############################################################################### + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + 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 that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU 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 as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + +############################################################################### + +Attribution-ShareAlike 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution-ShareAlike 4.0 International Public +License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution-ShareAlike 4.0 International Public License ("Public +License"). To the extent this Public License may be interpreted as a +contract, You are granted the Licensed Rights in consideration of Your +acceptance of these terms and conditions, and the Licensor grants You +such rights in consideration of benefits the Licensor receives from +making the Licensed Material available under these terms and +conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. BY-SA Compatible License means a license listed at + creativecommons.org/compatiblelicenses, approved by Creative + Commons as essentially the equivalent of this Public License. + + d. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + e. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + f. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + g. License Elements means the license attributes listed in the name + of a Creative Commons Public License. The License Elements of this + Public License are Attribution and ShareAlike. + + h. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + i. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + j. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + k. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + l. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + m. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part; and + + b. produce, reproduce, and Share Adapted Material. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. Additional offer from the Licensor -- Adapted Material. + Every recipient of Adapted Material from You + automatically receives an offer from the Licensor to + exercise the Licensed Rights in the Adapted Material + under the conditions of the Adapter's License You apply. + + c. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + b. ShareAlike. + + In addition to the conditions in Section 3(a), if You Share + Adapted Material You produce, the following conditions also apply. + + 1. The Adapter's License You apply must be a Creative Commons + license with the same License Elements, this version or + later, or a BY-SA Compatible License. + + 2. You must include the text of, or the URI or hyperlink to, the + Adapter's License You apply. You may satisfy this condition + in any reasonable manner based on the medium, means, and + context in which You Share Adapted Material. + + 3. You may not offer or impose any additional or different terms + or conditions on, or apply any Effective Technological + Measures to, Adapted Material that restrict exercise of the + rights granted under the Adapter's License You apply. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material, + + including for purposes of Section 3(b); and + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/basic_materials/electrical-electronic.lua b/basic_materials/electrical-electronic.lua new file mode 100644 index 0000000..91fac4e --- /dev/null +++ b/basic_materials/electrical-electronic.lua @@ -0,0 +1,86 @@ +-- Translation support +local S = minetest.get_translator("basic_materials") + +-- items + +minetest.register_craftitem("basic_materials:silicon", { + description = S("Silicon lump"), + inventory_image = "basic_materials_silicon.png", +}) + +minetest.register_craftitem("basic_materials:ic", { + description = S("Simple Integrated Circuit"), + inventory_image = "basic_materials_ic.png", +}) + +minetest.register_craftitem("basic_materials:motor", { + description = S("Simple Motor"), + inventory_image = "basic_materials_motor.png", +}) + +minetest.register_craftitem("basic_materials:heating_element", { + description = S("Heating element"), + inventory_image = "basic_materials_heating_element.png", +}) + +minetest.register_craftitem("basic_materials:energy_crystal_simple", { + description = S("Simple energy crystal"), + inventory_image = "basic_materials_energy_crystal.png", +}) + +-- crafts + +minetest.register_craft( { + output = "mesecons_materials:silicon 4", + recipe = { + { "default:sand", "default:sand" }, + { "default:sand", "default:steel_ingot" }, + }, +}) + +minetest.register_craft( { + output = "basic_materials:ic 4", + recipe = { + { "mesecons_materials:silicon", "mesecons_materials:silicon" }, + { "mesecons_materials:silicon", "default:copper_ingot" }, + }, +}) + +minetest.register_craft( { + output = "basic_materials:motor 2", + recipe = { + { "default:mese_crystal_fragment", "basic_materials:copper_wire", "basic_materials:plastic_sheet" }, + { "default:copper_ingot", "default:steel_ingot", "default:steel_ingot" }, + { "default:mese_crystal_fragment", "basic_materials:copper_wire", "basic_materials:plastic_sheet" } + }, + replacements = { + { "basic_materials:copper_wire", "basic_materials:empty_spool" }, + { "basic_materials:copper_wire", "basic_materials:empty_spool" }, + } +}) + +minetest.register_craft( { + output = "basic_materials:heating_element 2", + recipe = { + { "default:copper_ingot", "default:mese_crystal_fragment", "default:copper_ingot" } + }, +}) + +minetest.register_craft({ + --type = "shapeless", + output = "basic_materials:energy_crystal_simple 2", + recipe = { + { "default:mese_crystal_fragment", "default:torch", "default:mese_crystal_fragment" }, + { "default:diamond", "default:gold_ingot", "default:diamond" } + }, +}) + +-- aliases + +minetest.register_alias("homedecor:ic", "basic_materials:ic") +minetest.register_alias("homedecor:motor", "basic_materials:motor") +minetest.register_alias("technic:motor", "basic_materials:motor") +minetest.register_alias("homedecor:heating_element", "basic_materials:heating_element") +minetest.register_alias("homedecor:power_crystal", "basic_materials:energy_crystal_simple") + +minetest.register_alias_force("mesecons_materials:silicon", "basic_materials:silicon") diff --git a/basic_materials/init.lua b/basic_materials/init.lua new file mode 100644 index 0000000..32873a1 --- /dev/null +++ b/basic_materials/init.lua @@ -0,0 +1,14 @@ +-- Basic materials mod +-- by Vanessa Dannenberg + +-- This mod supplies all those little random craft items that everyone always +-- seems to need, such as metal bars (ala rebar), plastic, wire, and so on. + +local modpath = minetest.get_modpath("basic_materials") + +basic_materials = {} + +dofile(modpath.."/metals.lua") +dofile(modpath.."/plastics.lua") +dofile(modpath.."/electrical-electronic.lua") +dofile(modpath.."/misc.lua") diff --git a/basic_materials/locale/basic_materials.de.tr b/basic_materials/locale/basic_materials.de.tr new file mode 100644 index 0000000..e661fcd --- /dev/null +++ b/basic_materials/locale/basic_materials.de.tr @@ -0,0 +1,33 @@ +# textdomain: basic_materials +Silicon lump=Silikonklumpen +Simple Integrated Circuit=einfacher Integrierter Schaltkreis +Simple Motor=einfacher Motor +Heating element=Heizelement +Simple energy crystal=einfacher Energiekristall + +Spool of steel wire=Spule mit Stahldraht +Spool of copper wire=Spule mit Kupferdraht +Spool of silver wire=Spule mit Silberdraht +Spool of gold wire=Spule mit Golddraht +Steel Strip=Stahlstreifen +Copper Strip=Kupferstreifen +Steel Bar=Stahlstab +Chainlinks (brass)=Messing-Kettenglieder +Chainlinks (steel)=Stahl-Kettenglieder +Brass Ingot=Messingbarren +Steel gear=Stahlzahnrad +Padlock=Vorhängeschloss +Chain (steel, hanging)=Stahlkette +Chain (brass, hanging)=Messingkette +Brass Block=Messingblock + +Oil extract=raffiniertes Öl +Unprocessed paraffin=unbearbeitetes Paraffin +Uncooked Terracotta Base=ungebranntes Terrakotta +Wet Cement=nasser Zement +Cement=Zement +Concrete Block=Betonblock + +Plastic sheet=Kunststoffplatte +Plastic strips=Kunststoffstreifen +Empty wire spool=leere Drahtspule diff --git a/basic_materials/locale/basic_materials.fr.tr b/basic_materials/locale/basic_materials.fr.tr new file mode 100644 index 0000000..0bebf79 --- /dev/null +++ b/basic_materials/locale/basic_materials.fr.tr @@ -0,0 +1,33 @@ +# textdomain: basic_materials +Silicon lump=Morceau de silicium +Simple Integrated Circuit=Circuit intégré simple +Simple Motor=Moteur simple +Heating element=Élément chauffant +Simple energy crystal=Cristal d’énergie simple + +Spool of steel wire=Bobine de fil d’acier +Spool of copper wire=Bobine de fil de cuivre +Spool of silver wire=Bobine de fil d’argent +Spool of gold wire=Bobine de fil d’or +Steel Strip=Bande de acier +Copper Strip=Bande de cuivre +Steel Bar=Barre d’acier +Chainlinks (brass)=Maillon en laiton +Chainlinks (steel)=Maillon en acier +Brass Ingot=Lingot de laiton +Steel gear=Rouage en acier +Padlock=Cadenas +Chain (steel, hanging)=Chaine en acier +Chain (brass, hanging)=Chaine en laiton +Brass Block=Bloc de laiton + +Oil extract=Extrait d’huile +Unprocessed paraffin=Paraffine non transformée +Uncooked Terracotta Base=Argile crue +Wet Cement=Ciment humide +Cement=Ciment +Concrete Block=Bloc de béton + +Plastic sheet=Morceau de plastique +Plastic strips=Bande de plastique +Empty wire spool=Bobine de fil vide diff --git a/basic_materials/locale/basic_materials.ru.tr b/basic_materials/locale/basic_materials.ru.tr new file mode 100644 index 0000000..85e9c0c --- /dev/null +++ b/basic_materials/locale/basic_materials.ru.tr @@ -0,0 +1,33 @@ +# textdomain: basic_materials +Silicon lump=Кусок Кремния +Simple Integrated Circuit=Микросхема +Simple Motor=Мотор +Heating element=Нить Накала +Simple energy crystal=Энергетический Кристалл + +Spool of steel wire=Катушка Стальной Проволоки +Spool of copper wire=Катушка Медной Проволоки +Spool of silver wire=Катушка Серебрянной Проволоки +Spool of gold wire=Катушка Золотой Проволоки +Steel Strip=Стальная Полоса +Copper Strip=Медная Полоса +Steel Bar=Стальной Прут +Chainlinks (brass)=Латунные Звенья +Chainlinks (steel)=Стальные Звенья +Brass Ingot=Латунный Брусок +Steel gear=Стальная Шестерня +Padlock=Навесной Замок +Chain (steel, hanging)=Стальная Цепь +Chain (brass, hanging)=Латунная Цепь +Brass Block=Латунный Блок + +Oil extract=Масляный Экстракт +Unprocessed paraffin=Необработанный Парафин +Uncooked Terracotta Base=Ком Мокрого Терракота +Wet Cement=Ком Мокрого Цемента +Cement=Цемент +Concrete Block=Железобетон + +Plastic sheet=Пластиковый Лист +Plastic strips=Пластиковая Полоса +Empty wire spool=Пустая Катушка diff --git a/basic_materials/metals.lua b/basic_materials/metals.lua new file mode 100644 index 0000000..37685f8 --- /dev/null +++ b/basic_materials/metals.lua @@ -0,0 +1,300 @@ +-- Translation support +local S = minetest.get_translator("basic_materials") + +-- items + +minetest.register_craftitem("basic_materials:steel_wire", { + description = S("Spool of steel wire"), + inventory_image = "basic_materials_steel_wire.png" +}) + +minetest.register_craftitem("basic_materials:copper_wire", { + description = S("Spool of copper wire"), + inventory_image = "basic_materials_copper_wire.png" +}) + +minetest.register_craftitem("basic_materials:silver_wire", { + description = S("Spool of silver wire"), + inventory_image = "basic_materials_silver_wire.png" +}) + +minetest.register_craftitem("basic_materials:gold_wire", { + description = S("Spool of gold wire"), + inventory_image = "basic_materials_gold_wire.png" +}) + +minetest.register_craftitem("basic_materials:steel_strip", { + description = S("Steel Strip"), + inventory_image = "basic_materials_steel_strip.png" +}) + +minetest.register_craftitem("basic_materials:copper_strip", { + description = S("Copper Strip"), + inventory_image = "basic_materials_copper_strip.png" +}) + +minetest.register_craftitem("basic_materials:steel_bar", { + description = S("Steel Bar"), + inventory_image = "basic_materials_steel_bar.png", +}) + +minetest.register_craftitem("basic_materials:chainlink_brass", { + description = S("Chainlinks (brass)"), + inventory_image = "basic_materials_chainlink_brass.png" +}) + +minetest.register_craftitem("basic_materials:chainlink_steel", { + description = S("Chainlinks (steel)"), + inventory_image = "basic_materials_chainlink_steel.png" +}) + +minetest.register_craftitem("basic_materials:brass_ingot", { + description = S("Brass Ingot"), + inventory_image = "basic_materials_brass_ingot.png", +}) + +minetest.register_craftitem("basic_materials:gear_steel", { + description = S("Steel gear"), + inventory_image = "basic_materials_gear_steel.png" +}) + +minetest.register_craftitem("basic_materials:padlock", { + description = S("Padlock"), + inventory_image = "basic_materials_padlock.png" +}) + +-- nodes + +local chains_sbox = { + type = "fixed", + fixed = { -0.1, -0.5, -0.1, 0.1, 0.5, 0.1 } +} + +local topchains_sbox = { + type = "fixed", + fixed = { + { -0.25, 0.35, -0.25, 0.25, 0.5, 0.25 }, + { -0.1, -0.5, -0.1, 0.1, 0.4, 0.1 } + } +} + +minetest.register_node("basic_materials:chain_steel", { + description = S("Chain (steel, hanging)"), + drawtype = "mesh", + mesh = "basic_materials_chains.obj", + tiles = {"basic_materials_chain_steel.png"}, + walkable = false, + climbable = true, + sunlight_propagates = true, + paramtype = "light", + inventory_image = "basic_materials_chain_steel_inv.png", + groups = {cracky=3}, + selection_box = chains_sbox, +}) + +minetest.register_node("basic_materials:chain_brass", { + description = S("Chain (brass, hanging)"), + drawtype = "mesh", + mesh = "basic_materials_chains.obj", + tiles = {"basic_materials_chain_brass.png"}, + walkable = false, + climbable = true, + sunlight_propagates = true, + paramtype = "light", + inventory_image = "basic_materials_chain_brass_inv.png", + groups = {cracky=3}, + selection_box = chains_sbox, +}) + +minetest.register_node("basic_materials:brass_block", { + description = S("Brass Block"), + tiles = { "basic_materials_brass_block.png" }, + is_ground_content = false, + groups = {cracky=1, level=2}, + sounds = default.node_sound_metal_defaults() +}) + +-- crafts + +minetest.register_craft( { + output = "basic_materials:copper_wire 2", + type = "shapeless", + recipe = { + "default:copper_ingot", + "basic_materials:empty_spool", + "basic_materials:empty_spool", + }, +}) + +minetest.register_craft( { + output = "basic_materials:silver_wire 2", + type = "shapeless", + recipe = { + "moreores:silver_ingot", + "basic_materials:empty_spool", + "basic_materials:empty_spool", + }, +}) + +minetest.register_craft( { + output = "basic_materials:gold_wire 2", + type = "shapeless", + recipe = { + "default:gold_ingot", + "basic_materials:empty_spool", + "basic_materials:empty_spool", + }, +}) + +minetest.register_craft( { + output = "basic_materials:steel_wire 2", + type = "shapeless", + recipe = { + "default:steel_ingot", + "basic_materials:empty_spool", + "basic_materials:empty_spool", + }, +}) + +minetest.register_craft( { + output = "basic_materials:steel_strip 12", + recipe = { + { "", "default:steel_ingot", "" }, + { "default:steel_ingot", "", "" }, + }, +}) + +minetest.register_craft( { + output = "basic_materials:copper_strip 12", + recipe = { + { "", "default:copper_ingot", "" }, + { "default:copper_ingot", "", "" }, + }, +}) + +minetest.register_craft( { + output = "basic_materials:steel_bar 6", + recipe = { + { "", "", "default:steel_ingot" }, + { "", "default:steel_ingot", "" }, + { "default:steel_ingot", "", "" }, + }, +}) + +minetest.register_craft( { + output = "basic_materials:padlock 2", + recipe = { + { "basic_materials:steel_bar" }, + { "default:steel_ingot" }, + { "default:steel_ingot" }, + }, +}) + +minetest.register_craft({ + output = "basic_materials:chainlink_steel 12", + recipe = { + {"", "default:steel_ingot", "default:steel_ingot"}, + { "default:steel_ingot", "", "default:steel_ingot" }, + { "default:steel_ingot", "default:steel_ingot", "" }, + }, +}) + +minetest.register_craft({ + output = "basic_materials:chainlink_brass 12", + recipe = { + {"", "basic_materials:brass_ingot", "basic_materials:brass_ingot"}, + { "basic_materials:brass_ingot", "", "basic_materials:brass_ingot" }, + { "basic_materials:brass_ingot", "basic_materials:brass_ingot", "" }, + }, +}) + +minetest.register_craft({ + output = 'basic_materials:chain_steel 2', + recipe = { + {"basic_materials:chainlink_steel"}, + {"basic_materials:chainlink_steel"}, + {"basic_materials:chainlink_steel"} + } +}) + +minetest.register_craft({ + output = 'basic_materials:chain_brass 2', + recipe = { + {"basic_materials:chainlink_brass"}, + {"basic_materials:chainlink_brass"}, + {"basic_materials:chainlink_brass"} + } +}) + +minetest.register_craft( { + output = "basic_materials:gear_steel 6", + recipe = { + { "", "default:steel_ingot", "" }, + { "default:steel_ingot","basic_materials:chainlink_steel", "default:steel_ingot" }, + { "", "default:steel_ingot", "" } + }, +}) + +minetest.register_craft( { + type = "shapeless", + output = "basic_materials:brass_ingot 3", + recipe = { + "default:copper_ingot", + "default:copper_ingot", + "moreores:silver_ingot", + }, +}) + +if not minetest.get_modpath("moreores") then + -- Without moreores, there still should be a way to create brass. + minetest.register_craft( { + output = "basic_materials:brass_ingot 9", + recipe = { + {"default:copper_ingot", "default:tin_ingot", "default:copper_ingot"}, + {"default:gold_ingot", "default:copper_ingot", "default:gold_ingot"}, + {"default:copper_ingot", "default:tin_ingot", "default:copper_ingot"}, + }, + }) +end + +minetest.register_craft( { + type = "shapeless", + output = "basic_materials:brass_ingot 9", + recipe = { "basic_materials:brass_block" }, +}) + +minetest.register_craft( { + output = "basic_materials:brass_block", + recipe = { + { "basic_materials:brass_ingot", "basic_materials:brass_ingot", "basic_materials:brass_ingot" }, + { "basic_materials:brass_ingot", "basic_materials:brass_ingot", "basic_materials:brass_ingot" }, + { "basic_materials:brass_ingot", "basic_materials:brass_ingot", "basic_materials:brass_ingot" }, + }, +}) + +-- aliases + +minetest.register_alias("homedecor:copper_wire", "basic_materials:copper_wire") +minetest.register_alias("technic:fine_copper_wire", "basic_materials:copper_wire") +minetest.register_alias("technic:fine_silver_wire", "basic_materials:silver_wire") +minetest.register_alias("technic:fine_gold_wire", "basic_materials:gold_wire") + +minetest.register_alias("homedecor:steel_wire", "basic_materials:steel_wire") + +minetest.register_alias("homedecor:brass_ingot", "basic_materials:brass_ingot") +minetest.register_alias("technic:brass_ingot", "basic_materials:brass_ingot") +minetest.register_alias("technic:brass_block", "basic_materials:brass_block") + +minetest.register_alias("homedecor:copper_strip", "basic_materials:copper_strip") +minetest.register_alias("homedecor:steel_strip", "basic_materials:steel_strip") + +minetest.register_alias_force("glooptest:chainlink", "basic_materials:chainlink_steel") +minetest.register_alias_force("homedecor:chainlink_steel", "basic_materials:chainlink_steel") +minetest.register_alias("homedecor:chainlink_brass", "basic_materials:chainlink_brass") +minetest.register_alias("chains:chain", "basic_materials:chain_steel") +minetest.register_alias("chains:chain_brass", "basic_materials:chain_brass") + +minetest.register_alias("pipeworks:gear", "basic_materials:gear_steel") + +minetest.register_alias("technic:rebar", "basic_materials:steel_bar") + diff --git a/basic_materials/misc.lua b/basic_materials/misc.lua new file mode 100644 index 0000000..0012897 --- /dev/null +++ b/basic_materials/misc.lua @@ -0,0 +1,126 @@ +-- Translation support +local S = minetest.get_translator("basic_materials") + +-- items + +minetest.register_craftitem("basic_materials:oil_extract", { + description = S("Oil extract"), + inventory_image = "basic_materials_oil_extract.png", +}) + +minetest.register_craftitem("basic_materials:paraffin", { + description = S("Unprocessed paraffin"), + inventory_image = "basic_materials_paraffin.png", +}) + +minetest.register_craftitem("basic_materials:terracotta_base", { + description = S("Uncooked Terracotta Base"), + inventory_image = "basic_materials_terracotta_base.png", +}) + +minetest.register_craftitem("basic_materials:wet_cement", { + description = S("Wet Cement"), + inventory_image = "basic_materials_wet_cement.png", +}) + +-- nodes + +minetest.register_node("basic_materials:cement_block", { + description = S("Cement"), + tiles = {"basic_materials_cement_block.png"}, + is_ground_content = true, + groups = {cracky=2}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_node("basic_materials:concrete_block", { + description = S("Concrete Block"), + tiles = {"basic_materials_concrete_block.png",}, + groups = {cracky=1, level=2, concrete=1}, + sounds = default.node_sound_stone_defaults(), +}) + +-- crafts + +minetest.register_craft({ + type = "shapeless", + output = "basic_materials:oil_extract 2", + recipe = { + "group:leaves", + "group:leaves", + "group:leaves", + "group:leaves", + "group:leaves", + "group:leaves" + } +}) + +minetest.register_craft({ + type = "cooking", + output = "basic_materials:paraffin", + recipe = "basic_materials:oil_extract", +}) + +minetest.register_craft({ + type = "fuel", + recipe = "basic_materials:oil_extract", + burntime = 30, +}) + +minetest.register_craft({ + type = "fuel", + recipe = "basic_materials:paraffin", + burntime = 30, +}) + +minetest.register_craft( { + type = "shapeless", + output = "basic_materials:terracotta_base 8", + recipe = { + "bucket:bucket_water", + "default:clay_lump", + "default:gravel", + }, + replacements = { {"bucket:bucket_water", "bucket:bucket_empty"}, }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "basic_materials:wet_cement 3", + recipe = { + "default:dirt", + "dye:dark_grey", + "dye:dark_grey", + "dye:dark_grey", + "bucket:bucket_water" + }, + replacements = {{'bucket:bucket_water', 'bucket:bucket_empty'},}, +}) + +minetest.register_craft({ + type = "cooking", + output = "basic_materials:cement_block", + recipe = "basic_materials:wet_cement", + cooktime = 8 +}) + +minetest.register_craft({ + output = 'basic_materials:concrete_block 6', + recipe = { + {'group:sand', 'basic_materials:wet_cement', 'default:gravel'}, + {'basic_materials:steel_bar', 'basic_materials:wet_cement', 'basic_materials:steel_bar'}, + {'default:gravel', 'basic_materials:wet_cement', 'group:sand'}, + } +}) + +-- aliases + +minetest.register_alias("homedecor:oil_extract", "basic_materials:oil_extract") +minetest.register_alias("homedecor:paraffin", "basic_materials:paraffin") +minetest.register_alias("homedecor:plastic_base", "basic_materials:paraffin") +minetest.register_alias("homedecor:terracotta_base", "basic_materials:terracotta_base") + +minetest.register_alias("gloopblocks:wet_cement", "basic_materials:wet_cement") +minetest.register_alias("gloopblocks:cement", "basic_materials:cement_block") + +minetest.register_alias("technic:concrete", "basic_materials:concrete_block") diff --git a/basic_materials/mod.conf b/basic_materials/mod.conf new file mode 100644 index 0000000..4b58eba --- /dev/null +++ b/basic_materials/mod.conf @@ -0,0 +1,3 @@ +name = basic_materials +depends = default +optional_depends = moreores diff --git a/basic_materials/models/basic_materials_chains.obj b/basic_materials/models/basic_materials_chains.obj new file mode 100644 index 0000000..78724c9 --- /dev/null +++ b/basic_materials/models/basic_materials_chains.obj @@ -0,0 +1,881 @@ +# Blender v2.73 (sub 0) OBJ File: 'chains.blend' +# www.blender.org +o Torus.016_Torus +v 0.000000 -0.429978 0.000002 +v 0.000000 -0.401109 0.055211 +v -0.014044 -0.391975 0.048870 +v -0.014044 -0.423304 0.000002 +v -0.009826 -0.379748 0.040970 +v -0.009826 -0.406012 0.000002 +v 0.009826 -0.379748 0.040970 +v 0.009826 -0.406012 0.000002 +v 0.014044 -0.391975 0.048870 +v 0.014044 -0.423304 0.000002 +v 0.000000 -0.316336 0.080195 +v -0.014044 -0.316336 0.069112 +v -0.009826 -0.316336 0.057941 +v 0.009826 -0.316336 0.057941 +v 0.014044 -0.316336 0.069112 +v 0.000000 -0.231564 0.055211 +v -0.014044 -0.240700 0.048870 +v -0.009826 -0.252925 0.040970 +v 0.009826 -0.252925 0.040970 +v 0.014044 -0.240700 0.048870 +v 0.000000 -0.202695 0.000002 +v -0.014044 -0.209368 0.000002 +v -0.009826 -0.226661 0.000002 +v 0.009826 -0.226661 0.000002 +v 0.014044 -0.209368 0.000002 +v 0.000000 -0.231564 -0.055206 +v -0.014044 -0.240700 -0.048868 +v -0.009826 -0.252925 -0.040967 +v 0.009826 -0.252925 -0.040967 +v 0.014044 -0.240700 -0.048865 +v 0.000000 -0.316336 -0.080190 +v -0.014044 -0.316336 -0.069108 +v -0.009826 -0.316336 -0.057936 +v 0.009826 -0.316336 -0.057936 +v 0.014044 -0.316336 -0.069108 +v 0.000000 -0.400361 -0.055206 +v -0.014044 -0.391975 -0.048868 +v -0.009826 -0.379748 -0.040967 +v 0.009826 -0.379748 -0.040967 +v 0.014044 -0.391975 -0.048868 +v 0.000000 -0.262249 0.000002 +v -0.061672 -0.233381 0.000002 +v -0.054590 -0.224245 -0.012569 +v 0.000000 -0.255577 -0.012569 +v -0.045765 -0.212018 -0.008794 +v 0.000000 -0.238285 -0.008794 +v -0.045765 -0.212018 0.008798 +v 0.000000 -0.238285 0.008798 +v -0.054590 -0.224245 0.012574 +v 0.000000 -0.255577 0.012574 +v -0.089582 -0.148609 0.000002 +v -0.077200 -0.148609 -0.012569 +v -0.064722 -0.148609 -0.008794 +v -0.064722 -0.148609 0.008799 +v -0.077200 -0.148609 0.012574 +v -0.061672 -0.063837 0.000002 +v -0.054590 -0.072971 -0.012569 +v -0.045765 -0.085198 -0.008794 +v -0.045765 -0.085198 0.008799 +v -0.054590 -0.072971 0.012574 +v 0.000000 -0.034967 0.000002 +v 0.000000 -0.041641 -0.012569 +v 0.000000 -0.058933 -0.008794 +v 0.000000 -0.058933 0.008799 +v 0.000000 -0.041641 0.012574 +v 0.061672 -0.063837 0.000002 +v 0.054590 -0.072971 -0.012569 +v 0.045765 -0.085198 -0.008794 +v 0.045765 -0.085198 0.008799 +v 0.054590 -0.072971 0.012574 +v 0.089582 -0.148609 0.000002 +v 0.077200 -0.148609 -0.012569 +v 0.064722 -0.148609 -0.008794 +v 0.064722 -0.148609 0.008799 +v 0.077200 -0.148609 0.012574 +v 0.061672 -0.232631 0.000002 +v 0.054590 -0.224245 -0.012569 +v 0.045765 -0.212018 -0.008794 +v 0.045765 -0.212018 0.008798 +v 0.054590 -0.224245 0.012574 +v 0.000000 0.073316 0.000002 +v 0.061672 0.102183 0.000002 +v 0.054590 0.111319 0.012574 +v 0.000000 0.079988 0.012574 +v 0.045765 0.123546 0.008799 +v 0.000000 0.097280 0.008799 +v 0.045765 0.123546 -0.008794 +v 0.000000 0.097280 -0.008794 +v 0.054590 0.111319 -0.012569 +v 0.000000 0.079988 -0.012569 +v 0.089582 0.186956 0.000002 +v 0.077200 0.186956 0.012574 +v 0.064722 0.186956 0.008799 +v 0.064722 0.186956 -0.008794 +v 0.077200 0.186956 -0.012569 +v 0.061672 0.271728 0.000002 +v 0.054590 0.262594 0.012574 +v 0.045765 0.250367 0.008799 +v 0.045765 0.250367 -0.008794 +v 0.054590 0.262594 -0.012569 +v 0.000000 0.300597 0.000002 +v 0.000000 0.293923 0.012574 +v 0.000000 0.276631 0.008799 +v 0.000000 0.276631 -0.008794 +v 0.000000 0.293923 -0.012569 +v -0.061672 0.271728 0.000002 +v -0.054590 0.262594 0.012574 +v -0.045765 0.250367 0.008799 +v -0.045765 0.250367 -0.008794 +v -0.054590 0.262594 -0.012569 +v -0.089582 0.186956 0.000002 +v -0.077200 0.186956 0.012574 +v -0.064722 0.186956 0.008799 +v -0.064722 0.186956 -0.008794 +v -0.077200 0.186956 -0.012569 +v -0.061672 0.102931 0.000002 +v -0.054590 0.111319 0.012574 +v -0.045765 0.123546 0.008799 +v -0.045765 0.123546 -0.008794 +v -0.054590 0.111319 -0.012569 +v 0.000000 -0.095037 0.000002 +v 0.000000 -0.066168 -0.055206 +v 0.014044 -0.057034 -0.048868 +v 0.014044 -0.088363 0.000002 +v 0.009826 -0.044807 -0.040967 +v 0.009826 -0.071071 0.000002 +v -0.009826 -0.044807 -0.040967 +v -0.009826 -0.071071 0.000002 +v -0.014044 -0.057034 -0.048868 +v -0.014044 -0.088363 0.000002 +v 0.000000 0.018605 -0.080190 +v 0.014044 0.018605 -0.069108 +v 0.009826 0.018605 -0.057936 +v -0.009826 0.018605 -0.057936 +v -0.014044 0.018605 -0.069108 +v 0.000000 0.103377 -0.055206 +v 0.014044 0.094243 -0.048868 +v 0.009826 0.082016 -0.040967 +v -0.009826 0.082016 -0.040967 +v -0.014044 0.094243 -0.048868 +v 0.000000 0.132246 0.000002 +v 0.014044 0.125572 0.000002 +v 0.009826 0.108280 0.000002 +v -0.009826 0.108280 0.000002 +v -0.014044 0.125572 0.000002 +v 0.000000 0.103377 0.055211 +v 0.014044 0.094243 0.048870 +v 0.009826 0.082016 0.040970 +v -0.009826 0.082016 0.040970 +v -0.014044 0.094243 0.048870 +v 0.000000 0.018605 0.080195 +v 0.014044 0.018605 0.069112 +v 0.009826 0.018605 0.057941 +v -0.009826 0.018605 0.057941 +v -0.014044 0.018605 0.069112 +v 0.000000 -0.065420 0.055211 +v 0.014044 -0.057032 0.048870 +v 0.009826 -0.044807 0.040970 +v -0.009826 -0.044807 0.040970 +v -0.014044 -0.057032 0.048870 +v 0.000000 -0.598329 0.000002 +v 0.061672 -0.569460 0.000002 +v 0.054590 -0.560326 0.012574 +v 0.000000 -0.591655 0.012574 +v 0.045765 -0.548099 0.008798 +v 0.000000 -0.574363 0.008798 +v 0.045765 -0.548099 -0.008794 +v 0.000000 -0.574363 -0.008794 +v 0.054590 -0.560326 -0.012569 +v 0.000000 -0.591655 -0.012569 +v 0.089582 -0.484687 0.000002 +v 0.077200 -0.484687 0.012574 +v 0.064722 -0.484687 0.008798 +v 0.064722 -0.484687 -0.008794 +v 0.077200 -0.484687 -0.012569 +v 0.061672 -0.399915 0.000002 +v 0.054590 -0.409051 0.012574 +v 0.045765 -0.421278 0.008798 +v 0.045765 -0.421278 -0.008794 +v 0.054590 -0.409051 -0.012569 +v 0.000000 -0.371048 0.000002 +v 0.000000 -0.377719 0.012574 +v 0.000000 -0.395012 0.008798 +v 0.000000 -0.395012 -0.008794 +v 0.000000 -0.377719 -0.012569 +v -0.061672 -0.399915 0.000002 +v -0.054590 -0.409051 0.012574 +v -0.045765 -0.421278 0.008798 +v -0.045765 -0.421278 -0.008794 +v -0.054590 -0.409051 -0.012569 +v -0.089582 -0.484687 0.000002 +v -0.077200 -0.484687 0.012574 +v -0.064722 -0.484687 0.008798 +v -0.064722 -0.484687 -0.008794 +v -0.077200 -0.484687 -0.012569 +v -0.061672 -0.568712 0.000002 +v -0.054590 -0.560326 0.012574 +v -0.045765 -0.548099 0.008798 +v -0.045765 -0.548099 -0.008794 +v -0.054590 -0.560326 -0.012569 +v 0.000000 0.241043 0.000002 +v 0.000000 0.269910 0.055211 +v -0.014044 0.279047 0.048870 +v -0.014044 0.247717 0.000002 +v -0.009826 0.291274 0.040970 +v -0.009826 0.265007 0.000002 +v 0.009826 0.291274 0.040970 +v 0.009826 0.265007 0.000002 +v 0.014044 0.279047 0.048870 +v 0.014044 0.247717 0.000002 +v 0.000000 0.354683 0.080195 +v -0.014044 0.354683 0.069112 +v -0.009826 0.354683 0.057941 +v 0.009826 0.354683 0.057941 +v 0.014044 0.354683 0.069112 +v 0.000000 0.439455 0.055211 +v -0.014044 0.430321 0.048870 +v -0.009826 0.418094 0.040970 +v 0.009826 0.418094 0.040970 +v 0.014044 0.430321 0.048870 +v 0.000000 0.468325 0.000002 +v -0.014044 0.461651 0.000002 +v -0.009826 0.444361 0.000002 +v 0.009826 0.444361 0.000002 +v 0.014044 0.461651 0.000002 +v 0.000000 0.439455 -0.055206 +v -0.014044 0.430321 -0.048868 +v -0.009826 0.418094 -0.040967 +v 0.009826 0.418094 -0.040967 +v 0.014044 0.430321 -0.048868 +v 0.000000 0.354683 -0.080190 +v -0.014044 0.354683 -0.069108 +v -0.009826 0.354683 -0.057936 +v 0.009826 0.354683 -0.057936 +v 0.014044 0.354683 -0.069108 +v 0.000000 0.270661 -0.055206 +v -0.014044 0.279047 -0.048868 +v -0.009826 0.291274 -0.040967 +v 0.009826 0.291274 -0.040967 +v 0.014044 0.279047 -0.048868 +vt 0.187500 0.125000 +vt 0.250000 0.125000 +vt 0.250000 0.187500 +vt 0.187500 0.187500 +vt 0.250000 0.250000 +vt 0.187500 0.250000 +vt 0.250000 0.312500 +vt 0.187500 0.312500 +vt 0.250000 0.375000 +vt 0.187500 0.375000 +vt 0.187500 0.062500 +vt 0.250000 0.062500 +vt 0.312500 0.125000 +vt 0.312500 0.187500 +vt 0.312500 0.250000 +vt 0.312500 0.312500 +vt 0.312500 0.375000 +vt 0.312500 0.062500 +vt 0.375000 0.125000 +vt 0.375000 0.187500 +vt 0.375000 0.250000 +vt 0.375000 0.312500 +vt 0.375000 0.375000 +vt 0.375000 0.062500 +vt 0.437500 0.125000 +vt 0.437500 0.187500 +vt 0.437500 0.250000 +vt 0.437500 0.312500 +vt 0.437500 0.375000 +vt 0.437500 0.062500 +vt 0.500000 0.125000 +vt 0.500000 0.187500 +vt 0.500000 0.250000 +vt 0.500000 0.312500 +vt 0.500000 0.375000 +vt 0.500000 0.062500 +vt -0.000000 0.125000 +vt 0.062500 0.125000 +vt 0.062500 0.187500 +vt -0.000000 0.187500 +vt 0.062500 0.250000 +vt -0.000000 0.250000 +vt 0.062500 0.312500 +vt -0.000000 0.312500 +vt 0.062500 0.375000 +vt -0.000000 0.375000 +vt -0.000000 0.062500 +vt 0.062500 0.062500 +vt 0.125000 0.125000 +vt 0.125000 0.187500 +vt 0.125000 0.250000 +vt 0.125000 0.312500 +vt 0.125000 0.375000 +vt 0.125000 0.062500 +vt 0.750000 0.625000 +vt 0.812500 0.625000 +vt 0.812500 0.687500 +vt 0.750000 0.687500 +vt 0.750000 0.375000 +vt 0.812500 0.375000 +vt 0.812500 0.437500 +vt 0.750000 0.437500 +vt 0.812500 0.500000 +vt 0.750000 0.500000 +vt 0.812500 0.562500 +vt 0.750000 0.562500 +vt 0.875000 0.625000 +vt 0.875000 0.687500 +vt 0.875000 0.375000 +vt 0.875000 0.437500 +vt 0.875000 0.500000 +vt 0.875000 0.562500 +vt 0.937500 0.625000 +vt 0.937500 0.687500 +vt 0.937500 0.375000 +vt 0.937500 0.437500 +vt 0.937500 0.500000 +vt 0.937500 0.562500 +vt 1.000000 0.625000 +vt 1.000000 0.687500 +vt 1.000000 0.375000 +vt 1.000000 0.437500 +vt 1.000000 0.500000 +vt 1.000000 0.562500 +vt 0.500000 0.625000 +vt 0.562500 0.625000 +vt 0.562500 0.687500 +vt 0.500000 0.687500 +vt 0.562500 0.375000 +vt 0.562500 0.437500 +vt 0.500000 0.437500 +vt 0.562500 0.500000 +vt 0.500000 0.500000 +vt 0.562500 0.562500 +vt 0.500000 0.562500 +vt 0.625000 0.625000 +vt 0.625000 0.687500 +vt 0.625000 0.375000 +vt 0.625000 0.437500 +vt 0.625000 0.500000 +vt 0.625000 0.562500 +vt 0.687500 0.625000 +vt 0.687500 0.687500 +vt 0.687500 0.375000 +vt 0.687500 0.437500 +vt 0.687500 0.500000 +vt 0.687500 0.562500 +vt 0.250000 0.625000 +vt 0.312500 0.625000 +vt 0.312500 0.687500 +vt 0.250000 0.687500 +vt 0.312500 0.437500 +vt 0.250000 0.437500 +vt 0.312500 0.500000 +vt 0.250000 0.500000 +vt 0.312500 0.562500 +vt 0.250000 0.562500 +vt 0.375000 0.625000 +vt 0.375000 0.687500 +vt 0.375000 0.437500 +vt 0.375000 0.500000 +vt 0.375000 0.562500 +vt 0.437500 0.625000 +vt 0.437500 0.687500 +vt 0.437500 0.437500 +vt 0.437500 0.500000 +vt 0.437500 0.562500 +vt -0.000000 0.625000 +vt 0.062500 0.625000 +vt 0.062500 0.687500 +vt -0.000000 0.687500 +vt 0.062500 0.437500 +vt -0.000000 0.437500 +vt 0.062500 0.500000 +vt -0.000000 0.500000 +vt 0.062500 0.562500 +vt -0.000000 0.562500 +vt 0.125000 0.625000 +vt 0.125000 0.687500 +vt 0.125000 0.437500 +vt 0.125000 0.500000 +vt 0.125000 0.562500 +vt 0.187500 0.625000 +vt 0.187500 0.687500 +vt 0.187500 0.437500 +vt 0.187500 0.500000 +vt 0.187500 0.562500 +vt 0.687500 0.750000 +vt 0.750000 0.750000 +vt 0.750000 0.812500 +vt 0.687500 0.812500 +vt 0.750000 0.875000 +vt 0.687500 0.875000 +vt 0.750000 0.937500 +vt 0.687500 0.937500 +vt 0.750000 1.000000 +vt 0.687500 1.000000 +vt 0.812500 0.750000 +vt 0.812500 0.812500 +vt 0.812500 0.875000 +vt 0.812500 0.937500 +vt 0.812500 1.000000 +vt 0.875000 0.750000 +vt 0.875000 0.812500 +vt 0.875000 0.875000 +vt 0.875000 0.937500 +vt 0.875000 1.000000 +vt 0.937500 0.750000 +vt 0.937500 0.812500 +vt 0.937500 0.875000 +vt 0.937500 0.937500 +vt 0.937500 1.000000 +vt 1.000000 0.750000 +vt 1.000000 0.812500 +vt 1.000000 0.875000 +vt 1.000000 0.937500 +vt 1.000000 1.000000 +vt 0.500000 0.750000 +vt 0.562500 0.750000 +vt 0.562500 0.812500 +vt 0.500000 0.812500 +vt 0.562500 0.875000 +vt 0.500000 0.875000 +vt 0.562500 0.937500 +vt 0.500000 0.937500 +vt 0.562500 1.000000 +vt 0.500000 1.000000 +vt 0.625000 0.750000 +vt 0.625000 0.812500 +vt 0.625000 0.875000 +vt 0.625000 0.937500 +vt 0.625000 1.000000 +vt 0.750000 0.312500 +vt 0.812500 0.312500 +vt 0.750000 0.062500 +vt 0.812500 0.062500 +vt 0.812500 0.125000 +vt 0.750000 0.125000 +vt 0.812500 0.187500 +vt 0.750000 0.187500 +vt 0.812500 0.250000 +vt 0.750000 0.250000 +vt 0.875000 0.312500 +vt 0.875000 0.062500 +vt 0.875000 0.125000 +vt 0.875000 0.187500 +vt 0.875000 0.250000 +vt 0.937500 0.312500 +vt 0.937500 0.062500 +vt 0.937500 0.125000 +vt 0.937500 0.187500 +vt 0.937500 0.250000 +vt 1.000000 0.312500 +vt 1.000000 0.062500 +vt 1.000000 0.125000 +vt 1.000000 0.187500 +vt 1.000000 0.250000 +vt 0.562500 0.312500 +vt 0.562500 0.062500 +vt 0.562500 0.125000 +vt 0.562500 0.187500 +vt 0.562500 0.250000 +vt 0.625000 0.312500 +vt 0.625000 0.062500 +vt 0.625000 0.125000 +vt 0.625000 0.187500 +vt 0.625000 0.250000 +vt 0.687500 0.312500 +vt 0.687500 0.062500 +vt 0.687500 0.125000 +vt 0.687500 0.187500 +vt 0.687500 0.250000 +vt 0.250000 0.937500 +vt 0.312500 0.937500 +vt 0.312500 1.000000 +vt 0.250000 1.000000 +vt 0.312500 0.750000 +vt 0.250000 0.750000 +vt 0.312500 0.812500 +vt 0.250000 0.812500 +vt 0.312500 0.875000 +vt 0.250000 0.875000 +vt 0.375000 0.937500 +vt 0.375000 1.000000 +vt 0.375000 0.750000 +vt 0.375000 0.812500 +vt 0.375000 0.875000 +vt 0.437500 0.937500 +vt 0.437500 1.000000 +vt 0.437500 0.750000 +vt 0.437500 0.812500 +vt 0.437500 0.875000 +vt 0.000000 0.937500 +vt 0.062500 0.937500 +vt 0.062500 1.000000 +vt 0.000000 1.000000 +vt 0.062500 0.750000 +vt 0.000000 0.750000 +vt 0.062500 0.812500 +vt 0.000000 0.812500 +vt 0.062500 0.875000 +vt 0.000000 0.875000 +vt 0.125000 0.937500 +vt 0.125000 1.000000 +vt 0.125000 0.750000 +vt 0.125000 0.812500 +vt 0.125000 0.875000 +vt 0.187500 0.937500 +vt 0.187500 1.000000 +vt 0.187500 0.750000 +vt 0.187500 0.812500 +vt 0.187500 0.875000 +vn 0.000000 -1.000000 -0.004800 +vn 0.000000 -0.657400 0.753500 +vn -0.898300 -0.248500 0.362300 +vn -0.863600 -0.504100 -0.003400 +vn -0.661500 0.421500 -0.620200 +vn -0.746000 0.665900 0.000000 +vn 0.661500 0.421500 -0.620200 +vn 0.746000 0.665900 0.000000 +vn 0.898300 -0.248500 0.362300 +vn 0.863600 -0.504100 -0.003400 +vn 0.000000 0.000000 1.000000 +vn -0.925200 0.000000 0.379500 +vn -0.617100 0.000000 -0.786900 +vn 0.617100 0.000000 -0.786900 +vn 0.925200 0.000000 0.379500 +vn 0.000000 0.657400 0.753500 +vn -0.898300 0.248400 0.362300 +vn -0.661500 -0.421500 -0.620200 +vn 0.661500 -0.421500 -0.620200 +vn 0.898300 0.248400 0.362300 +vn 0.000000 1.000000 0.000000 +vn -0.866100 0.499800 0.000000 +vn -0.746000 -0.665900 0.000000 +vn 0.746000 -0.665900 0.000000 +vn 0.866100 0.499800 0.000000 +vn 0.000000 0.657400 -0.753500 +vn -0.898300 0.248400 -0.362400 +vn -0.661600 -0.421500 0.620200 +vn 0.661500 -0.421500 0.620200 +vn 0.898300 0.248400 -0.362300 +vn 0.000000 -0.000900 -1.000000 +vn -0.924600 -0.000600 -0.380700 +vn -0.617100 0.000000 0.786900 +vn 0.617100 0.000000 0.786900 +vn 0.924700 -0.000600 -0.380700 +vn 0.000000 -0.650300 -0.759600 +vn -0.895600 -0.254600 -0.364800 +vn -0.661600 0.421500 0.620200 +vn 0.661600 0.421500 0.620200 +vn 0.895600 -0.254600 -0.364800 +vn 0.004900 -1.000000 0.000000 +vn -0.729700 -0.683800 0.000000 +vn -0.324500 -0.256300 -0.910500 +vn 0.003300 -0.475500 -0.879700 +vn 0.578700 0.436200 -0.689100 +vn 0.000000 0.666600 -0.745400 +vn 0.578700 0.436200 0.689100 +vn 0.000000 0.666600 0.745400 +vn -0.324500 -0.256300 0.910500 +vn 0.003300 -0.475500 0.879700 +vn -1.000000 0.000000 0.000000 +vn -0.359600 0.000000 -0.933100 +vn 0.756400 0.000000 -0.654100 +vn 0.756400 0.000000 0.654100 +vn -0.359600 0.000000 0.933100 +vn -0.729700 0.683700 0.000000 +vn -0.324500 0.256300 -0.910500 +vn 0.578700 -0.436200 -0.689100 +vn 0.578700 -0.436200 0.689100 +vn -0.324500 0.256300 0.910500 +vn 0.000000 0.470900 -0.882200 +vn 0.000000 -0.666600 -0.745400 +vn 0.000000 -0.666600 0.745400 +vn 0.000000 0.470900 0.882200 +vn 0.729700 0.683700 0.000000 +vn 0.324500 0.256300 -0.910500 +vn -0.578700 -0.436200 -0.689100 +vn -0.578700 -0.436200 0.689100 +vn 0.324500 0.256300 0.910500 +vn 1.000000 -0.001100 0.000000 +vn 0.361000 -0.000700 -0.932600 +vn -0.756400 0.000000 -0.654100 +vn -0.756400 0.000000 0.654100 +vn 0.361000 -0.000700 0.932600 +vn 0.736100 -0.676800 0.000000 +vn 0.327100 -0.263100 -0.907600 +vn -0.578700 0.436200 -0.689100 +vn -0.578700 0.436200 0.689100 +vn 0.327100 -0.263100 0.907600 +vn -0.004900 -1.000000 0.000000 +vn 0.729700 -0.683800 0.000000 +vn 0.324500 -0.256300 0.910500 +vn -0.003300 -0.475400 0.879700 +vn 0.324500 -0.256300 -0.910500 +vn -0.003300 -0.475400 -0.879700 +vn 1.000000 0.000000 0.000000 +vn 0.359600 0.000000 0.933100 +vn 0.359600 0.000000 -0.933100 +vn -1.000000 -0.001100 0.000000 +vn -0.361000 -0.000700 0.932600 +vn -0.361000 -0.000700 -0.932600 +vn -0.736100 -0.676800 0.000000 +vn -0.327100 -0.263100 0.907600 +vn -0.327100 -0.263100 -0.907600 +vn 0.000000 -1.000000 0.004800 +vn 0.000000 -0.657400 -0.753500 +vn 0.898300 -0.248500 -0.362400 +vn 0.863600 -0.504100 0.003400 +vn -0.898300 -0.248500 -0.362400 +vn -0.863600 -0.504100 0.003400 +vn 0.000000 0.000000 -1.000000 +vn 0.925200 0.000000 -0.379500 +vn -0.925200 0.000000 -0.379500 +vn 0.898300 0.248500 -0.362400 +vn 0.661600 -0.421500 0.620200 +vn -0.898300 0.248500 -0.362400 +vn 0.898300 0.248500 0.362300 +vn -0.898300 0.248500 0.362300 +vn 0.000000 -0.000900 1.000000 +vn 0.924700 -0.000600 0.380700 +vn -0.924700 -0.000600 0.380700 +vn 0.000000 -0.650300 0.759600 +vn 0.895600 -0.254600 0.364700 +vn -0.895600 -0.254600 0.364700 +vn 0.729700 -0.683700 0.000000 +vn 0.729700 0.683800 0.000000 +vn -0.729700 0.683800 0.000000 +vn -0.898300 -0.248400 0.362300 +vn -0.863600 -0.504100 -0.003500 +vn 0.898300 -0.248400 0.362300 +vn 0.863600 -0.504100 -0.003500 +vn -0.661500 -0.421500 0.620200 +vn 0.924600 -0.000600 -0.380700 +vn -0.661500 0.421500 0.620200 +vn 0.661500 0.421500 0.620200 +s 1 +f 1/1/1 2/2/2 3/3/3 4/4/4 +f 4/4/4 3/3/3 5/5/5 6/6/6 +f 6/6/6 5/5/5 7/7/7 8/8/8 +f 8/8/8 7/7/7 9/9/9 10/10/10 +f 1/1/1 10/11/10 9/12/9 2/2/2 +f 2/2/2 11/13/11 12/14/12 3/3/3 +f 3/3/3 12/14/12 13/15/13 5/5/5 +f 5/5/5 13/15/13 14/16/14 7/7/7 +f 7/7/7 14/16/14 15/17/15 9/9/9 +f 9/12/9 15/18/15 11/13/11 2/2/2 +f 11/13/11 16/19/16 17/20/17 12/14/12 +f 12/14/12 17/20/17 18/21/18 13/15/13 +f 13/15/13 18/21/18 19/22/19 14/16/14 +f 14/16/14 19/22/19 20/23/20 15/17/15 +f 15/18/15 20/24/20 16/19/16 11/13/11 +f 16/19/16 21/25/21 22/26/22 17/20/17 +f 17/20/17 22/26/22 23/27/23 18/21/18 +f 18/21/18 23/27/23 24/28/24 19/22/19 +f 19/22/19 24/28/24 25/29/25 20/23/20 +f 20/24/20 25/30/25 21/25/21 16/19/16 +f 21/25/21 26/31/26 27/32/27 22/26/22 +f 22/26/22 27/32/27 28/33/28 23/27/23 +f 23/27/23 28/33/28 29/34/29 24/28/24 +f 24/28/24 29/34/29 30/35/30 25/29/25 +f 25/30/25 30/36/30 26/31/26 21/25/21 +f 26/37/26 31/38/31 32/39/32 27/40/27 +f 27/40/27 32/39/32 33/41/33 28/42/28 +f 28/42/28 33/41/33 34/43/34 29/44/29 +f 29/44/29 34/43/34 35/45/35 30/46/30 +f 30/47/30 35/48/35 31/38/31 26/37/26 +f 31/38/31 36/49/36 37/50/37 32/39/32 +f 32/39/32 37/50/37 38/51/38 33/41/33 +f 33/41/33 38/51/38 39/52/39 34/43/34 +f 34/43/34 39/52/39 40/53/40 35/45/35 +f 35/48/35 40/54/40 36/49/36 31/38/31 +f 36/49/36 1/1/1 4/4/4 37/50/37 +f 37/50/37 4/4/4 6/6/6 38/51/38 +f 38/51/38 6/6/6 8/8/8 39/52/39 +f 39/52/39 8/8/8 10/10/10 40/53/40 +f 1/1/1 36/49/36 40/54/40 10/11/10 +f 41/55/41 42/56/42 43/57/43 44/58/44 +f 44/59/44 43/60/43 45/61/45 46/62/46 +f 46/62/46 45/61/45 47/63/47 48/64/48 +f 48/64/48 47/63/47 49/65/49 50/66/50 +f 41/55/41 50/66/50 49/65/49 42/56/42 +f 42/56/42 51/67/51 52/68/52 43/57/43 +f 43/60/43 52/69/52 53/70/53 45/61/45 +f 45/61/45 53/70/53 54/71/54 47/63/47 +f 47/63/47 54/71/54 55/72/55 49/65/49 +f 49/65/49 55/72/55 51/67/51 42/56/42 +f 51/67/51 56/73/56 57/74/57 52/68/52 +f 52/69/52 57/75/57 58/76/58 53/70/53 +f 53/70/53 58/76/58 59/77/59 54/71/54 +f 54/71/54 59/77/59 60/78/60 55/72/55 +f 55/72/55 60/78/60 56/73/56 51/67/51 +f 56/73/56 61/79/21 62/80/61 57/74/57 +f 57/75/57 62/81/61 63/82/62 58/76/58 +f 58/76/58 63/82/62 64/83/63 59/77/59 +f 59/77/59 64/83/63 65/84/64 60/78/60 +f 60/78/60 65/84/64 61/79/21 56/73/56 +f 61/85/21 66/86/65 67/87/66 62/88/61 +f 62/35/61 67/89/66 68/90/67 63/91/62 +f 63/91/62 68/90/67 69/92/68 64/93/63 +f 64/93/63 69/92/68 70/94/69 65/95/64 +f 65/95/64 70/94/69 66/86/65 61/85/21 +f 66/86/65 71/96/70 72/97/71 67/87/66 +f 67/89/66 72/98/71 73/99/72 68/90/67 +f 68/90/67 73/99/72 74/100/73 69/92/68 +f 69/92/68 74/100/73 75/101/74 70/94/69 +f 70/94/69 75/101/74 71/96/70 66/86/65 +f 71/96/70 76/102/75 77/103/76 72/97/71 +f 72/98/71 77/104/76 78/105/77 73/99/72 +f 73/99/72 78/105/77 79/106/78 74/100/73 +f 74/100/73 79/106/78 80/107/79 75/101/74 +f 75/101/74 80/107/79 76/102/75 71/96/70 +f 76/102/75 41/55/41 44/58/44 77/103/76 +f 77/104/76 44/59/44 46/62/46 78/105/77 +f 78/105/77 46/62/46 48/64/48 79/106/78 +f 79/106/78 48/64/48 50/66/50 80/107/79 +f 41/55/41 76/102/75 80/107/79 50/66/50 +f 81/108/80 82/109/81 83/110/82 84/111/83 +f 84/9/83 83/17/82 85/112/78 86/113/48 +f 86/113/48 85/112/78 87/114/77 88/115/46 +f 88/115/46 87/114/77 89/116/84 90/117/85 +f 81/108/80 90/117/85 89/116/84 82/109/81 +f 82/109/81 91/118/86 92/119/87 83/110/82 +f 83/17/82 92/23/87 93/120/73 85/112/78 +f 85/112/78 93/120/73 94/121/72 87/114/77 +f 87/114/77 94/121/72 95/122/88 89/116/84 +f 89/116/84 95/122/88 91/118/86 82/109/81 +f 91/118/86 96/123/65 97/124/69 92/119/87 +f 92/23/87 97/29/69 98/125/68 93/120/73 +f 93/120/73 98/125/68 99/126/67 94/121/72 +f 94/121/72 99/126/67 100/127/66 95/122/88 +f 95/122/88 100/127/66 96/123/65 91/118/86 +f 96/123/65 101/85/21 102/88/64 97/124/69 +f 97/29/69 102/35/64 103/91/63 98/125/68 +f 98/125/68 103/91/63 104/93/62 99/126/67 +f 99/126/67 104/93/62 105/95/61 100/127/66 +f 100/127/66 105/95/61 101/85/21 96/123/65 +f 101/128/21 106/129/56 107/130/60 102/131/64 +f 102/46/64 107/45/60 108/132/59 103/133/63 +f 103/133/63 108/132/59 109/134/58 104/135/62 +f 104/135/62 109/134/58 110/136/57 105/137/61 +f 105/137/61 110/136/57 106/129/56 101/128/21 +f 106/129/56 111/138/89 112/139/90 107/130/60 +f 107/45/60 112/53/90 113/140/54 108/132/59 +f 108/132/59 113/140/54 114/141/53 109/134/58 +f 109/134/58 114/141/53 115/142/91 110/136/57 +f 110/136/57 115/142/91 111/138/89 106/129/56 +f 111/138/89 116/143/92 117/144/93 112/139/90 +f 112/53/90 117/10/93 118/145/47 113/140/54 +f 113/140/54 118/145/47 119/146/45 114/141/53 +f 114/141/53 119/146/45 120/147/94 115/142/91 +f 115/142/91 120/147/94 116/143/92 111/138/89 +f 116/143/92 81/108/80 84/111/83 117/144/93 +f 117/10/93 84/9/83 86/113/48 118/145/47 +f 118/145/47 86/113/48 88/115/46 119/146/45 +f 119/146/45 88/115/46 90/117/85 120/147/94 +f 81/108/80 116/143/92 120/147/94 90/117/85 +f 121/148/95 122/149/96 123/150/97 124/151/98 +f 124/151/98 123/150/97 125/152/39 126/153/8 +f 126/153/8 125/152/39 127/154/38 128/155/6 +f 128/155/6 127/154/38 129/156/99 130/157/100 +f 121/148/95 130/103/100 129/58/99 122/149/96 +f 122/149/96 131/158/101 132/159/102 123/150/97 +f 123/150/97 132/159/102 133/160/34 125/152/39 +f 125/152/39 133/160/34 134/161/33 127/154/38 +f 127/154/38 134/161/33 135/162/103 129/156/99 +f 129/58/99 135/57/103 131/158/101 122/149/96 +f 131/158/101 136/163/26 137/164/104 132/159/102 +f 132/159/102 137/164/104 138/165/105 133/160/34 +f 133/160/34 138/165/105 139/166/28 134/161/33 +f 134/161/33 139/166/28 140/167/106 135/162/103 +f 135/57/103 140/68/106 136/163/26 131/158/101 +f 136/163/26 141/168/21 142/169/25 137/164/104 +f 137/164/104 142/169/25 143/170/24 138/165/105 +f 138/165/105 143/170/24 144/171/23 139/166/28 +f 139/166/28 144/171/23 145/172/22 140/167/106 +f 140/68/106 145/74/22 141/168/21 136/163/26 +f 141/168/21 146/173/16 147/174/107 142/169/25 +f 142/169/25 147/174/107 148/175/19 143/170/24 +f 143/170/24 148/175/19 149/176/18 144/171/23 +f 144/171/23 149/176/18 150/177/108 145/172/22 +f 145/74/22 150/80/108 146/173/16 141/168/21 +f 146/178/16 151/179/109 152/180/110 147/181/107 +f 147/181/107 152/180/110 153/182/14 148/183/19 +f 148/183/19 153/182/14 154/184/13 149/185/18 +f 149/185/18 154/184/13 155/186/111 150/187/108 +f 150/88/108 155/87/111 151/179/109 146/178/16 +f 151/179/109 156/188/112 157/189/113 152/180/110 +f 152/180/110 157/189/113 158/190/7 153/182/14 +f 153/182/14 158/190/7 159/191/5 154/184/13 +f 154/184/13 159/191/5 160/192/114 155/186/111 +f 155/87/111 160/97/114 156/188/112 151/179/109 +f 156/188/112 121/148/95 124/151/98 157/189/113 +f 157/189/113 124/151/98 126/153/8 158/190/7 +f 158/190/7 126/153/8 128/155/6 159/191/5 +f 159/191/5 128/155/6 130/157/100 160/192/114 +f 121/148/95 156/188/112 160/97/114 130/103/100 +f 161/193/80 162/194/115 163/60/82 164/59/83 +f 164/195/83 163/196/82 165/197/78 166/198/48 +f 166/198/48 165/197/78 167/199/77 168/200/46 +f 168/200/46 167/199/77 169/201/84 170/202/85 +f 161/193/80 170/202/85 169/201/84 162/194/115 +f 162/194/115 171/203/86 172/69/87 163/60/82 +f 163/196/82 172/204/87 173/205/73 165/197/78 +f 165/197/78 173/205/73 174/206/72 167/199/77 +f 167/199/77 174/206/72 175/207/88 169/201/84 +f 169/201/84 175/207/88 171/203/86 162/194/115 +f 171/203/86 176/208/116 177/75/69 172/69/87 +f 172/204/87 177/209/69 178/210/68 173/205/73 +f 173/205/73 178/210/68 179/211/67 174/206/72 +f 174/206/72 179/211/67 180/212/66 175/207/88 +f 175/207/88 180/212/66 176/208/116 171/203/86 +f 176/208/116 181/213/21 182/81/64 177/75/69 +f 177/209/69 182/214/64 183/215/63 178/210/68 +f 178/210/68 183/215/63 184/216/62 179/211/67 +f 179/211/67 184/216/62 185/217/61 180/212/66 +f 180/212/66 185/217/61 181/213/21 176/208/116 +f 181/34/21 186/218/117 187/89/60 182/35/64 +f 182/36/64 187/219/60 188/220/59 183/31/63 +f 183/31/63 188/220/59 189/221/58 184/32/62 +f 184/32/62 189/221/58 190/222/57 185/33/61 +f 185/33/61 190/222/57 186/218/117 181/34/21 +f 186/218/117 191/223/89 192/98/90 187/89/60 +f 187/219/60 192/224/90 193/225/54 188/220/59 +f 188/220/59 193/225/54 194/226/53 189/221/58 +f 189/221/58 194/226/53 195/227/91 190/222/57 +f 190/222/57 195/227/91 191/223/89 186/218/117 +f 191/223/89 196/228/92 197/104/93 192/98/90 +f 192/224/90 197/229/93 198/230/47 193/225/54 +f 193/225/54 198/230/47 199/231/45 194/226/53 +f 194/226/53 199/231/45 200/232/94 195/227/91 +f 195/227/91 200/232/94 196/228/92 191/223/89 +f 196/228/92 161/193/80 164/59/83 197/104/93 +f 197/229/93 164/195/83 166/198/48 198/230/47 +f 198/230/47 166/198/48 168/200/46 199/231/45 +f 199/231/45 168/200/46 170/202/85 200/232/94 +f 161/193/80 196/228/92 200/232/94 170/202/85 +f 201/233/1 202/234/2 203/235/118 204/236/119 +f 204/111/119 203/110/118 205/237/5 206/238/6 +f 206/238/6 205/237/5 207/239/7 208/240/8 +f 208/240/8 207/239/7 209/241/120 210/242/121 +f 201/233/1 210/242/121 209/241/120 202/234/2 +f 202/234/2 211/243/11 212/244/12 203/235/118 +f 203/110/118 212/119/12 213/245/13 205/237/5 +f 205/237/5 213/245/13 214/246/14 207/239/7 +f 207/239/7 214/246/14 215/247/15 209/241/120 +f 209/241/120 215/247/15 211/243/11 202/234/2 +f 211/243/11 216/248/16 217/249/108 212/244/12 +f 212/119/12 217/124/108 218/250/18 213/245/13 +f 213/245/13 218/250/18 219/251/19 214/246/14 +f 214/246/14 219/251/19 220/252/107 215/247/15 +f 215/247/15 220/252/107 216/248/16 211/243/11 +f 216/248/16 221/185/21 222/187/22 217/249/108 +f 217/124/108 222/88/22 223/178/23 218/250/18 +f 218/250/18 223/178/23 224/181/24 219/251/19 +f 219/251/19 224/181/24 225/183/25 220/252/107 +f 220/252/107 225/183/25 221/185/21 216/248/16 +f 221/253/21 226/254/26 227/255/106 222/256/22 +f 222/131/22 227/130/106 228/257/122 223/258/23 +f 223/258/23 228/257/122 229/259/29 224/260/24 +f 224/260/24 229/259/29 230/261/104 225/262/25 +f 225/262/25 230/261/104 226/254/26 221/253/21 +f 226/254/26 231/263/31 232/264/32 227/255/106 +f 227/130/106 232/139/32 233/265/33 228/257/122 +f 228/257/122 233/265/33 234/266/34 229/259/29 +f 229/259/29 234/266/34 235/267/123 230/261/104 +f 230/261/104 235/267/123 231/263/31 226/254/26 +f 231/263/31 236/268/36 237/269/37 232/264/32 +f 232/139/32 237/144/37 238/270/124 233/265/33 +f 233/265/33 238/270/124 239/271/125 234/266/34 +f 234/266/34 239/271/125 240/272/40 235/267/123 +f 235/267/123 240/272/40 236/268/36 231/263/31 +f 236/268/36 201/233/1 204/236/119 237/269/37 +f 237/144/37 204/111/119 206/238/6 238/270/124 +f 238/270/124 206/238/6 208/240/8 239/271/125 +f 239/271/125 208/240/8 210/242/121 240/272/40 +f 201/233/1 236/268/36 240/272/40 210/242/121 diff --git a/basic_materials/plastics.lua b/basic_materials/plastics.lua new file mode 100644 index 0000000..3ac0f98 --- /dev/null +++ b/basic_materials/plastics.lua @@ -0,0 +1,55 @@ +-- Translation support +local S = minetest.get_translator("basic_materials") + +-- items + +minetest.register_craftitem("basic_materials:plastic_sheet", { + description = S("Plastic sheet"), + inventory_image = "basic_materials_plastic_sheet.png", +}) + +minetest.register_craftitem("basic_materials:plastic_strip", { + description = S("Plastic strips"), + inventory_image = "basic_materials_plastic_strip.png", +}) + +minetest.register_craftitem("basic_materials:empty_spool", { + description = S("Empty wire spool"), + inventory_image = "basic_materials_empty_spool.png" +}) + +-- crafts + +minetest.register_craft({ + type = "cooking", + output = "basic_materials:plastic_sheet", + recipe = "basic_materials:paraffin", +}) + +minetest.register_craft({ + type = "fuel", + recipe = "basic_materials:plastic_sheet", + burntime = 30, +}) + +minetest.register_craft( { + output = "basic_materials:plastic_strip 9", + recipe = { + { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" } + }, +}) + +minetest.register_craft( { + output = "basic_materials:empty_spool 3", + recipe = { + { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" }, + { "", "basic_materials:plastic_sheet", "" }, + { "basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet" } + }, +}) + +-- aliases + +minetest.register_alias("homedecor:plastic_sheeting", "basic_materials:plastic_sheet") +minetest.register_alias("homedecor:plastic_strips", "basic_materials:plastic_strip") +minetest.register_alias("homedecor:empty_spool", "basic_materials:empty_spool") diff --git a/basic_materials/textures/basic_materials_brass_block.png b/basic_materials/textures/basic_materials_brass_block.png new file mode 100644 index 0000000..c937800 Binary files /dev/null and b/basic_materials/textures/basic_materials_brass_block.png differ diff --git a/basic_materials/textures/basic_materials_brass_ingot.png b/basic_materials/textures/basic_materials_brass_ingot.png new file mode 100644 index 0000000..0bd030a Binary files /dev/null and b/basic_materials/textures/basic_materials_brass_ingot.png differ diff --git a/basic_materials/textures/basic_materials_cement_block.png b/basic_materials/textures/basic_materials_cement_block.png new file mode 100644 index 0000000..6d30f47 Binary files /dev/null and b/basic_materials/textures/basic_materials_cement_block.png differ diff --git a/basic_materials/textures/basic_materials_chain_brass.png b/basic_materials/textures/basic_materials_chain_brass.png new file mode 100644 index 0000000..e2fb20d Binary files /dev/null and b/basic_materials/textures/basic_materials_chain_brass.png differ diff --git a/basic_materials/textures/basic_materials_chain_brass_inv.png b/basic_materials/textures/basic_materials_chain_brass_inv.png new file mode 100644 index 0000000..8c2d554 Binary files /dev/null and b/basic_materials/textures/basic_materials_chain_brass_inv.png differ diff --git a/basic_materials/textures/basic_materials_chain_steel.png b/basic_materials/textures/basic_materials_chain_steel.png new file mode 100644 index 0000000..29af8db Binary files /dev/null and b/basic_materials/textures/basic_materials_chain_steel.png differ diff --git a/basic_materials/textures/basic_materials_chain_steel_inv.png b/basic_materials/textures/basic_materials_chain_steel_inv.png new file mode 100644 index 0000000..c552f7b Binary files /dev/null and b/basic_materials/textures/basic_materials_chain_steel_inv.png differ diff --git a/basic_materials/textures/basic_materials_chainlink_brass.png b/basic_materials/textures/basic_materials_chainlink_brass.png new file mode 100644 index 0000000..9a1ad87 Binary files /dev/null and b/basic_materials/textures/basic_materials_chainlink_brass.png differ diff --git a/basic_materials/textures/basic_materials_chainlink_steel.png b/basic_materials/textures/basic_materials_chainlink_steel.png new file mode 100644 index 0000000..d7132c3 Binary files /dev/null and b/basic_materials/textures/basic_materials_chainlink_steel.png differ diff --git a/basic_materials/textures/basic_materials_concrete_block.png b/basic_materials/textures/basic_materials_concrete_block.png new file mode 100644 index 0000000..5dd0d66 Binary files /dev/null and b/basic_materials/textures/basic_materials_concrete_block.png differ diff --git a/basic_materials/textures/basic_materials_copper_strip.png b/basic_materials/textures/basic_materials_copper_strip.png new file mode 100644 index 0000000..22e572a Binary files /dev/null and b/basic_materials/textures/basic_materials_copper_strip.png differ diff --git a/basic_materials/textures/basic_materials_copper_wire.png b/basic_materials/textures/basic_materials_copper_wire.png new file mode 100644 index 0000000..9df9f36 Binary files /dev/null and b/basic_materials/textures/basic_materials_copper_wire.png differ diff --git a/basic_materials/textures/basic_materials_empty_spool.png b/basic_materials/textures/basic_materials_empty_spool.png new file mode 100644 index 0000000..017a94f Binary files /dev/null and b/basic_materials/textures/basic_materials_empty_spool.png differ diff --git a/basic_materials/textures/basic_materials_energy_crystal.png b/basic_materials/textures/basic_materials_energy_crystal.png new file mode 100644 index 0000000..f1c28e8 Binary files /dev/null and b/basic_materials/textures/basic_materials_energy_crystal.png differ diff --git a/basic_materials/textures/basic_materials_gear_steel.png b/basic_materials/textures/basic_materials_gear_steel.png new file mode 100644 index 0000000..584f9a5 Binary files /dev/null and b/basic_materials/textures/basic_materials_gear_steel.png differ diff --git a/basic_materials/textures/basic_materials_gold_wire.png b/basic_materials/textures/basic_materials_gold_wire.png new file mode 100644 index 0000000..781de7b Binary files /dev/null and b/basic_materials/textures/basic_materials_gold_wire.png differ diff --git a/basic_materials/textures/basic_materials_heating_element.png b/basic_materials/textures/basic_materials_heating_element.png new file mode 100644 index 0000000..42e00b7 Binary files /dev/null and b/basic_materials/textures/basic_materials_heating_element.png differ diff --git a/basic_materials/textures/basic_materials_ic.png b/basic_materials/textures/basic_materials_ic.png new file mode 100644 index 0000000..4c88894 Binary files /dev/null and b/basic_materials/textures/basic_materials_ic.png differ diff --git a/basic_materials/textures/basic_materials_motor.png b/basic_materials/textures/basic_materials_motor.png new file mode 100644 index 0000000..f19ec0a Binary files /dev/null and b/basic_materials/textures/basic_materials_motor.png differ diff --git a/basic_materials/textures/basic_materials_oil_extract.png b/basic_materials/textures/basic_materials_oil_extract.png new file mode 100644 index 0000000..e34623d Binary files /dev/null and b/basic_materials/textures/basic_materials_oil_extract.png differ diff --git a/basic_materials/textures/basic_materials_padlock.png b/basic_materials/textures/basic_materials_padlock.png new file mode 100644 index 0000000..b05b7ef Binary files /dev/null and b/basic_materials/textures/basic_materials_padlock.png differ diff --git a/basic_materials/textures/basic_materials_paraffin.png b/basic_materials/textures/basic_materials_paraffin.png new file mode 100644 index 0000000..77d2bbd Binary files /dev/null and b/basic_materials/textures/basic_materials_paraffin.png differ diff --git a/basic_materials/textures/basic_materials_plastic_sheet.png b/basic_materials/textures/basic_materials_plastic_sheet.png new file mode 100644 index 0000000..034dcc2 Binary files /dev/null and b/basic_materials/textures/basic_materials_plastic_sheet.png differ diff --git a/basic_materials/textures/basic_materials_plastic_strip.png b/basic_materials/textures/basic_materials_plastic_strip.png new file mode 100644 index 0000000..1318dfc Binary files /dev/null and b/basic_materials/textures/basic_materials_plastic_strip.png differ diff --git a/basic_materials/textures/basic_materials_silicon.png b/basic_materials/textures/basic_materials_silicon.png new file mode 100644 index 0000000..847b366 Binary files /dev/null and b/basic_materials/textures/basic_materials_silicon.png differ diff --git a/basic_materials/textures/basic_materials_silver_wire.png b/basic_materials/textures/basic_materials_silver_wire.png new file mode 100644 index 0000000..a38a45e Binary files /dev/null and b/basic_materials/textures/basic_materials_silver_wire.png differ diff --git a/basic_materials/textures/basic_materials_steel_bar.png b/basic_materials/textures/basic_materials_steel_bar.png new file mode 100644 index 0000000..0673b6e Binary files /dev/null and b/basic_materials/textures/basic_materials_steel_bar.png differ diff --git a/basic_materials/textures/basic_materials_steel_strip.png b/basic_materials/textures/basic_materials_steel_strip.png new file mode 100644 index 0000000..6384dc8 Binary files /dev/null and b/basic_materials/textures/basic_materials_steel_strip.png differ diff --git a/basic_materials/textures/basic_materials_steel_wire.png b/basic_materials/textures/basic_materials_steel_wire.png new file mode 100644 index 0000000..0c96c8f Binary files /dev/null and b/basic_materials/textures/basic_materials_steel_wire.png differ diff --git a/basic_materials/textures/basic_materials_terracotta_base.png b/basic_materials/textures/basic_materials_terracotta_base.png new file mode 100644 index 0000000..9f04aad Binary files /dev/null and b/basic_materials/textures/basic_materials_terracotta_base.png differ diff --git a/basic_materials/textures/basic_materials_wet_cement.png b/basic_materials/textures/basic_materials_wet_cement.png new file mode 100644 index 0000000..6a7fbf1 Binary files /dev/null and b/basic_materials/textures/basic_materials_wet_cement.png differ diff --git a/compost/.gitignore b/compost/.gitignore new file mode 100644 index 0000000..ce3cbfc --- /dev/null +++ b/compost/.gitignore @@ -0,0 +1,2 @@ +# Backup files +*~ diff --git a/compost/LICENSE.txt b/compost/LICENSE.txt new file mode 100644 index 0000000..8f84ec4 --- /dev/null +++ b/compost/LICENSE.txt @@ -0,0 +1,19 @@ +License for Code +---------------- + +Copyright (C) 2016 cdqwertz + +This program 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. + +http://www.gnu.org/licenses/lgpl-2.1.html + +License for Media +----------------- + +CC-BY-SA 3.0 UNPORTED. Created by cdqwertz + +Note: screenshot.png contains textures from minetest_game. + diff --git a/compost/README.md b/compost/README.md new file mode 100644 index 0000000..744d594 --- /dev/null +++ b/compost/README.md @@ -0,0 +1,25 @@ +# Compost Mod +With this mod, you are able to compost grass, leaves, flowers... + +Adapted to techage/minecart by joe7575 + + +## License +see LICENSE.txt + +## Crafting +Wood barrel: + +| W | | W | +|---|---|---| +| W | | W | +| W | S | W | + +W : wood +S : wood slab + +## Bugs +Report bugs on the forum topic or open a issue on GitHub. + +## created by +cdqwertz - cdqwertz.github.io diff --git a/compost/depends.txt b/compost/depends.txt new file mode 100644 index 0000000..175a59d --- /dev/null +++ b/compost/depends.txt @@ -0,0 +1,3 @@ +default +minecart? +techage? diff --git a/compost/description.txt b/compost/description.txt new file mode 100644 index 0000000..2fab6d1 --- /dev/null +++ b/compost/description.txt @@ -0,0 +1,12 @@ +With this mod, you are able to compost grass, leaves, flowers... + +Crafting: +Wood barrel: + W W + W W + W S W + + W : wood + S : wood slab + +created by cd2 (cdqwertz) - cdqwertz.github.io diff --git a/compost/init.lua b/compost/init.lua new file mode 100644 index 0000000..60d8f7d --- /dev/null +++ b/compost/init.lua @@ -0,0 +1,308 @@ +compost = {} + +-- Version for compatibility checks +compost.version = 1.0 + +if minetest.global_exists("techage") and techage.version < 0.06 then + minetest.log("error", "[compost] Compost requires techage version 0.06 or newer!") + return +end + +compost.items = {} +compost.groups = {} + +function compost.register_item(name) + compost.items[name] = true +end + +function compost.register_group(name) + compost.groups[name] = true +end + +function compost.can_compost(name) + if compost.items[name] then + return true + else + for k, i in pairs(minetest.registered_items[name].groups) do + if i > 0 then + if compost.groups[tostring(k)] then + return true + end + end + end + + return false + end +end + +-- grass +compost.register_item("default:grass_1") +compost.register_item("default:junglegrass") + +-- leaves +compost.register_group("leaves") + +-- dirt +compost.register_item("default:dirt") +compost.register_item("default:dirt_with_grass") + +-- stick +compost.register_item("default:stick") + +-- food +compost.register_item("farming:bread") +compost.register_item("farming:wheat") + +-- groups +compost.register_group("plant") +compost.register_group("flower") + +-- flowers +minetest.after(1, function() + for name,_ in pairs(minetest.registered_decorations) do + if type(name) == "string" then + local mod = string.split(name, ":")[1] + if mod == "flowers" then + compost.register_item(name) + end + end + end +end) + + +local function next_state(pos, elapsed) + local node = minetest.get_node(pos) + if node.name == "compost:wood_barrel_1" then + minetest.set_node(pos, {name = "compost:wood_barrel_2"}) + return true + end + if node.name == "compost:wood_barrel_2" then + minetest.set_node(pos, {name = "compost:wood_barrel_3"}) + return false + end + return false +end + +local function minecart_hopper_additem(pos, stack) + if compost.can_compost(stack:get_name()) then + local meta = minetest.get_meta(pos) + -- 4 leaves for one compost node + local num = (meta:get_int("num") or 0) + stack:get_count() + if num >= 4 then + num = num - 4 + minetest.set_node(pos, {name = "compost:wood_barrel_1"}) + -- speed up the process by means of a timer + minetest.get_node_timer(pos):start(10) + end + meta:set_int("num", num) + stack:set_count(0) + return stack + end + return stack +end + +local function minecart_hopper_takeitem(pos, num) + local node = minetest.get_node(pos) + minetest.set_node(pos, {name = "compost:wood_barrel"}) + return ItemStack("compost:compost") +end + +local function minecart_hopper_untakeitem(pos, in_dir, stack) + minetest.set_node(pos, {name = "compost:wood_barrel_2"}) +end + +minetest.register_node("compost:wood_barrel", { + description = "Wood Barrel", + tiles = {"default_wood.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2}, + {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2}, + {3/8, -1/2, -1/2, 1/2, 1/2, 1/2}, + {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8}, + {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}}, + }, + paramtype = "light", + is_ground_content = false, + groups = {choppy = 3}, + sounds = default.node_sound_wood_defaults(), + on_punch = function(pos, node, puncher, pointed_thing) + local wielded_item = puncher:get_wielded_item():get_name() + if compost.can_compost(wielded_item) then + minetest.set_node(pos, {name = "compost:wood_barrel_1"}) + local w = puncher:get_wielded_item() + if not(minetest.setting_getbool("creative_mode")) then + w:take_item(1) + puncher:set_wielded_item(w) + end + end + end, + minecart_hopper_additem = minecart_hopper_additem, + minecart_hopper_untakeitem = minecart_hopper_untakeitem, +}) + +minetest.register_node("compost:wood_barrel_1", { + description = "Wood Barrel with compost", + tiles = {"default_wood.png^compost_compost_1.png", "default_wood.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2}, + {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2}, + {3/8, -1/2, -1/2, 1/2, 1/2, 1/2}, + {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8}, + {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}, + {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}}, + }, + paramtype = "light", + is_ground_content = false, + groups = {choppy = 3, not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + on_timer = next_state, + minecart_hopper_untakeitem = minecart_hopper_untakeitem, +}) + +minetest.register_node("compost:wood_barrel_2", { + description = "Wood Barrel with compost", + tiles = {"default_wood.png^compost_compost_2.png", "default_wood.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2}, + {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2}, + {3/8, -1/2, -1/2, 1/2, 1/2, 1/2}, + {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8}, + {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}, + {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}}, + }, + paramtype = "light", + is_ground_content = false, + groups = {choppy = 3, not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + on_timer = next_state, + minecart_hopper_untakeitem = minecart_hopper_untakeitem, +}) + +minetest.register_node("compost:wood_barrel_3", { + description = "Wood Barrel", + tiles = {"default_wood.png^compost_compost_3.png", "default_wood.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2}, + {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2}, + {3/8, -1/2, -1/2, 1/2, 1/2, 1/2}, + {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8}, + {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}, + {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}}, + }, + paramtype = "light", + is_ground_content = false, + groups = {choppy = 3, not_in_creative_inventory=1}, + sounds = default.node_sound_wood_defaults(), + on_punch = function(pos, node, player, pointed_thing) + local p = {x = pos.x + math.random(0, 5)/5 - 0.5, y = pos.y+1, z = pos.z + math.random(0, 5)/5 - 0.5} + minetest.add_item(p, {name = "compost:compost"}) + minetest.set_node(pos, {name = "compost:wood_barrel"}) + end, + minecart_hopper_takeitem = minecart_hopper_takeitem, + minecart_hopper_untakeitem = minecart_hopper_untakeitem, +}) + +minetest.register_abm({ + nodenames = {"compost:wood_barrel_1"}, + interval = 40, + chance = 5, + action = function(pos, node, active_object_count, active_object_count_wider) + minetest.set_node(pos, {name = "compost:wood_barrel_2"}) + end, +}) + +minetest.register_abm({ + nodenames = {"compost:wood_barrel_2"}, + interval = 40, + chance = 5, + action = function(pos, node, active_object_count, active_object_count_wider) + minetest.set_node(pos, {name = "compost:wood_barrel_3"}) + end, +}) + +minetest.register_craft({ + output = "compost:wood_barrel", + recipe = { + {"default:wood", "", "default:wood"}, + {"default:wood", "", "default:wood"}, + {"default:wood", "stairs:slab_wood", "default:wood"} + } +}) + +minetest.register_node("compost:compost", { + description = "Compost", + tiles = {"compost_compost.png"}, + groups = {crumbly = 3}, + sounds = default.node_sound_dirt_defaults(), +}) + +minetest.register_node("compost:garden_soil", { + description = "Garden Soil", + tiles = {"compost_garden_soil.png"}, + groups = {crumbly = 3, soil=3, grassland = 1, wet = 1}, + sounds = default.node_sound_dirt_defaults(), +}) + +minetest.register_craft({ + output = "compost:garden_soil", + recipe = { + {"compost:compost", "compost:compost"}, + } +}) + +minetest.register_craft({ + output = "default:dirt", + recipe = { + {"compost:garden_soil"}, + } +}) + +if minetest.global_exists("techage") then + techage.register_node( + { + "compost:wood_barrel", + "compost:wood_barrel_1", + "compost:wood_barrel_2", + "compost:wood_barrel_3", + }, + { + on_pull_item = function(pos, in_dir, num) + local node = minetest.get_node(pos) + if node.name == "compost:wood_barrel_3" then + minetest.set_node(pos, {name = "compost:wood_barrel"}) + return ItemStack("compost:compost") + end + return nil + end, + on_push_item = function(pos, in_dir, stack) + local node = minetest.get_node(pos) + if node.name == "compost:wood_barrel" and compost.can_compost(stack:get_name()) then + local meta = minetest.get_meta(pos) + -- 4 leaves for one compost node + local num = (meta:get_int("num") or 0) + 1 + if num >= 4 then + num = 0 + minetest.set_node(pos, {name = "compost:wood_barrel_1"}) + -- speed up the process by means of a timer + minetest.get_node_timer(pos):start(10) + end + meta:set_int("num", num) + return true + end + return false + end, + on_unpull_item = function(pos, in_dir, stack) + minetest.set_node(pos, {name = "compost:wood_barrel_2"}) + return true + end, + }) +end + diff --git a/compost/screenshot.png b/compost/screenshot.png new file mode 100644 index 0000000..d916bbd Binary files /dev/null and b/compost/screenshot.png differ diff --git a/compost/textures/compost_compost.png b/compost/textures/compost_compost.png new file mode 100644 index 0000000..dfe1768 Binary files /dev/null and b/compost/textures/compost_compost.png differ diff --git a/compost/textures/compost_compost_1.png b/compost/textures/compost_compost_1.png new file mode 100644 index 0000000..4a8921e Binary files /dev/null and b/compost/textures/compost_compost_1.png differ diff --git a/compost/textures/compost_compost_2.png b/compost/textures/compost_compost_2.png new file mode 100644 index 0000000..f5dcbff Binary files /dev/null and b/compost/textures/compost_compost_2.png differ diff --git a/compost/textures/compost_compost_3.png b/compost/textures/compost_compost_3.png new file mode 100644 index 0000000..6a70b03 Binary files /dev/null and b/compost/textures/compost_compost_3.png differ diff --git a/compost/textures/compost_garden_soil.png b/compost/textures/compost_garden_soil.png new file mode 100644 index 0000000..55409b8 Binary files /dev/null and b/compost/textures/compost_garden_soil.png differ diff --git a/datastorage/README.md b/datastorage/README.md new file mode 100644 index 0000000..b15b07a --- /dev/null +++ b/datastorage/README.md @@ -0,0 +1,22 @@ +datastorage +=========== + +Helper mod to manage players data. +All the mods can acces a single file (container) and easily have the data saved/loaded for them. + +Usage +----- + + local data = datastorage.get(id, ...) + +Returns a reference to a data container. The id is normally a player name. +Following arguments are keys to recurse into, normally only one, a string +describing the type of data, is used. If the container doesn't exist it will +be created, otherwise it will contain all previously stored data. The table +can store any data. Player's containers will be saved to disk when the player +leaves, and all references to the player's data should be dropped. All of the +containers will be saved on server shutdown. To forcibly save a container's +data use: + + datastorage.save(id) + diff --git a/datastorage/depends.txt b/datastorage/depends.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/datastorage/depends.txt @@ -0,0 +1 @@ + diff --git a/datastorage/init.lua b/datastorage/init.lua new file mode 100644 index 0000000..30677fc --- /dev/null +++ b/datastorage/init.lua @@ -0,0 +1,98 @@ +datastorage = {data = {}} + +local DIR_DELIM = DIR_DELIM or "/" +local data_path = minetest.get_worldpath()..DIR_DELIM.."datastorage"..DIR_DELIM + +function datastorage.save(id) + local data = datastorage.data[id] + -- Check if the container is empty + if not data or not next(data) then return end + for _, sub_data in pairs(data) do + if not next(sub_data) then return end + end + + local file = io.open(data_path..id, "w") + if not file then + -- Most likely the data directory doesn't exist, create it + -- and try again. + if minetest.mkdir then + minetest.mkdir(data_path) + else + -- Using os.execute like this is not very platform + -- independent or safe, but most platforms name their + -- directory creation utility mkdir, the data path is + -- unlikely to contain special characters, and the + -- data path is only mutable by the admin. + os.execute('mkdir "'..data_path..'"') + end + file = io.open(data_path..id, "w") + if not file then return end + end + + local datastr = minetest.serialize(data) + if not datastr then return end + + file:write(datastr) + file:close() + return true +end + +function datastorage.load(id) + local file = io.open(data_path..id, "r") + if not file then return end + + local data = minetest.deserialize(file:read("*all")) + datastorage.data[id] = data + + file:close() + return data +end + +-- Compatability +function datastorage.get_container(player, id) + return datastorage.get(player:get_player_name(), id) +end + +-- Retrieves a value from the data storage +function datastorage.get(id, ...) + local last = datastorage.data[id] + if last == nil then last = datastorage.load(id) end + if last == nil then + last = {} + datastorage.data[id] = last + end + local cur = last + for _, sub_id in ipairs({...}) do + last = cur + cur = cur[sub_id] + if cur == nil then + cur = {} + last[sub_id] = cur + end + end + return cur +end + +-- Saves a container and reomves it from memory +function datastorage.finish(id) + datastorage.save(id) + datastorage.data[id] = nil +end + +-- Compatability +function datastorage.save_container(player) + return datastorage.save(player:get_player_name()) +end + +minetest.register_on_leaveplayer(function(player) + local player_name = player:get_player_name() + datastorage.save(player_name) + datastorage.data[player_name] = nil +end) + +minetest.register_on_shutdown(function() + for id in pairs(datastorage.data) do + datastorage.save(id) + end +end) + diff --git a/doc/API.md b/doc/API.md new file mode 100644 index 0000000..49afeb3 --- /dev/null +++ b/doc/API.md @@ -0,0 +1,539 @@ +# API documentation for the Documentation System +## Core concepts +As a modder, you are free to write basically about everything and are also +relatively free in the presentation of information. There are no +restrictions on content whatsoever. + +### Categories and entries +In the Documentation System, everything is built on categories and entries. +An entry is a single piece of documentation and is the basis of all actual +documentation. Categories group multiple entries of the same topic together. + +Categories also define a template function which is used to determine how the +final result in the tab “Entry list” looks like. Entries themselves have +a data field attached to them, this is a table containing arbitrary metadata +which is used to construct the final formspec in the Entry tab. It may also +be used for sorting entries in the entry list. + +## Advanced concepts +### Viewed and hidden entries +The mod keeps track of which entries have been viewed on a per-player basis. +Any entry which has been accessed by a player is immediately marked as +“viewed”. + +Entries can also be hidden. Hidden entries are not visible or otherwise +accessible to players until they become revealed by function calls. + +Marking an entry as viewed or revealed is not reversible with this API. +The viewed and hidden states are stored in the file `doc.mt` inside the +world directory. You can safely delete this file if you want to reset +the player states. + +### Entry aliases +Entry aliases are alternative identifiers for entry identifiers. With the +exception of the alias functions themselves, for functions demanding an +`entry_id` you can either supply the original `entry_id` or any alias of the +`entry_id`. + +## Possible use cases +This section shows some possible use cases to give you a rough idea what +this mod is capable of and how these use cases could be implemented. + +### Simple use case: Minetest basics +Let's say you want to write in free form short help texts about the basic +concepts of Minetest or your game. First you could define a category +called “Basics”, the data for each of its entry is just a free form text. +The template function simply creates a formspec where this free form +text is displayed. + +This is one of the most simple use cases and the mod `doc_basics` does +exactly that. + +### Complex use case: Blocks +You could create a category called “Blocks”, and this category is supposed to +contain entries for every single block (i.e. node) in the game. For this use +case, a free form approach would be very inefficient and error-prone, as a +lot of data can be reused. + +Here the template function comes in handy: The internal entry data +contain a lot of different things about a block, like block name, identifier, +custom description and most importantly, the definition table of the block. + +Finally, the template function takes all that data and turns it into +sentences which are just concatenated, telling as many useful facts about +this block as possible. + +## Functions +This is a list of all publicly available functions. + +### Overview +The most important functions are `doc.add_category` and `doc.ad_entry`. All other functions +are mostly used for utility and examination purposes. + +If not mentioned otherwise, the return value of all functions is `nil`. + +These functions are available: + +#### Core +* `doc.add_category`: Adds a new category +* `doc.add_entry`: Adds a new entry + +#### Display +* `doc.show_entry`: Shows a particular entry to a player +* `doc.show_category`: Shows the entry list of a category to a player +* `doc.show_doc`: Opens the main help form for a player + +#### Query +* `doc.get_category_definition`: Returns the definition table of a category +* `doc.get_entry_definition`: Returns the definition table of an entry +* `doc.entry_exists`: Checks whether an entry exists +* `doc.entry_viewed`: Checks whether an entry has been viewed/read by a player +* `doc.entry_revealed`: Checks whether an entry is visible and normally accessible to a player +* `doc.get_category_count`: Returns the total number of categories +* `doc.get_entry_count`: Returns the total number of entries in a category +* `doc.get_viewed_count`: Returns the number of entries a player has viewed in a category +* `doc.get_revealed_count`: Returns the number of entries a player has access to in a category +* `doc.get_hidden_count`: Returns the number of entries which are hidden from a player in a category +* `doc.get_selection`: Returns the currently viewed entry/category of a player + +#### Modify +* `doc.set_category_order`: Sets the order of categories in the category list +* `doc.mark_entry_as_viewed`: Manually marks an entry as viewed/read by a player +* `doc.mark_entry_as_revealed`: Make a hidden entry visible and accessible to a player +* `doc.mark_all_entries_as_revealed`: Make all hidden entries visible and accessible to a player + +#### Aliases +* `doc.add_entry_alias`: Add an alternative name which can be used to access an entry + +#### Special widgets +This API provides functions to add unique “widgets” for functionality +you may find useful when creating entry templates. You find these +functions in `doc.widgets`. +Currently there is a widget for scrollable multi-line text and a +widget providing an image gallery. + + + +### `doc.add_category(id, def)` +Adds a new category. You have to define an unique identifier, a name +and a template function to build the entry formspec from the entry +data. + +**Important**: You must call this function *before* any player joins. + +#### Parameters +* `id`: Unique category identifier as a string +* `def`: Definition table with the following fields: + * `name`: Category name to be shown in the interface + * `description`: (optional) Short description of the category, + will be shown as tooltip. Recommended style (in English): + First letter capitalized, no punctuation at the end, + max. 100 characters + * `build_formspec`: The template function (see below). Takes entry data + as its first parameter (has the data type of the entry data) and the + name of the player who views the entry as its second parameter. It must + return a formspec which is inserted in the Entry tab. + * `sorting`: (optional) Sorting algorithm for display order of entries + * `"abc"`: Alphabetical (default) + * `"nosort"`: Entries appear in no particular order + * `"custom"`: Manually define the order of entries in `sorting_data` + * `"function"`: Sort by function defined in `sorting_data` + * `sorting_data`: (optional) Additional data for special sorting methods. + * If `sorting=="custom"`, this field must contain a table (list form) in which + the entry IDs are specified in the order they are supposed to appear in the + entry list. All entries which are missing in this table will appear in no + particular order below the final specified one. + * If `sorting=="function"`, this field is a compare function to be used as + the `comp` parameter of `table.sort`. The parameters given are two entries. + * This field is not required if `sorting` has any other value + * `hide_entries_by_default` (optional): If `true`, all entries + added to this category will start as hidden, unless explicitly specified otherwise + (default: `false`) + +Note: For function-based sorting, the entries provided to the compare function +will have the following format: + + { + eid = e, -- unique entry identifier + name = n, -- entry name + data = d, -- arbitrary entry data + } + +#### Using `build_formspec` +For `build_formspec` you can either define your own function which +procedurally generates the entry formspec or you use one of the +following predefined convenience functions: + +* `doc.entry_builders.text`: Expects entry data to be a string. + It will be inserted directly into the entry. Useful for entries with + a free form text. +* `doc.entry_builders.text_and_gallery`: For entries with text and + an optional standard gallery (3 rows, 3:2 aspect ratio). Expects + entry data to be a table with these fields: + * `text`: The entry text + * `images`: The images of the gallery, the format is the same as the + `imagedata` parameter of `doc.widgets.gallery`. Can be `nil`, in + which case no gallery is shown for the entry +* `doc.entry_builders.formspec`: Entry data is expected to contain the + complete entry formspec as a string. Useful if your entries. Useful + if you expect your entries to differ wildly in layouts. + +##### Formspec restrictions +When building your formspec, you have to respect the size limitations. +The help form currently uses a size of 15×10.5 and you must make sure +all entry widgets are inside a boundary box. The remaining space is +reserved for widgets of the help form and should not be used to avoid +overlapping. +Read from the following variables to calculate the final formspec coordinates: + +* `doc.FORMSPEC.WIDTH`: Width of help formspec +* `doc.FORMSPEC.HEIGHT`: Height of help formspec +* `doc.FORMSPEC.ENTRY_START_X`: Leftmost X point of bounding box +* `doc.FORMSPEC.ENTRY_START_Y`: Topmost Y point of bounding box +* `doc.FORMSPEC.ENTRY_END_X`: Rightmost X point of bounding box +* `doc.FORMSPEC.ENTRY_END_Y`: Bottom Y point of bounding box +* `doc.FORMSPEC.ENTRY_WIDTH`: Width of the entry widgets bounding box +* `doc.FORMSPEC.ENTRY_HEIGHT`: Height of the entry widgets bounding box + +Finally, to avoid naming collisions, you must make sure that all identifiers +of your own formspec elements do *not* begin with “`doc_`”. + +##### Receiving formspec events +You can even use the formspec elements you have added with `build_formspec` to +receive formspec events, just like with any other formspec. For receiving, use +the standard function `minetest.register_on_player_receive_fields` to register +your event handling. The `formname` parameter will be `doc:entry`. Use +`doc.get_selection` to get the category ID and entry ID of the entry in question. + +### `doc.add_entry(category_id, entry_id, def)` +Adds a new entry into an existing category. You have to define the category +to which to insert the entry, the entry's identifier, a name and some +data which defines the entry. Note you do not directly define here how the +end result of an entry looks like, this is done by `build_formspec` from +the category definition. + +**Important**: You must call this function *before* any player joins. + +#### Parameters +* `category_id`: Identifier of the category to add the entry into +* `entry_id`: Unique identifier of the new entry, as a string +* `def`: Definition table, it has the following fields: + * `name`: Entry name to be shown in the interface + * `hidden`: (optional) If `true`, entry will not be displayed in entry list + initially (default: `false`); it can be revealed later + * `data`: Arbitrary data attached to the entry. Any data type is allowed; + The data in this field will be used to create the actual formspec + with `build_formspec` from the category definition + +### `doc.set_category_order(category_list)` +Sets the order of categories in the category list. +The help starts with this default order: + + {"basics", "nodes", "tools", "craftitems", "advanced"} + +This function can be called at any time, but it recommended to only call +this function once for the entire server session and to only call it +from game mods, to avoid contradictions. If this function is called a +second time by any mod, a warning is written into the log. + +#### Parameters +* `category_list`: List of category IDs in the order they should appear + in the category list. All unspecified categories will be appended to + the end + + +### `doc.show_doc(playername)` +Opens the main help formspec for the player (“Category list” tab). + +#### Parameters +* `playername`: Name of the player to show the formspec to + +### `doc.show_category(playername, category_id)` +Opens the help formspec for the player at the specified category +(“Entry list” tab). + +#### Parameters +* `playername`: Name of the player to show the formspec to +* `category_id`: Category identifier of the selected category + +### `doc.show_entry(playername, category_id, entry_id, ignore_hidden)` +Opens the help formspec for the player showing the specified entry +of a category (“Entry” tab). If the entry is hidden, an error message +is displayed unless `ignore_hidden==true`. + +#### Parameters +* `playername`: Name of the player to show the formspec to +* `category_id`: Category identifier of the selected category +* `entry_id`: Entry identifier of the entry to show +* `ignore_hidden`: (optional) If `true`, shows entry even if it is still hidden + to the player; this will automatically reveal the entry to this player for the + rest of the game + +### `doc.get_category_definition(category_id)` +Returns the definition of the specified category. + +#### Parameters +* `category_id`: Category identifier of the category to the the definition + for + +#### Return value +The category's definition table as specified in the `def` argument of +`doc.add_category`. The table fields are the same. + +### `doc.get_entry_definition(category_id, entry_id)` +Returns the definition of the specified entry. + +#### Parameters +* `category_id`: Category identifier of entry's category +* `entry_id`: Entry identifier of the entry to get the definition for + +#### Return value +The entry's definition table as specified in the `def` argument of +`doc.add_entry`. The table fields are the same. + +### `doc.entry_exists(category_id, entry_id)` +Checks whether the specified entry exists and returns `true` or `false`. +Entry aliases are taken into account. + +#### Parameters +* `category_id`: Category identifier of the category to check +* `entry_id`: Entry identifier of the entry to check for its existence + +#### Return value +Returns `true` if and only if: + +* The specified category exists +* It contains the specified entry + +Otherwise, returns `false`. + +### `doc.entry_viewed(playername, category_id, entry_id)` +Tells whether the specified entry is marked as “viewed” (or read) by +the player. + +#### Parameters +* `playername`: Name of the player to check +* `category_id`: Category identifier of the category to check +* `entry_id`: Entry identifier of the entry to check + +#### Return value +`true`, if entry is viewed, `false` otherwise. + +### `doc.entry_revealed(playername, category_id, entry_id)` +Tells whether the specified entry is marked as “revealed” to the player +and thus visible and accessible to the player. + +#### Parameters +* `playername`: Name of the player to check +* `category_id`: Category identifier of the category to check +* `entry_id`: Entry identifier of the entry to check + +#### Return value +`true`, if entry is revealed, `false` otherwise. + +### `doc.mark_entry_as_viewed(playername, category_id, entry_id)` +Marks a particular entry as “viewed” (or read) by a player. This will +also automatically reveal the entry to the player for the rest of +the game. + +#### Parameters +* `playername`: Name of the player for whom to mark an entry as “viewed” +* `category_id`: Category identifier of the category of the entry to mark +* `entry_id`: Entry identifier of the entry to mark + +### `doc.mark_entry_as_revealed(playername, category_id, entry_id)` +Marks a particular entry as “revealed” to a player. If the entry is +declared as hidden, it will become visible in the list of entries for +this player and will always be accessible with `doc.show_entry`. This +change remains for the rest of the game. + +For entries which are not normally hidden, this function has no direct +effect. + +#### Parameters +* `playername`: Name of the player for whom to reveal the entry +* `category_id`: Category identifier of the category of the entry to reveal +* `entry_id`: Entry identifier of the entry to reveal + +### `doc.mark_all_entries_as_revealed(playername)` +Marks all entries as “revealed” to a player. This change remains for the +rest of the game. + +#### Parameters +* `playername`: Name of the player for whom to reveal the entries + +### `doc.add_entry_alias(category_id_orig, entry_id_orig, category_id_alias, entry_id_alias)` +Adds a single alias for an entry. If an entry has an alias, supplying the +alias to a function which demand `category_id` and `entry_id` will work as expected. +When using this function, you must make sure the category already exists. + +This function could be useful for legacy support after changing an entry ID or +moving an entry to a different category. + +#### Parameters +* `category_id_orig`: Category identifier of the category of the entry in question +* `entry_id_orig`: The original (!) entry identifier of the entry to create an alias + for +* `category_id_alias`: The category ID of the alias +* `entry_id_alias`: The entry ID of the alias + +#### Example + + doc.add_entry_alias("nodes", "test", "craftitems", "test2") + +When calling a function with category ID “craftitems” and entry ID “test2”, it will +act as if you supplied “nodes” as category ID and “test” as entry ID. + +### `doc.get_category_count()` +Returns the number of registered categories. + +#### Return value +Number of registered categories. + +### `doc.get_entry_count(category_id)` +Returns the number of entries in a category. + +#### Parameters +* `category_id`: Category identifier of the category in which to count entries + +#### Return value +Number of entries in the specified category. + +### `doc.get_viewed_count(playername, category_id)` +Returns how many entries have been viewed by a player. + +#### Parameters +* `playername`: Name of the player to count the viewed entries for +* `category_id`: Category identifier of the category in which to count the + viewed entries + +#### Return value +Amount of entries the player has viewed in the specified category. If the +player does not exist, this function returns `nil`. + +### `doc.get_revealed_count(playername, category_id)` +Returns how many entries the player has access to (non-hidden entries) +in this category. + +#### Parameters +* `playername`: Name of the player to count the revealed entries for +* `category_id`: Category identifier of the category in which to count the + revealed entries + +#### Return value +Amount of entries the player has access to in the specified category. If the +player does not exist, this function returns `nil`. + +### `doc.get_hidden_count(playername, category_id)` +Returns how many entries are hidden from the player in this category. + +#### Parameters +* `playername`: Name of the player to count the hidden entries for +* `category_id`: Category identifier of the category in which to count the + hidden entries + +#### Return value +Amount of entries hidden from the player. If the player does not exist, +this function returns `nil`. + +### `doc.get_selection(playername)` +Returns the currently or last viewed entry and/or category of a player. + +#### Parameter +* `playername`: Name of the player to query + +#### Return value +It returns up to 2 values. The first one is the category ID, the second one +is the entry ID of the entry/category which the player is currently viewing +or is the last entry the player viewed in this session. If the player only +viewed a category so far, the second value is `nil`. If the player has not +viewed a category as well, both returned values are `nil`. + + +### `doc.widgets.text(data, x, y, width, height)` +This is a convenience function for creating a special formspec widget. It creates +a widget in which you can insert scrollable multi-line text. + +#### Parameters +* `data`: Text to be written inside the widget +* `x`: Formspec X coordinate (optional) +* `y`: Formspec Y coordinate (optional) +* `width`: Width of the widget in formspec units (optional) +* `height`: Height of the widget in formspec units (optional) + +The default values for the optional parameters result in a widget which fills +nearly the entire entry page. + +#### Return value +Two values are returned, in this order: + +* string: Contains a complete formspec definition building the widget +* string: Formspec element ID of the created widget + +#### Note +If you use this function to build a formspec string, do not use identifiers +beginning with `doc_widget_text` to avoid naming collisions, as this function +makes use of such identifiers internally. + + +### `doc.widgets.gallery(imagedata, playername, x, y, aspect_ratio, width, rows, align_left, align_top)` +This function creates an image gallery which allows you to display an +arbitrary amount of images aligned horizontally. It is possible to add more +images than the space of an entry would normally held, this is done by adding +“scroll” buttons to the left and right which allows the user to see more images +of the gallery. + +This function is useful for adding multiple illustration to your entry without +worrying about space too much. Adding illustrations can help you to create +entry templates which aren't just lengthy walls of text. ;-) + +You can define the position, image aspect ratio, total gallery width and the +number of images displayed at once. You can *not* directly define the image +size, nor the resulting height of the overall gallery, those values will +be derived from the parameters. + +You can only really use this function efficiently inside a *custom* +`build_formspec` function definition. This is because you need to pass a +`playername`. You can currently also only add up to one gallery per entry; +adding more galleries is not supported and will lead to bugs. + +### Parameters +* `imagedata`: List of images to be displayed in the specified order. All images must + have the same aspect ratio. It's a table of tables with this format: + * `imagetype`: Type of image to be used (optional): + * `"image"`: Texture file (default) + * `"item"`: Item image, specified as itemstring + * `image`: What to display. Depending on `imagetype`, a texture file or itemstring +* `playername`: Name of the player who is viewing the entry in question +* `x`: Formspec X coordinate of the top left corner (optional) +* `y`: Formspec Y coordinate of the top left corner (optional) +* `aspect_ratio`: Aspect ratio of all the images (width/height) +* `width`: Total gallery width in formspec units (optional) +* `rows`: Number of images which can be seen at once (optional) +* `align_left`: If `false`, gallery is aligned to the left instead of the right (optional) +* `align_right`: If `false`, gallery is aligned to the bottom instead of the top (optional) + +The default values for the optional parameters result in a gallery with +3 rows which is placed at the top left corner and spans the width of the +entry and assumes an aspect ratio of two thirds. + +If the number of images is greater than `rows`, “scroll” buttons will appear +at the left and right side of the images. + +#### Return values +Two values are returned, in this order: + +* string: Contains a complete formspec definition building the gallery +* number: The height the gallery occupies in the formspec + +## Extending this mod (naming conventions) +If you want to extend this mod with your own functionality, it is recommended +that you put all API functions into `doc.sub.`. +As a naming convention, if you mod *primarily* depends on `doc`, it is recommended +to use a short mod name which starts with “`doc_`”, like `doc_items`, +`doc_minetest_game`, or `doc_identifier`. + +One mod which uses this convention is `doc_items` which uses the `doc.sub.items` +table. + + diff --git a/doc/README.md b/doc/README.md new file mode 100644 index 0000000..802701c --- /dev/null +++ b/doc/README.md @@ -0,0 +1,52 @@ +# Documentation System [`doc`] +This mod provides a simple and highly extensible form in which the user +can access help pages about various things and the modder can add those pages. +The mod itself does not provide any help texts, just the framework. +It is the heart of the Help modpack, on which the other Help mods depend. + +Current version: 1.2.1 + +## For players +### Accessing the help +To open the help, there are multiple ways: + +- Use the `/helpform` chat command. This works always. +- If you use one of these mods, there's a help button in the inventory menu: + - Unified Inventory [`unified_inventory`] + - Simple Fast Inventory Buttons [`sfinv_buttons`] + - Inventory++ [`inventory_plus`] + +The help itself should be more or less self-explanatory. + +This mod is useless on its own, you will only need this mod as a dependency +for mods which actually add some help entries. + +### Hidden entries +Some entries are initially hidden from you. You can't see them until you +unlocked them. Mods can decide for themselves how particular entries are +revealed. Normally you just have to proceed in the game to unlock more +entries. Hidden entries exist to avoid spoilers and give players a small +sense of progress. + +Players with the `help_reveal` privilege can use the `/help_reveal` chat +command to reveal all hidden entries instantly. + +### Maintenance +The information of which player has viewed and revealed which entries is +stored in the world directory in the file `doc.mt`. You can safely reset +the viewed/revealed state of all players by deleting this file. Players +then need to start over revealing all entries. + +## For modders and game authors +This mod helps you in creating extensive and flexible help entries for your +mods or game. You can write about basically anything in the presentation +you prefer. + +To get started, read `API.md` in the directory of this mod. + +Note: If you want to add help texts for items and nodes, refer to the API +documentation of `doc_items`, instead of manually adding entries. +For custom entities, you may also want to add support for `doc_identifier`. + +## License of everything +MIT License diff --git a/doc/init.lua b/doc/init.lua new file mode 100644 index 0000000..9c612b3 --- /dev/null +++ b/doc/init.lua @@ -0,0 +1,1220 @@ +local S = minetest.get_translator("doc") +local F = function(f) return minetest.formspec_escape(S(f)) end + +-- Compability for 0.4.14 or earlier +local colorize +if minetest.colorize then + colorize = minetest.colorize +else + colorize = function(color, text) return text end +end + +doc = {} + +-- Some informational variables +-- DO NOT CHANGE THEM AFTERWARDS AT RUNTIME! + +-- Version number (follows the SemVer specification 2.0.0) +doc.VERSION = {} +doc.VERSION.MAJOR = 1 +doc.VERSION.MINOR = 2 +doc.VERSION.PATCH = 1 +doc.VERSION.STRING = doc.VERSION.MAJOR.."."..doc.VERSION.MINOR.."."..doc.VERSION.PATCH + +-- Formspec information +doc.FORMSPEC = {} +-- Width of formspec +doc.FORMSPEC.WIDTH = 15 +doc.FORMSPEC.HEIGHT = 10.5 + +--[[ Recommended bounding box coordinates for widgets to be placed in entry pages. Make sure +all entry widgets are completely inside these coordinates to avoid overlapping. ]] +doc.FORMSPEC.ENTRY_START_X = 0.2 +doc.FORMSPEC.ENTRY_START_Y = 0.5 +doc.FORMSPEC.ENTRY_END_X = doc.FORMSPEC.WIDTH +doc.FORMSPEC.ENTRY_END_Y = doc.FORMSPEC.HEIGHT - 0.5 +doc.FORMSPEC.ENTRY_WIDTH = doc.FORMSPEC.ENTRY_END_X - doc.FORMSPEC.ENTRY_START_X +doc.FORMSPEC.ENTRY_HEIGHT = doc.FORMSPEC.ENTRY_END_Y - doc.FORMSPEC.ENTRY_START_Y + +--TODO: Use container formspec element later + +-- Internal helper variables +local DOC_INTRO = S("This is the help.") + +local COLOR_NOT_VIEWED = "#00FFFF" -- cyan +local COLOR_VIEWED = "#FFFFFF" -- white +local COLOR_HIDDEN = "#999999" -- gray +local COLOR_ERROR = "#FF0000" -- red + +local CATEGORYFIELDSIZE = { + WIDTH = math.ceil(doc.FORMSPEC.WIDTH / 4), + HEIGHT = math.floor(doc.FORMSPEC.HEIGHT-1), +} + +doc.data = {} +doc.data.categories = {} +doc.data.aliases = {} +-- Default order (includes categories of other mods from the Docuentation System modpack) +doc.data.category_order = {"basics", "nodes", "tools", "craftitems", "advanced"} +doc.data.category_count = 0 +doc.data.players = {} + +-- Space for additional APIs +doc.sub = {} + +-- Status variables +local set_category_order_was_called = false + +-- Returns the entry definition and true entry ID of an entry, taking aliases into account +local function get_entry(category_id, entry_id) + local category = doc.data.categories[category_id] + local entry + if category ~= nil then + entry = category.entries[entry_id] + end + if category == nil or entry == nil then + local c_alias = doc.data.aliases[category_id] + if c_alias then + local alias = c_alias[entry_id] + if alias then + category_id = alias.category_id + entry_id = alias.entry_id + category = doc.data.categories[category_id] + if category then + entry = category.entries[entry_id] + else + return nil + end + else + return nil + end + else + return nil + end + end + return entry, category_id, entry_id +end + +--[[ Core API functions ]] + +-- Add a new category +function doc.add_category(id, def) + if doc.data.categories[id] == nil and id ~= nil then + doc.data.categories[id] = {} + doc.data.categories[id].entries = {} + doc.data.categories[id].entry_count = 0 + doc.data.categories[id].hidden_count = 0 + doc.data.categories[id].def = def + -- Determine order position + local order_id = nil + for i=1,#doc.data.category_order do + if doc.data.category_order[i] == id then + order_id = i + break + end + end + if order_id == nil then + table.insert(doc.data.category_order, id) + doc.data.categories[id].order_position = #doc.data.category_order + else + doc.data.categories[id].order_position = order_id + end + doc.data.category_count = doc.data.category_count + 1 + return true + else + return false + end +end + +-- Add a new entry +function doc.add_entry(category_id, entry_id, def) + local cat = doc.data.categories[category_id] + if cat ~= nil then + local hidden = def.hidden or (def.hidden == nil and cat.def.hide_entries_by_default) + if hidden then + cat.hidden_count = cat.hidden_count + 1 + def.hidden = hidden + end + cat.entry_count = doc.data.categories[category_id].entry_count + 1 + if def.name == nil or def.name == "" then + minetest.log("warning", "[doc] Nameless entry added. Entry ID: "..entry_id) + end + cat.entries[entry_id] = def + return true + else + return false + end +end + +-- Marks a particular entry as viewed by a certain player, which also +-- automatically reveals it +function doc.mark_entry_as_viewed(playername, category_id, entry_id) + local entry, category_id, entry_id = get_entry(category_id, entry_id) + if not entry then + return + end + if doc.data.players[playername].stored_data.viewed[category_id] == nil then + doc.data.players[playername].stored_data.viewed[category_id] = {} + doc.data.players[playername].stored_data.viewed_count[category_id] = 0 + end + if doc.entry_exists(category_id, entry_id) and doc.data.players[playername].stored_data.viewed[category_id][entry_id] ~= true then + doc.data.players[playername].stored_data.viewed[category_id][entry_id] = true + doc.data.players[playername].stored_data.viewed_count[category_id] = doc.data.players[playername].stored_data.viewed_count[category_id] + 1 + -- Needed because viewed entries get a different color + doc.data.players[playername].entry_textlist_needs_updating = true + end + doc.mark_entry_as_revealed(playername, category_id, entry_id) +end + +-- Marks a particular entry as revealed/unhidden by a certain player +function doc.mark_entry_as_revealed(playername, category_id, entry_id) + local entry, category_id, entry_id = get_entry(category_id, entry_id) + if not entry then + return + end + if doc.data.players[playername].stored_data.revealed[category_id] == nil then + doc.data.players[playername].stored_data.revealed[category_id] = {} + doc.data.players[playername].stored_data.revealed_count[category_id] = doc.get_entry_count(category_id) - doc.data.categories[category_id].hidden_count + end + if doc.entry_exists(category_id, entry_id) and entry.hidden and doc.data.players[playername].stored_data.revealed[category_id][entry_id] ~= true then + doc.data.players[playername].stored_data.revealed[category_id][entry_id] = true + doc.data.players[playername].stored_data.revealed_count[category_id] = doc.data.players[playername].stored_data.revealed_count[category_id] + 1 + -- Needed because a new entry is added to the list of visible entries + doc.data.players[playername].entry_textlist_needs_updating = true + -- Notify player of entry revelation + if doc.data.players[playername].stored_data.notify_on_reveal == true then + if minetest.get_modpath("central_message") ~= nil then + local cat = doc.data.categories[category_id] + cmsg.push_message_player(minetest.get_player_by_name(playername), S("New help entry unlocked: @1 > @2", cat.def.name, entry.name)) + end + -- To avoid sound spamming, don't play sound more than once per second + local last_sound = doc.data.players[playername].last_reveal_sound + if last_sound == nil or os.difftime(os.time(), last_sound) >= 1 then + -- Play notification sound + minetest.sound_play({ name = "doc_reveal", gain = 0.2 }, { to_player = playername }) + doc.data.players[playername].last_reveal_sound = os.time() + end + end + end +end + +-- Reveal +function doc.mark_all_entries_as_revealed(playername) + -- Has at least 1 new entry been revealed? + local reveal1 = false + for category_id, category in pairs(doc.data.categories) do + if doc.data.players[playername].stored_data.revealed[category_id] == nil then + doc.data.players[playername].stored_data.revealed[category_id] = {} + doc.data.players[playername].stored_data.revealed_count[category_id] = doc.get_entry_count(category_id) - doc.data.categories[category_id].hidden_count + end + for entry_id, _ in pairs(category.entries) do + if doc.data.players[playername].stored_data.revealed[category_id][entry_id] ~= true then + doc.data.players[playername].stored_data.revealed[category_id][entry_id] = true + doc.data.players[playername].stored_data.revealed_count[category_id] = doc.data.players[playername].stored_data.revealed_count[category_id] + 1 + reveal1 = true + end + end + end + + local msg + if reveal1 then + -- Needed because new entries are added to player's view on entry list + doc.data.players[playername].entry_textlist_needs_updating = true + + msg = S("All help entries revealed!") + + -- Play notification sound (ignore sound limit intentionally) + minetest.sound_play({ name = "doc_reveal", gain = 0.2 }, { to_player = playername }) + doc.data.players[playername].last_reveal_sound = os.time() + else + msg = S("All help entries are already revealed.") + end + -- Notify + if minetest.get_modpath("central_message") ~= nil then + cmsg.push_message_player(minetest.get_player_by_name(playername), msg) + else + minetest.chat_send_player(playername, msg) + end +end + +-- Returns true if the specified entry has been viewed by the player +function doc.entry_viewed(playername, category_id, entry_id) + local entry, category_id, entry_id = get_entry(category_id, entry_id) + if doc.data.players[playername].stored_data.viewed[category_id] == nil then + return false + else + return doc.data.players[playername].stored_data.viewed[category_id][entry_id] == true + end +end + +-- Returns true if the specified entry is hidden from the player +function doc.entry_revealed(playername, category_id, entry_id) + local entry, category_id, entry_id = get_entry(category_id, entry_id) + local hidden = doc.data.categories[category_id].entries[entry_id].hidden + if doc.data.players[playername].stored_data.revealed[category_id] == nil then + return not hidden + else + if hidden then + return doc.data.players[playername].stored_data.revealed[category_id][entry_id] == true + else + return true + end + end +end + +-- Returns category definition +function doc.get_category_definition(category_id) + if doc.data.categories[category_id] == nil then + return nil + end + return doc.data.categories[category_id].def +end + +-- Returns entry definition +function doc.get_entry_definition(category_id, entry_id) + if not doc.entry_exists(category_id, entry_id) then + return nil + end + local entry, _, _ = get_entry(category_id, entry_id) + return entry +end + +-- Opens the main documentation formspec for the player +function doc.show_doc(playername) + if doc.get_category_count() <= 0 then + minetest.show_formspec(playername, "doc:error_no_categories", doc.formspec_error_no_categories()) + return + end + local formspec = doc.formspec_core()..doc.formspec_main(playername) + minetest.show_formspec(playername, "doc:main", formspec) +end + +-- Opens the documentation formspec for the player at the specified category +function doc.show_category(playername, category_id) + if doc.get_category_count() <= 0 then + minetest.show_formspec(playername, "doc:error_no_categories", doc.formspec_error_no_categories()) + return + end + doc.data.players[playername].catsel = nil + doc.data.players[playername].category = category_id + doc.data.players[playername].entry = nil + local formspec = doc.formspec_core(2)..doc.formspec_category(category_id, playername) + minetest.show_formspec(playername, "doc:category", formspec) +end + +-- Opens the documentation formspec for the player showing the specified entry in a category +function doc.show_entry(playername, category_id, entry_id, ignore_hidden) + if doc.get_category_count() <= 0 then + minetest.show_formspec(playername, "doc:error_no_categories", doc.formspec_error_no_categories()) + return + end + local entry, category_id, entry_id = get_entry(category_id, entry_id) + if ignore_hidden or doc.entry_revealed(playername, category_id, entry_id) then + local playerdata = doc.data.players[playername] + playerdata.category = category_id + playerdata.entry = entry_id + + doc.mark_entry_as_viewed(playername, category_id, entry_id) + playerdata.entry_textlist_needs_updating = true + doc.generate_entry_list(category_id, playername) + + playerdata.catsel = playerdata.catsel_list[entry_id] + playerdata.galidx = 1 + + local formspec = doc.formspec_core(3)..doc.formspec_entry(category_id, entry_id, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + else + minetest.show_formspec(playername, "doc:error_hidden", doc.formspec_error_hidden(category_id, entry_id)) + end +end + +-- Returns true if and only if: +-- * The specified category exists +-- * This category contains the specified entry +-- Aliases are taken into account +function doc.entry_exists(category_id, entry_id) + return get_entry(category_id, entry_id) ~= nil +end + +-- Sets the order of categories in the category list +function doc.set_category_order(categories) + local reverse_categories = {} + for cid=1,#categories do + reverse_categories[categories[cid]] = cid + end + doc.data.category_order = categories + for cid, cat in pairs(doc.data.categories) do + if reverse_categories[cid] == nil then + table.insert(doc.data.category_order, cid) + end + end + reverse_categories = {} + for cid=1, #doc.data.category_order do + reverse_categories[categories[cid]] = cid + end + + for cid, cat in pairs(doc.data.categories) do + cat.order_position = reverse_categories[cid] + end + if set_category_order_was_called then + minetest.log("warning", "[doc] doc.set_category_order was called again!") + end + set_category_order_was_called = true +end + +-- Adds an alias for an entry. Attempting to open an entry by an alias name +-- results in opening the entry of the original name. +function doc.add_entry_alias(category_id_orig, entry_id_orig, category_id_alias, entry_id_alias) + if not doc.data.aliases[category_id_alias] then + doc.data.aliases[category_id_alias] = {} + end + doc.data.aliases[category_id_alias][entry_id_alias] = { category_id = category_id_orig, entry_id = entry_id_orig } +end + +-- Returns number of categories +function doc.get_category_count() + return doc.data.category_count +end + +-- Returns number of entries in category +function doc.get_entry_count(category_id) + return doc.data.categories[category_id].entry_count +end + +-- Returns how many entries have been viewed by the player +function doc.get_viewed_count(playername, category_id) + local playerdata = doc.data.players[playername] + if playerdata == nil then + return nil + end + local count = playerdata.stored_data.viewed_count[category_id] + if count == nil then + playerdata.stored_data.viewed[category_id] = {} + count = 0 + playerdata.stored_data.viewed_count[category_id] = count + return count + else + return count + end +end + +-- Returns how many entries have been revealed by the player +function doc.get_revealed_count(playername, category_id) + local playerdata = doc.data.players[playername] + if playerdata == nil then + return nil + end + local count = playerdata.stored_data.revealed_count[category_id] + if count == nil then + playerdata.stored_data.revealed[category_id] = {} + count = doc.get_entry_count(category_id) - doc.data.categories[category_id].hidden_count + playerdata.stored_data.revealed_count[category_id] = count + return count + else + return count + end +end + +-- Returns how many entries are hidden from the player +function doc.get_hidden_count(playername, category_id) + local playerdata = doc.data.players[playername] + if playerdata == nil then + return nil + end + local total = doc.get_entry_count(category_id) + local rcount = playerdata.stored_data.revealed_count[category_id] + if rcount == nil then + return total + else + return total - rcount + end +end + +-- Returns the currently viewed entry and/or category of the player +function doc.get_selection(playername) + local playerdata = doc.data.players[playername] + if playerdata ~= nil then + local cat = playerdata.category + if cat then + local entry = playerdata.entry + if entry then + return cat, entry + else + return cat + end + else + return nil + end + else + return nil + end +end + +-- Template function templates, to be used for build_formspec in doc.add_category +doc.entry_builders = {} + +-- Scrollable freeform text +doc.entry_builders.text = function(data) + local formstring = doc.widgets.text(data, doc.FORMSPEC.ENTRY_START_X, doc.FORMSPEC.ENTRY_START_Y, doc.FORMSPEC.ENTRY_WIDTH - 0.4, doc.FORMSPEC.ENTRY_HEIGHT) + return formstring +end + +-- Scrollable freeform text with an optional standard gallery (3 rows, 3:2 aspect ratio) +doc.entry_builders.text_and_gallery = function(data, playername) + -- How much height the image gallery “steals” from the text widget + local stolen_height = 0 + local formstring = "" + -- Only add the gallery if images are in the data, otherwise, the text widget gets all of the space + if data.images ~= nil then + local gallery + gallery, stolen_height = doc.widgets.gallery(data.images, playername, nil, doc.FORMSPEC.ENTRY_END_Y + 0.2, nil, nil, nil, nil, false) + formstring = formstring .. gallery + end + formstring = formstring .. doc.widgets.text(data.text, + doc.FORMSPEC.ENTRY_START_X, + doc.FORMSPEC.ENTRY_START_Y, + doc.FORMSPEC.ENTRY_WIDTH - 0.4, + doc.FORMSPEC.ENTRY_HEIGHT - stolen_height) + + return formstring +end + +doc.widgets = {} + +-- Scrollable freeform text +doc.widgets.text = function(data, x, y, width, height) + if x == nil then + x = doc.FORMSPEC.ENTRY_START_X + end + -- Offset to table[], which was used for this in a previous version + local xfix = x + 0.35 + if y == nil then + y = doc.FORMSPEC.ENTRY_START_Y + end + if width == nil then + width = doc.FORMSPEC.ENTRY_WIDTH + end + if height == nil then + height = doc.FORMSPEC.ENTRY_HEIGHT + end + -- Weird offset for textarea[] + local heightfix = height + 1 + + -- Also add background box + local formstring = "box["..tostring(x-0.175)..","..tostring(y)..";"..tostring(width)..","..tostring(height)..";#000000]" .. + "textarea["..tostring(xfix)..","..tostring(y)..";"..tostring(width)..","..tostring(heightfix)..";;;"..minetest.formspec_escape(data).."]" + return formstring +end + +-- Image gallery +-- Currently, only one gallery per entry is supported. TODO: Add support for multiple galleries in an entry (low priority) +doc.widgets.gallery = function(imagedata, playername, x, y, aspect_ratio, width, rows, align_left, align_top) + if playername == nil then return nil end -- emergency exit + + local formstring = "" + + -- Defaults + if x == nil then + if align_left == false then + x = doc.FORMSPEC.ENTRY_END_X + else + x = doc.FORMSPEC.ENTRY_START_X + end + end + if y == nil then + if align_top == false then + y = doc.FORMSPEC.ENTRY_END_Y + else + y = doc.FORMSPEC.ENTRY_START_Y + end + end + if width == nil then width = doc.FORMSPEC.ENTRY_WIDTH end + if rows == nil then rows = 3 end + + if align_left == false then + x = x - width + end + + local imageindex = doc.data.players[playername].galidx + doc.data.players[playername].maxgalidx = #imagedata + doc.data.players[playername].galrows = rows + + if aspect_ratio == nil then aspect_ratio = (2/3) end + local pos = 0 + local totalimagewidth, iw, ih + local bw = 0.5 + local buttonoffset = 0 + if #imagedata > rows then + totalimagewidth = width - bw*2 + iw = totalimagewidth / rows + ih = iw * aspect_ratio + if align_top == false then + y = y - ih + end + + local tt + if imageindex > 1 then + formstring = formstring .. "button["..x..","..y..";"..bw..","..ih..";doc_button_gallery_prev;"..F("<").."]" + if rows == 1 then + tt = F("Show previous image") + else + tt = F("Show previous gallery page") + end + formstring = formstring .. "tooltip[doc_button_gallery_prev;"..tt.."]" + end + if (imageindex + rows) <= #imagedata then + local rightx = buttonoffset + (x + rows * iw) + formstring = formstring .. "button["..rightx..","..y..";"..bw..","..ih..";doc_button_gallery_next;"..F(">").."]" + if rows == 1 then + tt = F("Show next image") + else + tt = F("Show next gallery page") + end + formstring = formstring .. "tooltip[doc_button_gallery_next;"..tt.."]" + end + buttonoffset = bw + else + totalimagewidth = width + iw = totalimagewidth / rows + ih = iw * aspect_ratio + if align_top == false then + y = y - ih + end + end + for i=imageindex, math.min(#imagedata, (imageindex-1)+rows) do + local xoffset = buttonoffset + (x + pos * iw) + local nx = xoffset - 0.2 + local ny = y - 0.05 + if imagedata[i].imagetype == "item" then + formstring = formstring .. "item_image["..xoffset..","..y..";"..iw..","..ih..";"..imagedata[i].image.."]" + else + formstring = formstring .. "image["..xoffset..","..y..";"..iw..","..ih..";"..imagedata[i].image.."]" + end + formstring = formstring .. "label["..nx..","..ny..";"..i.."]" + pos = pos + 1 + end + local bw, bh + + return formstring, ih +end + +-- Direct formspec +doc.entry_builders.formspec = function(data) + return data +end + +--[[ Internal stuff ]] + +-- Loading and saving player data +do + local filepath = minetest.get_worldpath().."/doc.mt" + local file = io.open(filepath, "r") + if file then + minetest.log("action", "[doc] doc.mt opened.") + local string = file:read() + io.close(file) + if(string ~= nil) then + local savetable = minetest.deserialize(string) + for name, players_stored_data in pairs(savetable.players_stored_data) do + doc.data.players[name] = {} + doc.data.players[name].stored_data = players_stored_data + end + minetest.log("action", "[doc] doc.mt successfully read.") + end + end +end + +function doc.save_to_file() + local savetable = {} + savetable.players_stored_data = {} + for name, playerdata in pairs(doc.data.players) do + savetable.players_stored_data[name] = playerdata.stored_data + end + + local savestring = minetest.serialize(savetable) + + local filepath = minetest.get_worldpath().."/doc.mt" + local file = io.open(filepath, "w") + if file then + file:write(savestring) + io.close(file) + minetest.log("action", "[doc] Wrote player data into "..filepath..".") + else + minetest.log("error", "[doc] Failed to write player data into "..filepath..".") + end +end + +minetest.register_on_leaveplayer(function(player) + doc.save_to_file() +end) + +minetest.register_on_shutdown(function() + minetest.log("action", "[doc] Server shuts down. Player data is about to be saved.") + doc.save_to_file() +end) + +--[[ Functions for internal use ]] + +function doc.formspec_core(tab) + if tab == nil then tab = 1 else tab = tostring(tab) end + return "size["..doc.FORMSPEC.WIDTH..","..doc.FORMSPEC.HEIGHT.."]tabheader[0,0;doc_header;".. + minetest.formspec_escape(S("Category list")) .. "," .. + minetest.formspec_escape(S("Entry list")) .. "," .. + minetest.formspec_escape(S("Entry")) .. ";" + ..tab..";false;false]" + -- Let the Game decide on the style, such as background, etc. +end + +function doc.formspec_main(playername) + local formstring = "textarea[0.35,0;"..doc.FORMSPEC.WIDTH..",1;;;"..minetest.formspec_escape(DOC_INTRO) .. "\n" + local notify_checkbox_x, notify_checkbox_y + if doc.get_category_count() >= 1 then + formstring = formstring .. F("Please select a category you wish to learn more about:").."]" + if doc.get_category_count() <= (CATEGORYFIELDSIZE.WIDTH * CATEGORYFIELDSIZE.HEIGHT) then + local y = 1 + local x = 1 + -- Show all categories in order + for c=1,#doc.data.category_order do + local id = doc.data.category_order[c] + local data = doc.data.categories[id] + local bw = doc.FORMSPEC.WIDTH / math.floor(((doc.data.category_count-1) / CATEGORYFIELDSIZE.HEIGHT)+1) + -- Skip categories which do not exist + if data ~= nil then + -- Category buton + local button = "button["..((x-1)*bw)..","..y..";"..bw..",1;doc_button_category_"..id..";"..minetest.formspec_escape(data.def.name).."]" + local tooltip = "" + -- Optional description + if data.def.description ~= nil then + tooltip = "tooltip[doc_button_category_"..id..";"..minetest.formspec_escape(data.def.description).."]" + end + formstring = formstring .. button .. tooltip + y = y + 1 + if y > CATEGORYFIELDSIZE.HEIGHT then + x = x + 1 + y = 1 + end + end + end + notify_checkbox_x = 0 + notify_checkbox_y = doc.FORMSPEC.HEIGHT-0.5 + else + formstring = formstring .. "textlist[0,1;"..(doc.FORMSPEC.WIDTH-0.2)..","..(doc.FORMSPEC.HEIGHT-2)..";doc_mainlist;" + for c=1,#doc.data.category_order do + local id = doc.data.category_order[c] + local data = doc.data.categories[id] + formstring = formstring .. minetest.formspec_escape(data.def.name) + if c < #doc.data.category_order then + formstring = formstring .. "," + end + end + local sel = doc.data.categories[doc.data.players[playername].category] + if sel ~= nil then + formstring = formstring .. ";" + formstring = formstring .. doc.data.categories[doc.data.players[playername].category].order_position + end + formstring = formstring .. "]" + formstring = formstring .. "button[0,"..(doc.FORMSPEC.HEIGHT-1)..";3,1;doc_button_goto_category;"..F("Show category").."]" + notify_checkbox_x = 3.5 + notify_checkbox_y = doc.FORMSPEC.HEIGHT-1 + end + local text + if minetest.get_modpath("central_message") then + text = F("Notify me when new help is available") + else + text = F("Play notification sound when new help is available") + end + formstring = formstring .. "checkbox["..notify_checkbox_x..","..notify_checkbox_y..";doc_setting_notify_on_reveal;"..text..";".. + tostring(doc.data.players[playername].stored_data.notify_on_reveal == true) .. "]" + else + formstring = formstring .. "]" + end + return formstring +end + +function doc.formspec_error_no_categories() + local formstring = "size[8,6]textarea[0.25,0;8,6;;" + formstring = formstring .. + minetest.formspec_escape( + colorize(COLOR_ERROR, S("Error: No help available.")) .. "\n\n" .. +S("No categories have been registered, but they are required to provide help.").."\n".. +S("The Documentation System [doc] does not come with help contents on its own, it needs additional mods to add help content. Please make sure such mods are enabled on for this world, and try again.")) .. "\n\n" .. +S("Recommended mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia.") + formstring = formstring .. ";]button_exit[3,5;2,1;okay;"..F("OK").."]" + return formstring +end + +function doc.formspec_error_hidden(category_id, entry_id) + local formstring = "size[8,6]textarea[0.25,0;8,6;;" + formstring = formstring .. minetest.formspec_escape( + colorize(COLOR_ERROR, S("Error: Access denied.")) .. "\n\n" .. + S("Access to the requested entry has been denied; this entry is secret. You may unlock access by progressing in the game. Figure out on your own how to unlock this entry.")) + formstring = formstring .. ";]button_exit[3,5;2,1;okay;"..F("OK").."]" + return formstring +end + +function doc.generate_entry_list(cid, playername) + local formstring + if doc.data.players[playername].entry_textlist == nil + or doc.data.players[playername].catsel_list == nil + or doc.data.players[playername].category ~= cid + or doc.data.players[playername].entry_textlist_needs_updating == true then + local entry_textlist = "textlist[0,1;"..(doc.FORMSPEC.WIDTH-0.2)..","..(doc.FORMSPEC.HEIGHT-2)..";doc_catlist;" + local counter = 0 + doc.data.players[playername].entry_ids = {} + local entries = doc.get_sorted_entry_names(cid) + doc.data.players[playername].catsel_list = {} + for i=1, #entries do + local eid = entries[i] + local edata = doc.data.categories[cid].entries[eid] + if doc.entry_revealed(playername, cid, eid) then + table.insert(doc.data.players[playername].entry_ids, eid) + doc.data.players[playername].catsel_list[eid] = counter + 1 + -- Colorize entries based on viewed status + local viewedprefix = COLOR_NOT_VIEWED + local name = edata.name + if name == nil or name == "" then + name = S("Nameless entry (@1)", eid) + if doc.entry_viewed(playername, cid, eid) then + viewedprefix = "#FF4444" + else + viewedprefix = COLOR_ERROR + end + elseif doc.entry_viewed(playername, cid, eid) then + viewedprefix = COLOR_VIEWED + end + entry_textlist = entry_textlist .. viewedprefix .. minetest.formspec_escape(name) .. "," + counter = counter + 1 + end + end + if counter >= 1 then + entry_textlist = string.sub(entry_textlist, 1, #entry_textlist-1) + end + local catsel = doc.data.players[playername].catsel + if catsel then + entry_textlist = entry_textlist .. ";"..catsel + end + entry_textlist = entry_textlist .. "]" + doc.data.players[playername].entry_textlist = entry_textlist + formstring = entry_textlist + doc.data.players[playername].entry_textlist_needs_updating = false + else + formstring = doc.data.players[playername].entry_textlist + end + return formstring +end + +function doc.get_sorted_entry_names(cid) + local sort_table = {} + local entry_table = {} + local cat = doc.data.categories[cid] + local used_eids = {} + -- Helper function to extract the entry ID out of the output table + local extract = function(entry_table) + local eids = {} + for k,v in pairs(entry_table) do + local eid = v.eid + table.insert(eids, eid) + end + return eids + end + -- Predefined sorting + if cat.def.sorting == "custom" then + for i=1,#cat.def.sorting_data do + local new_entry = table.copy(cat.entries[cat.def.sorting_data[i]]) + new_entry.eid = cat.def.sorting_data[i] + table.insert(entry_table, new_entry) + used_eids[cat.def.sorting_data[i]] = true + end + end + for eid,entry in pairs(cat.entries) do + local new_entry = table.copy(entry) + new_entry.eid = eid + if not used_eids[eid] then + table.insert(entry_table, new_entry) + end + table.insert(sort_table, entry.name) + end + if cat.def.sorting == "custom" then + return extract(entry_table) + else + table.sort(sort_table) + end + local reverse_sort_table = table.copy(sort_table) + for i=1, #sort_table do + reverse_sort_table[sort_table[i]] = i + end + local comp + if cat.def.sorting ~= "nosort" then + -- Sorting by user function + if cat.def.sorting == "function" then + comp = cat.def.sorting_data + -- Alphabetic sorting + elseif cat.def.sorting == "abc" or cat.def.sorting == nil then + comp = function(e1, e2) + if reverse_sort_table[e1.name] < reverse_sort_table[e2.name] then return true else return false end + end + end + table.sort(entry_table, comp) + end + + return extract(entry_table) +end + +function doc.formspec_category(id, playername) + local formstring + if id == nil then + formstring = "label[0,0;"..F("Help > (No Category)") .. "]" + formstring = formstring .. "label[0,0.5;"..F("You haven't chosen a category yet. Please choose one in the category list first.").."]" + formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;"..F("Go to category list").."]" + else + formstring = "label[0,0;"..minetest.formspec_escape(S("Help > @1", doc.data.categories[id].def.name)).."]" + local total = doc.get_entry_count(id) + if total >= 1 then + local revealed = doc.get_revealed_count(playername, id) + if revealed == 0 then + formstring = formstring .. "label[0,0.5;"..minetest.formspec_escape(S("Currently all entries in this category are hidden from you.").."\n"..S("Unlock new entries by progressing in the game.")).."]" + formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]" + else + formstring = formstring .. "label[0,0.5;"..F("This category has the following entries:").."]" + formstring = formstring .. doc.generate_entry_list(id, playername) + formstring = formstring .. "button[0,"..(doc.FORMSPEC.HEIGHT-1)..";3,1;doc_button_goto_entry;"..F("Show entry").."]" + formstring = formstring .. "label["..(doc.FORMSPEC.WIDTH-4)..","..(doc.FORMSPEC.HEIGHT-1)..";"..minetest.formspec_escape(S("Number of entries: @1", total)).."\n" + local viewed = doc.get_viewed_count(playername, id) + local hidden = total - revealed + local new = total - viewed - hidden + -- TODO/FIXME: Check if number of hidden/viewed entries is always correct + if viewed < total then + formstring = formstring .. colorize(COLOR_NOT_VIEWED, minetest.formspec_escape(S("New entries: @1", new))) + if hidden > 0 then + formstring = formstring .. "\n" + formstring = formstring .. colorize(COLOR_HIDDEN, minetest.formspec_escape(S("Hidden entries: @1", hidden))).."]" + else + formstring = formstring .. "]" + end + else + formstring = formstring .. F("All entries read.").."]" + end + end + else + formstring = formstring .. "label[0,0.5;"..F("This category is empty.").."]" + formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]" + end + end + return formstring +end + +function doc.formspec_entry_navigation(category_id, entry_id) + if doc.get_entry_count(category_id) < 1 then + return "" + end + local formstring = "" + formstring = formstring .. "button["..(doc.FORMSPEC.WIDTH-2)..","..(doc.FORMSPEC.HEIGHT-0.5)..";1,1;doc_button_goto_prev;"..F("<").."]" + formstring = formstring .. "button["..(doc.FORMSPEC.WIDTH-1)..","..(doc.FORMSPEC.HEIGHT-0.5)..";1,1;doc_button_goto_next;"..F(">").."]" + formstring = formstring .. "tooltip[doc_button_goto_prev;"..F("Show previous entry").."]" + formstring = formstring .. "tooltip[doc_button_goto_next;"..F("Show next entry").."]" + return formstring +end + +function doc.formspec_entry(category_id, entry_id, playername) + local formstring + if category_id == nil then + formstring = "label[0,0;"..F("Help > (No Category)") .. "]" + formstring = formstring .. "label[0,0.5;"..F("You haven't chosen a category yet. Please choose one in the category list first.").."]" + formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;"..F("Go to category list").."]" + elseif entry_id == nil then + formstring = "label[0,0;"..minetest.formspec_escape(S("Help > @1 > (No Entry)", doc.data.categories[category_id].def.name)) .. "]" + if doc.get_entry_count(category_id) >= 1 then + formstring = formstring .. "label[0,0.5;"..F("You haven't chosen an entry yet. Please choose one in the entry list first.").."]" + formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_category;"..F("Go to entry list").."]" + else + formstring = formstring .. "label[0,0.5;"..F("This category does not have any entries.").."]" + formstring = formstring .. "button[0,1.5;3,1;doc_button_goto_main;"..F("Go to category list").."]" + end + else + + local category = doc.data.categories[category_id] + local entry = get_entry(category_id, entry_id) + local ename = entry.name + if ename == nil or ename == "" then + ename = S("Nameless entry (@1)", entry_id) + end + formstring = "label[0,0;"..minetest.formspec_escape(S("Help > @1 > @2", category.def.name, ename)).."]" + formstring = formstring .. category.def.build_formspec(entry.data, playername) + formstring = formstring .. doc.formspec_entry_navigation(category_id, entry_id) + end + return formstring +end + +function doc.process_form(player,formname,fields) + local playername = player:get_player_name() + --[[ process clicks on the tab header ]] + if(formname == "doc:main" or formname == "doc:category" or formname == "doc:entry") then + if fields.doc_header ~= nil then + local tab = tonumber(fields.doc_header) + local formspec, subformname, contents + local cid, eid + cid = doc.data.players[playername].category + eid = doc.data.players[playername].entry + if(tab==1) then + contents = doc.formspec_main(playername) + subformname = "main" + elseif(tab==2) then + contents = doc.formspec_category(cid, playername) + subformname = "category" + elseif(tab==3) then + doc.data.players[playername].galidx = 1 + contents = doc.formspec_entry(cid, eid, playername) + if cid ~= nil and eid ~= nil then + doc.mark_entry_as_viewed(playername, cid, eid) + end + subformname = "entry" + end + formspec = doc.formspec_core(tab)..contents + minetest.show_formspec(playername, "doc:" .. subformname, formspec) + return + end + end + if(formname == "doc:main") then + for cid,_ in pairs(doc.data.categories) do + if fields["doc_button_category_"..cid] then + doc.data.players[playername].catsel = nil + doc.data.players[playername].category = cid + doc.data.players[playername].entry = nil + doc.data.players[playername].entry_textlist_needs_updating = true + local formspec = doc.formspec_core(2)..doc.formspec_category(cid, playername) + minetest.show_formspec(playername, "doc:category", formspec) + break + end + end + if fields["doc_mainlist"] then + local event = minetest.explode_textlist_event(fields["doc_mainlist"]) + local cid = doc.data.category_order[event.index] + if cid ~= nil then + if event.type == "CHG" then + doc.data.players[playername].catsel = nil + doc.data.players[playername].category = cid + doc.data.players[playername].entry = nil + doc.data.players[playername].entry_textlist_needs_updating = true + elseif event.type == "DCL" then + doc.data.players[playername].catsel = nil + doc.data.players[playername].category = cid + doc.data.players[playername].entry = nil + doc.data.players[playername].entry_textlist_needs_updating = true + local formspec = doc.formspec_core(2)..doc.formspec_category(cid, playername) + minetest.show_formspec(playername, "doc:category", formspec) + end + end + end + if fields["doc_button_goto_category"] then + local cid = doc.data.players[playername].category + doc.data.players[playername].catsel = nil + doc.data.players[playername].entry = nil + doc.data.players[playername].entry_textlist_needs_updating = true + local formspec = doc.formspec_core(2)..doc.formspec_category(cid, playername) + minetest.show_formspec(playername, "doc:category", formspec) + end + if fields["doc_setting_notify_on_reveal"] then + doc.data.players[playername].stored_data.notify_on_reveal = fields["doc_setting_notify_on_reveal"] == "true" + end + elseif(formname == "doc:category") then + if fields["doc_button_goto_entry"] then + local cid = doc.data.players[playername].category + if cid ~= nil then + local eid = nil + local eids, catsel = doc.data.players[playername].entry_ids, doc.data.players[playername].catsel + if eids ~= nil and catsel ~= nil then + eid = eids[catsel] + end + doc.data.players[playername].galidx = 1 + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + doc.mark_entry_as_viewed(playername, cid, eid) + end + end + if fields["doc_button_goto_main"] then + local formspec = doc.formspec_core(1)..doc.formspec_main(playername) + minetest.show_formspec(playername, "doc:main", formspec) + end + if fields["doc_catlist"] then + local event = minetest.explode_textlist_event(fields["doc_catlist"]) + if event.type == "CHG" then + doc.data.players[playername].catsel = event.index + doc.data.players[playername].entry = doc.data.players[playername].entry_ids[event.index] + doc.data.players[playername].entry_textlist_needs_updating = true + elseif event.type == "DCL" then + local cid = doc.data.players[playername].category + local eid = nil + local eids, catsel = doc.data.players[playername].entry_ids, event.index + if eids ~= nil and catsel ~= nil then + eid = eids[catsel] + end + doc.mark_entry_as_viewed(playername, cid, eid) + doc.data.players[playername].entry_textlist_needs_updating = true + doc.data.players[playername].galidx = 1 + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + end + end + elseif(formname == "doc:entry") then + if fields["doc_button_goto_main"] then + local formspec = doc.formspec_core(1)..doc.formspec_main(playername) + minetest.show_formspec(playername, "doc:main", formspec) + elseif fields["doc_button_goto_category"] then + local formspec = doc.formspec_core(2)..doc.formspec_category(doc.data.players[playername].category, playername) + minetest.show_formspec(playername, "doc:category", formspec) + elseif fields["doc_button_goto_next"] then + if doc.data.players[playername].catsel == nil then return end -- emergency exit + local eids = doc.data.players[playername].entry_ids + local cid = doc.data.players[playername].category + local new_catsel= doc.data.players[playername].catsel + 1 + local new_eid = eids[new_catsel] + if #eids > 1 and new_catsel <= #eids then + doc.mark_entry_as_viewed(playername, cid, new_eid) + doc.data.players[playername].catsel = new_catsel + doc.data.players[playername].entry = new_eid + doc.data.players[playername].galidx = 1 + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, new_eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + end + elseif fields["doc_button_goto_prev"] then + if doc.data.players[playername].catsel == nil then return end -- emergency exit + local eids = doc.data.players[playername].entry_ids + local cid = doc.data.players[playername].category + local new_catsel= doc.data.players[playername].catsel - 1 + local new_eid = eids[new_catsel] + if #eids > 1 and new_catsel >= 1 then + doc.mark_entry_as_viewed(playername, cid, new_eid) + doc.data.players[playername].catsel = new_catsel + doc.data.players[playername].entry = new_eid + doc.data.players[playername].galidx = 1 + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, new_eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + end + elseif fields["doc_button_gallery_prev"] then + local cid, eid = doc.get_selection(playername) + if doc.data.players[playername].galidx - doc.data.players[playername].galrows > 0 then + doc.data.players[playername].galidx = doc.data.players[playername].galidx - doc.data.players[playername].galrows + end + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + elseif fields["doc_button_gallery_next"] then + local cid, eid = doc.get_selection(playername) + if doc.data.players[playername].galidx + doc.data.players[playername].galrows <= doc.data.players[playername].maxgalidx then + doc.data.players[playername].galidx = doc.data.players[playername].galidx + doc.data.players[playername].galrows + end + local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid, playername) + minetest.show_formspec(playername, "doc:entry", formspec) + end + else + if fields["doc_inventory_plus"] and minetest.get_modpath("inventory_plus") then + doc.show_doc(playername) + return + end + end +end + +minetest.register_on_player_receive_fields(doc.process_form) + +minetest.register_chatcommand("helpform", { + params = "", + description = S("Open a window providing help entries about Minetest and more"), + privs = {}, + func = function(playername, param) + doc.show_doc(playername) + end, + } +) + +minetest.register_on_joinplayer(function(player) + local playername = player:get_player_name() + local playerdata = doc.data.players[playername] + if playerdata == nil then + -- Initialize player data + doc.data.players[playername] = {} + playerdata = doc.data.players[playername] + -- Gallery index, stores current index of first displayed image in a gallery + playerdata.galidx = 1 + -- Maximum gallery index (index of last image in gallery) + playerdata.maxgalidx = 1 + -- Number of rows in an gallery of the current entry + playerdata.galrows = 1 + -- Table for persistant data + playerdata.stored_data = {} + -- Contains viewed entries + playerdata.stored_data.viewed = {} + -- Count viewed entries + playerdata.stored_data.viewed_count = {} + -- Contains revealed/unhidden entries + playerdata.stored_data.revealed = {} + -- Count revealed entries + playerdata.stored_data.revealed_count = {} + else + -- Completely rebuild viewed and revealed counts from scratch + for cid, cat in pairs(doc.data.categories) do + if playerdata.stored_data.viewed[cid] == nil then + playerdata.stored_data.viewed[cid] = {} + end + if playerdata.stored_data.revealed[cid] == nil then + playerdata.stored_data.revealed[cid] = {} + end + local vc = 0 + local rc = doc.get_entry_count(cid) - doc.data.categories[cid].hidden_count + for eid, entry in pairs(cat.entries) do + if playerdata.stored_data.viewed[cid][eid] then + vc = vc + 1 + playerdata.stored_data.revealed[cid][eid] = true + end + if playerdata.stored_data.revealed[cid][eid] and entry.hidden then + rc = rc + 1 + end + end + playerdata.stored_data.viewed_count[cid] = vc + playerdata.stored_data.revealed_count[cid] = rc + end + end + + -- Add button for Inventory++ + if minetest.get_modpath("inventory_plus") ~= nil then + inventory_plus.register_button(player, "doc_inventory_plus", S("Help")) + end +end) + +---[[ Add buttons for inventory mods ]] +local button_action = function(player) + doc.show_doc(player:get_player_name()) +end + +-- Unified Inventory +if minetest.get_modpath("unified_inventory") ~= nil then + unified_inventory.register_button("doc", { + type = "image", + image = "doc_button_icon_hires.png", + tooltip = S("Help"), + action = button_action, + }) +end + +-- sfinv_buttons +if minetest.get_modpath("sfinv_buttons") ~= nil then + sfinv_buttons.register_button("doc", { + image = "doc_button_icon_lores.png", + tooltip = S("Collection of help texts"), + title = S("Help"), + action = button_action, + }) +end + + +minetest.register_privilege("help_reveal", { + description = S("Allows you to reveal all hidden help entries with /help_reveal"), + give_to_singleplayer = false +}) + +minetest.register_chatcommand("help_reveal", { + params = "", + description = S("Reveal all hidden help entries to you"), + privs = { help_reveal = true }, + func = function(name, param) + doc.mark_all_entries_as_revealed(name) + end, +}) diff --git a/doc/locale/doc.de.tr b/doc/locale/doc.de.tr new file mode 100644 index 0000000..39fc725 --- /dev/null +++ b/doc/locale/doc.de.tr @@ -0,0 +1,51 @@ +# textdomain:doc +<=< +>=> +Access to the requested entry has been denied; this entry is secret. You may unlock access by progressing in the game. Figure out on your own how to unlock this entry.=Der Zugriff auf den angeforderten Eintrag wurde verweigert; dieser Eintrag ist geheim. Sie können durch weiteren Spielfortschritt den Zugriff freischalten. Finden Sie selbst heraus, wie Sie diesen Eintrag freischalten können. +All entries read.=Alle Einträge gelesen. +All help entries revealed!=Alle Hilfseinträge aufgedeckt! +All help entries are already revealed.=Alle Hilfseinträge sind schon aufgedeckt. +Allows you to reveal all hidden help entries with /help_reveal=Ermöglicht es Ihnen, alle verborgenen Hilfseinträge mit /help_reveal freizuschalten +Category list=Kategorienliste +Currently all entries in this category are hidden from you.=Momentan sind alle Einträge in dieser Kategorie vor Ihnen verborgen. +Unlock new entries by progressing in the game.=Schalten Sie neue Einträge frei, indem Sie im Spiel fortschreiten. +Help=Hilfe +Entry=Eintrag +Entry list=Eintragsliste +Error: Access denied.=Fehler: Zugriff verweigert. +Error: No help available.=Fehler: Keine Hilfe verfügbar. +Go to category list=Zur Kategorienliste +Go to entry list=Zur Eintragsliste +Help > (No Category)=Hilfe > (Keine Kategorie) +Help > @1=Hilfe > @1 +Help > @1 > @2=Hilfe > @1 > @2 +Help > @1 > (No Entry)=Hilfe > @1 > (Kein Eintrag) +Hidden entries: @1=Verborgene Einträge: @1 +New entries: @1=Neue Einträge: @1 +New help entry unlocked: @1 > @2=Neuen Hilfseintrag freigeschaltet: @1 > @2 +No categories have been registered, but they are required to provide help.=Es wurden keine Kategorien registriert, aber sie werden benötigt, um die Hilfe anbieten zu können. +The Documentation System [doc] does not come with help contents on its own, it needs additional mods to add help content. Please make sure such mods are enabled on for this world, and try again.=Das Dokumentationssystem [doc] bringt von sich aus keine eigenen Hilfsinhalte mit, es benötigt zusätzliche Mods, um sie hinzuzufügen. Bitte stellen Sie sicher, dass solche Mods für diese Welt aktiviert sind und versuchen Sie es erneut. +Number of entries: @1=Anzahl der Einträge: @1 +OK=OK +Open a window providing help entries about Minetest and more=Ein Fenster mit Hilfseinträgen über Minetest und mehr öffnen +Please select a category you wish to learn more about:=Bitte wählen Sie eine Kategorie, über die Sie mehr erfahren möchten, aus: +Recommended mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia.=Empfohlene Mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia. +Reveal all hidden help entries to you=Alle für Sie verborgenen Hilfseinträge freischalten +Show entry=Eintrag zeigen +Show category=Kategorie zeigen +Show next entry=Nächsten Eintrag zeigen +Show previous entry=Vorherigen Eintrag zeigen +This category does not have any entries.=Diese Kategorie hat keine Einträge. +This category has the following entries:=Diese Kategorie hat die folgenden Einträge: +This category is empty.=Diese Kategorie ist leer. +This is the help.=Dies ist die Hilfe. +You haven't chosen a category yet. Please choose one in the category list first.=Sie haben noch keine Kategorie gewählt, Bitte wählen Sie zuerst eine aus. +You haven't chosen an entry yet. Please choose one in the entry list first.=Sie haben noch keinen Eintrag gewählt. Bitte wählen Sie zuerst einen aus. +Nameless entry (@1)=Namenloser Eintrag (@1) +Collection of help texts=Sammlung von Hilfstexten +Notify me when new help is available=Benachrichtigen, wenn neue Hilfe verfügbar ist +Play notification sound when new help is available=Toneffekt abspielen, wenn neue Hilfe verfügbar ist +Show previous image=Vorheriges Bild zeigen +Show previous gallery page=Vorherige Galerieseite zeigen +Show next image=Nächstes Bild zeigen +Show next gallery page=Nächste Galerieseite zeigen diff --git a/doc/locale/doc.pt.tr b/doc/locale/doc.pt.tr new file mode 100644 index 0000000..52d6836 --- /dev/null +++ b/doc/locale/doc.pt.tr @@ -0,0 +1,43 @@ +# textdomain:doc +<= +>= +Access to the requested entry has been denied; this entry is secret. You may unlock access by progressing in the game. Figure out on your own how to unlock this entry.=O acesso à entrada solicitada foi negado; essa entrada é secreta. Você pode desbloquear o acesso progredindo no jogo. Descobrir por conta própria como desbloquear essa entrada. +All entries read.=Todas as entradas lidas. +All help entries revealed!=Todas as entradas de ajuda reveladas! +All help entries are already revealed.=Todas as entradas de ajuda já foram reveladas. +Allows you to reveal all hidden help entries with /help_reveal=Permite revelar todas as entradas de ajuda ocultas com /help_reveal +Category list=Lista de Categorias +Currently all entries in this category are hidden from you.\\nUnlock new entries by progressing in the game.=Atualmente, todas as entradas nessa categoria estão ocultas a você.\\nDesbloqueie novas entradas progredindo no jogo. +Help=Ajuda +Entry=Entrada +Entry list=Lista de Entradas +Error: Access denied.=Erro: Acesso negado. +Error: No help available.=Erro: Nenhuma ajuda disponível. +Go to category list=Ver categorias +Go to entry list=Ir para a lista de entradas +Help > @1=Ajuda > @1 +Help > @1 > @2=Ajuda > @1 > @2 +Help > @1 > (No Entry)=Ajuda > @1 > (Nenhuma Entrada) +Help > (No Category)=Ajuda > (Nenhuma Categoria) +Hidden entries: @1=Entradas ocultas: @1 +Nameless entry (@1)=Entrada sem nome (@1) +New entries: @1=Novas entradas: (@1) +New help entry unlocked: @1 > @2=Nova entrada de ajuda desbloqueada: @1 > @2 +No categories have been registered, but they are required to provide help.\nThe Documentation System [doc] does not come with help contents on its own, it needs additional mods to add help content. Please make sure such mods are enabled on for this world, and try again.=Nenhuma categoria foi registrada, mas é necessário fornecer ajuda.\nO Sistema de Documentação [doc] não vem com o conteúdo de ajuda, ele precisa de mods adicionais para adicionar conteúdo de ajuda. Por favor, certifique-se de que os mods estão habilitados para este mundo e tente novamente. +Number of entries: @1=Número de entradas: @1 +OK=OK +Open a window providing help entries about Minetest and more=Abra uma janela fornecendo entradas de ajuda sobre o Minetest e mais +Please select a category you wish to learn more about:=Por favor, selecione uma categoria sobre a qual você deseja saber mais: +Recommended mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia.=Mods recomendados: doc_basics, doc_items, doc_identifier, doc_encyclopedia. +Reveal all hidden help entries to you=Revela todas as entradas de ajuda ocultas para você +Show entry=Ver entrada +Show category=Ver categoria +Show next entry=Ver próxima entrada +Show previous entry=Ver entrada anterior +This category does not have any entries.=Essa categoria não possui entradas. +This category has the following entries:=Essa categoria tem as seguintes entradas: +This category is empty.=Essa categoria está vazia. +This is the help.=Essa é a ajuda. +You haven't chosen a category yet. Please choose one in the category list first.=Você ainda não escolheu uma categoria. Por favor, escolha uma na lista de categorias primeiro. +You haven't chosen an entry yet. Please choose one in the entry list first.=Você ainda não escolheu uma entrada. Por favor, escolha uma na lista de entrada primeiro. +Collection of help texts=Coleção de textos de ajuda diff --git a/doc/locale/doc.pt_BR.tr b/doc/locale/doc.pt_BR.tr new file mode 100644 index 0000000..52d6836 --- /dev/null +++ b/doc/locale/doc.pt_BR.tr @@ -0,0 +1,43 @@ +# textdomain:doc +<= +>= +Access to the requested entry has been denied; this entry is secret. You may unlock access by progressing in the game. Figure out on your own how to unlock this entry.=O acesso à entrada solicitada foi negado; essa entrada é secreta. Você pode desbloquear o acesso progredindo no jogo. Descobrir por conta própria como desbloquear essa entrada. +All entries read.=Todas as entradas lidas. +All help entries revealed!=Todas as entradas de ajuda reveladas! +All help entries are already revealed.=Todas as entradas de ajuda já foram reveladas. +Allows you to reveal all hidden help entries with /help_reveal=Permite revelar todas as entradas de ajuda ocultas com /help_reveal +Category list=Lista de Categorias +Currently all entries in this category are hidden from you.\\nUnlock new entries by progressing in the game.=Atualmente, todas as entradas nessa categoria estão ocultas a você.\\nDesbloqueie novas entradas progredindo no jogo. +Help=Ajuda +Entry=Entrada +Entry list=Lista de Entradas +Error: Access denied.=Erro: Acesso negado. +Error: No help available.=Erro: Nenhuma ajuda disponível. +Go to category list=Ver categorias +Go to entry list=Ir para a lista de entradas +Help > @1=Ajuda > @1 +Help > @1 > @2=Ajuda > @1 > @2 +Help > @1 > (No Entry)=Ajuda > @1 > (Nenhuma Entrada) +Help > (No Category)=Ajuda > (Nenhuma Categoria) +Hidden entries: @1=Entradas ocultas: @1 +Nameless entry (@1)=Entrada sem nome (@1) +New entries: @1=Novas entradas: (@1) +New help entry unlocked: @1 > @2=Nova entrada de ajuda desbloqueada: @1 > @2 +No categories have been registered, but they are required to provide help.\nThe Documentation System [doc] does not come with help contents on its own, it needs additional mods to add help content. Please make sure such mods are enabled on for this world, and try again.=Nenhuma categoria foi registrada, mas é necessário fornecer ajuda.\nO Sistema de Documentação [doc] não vem com o conteúdo de ajuda, ele precisa de mods adicionais para adicionar conteúdo de ajuda. Por favor, certifique-se de que os mods estão habilitados para este mundo e tente novamente. +Number of entries: @1=Número de entradas: @1 +OK=OK +Open a window providing help entries about Minetest and more=Abra uma janela fornecendo entradas de ajuda sobre o Minetest e mais +Please select a category you wish to learn more about:=Por favor, selecione uma categoria sobre a qual você deseja saber mais: +Recommended mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia.=Mods recomendados: doc_basics, doc_items, doc_identifier, doc_encyclopedia. +Reveal all hidden help entries to you=Revela todas as entradas de ajuda ocultas para você +Show entry=Ver entrada +Show category=Ver categoria +Show next entry=Ver próxima entrada +Show previous entry=Ver entrada anterior +This category does not have any entries.=Essa categoria não possui entradas. +This category has the following entries:=Essa categoria tem as seguintes entradas: +This category is empty.=Essa categoria está vazia. +This is the help.=Essa é a ajuda. +You haven't chosen a category yet. Please choose one in the category list first.=Você ainda não escolheu uma categoria. Por favor, escolha uma na lista de categorias primeiro. +You haven't chosen an entry yet. Please choose one in the entry list first.=Você ainda não escolheu uma entrada. Por favor, escolha uma na lista de entrada primeiro. +Collection of help texts=Coleção de textos de ajuda diff --git a/doc/locale/template.txt b/doc/locale/template.txt new file mode 100644 index 0000000..fdeecfd --- /dev/null +++ b/doc/locale/template.txt @@ -0,0 +1,51 @@ +# textdomain:doc +<= +>= +Access to the requested entry has been denied; this entry is secret. You may unlock access by progressing in the game. Figure out on your own how to unlock this entry.= +All entries read.= +All help entries revealed!= +All help entries are already revealed.= +Allows you to reveal all hidden help entries with /help_reveal= +Category list= +Currently all entries in this category are hidden from you. +Unlock new entries by progressing in the game.= +Help= +Entry= +Entry list= +Error: Access denied.= +Error: No help available.= +Go to category list= +Go to entry list= +Help > @1= +Help > @1 > @2= +Help > @1 > (No Entry)= +Help > (No Category)= +Hidden entries: @1= +Nameless entry (@1)= +New entries: @1= +New help entry unlocked: @1 > @2= +No categories have been registered, but they are required to provide help.= +The Documentation System [doc] does not come with help contents on its own, it needs additional mods to add help content. Please make sure such mods are enabled on for this world, and try again.= +Number of entries: @1= +OK= +Open a window providing help entries about Minetest and more= +Please select a category you wish to learn more about:= +Recommended mods: doc_basics, doc_items, doc_identifier, doc_encyclopedia.= +Reveal all hidden help entries to you= +Show entry= +Show category= +Show next entry= +Show previous entry= +This category does not have any entries.= +This category has the following entries:= +This category is empty.= +This is the help.= +You haven't chosen a category yet. Please choose one in the category list first.= +You haven't chosen an entry yet. Please choose one in the entry list first.= +Collection of help texts= +Notify me when new help is available= +Play notification sound when new help is available= +Show previous image= +Show previous gallery page= +Show next image= +Show next gallery page= diff --git a/doc/mod.conf b/doc/mod.conf new file mode 100644 index 0000000..302fd83 --- /dev/null +++ b/doc/mod.conf @@ -0,0 +1,3 @@ +name = doc +optional_depends = unified_inventory, sfinv_buttons, central_message, inventory_plus +description = A simple in-game documentation system which enables mods to add help entries based on templates. diff --git a/doc/screenshot.png b/doc/screenshot.png new file mode 100644 index 0000000..90946a9 Binary files /dev/null and b/doc/screenshot.png differ diff --git a/doc/sounds/doc_reveal.ogg b/doc/sounds/doc_reveal.ogg new file mode 100644 index 0000000..3fbe176 Binary files /dev/null and b/doc/sounds/doc_reveal.ogg differ diff --git a/doc/textures/doc_awards_icon_generic.png b/doc/textures/doc_awards_icon_generic.png new file mode 100644 index 0000000..b33fa34 Binary files /dev/null and b/doc/textures/doc_awards_icon_generic.png differ diff --git a/doc/textures/doc_button_icon_hires.png b/doc/textures/doc_button_icon_hires.png new file mode 100644 index 0000000..25c9fe4 Binary files /dev/null and b/doc/textures/doc_button_icon_hires.png differ diff --git a/doc/textures/doc_button_icon_lores.png b/doc/textures/doc_button_icon_lores.png new file mode 100644 index 0000000..3df6195 Binary files /dev/null and b/doc/textures/doc_button_icon_lores.png differ diff --git a/doc/textures/inventory_plus_doc_inventory_plus.png b/doc/textures/inventory_plus_doc_inventory_plus.png new file mode 100644 index 0000000..3df6195 Binary files /dev/null and b/doc/textures/inventory_plus_doc_inventory_plus.png differ diff --git a/hyperloop/LICENSE.txt b/hyperloop/LICENSE.txt new file mode 100644 index 0000000..1592dbb --- /dev/null +++ b/hyperloop/LICENSE.txt @@ -0,0 +1,13 @@ +This program 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 program 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 program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. diff --git a/hyperloop/README.md b/hyperloop/README.md new file mode 100644 index 0000000..c613a6c --- /dev/null +++ b/hyperloop/README.md @@ -0,0 +1,90 @@ +# Hyperloop v2 + +**A new evolution in the voxel word:** + +## Minetest goes Hyperloop! + +Hyperloop is passenger transportation system for travelling through evacuated tubes my means of passenger pods. +It is the fast and modern way of travelling. +* Hyperloop allows travelling from point to point in seconds (900 km/h) :-) +* The tubes system with all stations and pods have to be build by players +* It can be used even on small servers without lagging +* No configuration or programming of the tube network is necessary (only the station names have to be entered) + + +**![See Wiki Page for more info](https://github.com/joe7575/Minetest-Hyperloop/wiki)** + +![screenshot](https://github.com/joe7575/Minetest-Hyperloop/blob/master/screenshot.png) + + +The mod includes many different kind of blocks: +- Hyperloop Stations Block to automatically build the pod/car +- Hyperloop Booking Machine for the station to select the destination +- Hyperloop Tube to connect two stations +- Hyperloop Junction Block to connect up to 6 tubes for complex network structures +- Hyperloop Stations Signs +- Hyperloop Promo Poster for station advertisement +- Hyperloop Elevator to reach other levels +- Hyperloop Elevator Shaft to connect two elevator cars +- Hyperloop Station Book with all available stations (for builders/engineers) +- Hyperloop Tube Crowbar to crack/repair tube lines (for admins) +- Hyperloop WiFi Tubes for very large distances (optional) +- chat command to repair WorldEdit placed tubes +..and more. + + +Browse on: ![GitHub](https://github.com/joe7575/Minetest-Hyperloop) + +Download: ![GitHub](https://github.com/joe7575/Minetest-Hyperloop/archive/master.zip) + + +## Migration from v1 to v2 +The logic behind the tubes/shafts has changed. Hyperloop now uses tubelib2 as tube library. +That means, available worlds have to be migrated for the new tubes. This is done automatically but +has some risks. Therefore: + +**I recommend to backup your world or test the migration from v1 to v2 on a copy of your world!!!** + + +## What is new in v2 +- some textures changed +- the Elevator Shafts can now be used as ladder/climbing shafts +- the Crowbar is public available, but cracking a tube line need 'hyperloop' privs +- the Station Book is improved and simplified to find stations, junctions, and open tube ends +- a Waypoint plate is added to mark and easier find the tube destination +- Elevator shafts can be build in all directions (optional) +- WiFi Tubes can be crafted and placed by players (optional) +- intllib support added (German translation available) + + +## Introduction + +**![See Wiki Page for more info](https://github.com/joe7575/Minetest-Hyperloop/wiki)** + + +## Configuration +The following can be changed in the minetest menu (Settings -> Advanced Settings -> Mods -> hyperloop) or directly in 'minetest.conf' +* "WiFi block enabled" - To enable the usage of WiFi blocks +* "WiFi block crafting enabled" - To enable the crafting of WiFi blocks +* "free tube placement enabled" - If enabled Hyperloop Tubes and Elevator Shafts can be build in all directions. + When this option is disabled, Hyperloop tubes can only be built in the horizontal direction and elevator shafts in the vertical direction. + +Example for 'minetest.conf': +```LUA +hyperloop_wifi_enabled = true +hyperloop_wifi_crafting_enabled = false +hyperloop_free_tube_placement_enabled = true +``` + +## Dependencies +tubelib2 (![GitHub](https://github.com/joe7575/tubelib2)) +default +intllib +optional: worldedit, techage + + +# License +Copyright (C) 2017,2020 Joachim Stolberg +Code: Licensed under the GNU LGPL version 2.1 or later. See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt +Textures: CC0 +Display: Derived from the work of kaeza, sofar and others (digilines) LGPLv2.1+ diff --git a/hyperloop/booking.lua b/hyperloop/booking.lua new file mode 100644 index 0000000..c9536f1 --- /dev/null +++ b/hyperloop/booking.lua @@ -0,0 +1,84 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + Station reservation/blocking and trip booking +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +local S = hyperloop.S +local NS = hyperloop.NS + +local tBlockingTime = {} +local tBookings = {} -- open bookings: tBookings[SP(departure_pos)] = arrival_pos + +local Stations = hyperloop.Stations + +-- Reserve departure and arrival stations for some time +function hyperloop.reserve(departure_pos, arrival_pos, player) + if Stations:get(departure_pos) == nil then + hyperloop.chat(player, S("Station data is corrupted. Please rebuild the station!")) + return false + elseif Stations:get(arrival_pos) == nil then + hyperloop.chat(player, S("Station data is corrupted. Please rebuild the station!")) + return false + end + + if (tBlockingTime[SP(departure_pos)] or 0) > minetest.get_gametime() then + hyperloop.chat(player, S("Station is still blocked. Please try again in a few seconds!")) + return false + elseif (tBlockingTime[SP(arrival_pos)] or 0) > minetest.get_gametime() then + hyperloop.chat(player, S("Station is still blocked. Please try again in a few seconds!")) + return false + end + + -- place a reservation for 20 seconds to start the trip + tBlockingTime[SP(departure_pos)] = minetest.get_gametime() + 20 + tBlockingTime[SP(arrival_pos)] = minetest.get_gametime() + 20 + return true +end + +-- block the already reserved stations +function hyperloop.block(departure_pos, arrival_pos, seconds) + if Stations:get(departure_pos) == nil then + return false + elseif Stations:get(arrival_pos) == nil then + return false + end + + tBlockingTime[SP(departure_pos)] = minetest.get_gametime() + seconds + tBlockingTime[SP(arrival_pos)] = minetest.get_gametime() + seconds + return true +end + +-- check if station is blocked +function hyperloop.is_blocked(pos) + if not pos then return false end + if Stations:get(pos) == nil then + return false + end + + return (tBlockingTime[SP(pos)] or 0) > minetest.get_gametime() +end + + +function hyperloop.set_arrival(departure_pos, arrival_pos) + tBookings[SP(departure_pos)] = arrival_pos +end + +function hyperloop.get_arrival(departure_pos) + -- Return and delete the arrival pos + local arrival_pos = tBookings[SP(departure_pos)] + tBookings[SP(departure_pos)] = nil + return arrival_pos +end diff --git a/hyperloop/booking_node.lua b/hyperloop/booking_node.lua new file mode 100644 index 0000000..494d4cb --- /dev/null +++ b/hyperloop/booking_node.lua @@ -0,0 +1,288 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + Booking/ticket machine +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +-- Used to store the Station list for each booking machine: +-- tStationList[SP(pos)] = {pos1, pos2, ...} +local tStationList = {} + +local Stations = hyperloop.Stations + + +-- Form spec for the station list +local function generate_string(sortedList) + local tRes = {"size[12,8]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "item_image[0,0;1,1;hyperloop:booking]".. + "label[4,0; "..S("Select your destination").."]"} + tRes[2] = "tablecolumns[text,width=20;text,width=6,align=right;text]" + + local stations = {} + for idx,tDest in ipairs(sortedList) do + local name = tDest.name or S("") + local distance = tDest.distance or 0 + local info = tDest.booking_info or "" + + stations[#stations+1] = minetest.formspec_escape(string.sub(name, 1, 28)) + stations[#stations+1] = distance.."m" + stations[#stations+1] = minetest.formspec_escape(info) + end + + if #stations>0 then + tRes[#tRes+1] = "table[0,1;11.8,7.2;button;"..table.concat(stations, ",").."]" + else + tRes[#tRes+1] = "button_exit[4,4;3,1;button;Update]" + end + + return table.concat(tRes) +end + +local function store_station_list(pos, sortedList) + local tbl = {} + for idx,item in ipairs(sortedList) do + tbl[#tbl+1] = item.pos + end + tStationList[SP(pos)] = tbl +end + +local function remove_junctions(sortedList) + local tbl = {} + for idx,item in ipairs(sortedList) do + if not item.junction and item.booking_pos then + tbl[#tbl+1] = item + end + end + return tbl +end + +local function station_list_as_string(pos) + -- Generate a distance sorted list of all connected stations + local sortedList = Stations:station_list(pos, pos, "dist") + -- Delete the own station from list + table.remove(sortedList, 1) + -- remove all junctions from the list + sortedList = remove_junctions(sortedList) + -- store the list for later use + store_station_list(pos, sortedList) + -- Generate the formspec string + return generate_string(sortedList) +end + + +local function naming_formspec(pos) + local meta = minetest.get_meta(pos) + local formspec = "size[6,4]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[0,0;"..S("Please enter the station name to\nwhich this booking machine belongs.").."]" .. + "field[0.5,1.5;5,1;name;"..S("Station name")..";MyTown]" .. + "field[0.5,2.7;5,1;info;"..S("Additional station information")..";]" .. + "button_exit[2,3.6;2,1;exit;Save]" + meta:set_string("formspec", formspec) + meta:set_int("change_counter", 0) +end + + +local function booking_machine_update(pos) + local meta = M(pos) + local sStationPos = meta:get_string("sStationPos") + if sStationPos ~= "" then + local station_pos = P(sStationPos) + local counter = meta:get_int("change_counter") or 0 + local changed, newcounter = Stations:changed(counter) + if changed then + meta:set_string("formspec", station_list_as_string(station_pos)) + meta:set_int("change_counter", newcounter) + end + if not tStationList[sStationPos] then + local sortedList = Stations:station_list(station_pos, station_pos, "dist") + -- Delete the own station from list + table.remove(sortedList, 1) + -- remove all junctions from the list + sortedList = remove_junctions(sortedList) + -- store the list for later use + store_station_list(station_pos, sortedList) + end + end +end + + +local function on_receive_fields(pos, formname, fields, player) + booking_machine_update(pos) + -- station name entered? + if fields.name ~= nil then + local station_name = string.trim(fields.name) + if station_name == "" then + return + end + local stationPos = Stations:get_next_station(pos) + if stationPos then + if Stations:get(stationPos).booking_pos then + hyperloop.chat(player, S("Station has already a booking machine!")) + return + end + -- store meta and generate station formspec + Stations:update(stationPos, { + name = station_name, + booking_pos = pos, + booking_info = string.trim(fields.info), + }) + + local meta = M(pos) + meta:set_string("sStationPos", SP(stationPos)) + meta:set_string("infotext", "Station: "..station_name) + meta:set_string("formspec", station_list_as_string(stationPos)) + else + hyperloop.chat(player, S("Invalid station name!")) + end + elseif fields.button ~= nil then -- destination selected? + local te = minetest.explode_table_event(fields.button) + local idx = tonumber(te.row) + if idx and te.type=="CHG" then + local tStation, src_pos = hyperloop.get_base_station(pos) + local dest_pos = tStationList[SP(src_pos)] and tStationList[SP(src_pos)][idx] + if dest_pos and tStation then + -- place booking if not already blocked + if hyperloop.reserve(src_pos, dest_pos, player) then + hyperloop.set_arrival(src_pos, dest_pos) + -- open the pod door + hyperloop.open_pod_door(tStation) + end + else + -- data is corrupt, try an update + M(pos):set_int("change_counter", 0) + end + + minetest.close_formspec(player:get_player_name(), formname) + end + end +end + +local function on_destruct(pos) + local sStationPos = M(pos):get_string("sStationPos") + if sStationPos ~= "" then + Stations:update(P(sStationPos), { + booking_pos = "nil", + booking_info = "nil", + name = "Station", + }) + end +end + +-- wap from wall to ground +local function swap_node(pos, placer) + pos.y = pos.y - 1 + if minetest.get_node_or_nil(pos).name ~= "air" then + local node = minetest.get_node(pos) + node.name = "hyperloop:booking_ground" + node.param2 = hyperloop.get_facedir(placer) + pos.y = pos.y + 1 + minetest.swap_node(pos, node) + else + pos.y = pos.y + 1 + end +end + +-- wall mounted booking machine +minetest.register_node("hyperloop:booking", { + description = S("Hyperloop Booking Machine"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking_front.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, 2/16, 8/16, 8/16, 8/16}, + }, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + naming_formspec(pos) + swap_node(pos, placer) + end, + + on_rotate = screwdriver.disallow, + on_receive_fields = on_receive_fields, + on_destruct = on_destruct, + + paramtype = 'light', + light_source = 2, + paramtype2 = "facedir", + groups = {cracky=2}, + is_ground_content = false, +}) + +-- ground mounted booking machine +minetest.register_node("hyperloop:booking_ground", { + description = S("Hyperloop Booking Machine"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking.png", + "hyperloop_booking_front.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -3/16, 8/16, 8/16, 3/16}, + }, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + naming_formspec(pos) + end, + + on_receive_fields = on_receive_fields, + on_destruct = on_destruct, + + on_rotate = screwdriver.disallow, + drop = "hyperloop:booking", + light_source = 2, + paramtype = 'light', + paramtype2 = "facedir", + groups = {cracky=2, not_in_creative_inventory=1}, + is_ground_content = false, +}) + + +minetest.register_lbm({ + label = "[Hyperloop] Booking machine update", + name = "hyperloop:update", + nodenames = {"hyperloop:booking", "hyperloop:booking_ground"}, + run_at_every_load = true, + action = booking_machine_update +}) diff --git a/hyperloop/characters.data b/hyperloop/characters.data new file mode 100644 index 0000000..0bf29f5 --- /dev/null +++ b/hyperloop/characters.data @@ -0,0 +1,270 @@ +A +_a_ +7 +B +_b_ +5 +C +_c_ +6 +D +_d_ +6 +E +_e_ +5 +F +_f_ +5 +G +_g_ +6 +H +_h_ +6 +I +_i_ +1 +J +_j_ +4 +K +_k_ +5 +L +_l_ +4 +M +_m_ +7 +N +_n_ +6 +O +_o_ +6 +P +_p_ +5 +Q +_q_ +7 +R +_r_ +5 +S +_s_ +5 +T +_t_ +5 +U +_u_ +6 +V +_v_ +7 +W +_w_ +9 +X +_x_ +5 +Y +_y_ +7 +Z +_z_ +5 +a +_a +5 +b +_b +5 +c +_c +4 +d +_d +5 +e +_e +4 +f +_f +4 +g +_g +5 +h +_h +5 +i +_i +1 +j +_j +1 +k +_k +4 +l +_l +1 +m +_m +7 +n +_n +5 +o +_o +5 +p +_p +5 +q +_q +5 +r +_r +3 +s +_s +4 +t +_t +3 +u +_u +4 +v +_v +5 +w +_w +7 +x +_x +5 +y +_y +4 +z +_z +4 + +_sp +2 +0 +_0 +4 +1 +_1 +2 +2 +_2 +4 +3 +_3 +4 +4 +_4 +4 +5 +_5 +4 +6 +_6 +4 +7 +_7 +4 +8 +_8 +4 +9 +_9 +4 +( +_bl +2 +) +_br +2 +{ +_cl +3 +} +_cr +3 +[ +_sl +2 +] +_sr +2 +! +_ex +1 +? +_qu +4 +# +_hs +5 +$ +_dl +4 +% +_pr +5 +^ +_ca +3 +_ +_un +3 ++ +_ps +3 +- +_mn +3 += +_eq +3 +; +_sm +1 +: +_co +1 +, +_cm +2 +" +_qo +3 +/ +_dv +5 +~ +_tl +4 +< +_lt +3 +> +_gt +3 +\ +_re +5 +| +_vb +1 +. +_dt +1 diff --git a/hyperloop/data_base.lua b/hyperloop/data_base.lua new file mode 100644 index 0000000..0c7f1f4 --- /dev/null +++ b/hyperloop/data_base.lua @@ -0,0 +1,60 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + mod storage and data integrity +]]-- + +-- for lazy programmers +local S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +hyperloop.Stations = hyperloop.Network:new() +hyperloop.Elevators = hyperloop.Network:new() + + +-- Check all nodes on the map and delete useless data base entries +local function check_data_base() + -- used for VM get_node + local tube = tubelib2.Tube:new({}) + + hyperloop.Stations:filter(function(pos) + local _,node = tube:get_node(pos) + return node.name == "hyperloop:station" or node.name == "hyperloop:junction" + end) + + hyperloop.Elevators:filter(function(pos) + local _,node = tube:get_node(pos) + return node.name == "hyperloop:elevator_bottom" + end) +end + +local storage = minetest.get_mod_storage() +hyperloop.Stations:deserialize(storage:get_string("Stations")) +hyperloop.Elevators:deserialize(storage:get_string("Elevators")) + +local function update_mod_storage() + minetest.log("action", "[Hyperloop] Store data...") + storage:set_string("Stations", hyperloop.Stations:serialize()) + storage:set_string("Elevators", hyperloop.Elevators:serialize()) + -- store data each hour + minetest.after(60*60, update_mod_storage) + minetest.log("action", "[Hyperloop] Data stored") +end + +minetest.register_on_shutdown(function() + update_mod_storage() +end) + +-- delete data base entries without corresponding nodes +minetest.after(5, check_data_base) + +-- store data after one hour +minetest.after(60*60, update_mod_storage) diff --git a/hyperloop/deco.lua b/hyperloop/deco.lua new file mode 100644 index 0000000..28e7898 --- /dev/null +++ b/hyperloop/deco.lua @@ -0,0 +1,242 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + History: + see init.lua + +]]-- + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local tilesL = {"hyperloop_alpsL.png", "hyperloop_seaL.png", "hyperloop_agyptL.png"} +local tilesR = {"hyperloop_alpsR.png", "hyperloop_seaR.png", "hyperloop_agyptR.png"} + +-- determine facedir and pos on the right hand side from the given pos +function right_hand_side(pos, placer) + local facedir = hyperloop.get_facedir(placer) + pos = hyperloop.new_pos(pos, facedir, "1R", 0) + return facedir,pos +end + +for idx = 1,3 do + + minetest.register_node("hyperloop:poster"..idx.."L", { + description = S("Hyperloop Promo Poster ")..idx, + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + tilesL[idx], + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -6/16, 8/16, 8/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = { -8/16, -8/16, -6/16, 24/16, 8/16, 8/16}, + }, + + after_place_node = function(pos, placer) + local meta = minetest.get_meta(pos) + local facedir + facedir, pos = right_hand_side(pos, placer) + meta:set_string("pos", minetest.pos_to_string(pos)) + if minetest.get_node_or_nil(pos).name == "air" then + minetest.add_node(pos, {name="hyperloop:poster"..idx.."R", param2=facedir}) + end + end, + + on_destruct = function(pos) + local meta = minetest.get_meta(pos) + pos = minetest.string_to_pos(meta:get_string("pos")) + if pos ~= nil and minetest.get_node_or_nil(pos).name == "hyperloop:poster"..idx.."R" then + minetest.remove_node(pos) + end + end, + + + paramtype2 = "facedir", + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, + }) + + minetest.register_node("hyperloop:poster"..idx.."R", { + description = S("Hyperloop Promo Poster ")..idx, + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin2.png", + tilesR[idx], + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -6/16, 8/16, 8/16, 8/16}, + }, + }, + paramtype2 = "facedir", + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2, not_in_creative_inventory=1}, + }) +end + + +minetest.register_node("hyperloop:sign", { + description = S("Hyperloop Station Sign"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_sign_top.png", + "hyperloop_sign.png", + }, + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, +}) + +minetest.register_node("hyperloop:signR", { + description = S("Hyperloop Station Sign Right"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png", + "hyperloop_sign3.png", + "hyperloop_sign2.png^[transformFX", + "hyperloop_sign2.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -5/16, 6/16, 8/16, 5/16, 8/16}, + }, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + pos.y = pos.y - 1 + if minetest.get_node_or_nil(pos).name ~= "air" then + local node = minetest.get_node(pos) + node.name = "hyperloop:signR_ground" + node.param2 = hyperloop.get_facedir(placer) + pos.y = pos.y + 1 + minetest.swap_node(pos, node) + end + end, + + paramtype2 = "facedir", + paramtype = 'light', + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, +}) + +minetest.register_node("hyperloop:signL", { + description = S("Hyperloop Station Sign Left"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png", + "hyperloop_sign3.png", + "hyperloop_sign2.png", + "hyperloop_sign2.png^[transformFX", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -5/16, 6/16, 8/16, 5/16, 8/16}, + }, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + pos.y = pos.y - 1 + if minetest.get_node_or_nil(pos).name ~= "air" then + local node = minetest.get_node(pos) + node.name = "hyperloop:signL_ground" + node.param2 = hyperloop.get_facedir(placer) + pos.y = pos.y + 1 + minetest.swap_node(pos, node) + end + end, + + paramtype2 = "facedir", + paramtype = 'light', + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, +}) + +minetest.register_node("hyperloop:signR_ground", { + description = S("Hyperloop Station Sign Right"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png", + "hyperloop_sign3.png", + "hyperloop_sign2_ground.png^[transformFX", + "hyperloop_sign2_ground.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -1/16, 8/16, 2/16, 1/16}, + }, + }, + paramtype2 = "facedir", + drop = "hyperloop:signR", + paramtype = 'light', + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2, not_in_creative_inventory=1}, +}) + +minetest.register_node("hyperloop:signL_ground", { + description = S("Hyperloop Station Sign Left"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png^[transformR90]", + "hyperloop_sign3.png", + "hyperloop_sign3.png", + "hyperloop_sign2_ground.png", + "hyperloop_sign2_ground.png^[transformFX", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -1/16, 8/16, 2/16, 1/16}, + }, + }, + paramtype2 = "facedir", + drop = "hyperloop:signL", + paramtype = 'light', + light_source = 4, + is_ground_content = false, + groups = {cracky = 2, stone = 2, not_in_creative_inventory=1}, +}) diff --git a/hyperloop/depends.txt b/hyperloop/depends.txt new file mode 100644 index 0000000..da0d582 --- /dev/null +++ b/hyperloop/depends.txt @@ -0,0 +1,4 @@ +tubelib2 +default +worldedit? +techage? diff --git a/hyperloop/description.txt b/hyperloop/description.txt new file mode 100644 index 0000000..e50a363 --- /dev/null +++ b/hyperloop/description.txt @@ -0,0 +1 @@ +Hyperloop Mod, the fast and modern way of traveling. \ No newline at end of file diff --git a/hyperloop/door.lua b/hyperloop/door.lua new file mode 100644 index 0000000..c21600e --- /dev/null +++ b/hyperloop/door.lua @@ -0,0 +1,201 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +--- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +-- Open the door for an emergency +local function door_on_punch(pos, node, puncher, pointed_thing) + local station = hyperloop.get_base_station(pos) + if station then + if station.name == "Station" then + hyperloop.chat(puncher, S("The Booking Machine for this station is missing!")) + elseif not hyperloop.is_blocked(station.pos) then + hyperloop.open_pod_door(station) + end + end +end + +-- Open/close/animate the pod door +-- door_pos1: position of the bottom door +-- cmnd: "close", "open", or "animate" +local function door_command(door_pos1, facedir, cmnd) + -- one step up + local door_pos2 = vector.add(door_pos1, {x=0, y=1, z=0}) + + local node1 = minetest.get_node(door_pos1) + local node2 = minetest.get_node(door_pos2) + local meta = minetest.get_meta(door_pos1) + if cmnd == "open" then + minetest.sound_play("door", { + pos = door_pos1, + gain = 0.5, + max_hear_distance = 10, + }) + node1.name = "air" + minetest.swap_node(door_pos1, node1) + node2.name = "air" + minetest.swap_node(door_pos2, node2) + elseif cmnd == "close" then + minetest.sound_play("door", { + pos = door_pos1, + gain = 0.5, + max_hear_distance = 10, + }) + node1.name = "hyperloop:doorBottom" + node1.param2 = facedir + minetest.swap_node(door_pos1, node1) + node2.name = "hyperloop:doorTopPassive" + node2.param2 = facedir + minetest.swap_node(door_pos2, node2) + elseif cmnd == "animate" then + node2.name = "hyperloop:doorTopActive" + node2.param2 = facedir + minetest.swap_node(door_pos2, node2) + end +end + +-- door command based on the station data table +function hyperloop.open_pod_door(tStation) + if tStation ~= nil then + local door_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F1L", 1) + local door_facedir = (tStation.facedir + 1) % 4 + door_command(door_pos, door_facedir, "open") + end +end + +-- door command based on the station data table +function hyperloop.close_pod_door(tStation) + if tStation ~= nil then + local door_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F1L", 1) + local door_facedir = (tStation.facedir + 1) % 4 + door_command(door_pos, door_facedir, "close") + end +end + +-- door command based on the station data table +function hyperloop.animate_pod_door(tStation) + if tStation ~= nil then + local door_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F1L", 1) + local door_facedir = (tStation.facedir + 1) % 4 + door_command(door_pos, door_facedir, "animate") + end +end + +minetest.register_node("hyperloop:doorTopPassive", { + description = S("Hyperloop Door Top"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_door1OUT.png", + "hyperloop_door1OUT.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-8/16, -8/16, -5/16, 8/16, 8/16, 5/16}, + }, + + on_punch = door_on_punch, + + auto_place_node = function(pos, facedir, sStationPos) + M(pos):set_int("facedir", facedir) + M(pos):set_string("sStationPos", sStationPos) + end, + + on_rotate = screwdriver.disallow, + paramtype = 'light', + light_source = 1, + paramtype2 = "facedir", + drop = "", + sounds = default.node_sound_metal_defaults(), + groups = {cracky=1, not_in_creative_inventory=1}, + is_ground_content = false, +}) + +minetest.register_node("hyperloop:doorTopActive", { + description = S("Hyperloop Door Top"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + { + name = "hyperloop_door1IN.png", + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 1.0, + }, + }, + "hyperloop_door1OUT.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-8/16, -8/16, -5/16, 8/16, 8/16, 5/16}, + }, + + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + drop = "", + light_source = 2, + sounds = default.node_sound_metal_defaults(), + groups = {cracky=1, not_in_creative_inventory=1}, + is_ground_content = false, +}) + +minetest.register_node("hyperloop:doorBottom", { + description = S("Hyperloop Door Bottom"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_skin_door.png", + "hyperloop_door2IN.png", + "hyperloop_door2OUT.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-8/16, -8/16, -5/16, 8/16, 8/16, 5/16}, + }, + + on_punch = door_on_punch, + + auto_place_node = function(pos, facedir, sStationPos) + M(pos):set_int("facedir", facedir) + M(pos):set_string("sStationPos", sStationPos) + end, + + on_rotate = screwdriver.disallow, + paramtype = 'light', + light_source = 1, + paramtype2 = "facedir", + drop = "", + sounds = default.node_sound_metal_defaults(), + groups = {cracky=1, not_in_creative_inventory=1}, + is_ground_content = false, +}) + diff --git a/hyperloop/elevator.lua b/hyperloop/elevator.lua new file mode 100644 index 0000000..c07b551 --- /dev/null +++ b/hyperloop/elevator.lua @@ -0,0 +1,645 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +-- To store elevator floors and formspecs +local Cache = {} + +local kPLAYER_OVER_GROUND = 0.5 + +------------------------------------------------------------------------------- +-- Elevator Shaft +------------------------------------------------------------------------------- + +-- Down, Up +local dirs_to_check = {5,6} -- vertical only +if hyperloop.free_tube_placement_enabled then + dirs_to_check = {1,2,3,4,5,6} -- all directions +end + +local Shaft = tubelib2.Tube:new({ + dirs_to_check = dirs_to_check, + max_tube_length = 1000, + show_infotext = true, + primary_node_names = {"hyperloop:shaft", "hyperloop:shaft2", "hyperloop:shaftA", "hyperloop:shaftA2"}, + secondary_node_names = {"hyperloop:elevator_bottom", "hyperloop:elevator_top"}, + after_place_tube = function(pos, param2, tube_type, num_tubes) + if tube_type == "S" then + if num_tubes == 2 then + minetest.swap_node(pos, {name = "hyperloop:shaft2", param2 = param2}) + else + minetest.swap_node(pos, {name = "hyperloop:shaft", param2 = param2}) + end + else + if num_tubes == 2 then + minetest.swap_node(pos, {name = "hyperloop:shaftA2", param2 = param2}) + else + minetest.swap_node(pos, {name = "hyperloop:shaftA", param2 = param2}) + end + end + end, +}) + +hyperloop.Shaft = Shaft +local Elevators = hyperloop.Elevators + +Shaft:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) + if out_dir == 6 then -- to the top? + -- switch to elevator_bottom node + pos = Shaft:get_pos(pos, 5) + elseif peer_pos then + local _,node = Shaft:get_node(peer_pos) + if node.name == "hyperloop:elevator_top" then + peer_pos = Shaft:get_pos(peer_pos, 5) + end + end + Elevators:update_connections(pos, out_dir, peer_pos) +end) + + +minetest.register_node("hyperloop:shaft", { + description = S("Hyperloop Elevator Shaft"), + inventory_image = 'hyperloop_shaft_inv.png', + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_closed.png^[transformR90]", + "hyperloop_tube_closed.png^[transformR90]", + "hyperloop_tube_closed.png", + "hyperloop_tube_closed.png", + 'hyperloop_tube.png', + 'hyperloop_tube.png', + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if not Shaft:after_place_tube(pos, placer, pointed_thing) then + minetest.remove_node(pos) + return true + end + return false + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Shaft:after_dig_tube(pos, oldnode, oldmetadata) + end, + + climbable = true, + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky = 1}, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:shaftA", { + description = S("Hyperloop Elevator Shaft"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_closed.png^[transformR90]", + 'hyperloop_tube.png', + "hyperloop_tube_closed.png", + "hyperloop_tube_closed.png", + "hyperloop_tube_closed.png", + 'hyperloop_tube.png', + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, -7/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if not Shaft:after_place_tube(pos, placer, pointed_thing) then + minetest.remove_node(pos) + return true + end + return false + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Shaft:after_dig_tube(pos, oldnode, oldmetadata) + end, + + climbable = true, + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + drop = "hyperloop:shaft", + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:shaft2", { + description = S("Hyperloop Elevator Shaft"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR270]", + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR90]", + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR180]", + "hyperloop_tube_locked.png^hyperloop_elogo.png", + 'hyperloop_tube.png', + 'hyperloop_tube.png', + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Shaft:after_dig_tube(pos, oldnode, oldmetadata) + end, + + climbable = true, + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + diggable = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:shaftA2", { + description = S("Hyperloop Elevator Shaft"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR270]", + 'hyperloop_tube.png', + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR180]", + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR180]", + "hyperloop_tube_locked.png^hyperloop_elogo.png^[transformR90]", + 'hyperloop_tube.png', + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, -7/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Shaft:after_dig_tube(pos, oldnode, oldmetadata) + end, + + climbable = true, + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + diggable = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + sounds = default.node_sound_metal_defaults(), +}) + +------------------------------------------------------------------------------- +-- Elevator Car +------------------------------------------------------------------------------- + +-- Form spec for the floor list +local function formspec(pos, lFloors) + local tRes = {"size[5,10]label[0.5,0; "..S("Select your destination").."]"} + tRes[2] = "label[1,0.6;"..S("Destination").."]label[2.5,0.6;"..S("Floor").."]" + for idx,floor in ipairs(lFloors) do + if idx >= 12 then + break + end + local ypos = 0.5 + idx*0.8 + local ypos2 = ypos - 0.2 + tRes[#tRes+1] = "button_exit[1,"..ypos2..";1,1;button;"..(#lFloors-idx).."]" + if vector.equals(floor.pos, pos) then + tRes[#tRes+1] = "label[2.5,"..ypos..";"..S("(current position)").."]" + else + tRes[#tRes+1] = "label[2.5,"..ypos..";"..(floor.name or "").."]" + end + end + if #tRes == 2 then + tRes[#tRes+1] = "button_exit[1,3;3,1;button;Update]" + end + return table.concat(tRes) +end + +local function update_formspec(pos) + local meta = M(pos) + local counter = meta:get_int("change_counter") or 0 + local changed, newcounter = Elevators:changed(counter) + local sKey = SP(pos) + if changed or not Cache[sKey] then + local lFloors = Elevators:station_list(pos, pos, "level") + Cache[sKey] = {} + Cache[sKey].lFloors = lFloors + Cache[sKey].formspec = formspec(pos, lFloors) + meta:set_int("change_counter", newcounter) + end + M(pos):set_string("formspec", Cache[sKey].formspec) +end + + +-- Open/close/darken the elevator door +-- floor_pos: position of elevator floor +-- cmnd: "close", "open", or "darken" +local function door_command(floor_pos, facedir, cmnd, sound) + -- one step up + local door_pos1 = hyperloop.new_pos(floor_pos, facedir, "1B", 0) + local door_pos2 = hyperloop.new_pos(floor_pos, facedir, "1B", 1) + local node1 = minetest.get_node(door_pos1) + local node2 = minetest.get_node(door_pos2) + + if sound then + minetest.sound_play("ele_door", { + pos = floor_pos, + gain = 0.8, + max_hear_distance = 10, + }) + end + if cmnd == "open" then + node1.name = "air" + minetest.swap_node(door_pos1, node1) + node2.name = "air" + minetest.swap_node(door_pos2, node2) + elseif cmnd == "close" then + M(door_pos1):set_string("floor_pos", SP(floor_pos)) + M(door_pos2):set_string("floor_pos", SP(floor_pos)) + node1.name = "hyperloop:elevator_door" + node1.param2 = facedir + minetest.swap_node(door_pos1, node1) + node2.name = "hyperloop:elevator_door_top" + node2.param2 = facedir + minetest.swap_node(door_pos2, node2) + elseif cmnd == "darken" then + node1.name = "hyperloop:elevator_door_dark" + node1.param2 = facedir + minetest.swap_node(door_pos1, node1) + node2.name = "hyperloop:elevator_door_dark_top" + node2.param2 = facedir + minetest.swap_node(door_pos2, node2) + end +end + +local function on_final_close_door(tArrival) + -- close the door and play sound if no player is around + if hyperloop.is_player_around(tArrival.pos) then + -- try again later + minetest.after(3.0, on_final_close_door, tArrival) + else + door_command(tArrival.pos, tArrival.facedir, "close", true) + end +end + +local function on_open_door(tArrival) + door_command(tArrival.pos, tArrival.facedir, "open", true) + minetest.after(5.0, on_final_close_door, tArrival) + tArrival.busy = false +end + +local function on_arrival_floor(tDeparture, tArrival, player_name, snd) + local player = minetest.get_player_by_name(player_name) + door_command(tDeparture.pos, tDeparture.facedir, "close", false) + door_command(tArrival.pos, tArrival.facedir, "close", false) + tDeparture.busy = false + if player ~= nil then + tArrival.pos.y = tArrival.pos.y - kPLAYER_OVER_GROUND + player:set_pos(tArrival.pos) + tArrival.pos.y = tArrival.pos.y + kPLAYER_OVER_GROUND + end + minetest.sound_stop(snd) + minetest.after(1.0, on_open_door, tArrival) +end + +local function on_travel(tDeparture, tArrival, player_name, seconds) + door_command(tDeparture.pos, tDeparture.facedir, "darken", false) + door_command(tArrival.pos, tArrival.facedir, "darken", false) + local snd = minetest.sound_play("ele_norm", { + pos = tDeparture.pos, + gain = 0.5, + max_hear_distance = 3, + loop = true, + }) + minetest.after(seconds, on_arrival_floor, tDeparture, tArrival, player_name, snd) +end + +minetest.register_node("hyperloop:elevator_bottom", { + description = S("Hyperloop Elevator"), + tiles = { + "hyperloop_elevator_bottom.png", + "hyperloop_elevator_bottom.png", + "hyperloop_elevator.png", + "hyperloop_elevator.png", + "hyperloop_elevator.png", + "hyperloop_elevator.png", + }, + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + { -7/16, -8/16, 7/16, 7/16, 8/16, 8/16}, + { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = { -8/16, -8/16, -8/16, 8/16, 23/16, 8/16 }, + }, + inventory_image = "hyperloop_elevator_inventory.png", + on_rotate = screwdriver.disallow, + drawtype = "nodebox", + paramtype = 'light', + light_source = 6, + paramtype2 = "facedir", + is_ground_content = false, + groups = {snappy = 3}, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + local _,node = Shaft:get_node(pos, 6) + if node.name == "air" then + local facedir = hyperloop.get_facedir(placer) + Elevators:set(pos, "", {facedir=facedir, busy=false}) + + Shaft:after_place_node(pos, {5}) + + -- formspec + local meta = minetest.get_meta(pos) + local formspec = "size[6,4]".. + "label[0,0;"..S("Please insert floor name").."]" .. + "field[0.5,1.5;5,1;floor;"..S("Floor name")..";"..S("Base").."]" .. + "button_exit[2,3;2,1;exit;"..S("Save").."]" + meta:set_string("formspec", formspec) + + -- add upper part of the car + pos = Shaft:get_pos(pos, 6) + minetest.add_node(pos, {name="hyperloop:elevator_top", param2=facedir}) + Shaft:after_place_node(pos, {6}) + else + minetest.remove_node(pos) + return true + end + end, + + on_receive_fields = function(pos, formname, fields, player) + -- floor name entered? + if fields.floor ~= nil then + local floor = string.trim(fields.floor) + if floor == "" then + return + end + Elevators:update(pos, {name=floor}) + update_formspec(pos) + elseif fields.button ~= nil then -- destination selected? + update_formspec(pos) + local floor = Elevators:get(pos) + if floor then + floor = table.copy(floor) + floor.pos = pos + local sKey = SP(pos) + local idx = tonumber(fields.button) + if idx then + local lFloors = Cache[sKey].lFloors + local dest = lFloors[#lFloors-idx] + if dest and dest.pos and floor.pos then + local dist = hyperloop.distance(dest.pos, floor.pos) + if dist ~= 0 and floor.busy ~= true then + if player ~= nil then + pos.y = pos.y - kPLAYER_OVER_GROUND + player:set_pos(pos) + pos.y = pos.y + kPLAYER_OVER_GROUND + end + -- due to the missing display, a trip needs 20 sec maximum + local seconds = math.min(1 + math.floor(dist/30), 20) + floor.busy = true + door_command(floor.pos, floor.facedir, "close", true) + door_command(dest.pos, dest.facedir, "close", true) + minetest.after(1.0, on_travel, floor, dest, player:get_player_name(), seconds) + end + end + end + end + end + end, + + on_punch = function(pos, node, puncher, pointed_thing) + update_formspec(pos) + local floor = Elevators:get(pos) + if floor and floor.busy ~= true then + door_command(pos, floor.facedir, "open", true) + end + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Shaft:after_dig_node(pos, {5}) + Elevators:delete(pos) + -- remove the bottom also + pos = Shaft:get_pos(pos, 6) + minetest.remove_node(pos) + Shaft:after_dig_node(pos, {6}) + end, +}) + +minetest.register_node("hyperloop:elevator_top", { + description = S("Hyperloop Elevator"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_elevator_bottom.png", + "hyperloop_elevator_bottom.png", + "hyperloop_elevator_top.png", + "hyperloop_elevator.png", + "hyperloop_elevator.png", + "hyperloop_elevator.png", + }, + node_box = { + type = "fixed", + fixed = { + { -8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + { -8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + { -7/16, -8/16, 7/16, 7/16, 8/16, 8/16}, + }, + }, + + on_rotate = screwdriver.disallow, + drawtype = "nodebox", + paramtype = 'light', + light_source = 6, + paramtype2 = "facedir", + is_ground_content = false, + diggable = false, + groups = {not_in_creative_inventory=1}, + drop = "", +}) + +minetest.register_node("hyperloop:elevator_door_top", { + description = "Hyperloop Elevator Door", + tiles = { + -- up, down, right, left, back, front + "hyperloop_elevator_door_top.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + }, + }, + + on_rotate = screwdriver.disallow, + drop = "", + paramtype = 'light', + paramtype2 = "facedir", + is_ground_content = false, + groups = {snappy = 3, not_in_creative_inventory=1}, +}) + +minetest.register_node("hyperloop:elevator_door", { + description = "Hyperloop Elevator Door", + tiles = { + -- up, down, right, left, back, front + "hyperloop_elevator_door.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + }, + }, + + selection_box = { + type = "fixed", + fixed = { -8/16, -8/16, 6.5/16, 8/16, 24/16, 8/16 }, + }, + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local floor_pos = P(M(pos):get_string("floor_pos")) + if floor_pos ~= nil then + update_formspec(floor_pos) + local floor = Elevators:get(floor_pos) + if floor and floor.busy ~= true then + door_command(floor_pos, floor.facedir, "open", true) + end + end + end, + + on_rotate = screwdriver.disallow, + drop = "", + paramtype = 'light', + paramtype2 = "facedir", + is_ground_content = false, + groups = {snappy = 3, not_in_creative_inventory=1}, +}) + +minetest.register_node("hyperloop:elevator_door_dark_top", { + description = "Hyperloop Elevator Door", + tiles = { + -- up, down, right, left, back, front + "hyperloop_elevator_dark_top.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + }, + }, + + on_rotate = screwdriver.disallow, + drop = "", + paramtype = 'light', + paramtype2 = "facedir", + is_ground_content = false, + groups = {snappy = 3, not_in_creative_inventory=1}, +}) + +minetest.register_node("hyperloop:elevator_door_dark", { + description = "Hyperloop Elevator Door", + tiles = { + -- up, down, right, left, back, front + "hyperloop_elevator_dark.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + }, + }, + + selection_box = { + type = "fixed", + fixed = { -8/16, -8/16, 7/16, 8/16, 24/16, 8/16 }, + }, + + on_rotate = screwdriver.disallow, + drop = "", + paramtype = 'light', + paramtype2 = "facedir", + is_ground_content = false, + groups = {snappy = 3, not_in_creative_inventory=1}, +}) diff --git a/hyperloop/init.lua b/hyperloop/init.lua new file mode 100644 index 0000000..5549a38 --- /dev/null +++ b/hyperloop/init.lua @@ -0,0 +1,92 @@ +--[[ + + Hyperloop Mod + ============= + + v2.04 by JoSt + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + History: + 2017-06-18 v0.01 First version + 2017-07-06 v0.02 Version on GitHub + 2017-07-07 v0.03 Recipes added, settingstypes added + 2017-07-08 v0.04 Door removal issue fixed + 2017-07-16 v0.05 Doors can be opened manually + 2017-07-24 v0.06 Tubes with limited slope, elevator and deco blocks added + 2017-07-28 v0.07 Slope removed, Station auto-builder added + 2017-07-30 v0.08 Signs added, tube robot added, crowbar added + 2017-07-31 v0.09 Some bug fixes on the Bocking Machine + 2017-08-01 v0.10 Elevator now with sound and travel animation plus minor bug fixes + 2017-08-06 v0.11 Crowbar now allows repairing of illegally detroyed tubes + 2018-03-27 v0.12 Some minor improvements with player position, arrival time, + Wifi node improvements, Podshell cheating bugfix, + forceload_block removed. + 2018-04-13 v0.13 Potential "Never Store ObjectRefs" bug fixed + 2018-10-27 v1.00 Release + 2018-10-27 v2.00 Switched to lubelib2 for shafts and tubes + 2018-12-16 v2.01 Adapted to lubelib2 v0.5 + 2018-12-20 v2.02 Intllib support added, bugs fixed + 2019-03-23 v2.03 Elevator duplication bugfix + 2020-01-03 v2.04 Elevator door bugfix (MT 5+) + 2020-03-12 v2.05 minetest translator added (thanks to acmgit/Clyde) + +]]-- + +hyperloop = {} + +-- Version for compatibility checks, see history +hyperloop.version = 2.05 + +if minetest.global_exists("techage") and techage.version < 0.06 then + minetest.log("error", "[hyperloop] Hyperloop requires techage version 0.06 or newer!") + return +end + + +if minetest.get_translator ~= nil then + hyperloop.S = minetest.get_translator(minetest.get_current_modname()) + +else + -- Load support for intllib. + local MP = minetest.get_modpath("hyperloop") + hyperloop.S, hyperloop.NS = dofile(MP.."/intllib.lua") + +end + +if tubelib2.version < 1.7 then + minetest.log("error", "Hyperloop requires tubelib2 version 1.7 or newer!!!") +else + -- Configuration settings + hyperloop.wifi_enabled = minetest.settings:get_bool("hyperloop_wifi_enabled") + hyperloop.wifi_crafting_enabled = minetest.settings:get_bool("hyperloop_wifi_crafting_enabled") + hyperloop.free_tube_placement_enabled = minetest.settings:get_bool("hyperloop_free_tube_placement_enabled") + + dofile(minetest.get_modpath("hyperloop") .. "/network.lua") + dofile(minetest.get_modpath("hyperloop") .. "/data_base.lua") + dofile(minetest.get_modpath("hyperloop") .. "/booking.lua") + dofile(minetest.get_modpath("hyperloop") .. "/utils.lua") + dofile(minetest.get_modpath("hyperloop") .. "/elevator.lua") + dofile(minetest.get_modpath("hyperloop") .. "/tube.lua") + dofile(minetest.get_modpath("hyperloop") .. "/tubecrowbar.lua") + dofile(minetest.get_modpath("hyperloop") .. "/junction.lua") + dofile(minetest.get_modpath("hyperloop") .. "/station.lua") + dofile(minetest.get_modpath("hyperloop") .. "/booking_node.lua") + if hyperloop.wifi_enabled then + dofile(minetest.get_modpath("hyperloop") .. "/wifi.lua") + end + dofile(minetest.get_modpath("hyperloop") .. "/map.lua") + dofile(minetest.get_modpath("hyperloop") .. "/door.lua") + dofile(minetest.get_modpath("hyperloop") .. "/seat.lua") + dofile(minetest.get_modpath("hyperloop") .. "/lcd.lua") + dofile(minetest.get_modpath("hyperloop") .. "/waypoint.lua") + dofile(minetest.get_modpath("hyperloop") .. "/deco.lua") + dofile(minetest.get_modpath("hyperloop") .. "/recipes.lua") + ---- Migration from v1 to v2 + dofile(minetest.get_modpath("hyperloop") .. "/migrate.lua") + + print ("[MOD] Hyperloop loaded") +end diff --git a/hyperloop/intllib.lua b/hyperloop/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/hyperloop/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/hyperloop/intllib.sh b/hyperloop/intllib.sh new file mode 100755 index 0000000..b831fc2 --- /dev/null +++ b/hyperloop/intllib.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +../intllib/tools/xgettext.sh ./booking.lua ./door.lua ./lcd.lua ./tube.lua ./booking_node.lua ./elevator.lua ./map.lua ./seat.lua ./utils.lua ./data_base.lua ./init.lua ./waypoint.lua ./network.lua ./station.lua ./wifi.lua ./deco.lua ./junction.lua ./recipes.lua ./tubecrowbar.lua ./recipes.lua diff --git a/hyperloop/junction.lua b/hyperloop/junction.lua new file mode 100644 index 0000000..47be4b6 --- /dev/null +++ b/hyperloop/junction.lua @@ -0,0 +1,87 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Tube = hyperloop.Tube +local Stations = hyperloop.Stations + + +Tube:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) + if node.name == "hyperloop:station" then + if out_dir <= 5 then + Stations:update_connections(pos, out_dir, peer_pos) + local s = hyperloop.get_connection_string(pos) + M(pos):set_string("infotext", S("Station connected with ")..s) + end + elseif node.name == "hyperloop:junction" then + Stations:update_connections(pos, out_dir, peer_pos) + local s = hyperloop.get_connection_string(pos) + M(pos):set_string("infotext", S("Junction connected with ")..s) + end +end) + +minetest.register_node("hyperloop:junction", { + description = S("Hyperloop Junction Block"), + tiles = { + "hyperloop_junction_top.png", + "hyperloop_junction_top.png", + "hyperloop_station_connection.png", + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + hyperloop.check_network_level(pos, placer) + M(pos):set_string("infotext", S("Junction")) + Stations:set(pos, "Junction", { + owner = placer:get_player_name(), junction = true}) + Tube:after_place_node(pos) + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_node(pos) + Stations:delete(pos) + end, + + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + sunlight_propagates = true, + groups = {cracky = 1}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), +}) + +-- for tube viaducts +minetest.register_node("hyperloop:pillar", { + description = S("Hyperloop Pillar"), + tiles = {"hyperloop_tube_locked.png^[transformR90]"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -3/8, -4/8, -3/8, 3/8, 4/8, 3/8}, + }, + }, + on_rotate = screwdriver.disallow, + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, + sounds = default.node_sound_metal_defaults(), +}) diff --git a/hyperloop/lcd.lua b/hyperloop/lcd.lua new file mode 100644 index 0000000..b0a8101 --- /dev/null +++ b/hyperloop/lcd.lua @@ -0,0 +1,203 @@ +--[[ + + LCD + === + + Derived from the work of kaeza, sofar and others (digilines) + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + + +-- load characters map +local chars_file = io.open(minetest.get_modpath("hyperloop").."/characters.data", "r") +local charmap = {} +local max_chars = 16 +if not chars_file then + print("[Hyperloop] E: LCD: character map file not found") +else + while true do + local char = chars_file:read("*l") + if char == nil then + break + end + local img = chars_file:read("*l") + chars_file:read("*l") + charmap[char] = img + end +end + +-- CONSTANTS +local LCD_WITH = 112 + +local LINE_LENGTH = 17 +local NUMBER_OF_LINES = 6 + +local LINE_HEIGHT = 14 +local CHAR_WIDTH = 5 + +local create_lines = function(text) + local line = "" + local line_num = 1 + local tab = {} + for word in string.gmatch(text, "%S+") do + if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then + if line ~= "" then + line = line.." "..word + else + line = word + end + else + table.insert(tab, line) + if word ~= "|" then + line = word + else + line = "" + end + line_num = line_num+1 + if line_num > NUMBER_OF_LINES then + return tab + end + end + end + table.insert(tab, line) + return tab +end + +local generate_line = function(s, ypos) + local i = 1 + local parsed = {} + local width = 0 + local chars = 0 + while chars < max_chars and i <= #s do + local file = nil + if charmap[s:sub(i, i)] ~= nil then + file = charmap[s:sub(i, i)] + i = i + 1 + elseif i < #s and charmap[s:sub(i, i + 1)] ~= nil then + file = charmap[s:sub(i, i + 1)] + i = i + 2 + else + i = i + 1 + end + if file ~= nil then + width = width + CHAR_WIDTH + table.insert(parsed, file) + chars = chars + 1 + end + end + width = width - 1 + + local texture = "" + local xpos = math.floor((LCD_WITH - width) / 2) - CHAR_WIDTH + --xpos = 5 + for ii = 1, #parsed do + texture = texture..":"..xpos..","..ypos.."="..parsed[ii]..".png" + xpos = xpos + CHAR_WIDTH + 1 + end + return texture +end + +local generate_texture = function(lines) + local texture = "[combine:"..LCD_WITH.."x"..LCD_WITH + local ypos = 8 + for i = 1, #lines do + texture = texture..generate_line(lines[i], ypos) + ypos = ypos + LINE_HEIGHT + end + return texture +end + +local lcds = { + [2] = {delta = {x = 0.437, y = 0, z = 0}, yaw = math.pi / -2}, + [3] = {delta = {x = -0.437, y = 0, z = 0}, yaw = math.pi / 2}, + [4] = {delta = {x = 0, y = 0, z = 0.437}, yaw = 0}, + [5] = {delta = {x = 0, y = 0, z = -0.437}, yaw = math.pi}, +} + +local clearscreen = function(pos) + local objects = minetest.get_objects_inside_radius(pos, 0.5) + for _, o in ipairs(objects) do + local o_entity = o:get_luaentity() + if o_entity and o_entity.name == "hyperloop_lcd:text" then + o:remove() + end + end +end + +local prepare_writing = function(pos) + local lcd_info = lcds[minetest.get_node(pos).param2] + if lcd_info == nil then return end + local text = minetest.add_entity( + {x = pos.x + lcd_info.delta.x, + y = pos.y + lcd_info.delta.y, + z = pos.z + lcd_info.delta.z}, "hyperloop_lcd:text") + text:setyaw(lcd_info.yaw or 0) + --* text:setpitch(lcd_info.yaw or 0) + return text +end + +local lcd_update = function(pos, text) + local meta = minetest.get_meta(pos) + meta:set_string("text", text) + clearscreen(pos) + prepare_writing(pos) +end + +local lcd_box = { + type = "wallmounted", + wall_top = {-8/16, 15/32, -8/16, 8/16, 8/16, 8/16} +} + + +minetest.register_node("hyperloop:lcd", { + drawtype = "nodebox", + description = S("Hyperloop Display"), + tiles = {"hyperloop_lcd.png"}, + + on_rotate = screwdriver.disallow, + paramtype = "light", + sunlight_propagates = true, + paramtype2 = "wallmounted", + node_box = lcd_box, + selection_box = lcd_box, + drop = "", + groups = {cracky=1, not_in_creative_inventory=1}, + + auto_place_node = function(pos, placer, facedir) + local param2 = minetest.get_node(pos).param2 + if param2 == 0 or param2 == 1 then + minetest.add_node(pos, {name = "hyperloop:lcd", param2 = 3}) + end + lcd_update(pos, " | | << Hyperloop >> | be anywhere") + end, + + on_destruct = function(pos) + clearscreen(pos) + end, + + update = function(pos, text) + lcd_update(pos, text) + end, + + light_source = 6, +}) + +minetest.register_entity(":hyperloop_lcd:text", { + collisionbox = { 0, 0, 0, 0, 0, 0 }, + visual = "upright_sprite", + textures = {}, + + on_activate = function(self) + local meta = minetest.get_meta(self.object:get_pos()) + local text = meta:get_string("text") + self.object:set_properties({textures={generate_texture(create_lines(text))}}) + end +}) + diff --git a/hyperloop/locale/de.mo b/hyperloop/locale/de.mo new file mode 100644 index 0000000..b3e4892 Binary files /dev/null and b/hyperloop/locale/de.mo differ diff --git a/hyperloop/locale/de.po b/hyperloop/locale/de.po new file mode 100644 index 0000000..24228a2 --- /dev/null +++ b/hyperloop/locale/de.po @@ -0,0 +1,314 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-12-22 11:22+0100\n" +"PO-Revision-Date: 2018-12-22 11:23+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.0.6\n" + +#: booking.lua +msgid "Station data is corrupted. Please rebuild the station!" +msgstr "Stationsdaten sind beschädigt. Bitte die Station neu bauen!" + +#: booking.lua +msgid "Station is still blocked. Please try again in a few seconds!" +msgstr "" +"Die Station ist noch blockiert. Bitte versuche es in ein paar Sekunden " +"wieder!" + +#: door.lua +msgid "The Booking Machine for this station is missing!" +msgstr "Der Fahrkartenautomat für die Station fehlt!" + +#: lcd.lua +msgid "Hyperloop Display" +msgstr "Hyperloop Bildschirm" + +#: lcd.lua seat.lua +msgid " | | << Hyperloop >> | be anywhere" +msgstr " | | << Hyperloop >> | be anywhere" + +#: tube.lua +msgid "Junction at " +msgstr "Anschlussstelle bei " + +#: tube.lua +msgid "There is no station/junction on this level. " +msgstr "Es gibt keine Station/Anschlussstelle auf dieser Höhe. " + +#: tube.lua +msgid "Do you really want to start a new network?!" +msgstr "Willst du wirklich ein neues Liniennetz beginnen?!" + +#: tube.lua +msgid "Hyperloop Tube" +msgstr "Hyperloop Röhre" + +#: booking_node.lua elevator.lua +msgid "Select your destination" +msgstr "Wähle dein Ziel" + +#: booking_node.lua elevator.lua +msgid "Destination" +msgstr "Ziel" + +#: booking_node.lua +msgid "Distance" +msgstr "Entfernung" + +#: booking_node.lua +msgid "Local Info" +msgstr "Zusatzinfo" + +#: booking_node.lua +msgid "" +"Please enter the station name to\n" +"which this booking machine belongs." +msgstr "" +"Bitte gib den Stationsnamen ein\n" +"zu dem dieser Fahrkartenautomat gehört." + +#: booking_node.lua +msgid "Station name" +msgstr "Stationsname" + +#: booking_node.lua +msgid "Additional station information" +msgstr "Zusätzliche Stationsinformationen" + +#: booking_node.lua +msgid "Station has already a booking machine!" +msgstr "Station hat bereits einen Fahrkartenautomat!" + +#: booking_node.lua +msgid "Invalid station name!" +msgstr "Ungültiger Stationsname!" + +#: booking_node.lua +msgid "Hyperloop Booking Machine" +msgstr "Hyperloop Fahrkartenautomat" + +#: elevator.lua +msgid "Hyperloop Elevator Shaft" +msgstr "Hyperloop Aufzugsschacht" + +#: elevator.lua +msgid "Floor" +msgstr "Stockwerk" + +#: elevator.lua +msgid "(current position)" +msgstr "(aktuelle Position)" + +#: elevator.lua +msgid "Hyperloop Elevator" +msgstr "Hyperloop Aufzug" + +#: elevator.lua +msgid "Please insert floor name" +msgstr "Gib den Stockwerknamen ein" + +#: elevator.lua +msgid "Floor name" +msgstr "Stockwerkname" + +#: elevator.lua +msgid "Base" +msgstr "Basis" + +#: elevator.lua wifi.lua +msgid "Save" +msgstr "Speichern" + +#: map.lua +msgid "Dist." +msgstr "Entf." + +#: map.lua +msgid "Station/Junction" +msgstr "Station/Anschlussstelle" + +#: map.lua +msgid "Position" +msgstr "Position" + +#: map.lua +msgid "Owner" +msgstr "Besitzer" + +#: map.lua +msgid "Conn. with" +msgstr "Verb. mit" + +#: map.lua +msgid "Close" +msgstr "Schließen" + +#: map.lua +msgid "Hyperloop Station Book" +msgstr "Hyperloop Stationsbuch" + +#: seat.lua +msgid "Thank you | for | travelling | with | Hyperloop." +msgstr "Thank you | for | travelling | with | Hyperloop." + +#: seat.lua +msgid " | Welcome at | | " +msgstr " | Willkommen | in | | " + +#: seat.lua +msgid "[Hyperloop] No booking entered!" +msgstr "[Hyperloop] Keine Buchung eingegeben!" + +#: seat.lua +msgid "Destination:" +msgstr "Ziel:" + +#: seat.lua +msgid "Distance:" +msgstr "Entfernung:" + +#: seat.lua +msgid "Arrival in:" +msgstr "Ankunft in:" + +#: seat.lua +msgid "Hyperloop Pod Seat" +msgstr "Hyperloop Sitz" + +#: waypoint.lua +msgid "Hyperloop Waypoint" +msgstr "Hyperloop Wegpunkt" + +#: station.lua +msgid "Station completed. Now place the Booking Machine!" +msgstr "Station fertig. Setze nun den Fahrkartenautomat!" + +#: station.lua +msgid "Area is protected!" +msgstr "Die Area ist geschützt!" + +#: station.lua +msgid "Not enough space to build the station!" +msgstr "Nicht ausreichend Platz um die Station zu errichten!" + +#: station.lua +msgid "Hyperloop Station Pod Builder" +msgstr "Hyperloop Stations Ersteller" + +#: station.lua +msgid "Hyperloop Pod Shell" +msgstr "Hyperloop Kabinenwand" + +#: station.lua recipes.lua +msgid "Hypersteel Ingot" +msgstr "Hypersteel Barren" + +#: station.lua +msgid "Blue Wool" +msgstr "Blaue Wolle" + +#: station.lua +msgid "Glass" +msgstr "Glas" + +#: station.lua +msgid "Not enough inventory items to build the station!" +msgstr "Nicht ausreichend Inventory Items um die Station zu bauen!" + +#: station.lua +msgid "Destroy Station" +msgstr "Zerstöre Station" + +#: station.lua +msgid "Build Station" +msgstr "Baue Station" + +#: station.lua +msgid "Hyperloop Station Block" +msgstr "Hyperloop Stations Block" + +#: station.lua +msgid "Station" +msgstr "Station" + +#: wifi.lua +msgid "Enter channel string" +msgstr "Kanalname eingeben" + +#: wifi.lua +msgid "Hyperloop WiFi Tube" +msgstr "Hyperloop Wifi Röhre" + +#: deco.lua +msgid "Hyperloop Promo Poster " +msgstr "Hyperloop Werbeposter " + +#: deco.lua +msgid "Hyperloop Station Sign" +msgstr "Hyperloop Stationszeichen" + +#: deco.lua +msgid "Hyperloop Station Sign Right" +msgstr "Hyperloop Stationszeichen rechts" + +#: deco.lua +msgid "Hyperloop Station Sign Left" +msgstr "Hyperloop Stationszeichen links" + +#: junction.lua +msgid "Station connected with " +msgstr "Station verbunden mit " + +#: junction.lua +msgid "Junction connected with " +msgstr "Anschlussstelle verbunden mit " + +#: junction.lua +msgid "Hyperloop Junction Block" +msgstr "Hyperloop Anschlussstelle" + +#: junction.lua +msgid "Junction" +msgstr "Anschlussstelle" + +#: junction.lua +msgid "Hyperloop Pillar" +msgstr "Hyperloop Stütze" + +#: tubecrowbar.lua +msgid "[Crowbar Help]\n" +msgstr "[Brecheisen Hilfe]\n" + +#: tubecrowbar.lua +msgid " left: remove node\n" +msgstr " links: entferne Block\n" + +#: tubecrowbar.lua +msgid " right: repair tube/shaft line\n" +msgstr " rechts: repariere Röhre/Schacht\n" + +#: tubecrowbar.lua +msgid "You don't have the necessary privs!" +msgstr "Du hast nicht die notwendigen Rechte!" + +#: tubecrowbar.lua +msgid "Hyperloop Tube Crowbar" +msgstr "Hyperloop Brecheisen" + +#~ msgid "Tube connection missing!" +#~ msgstr "Anschluss an eine Röhre fehlt!" + +#~ msgid "Hypersteel Pod Shell" +#~ msgstr "Hyperloop Kabinenwand" diff --git a/hyperloop/locale/hyperloop.de.tr b/hyperloop/locale/hyperloop.de.tr new file mode 100644 index 0000000..77eccaa --- /dev/null +++ b/hyperloop/locale/hyperloop.de.tr @@ -0,0 +1,111 @@ +# textdomain: hyperloop + + +### booking.lua ### +Station data is corrupted. Please rebuild the station!=Stationsdaten sind beschädigt. Bitte die Station neu bauen! +Station is still blocked. Please try again in a few seconds!=Die Station ist noch blockiert. Bitte versuche es in ein paar Sekunden wieder! + +### booking_node.lua ### +Additional station information=Zusätzliche Stationsinformationen +Hyperloop Booking Machine=Hyperloop Fahrkartenautomat +Invalid station name!=Ungültiger Stationsname! +Please enter the station name to@nwhich this booking machine belongs.=Bitte gib den Stationsnamen ein@nzu dem dieser Fahrkartenautomat gehört. +Station has already a booking machine!=Station hat bereits einen Fahrkartenautomat! +Station name=Stationsname + +### elevator.lua ### +Select your destination=Wähle dein Ziel + +### migrate.lua ### += + +### deco.lua ### +Hyperloop Promo Poster =Hyperloop Werbeposter +Hyperloop Station Sign=Hyperloop Stationszeichen +Hyperloop Station Sign Left=Hyperloop Stationszeichen links +Hyperloop Station Sign Right=Hyperloop Stationszeichen rechts + +### door.lua ### +Hyperloop Door Bottom=Hyperloop Tür Unterteil +Hyperloop Door Top=Hyperloop Tür Oberteil +The Booking Machine for this station is missing!=Der Fahrkartenautomat für die Station fehlt! + +### elevator.lua ### +(current position)=(aktuelle Position) +Base=Basis +Destination=Ziel +Floor=Stockwerk +Floor name=Stockwerkname +Hyperloop Elevator=Hyperloop Aufzug +Hyperloop Elevator Shaft=Hyperloop Aufzugsschacht +Please insert floor name=Gib den Stockwerknamen ein + +### wifi.lua ### +Save=Speichern + +### junction.lua ### +Hyperloop Junction Block=Hyperloop Anschlussstelle +Hyperloop Pillar=Hyperloop Stütze +Junction connected with =Anschlussstelle verbunden mit +Station connected with =Station verbunden mit + +### migrate.lua ### +Junction=Anschlussstelle +Hyperloop Legacy Tube=Hyperloop veraltetes Rohr +unknown=unbekant + +### lcd.lua ### +Hyperloop Display=Hyperloop Bildschirm + +### map.lua ### +Close=Schließen +Conn. with=Verb. mit +Dist.=Entf. +Hyperloop Station Book=Hyperloop Stationsbuch +Owner=Besitzer +Position=Position +Station/Junction=Station/Anschlussstelle + +### seat.lua ### +Hyperloop Pod Seat=Hyperloop Sitz +[Hyperloop] No booking entered!=[Hyperloop] Keine Buchung eingegeben! + +### station.lua ### +Hypersteel Ingot=Hyperstahl Barren +Area is protected!=Die Area ist geschützt! +Blue Wool=Blaue Wolle +Build Station=Baue Station +Destroy Station=Zerstöre Station +Glass=Glas +Hyperloop Pod Shell=Hyperloop Kabinenwand +Hyperloop Station Block=Hyperloop Stations Block +Hyperloop Station Pod Builder=Hyperloop Stations Ersteller +Not enough inventory items to build the station!=Nicht ausreichend Inventory Items um die Station zu bauen! +Not enough space to build the station!=Nicht ausreichend Platz um die Station zu errichten! +Station=Station +Station completed. Now place the Booking Machine!=Station fertig. Setze nun den Fahrkartenautomat! + +### tube.lua ### +Do you really want to start a new network?!=Willst du wirklich ein neues Liniennetz beginnen?! +Hyperloop Tube=Hyperloop Röhre +Junction at =Anschlussstelle bei +Open end at =Offenes Ende bei +Station '=Station ' +Station at =Station bei +There is no station/junction on this level. =Es gibt keine Station/Anschlussstelle auf dieser Höhe. + +### tubecrowbar.lua ### + left: remove node@n= links: entferne Block@n + right: repair tube/shaft line@n= rechts: repariere Röhre/Schacht@n +Hyperloop Tube Crowbar=Hyperloop Brecheisen +Repair via WorldEdit placed Hyperloop tubes by reusing WorldEdit pos1/pos2=Reparatur über WorldEdit platzierte Hyperloop-Röhren durch Wiederverwendung von WorldEdit pos1/pos2 +Rights to remove tube nodes by means of the crowbar=Rechte zur Entfernung von Rohrknoten mit Hilfe der Brechstange +You don't have the necessary privs!=Du hast nicht die notwendigen Rechte! +[Crowbar Help]@n=[Brecheisen Hilfe]@n + +### waypoint.lua ### +Hyperloop Waypoint=Hyperloop Wegpunkt + +### wifi.lua ### +Enter channel string=Kanalname eingeben +Hyperloop WiFi Tube=Hyperloop Wifi Röhre diff --git a/hyperloop/locale/template.pot b/hyperloop/locale/template.pot new file mode 100644 index 0000000..e477bf9 --- /dev/null +++ b/hyperloop/locale/template.pot @@ -0,0 +1,304 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-12-22 11:22+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: booking.lua +msgid "Station data is corrupted. Please rebuild the station!" +msgstr "" + +#: booking.lua +msgid "Station is still blocked. Please try again in a few seconds!" +msgstr "" + +#: door.lua +msgid "The Booking Machine for this station is missing!" +msgstr "" + +#: lcd.lua +msgid "Hyperloop Display" +msgstr "" + +#: lcd.lua seat.lua +msgid " | | << Hyperloop >> | be anywhere" +msgstr "" + +#: tube.lua +msgid "Junction at " +msgstr "" + +#: tube.lua +msgid "There is no station/junction on this level. " +msgstr "" + +#: tube.lua +msgid "Do you really want to start a new network?!" +msgstr "" + +#: tube.lua +msgid "Hyperloop Tube" +msgstr "" + +#: booking_node.lua elevator.lua +msgid "Select your destination" +msgstr "" + +#: booking_node.lua elevator.lua +msgid "Destination" +msgstr "" + +#: booking_node.lua +msgid "Distance" +msgstr "" + +#: booking_node.lua +msgid "Local Info" +msgstr "" + +#: booking_node.lua +msgid "" +"Please enter the station name to\n" +"which this booking machine belongs." +msgstr "" + +#: booking_node.lua +msgid "Station name" +msgstr "" + +#: booking_node.lua +msgid "Additional station information" +msgstr "" + +#: booking_node.lua +msgid "Station has already a booking machine!" +msgstr "" + +#: booking_node.lua +msgid "Invalid station name!" +msgstr "" + +#: booking_node.lua +msgid "Hyperloop Booking Machine" +msgstr "" + +#: elevator.lua +msgid "Hyperloop Elevator Shaft" +msgstr "" + +#: elevator.lua +msgid "Floor" +msgstr "" + +#: elevator.lua +msgid "(current position)" +msgstr "" + +#: elevator.lua +msgid "Hyperloop Elevator" +msgstr "" + +#: elevator.lua +msgid "Please insert floor name" +msgstr "" + +#: elevator.lua +msgid "Floor name" +msgstr "" + +#: elevator.lua +msgid "Base" +msgstr "" + +#: elevator.lua wifi.lua +msgid "Save" +msgstr "" + +#: map.lua +msgid "Dist." +msgstr "" + +#: map.lua +msgid "Station/Junction" +msgstr "" + +#: map.lua +msgid "Position" +msgstr "" + +#: map.lua +msgid "Owner" +msgstr "" + +#: map.lua +msgid "Conn. with" +msgstr "" + +#: map.lua +msgid "Close" +msgstr "" + +#: map.lua +msgid "Hyperloop Station Book" +msgstr "" + +#: seat.lua +msgid "Thank you | for | travelling | with | Hyperloop." +msgstr "" + +#: seat.lua +msgid " | Welcome at | | " +msgstr "" + +#: seat.lua +msgid "[Hyperloop] No booking entered!" +msgstr "" + +#: seat.lua +msgid "Destination:" +msgstr "" + +#: seat.lua +msgid "Distance:" +msgstr "" + +#: seat.lua +msgid "Arrival in:" +msgstr "" + +#: seat.lua +msgid "Hyperloop Pod Seat" +msgstr "" + +#: waypoint.lua +msgid "Hyperloop Waypoint" +msgstr "" + +#: station.lua +msgid "Station completed. Now place the Booking Machine!" +msgstr "" + +#: station.lua +msgid "Area is protected!" +msgstr "" + +#: station.lua +msgid "Not enough space to build the station!" +msgstr "" + +#: station.lua +msgid "Hyperloop Station Pod Builder" +msgstr "" + +#: station.lua +msgid "Hyperloop Pod Shell" +msgstr "" + +#: station.lua recipes.lua +msgid "Hypersteel Ingot" +msgstr "" + +#: station.lua +msgid "Blue Wool" +msgstr "" + +#: station.lua +msgid "Glass" +msgstr "" + +#: station.lua +msgid "Not enough inventory items to build the station!" +msgstr "" + +#: station.lua +msgid "Destroy Station" +msgstr "" + +#: station.lua +msgid "Build Station" +msgstr "" + +#: station.lua +msgid "Hyperloop Station Block" +msgstr "" + +#: station.lua +msgid "Station" +msgstr "" + +#: wifi.lua +msgid "Enter channel string" +msgstr "" + +#: wifi.lua +msgid "Hyperloop WiFi Tube" +msgstr "" + +#: deco.lua +msgid "Hyperloop Promo Poster " +msgstr "" + +#: deco.lua +msgid "Hyperloop Station Sign" +msgstr "" + +#: deco.lua +msgid "Hyperloop Station Sign Right" +msgstr "" + +#: deco.lua +msgid "Hyperloop Station Sign Left" +msgstr "" + +#: junction.lua +msgid "Station connected with " +msgstr "" + +#: junction.lua +msgid "Junction connected with " +msgstr "" + +#: junction.lua +msgid "Hyperloop Junction Block" +msgstr "" + +#: junction.lua +msgid "Junction" +msgstr "" + +#: junction.lua +msgid "Hyperloop Pillar" +msgstr "" + +#: tubecrowbar.lua +msgid "[Crowbar Help]\n" +msgstr "" + +#: tubecrowbar.lua +msgid " left: remove node\n" +msgstr "" + +#: tubecrowbar.lua +msgid " right: repair tube/shaft line\n" +msgstr "" + +#: tubecrowbar.lua +msgid "You don't have the necessary privs!" +msgstr "" + +#: tubecrowbar.lua +msgid "Hyperloop Tube Crowbar" +msgstr "" diff --git a/hyperloop/locale/template.txt b/hyperloop/locale/template.txt new file mode 100644 index 0000000..8b7b478 --- /dev/null +++ b/hyperloop/locale/template.txt @@ -0,0 +1,154 @@ +# textdomain: hyperloop + + +### booking.lua ### + +Station data is corrupted. Please rebuild the station!= +Station is still blocked. Please try again in a few seconds!= + +### booking_node.lua ### + +Additional station information= +Hyperloop Booking Machine= +Invalid station name!= + +Please enter the station name to@nwhich this booking machine belongs.= + +Station has already a booking machine!= +Station name= + +### booking_node.lua ### +### elevator.lua ### + +Select your destination= + +### booking_node.lua ### +### migrate.lua ### + += + +### deco.lua ### + +Hyperloop Promo Poster = +Hyperloop Station Sign= +Hyperloop Station Sign Left= +Hyperloop Station Sign Right= + +### door.lua ### + +Hyperloop Door Bottom= +Hyperloop Door Top= +The Booking Machine for this station is missing!= + +### elevator.lua ### + +(current position)= +Base= +Destination= +Floor= +Floor name= +Hyperloop Elevator= +Hyperloop Elevator Shaft= +Please insert floor name= + +### elevator.lua ### +### wifi.lua ### + +Save= + +### junction.lua ### + +Hyperloop Junction Block= +Hyperloop Pillar= +Junction connected with = +Station connected with = + +### junction.lua ### +### migrate.lua ### + +Junction= + +### lcd.lua ### + +Hyperloop Display= + +### lcd.lua ### +### seat.lua ### + + | | << Hyperloop >> | be anywhere= + +### map.lua ### + +Close= +Conn. with= +Dist.= +Hyperloop Station Book= +Owner= +Position= +Station/Junction= + +### migrate.lua ### + +Hyperloop Legacy Tube= +unknown= + +### recipes.lua ### +### station.lua ### + +Hypersteel Ingot= + +### seat.lua ### + + | Welcome at | | = +Arrival in:= +Destination:= +Distance:= +Hyperloop Pod Seat= +Thank you | for | travelling | with | Hyperloop.= +[Hyperloop] No booking entered!= + +### station.lua ### + +Area is protected!= +Blue Wool= +Build Station= +Destroy Station= +Glass= +Hyperloop Pod Shell= +Hyperloop Station Block= +Hyperloop Station Pod Builder= +Not enough inventory items to build the station!= +Not enough space to build the station!= +Station= +Station completed. Now place the Booking Machine!= + +### tube.lua ### + +Do you really want to start a new network?!= +Hyperloop Tube= +Junction at = +Open end at = +Station '= +Station at = +There is no station/junction on this level. = + +### tubecrowbar.lua ### + + left: remove node@n= + right: repair tube/shaft line@n= +Hyperloop Tube Crowbar= + +Repair via WorldEdit placed Hyperloop tubes by reusing WorldEdit pos1/pos2= + +Rights to remove tube nodes by means of the crowbar= +You don't have the necessary privs!= +[Crowbar Help]@n= + +### waypoint.lua ### + +Hyperloop Waypoint= + +### wifi.lua ### + +Enter channel string= +Hyperloop WiFi Tube= diff --git a/hyperloop/map.lua b/hyperloop/map.lua new file mode 100644 index 0000000..c875268 --- /dev/null +++ b/hyperloop/map.lua @@ -0,0 +1,127 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Stations = hyperloop.Stations + +-- Return a text block with all given station names and their attributes +local function generate_string(sortedList) + -- Generate a list with lStationPositions[pos] = idx + -- used to generate the "connected with" list. + local lStationPositions = {} + for idx,item in ipairs(sortedList) do + local sKey = SP(item.pos) + lStationPositions[sKey] = idx + end + + local tRes = { + "label[0,0;ID]".. + "label[0.7,0;"..S("Dist.").."]".. + "label[1.8,0;"..S("Station/Junction").."]".. + "label[5.4,0;"..S("Position").."]".. + "label[7.9,0;"..S("Owner").."]".. + "label[10,0;"..S("Conn. with").."]"} + for idx,dataSet in ipairs(sortedList) do + if idx == 23 then + break + end + local ypos = 0.2 + idx * 0.4 + local owner = dataSet.owner or "" + local name = dataSet.name or "" + local distance = dataSet.distance or 0 + + tRes[#tRes+1] = "label[0,"..ypos..";"..idx.."]" + tRes[#tRes+1] = "label[0.7,"..ypos..";"..distance.." m]" + tRes[#tRes+1] = "label[1.8,"..ypos..";"..string.sub(name,1,24).."]" + tRes[#tRes+1] = "label[5.4,"..ypos..";"..SP(dataSet.pos).."]" + tRes[#tRes+1] = "label[7.9,"..ypos..";"..string.sub(owner,1,14).."]" + tRes[#tRes+1] = "label[10,"..ypos..";" + for dir,conn in pairs(dataSet.conn) do + if conn and lStationPositions[conn] then + tRes[#tRes + 1] = lStationPositions[conn] + tRes[#tRes + 1] = ", " + else + tRes[#tRes + 1] = conn + tRes[#tRes + 1] = ", " + end + end + tRes[#tRes] = "]" + end + return table.concat(tRes) +end + +local function station_list_as_string(pos) + -- Generate a distance sorted list of all stations + local sortedList = Stations:station_list(pos, nil, "dist") + -- Generate the formspec string + return generate_string(sortedList) +end + +local function network_list_as_string(pos) + -- Determine next station position + local next_pos = Stations:get_next_station(pos) + -- Generate a distance sorted list of all connected stations + local sortedList = Stations:station_list(pos, next_pos, "dist") + -- Generate the formspec string + return generate_string(sortedList) +end + +local function map_on_use(itemstack, user) + local player_name = user:get_player_name() + local pos = user:get_pos() + local sStationList = station_list_as_string(pos) + local formspec = "size[12,10]" .. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + sStationList .. + "button_exit[5,9.5;2,1;close;"..S("Close").."]" + + minetest.show_formspec(player_name, "hyperloop:station_map", formspec) + return itemstack +end + +local function map_on_secondary_use(itemstack, user) + local player_name = user:get_player_name() + local pos = user:get_pos() + local sStationList = network_list_as_string(pos) + local formspec = "size[12,10]" .. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + sStationList .. + "button_exit[5,9.5;2,1;close;"..S("Close").."]" + + minetest.show_formspec(player_name, "hyperloop:station_map", formspec) + return itemstack +end + +-- Tool for tube workers to find the next station +minetest.register_node("hyperloop:station_map", { + description = S("Hyperloop Station Book"), + inventory_image = "hyperloop_stations_book.png", + wield_image = "hyperloop_stations_book.png", + groups = {cracky=1, book=1}, + on_use = map_on_use, + on_place = map_on_secondary_use, + on_secondary_use = map_on_secondary_use, + stack_max = 1, +}) + diff --git a/hyperloop/migrate.lua b/hyperloop/migrate.lua new file mode 100644 index 0000000..e438e79 --- /dev/null +++ b/hyperloop/migrate.lua @@ -0,0 +1,389 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + History: + see init.lua + + Migrate from v1 to v2 + +]]-- + +-- for lazy programmers +local SP = minetest.pos_to_string +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Tube = hyperloop.Tube +local Shaft = hyperloop.Shaft + +local Elevators = hyperloop.Elevators +local Stations = hyperloop.Stations + +local tLegacyNodeNames = {} + +local JunctionsToBePlacedAfter = {} + +local function get_tube_data(pos, dir1, dir2, num_tubes) + local param2, tube_type = tubelib2.encode_param2(dir1, dir2, num_tubes) + return pos, param2, tube_type, num_tubes +end + +-- Check if node has a connection on the given dir +local function connected(self, pos, dir) + local _,node = self:get_node(pos, dir) + return self.primary_node_names[node.name] + or self.secondary_node_names[node.name] +end + +-- Determine dirs via surrounding nodes +local function determine_dir1_dir2_and_num_conn(self, pos) + local dirs = {} + for dir = 1, 6 do + if connected(self, pos, dir) then + dirs[#dirs+1] = dir + end + end + if #dirs == 1 then + return dirs[1], nil, 1 + elseif #dirs == 2 then + return dirs[1], dirs[2], 2 + end +end + +-- convert legacy tubes to current tubes +for idx = 0,2 do + minetest.register_node("hyperloop:tube"..idx, { + description = S("Hyperloop Legacy Tube"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^[transformR90]", + "hyperloop_tube_locked.png^[transformR90]", + 'hyperloop_tube_closed.png', + 'hyperloop_tube_closed.png', + 'hyperloop_tube_open.png', + 'hyperloop_tube_open.png', + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + local node = minetest.get_node(pos) + node.name = "hyperloop:tubeS" + minetest.swap_node(pos, node) + if not Tube:after_place_tube(pos, placer, pointed_thing) then + minetest.remove_node(pos) + return true + end + return false + end, + + paramtype2 = "facedir", + node_placement_prediction = "hyperloop:tubeS", + groups = {cracky=2, not_in_creative_inventory=1}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + }) +end + +local function convert_legary_nodes(self, pos, dir) + local convert_next_tube = function(self, pos, dir) + local npos, node = self:get_node(pos, dir) + if tLegacyNodeNames[node.name] then + local dir1, dir2, num = determine_dir1_dir2_and_num_conn(self, npos) + if dir1 then + self.clbk_after_place_tube(get_tube_data(npos, dir1, + dir2 or tubelib2.Turn180Deg[dir1], num)) + if tubelib2.Turn180Deg[dir] == dir1 then + return npos, dir2 + else + return npos, dir1 + end + end + end + end + + local cnt = 0 + if not dir then return pos, dir, cnt end + while cnt <= 64000 do + local new_pos, new_dir = convert_next_tube(self, pos, dir) + if cnt > 0 and (cnt % self.max_tube_length) == 0 then -- border reached? + JunctionsToBePlacedAfter[#JunctionsToBePlacedAfter + 1] = pos + end + if not new_dir then break end + pos, dir = new_pos, new_dir + cnt = cnt + 1 + end + return pos, dir, cnt +end + +local function convert_line(self, pos, dir) + local fpos,fdir = convert_legary_nodes(self, pos, dir) + self:tool_repair_tube(pos) +end + + +local tWifiNodes = {} -- user for pairing +local lWifiNodes = {} -- used for post processing + +local function set_pairing(pos, peer_pos) + + M(pos):set_int("tube_dir", Tube:get_primary_dir(pos)) + M(peer_pos):set_int("tube_dir", Tube:get_primary_dir(peer_pos)) + + local tube_dir1 = Tube:store_teleport_data(pos, peer_pos) + local tube_dir2 = Tube:store_teleport_data(peer_pos, pos) +end + + +local function wifi_post_processing() + for _,pos in ipairs(lWifiNodes) do + local dir = Tube:get_primary_dir(pos) + local npos = Tube:get_pos(pos, dir) + Tube:tool_repair_tube(npos) + end +end + +-- Wifi nodes don't know their counterpart. +-- But by means of the tube head nodes, two +-- Wifi nodes in one tube line can be determined. +local function determine_wifi_pairs(pos) + -- determine 1. tube head node + local pos1 = M(pos):get_string("peer") + if pos1 == "" then return end + -- determine 2. tube head node + local pos2 = M(P(pos1)):get_string("peer") + if pos2 == "" then return end + for k,item in pairs(tWifiNodes) do + -- entry already available + if item[1] == pos2 and item[2] == pos1 then + tWifiNodes[k] = nil + -- start paring + set_pairing(P(k), pos) + return + end + end + -- add single Wifi node to pairing table + tWifiNodes[SP(pos)] = {pos1, pos2} +end + +local function next_node_on_the_way_to_a_wifi_node(pos) + local dirs = {} + for dir = 1, 6 do + local npos, node = Tube:get_node(pos, dir) + if tLegacyNodeNames[node.name] then + dirs[#dirs+1] = dir + elseif node.name == "hyperloop:tube_wifi1" then + lWifiNodes[#lWifiNodes+1] = npos + determine_wifi_pairs(npos) + end + end + if #dirs == 1 then + return dirs[1], nil, 1 + elseif #dirs == 2 then + return dirs[1], dirs[2], 2 + end +end + +local function search_wifi_node(pos, dir) + local convert_next_tube = function(pos, dir) + local npos, node = Tube:get_node(pos, dir) + local dir1, dir2, num = next_node_on_the_way_to_a_wifi_node(npos) + if dir1 then + if tubelib2.Turn180Deg[dir] == dir1 then + return npos, dir2 + else + return npos, dir1 + end + end + end + + local cnt = 0 + if not dir then return pos, cnt end + while true do + local new_pos, new_dir = convert_next_tube(pos, dir) + if not new_dir then break end + pos, dir = new_pos, new_dir + cnt = cnt + 1 + end + return pos, dir, cnt +end + +local function search_wifi_node_in_all_dirs(pos) + -- check all positions + for dir = 1, 6 do + local npos, node = Tube:get_node(pos, dir) + if node and node.name == "hyperloop:tube1" then + search_wifi_node(pos, dir) + end + end +end + +local function convert_tube_line(pos) + -- check all positions + for dir = 1, 6 do + local npos, node = Tube:get_node(pos, dir) + if node and node.name == "hyperloop:tube1" then + convert_line(Tube, pos, dir) + end + end +end + +local function convert_shaft_line(pos) + -- check lower position + convert_line(Shaft, pos, 5) + -- check upper position + pos.y = pos.y + 1 + convert_line(Shaft, pos, 6) + pos.y = pos.y - 1 +end + +local function station_name(item) + if item.junction == true then + return "Junction" + elseif item.station_name then + return item.station_name + else + return "Station" + end +end + +local function add_to_table(tbl, tValues) + local res = table.copy(tbl) + for k,v in pairs(tValues) do + tbl[k] = v + end + return res +end + +local function convert_station_data(tAllStations) + tLegacyNodeNames = { + ["hyperloop:tube0"] = true, + ["hyperloop:tube1"] = true, + ["hyperloop:tube2"] = true, + } + + local originNodeNames = add_to_table(Tube.primary_node_names, tLegacyNodeNames) + + for key,item in pairs(tAllStations) do + if item.pos and Tube:is_secondary_node(item.pos) then + Stations:set(item.pos, station_name(item), { + owner = item.owner or S(""), + junction = item.junction, + facedir = item.facedir, + booking_info = item.booking_info, + booking_pos = item.booking_pos, + }) + end + end + -- First perform the Wifi node pairing + -- before all tube node loose their meta data + -- while converted. + for key,item in pairs(tAllStations) do + if item.pos and Tube:is_secondary_node(item.pos) then + search_wifi_node_in_all_dirs(item.pos) + end + end + -- Then convert all tube nodes + for key,item in pairs(tAllStations) do + if item.pos and Tube:is_secondary_node(item.pos) then + convert_tube_line(item.pos) + Tube:after_place_node(item.pos) + end + end + -- Repair the tube lines of wifi nodes + wifi_post_processing() + + Tube.primary_node_names = originNodeNames +end + +local function convert_elevator_data(tAllElevators) + tLegacyNodeNames = { + ["hyperloop:shaft"] = true, + ["hyperloop:shaft2"] = true, + } + local originNodeNames = add_to_table(Shaft.primary_node_names, tLegacyNodeNames) + local originDirsToCheck = table.copy(Shaft.dirs_to_check) + Shaft.dirs_to_check = {5,6} -- legacy elevators use up/down only + + for pos,tElevator in pairs(tAllElevators) do + for _,floor in pairs(tElevator.floors) do + if floor.pos and Shaft:is_secondary_node(floor.pos) then + Elevators:set(floor.pos, floor.name, { + facedir = floor.facedir, + }) + convert_shaft_line(floor.pos) + M(floor.pos):set_int("change_counter", 0) + Shaft:after_place_node(floor.pos) + end + end + end + + Shaft.primary_node_names = originNodeNames + Shaft.dirs_to_check = originDirsToCheck +end + +local function place_junctions() + for _,pos in ipairs(JunctionsToBePlacedAfter) do + minetest.set_node(pos, {name = "hyperloop:junction"}) + M(pos):set_string("infotext", S("Junction")) + Stations:set(pos, "Junction", {owner = S("unknown"), junction = true}) + Tube:after_place_node(pos) + minetest.log("action", "[Hyperloop] Junction placed at "..SP(pos)) + end +end + +local wpath = minetest.get_worldpath() +function hyperloop.file2table(filename) + local f = io.open(wpath..DIR_DELIM..filename, "r") + if f == nil then return nil end + local t = f:read("*all") + f:close() + if t == "" or t == nil then return nil end + return minetest.deserialize(t) +end + +local function migrate() + local data = hyperloop.file2table("mod_hyperloop.data") + if data then + minetest.log("action", "[Hyperloop] Migrate data...") + hyperloop.convert = true + convert_station_data(data.tAllStations) + convert_elevator_data(data.tAllElevators) + os.remove(wpath..DIR_DELIM.."mod_hyperloop.data") + place_junctions() + hyperloop.convert = nil + minetest.log("action", "[Hyperloop] Data migrated") + end +end + +minetest.after(5, migrate) + +minetest.register_lbm({ + label = "[Hyperloop] booking/seat/door migration", + name = "hyperloop:migrate", + nodenames = { + "hyperloop:booking", "hyperloop:booking_ground", + "hyperloop:doorTopPassive", "hyperloop:doorBottom", + "hyperloop:seat", + }, + run_at_every_load = true, + action = function(pos, node) + local meta = M(pos) + if meta:get_string("key_str") ~= "" then + local s = meta:get_string("key_str") + meta:set_string("sStationPos", "("..string.sub(s, 2, -2)..")") + if node.name == "hyperloop:booking" or node.name == "hyperloop:booking_ground" then + meta:set_int("change_counter", 0) + end + end + end +}) diff --git a/hyperloop/mod.conf b/hyperloop/mod.conf new file mode 100644 index 0000000..5fbe8af --- /dev/null +++ b/hyperloop/mod.conf @@ -0,0 +1,3 @@ +name = hyperloop +depends = default, tubelib2 +optional_depends = techage, worldedit, intllib diff --git a/hyperloop/network.lua b/hyperloop/network.lua new file mode 100644 index 0000000..ddb8fa8 --- /dev/null +++ b/hyperloop/network.lua @@ -0,0 +1,266 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + Station and elevator network management +]]-- + +-- for lazy programmers +local S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Convert to list and add pos based on key string +local function table_to_list(table) + local lRes = {} + for key,item in pairs(table) do + item.pos = P(key) + lRes[#lRes+1] = item + end + return lRes +end + +local function distance(pos1, pos2) + return math.floor(math.abs(pos1.x - pos2.x) + + math.abs(pos1.y - pos2.y) + math.abs(pos1.z - pos2.z)) +end + +-- Add the distance to pos to each list item +local function add_distance_to_list(lStations, pos) + for _,item in ipairs(lStations) do + item.distance = distance(item.pos, pos) + end + return lStations +end + +-- Add the index to each list item +local function add_index_to_list(lStations) + -- walk through the list of floors for the next connection + local get_next = function(key, idx) + for _,floor in ipairs(lStations) do + if floor.conn[6] == key then -- upward match? + floor.idx = idx + return S(floor.pos) -- return floor key + end + end + end + + local key = nil + for idx = 1,#lStations do + key = get_next(key, idx) + end + return lStations +end + +-- Return a table with all stations, the given station (as 'sKey') is connected with +-- tRes is used for the resulting table (recursive call) +local function get_stations(tStations, sKey, tRes) + if not tStations[sKey] or not tStations[sKey].conn then + return {} + end + for dir,dest in pairs(tStations[sKey].conn) do + -- Not already visited? + if not tRes[dest] then + -- Known station? + if tStations[dest] then + tRes[dest] = tStations[dest] + get_stations(tStations, dest, tRes) + end + end + end + return tRes +end + +-- Return a list with sorted elevators, beginning with the top car +-- with no shaft upwards +local function sort_based_on_level(tStations) + local lStations = table_to_list(table.copy(tStations)) + -- to be able to sort the list, an index has to be added + lStations = add_index_to_list(lStations) + table.sort(lStations, function(a,b) return (a.idx or 9999) < (b.idx or 9999) end) + return lStations +end + +-- Return a list with sorted stations +local function sort_based_on_distance(tStations, pos) + local lStations = table_to_list(table.copy(tStations)) + -- to be able to sort the list, the distance to pos has to be added + lStations = add_distance_to_list(lStations, pos) + table.sort(lStations, function(a,b) return a.distance < b.distance end) + return lStations +end + + +-- +-- Class Network +-- + +--[[ + tStations["(x,y,z)"] = { + ["conn"] = { + dir = "(200,0,20)", + }, + } + change_counter = n, +]]-- + + +local Network = {} +hyperloop.Network = Network + +function Network:new() + local o = { + tStations = {}, + change_counter = 0, + } + setmetatable(o, self) + self.__index = self + return o +end + +-- Set an elevator or station entry. +-- tAttr is a table with additional attributes to be stored. +function Network:set(pos, name, tAttr) + if pos then + local sKey = S(pos) + if not self.tStations[sKey] then + self.tStations[sKey] = { + conn = {}, + } + end + self.tStations[sKey].name = name + for k,v in pairs(tAttr) do + self.tStations[sKey][k] = v + end + self.change_counter = self.change_counter + 1 + end +end + +-- Update an elevator or station entry. +-- tAttr is a table with additional attributes to be stored. +function Network:update(pos, tAttr) + if pos then + local sKey = S(pos) + if self.tStations[sKey] then + for k,v in pairs(tAttr) do + if v == "nil" then + self.tStations[sKey][k] = nil + else + self.tStations[sKey][k] = v + end + end + self.change_counter = self.change_counter + 1 + end + end +end + +function Network:get(pos) + return pos and self.tStations[S(pos)] +end + +-- Delete an elevator or station entry. +function Network:delete(pos) + if pos then + self.tStations[S(pos)] = nil + self.change_counter = self.change_counter + 1 + end +end + +function Network:changed(counter) + return self.change_counter > counter, self.change_counter +end + +-- Update the connection data base. The output dir information is needed +-- to be able to delete a connection, if necessary. +-- Returns true, if data base is changed. +function Network:update_connections(pos, out_dir, conn_pos) + local sKey = S(pos) + local res = false + if not self.tStations[sKey] then + self.tStations[sKey] = {} + res = true + end + if not self.tStations[sKey].conn then + self.tStations[sKey].conn = {} + res = true + end + conn_pos = S(conn_pos) + if self.tStations[sKey].conn[out_dir] ~= conn_pos then + self.tStations[sKey].conn[out_dir] = conn_pos + res = true + end + if res then + self.change_counter = self.change_counter + 1 + end + return res +end + +-- Return the nearest station position +function Network:get_next_station(pos) + local min_dist = 999999 + local min_key = nil + local dist + for key,item in pairs(self.tStations) do + if not item.junction then + dist = distance(pos, P(key)) + if dist < min_dist then + min_dist = dist + min_key = key + end + end + end + return P(min_key) +end + +-- Return a sorted list of stations +-- Param pos: player pos +-- Param station_pos: next station pos or nil. +-- Used to generate list with connected stations only +-- Param sorted: either "dist" or "level" +function Network:station_list(pos, station_pos, sorted) + local tStations, lStations + if station_pos then + local tRes = {} + tStations = get_stations(self.tStations, S(station_pos), tRes) -- reduced + else + tStations = self.tStations -- all stations + end + if sorted == "dist" then + lStations = sort_based_on_distance(tStations, pos) + else + lStations = sort_based_on_level(tStations) + end + return lStations +end + +-- Check the complete table by means of the provided callback bool = func(pos) +function Network:filter(callback) + local lKeys = {} + for key,_ in pairs(self.tStations) do + lKeys[#lKeys+1] = key + end + for _,key in ipairs(lKeys) do + if not callback(P(key)) then + self.tStations[key] = nil + end + end +end + +function Network:deserialize(data) + if data ~= "" then + data = minetest.deserialize(data) + self.tStations = data.tStations + self.change_counter = data.change_counter + end +end + +function Network:serialize() + return minetest.serialize(self) +end + \ No newline at end of file diff --git a/hyperloop/recipes.lua b/hyperloop/recipes.lua new file mode 100644 index 0000000..a1afb80 --- /dev/null +++ b/hyperloop/recipes.lua @@ -0,0 +1,244 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + History: + see init.lua + +]]-- + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +minetest.register_craftitem("hyperloop:hypersteel_ingot", { + description = S("Hypersteel Ingot"), + inventory_image = "hyperloop_hypersteel_ingot.png", +}) + +if minetest.global_exists("techage") then + minetest.register_craft({ + output = "hyperloop:hypersteel_ingot 4", + recipe = { + {"techage:aluminum", "default:tin_ingot"}, + {"techage:aluminum", "dye:cyan"}, + }, + }) +else + minetest.register_craft({ + output = "hyperloop:hypersteel_ingot 4", + recipe = { + {"default:steel_ingot", "default:tin_ingot"}, + {"default:copper_ingot", "dye:cyan"}, + }, + }) +end + +minetest.register_craft({ + output = "hyperloop:tubeS 8", + recipe = { + {"", "hyperloop:hypersteel_ingot", ""}, + {"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"}, + {"", "hyperloop:hypersteel_ingot", ""}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:pillar 8", + recipe = { + {"", "hyperloop:hypersteel_ingot", ""}, + {"", "hyperloop:hypersteel_ingot", ""}, + {"", "hyperloop:hypersteel_ingot", ""}, + }, +}) + +if minetest.global_exists("techage") then + minetest.register_craft({ + output = "hyperloop:pod_wall 6", + recipe = { + {"basic_materials:plastic_sheet", "basic_materials:plastic_sheet", "basic_materials:plastic_sheet"}, + {"basic_materials:plastic_sheet", "dye:white", "basic_materials:plastic_sheet"}, + {"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot"}, + }, + }) +else + minetest.register_craft({ + output = "hyperloop:pod_wall 8", + recipe = { + {"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot"}, + {"hyperloop:hypersteel_ingot", "dye:white", "hyperloop:hypersteel_ingot"}, + {"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot"}, + }, + }) +end + +minetest.register_craft({ + output = "hyperloop:booking 1", + recipe = { + {"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"}, + {"", "default:paper", ""}, + {"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:junction", + recipe = { + {"", "hyperloop:hypersteel_ingot", ""}, + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + {"", "hyperloop:hypersteel_ingot", ""}, + }, +}) + +if minetest.global_exists("techage") then + minetest.register_craft({ + output = "hyperloop:station", + recipe = { + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + {"", "techage:ta4_wlanchip", ""}, + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + }, + }) +else + minetest.register_craft({ + output = "hyperloop:station", + recipe = { + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + {"", "default:mese_crystal", ""}, + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + }, + }) +end + +minetest.register_craft({ + output = "hyperloop:robot", + recipe = { + {"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot"}, + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + {"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot"}, + }, +}) + +if hyperloop.wifi_crafting_enabled then + minetest.register_craft({ + output = "hyperloop:tube_wifi1 2", + recipe = { + {"default:mese_crystal", "hyperloop:hypersteel_ingot", "default:mese_crystal"}, + {"hyperloop:hypersteel_ingot", "default:mese_crystal", "hyperloop:hypersteel_ingot"}, + {"default:mese_crystal", "hyperloop:hypersteel_ingot", "default:mese_crystal"}, + }, + }) +end + +minetest.register_craft({ + output = "hyperloop:station_map", + recipe = { + {"default:paper", "dye:red", ""}, + {"default:paper", "dye:red", ""}, + {"default:paper", "dye:red", ""}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:shaft 8", + recipe = { + {"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"}, + {"", "", ""}, + {"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:elevator_bottom 2", + recipe = { + {"", "default:glass", "hyperloop:hypersteel_ingot"}, + {"", "dye:red", "default:mese_crystal"}, + {"", "default:glass", "hyperloop:hypersteel_ingot"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:sign", + recipe = { + {"", "", ""}, + {"", "dye:cyan", "hyperloop:hypersteel_ingot"}, + {"", "default:wood", "default:wood"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:signL 4", + recipe = { + {"", "", ""}, + {"", "", ""}, + {"dye:cyan", "hyperloop:hypersteel_ingot", "default:wood"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:signR 4", + recipe = { + {"", "", ""}, + {"", "", ""}, + {"default:wood", "hyperloop:hypersteel_ingot", "dye:cyan"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:poster1L", + recipe = { + {"", "", ""}, + {"", "dye:white", "hyperloop:hypersteel_ingot"}, + {"", "dye:blue", "default:wood"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:poster2L", + recipe = { + {"", "", ""}, + {"", "dye:white", "hyperloop:hypersteel_ingot"}, + {"", "dye:cyan", "default:wood"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:poster3L", + recipe = { + {"", "", ""}, + {"", "dye:white", "hyperloop:hypersteel_ingot"}, + {"", "dye:brown", "default:wood"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:waypoint", + recipe = { + {"", "", ""}, + {"", "", ""}, + {"default:steel_ingot", "hyperloop:hypersteel_ingot", "default:gold_ingot"}, + }, +}) + +minetest.register_craft({ + output = "hyperloop:tube_crowbar", + recipe = { + {"", "", "dye:red"}, + {"", "hyperloop:hypersteel_ingot", ""}, + {"hyperloop:hypersteel_ingot", "", ""}, + }, +}) + +minetest.register_craft({ + type = "cooking", + output = "dye:cyan", + recipe = "default:cactus", + cooktime = 3, +}) + diff --git a/hyperloop/screenshot.png b/hyperloop/screenshot.png new file mode 100644 index 0000000..9165627 Binary files /dev/null and b/hyperloop/screenshot.png differ diff --git a/hyperloop/seat.lua b/hyperloop/seat.lua new file mode 100644 index 0000000..839d9ff --- /dev/null +++ b/hyperloop/seat.lua @@ -0,0 +1,227 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS +local I, _ = dofile( minetest.get_modpath("hyperloop").."/intllib.lua") + +local Stations = hyperloop.Stations + +local function enter_display(tStation, text) + -- determine position + if tStation ~= nil then + local lcd_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F", 2) + -- update display + minetest.registered_nodes["hyperloop:lcd"].update(lcd_pos, text) + end +end + +local function on_final_close_door(tStation) + -- close the door and play sound if no player is around + if hyperloop.is_player_around(tStation.pos) then + -- try again later + minetest.after(3.0, on_final_close_door, tStation) + else + hyperloop.close_pod_door(tStation) + enter_display(tStation, I(" | | << Hyperloop >> | be anywhere")) + end +end + +local function on_open_door(tArrival) + -- open the door and play sound + local meta = minetest.get_meta(tArrival.pos) + meta:set_int("arrival_time", 0) -- finished + -- open door + hyperloop.open_pod_door(tArrival) + -- prepare display for the next trip + enter_display(tArrival, I("Thank you | for | travelling | with | Hyperloop.")) + minetest.after(5.0, on_final_close_door, tArrival, tArrival.facedir) +end + +local function on_arrival(tDeparture, tArrival, player_name, sound) + local player = minetest.get_player_by_name(player_name) + -- activate display + local text = I(" | Welcome at | | ")..string.sub(tArrival.name, 1, 13) + enter_display(tArrival, text) + -- stop timer + minetest.get_node_timer(tDeparture.pos):stop() + -- move player to the arrival station + if player ~= nil then + local pos = table.copy(tArrival.pos) + pos.y = pos.y + 0.5 + player:set_pos(pos) + -- rotate player to look in correct arrival direction + -- calculate the look correction + -- workaround to prevent server crashes + local val1 = hyperloop.facedir_to_rad(tDeparture.facedir) + local val2 = player:get_look_horizontal() + if val1 ~= nil and val2 ~= nil then + local offs = val1 - val2 + local yaw = hyperloop.facedir_to_rad(tArrival.facedir) - offs + player:set_look_yaw(yaw) + end + end + -- play arrival sound + minetest.sound_stop(sound) + minetest.sound_play("down2", { + pos = tArrival.pos, + gain = 0.5, + max_hear_distance = 2 + }) + + minetest.after(4.0, on_open_door, tArrival) +end + +local function on_travel(tDeparture, tArrival, player_name, atime) + -- play sound and switch door state + local sound = minetest.sound_play("normal2", { + pos = tDeparture.pos, + gain = 0.5, + max_hear_distance = 2, + loop = true, + }) + hyperloop.animate_pod_door(tDeparture) + minetest.after(atime, on_arrival, tDeparture, tArrival, player_name, sound) + minetest.after(atime, on_final_close_door, tDeparture) +end + +local function display_timer(pos, elapsed) + -- update display with trip data + local tStation = hyperloop.get_base_station(pos) + if tStation then + local meta = M(pos) + local atime = meta:get_int("arrival_time") - 1 + meta:set_int("arrival_time", atime) + local text = meta:get_string("lcd_text") + if atime > 2 then + enter_display(tStation, text..atime.." sec") + return true + else + return false + end + end + return false +end + +local function meter_to_km(dist) + if dist < 1000 then + return tostring(dist).." m" + elseif dist < 10000 then + return string.format("%.3f km", dist/1000) + else + return string.format("%.1f km", dist/1000) + end +end + +-- place the player, close the door, activate display +local function on_start_travel(pos, node, clicker) + -- arrival data + local meta = M(pos) + local tDeparture, departure_pos = hyperloop.get_base_station(pos) + local arrival_pos = hyperloop.get_arrival(departure_pos) + if arrival_pos == nil then + minetest.chat_send_player(clicker:get_player_name(), S("[Hyperloop] No booking entered!")) + return + end + local tArrival = hyperloop.get_station(arrival_pos) + if tDeparture == nil or tArrival == nil then + return + end + + minetest.sound_play("up2", { + pos = pos, + gain = 0.5, + max_hear_distance = 2 + }) + + -- close the door at arrival station + hyperloop.close_pod_door(tArrival) + -- place player on the seat + pos.y = pos.y - 0.5 + clicker:set_pos(pos) + -- rotate player to look in move direction + clicker:set_look_horizontal(hyperloop.facedir_to_rad(tDeparture.facedir)) + + -- activate display + local dist = hyperloop.distance(pos, tArrival.pos) + local text = I("Destination:").." | "..string.sub(tArrival.name, 1, 13).." | "..I("Distance:").." | ".. + meter_to_km(dist).." | "..I("Arrival in:").." | " + local atime + if dist < 1000 then + atime = 10 + math.floor(dist/200) -- 10..15 sec + elseif dist < 10000 then + atime = 15 + math.floor(dist/600) -- 16..32 sec + else + atime = 32 -- 32 sec is the maximum + end + enter_display(tDeparture, text..atime.." sec") + + -- block departure and arrival stations + hyperloop.block(departure_pos, arrival_pos, atime+10) + + -- store some data for on_timer() + meta:set_int("arrival_time", atime) + meta:set_string("lcd_text", text) + minetest.get_node_timer(pos):start(1.0) + hyperloop.close_pod_door(tDeparture) + + atime = atime - 7 -- substract start/arrival time + minetest.after(4.9, on_travel, tDeparture, tArrival, clicker:get_player_name(), atime) +end + +-- Hyperloop Seat +minetest.register_node("hyperloop:seat", { + description = S("Hyperloop Pod Seat"), + tiles = { + "hyperloop_seat-top.png", + "hyperloop_seat-side.png", + "hyperloop_seat-side.png", + "hyperloop_seat-side.png", + "hyperloop_seat-side.png", + "hyperloop_seat-side.png", + }, + drawtype = "nodebox", + paramtype = 'light', + light_source = 1, + paramtype2 = "facedir", + is_ground_content = false, + walkable = false, + drop = "", + groups = {not_in_creative_inventory=1, crumbly=3}, + node_box = { + type = "fixed", + fixed = { + { -6/16, -8/16, -8/16, 6/16, -2/16, 5/16}, + { -8/16, -8/16, -8/16, -6/16, 4/16, 8/16}, + { 6/16, -8/16, -8/16, 8/16, 4/16, 8/16}, + { -6/16, -8/16, 4/16, 6/16, 6/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = { -8/16, -8/16, -8/16, 8/16, -2/16, 8/16 }, + }, + + on_timer = display_timer, + on_rightclick = on_start_travel, + on_rotate = screwdriver.disallow, + + auto_place_node = function(pos, facedir, sStationPos) + M(pos):set_string("sStationPos", sStationPos) + end, +}) diff --git a/hyperloop/settingtypes.txt b/hyperloop/settingtypes.txt new file mode 100644 index 0000000..1fc0431 --- /dev/null +++ b/hyperloop/settingtypes.txt @@ -0,0 +1,10 @@ +# Enable WiFi blocks (exclude recipe) +hyperloop_wifi_enabled (WiFi block enabled) bool false + +# Enable WiFi block crafting +hyperloop_wifi_crafting_enabled (WiFi block crafting enabled) bool false + +# Enable free tube placement with no level limitation. +# If disabled, connected stations have to be on one level, +# typically underground. +hyperloop_free_tube_placement_enabled (free tube placement enabled) bool false diff --git a/hyperloop/sounds/door.ogg b/hyperloop/sounds/door.ogg new file mode 100644 index 0000000..df4d8b4 Binary files /dev/null and b/hyperloop/sounds/door.ogg differ diff --git a/hyperloop/sounds/down2.ogg b/hyperloop/sounds/down2.ogg new file mode 100644 index 0000000..bd42802 Binary files /dev/null and b/hyperloop/sounds/down2.ogg differ diff --git a/hyperloop/sounds/ele_door.ogg b/hyperloop/sounds/ele_door.ogg new file mode 100644 index 0000000..32bde74 Binary files /dev/null and b/hyperloop/sounds/ele_door.ogg differ diff --git a/hyperloop/sounds/ele_norm.ogg b/hyperloop/sounds/ele_norm.ogg new file mode 100644 index 0000000..8daa6ae Binary files /dev/null and b/hyperloop/sounds/ele_norm.ogg differ diff --git a/hyperloop/sounds/hyperloop_crowbar.ogg b/hyperloop/sounds/hyperloop_crowbar.ogg new file mode 100644 index 0000000..d47f563 Binary files /dev/null and b/hyperloop/sounds/hyperloop_crowbar.ogg differ diff --git a/hyperloop/sounds/normal2.ogg b/hyperloop/sounds/normal2.ogg new file mode 100644 index 0000000..6e0a0d6 Binary files /dev/null and b/hyperloop/sounds/normal2.ogg differ diff --git a/hyperloop/sounds/up2.ogg b/hyperloop/sounds/up2.ogg new file mode 100644 index 0000000..ab2f043 Binary files /dev/null and b/hyperloop/sounds/up2.ogg differ diff --git a/hyperloop/station.lua b/hyperloop/station.lua new file mode 100644 index 0000000..10efae2 --- /dev/null +++ b/hyperloop/station.lua @@ -0,0 +1,354 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Tube = hyperloop.Tube +local Stations = hyperloop.Stations + + +-- Station Pod Assembly Plan +local AssemblyPlan = { + -- y-offs, x/z-path, facedir-offs, name + -- middle slice + { 1, "2F", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1F", 2, "hyperloop:seat"}, + { 0, "1F", 0, "hyperloop:pod_floor"}, + { 1, "", 0, "hyperloop:lcd"}, + -- right slice + {-1, "1F1R", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1F", 0, "hyperloop:pod_wall_ni"}, + { 0, "1F", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + -- left slice + {-1, "2L2R", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + { 0, "1B", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + {-1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1F", 0, "hyperloop:pod_wall_ni"}, + { 1, "", 0, "hyperloop:pod_wall_ni"}, + { 0, "1F", 1, "hyperloop:doorTopPassive"}, + {-1, "", 1, "hyperloop:doorBottom"}, +} + + +local function store_station(pos, placer) + local facedir = hyperloop.get_facedir(placer) + -- do a facedir correction + facedir = (facedir + 3) % 4 -- face to LCD + Stations:set(pos, "Station", { + owner = placer:get_player_name(), + facedir = facedir, + time_blocked = 0}) +end + +-- Calls the node related "auto_place_node()" callback. +local function call_auto_place_node(name, pos, facedir, sKey) + local node = minetest.registered_nodes[name] + if node.auto_place_node ~= nil then + node.auto_place_node(pos, facedir, sKey) + end +end + +local function place_node(pos, facedir, node_name, sKey) + if node_name == "hyperloop:lcd" then + -- wallmounted devices need a facedir correction + local tbl = {[0]=4, [1]=2, [2]=5, [3]=3} + minetest.add_node(pos, {name=node_name, paramtype2="wallmounted", param2=tbl[facedir]}) + else + minetest.add_node(pos, {name=node_name, param2=facedir}) + end + call_auto_place_node(node_name, pos, facedir, sKey) +end + +-- timer function, called cyclically +local function construct(idx, pos, facedir, player_name, sKey) + local item = AssemblyPlan[idx] + if item ~= nil then + local y, path, fd_offs, node_name = item[1], item[2], item[3], item[4] + pos = hyperloop.new_pos(pos, facedir, path, y) + place_node(pos, (facedir + fd_offs) % 4, node_name, sKey) + minetest.after(0.5, construct, idx+1, pos, facedir, player_name, sKey) + else + hyperloop.chat(player_name, S("Station completed. Now place the Booking Machine!")) + end +end + +local function check_space(pos, facedir, placer) + for _,item in ipairs(AssemblyPlan) do + local y, path, node_name = item[1], item[2], item[4] + pos = hyperloop.new_pos(pos, facedir, path, y) + if minetest.is_protected(pos, placer:get_player_name()) then + hyperloop.chat(placer, S("Area is protected!")) + return false + elseif minetest.get_node_or_nil(pos).name ~= "air" then + hyperloop.chat(placer, S("Not enough space to build the station!")) + return false + end + end + return true +end + +local station_formspec = + "size[8,9]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "label[2,0;"..S("Hyperloop Station Pod Builder").."]" .. + "image[0.2,0.9;3,3;hyperloop_station_formspec.png]".. + "list[context;src;3,0.9;1,4;]".. + "label[4,1.2;30 x "..S("Hyperloop Pod Shell").."]" .. + "item_image[3,0.9;1,1;hyperloop:pod_wall]".. + "label[4,2.2;4 x "..S("Hypersteel Ingot").."]" .. + "item_image[3,1.9;1,1;hyperloop:hypersteel_ingot]".. + "label[4,3.2;2 x "..S("Blue Wool").."]" .. + "item_image[3,2.9;1,1;wool:blue]".. + "label[4,4.2;2 x "..S("Glass").."]" .. + "item_image[3,3.9;1,1;default:glass]".. + "list[current_player;main;0,5.3;8,4;]".. + "listring[context;src]".. + "listring[current_player;main]" + + +local function allow_metadata_inventory(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + if M(pos):get_int("busy") == 1 then + return 0 + end + return stack:get_count() +end + +local function check_inventory(inv, player) + local list = inv:get_list("src") + if list[1]:get_name() == "hyperloop:pod_wall" and list[1]:get_count() >= 30 then + if list[2]:get_name() == "hyperloop:hypersteel_ingot" and list[2]:get_count() >= 4 then + if list[3]:get_name() == "wool:blue" and list[3]:get_count() >= 2 then + if list[4]:get_name() == "default:glass" and list[4]:get_count() >= 2 then + return true + end + end + end + end + hyperloop.chat(player, S("Not enough inventory items to build the station!")) + return false +end + +local function remove_inventory_items(inv, meta) + inv:remove_item("src", ItemStack("hyperloop:pod_wall 30")) + inv:remove_item("src", ItemStack("hyperloop:hypersteel_ingot 4")) + inv:remove_item("src", ItemStack("wool:blue 2")) + inv:remove_item("src", ItemStack("default:glass 2")) + meta:set_int("busy", 0) +end + +local function add_inventory_items(inv) + inv:add_item("src", ItemStack("hyperloop:pod_wall 30")) + inv:add_item("src", ItemStack("hyperloop:hypersteel_ingot 4")) + inv:add_item("src", ItemStack("wool:blue 2")) + inv:add_item("src", ItemStack("default:glass 2")) +end + +local function build_station(pos, placer) + -- check protection + if minetest.is_protected(pos, placer:get_player_name()) then + return + end + local meta = M(pos) + local inv = meta:get_inventory() + local facedir = hyperloop.get_facedir(placer) + -- do a facedir correction + facedir = (facedir + 3) % 4 -- face to LCD + if check_inventory(inv, placer) then + Stations:update(pos, {facedir = facedir}) + + if check_space(table.copy(pos), facedir, placer) then + construct(1, table.copy(pos), facedir, placer:get_player_name(), SP(pos)) + meta:set_string("formspec", station_formspec .. + "button_exit[0,3.9;3,1;destroy;"..S("Destroy Station").."]") + meta:set_int("built", 1) + meta:set_int("busy", 1) + -- remove items aften the station is build + minetest.after(20, remove_inventory_items, inv, meta) + end + end +end + +local function on_destruct(pos) + Stations:update(pos, { + booking_pos = "nil", + booking_info = "nil", + name = "Station", + }) +end + +local function destroy_station(pos, player_name) + -- check protection + if minetest.is_protected(pos, player_name) then + return + end + + local station = Stations:get(pos) + if station then + -- remove nodes + local _pos = table.copy(pos) + for _,item in ipairs(AssemblyPlan) do + local y, path, node_name = item[1], item[2], item[4] + _pos = hyperloop.new_pos(_pos, station.facedir, path, y) + minetest.remove_node(_pos) + end + on_destruct(pos) + -- maintain meta + local meta = M(pos) + meta:set_string("formspec", station_formspec .. + "button_exit[0,3.9;3,1;build;"..S("Build Station").."]") + local inv = meta:get_inventory() + add_inventory_items(inv) + meta:set_int("built", 0) + else + M(pos):set_int("built", 0) + end +end + +minetest.register_node("hyperloop:station", { + description = S("Hyperloop Station Block"), + drawtype = "nodebox", + tiles = { + "hyperloop_station.png", + "hyperloop_station_connection.png", + "hyperloop_station_connection.png", + }, + + on_construct = function(pos) + local meta = M(pos) + meta:set_string("formspec", station_formspec .. + "button_exit[0,3.9;3,1;build;"..S("Build Station").."]") + local inv = meta:get_inventory() + inv:set_size('src', 4) + end, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + hyperloop.check_network_level(pos, placer) + M(pos):set_string("infotext", S("Station")) + store_station(pos, placer) + Tube:after_place_node(pos) + end, + + allow_metadata_inventory_put = allow_metadata_inventory, + allow_metadata_inventory_take = allow_metadata_inventory, + + on_receive_fields = function(pos, formname, fields, player) + if fields.destroy ~= nil then + destroy_station(pos, player:get_player_name()) + elseif fields.build ~= nil then + build_station(pos, player) + end + end, + + on_dig = function(pos, node, puncher, pointed_thing) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if inv:is_empty("src") and meta:get_int("built") ~= 1 then + minetest.node_dig(pos, node, puncher, pointed_thing) + end + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_node(pos) + Stations:delete(pos) + end, + + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + groups = {cracky = 1}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:pod_wall", { + description = S("Hyperloop Pod Shell"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin.png", + }, + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + groups = {cracky=2}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:pod_wall_ni", { + description = S("Hyperloop Pod Shell"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin2.png", + "hyperloop_skin2.png", + "hyperloop_skin.png", + }, + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + groups = {cracky=2, not_in_creative_inventory=1}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + drop = "", +}) + +minetest.register_node("hyperloop:pod_floor", { + description = S("Hyperloop Pod Shell"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_skin2.png", + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, -7.5/16, 8/16}, + }, + }, + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + groups = {cracky=2, not_in_creative_inventory=1}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + drop = "", +}) diff --git a/hyperloop/textures/_0.png b/hyperloop/textures/_0.png new file mode 100644 index 0000000..31c16b0 Binary files /dev/null and b/hyperloop/textures/_0.png differ diff --git a/hyperloop/textures/_1.png b/hyperloop/textures/_1.png new file mode 100644 index 0000000..21723cc Binary files /dev/null and b/hyperloop/textures/_1.png differ diff --git a/hyperloop/textures/_2.png b/hyperloop/textures/_2.png new file mode 100644 index 0000000..08fa263 Binary files /dev/null and b/hyperloop/textures/_2.png differ diff --git a/hyperloop/textures/_3.png b/hyperloop/textures/_3.png new file mode 100644 index 0000000..c724fe5 Binary files /dev/null and b/hyperloop/textures/_3.png differ diff --git a/hyperloop/textures/_4.png b/hyperloop/textures/_4.png new file mode 100644 index 0000000..a3624a9 Binary files /dev/null and b/hyperloop/textures/_4.png differ diff --git a/hyperloop/textures/_5.png b/hyperloop/textures/_5.png new file mode 100644 index 0000000..054f1b1 Binary files /dev/null and b/hyperloop/textures/_5.png differ diff --git a/hyperloop/textures/_6.png b/hyperloop/textures/_6.png new file mode 100644 index 0000000..ab0b63e Binary files /dev/null and b/hyperloop/textures/_6.png differ diff --git a/hyperloop/textures/_7.png b/hyperloop/textures/_7.png new file mode 100644 index 0000000..a4257d7 Binary files /dev/null and b/hyperloop/textures/_7.png differ diff --git a/hyperloop/textures/_8.png b/hyperloop/textures/_8.png new file mode 100644 index 0000000..a2f5982 Binary files /dev/null and b/hyperloop/textures/_8.png differ diff --git a/hyperloop/textures/_9.png b/hyperloop/textures/_9.png new file mode 100644 index 0000000..213a4af Binary files /dev/null and b/hyperloop/textures/_9.png differ diff --git a/hyperloop/textures/_a.png b/hyperloop/textures/_a.png new file mode 100644 index 0000000..3eede21 Binary files /dev/null and b/hyperloop/textures/_a.png differ diff --git a/hyperloop/textures/_a_.png b/hyperloop/textures/_a_.png new file mode 100644 index 0000000..7d1c074 Binary files /dev/null and b/hyperloop/textures/_a_.png differ diff --git a/hyperloop/textures/_b.png b/hyperloop/textures/_b.png new file mode 100644 index 0000000..f95dbdb Binary files /dev/null and b/hyperloop/textures/_b.png differ diff --git a/hyperloop/textures/_b_.png b/hyperloop/textures/_b_.png new file mode 100644 index 0000000..0c2641b Binary files /dev/null and b/hyperloop/textures/_b_.png differ diff --git a/hyperloop/textures/_bl.png b/hyperloop/textures/_bl.png new file mode 100644 index 0000000..3a0d5e5 Binary files /dev/null and b/hyperloop/textures/_bl.png differ diff --git a/hyperloop/textures/_br.png b/hyperloop/textures/_br.png new file mode 100644 index 0000000..48a6f30 Binary files /dev/null and b/hyperloop/textures/_br.png differ diff --git a/hyperloop/textures/_c.png b/hyperloop/textures/_c.png new file mode 100644 index 0000000..d871030 Binary files /dev/null and b/hyperloop/textures/_c.png differ diff --git a/hyperloop/textures/_c_.png b/hyperloop/textures/_c_.png new file mode 100644 index 0000000..ce5ee19 Binary files /dev/null and b/hyperloop/textures/_c_.png differ diff --git a/hyperloop/textures/_ca.png b/hyperloop/textures/_ca.png new file mode 100644 index 0000000..160b6a3 Binary files /dev/null and b/hyperloop/textures/_ca.png differ diff --git a/hyperloop/textures/_cl.png b/hyperloop/textures/_cl.png new file mode 100644 index 0000000..800a001 Binary files /dev/null and b/hyperloop/textures/_cl.png differ diff --git a/hyperloop/textures/_cm.png b/hyperloop/textures/_cm.png new file mode 100644 index 0000000..c24088a Binary files /dev/null and b/hyperloop/textures/_cm.png differ diff --git a/hyperloop/textures/_co.png b/hyperloop/textures/_co.png new file mode 100644 index 0000000..b161819 Binary files /dev/null and b/hyperloop/textures/_co.png differ diff --git a/hyperloop/textures/_cr.png b/hyperloop/textures/_cr.png new file mode 100644 index 0000000..caa52c8 Binary files /dev/null and b/hyperloop/textures/_cr.png differ diff --git a/hyperloop/textures/_d.png b/hyperloop/textures/_d.png new file mode 100644 index 0000000..43703b2 Binary files /dev/null and b/hyperloop/textures/_d.png differ diff --git a/hyperloop/textures/_d_.png b/hyperloop/textures/_d_.png new file mode 100644 index 0000000..005a7c6 Binary files /dev/null and b/hyperloop/textures/_d_.png differ diff --git a/hyperloop/textures/_dl.png b/hyperloop/textures/_dl.png new file mode 100644 index 0000000..d56a153 Binary files /dev/null and b/hyperloop/textures/_dl.png differ diff --git a/hyperloop/textures/_dt.png b/hyperloop/textures/_dt.png new file mode 100644 index 0000000..90d4eb9 Binary files /dev/null and b/hyperloop/textures/_dt.png differ diff --git a/hyperloop/textures/_dv.png b/hyperloop/textures/_dv.png new file mode 100644 index 0000000..a8e083b Binary files /dev/null and b/hyperloop/textures/_dv.png differ diff --git a/hyperloop/textures/_e.png b/hyperloop/textures/_e.png new file mode 100644 index 0000000..f77eefe Binary files /dev/null and b/hyperloop/textures/_e.png differ diff --git a/hyperloop/textures/_e_.png b/hyperloop/textures/_e_.png new file mode 100644 index 0000000..f9fd71e Binary files /dev/null and b/hyperloop/textures/_e_.png differ diff --git a/hyperloop/textures/_eq.png b/hyperloop/textures/_eq.png new file mode 100644 index 0000000..6a79076 Binary files /dev/null and b/hyperloop/textures/_eq.png differ diff --git a/hyperloop/textures/_ex.png b/hyperloop/textures/_ex.png new file mode 100644 index 0000000..974ce9b Binary files /dev/null and b/hyperloop/textures/_ex.png differ diff --git a/hyperloop/textures/_f.png b/hyperloop/textures/_f.png new file mode 100644 index 0000000..a9a07cf Binary files /dev/null and b/hyperloop/textures/_f.png differ diff --git a/hyperloop/textures/_f_.png b/hyperloop/textures/_f_.png new file mode 100644 index 0000000..039bd60 Binary files /dev/null and b/hyperloop/textures/_f_.png differ diff --git a/hyperloop/textures/_g.png b/hyperloop/textures/_g.png new file mode 100644 index 0000000..97dc09e Binary files /dev/null and b/hyperloop/textures/_g.png differ diff --git a/hyperloop/textures/_g_.png b/hyperloop/textures/_g_.png new file mode 100644 index 0000000..528f025 Binary files /dev/null and b/hyperloop/textures/_g_.png differ diff --git a/hyperloop/textures/_gt.png b/hyperloop/textures/_gt.png new file mode 100644 index 0000000..a21fa85 Binary files /dev/null and b/hyperloop/textures/_gt.png differ diff --git a/hyperloop/textures/_h.png b/hyperloop/textures/_h.png new file mode 100644 index 0000000..6fd2495 Binary files /dev/null and b/hyperloop/textures/_h.png differ diff --git a/hyperloop/textures/_h_.png b/hyperloop/textures/_h_.png new file mode 100644 index 0000000..1a35c89 Binary files /dev/null and b/hyperloop/textures/_h_.png differ diff --git a/hyperloop/textures/_ha.png b/hyperloop/textures/_ha.png new file mode 100644 index 0000000..63653f9 Binary files /dev/null and b/hyperloop/textures/_ha.png differ diff --git a/hyperloop/textures/_hs.png b/hyperloop/textures/_hs.png new file mode 100644 index 0000000..0315a47 Binary files /dev/null and b/hyperloop/textures/_hs.png differ diff --git a/hyperloop/textures/_i.png b/hyperloop/textures/_i.png new file mode 100644 index 0000000..7465837 Binary files /dev/null and b/hyperloop/textures/_i.png differ diff --git a/hyperloop/textures/_i_.png b/hyperloop/textures/_i_.png new file mode 100644 index 0000000..aff4137 Binary files /dev/null and b/hyperloop/textures/_i_.png differ diff --git a/hyperloop/textures/_j.png b/hyperloop/textures/_j.png new file mode 100644 index 0000000..8b87245 Binary files /dev/null and b/hyperloop/textures/_j.png differ diff --git a/hyperloop/textures/_j_.png b/hyperloop/textures/_j_.png new file mode 100644 index 0000000..bc9101d Binary files /dev/null and b/hyperloop/textures/_j_.png differ diff --git a/hyperloop/textures/_k.png b/hyperloop/textures/_k.png new file mode 100644 index 0000000..9af9adf Binary files /dev/null and b/hyperloop/textures/_k.png differ diff --git a/hyperloop/textures/_k_.png b/hyperloop/textures/_k_.png new file mode 100644 index 0000000..b558f7e Binary files /dev/null and b/hyperloop/textures/_k_.png differ diff --git a/hyperloop/textures/_l.png b/hyperloop/textures/_l.png new file mode 100644 index 0000000..a77d2af Binary files /dev/null and b/hyperloop/textures/_l.png differ diff --git a/hyperloop/textures/_l_.png b/hyperloop/textures/_l_.png new file mode 100644 index 0000000..1db4568 Binary files /dev/null and b/hyperloop/textures/_l_.png differ diff --git a/hyperloop/textures/_lt.png b/hyperloop/textures/_lt.png new file mode 100644 index 0000000..5e54647 Binary files /dev/null and b/hyperloop/textures/_lt.png differ diff --git a/hyperloop/textures/_m.png b/hyperloop/textures/_m.png new file mode 100644 index 0000000..68f5d64 Binary files /dev/null and b/hyperloop/textures/_m.png differ diff --git a/hyperloop/textures/_m_.png b/hyperloop/textures/_m_.png new file mode 100644 index 0000000..2f180e5 Binary files /dev/null and b/hyperloop/textures/_m_.png differ diff --git a/hyperloop/textures/_mn.png b/hyperloop/textures/_mn.png new file mode 100644 index 0000000..571f122 Binary files /dev/null and b/hyperloop/textures/_mn.png differ diff --git a/hyperloop/textures/_n.png b/hyperloop/textures/_n.png new file mode 100644 index 0000000..586bd58 Binary files /dev/null and b/hyperloop/textures/_n.png differ diff --git a/hyperloop/textures/_n_.png b/hyperloop/textures/_n_.png new file mode 100644 index 0000000..4025d51 Binary files /dev/null and b/hyperloop/textures/_n_.png differ diff --git a/hyperloop/textures/_o.png b/hyperloop/textures/_o.png new file mode 100644 index 0000000..b82be61 Binary files /dev/null and b/hyperloop/textures/_o.png differ diff --git a/hyperloop/textures/_o_.png b/hyperloop/textures/_o_.png new file mode 100644 index 0000000..a70f312 Binary files /dev/null and b/hyperloop/textures/_o_.png differ diff --git a/hyperloop/textures/_p.png b/hyperloop/textures/_p.png new file mode 100644 index 0000000..a3bae2d Binary files /dev/null and b/hyperloop/textures/_p.png differ diff --git a/hyperloop/textures/_p_.png b/hyperloop/textures/_p_.png new file mode 100644 index 0000000..cd4324d Binary files /dev/null and b/hyperloop/textures/_p_.png differ diff --git a/hyperloop/textures/_pr.png b/hyperloop/textures/_pr.png new file mode 100644 index 0000000..506ea69 Binary files /dev/null and b/hyperloop/textures/_pr.png differ diff --git a/hyperloop/textures/_ps.png b/hyperloop/textures/_ps.png new file mode 100644 index 0000000..905d76c Binary files /dev/null and b/hyperloop/textures/_ps.png differ diff --git a/hyperloop/textures/_q.png b/hyperloop/textures/_q.png new file mode 100644 index 0000000..7b0c8fd Binary files /dev/null and b/hyperloop/textures/_q.png differ diff --git a/hyperloop/textures/_q_.png b/hyperloop/textures/_q_.png new file mode 100644 index 0000000..8eb0113 Binary files /dev/null and b/hyperloop/textures/_q_.png differ diff --git a/hyperloop/textures/_qo.png b/hyperloop/textures/_qo.png new file mode 100644 index 0000000..b0a7ccb Binary files /dev/null and b/hyperloop/textures/_qo.png differ diff --git a/hyperloop/textures/_qu.png b/hyperloop/textures/_qu.png new file mode 100644 index 0000000..4d7e039 Binary files /dev/null and b/hyperloop/textures/_qu.png differ diff --git a/hyperloop/textures/_r.png b/hyperloop/textures/_r.png new file mode 100644 index 0000000..9649f95 Binary files /dev/null and b/hyperloop/textures/_r.png differ diff --git a/hyperloop/textures/_r_.png b/hyperloop/textures/_r_.png new file mode 100644 index 0000000..6425171 Binary files /dev/null and b/hyperloop/textures/_r_.png differ diff --git a/hyperloop/textures/_re.png b/hyperloop/textures/_re.png new file mode 100644 index 0000000..c8cd367 Binary files /dev/null and b/hyperloop/textures/_re.png differ diff --git a/hyperloop/textures/_s.png b/hyperloop/textures/_s.png new file mode 100644 index 0000000..0a3058e Binary files /dev/null and b/hyperloop/textures/_s.png differ diff --git a/hyperloop/textures/_s_.png b/hyperloop/textures/_s_.png new file mode 100644 index 0000000..10e9ef6 Binary files /dev/null and b/hyperloop/textures/_s_.png differ diff --git a/hyperloop/textures/_sl.png b/hyperloop/textures/_sl.png new file mode 100644 index 0000000..70f2b85 Binary files /dev/null and b/hyperloop/textures/_sl.png differ diff --git a/hyperloop/textures/_sm.png b/hyperloop/textures/_sm.png new file mode 100644 index 0000000..ce3297b Binary files /dev/null and b/hyperloop/textures/_sm.png differ diff --git a/hyperloop/textures/_sp.png b/hyperloop/textures/_sp.png new file mode 100644 index 0000000..ec2263a Binary files /dev/null and b/hyperloop/textures/_sp.png differ diff --git a/hyperloop/textures/_sr.png b/hyperloop/textures/_sr.png new file mode 100644 index 0000000..04a39d8 Binary files /dev/null and b/hyperloop/textures/_sr.png differ diff --git a/hyperloop/textures/_t.png b/hyperloop/textures/_t.png new file mode 100644 index 0000000..fbf688f Binary files /dev/null and b/hyperloop/textures/_t.png differ diff --git a/hyperloop/textures/_t_.png b/hyperloop/textures/_t_.png new file mode 100644 index 0000000..aa71d72 Binary files /dev/null and b/hyperloop/textures/_t_.png differ diff --git a/hyperloop/textures/_tl.png b/hyperloop/textures/_tl.png new file mode 100644 index 0000000..b88cf8a Binary files /dev/null and b/hyperloop/textures/_tl.png differ diff --git a/hyperloop/textures/_u.png b/hyperloop/textures/_u.png new file mode 100644 index 0000000..a0e3063 Binary files /dev/null and b/hyperloop/textures/_u.png differ diff --git a/hyperloop/textures/_u_.png b/hyperloop/textures/_u_.png new file mode 100644 index 0000000..161d37c Binary files /dev/null and b/hyperloop/textures/_u_.png differ diff --git a/hyperloop/textures/_un.png b/hyperloop/textures/_un.png new file mode 100644 index 0000000..b127ab2 Binary files /dev/null and b/hyperloop/textures/_un.png differ diff --git a/hyperloop/textures/_v.png b/hyperloop/textures/_v.png new file mode 100644 index 0000000..503c923 Binary files /dev/null and b/hyperloop/textures/_v.png differ diff --git a/hyperloop/textures/_v_.png b/hyperloop/textures/_v_.png new file mode 100644 index 0000000..0f2e724 Binary files /dev/null and b/hyperloop/textures/_v_.png differ diff --git a/hyperloop/textures/_vb.png b/hyperloop/textures/_vb.png new file mode 100644 index 0000000..285c08c Binary files /dev/null and b/hyperloop/textures/_vb.png differ diff --git a/hyperloop/textures/_w.png b/hyperloop/textures/_w.png new file mode 100644 index 0000000..db469b1 Binary files /dev/null and b/hyperloop/textures/_w.png differ diff --git a/hyperloop/textures/_w_.png b/hyperloop/textures/_w_.png new file mode 100644 index 0000000..47506b1 Binary files /dev/null and b/hyperloop/textures/_w_.png differ diff --git a/hyperloop/textures/_x.png b/hyperloop/textures/_x.png new file mode 100644 index 0000000..fc81f7f Binary files /dev/null and b/hyperloop/textures/_x.png differ diff --git a/hyperloop/textures/_x_.png b/hyperloop/textures/_x_.png new file mode 100644 index 0000000..3378982 Binary files /dev/null and b/hyperloop/textures/_x_.png differ diff --git a/hyperloop/textures/_y.png b/hyperloop/textures/_y.png new file mode 100644 index 0000000..d0fad75 Binary files /dev/null and b/hyperloop/textures/_y.png differ diff --git a/hyperloop/textures/_y_.png b/hyperloop/textures/_y_.png new file mode 100644 index 0000000..0bc5bb9 Binary files /dev/null and b/hyperloop/textures/_y_.png differ diff --git a/hyperloop/textures/_z.png b/hyperloop/textures/_z.png new file mode 100644 index 0000000..c66b0fd Binary files /dev/null and b/hyperloop/textures/_z.png differ diff --git a/hyperloop/textures/_z_.png b/hyperloop/textures/_z_.png new file mode 100644 index 0000000..3cfb1ff Binary files /dev/null and b/hyperloop/textures/_z_.png differ diff --git a/hyperloop/textures/hyperloop_agyptL.png b/hyperloop/textures/hyperloop_agyptL.png new file mode 100644 index 0000000..9bb3fa7 Binary files /dev/null and b/hyperloop/textures/hyperloop_agyptL.png differ diff --git a/hyperloop/textures/hyperloop_agyptR.png b/hyperloop/textures/hyperloop_agyptR.png new file mode 100644 index 0000000..4185c12 Binary files /dev/null and b/hyperloop/textures/hyperloop_agyptR.png differ diff --git a/hyperloop/textures/hyperloop_alpsL.png b/hyperloop/textures/hyperloop_alpsL.png new file mode 100644 index 0000000..7b5952a Binary files /dev/null and b/hyperloop/textures/hyperloop_alpsL.png differ diff --git a/hyperloop/textures/hyperloop_alpsR.png b/hyperloop/textures/hyperloop_alpsR.png new file mode 100644 index 0000000..2f1257c Binary files /dev/null and b/hyperloop/textures/hyperloop_alpsR.png differ diff --git a/hyperloop/textures/hyperloop_booking.png b/hyperloop/textures/hyperloop_booking.png new file mode 100644 index 0000000..7b7eb9d Binary files /dev/null and b/hyperloop/textures/hyperloop_booking.png differ diff --git a/hyperloop/textures/hyperloop_booking_front.png b/hyperloop/textures/hyperloop_booking_front.png new file mode 100644 index 0000000..87b29f5 Binary files /dev/null and b/hyperloop/textures/hyperloop_booking_front.png differ diff --git a/hyperloop/textures/hyperloop_door1IN.png b/hyperloop/textures/hyperloop_door1IN.png new file mode 100644 index 0000000..90dffca Binary files /dev/null and b/hyperloop/textures/hyperloop_door1IN.png differ diff --git a/hyperloop/textures/hyperloop_door1OUT.png b/hyperloop/textures/hyperloop_door1OUT.png new file mode 100644 index 0000000..4d265f1 Binary files /dev/null and b/hyperloop/textures/hyperloop_door1OUT.png differ diff --git a/hyperloop/textures/hyperloop_door2IN.png b/hyperloop/textures/hyperloop_door2IN.png new file mode 100644 index 0000000..0489150 Binary files /dev/null and b/hyperloop/textures/hyperloop_door2IN.png differ diff --git a/hyperloop/textures/hyperloop_door2OUT.png b/hyperloop/textures/hyperloop_door2OUT.png new file mode 100644 index 0000000..7906051 Binary files /dev/null and b/hyperloop/textures/hyperloop_door2OUT.png differ diff --git a/hyperloop/textures/hyperloop_elevator.png b/hyperloop/textures/hyperloop_elevator.png new file mode 100644 index 0000000..07c32bc Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator.png differ diff --git a/hyperloop/textures/hyperloop_elevator_bottom.png b/hyperloop/textures/hyperloop_elevator_bottom.png new file mode 100644 index 0000000..9375560 Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_bottom.png differ diff --git a/hyperloop/textures/hyperloop_elevator_dark.png b/hyperloop/textures/hyperloop_elevator_dark.png new file mode 100644 index 0000000..a5dc86a Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_dark.png differ diff --git a/hyperloop/textures/hyperloop_elevator_dark_top.png b/hyperloop/textures/hyperloop_elevator_dark_top.png new file mode 100644 index 0000000..204d007 Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_dark_top.png differ diff --git a/hyperloop/textures/hyperloop_elevator_door.png b/hyperloop/textures/hyperloop_elevator_door.png new file mode 100644 index 0000000..33218e9 Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_door.png differ diff --git a/hyperloop/textures/hyperloop_elevator_door_top.png b/hyperloop/textures/hyperloop_elevator_door_top.png new file mode 100644 index 0000000..b6be8d7 Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_door_top.png differ diff --git a/hyperloop/textures/hyperloop_elevator_inventory.png b/hyperloop/textures/hyperloop_elevator_inventory.png new file mode 100644 index 0000000..c2c6b80 Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_inventory.png differ diff --git a/hyperloop/textures/hyperloop_elevator_top.png b/hyperloop/textures/hyperloop_elevator_top.png new file mode 100644 index 0000000..eed7dab Binary files /dev/null and b/hyperloop/textures/hyperloop_elevator_top.png differ diff --git a/hyperloop/textures/hyperloop_elogo.png b/hyperloop/textures/hyperloop_elogo.png new file mode 100644 index 0000000..b0d1129 Binary files /dev/null and b/hyperloop/textures/hyperloop_elogo.png differ diff --git a/hyperloop/textures/hyperloop_hypersteel_ingot.png b/hyperloop/textures/hyperloop_hypersteel_ingot.png new file mode 100644 index 0000000..2997dea Binary files /dev/null and b/hyperloop/textures/hyperloop_hypersteel_ingot.png differ diff --git a/hyperloop/textures/hyperloop_junction_top.png b/hyperloop/textures/hyperloop_junction_top.png new file mode 100644 index 0000000..b3857a9 Binary files /dev/null and b/hyperloop/textures/hyperloop_junction_top.png differ diff --git a/hyperloop/textures/hyperloop_lcd.png b/hyperloop/textures/hyperloop_lcd.png new file mode 100644 index 0000000..4eb8337 Binary files /dev/null and b/hyperloop/textures/hyperloop_lcd.png differ diff --git a/hyperloop/textures/hyperloop_logo.png b/hyperloop/textures/hyperloop_logo.png new file mode 100644 index 0000000..4889845 Binary files /dev/null and b/hyperloop/textures/hyperloop_logo.png differ diff --git a/hyperloop/textures/hyperloop_seaL.png b/hyperloop/textures/hyperloop_seaL.png new file mode 100644 index 0000000..f70dca9 Binary files /dev/null and b/hyperloop/textures/hyperloop_seaL.png differ diff --git a/hyperloop/textures/hyperloop_seaR.png b/hyperloop/textures/hyperloop_seaR.png new file mode 100644 index 0000000..39bf0d7 Binary files /dev/null and b/hyperloop/textures/hyperloop_seaR.png differ diff --git a/hyperloop/textures/hyperloop_seat-side.png b/hyperloop/textures/hyperloop_seat-side.png new file mode 100644 index 0000000..56dc730 Binary files /dev/null and b/hyperloop/textures/hyperloop_seat-side.png differ diff --git a/hyperloop/textures/hyperloop_seat-top.png b/hyperloop/textures/hyperloop_seat-top.png new file mode 100644 index 0000000..b6bbb5c Binary files /dev/null and b/hyperloop/textures/hyperloop_seat-top.png differ diff --git a/hyperloop/textures/hyperloop_shaft_inv.png b/hyperloop/textures/hyperloop_shaft_inv.png new file mode 100644 index 0000000..29c3f0b Binary files /dev/null and b/hyperloop/textures/hyperloop_shaft_inv.png differ diff --git a/hyperloop/textures/hyperloop_sign.png b/hyperloop/textures/hyperloop_sign.png new file mode 100644 index 0000000..254f353 Binary files /dev/null and b/hyperloop/textures/hyperloop_sign.png differ diff --git a/hyperloop/textures/hyperloop_sign2.png b/hyperloop/textures/hyperloop_sign2.png new file mode 100644 index 0000000..02379f5 Binary files /dev/null and b/hyperloop/textures/hyperloop_sign2.png differ diff --git a/hyperloop/textures/hyperloop_sign2_ground.png b/hyperloop/textures/hyperloop_sign2_ground.png new file mode 100644 index 0000000..956532c Binary files /dev/null and b/hyperloop/textures/hyperloop_sign2_ground.png differ diff --git a/hyperloop/textures/hyperloop_sign3.png b/hyperloop/textures/hyperloop_sign3.png new file mode 100644 index 0000000..33e290b Binary files /dev/null and b/hyperloop/textures/hyperloop_sign3.png differ diff --git a/hyperloop/textures/hyperloop_sign_top.png b/hyperloop/textures/hyperloop_sign_top.png new file mode 100644 index 0000000..46776b4 Binary files /dev/null and b/hyperloop/textures/hyperloop_sign_top.png differ diff --git a/hyperloop/textures/hyperloop_skin.png b/hyperloop/textures/hyperloop_skin.png new file mode 100644 index 0000000..fbc1b4e Binary files /dev/null and b/hyperloop/textures/hyperloop_skin.png differ diff --git a/hyperloop/textures/hyperloop_skin2.png b/hyperloop/textures/hyperloop_skin2.png new file mode 100644 index 0000000..0cd1f41 Binary files /dev/null and b/hyperloop/textures/hyperloop_skin2.png differ diff --git a/hyperloop/textures/hyperloop_skin_door.png b/hyperloop/textures/hyperloop_skin_door.png new file mode 100644 index 0000000..b0a66f7 Binary files /dev/null and b/hyperloop/textures/hyperloop_skin_door.png differ diff --git a/hyperloop/textures/hyperloop_station.png b/hyperloop/textures/hyperloop_station.png new file mode 100644 index 0000000..af89f73 Binary files /dev/null and b/hyperloop/textures/hyperloop_station.png differ diff --git a/hyperloop/textures/hyperloop_station_connection.png b/hyperloop/textures/hyperloop_station_connection.png new file mode 100644 index 0000000..44bfe27 Binary files /dev/null and b/hyperloop/textures/hyperloop_station_connection.png differ diff --git a/hyperloop/textures/hyperloop_station_formspec.png b/hyperloop/textures/hyperloop_station_formspec.png new file mode 100644 index 0000000..8e6934c Binary files /dev/null and b/hyperloop/textures/hyperloop_station_formspec.png differ diff --git a/hyperloop/textures/hyperloop_stations_book.png b/hyperloop/textures/hyperloop_stations_book.png new file mode 100644 index 0000000..42c0dd1 Binary files /dev/null and b/hyperloop/textures/hyperloop_stations_book.png differ diff --git a/hyperloop/textures/hyperloop_tube.png b/hyperloop/textures/hyperloop_tube.png new file mode 100644 index 0000000..c3c1598 Binary files /dev/null and b/hyperloop/textures/hyperloop_tube.png differ diff --git a/hyperloop/textures/hyperloop_tube_closed.png b/hyperloop/textures/hyperloop_tube_closed.png new file mode 100644 index 0000000..b4a93d6 Binary files /dev/null and b/hyperloop/textures/hyperloop_tube_closed.png differ diff --git a/hyperloop/textures/hyperloop_tube_locked.png b/hyperloop/textures/hyperloop_tube_locked.png new file mode 100644 index 0000000..40e780a Binary files /dev/null and b/hyperloop/textures/hyperloop_tube_locked.png differ diff --git a/hyperloop/textures/hyperloop_tube_open.png b/hyperloop/textures/hyperloop_tube_open.png new file mode 100644 index 0000000..0b50cc1 Binary files /dev/null and b/hyperloop/textures/hyperloop_tube_open.png differ diff --git a/hyperloop/textures/hyperloop_tube_open_active.png b/hyperloop/textures/hyperloop_tube_open_active.png new file mode 100644 index 0000000..7e7cda5 Binary files /dev/null and b/hyperloop/textures/hyperloop_tube_open_active.png differ diff --git a/hyperloop/textures/hyperloop_tube_wifi.png b/hyperloop/textures/hyperloop_tube_wifi.png new file mode 100644 index 0000000..d435fb8 Binary files /dev/null and b/hyperloop/textures/hyperloop_tube_wifi.png differ diff --git a/hyperloop/textures/hyperloop_tubecrowbar.png b/hyperloop/textures/hyperloop_tubecrowbar.png new file mode 100644 index 0000000..db94e8a Binary files /dev/null and b/hyperloop/textures/hyperloop_tubecrowbar.png differ diff --git a/hyperloop/textures/hyperloop_waypoint.png b/hyperloop/textures/hyperloop_waypoint.png new file mode 100644 index 0000000..6d8bf47 Binary files /dev/null and b/hyperloop/textures/hyperloop_waypoint.png differ diff --git a/hyperloop/textures/hyperloop_waypoint_inv.png b/hyperloop/textures/hyperloop_waypoint_inv.png new file mode 100644 index 0000000..153730e Binary files /dev/null and b/hyperloop/textures/hyperloop_waypoint_inv.png differ diff --git a/hyperloop/tube.lua b/hyperloop/tube.lua new file mode 100644 index 0000000..94e2f43 --- /dev/null +++ b/hyperloop/tube.lua @@ -0,0 +1,286 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local function station_name(pos) + local dataSet = hyperloop.get_station(pos) + if dataSet then + if dataSet.junction == true then + return S("Junction at ")..SP(pos) + elseif dataSet.name ~= nil then + return S("Station '")..dataSet.name.."' at "..SP(pos) + else + return S("Station at ")..SP(pos) + end + end + return S("Open end at ")..minetest.pos_to_string(pos) +end + +function hyperloop.check_network_level(pos, player) + if hyperloop.free_tube_placement_enabled then + return + end + for key,_ in pairs(hyperloop.Stations.tStations) do + if pos.y == P(key).y then + return + end + end + hyperloop.chat(player, S("There is no station/junction on this level. ").. + S("Do you really want to start a new network?!")) +end + +-- North, East, South, West, Down, Up +local dirs_to_check = {1,2,3,4} -- horizontal only +if hyperloop.free_tube_placement_enabled then + dirs_to_check = {1,2,3,4,5,6} -- all directions +end + +local Tube = tubelib2.Tube:new({ + dirs_to_check = dirs_to_check, + max_tube_length = 1000, + show_infotext = true, + primary_node_names = {"hyperloop:tubeS", "hyperloop:tubeS2", "hyperloop:tubeA", "hyperloop:tubeA2"}, + secondary_node_names = {"hyperloop:junction", "hyperloop:station", "hyperloop:tube_wifi1"}, + after_place_tube = function(pos, param2, tube_type, num_tubes) + if num_tubes == 2 then + minetest.set_node(pos, {name = "hyperloop:tube"..tube_type.."2", param2 = param2}) + else + minetest.set_node(pos, {name = "hyperloop:tube"..tube_type, param2 = param2}) + end + end, +}) + +hyperloop.Tube = Tube + +minetest.register_node("hyperloop:tubeS", { + description = S("Hyperloop Tube"), + inventory_image = minetest.inventorycube("hyperloop_tube_locked.png", + 'hyperloop_tube_open.png', "hyperloop_tube_locked.png"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_closed.png^[transformR90]", + "hyperloop_tube_closed.png^[transformR90]", + 'hyperloop_tube_closed.png', + 'hyperloop_tube_closed.png', + { + image = 'hyperloop_tube_open_active.png', + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.5, + }, + }, + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + if not Tube:after_place_tube(pos, placer, pointed_thing) then + minetest.remove_node(pos) + return true + end + return false + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_tube(pos, oldnode, oldmetadata) + end, + + paramtype2 = "facedir", -- important! + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky = 1}, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:tubeS2", { + description = "Hyperloop Tube", + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^hyperloop_logo.png^[transformR90]", + "hyperloop_tube_locked.png^hyperloop_logo.png^[transformR90]", + 'hyperloop_tube_locked.png^hyperloop_logo.png', + 'hyperloop_tube_locked.png^hyperloop_logo.png', + { + image = 'hyperloop_tube_open_active.png', + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.5, + }, + }, + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16}, + {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_tube(pos, oldnode, oldmetadata) + end, + + paramtype2 = "facedir", -- important! + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + diggable = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:tubeA", { + description = S("Hyperloop Tube"), + inventory_image = minetest.inventorycube("hyperloop_tube_locked.png", + 'hyperloop_tube_open.png', "hyperloop_tube_locked.png"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_closed.png^[transformR90]", + { + image = 'hyperloop_tube_open_active.png', + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.5, + }, + }, + 'hyperloop_tube_closed.png', + 'hyperloop_tube_closed.png', + "hyperloop_tube_closed.png^[transformR90]", + { + image = 'hyperloop_tube_open_active.png', + backface_culling = false, + animation = { + type = "vertical_frames", + aspect_w = 32, + aspect_h = 32, + length = 0.5, + }, + }, + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, -7/16, 8/16, 8/16}, + { 7/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, 7/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, 7/16, 8/16, 8/16, 8/16}, + {-8/16, -8/16, -8/16, 8/16, -7/16, -7/16}, + {-7/16, -7/16, -7/16, 7/16, 7/16, 7/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_tube(pos, oldnode, oldmetadata) + end, + + paramtype2 = "facedir", -- important! + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + drop = "hyperloop:tubeS", + sounds = default.node_sound_metal_defaults(), +}) + +minetest.register_node("hyperloop:tubeA2", { + description = "Hyperloop Tube", + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^hyperloop_logo.png^[transformR90]", + "hyperloop_tube_locked.png^hyperloop_logo.png^[transformR90]", + "hyperloop_tube_locked.png^hyperloop_logo.png", + "hyperloop_tube_locked.png^hyperloop_logo.png", + "hyperloop_tube_locked.png^hyperloop_logo.png", + "hyperloop_tube_locked.png^hyperloop_logo.png", + }, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:after_dig_tube(pos, oldnode, oldmetadata) + end, + + paramtype2 = "facedir", -- important! + on_rotate = screwdriver.disallow, -- important! + paramtype = "light", + light_source = 2, + sunlight_propagates = true, + is_ground_content = false, + diggable = false, + groups = {cracky = 1, not_in_creative_inventory=1}, + sounds = default.node_sound_metal_defaults(), +}) + + +-- for tube viaducts +minetest.register_node("hyperloop:pillar", { + description = "Hyperloop Pillar", + tiles = {"hyperloop_tube_locked.png^[transformR90]"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -3/8, -4/8, -3/8, 3/8, 4/8, 3/8}, + }, + }, + is_ground_content = false, + groups = {cracky = 2, stone = 2}, + sounds = default.node_sound_metal_defaults(), +}) diff --git a/hyperloop/tubecrowbar.lua b/hyperloop/tubecrowbar.lua new file mode 100644 index 0000000..4e9f1ee --- /dev/null +++ b/hyperloop/tubecrowbar.lua @@ -0,0 +1,128 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Shaft = hyperloop.Shaft +local Tube = hyperloop.Tube + + +local function chat_message(dir, cnt, peer_pos, peer_dir) + local sdir = tubelib2.dir_to_string(dir) + if Shaft:is_secondary_node(peer_pos, peer_dir) then + local npos, node = Shaft:get_node(peer_pos, peer_dir) + return "[Hyperloop] To the "..sdir..": "..cnt.." tube nodes to "..node.name.." at "..SP(npos) + else + return "[Hyperloop] To the "..sdir..": "..cnt.." tube nodes to "..SP(peer_pos) + end +end + +local function repair_tubes(itemstack, placer, pointed_thing) + if pointed_thing.type == "node" then + local pos = pointed_thing.under + local dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 = + Shaft:tool_repair_tube(pos, placer, pointed_thing) + if fpos1 and fpos2 then + minetest.chat_send_player(placer:get_player_name(), chat_message(dir1, cnt1, fpos1, fdir1)) + minetest.chat_send_player(placer:get_player_name(), chat_message(dir2, cnt2, fpos2, fdir2)) + minetest.sound_play({ + name="hyperloop_crowbar"},{ + pos = pos, + gain=2, + max_hear_distance=5, + loop=false}) + else + local dir1, dir2, fpos1, fpos2, fdir1, fdir2, cnt1, cnt2 = + Tube:tool_repair_tube(pos, placer, pointed_thing) + if fpos1 and fpos2 then + minetest.chat_send_player(placer:get_player_name(), chat_message(dir1, cnt1, fpos1, fdir1)) + minetest.chat_send_player(placer:get_player_name(), chat_message(dir2, cnt2, fpos2, fdir2)) + minetest.sound_play({ + name="hyperloop_crowbar"},{ + pos = pos, + gain=2, + max_hear_distance=5, + loop=false}) + end + end + else + minetest.chat_send_player(placer:get_player_name(), + S("[Crowbar Help]\n").. + S(" left: remove node\n").. + S(" right: repair tube/shaft line\n")) + end +end + +local function add_to_inventory(placer, item_name) + local inv = placer:get_inventory() + local item = ItemStack(item_name) + if inv and item and inv:room_for_item("main", item) then + inv:add_item("main", item) + end +end + +local function remove_tube(itemstack, placer, pointed_thing) + if minetest.check_player_privs(placer:get_player_name(), "hyperloop") then + if pointed_thing.type == "node" then + local pos = pointed_thing.under + if Shaft:tool_remove_tube(pos, "default_break_glass") then + add_to_inventory(placer, "hyperloop:shaft") + elseif Tube:tool_remove_tube(pos, "default_break_glass") then + add_to_inventory(placer, "hyperloop:tubeS") + end + end + else + minetest.chat_send_player(placer:get_player_name(), S("You don't have the necessary privs!")) + end +end + +local function dump_data_base(pos) + print(dump(hyperloop.tDatabase)) +end + +-- Tool for tube workers to crack a protected tube line +minetest.register_node("hyperloop:tube_crowbar", { + description = S("Hyperloop Tube Crowbar"), + inventory_image = "hyperloop_tubecrowbar.png", + wield_image = "hyperloop_tubecrowbar.png", + use_texture_alpha = true, + groups = {cracky=1, book=1}, + on_use = remove_tube, + on_place = repair_tubes, + on_secondary_use = repair_tubes, + node_placement_prediction = "", + stack_max = 1, +}) + +minetest.register_privilege("hyperloop", + {description = S("Rights to remove tube nodes by means of the crowbar"), + give_to_singleplayer = false}) + + +if(minetest.get_modpath("worldedit")) ~= nil then + minetest.register_chatcommand("hyperloop_repair_tubes", { + description = S("Repair via WorldEdit placed Hyperloop tubes by reusing WorldEdit pos1/pos2"), + privs = {worldedit=true}, + func = function(name, param) + local pos1 = worldedit.pos1[name] + local pos2 = worldedit.pos2[name] + Tube:replace_tube_line(pos1, pos2) + end, + }) +end diff --git a/hyperloop/utils.lua b/hyperloop/utils.lua new file mode 100644 index 0000000..486c535 --- /dev/null +++ b/hyperloop/utils.lua @@ -0,0 +1,111 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + Some common used helper functions +]]-- + +local PI = 3.1415926 + +-- for lazy programmers +local SP = function(pos) if pos then return minetest.pos_to_string(pos) end end +local P = minetest.string_to_pos +local M = minetest.get_meta + +local Stations = hyperloop.Stations + +function hyperloop.chat(player, text) + if type(player) == "string" then + minetest.chat_send_player(player, "[Hyperloop] "..text) + elseif player ~= nil then + minetest.chat_send_player(player:get_player_name(), "[Hyperloop] "..text) + end +end + +function hyperloop.get_facedir(placer) + local lookdir = placer:get_look_dir() + return core.dir_to_facedir(lookdir) +end + +function hyperloop.facedir_to_rad(facedir) + local tbl = {[0]=0, [1]=3, [2]=2, [3]=1} + return tbl[facedir] / 2 * PI +end + +-- Distance between two points in (tube) blocks +function hyperloop.distance(pos1, pos2) + return math.floor(math.abs(pos1.x - pos2.x) + + math.abs(pos1.y - pos2.y) + math.abs(pos1.z - pos2.z)) +end + +-- calculate the new pos based on the given pos, the players facedir, the y-offset +-- and the given walk path like "3F2L" (F-orward, L-eft, R-ight, B-ack). +function hyperloop.new_pos(pos, facedir, path, y_offs) + if facedir == nil or pos == nil or path == nil or y_offs == nil then + return pos + end + local _pos = table.copy(pos) + _pos.y = _pos.y + y_offs + while path:len() > 0 do + local num = tonumber(path:sub(1,1)) + local dir = path:sub(2,2) + path = path:sub(3) + if dir == "B" then + facedir = (facedir + 2) % 4 + elseif dir == "L" then + facedir = (facedir + 3) % 4 + elseif dir == "R" then + facedir = (facedir + 1) % 4 + end + dir = core.facedir_to_dir(facedir) + _pos = vector.add(_pos, vector.multiply(dir, num)) + end + return _pos +end + +function hyperloop.is_player_around(pos) + for _,obj in ipairs(minetest.get_objects_inside_radius(pos, 2)) do + if obj:is_player() then + return true + end + end + return false +end + +function hyperloop.get_connection_string(pos) + local item = Stations:get(pos) + if item then + local tbl = {} + for k,v in pairs(item.conn) do + tbl[#tbl+1] = v + end + return table.concat(tbl, " ") + end + return "" +end + +function hyperloop.get_station(station_pos) + local data = Stations:get(station_pos) + if data then + local tStation = table.copy(data) + tStation.pos = station_pos + return tStation + end +end +-- Return a copy of the station table including the station pos information +-- based on the given seat/booking/lcd position (the station position +-- is determined via meta "sStationPos"). +function hyperloop.get_base_station(pos) + local meta = M(pos) + local sStationPos = meta:get_string("sStationPos") + if sStationPos ~= "" then + local station_pos = P(sStationPos) + return hyperloop.get_station(station_pos), station_pos + end +end diff --git a/hyperloop/waypoint.lua b/hyperloop/waypoint.lua new file mode 100644 index 0000000..34a9dda --- /dev/null +++ b/hyperloop/waypoint.lua @@ -0,0 +1,68 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + History: + see init.lua + +]]-- + +local Waypoints = {} + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +minetest.register_node("hyperloop:waypoint", { + description = S("Hyperloop Waypoint"), + inventory_image = "hyperloop_waypoint_inv.png", + tiles = { + "hyperloop_waypoint.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + { -4/16, -8/16, -4/16, 4/16, -7/16, 4/16}, + }, + }, + + after_place_node = function(pos, placer) + local name = placer:get_player_name() + if Waypoints[name] then + placer:hud_remove(Waypoints[name]) + Waypoints[name] = nil + end + Waypoints[name] = placer:hud_add({ + hud_elem_type = "waypoint", + number = 0x99d8d9, + name = "Hyperloop", + text = "m", + world_pos = pos + }) + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + local name = digger:get_player_name() + if Waypoints[name] then + digger:hud_remove(Waypoints[name]) + Waypoints[name] = nil + end + end, + + on_rotate = screwdriver.disallow, + paramtype = "light", + light_source = minetest.LIGHT_MAX, + sunlight_propagates = true, + groups = {cracky=2, crumbly=2, choppy=2}, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + stack_max = 1, +}) diff --git a/hyperloop/wifi.lua b/hyperloop/wifi.lua new file mode 100644 index 0000000..9e55a9e --- /dev/null +++ b/hyperloop/wifi.lua @@ -0,0 +1,63 @@ +--[[ + + Hyperloop Mod + ============= + + Copyright (C) 2017-2019 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + +]]-- + +-- Load support for intllib. +local S = hyperloop.S +local NS = hyperloop.NS + +local Tube = hyperloop.Tube + +local sFormspec = "size[7.5,3]".. + "field[0.5,1;7,1;channel;"..S("Enter channel string")..";]" .. + "button_exit[2,2;3,1;exit;"..S("Save").."]" + +minetest.register_node("hyperloop:tube_wifi1", { + description = S("Hyperloop WiFi Tube"), + tiles = { + -- up, down, right, left, back, front + "hyperloop_tube_locked.png^[transformR90]", + "hyperloop_tube_locked.png^[transformR90]", + "hyperloop_tube_wifi.png", + }, + + after_place_node = function(pos, placer) + -- determine the tube side + local tube_dir = Tube:get_primary_dir(pos) + Tube:prepare_pairing(pos, tube_dir, sFormspec) + Tube:after_place_node(pos, {tube_dir}) + end, + + tubelib2_on_update = function(node, pos, out_dir, peer_pos, peer_in_dir) + Tube:prepare_pairing(pos, out_dir, sFormspec) + end, + + on_receive_fields = function(pos, formname, fields, player) + if fields.channel ~= nil then + Tube:pairing(pos, fields.channel) + end + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Tube:stop_pairing(pos, oldmetadata, sFormspec) + local tube_dir = tonumber(oldmetadata.fields.tube_dir or 0) + Tube:after_dig_node(pos, {tube_dir}) + end, + + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, + paramtype = "light", + groups = {cracky = 2}, + sunlight_propagates = true, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), +}) + diff --git a/lcdlib/LICENSE.txt b/lcdlib/LICENSE.txt new file mode 100644 index 0000000..341c30b --- /dev/null +++ b/lcdlib/LICENSE.txt @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + 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 that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU 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 as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + diff --git a/lcdlib/README.md b/lcdlib/README.md new file mode 100644 index 0000000..3f620e3 --- /dev/null +++ b/lcdlib/README.md @@ -0,0 +1,13 @@ +# LCD Lib + +This LCD Lib is based on Display Lib and Font Lib from Pierre-Yves Rollo + +**Dependancies**: default + +**License**: LGPL + +Code by Pierre-Yves Rollo (pyrollo) +Textures by Vanessa Ezekowitz (VanessaE). +(Default font taken from VanessaE's homedecor/signs_lib, originally under WTFPL) + + diff --git a/lcdlib/copyright.txt b/lcdlib/copyright.txt new file mode 100644 index 0000000..eb0ec6a --- /dev/null +++ b/lcdlib/copyright.txt @@ -0,0 +1,2 @@ +Code by Pierre-Yves Rollo (pyrollo) +Textures by Vanessa Ezekowitz (VanessaE) diff --git a/lcdlib/depends.txt b/lcdlib/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/lcdlib/display.lua b/lcdlib/display.lua new file mode 100644 index 0000000..de8689a --- /dev/null +++ b/lcdlib/display.lua @@ -0,0 +1,229 @@ +--[[ + cldlib based on: + + display_lib mod for Minetest - Library to add dynamic display + capabilities to nodes + (c) Pierre-Yves Rollo + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +--]] + +-- Miscelaneous values depending on wallmounted param2 +local wallmounted_values = { + [0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used + {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5}, + {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4}, + {dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2}, + {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3} +} + +-- Miscelaneous values depending on facedir param2 +local facedir_values = { + [0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1}, + {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2}, + {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}, + {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0}, + -- Forbiden values : + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, + } + +-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity, +-- rotate = next facedir/wallmount on rotate + +local function get_values(node) + local ndef = minetest.registered_nodes[node.name] + + if ndef then + if ndef.paramtype2 == "wallmounted" then + return wallmounted_values[node.param2] + end + if ndef.paramtype2 == "facedir" then + return facedir_values[node.param2] + end + end +end + +--- Gets the display entities attached with a node. Removes extra ones +local function get_entities(pos) + local objrefs = {} + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + if ndef and ndef.display_entities then + for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do + local entity = objref:get_luaentity() + if entity and ndef.display_entities[entity.name] then + if objrefs[entity.name] then + objref:remove() + else + objrefs[entity.name] = objref + end + end + end + end + return objrefs +end + +local function clip_pos_prop(posprop) + if posprop then + return math.max(-0.5, math.min(0.5, posprop)) + else + return 0 + end +end + +--- (Create and) place display entities according to the node orientation +local function place_entities(pos) + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local values = get_values(node) + local objrefs = get_entities(pos) + + if values and ndef and ndef.display_entities then + + for entity_name, props in pairs(ndef.display_entities) do + local depth = clip_pos_prop(props.depth) + local height = clip_pos_prop(props.height) + local right = clip_pos_prop(props.right) + if not objrefs[entity_name] then + objrefs[entity_name] = minetest.add_entity(pos, entity_name) + end + + objrefs[entity_name]:setpos({ + x = pos.x - values.dx * depth + values.rx * right, + y = pos.y + height, + z = pos.z - values.dz * depth + values.rz * right}) + + objrefs[entity_name]:setyaw(values.yaw) + end + end + return objrefs +end + +--- Call on_display_update callback of a node for one of its display entities +local function call_node_on_display_update(pos, objref) + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + local entity = objref:get_luaentity() + if ndef and ndef.display_entities and entity and ndef.display_entities[entity.name] then + ndef.display_entities[entity.name].on_display_update(pos, objref) + end +end + +--- Force entity update +function lcdlib.update_entities(pos) + local objrefs = place_entities(pos) + for _, objref in pairs(objrefs) do + call_node_on_display_update(pos, objref) + end +end + +--- On_activate callback for lcdlib entities. Calls on_display_update callbacks +--- of corresponding node for each entity. +function lcdlib.on_activate(entity, staticdata) + if entity then + entity.object:set_armor_groups({immortal=1}) + call_node_on_display_update(entity.object:getpos(), entity.object) + end +end + +--- On_place callback for lcdlib items. Does nothing more than preventing item +--- from being placed on ceiling or ground +function lcdlib.on_place(itemstack, placer, pointed_thing) + local ndef = itemstack:get_definition() + local above = pointed_thing.above + local under = pointed_thing.under + local dir = {x = under.x - above.x, + y = under.y - above.y, + z = under.z - above.z} + + if ndef then + if ndef.paramtype2 == "wallmounted" then + + local wdir = minetest.dir_to_wallmounted(dir) + + if wdir == 0 or wdir == 1 then + dir = placer:get_look_dir() + dir.y = 0 + wdir = minetest.dir_to_wallmounted(dir) + end + + return minetest.item_place(itemstack, placer, pointed_thing, wdir) + else + return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(dir)) + end + end + +end + +--- On_construct callback for lcdlib items. Creates entities and update them. +function lcdlib.on_construct(pos) + lcdlib.update_entities(pos) +end + +--- On_destruct callback for lcdlib items. Removes entities. +function lcdlib.on_destruct(pos) + local objrefs = get_entities(pos) + + for _, objref in pairs(objrefs) do + objref:remove() + end +end + +-- On_rotate (screwdriver) callback for lcdlib items. Prevents axis rotation and reorients entities. +function lcdlib.on_rotate(pos, node, user, mode, new_param2) + if mode ~= 1 then return false end + + local values = get_values(node) + + if values then + minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate}) + place_entities(pos) + return true + else + return false + end +end + +--- Creates display entity with some fields and the on_activate callback +function lcdlib.register_display_entity(entity_name) + if not minetest.registered_entity then + minetest.register_entity(':'..entity_name, { + collisionbox = { 0, 0, 0, 0, 0, 0 }, + visual = "upright_sprite", + textures = {}, + on_activate = lcdlib.on_activate, + }) + end +end + + + diff --git a/lcdlib/font_default.lua b/lcdlib/font_default.lua new file mode 100644 index 0000000..1802b57 --- /dev/null +++ b/lcdlib/font_default.lua @@ -0,0 +1,12 @@ +--[[ + + generated by tools/make_font_lua.sh Thu Dec 21 21:45:53 CET 2017 + +--]] + +lcdlib.register_font( + 'default', + 12, + { [0]=6, [32]=4, [33]=3, [34]=4, [35]=7, [36]=6, [37]=8, [38]=8, [39]=3, [40]=4, [41]=4, [42]=4, [43]=7, [44]=3, [45]=5, [46]=3, [47]=5, [48]=6, [49]=4, [50]=6, [51]=6, [52]=7, [53]=6, [54]=6, [55]=6, [56]=6, [57]=6, [58]=3, [59]=3, [60]=5, [61]=6, [62]=5, [63]=6, [64]=11, [65]=8, [66]=7, [67]=8, [68]=7, [69]=6, [70]=6, [71]=8, [72]=7, [73]=3, [74]=6, [75]=8, [76]=6, [77]=10, [78]=8, [79]=8, [80]=7, [81]=8, [82]=7, [83]=7, [84]=7, [85]=7, [86]=8, [87]=11, [88]=8, [89]=9, [90]=7, [91]=4, [92]=5, [93]=4, [94]=5, [95]=7, [96]=3, [97]=7, [98]=6, [99]=5, [100]=6, [101]=6, [102]=5, [103]=6, [104]=6, [105]=3, [106]=3, [107]=7, [108]=3, [109]=9, [110]=6, [111]=6, [112]=6, [113]=6, [114]=5, [115]=6, [116]=4, [117]=6, [118]=6, [119]=8, [120]=7, [121]=6, [122]=6, [123]=5, [124]=3, [125]=5, [126]=6, [138]=6, [141]=3, [161]=3, [177]=6, [191]=6, [192]=8, [193]=8, [194]=8, [195]=8, [196]=8, [197]=8, [198]=10, [199]=8, [200]=6, [201]=6, [202]=6, [203]=6, [204]=3, [205]=3, [206]=3, [207]=3, [208]=8, [209]=8, [210]=8, [211]=8, [212]=8, [213]=8, [214]=8, [215]=6, [216]=8, [217]=7, [218]=7, [219]=7, [220]=7, [221]=9, [224]=7, [225]=7, [226]=7, [227]=7, [228]=7, [229]=7, [230]=9, [231]=5, [232]=6, [233]=6, [234]=6, [235]=6, [236]=3, [237]=3, [238]=3, [239]=3, [242]=6, [244]=6, [245]=6, [246]=6, [247]=6, [249]=6, [250]=6, [251]=6, [252]=6, [253]=6, [255]=6 } +); + diff --git a/lcdlib/init.lua b/lcdlib/init.lua new file mode 100644 index 0000000..f3fd593 --- /dev/null +++ b/lcdlib/init.lua @@ -0,0 +1,285 @@ +--[[ + lcdlib based on: + + font_lib mod for Minetest - Library to add font display capability + to display_lib mod. + (c) Pierre-Yves Rollo + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +--]] + +-- Global variables +lcdlib = {} +lcdlib.registered_fonts = {} + +-- Version for compatibility checks +lcdlib.version = 1.0 + +-- Local functions +------------------ + +-- Split multiline text into array of lines, with maximum lines. + +local function split_lines(text, maxlines) + local splits = text:split("\n") + if maxlines then + local lines = {} + for num = 1,maxlines do + lines[num] = splits[num] + end + return lines + else + return splits + end +end + +-- Returns next char, managing ascii and unicode plane 0 (0000-FFFF). + +local function get_next_char(text, pos) + pos = pos + 1 + local char = text:sub(pos, pos):byte() + + -- 1 byte char + if char < 0x80 then + return char, pos + end + + -- 4 bytes char not managed + if char >= 0xF0 then + pos = pos + 3 + return 0, pos + end + + -- 3 bytes char not managed + if char >= 0xE0 then + pos = pos + 2 + return 0, pos + end + + -- 2 bytes char (little endian) + if char >= 0xC2 then + pos = pos + 1 + return (char - 0xC2) * 0x40 + text:sub(pos, pos):byte(), pos + end + + -- Not an UTF char + return 0, pos + +end + +-- Returns font properties to be used according to font_name + +local function get_font(font_name) + local font = lcdlib.registered_fonts[font_name] + + if font == nil then + local message + + if font_name == nil then + message = "No font given" + else + message = "Font \""..font_name.."\" unregistered" + end + + if lcdlib.fallback_font == nil then + minetest.log("error", message.." and no other font registered.") + else + minetest.log("info", message..", using font \""..lcdlib.fallback_font.."\".") + font = lcdlib.registered_fonts[lcdlib.fallback_font] + end + end + + return font +end + +-- API functions +---------------- + +-- Computes text size for a given font and text (ignores new lines) +-- @param font_name Font to be used +-- @param text Text to be rendered +-- @return Rendered text (width, height) + +function lcdlib.get_text_size(font_name, text) + local char + local width = 0 + local pos = 0 + local font = get_font(font_name) + + if font == nil then + return 0, 0 + else + while pos < #text do + char, pos = get_next_char(text, pos) + -- Ignore chars with no texture + if font.widths[char] ~= nil then + width = width + font.widths[char] + end + end + end + + return width, font.height +end + +--- Builds texture part for a text line +-- @param font_name Font to be used +-- @param text Text to be rendered +-- @param width Width of the texture (extra text is not rendered) +-- @param x Starting x position in texture +-- @param y Vertical position of the line in texture +-- @return Texture string + +--> ADD ALIGN +function lcdlib.make_line_texture(font_name, text, width, x, y) + local texture = "" + local char + local pos = 0 + local font = get_font(font_name) + + if font ~= nil then + while pos < #text do + char, pos = get_next_char(text, pos) + + -- Ignore chars with no texture + if font.widths[char] ~= nil then + -- Add image only if it is visible (at least partly) + if x + font.widths[char] >= 0 and x <= width then + texture = texture.. + string.format(":%d,%d=font_%s_%04x.png", + x, y, font.name, char) + end + x = x + font.widths[char] + else + print(string.format("Missing char %d (%04x)",char,char)) + end + end + end + + return texture +end + +--- Builds texture for a multiline colored text +-- @param font_name Font to be used +-- @param text Text to be rendered +-- @param texturew Width of the texture (extra text will be truncated) +-- @param textureh Height of the texture +-- @param maxlines Maximum number of lines +-- @param valign Vertical text align ("top" or "center") +-- @param color Color of the text +-- @return Texture string + +function lcdlib.make_multiline_texture(font_name, text, width, height, + maxlines, valign, color) + local texture = "" + local lines = {} + local textheight = 0 + local y, w, h + h = get_font(font_name).height + + for num, line in pairs(split_lines(text, maxlines)) do + if line:byte(1) == 60 then -- '<' + lines[num] = { text = line:sub(2,-1), width = width - 4, height = h, } + else + w, h = lcdlib.get_text_size(font_name, line) + lines[num] = { text = line, width = w, height = h, } + end + textheight = textheight + h + end + + if #lines then + if valign == "top" then + y = 0 + elseif valign == "bottom" then + y = height - textheight + else + y = (height - textheight) / 2 + end + end + + for _, line in pairs(lines) do + texture = texture.. + lcdlib.make_line_texture(font_name, line.text, width, + (width - line.width) / 2, y) + y = y + line.height + end + + texture = string.format("[combine:%dx%d", width, height)..texture + if color then texture = texture.."^[colorize:"..color end + + return texture +end + +--- Register a new font +-- Textures corresponding to the font should be named after following patern : +-- font__.png +-- : name of the font +-- : 4 digit hexadecimal unicode of the char +-- If registering different sizes, add size in the font name (e.g. times_10, times_12...) +-- @param height Font height in pixels +-- @param widths Array of character widths in pixel, indexed by unicode number. + +function lcdlib.register_font(font_name, height, widths) + if lcdlib.registered_fonts[font_name] ~= nil then + minetest.log("error", "Font \""..font_name.."\" already registered.") + return + end + + lcdlib.registered_fonts[font_name] = + { name = font_name, height = height, widths = widths } + + -- If no fallback font, set it (so, first font registered will be the default fallback font) + if lcdlib.fallback_font == nil then + lcdlib.fallback_font = font_name + end +end + +--- Define the fallback font +-- This font will be used instead of given font if not registered. +-- @param font_name Name of the font to be used as fallback font (has to be registered). + +function lcdlib.set_fallback_font(font_name) + if lcdlib.registered_fonts[font_name] == nil then + minetest.log("error", "Fallback font \""..font_name.."\" not registered.") + else + lcdlib.fallback_font = font_name + end +end + +--- Standard on_display_update entity callback. +-- Node should have a corresponding display_entity with size, resolution and maxlines fields and +-- optionally valign and color fields +-- @param pos Node position +-- @param objref Object reference of entity + +function lcdlib.on_display_update(pos, objref) + local meta = minetest.get_meta(pos) + local text = meta:get_string("display_text") + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + local entity = objref:get_luaentity() + + if entity and ndef.display_entities[entity.name] then + local def = ndef.display_entities[entity.name] + + objref:set_properties({ + textures={lcdlib.make_multiline_texture( + def.font_name, text, def.size.x*def.resolution.x, def.size.y*def.resolution.y, + def.maxlines, def.valign, def.color)}, + visual_size = def.size + }) + end +end + +dofile(minetest.get_modpath("lcdlib").."/font_default.lua") +dofile(minetest.get_modpath("lcdlib").."/display.lua") + diff --git a/lcdlib/textures/font_default_0000.png b/lcdlib/textures/font_default_0000.png new file mode 100644 index 0000000..65e43a7 Binary files /dev/null and b/lcdlib/textures/font_default_0000.png differ diff --git a/lcdlib/textures/font_default_0020.png b/lcdlib/textures/font_default_0020.png new file mode 100644 index 0000000..049fd14 Binary files /dev/null and b/lcdlib/textures/font_default_0020.png differ diff --git a/lcdlib/textures/font_default_0021.png b/lcdlib/textures/font_default_0021.png new file mode 100644 index 0000000..7691a14 Binary files /dev/null and b/lcdlib/textures/font_default_0021.png differ diff --git a/lcdlib/textures/font_default_0022.png b/lcdlib/textures/font_default_0022.png new file mode 100644 index 0000000..91f4c5f Binary files /dev/null and b/lcdlib/textures/font_default_0022.png differ diff --git a/lcdlib/textures/font_default_0023.png b/lcdlib/textures/font_default_0023.png new file mode 100644 index 0000000..9290dc1 Binary files /dev/null and b/lcdlib/textures/font_default_0023.png differ diff --git a/lcdlib/textures/font_default_0024.png b/lcdlib/textures/font_default_0024.png new file mode 100644 index 0000000..cde69d4 Binary files /dev/null and b/lcdlib/textures/font_default_0024.png differ diff --git a/lcdlib/textures/font_default_0025.png b/lcdlib/textures/font_default_0025.png new file mode 100644 index 0000000..703ab16 Binary files /dev/null and b/lcdlib/textures/font_default_0025.png differ diff --git a/lcdlib/textures/font_default_0026.png b/lcdlib/textures/font_default_0026.png new file mode 100644 index 0000000..6f98d49 Binary files /dev/null and b/lcdlib/textures/font_default_0026.png differ diff --git a/lcdlib/textures/font_default_0027.png b/lcdlib/textures/font_default_0027.png new file mode 100644 index 0000000..df31d75 Binary files /dev/null and b/lcdlib/textures/font_default_0027.png differ diff --git a/lcdlib/textures/font_default_0028.png b/lcdlib/textures/font_default_0028.png new file mode 100644 index 0000000..478c2c4 Binary files /dev/null and b/lcdlib/textures/font_default_0028.png differ diff --git a/lcdlib/textures/font_default_0029.png b/lcdlib/textures/font_default_0029.png new file mode 100644 index 0000000..8973488 Binary files /dev/null and b/lcdlib/textures/font_default_0029.png differ diff --git a/lcdlib/textures/font_default_002a.png b/lcdlib/textures/font_default_002a.png new file mode 100644 index 0000000..2b83a5c Binary files /dev/null and b/lcdlib/textures/font_default_002a.png differ diff --git a/lcdlib/textures/font_default_002b.png b/lcdlib/textures/font_default_002b.png new file mode 100644 index 0000000..abce910 Binary files /dev/null and b/lcdlib/textures/font_default_002b.png differ diff --git a/lcdlib/textures/font_default_002c.png b/lcdlib/textures/font_default_002c.png new file mode 100644 index 0000000..8a624c7 Binary files /dev/null and b/lcdlib/textures/font_default_002c.png differ diff --git a/lcdlib/textures/font_default_002d.png b/lcdlib/textures/font_default_002d.png new file mode 100644 index 0000000..f0ff962 Binary files /dev/null and b/lcdlib/textures/font_default_002d.png differ diff --git a/lcdlib/textures/font_default_002e.png b/lcdlib/textures/font_default_002e.png new file mode 100644 index 0000000..aff49bc Binary files /dev/null and b/lcdlib/textures/font_default_002e.png differ diff --git a/lcdlib/textures/font_default_002f.png b/lcdlib/textures/font_default_002f.png new file mode 100644 index 0000000..4667bf7 Binary files /dev/null and b/lcdlib/textures/font_default_002f.png differ diff --git a/lcdlib/textures/font_default_0030.png b/lcdlib/textures/font_default_0030.png new file mode 100644 index 0000000..470f0b0 Binary files /dev/null and b/lcdlib/textures/font_default_0030.png differ diff --git a/lcdlib/textures/font_default_0031.png b/lcdlib/textures/font_default_0031.png new file mode 100644 index 0000000..e84a9d3 Binary files /dev/null and b/lcdlib/textures/font_default_0031.png differ diff --git a/lcdlib/textures/font_default_0032.png b/lcdlib/textures/font_default_0032.png new file mode 100644 index 0000000..1ef3e84 Binary files /dev/null and b/lcdlib/textures/font_default_0032.png differ diff --git a/lcdlib/textures/font_default_0033.png b/lcdlib/textures/font_default_0033.png new file mode 100644 index 0000000..ec9f518 Binary files /dev/null and b/lcdlib/textures/font_default_0033.png differ diff --git a/lcdlib/textures/font_default_0034.png b/lcdlib/textures/font_default_0034.png new file mode 100644 index 0000000..bc82823 Binary files /dev/null and b/lcdlib/textures/font_default_0034.png differ diff --git a/lcdlib/textures/font_default_0035.png b/lcdlib/textures/font_default_0035.png new file mode 100644 index 0000000..3ed26c5 Binary files /dev/null and b/lcdlib/textures/font_default_0035.png differ diff --git a/lcdlib/textures/font_default_0036.png b/lcdlib/textures/font_default_0036.png new file mode 100644 index 0000000..6e706a4 Binary files /dev/null and b/lcdlib/textures/font_default_0036.png differ diff --git a/lcdlib/textures/font_default_0037.png b/lcdlib/textures/font_default_0037.png new file mode 100644 index 0000000..884b48a Binary files /dev/null and b/lcdlib/textures/font_default_0037.png differ diff --git a/lcdlib/textures/font_default_0038.png b/lcdlib/textures/font_default_0038.png new file mode 100644 index 0000000..a1e05bf Binary files /dev/null and b/lcdlib/textures/font_default_0038.png differ diff --git a/lcdlib/textures/font_default_0039.png b/lcdlib/textures/font_default_0039.png new file mode 100644 index 0000000..6443be9 Binary files /dev/null and b/lcdlib/textures/font_default_0039.png differ diff --git a/lcdlib/textures/font_default_003a.png b/lcdlib/textures/font_default_003a.png new file mode 100644 index 0000000..752e9de Binary files /dev/null and b/lcdlib/textures/font_default_003a.png differ diff --git a/lcdlib/textures/font_default_003b.png b/lcdlib/textures/font_default_003b.png new file mode 100644 index 0000000..77878e8 Binary files /dev/null and b/lcdlib/textures/font_default_003b.png differ diff --git a/lcdlib/textures/font_default_003c.png b/lcdlib/textures/font_default_003c.png new file mode 100644 index 0000000..0252ab9 Binary files /dev/null and b/lcdlib/textures/font_default_003c.png differ diff --git a/lcdlib/textures/font_default_003d.png b/lcdlib/textures/font_default_003d.png new file mode 100644 index 0000000..af0325a Binary files /dev/null and b/lcdlib/textures/font_default_003d.png differ diff --git a/lcdlib/textures/font_default_003e.png b/lcdlib/textures/font_default_003e.png new file mode 100644 index 0000000..77fe954 Binary files /dev/null and b/lcdlib/textures/font_default_003e.png differ diff --git a/lcdlib/textures/font_default_003f.png b/lcdlib/textures/font_default_003f.png new file mode 100644 index 0000000..e94177c Binary files /dev/null and b/lcdlib/textures/font_default_003f.png differ diff --git a/lcdlib/textures/font_default_0040.png b/lcdlib/textures/font_default_0040.png new file mode 100644 index 0000000..c7a11d2 Binary files /dev/null and b/lcdlib/textures/font_default_0040.png differ diff --git a/lcdlib/textures/font_default_0041.png b/lcdlib/textures/font_default_0041.png new file mode 100644 index 0000000..5917cc0 Binary files /dev/null and b/lcdlib/textures/font_default_0041.png differ diff --git a/lcdlib/textures/font_default_0042.png b/lcdlib/textures/font_default_0042.png new file mode 100644 index 0000000..69a92b3 Binary files /dev/null and b/lcdlib/textures/font_default_0042.png differ diff --git a/lcdlib/textures/font_default_0043.png b/lcdlib/textures/font_default_0043.png new file mode 100644 index 0000000..6f68703 Binary files /dev/null and b/lcdlib/textures/font_default_0043.png differ diff --git a/lcdlib/textures/font_default_0044.png b/lcdlib/textures/font_default_0044.png new file mode 100644 index 0000000..94c0a30 Binary files /dev/null and b/lcdlib/textures/font_default_0044.png differ diff --git a/lcdlib/textures/font_default_0045.png b/lcdlib/textures/font_default_0045.png new file mode 100644 index 0000000..b6732c3 Binary files /dev/null and b/lcdlib/textures/font_default_0045.png differ diff --git a/lcdlib/textures/font_default_0046.png b/lcdlib/textures/font_default_0046.png new file mode 100644 index 0000000..992bdc1 Binary files /dev/null and b/lcdlib/textures/font_default_0046.png differ diff --git a/lcdlib/textures/font_default_0047.png b/lcdlib/textures/font_default_0047.png new file mode 100644 index 0000000..12340e7 Binary files /dev/null and b/lcdlib/textures/font_default_0047.png differ diff --git a/lcdlib/textures/font_default_0048.png b/lcdlib/textures/font_default_0048.png new file mode 100644 index 0000000..f315c03 Binary files /dev/null and b/lcdlib/textures/font_default_0048.png differ diff --git a/lcdlib/textures/font_default_0049.png b/lcdlib/textures/font_default_0049.png new file mode 100644 index 0000000..53ef0bc Binary files /dev/null and b/lcdlib/textures/font_default_0049.png differ diff --git a/lcdlib/textures/font_default_004a.png b/lcdlib/textures/font_default_004a.png new file mode 100644 index 0000000..32cd569 Binary files /dev/null and b/lcdlib/textures/font_default_004a.png differ diff --git a/lcdlib/textures/font_default_004b.png b/lcdlib/textures/font_default_004b.png new file mode 100644 index 0000000..1f770e7 Binary files /dev/null and b/lcdlib/textures/font_default_004b.png differ diff --git a/lcdlib/textures/font_default_004c.png b/lcdlib/textures/font_default_004c.png new file mode 100644 index 0000000..313ecfe Binary files /dev/null and b/lcdlib/textures/font_default_004c.png differ diff --git a/lcdlib/textures/font_default_004d.png b/lcdlib/textures/font_default_004d.png new file mode 100644 index 0000000..f6676fb Binary files /dev/null and b/lcdlib/textures/font_default_004d.png differ diff --git a/lcdlib/textures/font_default_004e.png b/lcdlib/textures/font_default_004e.png new file mode 100644 index 0000000..4e28110 Binary files /dev/null and b/lcdlib/textures/font_default_004e.png differ diff --git a/lcdlib/textures/font_default_004f.png b/lcdlib/textures/font_default_004f.png new file mode 100644 index 0000000..1b27777 Binary files /dev/null and b/lcdlib/textures/font_default_004f.png differ diff --git a/lcdlib/textures/font_default_0050.png b/lcdlib/textures/font_default_0050.png new file mode 100644 index 0000000..ddfff40 Binary files /dev/null and b/lcdlib/textures/font_default_0050.png differ diff --git a/lcdlib/textures/font_default_0051.png b/lcdlib/textures/font_default_0051.png new file mode 100644 index 0000000..c3df8ec Binary files /dev/null and b/lcdlib/textures/font_default_0051.png differ diff --git a/lcdlib/textures/font_default_0052.png b/lcdlib/textures/font_default_0052.png new file mode 100644 index 0000000..f93ff7c Binary files /dev/null and b/lcdlib/textures/font_default_0052.png differ diff --git a/lcdlib/textures/font_default_0053.png b/lcdlib/textures/font_default_0053.png new file mode 100644 index 0000000..389a62b Binary files /dev/null and b/lcdlib/textures/font_default_0053.png differ diff --git a/lcdlib/textures/font_default_0054.png b/lcdlib/textures/font_default_0054.png new file mode 100644 index 0000000..11ec544 Binary files /dev/null and b/lcdlib/textures/font_default_0054.png differ diff --git a/lcdlib/textures/font_default_0055.png b/lcdlib/textures/font_default_0055.png new file mode 100644 index 0000000..5d15704 Binary files /dev/null and b/lcdlib/textures/font_default_0055.png differ diff --git a/lcdlib/textures/font_default_0056.png b/lcdlib/textures/font_default_0056.png new file mode 100644 index 0000000..3e6f48a Binary files /dev/null and b/lcdlib/textures/font_default_0056.png differ diff --git a/lcdlib/textures/font_default_0057.png b/lcdlib/textures/font_default_0057.png new file mode 100644 index 0000000..cc140d0 Binary files /dev/null and b/lcdlib/textures/font_default_0057.png differ diff --git a/lcdlib/textures/font_default_0058.png b/lcdlib/textures/font_default_0058.png new file mode 100644 index 0000000..fe71fb9 Binary files /dev/null and b/lcdlib/textures/font_default_0058.png differ diff --git a/lcdlib/textures/font_default_0059.png b/lcdlib/textures/font_default_0059.png new file mode 100644 index 0000000..1d1db03 Binary files /dev/null and b/lcdlib/textures/font_default_0059.png differ diff --git a/lcdlib/textures/font_default_005a.png b/lcdlib/textures/font_default_005a.png new file mode 100644 index 0000000..e89b0eb Binary files /dev/null and b/lcdlib/textures/font_default_005a.png differ diff --git a/lcdlib/textures/font_default_005b.png b/lcdlib/textures/font_default_005b.png new file mode 100644 index 0000000..e547c51 Binary files /dev/null and b/lcdlib/textures/font_default_005b.png differ diff --git a/lcdlib/textures/font_default_005c.png b/lcdlib/textures/font_default_005c.png new file mode 100644 index 0000000..35fc222 Binary files /dev/null and b/lcdlib/textures/font_default_005c.png differ diff --git a/lcdlib/textures/font_default_005d.png b/lcdlib/textures/font_default_005d.png new file mode 100644 index 0000000..040ebe0 Binary files /dev/null and b/lcdlib/textures/font_default_005d.png differ diff --git a/lcdlib/textures/font_default_005e.png b/lcdlib/textures/font_default_005e.png new file mode 100644 index 0000000..be3bbb1 Binary files /dev/null and b/lcdlib/textures/font_default_005e.png differ diff --git a/lcdlib/textures/font_default_005f.png b/lcdlib/textures/font_default_005f.png new file mode 100644 index 0000000..3cc8d3d Binary files /dev/null and b/lcdlib/textures/font_default_005f.png differ diff --git a/lcdlib/textures/font_default_0060.png b/lcdlib/textures/font_default_0060.png new file mode 100644 index 0000000..58500d2 Binary files /dev/null and b/lcdlib/textures/font_default_0060.png differ diff --git a/lcdlib/textures/font_default_0061.png b/lcdlib/textures/font_default_0061.png new file mode 100644 index 0000000..2121aa8 Binary files /dev/null and b/lcdlib/textures/font_default_0061.png differ diff --git a/lcdlib/textures/font_default_0062.png b/lcdlib/textures/font_default_0062.png new file mode 100644 index 0000000..ba3feeb Binary files /dev/null and b/lcdlib/textures/font_default_0062.png differ diff --git a/lcdlib/textures/font_default_0063.png b/lcdlib/textures/font_default_0063.png new file mode 100644 index 0000000..cee372c Binary files /dev/null and b/lcdlib/textures/font_default_0063.png differ diff --git a/lcdlib/textures/font_default_0064.png b/lcdlib/textures/font_default_0064.png new file mode 100644 index 0000000..c5989c1 Binary files /dev/null and b/lcdlib/textures/font_default_0064.png differ diff --git a/lcdlib/textures/font_default_0065.png b/lcdlib/textures/font_default_0065.png new file mode 100644 index 0000000..7cd370a Binary files /dev/null and b/lcdlib/textures/font_default_0065.png differ diff --git a/lcdlib/textures/font_default_0066.png b/lcdlib/textures/font_default_0066.png new file mode 100644 index 0000000..a63276c Binary files /dev/null and b/lcdlib/textures/font_default_0066.png differ diff --git a/lcdlib/textures/font_default_0067.png b/lcdlib/textures/font_default_0067.png new file mode 100644 index 0000000..baf3e88 Binary files /dev/null and b/lcdlib/textures/font_default_0067.png differ diff --git a/lcdlib/textures/font_default_0068.png b/lcdlib/textures/font_default_0068.png new file mode 100644 index 0000000..1c9e9b4 Binary files /dev/null and b/lcdlib/textures/font_default_0068.png differ diff --git a/lcdlib/textures/font_default_0069.png b/lcdlib/textures/font_default_0069.png new file mode 100644 index 0000000..785cdb5 Binary files /dev/null and b/lcdlib/textures/font_default_0069.png differ diff --git a/lcdlib/textures/font_default_006a.png b/lcdlib/textures/font_default_006a.png new file mode 100644 index 0000000..a7abd8e Binary files /dev/null and b/lcdlib/textures/font_default_006a.png differ diff --git a/lcdlib/textures/font_default_006b.png b/lcdlib/textures/font_default_006b.png new file mode 100644 index 0000000..ff5f32a Binary files /dev/null and b/lcdlib/textures/font_default_006b.png differ diff --git a/lcdlib/textures/font_default_006c.png b/lcdlib/textures/font_default_006c.png new file mode 100644 index 0000000..53ef0bc Binary files /dev/null and b/lcdlib/textures/font_default_006c.png differ diff --git a/lcdlib/textures/font_default_006d.png b/lcdlib/textures/font_default_006d.png new file mode 100644 index 0000000..351aeef Binary files /dev/null and b/lcdlib/textures/font_default_006d.png differ diff --git a/lcdlib/textures/font_default_006e.png b/lcdlib/textures/font_default_006e.png new file mode 100644 index 0000000..60e089d Binary files /dev/null and b/lcdlib/textures/font_default_006e.png differ diff --git a/lcdlib/textures/font_default_006f.png b/lcdlib/textures/font_default_006f.png new file mode 100644 index 0000000..dd48b6c Binary files /dev/null and b/lcdlib/textures/font_default_006f.png differ diff --git a/lcdlib/textures/font_default_0070.png b/lcdlib/textures/font_default_0070.png new file mode 100644 index 0000000..0fdb26f Binary files /dev/null and b/lcdlib/textures/font_default_0070.png differ diff --git a/lcdlib/textures/font_default_0071.png b/lcdlib/textures/font_default_0071.png new file mode 100644 index 0000000..787418e Binary files /dev/null and b/lcdlib/textures/font_default_0071.png differ diff --git a/lcdlib/textures/font_default_0072.png b/lcdlib/textures/font_default_0072.png new file mode 100644 index 0000000..7d2bf4c Binary files /dev/null and b/lcdlib/textures/font_default_0072.png differ diff --git a/lcdlib/textures/font_default_0073.png b/lcdlib/textures/font_default_0073.png new file mode 100644 index 0000000..b2b2ed2 Binary files /dev/null and b/lcdlib/textures/font_default_0073.png differ diff --git a/lcdlib/textures/font_default_0074.png b/lcdlib/textures/font_default_0074.png new file mode 100644 index 0000000..dcdbd37 Binary files /dev/null and b/lcdlib/textures/font_default_0074.png differ diff --git a/lcdlib/textures/font_default_0075.png b/lcdlib/textures/font_default_0075.png new file mode 100644 index 0000000..5ef59c7 Binary files /dev/null and b/lcdlib/textures/font_default_0075.png differ diff --git a/lcdlib/textures/font_default_0076.png b/lcdlib/textures/font_default_0076.png new file mode 100644 index 0000000..710703f Binary files /dev/null and b/lcdlib/textures/font_default_0076.png differ diff --git a/lcdlib/textures/font_default_0077.png b/lcdlib/textures/font_default_0077.png new file mode 100644 index 0000000..373ecb0 Binary files /dev/null and b/lcdlib/textures/font_default_0077.png differ diff --git a/lcdlib/textures/font_default_0078.png b/lcdlib/textures/font_default_0078.png new file mode 100644 index 0000000..23541ff Binary files /dev/null and b/lcdlib/textures/font_default_0078.png differ diff --git a/lcdlib/textures/font_default_0079.png b/lcdlib/textures/font_default_0079.png new file mode 100644 index 0000000..e3fddb2 Binary files /dev/null and b/lcdlib/textures/font_default_0079.png differ diff --git a/lcdlib/textures/font_default_007a.png b/lcdlib/textures/font_default_007a.png new file mode 100644 index 0000000..2a92823 Binary files /dev/null and b/lcdlib/textures/font_default_007a.png differ diff --git a/lcdlib/textures/font_default_007b.png b/lcdlib/textures/font_default_007b.png new file mode 100644 index 0000000..7606697 Binary files /dev/null and b/lcdlib/textures/font_default_007b.png differ diff --git a/lcdlib/textures/font_default_007c.png b/lcdlib/textures/font_default_007c.png new file mode 100644 index 0000000..777f1e4 Binary files /dev/null and b/lcdlib/textures/font_default_007c.png differ diff --git a/lcdlib/textures/font_default_007d.png b/lcdlib/textures/font_default_007d.png new file mode 100644 index 0000000..b9ee397 Binary files /dev/null and b/lcdlib/textures/font_default_007d.png differ diff --git a/lcdlib/textures/font_default_007e.png b/lcdlib/textures/font_default_007e.png new file mode 100644 index 0000000..759b56e Binary files /dev/null and b/lcdlib/textures/font_default_007e.png differ diff --git a/lcdlib/textures/font_default_008a.png b/lcdlib/textures/font_default_008a.png new file mode 100644 index 0000000..e4f3236 Binary files /dev/null and b/lcdlib/textures/font_default_008a.png differ diff --git a/lcdlib/textures/font_default_008d.png b/lcdlib/textures/font_default_008d.png new file mode 100644 index 0000000..fcc3b38 Binary files /dev/null and b/lcdlib/textures/font_default_008d.png differ diff --git a/lcdlib/textures/font_default_00a1.png b/lcdlib/textures/font_default_00a1.png new file mode 100644 index 0000000..df91ae3 Binary files /dev/null and b/lcdlib/textures/font_default_00a1.png differ diff --git a/lcdlib/textures/font_default_00b1.png b/lcdlib/textures/font_default_00b1.png new file mode 100644 index 0000000..2413844 Binary files /dev/null and b/lcdlib/textures/font_default_00b1.png differ diff --git a/lcdlib/textures/font_default_00bf.png b/lcdlib/textures/font_default_00bf.png new file mode 100644 index 0000000..fec3deb Binary files /dev/null and b/lcdlib/textures/font_default_00bf.png differ diff --git a/lcdlib/textures/font_default_00c0.png b/lcdlib/textures/font_default_00c0.png new file mode 100644 index 0000000..4652acf Binary files /dev/null and b/lcdlib/textures/font_default_00c0.png differ diff --git a/lcdlib/textures/font_default_00c1.png b/lcdlib/textures/font_default_00c1.png new file mode 100644 index 0000000..f2d7464 Binary files /dev/null and b/lcdlib/textures/font_default_00c1.png differ diff --git a/lcdlib/textures/font_default_00c2.png b/lcdlib/textures/font_default_00c2.png new file mode 100644 index 0000000..c759ac9 Binary files /dev/null and b/lcdlib/textures/font_default_00c2.png differ diff --git a/lcdlib/textures/font_default_00c3.png b/lcdlib/textures/font_default_00c3.png new file mode 100644 index 0000000..6239ee6 Binary files /dev/null and b/lcdlib/textures/font_default_00c3.png differ diff --git a/lcdlib/textures/font_default_00c4.png b/lcdlib/textures/font_default_00c4.png new file mode 100644 index 0000000..1178423 Binary files /dev/null and b/lcdlib/textures/font_default_00c4.png differ diff --git a/lcdlib/textures/font_default_00c5.png b/lcdlib/textures/font_default_00c5.png new file mode 100644 index 0000000..64e5efc Binary files /dev/null and b/lcdlib/textures/font_default_00c5.png differ diff --git a/lcdlib/textures/font_default_00c6.png b/lcdlib/textures/font_default_00c6.png new file mode 100644 index 0000000..7eaf588 Binary files /dev/null and b/lcdlib/textures/font_default_00c6.png differ diff --git a/lcdlib/textures/font_default_00c7.png b/lcdlib/textures/font_default_00c7.png new file mode 100644 index 0000000..247fbc4 Binary files /dev/null and b/lcdlib/textures/font_default_00c7.png differ diff --git a/lcdlib/textures/font_default_00c8.png b/lcdlib/textures/font_default_00c8.png new file mode 100644 index 0000000..517b63d Binary files /dev/null and b/lcdlib/textures/font_default_00c8.png differ diff --git a/lcdlib/textures/font_default_00c9.png b/lcdlib/textures/font_default_00c9.png new file mode 100644 index 0000000..cd4f8d8 Binary files /dev/null and b/lcdlib/textures/font_default_00c9.png differ diff --git a/lcdlib/textures/font_default_00ca.png b/lcdlib/textures/font_default_00ca.png new file mode 100644 index 0000000..39aa1aa Binary files /dev/null and b/lcdlib/textures/font_default_00ca.png differ diff --git a/lcdlib/textures/font_default_00cb.png b/lcdlib/textures/font_default_00cb.png new file mode 100644 index 0000000..7058b5a Binary files /dev/null and b/lcdlib/textures/font_default_00cb.png differ diff --git a/lcdlib/textures/font_default_00cc.png b/lcdlib/textures/font_default_00cc.png new file mode 100644 index 0000000..a382d73a Binary files /dev/null and b/lcdlib/textures/font_default_00cc.png differ diff --git a/lcdlib/textures/font_default_00cd.png b/lcdlib/textures/font_default_00cd.png new file mode 100644 index 0000000..86339a1 Binary files /dev/null and b/lcdlib/textures/font_default_00cd.png differ diff --git a/lcdlib/textures/font_default_00ce.png b/lcdlib/textures/font_default_00ce.png new file mode 100644 index 0000000..78583df Binary files /dev/null and b/lcdlib/textures/font_default_00ce.png differ diff --git a/lcdlib/textures/font_default_00cf.png b/lcdlib/textures/font_default_00cf.png new file mode 100644 index 0000000..b680e2e Binary files /dev/null and b/lcdlib/textures/font_default_00cf.png differ diff --git a/lcdlib/textures/font_default_00d0.png b/lcdlib/textures/font_default_00d0.png new file mode 100644 index 0000000..50db9f9 Binary files /dev/null and b/lcdlib/textures/font_default_00d0.png differ diff --git a/lcdlib/textures/font_default_00d1.png b/lcdlib/textures/font_default_00d1.png new file mode 100644 index 0000000..912524f Binary files /dev/null and b/lcdlib/textures/font_default_00d1.png differ diff --git a/lcdlib/textures/font_default_00d2.png b/lcdlib/textures/font_default_00d2.png new file mode 100644 index 0000000..d7e635f Binary files /dev/null and b/lcdlib/textures/font_default_00d2.png differ diff --git a/lcdlib/textures/font_default_00d3.png b/lcdlib/textures/font_default_00d3.png new file mode 100644 index 0000000..27ae016 Binary files /dev/null and b/lcdlib/textures/font_default_00d3.png differ diff --git a/lcdlib/textures/font_default_00d4.png b/lcdlib/textures/font_default_00d4.png new file mode 100644 index 0000000..a62a3ed Binary files /dev/null and b/lcdlib/textures/font_default_00d4.png differ diff --git a/lcdlib/textures/font_default_00d5.png b/lcdlib/textures/font_default_00d5.png new file mode 100644 index 0000000..3740df7 Binary files /dev/null and b/lcdlib/textures/font_default_00d5.png differ diff --git a/lcdlib/textures/font_default_00d6.png b/lcdlib/textures/font_default_00d6.png new file mode 100644 index 0000000..9b3cd62 Binary files /dev/null and b/lcdlib/textures/font_default_00d6.png differ diff --git a/lcdlib/textures/font_default_00d7.png b/lcdlib/textures/font_default_00d7.png new file mode 100644 index 0000000..a92ac66 Binary files /dev/null and b/lcdlib/textures/font_default_00d7.png differ diff --git a/lcdlib/textures/font_default_00d8.png b/lcdlib/textures/font_default_00d8.png new file mode 100644 index 0000000..0453191 Binary files /dev/null and b/lcdlib/textures/font_default_00d8.png differ diff --git a/lcdlib/textures/font_default_00d9.png b/lcdlib/textures/font_default_00d9.png new file mode 100644 index 0000000..607ac14 Binary files /dev/null and b/lcdlib/textures/font_default_00d9.png differ diff --git a/lcdlib/textures/font_default_00da.png b/lcdlib/textures/font_default_00da.png new file mode 100644 index 0000000..91e5781 Binary files /dev/null and b/lcdlib/textures/font_default_00da.png differ diff --git a/lcdlib/textures/font_default_00db.png b/lcdlib/textures/font_default_00db.png new file mode 100644 index 0000000..f63177d Binary files /dev/null and b/lcdlib/textures/font_default_00db.png differ diff --git a/lcdlib/textures/font_default_00dc.png b/lcdlib/textures/font_default_00dc.png new file mode 100644 index 0000000..eeaa7c6 Binary files /dev/null and b/lcdlib/textures/font_default_00dc.png differ diff --git a/lcdlib/textures/font_default_00dd.png b/lcdlib/textures/font_default_00dd.png new file mode 100644 index 0000000..f194136 Binary files /dev/null and b/lcdlib/textures/font_default_00dd.png differ diff --git a/lcdlib/textures/font_default_00e0.png b/lcdlib/textures/font_default_00e0.png new file mode 100644 index 0000000..b9779fe Binary files /dev/null and b/lcdlib/textures/font_default_00e0.png differ diff --git a/lcdlib/textures/font_default_00e1.png b/lcdlib/textures/font_default_00e1.png new file mode 100644 index 0000000..aeaeaf5 Binary files /dev/null and b/lcdlib/textures/font_default_00e1.png differ diff --git a/lcdlib/textures/font_default_00e2.png b/lcdlib/textures/font_default_00e2.png new file mode 100644 index 0000000..8ca07ed Binary files /dev/null and b/lcdlib/textures/font_default_00e2.png differ diff --git a/lcdlib/textures/font_default_00e3.png b/lcdlib/textures/font_default_00e3.png new file mode 100644 index 0000000..e2f00bb Binary files /dev/null and b/lcdlib/textures/font_default_00e3.png differ diff --git a/lcdlib/textures/font_default_00e4.png b/lcdlib/textures/font_default_00e4.png new file mode 100644 index 0000000..6bcf6fb Binary files /dev/null and b/lcdlib/textures/font_default_00e4.png differ diff --git a/lcdlib/textures/font_default_00e5.png b/lcdlib/textures/font_default_00e5.png new file mode 100644 index 0000000..698094e Binary files /dev/null and b/lcdlib/textures/font_default_00e5.png differ diff --git a/lcdlib/textures/font_default_00e6.png b/lcdlib/textures/font_default_00e6.png new file mode 100644 index 0000000..70ac70a Binary files /dev/null and b/lcdlib/textures/font_default_00e6.png differ diff --git a/lcdlib/textures/font_default_00e7.png b/lcdlib/textures/font_default_00e7.png new file mode 100644 index 0000000..f0462bd Binary files /dev/null and b/lcdlib/textures/font_default_00e7.png differ diff --git a/lcdlib/textures/font_default_00e8.png b/lcdlib/textures/font_default_00e8.png new file mode 100644 index 0000000..841363e Binary files /dev/null and b/lcdlib/textures/font_default_00e8.png differ diff --git a/lcdlib/textures/font_default_00e9.png b/lcdlib/textures/font_default_00e9.png new file mode 100644 index 0000000..7752df4 Binary files /dev/null and b/lcdlib/textures/font_default_00e9.png differ diff --git a/lcdlib/textures/font_default_00ea.png b/lcdlib/textures/font_default_00ea.png new file mode 100644 index 0000000..b549be6 Binary files /dev/null and b/lcdlib/textures/font_default_00ea.png differ diff --git a/lcdlib/textures/font_default_00eb.png b/lcdlib/textures/font_default_00eb.png new file mode 100644 index 0000000..f9c4dbc Binary files /dev/null and b/lcdlib/textures/font_default_00eb.png differ diff --git a/lcdlib/textures/font_default_00ec.png b/lcdlib/textures/font_default_00ec.png new file mode 100644 index 0000000..e86f3a7 Binary files /dev/null and b/lcdlib/textures/font_default_00ec.png differ diff --git a/lcdlib/textures/font_default_00ed.png b/lcdlib/textures/font_default_00ed.png new file mode 100644 index 0000000..94f12e8 Binary files /dev/null and b/lcdlib/textures/font_default_00ed.png differ diff --git a/lcdlib/textures/font_default_00ee.png b/lcdlib/textures/font_default_00ee.png new file mode 100644 index 0000000..e8a743d Binary files /dev/null and b/lcdlib/textures/font_default_00ee.png differ diff --git a/lcdlib/textures/font_default_00ef.png b/lcdlib/textures/font_default_00ef.png new file mode 100644 index 0000000..d2c744f Binary files /dev/null and b/lcdlib/textures/font_default_00ef.png differ diff --git a/lcdlib/textures/font_default_00f2.png b/lcdlib/textures/font_default_00f2.png new file mode 100644 index 0000000..f7d1127 Binary files /dev/null and b/lcdlib/textures/font_default_00f2.png differ diff --git a/lcdlib/textures/font_default_00f4.png b/lcdlib/textures/font_default_00f4.png new file mode 100644 index 0000000..4b0cce6 Binary files /dev/null and b/lcdlib/textures/font_default_00f4.png differ diff --git a/lcdlib/textures/font_default_00f5.png b/lcdlib/textures/font_default_00f5.png new file mode 100644 index 0000000..ec7cec1 Binary files /dev/null and b/lcdlib/textures/font_default_00f5.png differ diff --git a/lcdlib/textures/font_default_00f6.png b/lcdlib/textures/font_default_00f6.png new file mode 100644 index 0000000..7213c8a Binary files /dev/null and b/lcdlib/textures/font_default_00f6.png differ diff --git a/lcdlib/textures/font_default_00f7.png b/lcdlib/textures/font_default_00f7.png new file mode 100644 index 0000000..408687d Binary files /dev/null and b/lcdlib/textures/font_default_00f7.png differ diff --git a/lcdlib/textures/font_default_00f9.png b/lcdlib/textures/font_default_00f9.png new file mode 100644 index 0000000..67d16b5 Binary files /dev/null and b/lcdlib/textures/font_default_00f9.png differ diff --git a/lcdlib/textures/font_default_00fa.png b/lcdlib/textures/font_default_00fa.png new file mode 100644 index 0000000..97de7e1 Binary files /dev/null and b/lcdlib/textures/font_default_00fa.png differ diff --git a/lcdlib/textures/font_default_00fb.png b/lcdlib/textures/font_default_00fb.png new file mode 100644 index 0000000..2861e15 Binary files /dev/null and b/lcdlib/textures/font_default_00fb.png differ diff --git a/lcdlib/textures/font_default_00fc.png b/lcdlib/textures/font_default_00fc.png new file mode 100644 index 0000000..c7deddd Binary files /dev/null and b/lcdlib/textures/font_default_00fc.png differ diff --git a/lcdlib/textures/font_default_00fd.png b/lcdlib/textures/font_default_00fd.png new file mode 100644 index 0000000..b6f45f9 Binary files /dev/null and b/lcdlib/textures/font_default_00fd.png differ diff --git a/lcdlib/textures/font_default_00ff.png b/lcdlib/textures/font_default_00ff.png new file mode 100644 index 0000000..d182a29 Binary files /dev/null and b/lcdlib/textures/font_default_00ff.png differ diff --git a/minecart/README.md b/minecart/README.md new file mode 100644 index 0000000..444fe16 --- /dev/null +++ b/minecart/README.md @@ -0,0 +1,110 @@ +Minecart +======== + +**Minecart, the lean railway transportation automation system** + + +Browse on: ![GitHub](https://github.com/joe7575/minecart) + +Download: ![GitHub](https://github.com/joe7575/minecart/archive/master.zip) + +![minecart](https://github.com/joe7575/minecart/blob/master/screenshot.png) + + +Minecart is based on carts, which is +based almost entirely on the mod boost_cart [1], which +itself is based on (and fully compatible with) the carts mod [2]. + +The model was originally designed by stujones11 [3] (CC-0). + +Cart textures are based on original work from PixelBOX by Gambit (permissive +license). + + +1. https://github.com/SmallJoker/boost_cart/ +2. https://github.com/PilzAdam/carts/ +3. https://github.com/stujones11/railcart/ + + +Original Cart Features +---------------------- + +- A fast cart for your railway or roller coaster (up to 7 m/s!) +- Boost and brake rails +- Rail junction switching with the 'right-left' walking keys +- Handbrake with the 'back' key + + +Minecart Features +----------------- + +The mod Minecart has its own cart (called Minecart) in addition to the standard cart. +Minecarts are used for automated item transport on private and public rail networks. +The mod features are: +- configurable timetables and routes for Minecarts +- automated loading/unloading of Minecarts by means of a Minecart Hopper +- rail network protection based on protection blocks called Land Marks +- protection of minecarts and cargo +- Minecarts run through unloaded areas (only the stations/hopper have to be loaded) +- Extra Minecart privs for rail workers +- Ingame documentation (German and English), based on the mod "doc" + + +Technical Background +-------------------- + +The Minecart can "run" through unloaded areas. This is done by means of recorded +and stored routes. If the area is unloaded the cart will simply follow the +predefined route until an area is loaded again. In this case the cart will be +spawned and run as usual. + + +Introduction +------------ + +1. Place your rails and build a route with two endpoints. Junctions are allowed + as long as each route has its own start and endpoint. +2. Place a Railway Buffer at both endpoints. (buffers are always needed, + they store the route and timing information) +3. Give both Railway Buffers unique station names, like Oxford and Cambridge +4. Drive from buffer to buffer in both directions using a Minecart(!) to record the + routes (use 'right-left' keys to control the Minecart) +5. Punch the buffers to check the connection data (e.g. "Oxford: connected to Cambridge") +6. Optional: Configure the Minecart stop time in one or both buffers. The Minecart + will then start automatically after the configured time +7. Optional: Protect your rail network with the Protection Landmarks (one Landmark + at least every 16 nodes/meters) +8. Place a Minecart in front of the buffer and check whether it starts after the + configured time +9. Drop items into the Minecart and punch the cart to start it, or "sneak+click" the + Minecart to get the items back +10. Dig the empty cart with a second "sneak+click" (as usual) + + +Hopper +------ + +![hopper](https://github.com/joe7575/minecart/blob/master/hopper.png) + +The Hopper is used to load/unload Minecarts. +The Hopper can pull and push items into/out off chests and can drop/pick up items +to/from Minecarts. To unload a Minecart place the hopper below the rail. +To load the Minecart, place the hopper right next to the Minecart. + + +History +------- + +2019-04-19 v0.01 first commit +2019-04-21 v0.02 functional, with junctions support +2019-04-23 v0.03 bug fixes and improvements +2019-04-25 v0.04 Landmarks and Minecart protection added +2019-05-04 v0.05 Route recording protection added +2019-05-22 v0.06 Pick up items from a cart improved +2019-06-23 v0.07 'doc' mod support and German translation added +2020-01-04 v1.00 Hopper added, buffer improved +2020-02-09 v1.01 cart loading bugfix +2020-02-24 v1.02 Hopper improved +2020-03-05 v1.03 Hopper again improved +2020-03-28 v1.04 cart unloading bugfix + diff --git a/minecart/buffer.lua b/minecart/buffer.lua new file mode 100644 index 0000000..e5e32a1 --- /dev/null +++ b/minecart/buffer.lua @@ -0,0 +1,140 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos +local S = minecart.S + +local CYCLE_TIME = 2 + +local StopTime = {} + +local function formspec(pos) + local name = M(pos):get_string("name") + local time = M(pos):get_int("time") + local s = "size[4,4.2]" .. + "label[0,0;Configuration]" .. + "field[0.5,1.2;3.6,1;name;"..S("Station name")..":;"..name.."]".. + "button_exit[1,3.4;2,1;exit;Save]" + if minecart.hopper_enabled then + return s.."field[0.5,2.5;3.6,1;time;"..S("Stop time/sec")..":;"..time.."]" + end + return s +end + +local function remote_station_name(pos) + local route = minecart.get_route(P2S(pos)) + if route and route.dest_pos then + local pos2 = S2P(route.dest_pos) + return M(pos2):get_string("name") + end + return "none" +end + +local function on_punch(pos, node, puncher) + local name = M(pos):get_string("name") + M(pos):set_string("infotext", name..": "..S("connected to").." "..remote_station_name(pos)) + M(pos):set_string("formspec", formspec(pos)) + if minecart.hopper_enabled then + minetest.get_node_timer(pos):start(CYCLE_TIME) + end +end + +minetest.register_node("minecart:buffer", { + description = S("Minecart Railway Buffer"), + tiles = { + 'default_junglewood.png', + 'default_junglewood.png', + 'default_junglewood.png', + 'default_junglewood.png', + 'default_junglewood.png', + 'default_junglewood.png^minecart_buffer.png', + }, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, -4/16, 8/16}, + {-8/16, -4/16, -8/16, 8/16, 0/16, 4/16}, + {-8/16, 0/16, -8/16, 8/16, 4/16, 0/16}, + {-8/16, 4/16, -8/16, 8/16, 8/16, -4/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + after_place_node = function(pos, placer) + M(pos):set_string("owner", placer:get_player_name()) + minecart.del_route(minetest.pos_to_string(pos)) + M(pos):set_string("formspec", formspec(pos)) + if minecart.hopper_enabled then + minetest.get_node_timer(pos):start(CYCLE_TIME) + end + end, + on_timer = function(pos, elapsed) + local time = M(pos):get_int("time") + if time > 0 then + local hash = minetest.hash_node_position(pos) + local param2 = (minetest.get_node(pos).param2 + 2) % 4 + if minecart.check_cart_for_pushing(pos, param2) then + if StopTime[hash] then + if StopTime[hash] < minetest.get_gametime() then + StopTime[hash] = nil + local node = minetest.get_node(pos) + local dir = minetest.facedir_to_dir(node.param2) + minecart.punch_cart(pos, param2, 0, dir) + end + else + StopTime[hash] = minetest.get_gametime() + time + end + else + StopTime[hash] = nil + end + end + return true + end, + after_dig_node = function(pos) + minecart.del_route(minetest.pos_to_string(pos)) + local hash = minetest.hash_node_position(pos) + StopTime[hash] = nil + end, + on_receive_fields = function(pos, formname, fields, player) + if M(pos):get_string("owner") ~= player:get_player_name() then + return + end + if (fields.key_enter == "true" or fields.exit == "Save") and fields.name ~= "" then + M(pos):set_string("name", fields.name) + M(pos):set_int("time", tonumber(fields.time) or 0) + M(pos):set_string("formspec", formspec(pos)) + M(pos):set_string("infotext", fields.name.." "..S("connected to").." "..remote_station_name(pos)) + end + end, + on_punch = on_punch, + paramtype = "light", + sunlight_propagates = true, + on_rotate = screwdriver.disallow, + paramtype2 = "facedir", + groups = {cracky=2, crumbly=2, choppy=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +minetest.register_craft({ + output = "minecart:buffer", + recipe = { + {"dye:red", "", "dye:white"}, + {"default:steel_ingot", "default:junglewood", "default:steel_ingot"}, + }, +}) diff --git a/minecart/cart_api.lua b/minecart/cart_api.lua new file mode 100644 index 0000000..7b384bd --- /dev/null +++ b/minecart/cart_api.lua @@ -0,0 +1,450 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + + Cart API for external cart definitions on a node based model + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local S = minecart.S +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos + +-- register cart here, because entity is already registered +minecart.register_cart_names("minecart:cart", "minecart:cart") + +function minecart.register_cart_entity(entity_name, node_name, entity_def) + entity_def.velocity = {x=0, y=0, z=0} -- only used on punch + entity_def.old_dir = {x=1, y=0, z=0} -- random value to start the cart on punch + entity_def.old_pos = nil + entity_def.old_switch = 0 + entity_def.node_name = node_name + minetest.register_entity(entity_name, entity_def) + -- register node for punching + minecart.register_cart_names(node_name, entity_name) +end + +local function switch_to_node(pos, node_name, owner, param2, cargo) + local node = minetest.get_node(pos) + local rail = node.name + local ndef = minetest.registered_nodes[node_name] + if ndef then + node.name = node_name + node.param2 = param2 + minetest.add_node(pos, node) + M(pos):set_string("removed_rail", rail) + M(pos):set_string("owner", owner) + if ndef.after_place_node then + ndef.after_place_node(pos) + end + if cargo and ndef.set_cargo then + ndef.set_cargo(pos, cargo) + end + end + +end + +function minecart.node_on_place(itemstack, placer, pointed_thing, node_name) + local under = pointed_thing.under + local node = minetest.get_node(under) + local udef = minetest.registered_nodes[node.name] + if udef and udef.on_rightclick and + not (placer and placer:is_player() and + placer:get_player_control().sneak) then + return udef.on_rightclick(under, node, placer, itemstack, + pointed_thing) or itemstack + end + + if not pointed_thing.type == "node" then + return + end + local owner = placer:get_player_name() + local param2 = minetest.dir_to_facedir(placer:get_look_dir()) + if carts:is_rail(pointed_thing.under) then + switch_to_node(pointed_thing.under, node_name, owner, param2) + elseif carts:is_rail(pointed_thing.above) then + switch_to_node(pointed_thing.above, node_name, owner, param2) + else + return + end + + minetest.sound_play({name = "default_place_node_metal", gain = 0.5}, + {pos = pointed_thing.above}) + + if not (creative and creative.is_enabled_for + and creative.is_enabled_for(placer:get_player_name())) then + itemstack:take_item() + end + return itemstack +end + +function minecart.node_on_punch(pos, node, puncher, pointed_thing, entity_name, dir) + local ndef = minetest.registered_nodes[node.name] + local cargo = {} + -- Player digs cart by sneak-punch + if puncher and puncher:get_player_control().sneak then + -- Pick up cart + if ndef.can_dig and ndef.can_dig(pos, puncher) then + local inv = puncher:get_inventory() + if not (creative and creative.is_enabled_for + and creative.is_enabled_for(puncher:get_player_name())) + or not inv:contains_item("main", node.name) then + local leftover = inv:add_item("main", node.name) + -- If no room in inventory add a replacement cart to the world + if not leftover:is_empty() then + minetest.add_item(pos, leftover) + end + end + node.name = M(pos):get_string("removed_rail") + if node.name == "" then + node.name = "carts:rail" + end + minetest.remove_node(pos) + minetest.add_node(pos, node) + end + return + end + -- start cart + node.name = M(pos):get_string("removed_rail") + if node.name ~= "" then + if ndef.get_cargo then + cargo = ndef.get_cargo(pos) + end + minetest.add_node(pos, node) + local obj = minetest.add_entity(pos, entity_name) + local owner = puncher and puncher:get_player_name() + minecart.add_cart_to_monitoring(obj, owner, cargo) + obj:punch(puncher or obj, 1, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 1}, + }, dir) + end +end + +function minecart:on_activate(staticdata, dtime_s) + self.object:set_armor_groups({immortal=1}) +end + + +function minecart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) + --print("on_punch", direction) + local pos = self.object:get_pos() + local vel = self.object:get_velocity() + local stopped = vector.equals(vel, {x=0, y=0, z=0}) + + -- running carts can't be punched + if not stopped then + return + end + + if not self.railtype then + local node = minetest.get_node(pos).name + self.railtype = minetest.get_item_group(node, "connect_to_raillike") + end + + -- Punched by non-authorized player + if puncher and self.owner and self.owner ~= puncher:get_player_name() + and not minetest.check_player_privs(puncher:get_player_name(), "minecart") then + return + end + + -- Punched by non-player + if not puncher or not puncher:is_player() then + local cart_dir = carts:get_rail_direction(pos, direction, nil, nil, self.railtype) + if vector.equals(cart_dir, {x=0, y=0, z=0}) then + return + end + self.velocity = vector.multiply(cart_dir, 2) + self.punched = true + return + end + + -- Player digs cart by sneak-punch + if puncher:get_player_control().sneak then + if self.sound_handle then + minetest.sound_stop(self.sound_handle) + end + + -- Pick up cart + local node_name = self.node_name or "minecart:cart" + local inv = puncher:get_inventory() + if not (creative and creative.is_enabled_for + and creative.is_enabled_for(puncher:get_player_name())) + or not inv:contains_item("main", node_name) then + local leftover = inv:add_item("main", node_name) + -- If no room in inventory add a replacement cart to the world + if not leftover:is_empty() then + minetest.add_item(self.object:get_pos(), leftover) + end + end + minecart.on_dig(self) + self.object:remove() + return + end + + local punch_dir = carts:velocity_to_dir(puncher:get_look_dir()) + punch_dir.y = 0 + local cart_dir = carts:get_rail_direction(pos, punch_dir, nil, nil, self.railtype) + if vector.equals(cart_dir, {x=0, y=0, z=0}) then + return + end + + self.velocity = vector.multiply(cart_dir, 2) + self.old_dir = cart_dir + self.punched = true +end + +-- sound refresh interval = 1.0sec +local function rail_sound(self, dtime) + if not self.sound_ttl then + self.sound_ttl = 1.0 + return + elseif self.sound_ttl > 0 then + self.sound_ttl = self.sound_ttl - dtime + return + end + self.sound_ttl = 1.0 + if self.sound_handle then + local handle = self.sound_handle + self.sound_handle = nil + minetest.after(0.2, minetest.sound_stop, handle) + end + local vel = self.object:get_velocity() or {x=0, y=0, z=0} + local speed = vector.length(vel) + if speed > 0 then + self.sound_handle = minetest.sound_play( + "carts_cart_moving", { + object = self.object, + gain = (speed / carts.speed_max) / 2, + loop = true, + }) + end +end + +local function get_railparams(pos) + local node = minetest.get_node(pos) + return carts.railparams[node.name] or {} +end + +local function rail_on_step(self, dtime) + local vel = self.object:get_velocity() + local pos = self.object:get_pos() + + if self.punched then + minecart.start_run(self, pos, vel, self.driver) + vel = vector.add(vel, self.velocity) + self.object:set_velocity(vel) + self.old_dir.y = 0 + elseif vector.equals(vel, {x=0, y=0, z=0}) then + if minecart.get_route_key(pos) then + local cargo = minecart.stopped(self, pos) + local param2 = minetest.dir_to_facedir(self.old_dir) + switch_to_node(vector.round(pos), self.node_name, self.owner, param2, cargo) + minecart.on_dig(self) + self.object:remove() + end + return + end + + -- cart position correction on slopes + local rot = self.object:get_rotation() + if rot.x ~= 0 then + pos.y = pos.y - 0.5 + end + + local cart_dir = carts:velocity_to_dir(vel) + local same_dir = vector.equals(cart_dir, self.old_dir) + local update = {} + + if self.old_pos and not self.punched and same_dir then + local flo_pos = vector.round(pos) + local flo_old = vector.round(self.old_pos) + if vector.equals(flo_pos, flo_old) then + -- Do not check one node multiple times + return + end + end + + local ctrl, player + + + local stop_wiggle = false + if self.old_pos and same_dir then + -- Detection for "skipping" nodes (perhaps use average dtime?) + -- It's sophisticated enough to take the acceleration in account + local acc = self.object:get_acceleration() + local distance = dtime * (vector.length(vel) + 0.5 * dtime * vector.length(acc)) + + local new_pos, new_dir = carts:pathfinder( + pos, self.old_pos, self.old_dir, distance, ctrl, + self.old_switch, self.railtype + ) + + if new_pos then + -- No rail found: set to the expected position + pos = new_pos + update.pos = true + cart_dir = new_dir + end + elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then + -- Stop wiggle + stop_wiggle = true + end + + local railparams + + -- dir: New moving direction of the cart + -- switch_keys: Currently pressed L/R key, used to ignore the key on the next rail node + local dir, switch_keys = carts:get_rail_direction( + pos, cart_dir, ctrl, self.old_switch, self.railtype + ) + ------------------------------- changed + if switch_keys then + minecart.set_junction(self, pos, dir, switch_keys) + else + dir, switch_keys = minecart.get_junction(self, pos, dir) + end + ------------------------------- changed + local dir_changed = not vector.equals(dir, self.old_dir) + + local new_acc = {x=0, y=0, z=0} + if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then + vel = {x = 0, y = 0, z = 0} + local pos_r = vector.round(pos) + if not carts:is_rail(pos_r, self.railtype) + and self.old_pos then + pos = self.old_pos + elseif not stop_wiggle then + pos = pos_r + else + pos.y = math.floor(pos.y + 0.5) + end + update.pos = true + update.vel = true + else + -- Direction change detected + if dir_changed then + vel = vector.multiply(dir, math.abs(vel.x + vel.z)) + update.vel = true + if dir.y ~= self.old_dir.y then + pos = vector.round(pos) + update.pos = true + end + end + -- Center on the rail + if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then + pos.x = math.floor(pos.x + 0.5) + update.pos = true + end + if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then + pos.z = math.floor(pos.z + 0.5) + update.pos = true + end + + -- Slow down or speed up.. + local acc = dir.y * -4.0 + + -- Get rail for corrected position + railparams = get_railparams(pos) + + -- no need to check for railparams == nil since we always make it exist. + local speed_mod = railparams.acceleration + if speed_mod and speed_mod ~= 0 then + -- Try to make it similar to the original carts mod + acc = acc + speed_mod + else + -- Handbrake or coast + if ctrl and ctrl.down then + acc = acc - 3 + else + acc = acc - 0.4 + end + end + + new_acc = vector.multiply(dir, acc) + end + + -- Limits + local max_vel = carts.speed_max + for _, v in pairs({"x","y","z"}) do + if math.abs(vel[v]) > max_vel then + vel[v] = carts:get_sign(vel[v]) * max_vel + new_acc[v] = 0 + update.vel = true + end + end + + self.object:set_acceleration(new_acc) + self.old_pos = vector.round(pos) + if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then + self.old_dir = vector.new(dir) + end + self.old_switch = switch_keys + + if self.punched then + self.punched = false + update.vel = true + end + + railparams = railparams or get_railparams(pos) + + if not (update.vel or update.pos) then + return + end + + local yaw = 0 + if self.old_dir.x < 0 then + yaw = math.pi/2*3 + elseif self.old_dir.x > 0 then + yaw = math.pi/2 + elseif self.old_dir.z < 0 then + yaw = math.pi + end + --self.object:set_yaw(yaw * math.pi) + + local pitch = 0 + if self.old_dir.z ~= 0 then + if dir.y == -1 then + pitch = -math.pi/4 + elseif dir.y == 1 then + pitch = math.pi/4 + end + else + if dir.y == -1 then + pitch = math.pi/4 + elseif dir.y == 1 then + pitch = -math.pi/4 + end + end + self.object:set_rotation({x = pitch, y = yaw, z = 0}) + + -- cart position correction on slopes + if pitch ~= 0 then + pos.y = pos.y + 0.5 + update.pos = true + end + + if update.vel then + self.object:set_velocity(vel) + end + if update.pos then + if dir_changed then + self.object:set_pos(pos) + else + self.object:move_to(pos) + end + end +end + +function minecart:on_step(dtime) + rail_on_step(self, dtime) + rail_sound(self, dtime) +end diff --git a/minecart/cart_entity.lua b/minecart/cart_entity.lua new file mode 100644 index 0000000..8d03993 --- /dev/null +++ b/minecart/cart_entity.lua @@ -0,0 +1,468 @@ +local S = minecart.S + +local cart_entity = { + initial_properties = { + physical = false, -- otherwise going uphill breaks + collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + visual = "mesh", + mesh = "carts_cart.b3d", + visual_size = {x=1, y=1}, + textures = {"carts_cart.png^minecart_cart.png"}, + static_save = false, + }, + ------------------------------------ changed + owner = nil, + ------------------------------------ changed + driver = nil, + punched = false, -- used to re-send velocity and position + velocity = {x=0, y=0, z=0}, -- only used on punch + old_dir = {x=1, y=0, z=0}, -- random value to start the cart on punch + old_pos = nil, + old_switch = 0, + railtype = nil, + attached_items = {} +} + +function cart_entity:on_rightclick(clicker) + if not clicker or not clicker:is_player() then + return + end + local player_name = clicker:get_player_name() + if self.driver and player_name == self.driver then + self.driver = nil + carts:manage_attachment(clicker, nil) + elseif not self.driver then + self.driver = player_name + carts:manage_attachment(clicker, self.object) + + -- player_api does not update the animation + -- when the player is attached, reset to default animation + player_api.set_animation(clicker, "stand") + end +end + +function cart_entity:on_activate(staticdata, dtime_s) + self.object:set_armor_groups({immortal=1}) +end + +-- 0.5.x and later: When the driver leaves +function cart_entity:on_detach_child(child) + if child and child:get_player_name() == self.driver then + self.driver = nil + end +end + +local function add_cargo_to_player_inv(self, pos, puncher) + local added = false + local inv = puncher:get_inventory() + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do + local entity = obj:get_luaentity() + if not obj:is_player() and entity and entity.name == "__builtin:item" then + obj:remove() + local item = ItemStack(entity.itemstring) + local leftover = inv:add_item("main", item) + if leftover:get_count() > 0 then + minetest.add_item(pos, leftover) + end + added = true + end + end + return added +end + +function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) + local pos = self.object:get_pos() + local vel = self.object:get_velocity() + if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) then + local node = minetest.get_node(pos).name + self.railtype = minetest.get_item_group(node, "connect_to_raillike") + end + -- Punched by non-player + if not puncher or not puncher:is_player() then + local cart_dir = carts:get_rail_direction(pos, direction, nil, nil, self.railtype) + if vector.equals(cart_dir, {x=0, y=0, z=0}) then + return + end + self.velocity = vector.multiply(cart_dir, 2) + self.punched = true + return + end + ------------------------------------ changed + -- Punched by non-authorized player + if puncher and self.owner and self.owner ~= puncher:get_player_name() + and not minetest.check_player_privs(puncher:get_player_name(), "minecart") then + return + end + ------------------------------------ changed + -- Player digs cart by sneak-punch + if puncher:get_player_control().sneak then + if self.sound_handle then + minetest.sound_stop(self.sound_handle) + end + -- Detach driver and items + if self.driver then + if self.old_pos then + self.object:set_pos(self.old_pos) + end + local player = minetest.get_player_by_name(self.driver) + carts:manage_attachment(player, nil) + end + ------------------------------------ changed + if add_cargo_to_player_inv(self, pos, puncher) then + return + end + ------------------------------------ changed + -- Pick up cart + local inv = puncher:get_inventory() + if not (creative and creative.is_enabled_for + and creative.is_enabled_for(puncher:get_player_name())) + or not inv:contains_item("main", "minecart:cart") then + local leftover = inv:add_item("main", "minecart:cart") + -- If no room in inventory add a replacement cart to the world + if not leftover:is_empty() then + minetest.add_item(self.object:get_pos(), leftover) + end + end + ------------------------------------ changed + minecart.on_dig(self) + ------------------------------------ changed + self.object:remove() + return + end + ------------------------------------ changed + minecart.start_recording(self, pos, vel, puncher) + ------------------------------------ changed + -- Player punches cart to alter velocity + if puncher:get_player_name() == self.driver then + if math.abs(vel.x + vel.z) > carts.punch_speed_max then + return + end + end + + local punch_dir = carts:velocity_to_dir(puncher:get_look_dir()) + punch_dir.y = 0 + local cart_dir = carts:get_rail_direction(pos, punch_dir, nil, nil, self.railtype) + if vector.equals(cart_dir, {x=0, y=0, z=0}) then + return + end + + local punch_interval = 1 + if tool_capabilities and tool_capabilities.full_punch_interval then + punch_interval = tool_capabilities.full_punch_interval + end + time_from_last_punch = math.min(time_from_last_punch or punch_interval, punch_interval) + local f = 2 * (time_from_last_punch / punch_interval) + + ------------------------------------ changed + if vector.equals(vel, {x=0, y=0, z=0}) then + self.velocity = vector.multiply(cart_dir, f) + else + self.velocity = {x=0, y=0, z=0} + end + ------------------------------------ changed + self.old_dir = cart_dir + self.punched = true +end + +local function rail_on_step_event(handler, obj, dtime) + if handler then + handler(obj, dtime) + end +end + +-- sound refresh interval = 1.0sec +local function rail_sound(self, dtime) + if not self.sound_ttl then + self.sound_ttl = 1.0 + return + elseif self.sound_ttl > 0 then + self.sound_ttl = self.sound_ttl - dtime + return + end + self.sound_ttl = 1.0 + if self.sound_handle then + local handle = self.sound_handle + self.sound_handle = nil + minetest.after(0.2, minetest.sound_stop, handle) + end + local vel = self.object:get_velocity() + local speed = vector.length(vel) + if speed > 0 then + self.sound_handle = minetest.sound_play( + "carts_cart_moving", { + object = self.object, + gain = (speed / carts.speed_max) / 2, + loop = true, + }) + end +end + +local function get_railparams(pos) + local node = minetest.get_node(pos) + return carts.railparams[node.name] or {} +end + +local v3_len = vector.length +local function rail_on_step(self, dtime) + local vel = self.object:get_velocity() + ------------------------------------ changed + local pos = self.object:get_pos() + minecart.store_next_waypoint(self, pos, vel) + ------------------------------------ changed + if self.punched then + ------------------------------- changed + minecart.start_run(self, pos, vel, self.driver) + ------------------------------- changed + vel = vector.add(vel, self.velocity) + self.object:set_velocity(vel) + self.old_dir.y = 0 + elseif vector.equals(vel, {x=0, y=0, z=0}) then + ------------------------------- changed + minecart.stopped(self, pos) + ------------------------------- changed + return + end + + --local pos = self.object:get_pos() + local cart_dir = carts:velocity_to_dir(vel) + local same_dir = vector.equals(cart_dir, self.old_dir) + local update = {} + + if self.old_pos and not self.punched and same_dir then + local flo_pos = vector.round(pos) + local flo_old = vector.round(self.old_pos) + if vector.equals(flo_pos, flo_old) then + -- Do not check one node multiple times + return + end + end + + local ctrl, player + + -- Get player controls + if self.driver then + player = minetest.get_player_by_name(self.driver) + if player then + ctrl = player:get_player_control() + end + end + + local stop_wiggle = false + if self.old_pos and same_dir then + -- Detection for "skipping" nodes (perhaps use average dtime?) + -- It's sophisticated enough to take the acceleration in account + local acc = self.object:get_acceleration() + local distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc)) + + local new_pos, new_dir = carts:pathfinder( + pos, self.old_pos, self.old_dir, distance, ctrl, + self.old_switch, self.railtype + ) + + if new_pos then + -- No rail found: set to the expected position + pos = new_pos + update.pos = true + cart_dir = new_dir + end + elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then + -- Stop wiggle + stop_wiggle = true + end + + local railparams + + -- dir: New moving direction of the cart + -- switch_keys: Currently pressed L/R key, used to ignore the key on the next rail node + local dir, switch_keys = carts:get_rail_direction( + pos, cart_dir, ctrl, self.old_switch, self.railtype + ) + ------------------------------- changed + if switch_keys then + minecart.set_junction(self, pos, dir, switch_keys) + else + dir, switch_keys = minecart.get_junction(self, pos, dir) + end + ------------------------------- changed + local dir_changed = not vector.equals(dir, self.old_dir) + + local new_acc = {x=0, y=0, z=0} + if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then + vel = {x = 0, y = 0, z = 0} + local pos_r = vector.round(pos) + if not carts:is_rail(pos_r, self.railtype) + and self.old_pos then + pos = self.old_pos + elseif not stop_wiggle then + pos = pos_r + else + pos.y = math.floor(pos.y + 0.5) + end + update.pos = true + update.vel = true + else + -- Direction change detected + if dir_changed then + vel = vector.multiply(dir, math.abs(vel.x + vel.z)) + update.vel = true + if dir.y ~= self.old_dir.y then + pos = vector.round(pos) + update.pos = true + end + end + -- Center on the rail + if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then + pos.x = math.floor(pos.x + 0.5) + update.pos = true + end + if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then + pos.z = math.floor(pos.z + 0.5) + update.pos = true + end + + -- Slow down or speed up.. + local acc = dir.y * -4.0 + + -- Get rail for corrected position + railparams = get_railparams(pos) + + -- no need to check for railparams == nil since we always make it exist. + local speed_mod = railparams.acceleration + if speed_mod and speed_mod ~= 0 then + -- Try to make it similar to the original carts mod + acc = acc + speed_mod + else + -- Handbrake or coast + if ctrl and ctrl.down then + acc = acc - 3 + else + acc = acc - 0.4 + end + end + + new_acc = vector.multiply(dir, acc) + end + + -- Limits + local max_vel = carts.speed_max + for _, v in pairs({"x","y","z"}) do + if math.abs(vel[v]) > max_vel then + vel[v] = carts:get_sign(vel[v]) * max_vel + new_acc[v] = 0 + update.vel = true + end + end + + self.object:set_acceleration(new_acc) + self.old_pos = vector.round(pos) + if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then + self.old_dir = vector.new(dir) + end + self.old_switch = switch_keys + + if self.punched then + -- Collect dropped items + ------------------------------- changed + minecart.attach_cargo(self, pos) + ------------------------------- changed + self.punched = false + update.vel = true + end + + railparams = railparams or get_railparams(pos) + + if not (update.vel or update.pos) then + rail_on_step_event(railparams.on_step, self, dtime) + return + end + + local yaw = 0 + if self.old_dir.x < 0 then + yaw = 0.5 + elseif self.old_dir.x > 0 then + yaw = 1.5 + elseif self.old_dir.z < 0 then + yaw = 1 + end + self.object:set_yaw(yaw * math.pi) + + local anim = {x=0, y=0} + if dir.y == -1 then + anim = {x=1, y=1} + elseif dir.y == 1 then + anim = {x=2, y=2} + end + self.object:set_animation(anim, 1, 0) + + if update.vel then + self.object:set_velocity(vel) + end + if update.pos then + if dir_changed then + self.object:set_pos(pos) + else + self.object:move_to(pos) + end + end + + -- call event handler + rail_on_step_event(railparams.on_step, self, dtime) +end + +function cart_entity:on_step(dtime) + rail_on_step(self, dtime) + rail_sound(self, dtime) +end + +minetest.register_entity("minecart:cart", cart_entity) + +minetest.register_craftitem("minecart:cart", { + description = S("Minecart (Sneak+Click to pick up)"), + inventory_image = minetest.inventorycube("carts_cart_top.png", "carts_cart_side.png^minecart_logo.png", "carts_cart_side.png^minecart_logo.png"), + wield_image = "carts_cart_side.png", + on_place = function(itemstack, placer, pointed_thing) + local under = pointed_thing.under + local node = minetest.get_node(under) + local udef = minetest.registered_nodes[node.name] + if udef and udef.on_rightclick and + not (placer and placer:is_player() and + placer:get_player_control().sneak) then + return udef.on_rightclick(under, node, placer, itemstack, + pointed_thing) or itemstack + end + + if not pointed_thing.type == "node" then + return + end + if carts:is_rail(pointed_thing.under) then + ------------------------------- changed + local cart = minetest.add_entity(pointed_thing.under, "minecart:cart") + minecart.add_cart_to_monitoring(cart, placer:get_player_name()) + ------------------------------- changed + elseif carts:is_rail(pointed_thing.above) then + ------------------------------- changed + local cart = minetest.add_entity(pointed_thing.above, "minecart:cart") + minecart.add_cart_to_monitoring(cart, placer:get_player_name()) + ------------------------------- changed + else + return + end + + minetest.sound_play({name = "default_place_node_metal", gain = 0.5}, + {pos = pointed_thing.above}) + + if not (creative and creative.is_enabled_for + and creative.is_enabled_for(placer:get_player_name())) then + itemstack:take_item() + end + return itemstack + end, +}) + +minetest.register_craft({ + output = "minecart:cart", + recipe = { + {"default:steel_ingot", "default:cobble", "default:steel_ingot"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + }, +}) diff --git a/minecart/depends.txt b/minecart/depends.txt new file mode 100644 index 0000000..a8e9b3e --- /dev/null +++ b/minecart/depends.txt @@ -0,0 +1,3 @@ +default +carts +doc? diff --git a/minecart/doc.lua b/minecart/doc.lua new file mode 100644 index 0000000..b029a6b --- /dev/null +++ b/minecart/doc.lua @@ -0,0 +1,96 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + + +minecart.doc = {} + +if not minetest.get_modpath("doc") then + return +end + +local S = minecart.S + +local summary_doc = table.concat({ + S("Summary"), + "------------", + "", + S("1. Place your rails and build a route with two endpoints. Junctions are allowed as long as each route has its own start and endpoint."), + S("2. Place a Railway Buffer at both endpoints (buffers are always needed, they store the route and timing information)."), + S("3. Give both Railway Buffers unique station names, like Oxford and Cambridge."), + S("4. Drive from buffer to buffer in both directions using a Minecart(!) to record the routes (use 'right-left' keys to control the Minecart)."), + S("5. Punch the buffers to check the connection data (e.g. 'Oxford: connected to Cambridge')."), + S("6. Optional: Configure the Minecart stop time in one or both buffers. The Minecart will then start automatically after the configured time."), + S("7. Optional: Protect your rail network with the Protection Landmarks (one Landmark at least every 16 nodes/meters)."), + S("8. Place a Minecart in front of the buffer and check whether it starts after the configured time."), + S("9. Drop items into the Minecart and punch the cart to start it, or 'sneak+click' the Minecart to get the items back."), + S("10. Dig the empty cart with a second 'sneak+click' (as usual)."), +}, "\n") + +local cart_doc = S("Primary used to transport items. You can drop items into the Minecart and punch the cart to get started. Sneak+click the cart to get the items back") + +local buffer_doc = S("Used as buffer on both rail ends. Needed to be able to record the cart routes") + +local landmark_doc = S("Protect your rails with the Landmarks (one Landmark at least every 16 blocks near the rail)") + +local hopper_doc = S("Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.") + + +local function formspec(data) + if data.image then + local image = "image["..(doc.FORMSPEC.ENTRY_WIDTH - 3)..",0;3,2;"..data.image.."]" + local formstring = doc.widgets.text(data.text, doc.FORMSPEC.ENTRY_START_X, doc.FORMSPEC.ENTRY_START_Y+1.6, doc.FORMSPEC.ENTRY_WIDTH, doc.FORMSPEC.ENTRY_HEIGHT - 1.6) + return image..formstring + elseif data.item then + local box = "box["..(doc.FORMSPEC.ENTRY_WIDTH - 1.6)..",0;1,1.1;#BBBBBB]" + local image = "item_image["..(doc.FORMSPEC.ENTRY_WIDTH - 1.5)..",0.1;1,1;"..data.item.."]" + local formstring = doc.widgets.text(data.text, doc.FORMSPEC.ENTRY_START_X, doc.FORMSPEC.ENTRY_START_Y+0.8, doc.FORMSPEC.ENTRY_WIDTH, doc.FORMSPEC.ENTRY_HEIGHT - 0.8) + return box..image..formstring + else + return doc.entry_builders.text(data.text) + end +end + +doc.add_category("minecart", +{ + name = S("Minecart"), + description = S("Minecart, the lean railway transportation automation system"), + sorting = "custom", + sorting_data = {"summary", "cart"}, + build_formspec = formspec, +}) + +doc.add_entry("minecart", "summary", { + name = S("Summary"), + data = {text=summary_doc, image="minecart_doc_image.png"}, +}) + +doc.add_entry("minecart", "cart", { + name = S("Minecart Cart"), + data = {text=cart_doc, item="minecart:cart"}, +}) + +doc.add_entry("minecart", "buffer", { + name = S("Minecart Railway Buffer"), + data = {text=buffer_doc, item="minecart:buffer"}, +}) + +doc.add_entry("minecart", "landmark", { + name = S("Minecart Landmark"), + data = {text = landmark_doc, item="minecart:landmark"}, +}) + +if minecart.hopper_enabled then + doc.add_entry("minecart", "hopper", { + name = S("Minecart Hopper"), + data = {text=hopper_doc, item="minecart:hopper"}, + }) +end diff --git a/minecart/hopper.lua b/minecart/hopper.lua new file mode 100644 index 0000000..49f045b --- /dev/null +++ b/minecart/hopper.lua @@ -0,0 +1,171 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +local NUM_ITEMS = 4 + +-- for lazy programmers +local M = minetest.get_meta +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos +local S = minecart.S + +local function scan_for_objects(pos, inv) + for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do + local lua_entity = object:get_luaentity() + if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then + if lua_entity.itemstring ~= "" then + local stack = ItemStack(lua_entity.itemstring) + if inv:room_for_item("main", stack) then + inv:add_item("main", stack) + object:remove() + end + end + end + end +end + +local function pull_push_item(pos, param2) + local items = minecart.take_items(pos, param2, NUM_ITEMS) + if items then + local leftover = minecart.put_items(pos, param2, items) + if leftover then + -- place item back + minecart.untake_items(pos, param2, leftover) + return false + end + return true + else + items = minecart.take_items({x=pos.x, y=pos.y+1, z=pos.z}, nil, NUM_ITEMS) + if items then + local leftover = minecart.put_items(pos, param2, items) + if leftover then + -- place item back + minecart.untake_items({x=pos.x, y=pos.y+1, z=pos.z}, nil, leftover) + return false + end + return true + end + end + return false +end + +local function push_item(pos, inv, param2) + local taken = minecart.inv_take_items(inv, "main", NUM_ITEMS) + if taken then + local leftover = minecart.put_items(pos, param2, taken) + if leftover then + inv:add_item("main", leftover) + end + end +end + +local formspec = "size[8,6.5]".. + "list[context;main;3,0;2,2;]".. + "list[current_player;main;0,2.7;8,4;]".. + "listring[context;main]".. + "listring[current_player;main]" + +minetest.register_node("minecart:hopper", { + description = S("Minecart Hopper"), + tiles = { + -- up, down, right, left, back, front + "default_cobble.png^minecart_appl_hopper_top.png", + "default_cobble.png^minecart_appl_hopper.png", + "default_cobble.png^minecart_appl_hopper_right.png", + "default_cobble.png^minecart_appl_hopper.png", + "default_cobble.png^minecart_appl_hopper.png", + "default_cobble.png^minecart_appl_hopper.png", + }, + + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, 2/16, -8/16, 8/16, 8/16, -6/16}, + {-8/16, 2/16, 6/16, 8/16, 8/16, 8/16}, + {-8/16, 2/16, -8/16, -6/16, 8/16, 8/16}, + { 6/16, 2/16, -8/16, 8/16, 8/16, 8/16}, + {-6/16, 0/16, -6/16, 6/16, 3/16, 6/16}, + {-5/16, -4/16, -5/16, 5/16, 0/16, 5/16}, + { 0/16, -4/16, -3/16, 11/16, 2/16, 3/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-8/16, 2/16, -8/16, 8/16, 8/16, 8/16}, + {-5/16, -4/16, -5/16, 5/16, 0/16, 5/16}, + { 0/16, -4/16, -3/16, 11/16, 2/16, 3/16}, + }, + }, + + on_construct = function(pos) + local inv = M(pos):get_inventory() + inv:set_size('main', 4) + end, + + after_place_node = function(pos, placer) + local meta = M(pos) + meta:set_string("owner", placer:get_player_name()) + meta:set_string("formspec", formspec) + minetest.get_node_timer(pos):start(2) + end, + + on_timer = function(pos, elapsed) + local inv = M(pos):get_inventory() + local param2 = minetest.get_node(pos).param2 + param2 = (param2 + 1) % 4 -- output is on the right + if not pull_push_item(pos, param2) then + scan_for_objects({x=pos.x, y=pos.y+1, z=pos.z}, inv) + push_item(pos, inv, param2) + end + return true + end, + + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + minetest.get_node_timer(pos):start(2) + return stack:get_count() + end, + + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + return stack:get_count() + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + for _,stack in ipairs(oldmetadata.inventory.main) do + minetest.add_item(pos, stack) + end + end, + + paramtype = "light", + sunlight_propagates = true, + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + + +minetest.register_craft({ + output = "minecart:hopper", + recipe = { + {"default:stone", "", "default:stone"}, + {"default:stone", "default:gold_ingot", "default:stone"}, + {"", "default:stone", ""}, + }, +}) diff --git a/minecart/hopper.png b/minecart/hopper.png new file mode 100644 index 0000000..a773f96 Binary files /dev/null and b/minecart/hopper.png differ diff --git a/minecart/i18n.py b/minecart/i18n.py new file mode 100755 index 0000000..6c7ffed --- /dev/null +++ b/minecart/i18n.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Generate a template file for translation purposes + + +import os, fnmatch, re + +pattern = re.compile(r'[ \.=^\t]S\("(.+?)"\)', re.DOTALL) + + +def gen_template(templ_file, lkeyStrings): + lOut = [] + lkeyStrings = list(set(lkeyStrings)) + lkeyStrings.sort() + for s in lkeyStrings: + lOut.append("%s=" % s) + file(templ_file, "wt").write("\n".join(lOut)) + +def read_strings(fname): + lOut = [] + text = file(fname).read() + for s in pattern.findall(text): + lOut.append(s) + return lOut + +def i18n(templ_file): + lOut = [] + for root, dirs, files in os.walk('./'): + for name in files: + if fnmatch.fnmatch(name, "*.lua"): + fname = os.path.join(root, name) + print fname + lOut.extend(read_strings(fname)) + gen_template(templ_file, lOut) + +i18n("./locale/template.txt") +print "Done.\n" diff --git a/minecart/init.lua b/minecart/init.lua new file mode 100644 index 0000000..3882bbb --- /dev/null +++ b/minecart/init.lua @@ -0,0 +1,36 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +minecart = {} + +-- Version for compatibility checks, see readme.md/history +minecart.version = 1.05 + +minecart.hopper_enabled = minetest.settings:get_bool("minecart_hopper_enabled") ~= false + +print("minecart_hopper_enabled", dump(minetest.settings:get_bool("minecart_hopper_enabled"))) + +minecart.S = minetest.get_translator("minecart") +local MP = minetest.get_modpath("minecart") +dofile(MP.."/storage.lua") +dofile(MP.."/lib.lua") +dofile(MP.."/routes.lua") +dofile(MP.."/cart_entity.lua") +dofile(MP.."/buffer.lua") +dofile(MP.."/protection.lua") +dofile(MP.."/cart_api.lua") + +if minecart.hopper_enabled then + dofile(MP.."/hopper.lua") +end +dofile(MP.."/doc.lua") +minetest.log("info", "[MOD] Minecart loaded") diff --git a/minecart/lib.lua b/minecart/lib.lua new file mode 100644 index 0000000..dea1d94 --- /dev/null +++ b/minecart/lib.lua @@ -0,0 +1,274 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos +local S = minecart.S + +local RegisteredInventories = {} + +local param2_to_dir = {[0]= + {x=0, y=0, z=1}, + {x=1, y=0, z=0}, + {x=0, y=0, z=-1}, + {x=-1, y=0, z=0}, + {x=0, y=-1, z=0}, + {x=0, y=1, z=0} +} + +-- Registered carts +local tValidCarts = {} -- [] = +local lValidCartNodes = {} +local tValidCartEntities = {} + +minetest.tValidCarts = tValidCarts + +function minecart.register_cart_names(cart_name_stopped, cart_name_running) + tValidCarts[cart_name_stopped] = cart_name_running + + if minetest.registered_nodes[cart_name_stopped] then + lValidCartNodes[#lValidCartNodes+1] = cart_name_stopped + end + if minetest.registered_nodes[cart_name_running] then + lValidCartNodes[#lValidCartNodes+1] = cart_name_running + end + if minetest.registered_entities[cart_name_stopped] then + tValidCartEntities[cart_name_stopped] = true + end + if minetest.registered_entities[cart_name_running] then + tValidCartEntities[cart_name_running] = true + end +end + +local function is_air_like(name) + local ndef = minetest.registered_nodes[name] + if ndef and ndef.buildable_to then + return true + end + return false +end + +function minecart.get_next_node(pos, param2) + local pos2 = param2 and vector.add(pos, param2_to_dir[param2]) or pos + local node = minetest.get_node(pos2) + return pos2, node +end + +-- check if cart can be pushed +function minecart.check_cart_for_pushing(pos, param2, radius) + local pos2 = param2 and vector.add(pos, param2_to_dir[param2]) or pos + + if minetest.find_node_near(pos2, radius or 0.5, lValidCartNodes, true) then + return true + end + + for _, object in pairs(minetest.get_objects_inside_radius(pos2, radius or 0.5)) do + --print(object:get_entity_name(), tValidCartEntities[object:get_entity_name()]) + if tValidCartEntities[object:get_entity_name()] then + local vel = object:get_velocity() + if vector.equals(vel, {x=0, y=0, z=0}) then -- still standing? + return true + end + end + end + + return false +end + +-- check if cargo can be loaded +function minecart.check_cart_for_loading(pos, param2, radius) + local pos2 = param2 and vector.add(pos, param2_to_dir[param2]) or pos + + if minetest.find_node_near(pos2, radius or 0.5, lValidCartNodes, true) then + return true + end + + for _, object in pairs(minetest.get_objects_inside_radius(pos2, radius or 0.5)) do + if object:get_entity_name() == "minecart:cart" then + local vel = object:get_velocity() + if vector.equals(vel, {x=0, y=0, z=0}) then -- still standing? + return true + end + end + end + + return false +end + +local get_next_node = minecart.get_next_node +local check_cart_for_loading = minecart.check_cart_for_loading +local check_cart_for_pushing = minecart.check_cart_for_pushing + +-- Take the given number of items from the inv. +-- Returns nil if ItemList is empty. +function minecart.inv_take_items(inv, listname, num) + if inv:is_empty(listname) then + return nil + end + local size = inv:get_size(listname) + for idx = 1, size do + local items = inv:get_stack(listname, idx) + if items:get_count() > 0 then + local taken = items:take_item(num) + inv:set_stack(listname, idx, items) + return taken + end + end + return nil +end + +function minecart.take_items(pos, param2, num) + local npos, node + if param2 then + npos, node = get_next_node(pos, (param2 + 2) % 4) + else + npos, node = pos, minetest.get_node(pos) + end + local def = RegisteredInventories[node.name] + local owner = M(pos):get_string("owner") + local inv = minetest.get_inventory({type="node", pos=npos}) + + if def and inv and (not def.allow_take or def.allow_take(npos, nil, owner)) then + return minecart.inv_take_items(inv, def.take_listname, num) + else + local ndef = minetest.registered_nodes[node.name] + if ndef and ndef.minecart_hopper_takeitem then + return ndef.minecart_hopper_takeitem(npos, num) + end + end +end + +function minecart.put_items(pos, param2, stack) + local npos, node = get_next_node(pos, param2) + local def = RegisteredInventories[node.name] + local owner = M(pos):get_string("owner") + local inv = minetest.get_inventory({type="node", pos=npos}) + + if def and inv and (not def.allow_put or def.allow_put(npos, stack, owner)) then + local leftover = inv:add_item(def.put_listname, stack) + if leftover:get_count() > 0 then + return leftover + end + elseif is_air_like(node.name) or check_cart_for_loading(npos) then + minetest.add_item(npos, stack) + else + local ndef = minetest.registered_nodes[node.name] + if ndef and ndef.minecart_hopper_additem then + local leftover = ndef.minecart_hopper_additem(npos, stack) + if leftover:get_count() > 0 then + return leftover + end + else + return stack + end + end +end + +function minecart.untake_items(pos, param2, stack) + local npos, node + if param2 then + npos, node = get_next_node(pos, (param2 + 2) % 4) + else + npos, node = pos, minetest.get_node(pos) + end + local def = RegisteredInventories[node.name] + local inv = minetest.get_inventory({type="node", pos=npos}) + + if def then + return inv and inv:add_item(def.put_listname, stack) + else + local ndef = minetest.registered_nodes[node.name] + if ndef and ndef.minecart_hopper_untakeitem then + return ndef.minecart_hopper_untakeitem(npos, stack) + end + end +end + +function minecart.punch_cart(pos, param2, radius, dir) + local pos2 = param2 and vector.add(pos, param2_to_dir[param2]) or pos + + local pos3 = minetest.find_node_near(pos2, radius or 0.5, lValidCartNodes, true) + if pos3 then + local node = minetest.get_node(pos3) + --print(node.name) + minecart.node_on_punch(pos3, node, nil, nil, tValidCarts[node.name], dir) + return true + end + + for _, object in pairs(minetest.get_objects_inside_radius(pos2, radius or 0.5)) do + if tValidCartEntities[object:get_entity_name()] then + object:punch(object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 1}, + }, dir) + break -- start only one cart + end + end +end + +-- Register inventory node for hopper access +-- (for examples, see below) +function minecart.register_inventory(node_names, def) + for _, name in ipairs(node_names) do + RegisteredInventories[name] = { + allow_put = def.put and def.put.allow_inventory_put, + put_listname = def.put and def.put.listname, + allow_take = def.take and def.take.allow_inventory_take, + take_listname = def.take and def.take.listname, + } + end +end + +minecart.register_inventory({"default:chest", "default:chest_open"}, { + put = { + listname = "main", + }, + take = { + listname = "main", + }, +}) + +minecart.register_inventory({"default:chest_locked", "default:chest_locked_open"}, { + put = { + allow_inventory_put = function(pos, stack, player_name) + local owner = M(pos):get_string("owner") + return owner == player_name + end, + listname = "main", + }, + take = { + allow_inventory_take = function(pos, stack, player_name) + local owner = M(pos):get_string("owner") + return owner == player_name + end, + listname = "main", + }, +}) + +minecart.register_inventory({"minecart:hopper"}, { + put = { + allow_inventory_put = function(pos, stack, player_name) + local owner = M(pos):get_string("owner") + return owner == player_name + end, + listname = "main", + }, + take = { + allow_inventory_take = function(pos, stack, player_name) + local owner = M(pos):get_string("owner") + return owner == player_name + end, + listname = "main", + }, +}) diff --git a/minecart/license.txt b/minecart/license.txt new file mode 100644 index 0000000..6c5beb4 --- /dev/null +++ b/minecart/license.txt @@ -0,0 +1,54 @@ + +License of source code +---------------------- + +The MIT License (MIT) +Copyright (C) 2012-2016 PilzAdam +Copyright (C) 2014-2016 SmallJoker +Copyright (C) 2012-2016 Various Minetest developers and contributors + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +For more details: +https://opensource.org/licenses/MIT + + +Licenses of media +----------------- + +CC-0, see: https://creativecommons.org/share-your-work/public-domain/cc0/, except +if other license is mentioned. + + +Authors +--------- +Originally from PixelBOX (Gambit): + carts_cart_side.png + carts_cart_top.png + carts_cart_front.png* + carts_cart.png* + +sofar + stujones11: + carts_cart.b3d and carts_cart.blend + +hexafraction, modified by sofar + carts_rail_*.png + +http://www.freesound.org/people/YleArkisto/sounds/253159/ - YleArkisto - CC-BY-3.0 + carts_cart_moving.*.ogg diff --git a/minecart/locale/minecart.de.tr b/minecart/locale/minecart.de.tr new file mode 100644 index 0000000..9c7f0ac --- /dev/null +++ b/minecart/locale/minecart.de.tr @@ -0,0 +1,35 @@ +# textdomain: minecart + +1. Place your rails and build a route with two endpoints. Junctions are allowed as long as each route has its own start and endpoint.=1. Baue eine Schienenstrecke mit zwei Enden. Kreuzungen sind zulässig, solange jede Route ihre eigenen Start- und Endpunkte hat. +10. Dig the empty cart with a second 'sneak+click' (as usual).=10. Klicke erneut mit gedrückter Shift-Taste auf den Wagen, um diesen zu entfernen. +2. Place a Railway Buffer at both endpoints (buffers are always needed, they store the route and timing information).=2. Platziere einen Prellbock an beide Schienenenden (Prellböcke sind zwingend notwendig, sie speichern die Routen- und Zeit-Informationen). +3. Give both Railway Buffers unique station names, like Oxford and Cambridge.=3. Gib beiden Prellböcken eindeutige Stationsnamen wie: Stuttgart und München. +4. Drive from buffer to buffer in both directions using a Minecart(!) to record the routes (use 'right-left' keys to control the Minecart).=4. Um eine Route aufzuzeichnen, fahre die Route in beide Richtungen von Prellbock zu Prellbock mit einem Minecart Wagen(!). Nutze 'links-rechts' Tasten zur Steuerung. +5. Punch the buffers to check the connection data (e.g. 'Oxford: connected to Cambridge').=5. Schlage auf die Prellböcke um die Verbindungsdaten zu prüfen (bspw.: 'München: verbunden mit Stuttgart') +6. Optional: Configure the Minecart stop time in one or both buffers. The Minecart will then start automatically after the configured time.=6. Optional: Konfiguriere die Wagenwartezeit in einem oder in beiden Prellböcken. Der Wagen startet dann nach dieser Zeit automatisch. +7. Optional: Protect your rail network with the Protection Landmarks (one Landmark at least every 16 nodes/meters).=7. Optional: Schütze deine Schienen mit Hilfe der Meilensteine (ein Meilenstein mindestens alle 16 Blöcke). +8. Place a Minecart in front of the buffer and check whether it starts after the configured time.=8. Platziere einen Wagen direkt vor einem Prellbock und prüfe, ob er nach der konfigurierten Zeit startet. +9. Drop items into the Minecart and punch the cart to start it, or 'sneak+click' the Minecart to get the items back.=9: Lege Gegenstände in ein Wagen (Taste Q) und starte dann den Wagen durch Anklicken. Klicke mit gedrückter Shift-Taste auf den Wagen, um Gegenstände wieder auszuladen. +A minecart running through unloaded areas, mainly used for item transportation=Ein Wagen, welcher auch durch nicht geladene Kartenbereiche fährt, primär für den Transport von Gegenständen genutzt (Lore) +Allow to dig/place rails in Minecart Landmark areas=Erlaubt dir, Schienen in Meilensteinbereichen zu setzen/zu entfernen +Minecart=Minecart +Minecart (Sneak+Click to pick up)=Minecart (Shift+Klick zum Entfernen des Carts) +Minecart Cart=Wagen +Minecart Hopper=Minecart Hopper +Minecart Landmark=Minecart Meilenstein +Minecart Railway Buffer=Minecart Prellbock +Minecart, the lean railway transportation automation system=Minecart, das schlanke Schienentransport Automatisierungssystem +Primary used to transport items. You can drop items into the Minecart and punch the cart to get started. Sneak+click the cart to get the items back=Primär für den Transport von Gegenständen genutzt. Du kannst Gegenstände in ein Cart legen (Taste Q) und dann den Wagen durch Anklicken starten. Klicke mit gedrückter Shift-Taste auf den Wagen, um die Gegenstände wieder auszuladen +Protect your rails with the Landmarks (one Landmark at least every 16 blocks near the rail)=Schütze deine Schienen mit Hilfe der Meilensteine (ein Meilenstein mindestens alle 16 Blöcke der Strecke entlang) +Station name=Stationsname +Stop time/sec=Haltezeit/s +Summary=Zusammenfassung +Used as buffer on both rail ends. Needed to be able to record the cart routes=Preckblöcke müssen an beiden Schienenenden platziert sein, so dass Aufzeichnungen der Strecke gemacht werden können. +Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.=Um Wagen zu be- und entladen. Der Hopper kann Gegenstände aus Kisten Holen und legen, sowie diese in Wagen fallen lassen bzw. aus Wagen entnehmen. Um einen Wagen zu entladen, muss der Hopper unter die Schiene platziert werden. Um einen Wagen zu beladen, muss der Hopper direkt neben die Schiene platziert werden. +[minecart] Area is protected!=[minecart] Bereich ist geschützt! +[minecart] Please start at a Railway Buffer!=[minecart] Bitte starte beim Prellbock! +[minecart] Recording canceled!=[minecart] Aufzeichnung abgebrochen! +[minecart] Route stored!=[minecart] Strecke gespeichert +[minecart] Start route recording!=[minecart] Starte die Streckenaufzeichnung! +connected to=verbunden mit + diff --git a/minecart/locale/template.txt b/minecart/locale/template.txt new file mode 100644 index 0000000..eb95b9c --- /dev/null +++ b/minecart/locale/template.txt @@ -0,0 +1,31 @@ +1. Place your rails and build a route with two endpoints. Junctions are allowed as long as each route has its own start and endpoint.= +10. Dig the empty cart with a second 'sneak+click' (as usual).= +2. Place a Railway Buffer at both endpoints (buffers are always needed, they store the route and timing information).= +3. Give both Railway Buffers unique station names, like Oxford and Cambridge.= +4. Drive from buffer to buffer in both directions using a Minecart(!) to record the routes (use 'right-left' keys to control the Minecart).= +5. Punch the buffers to check the connection data (e.g. 'Oxford: connected to Cambridge').= +6. Optional: Configure the Minecart stop time in one or both buffers. The Minecart will then start automatically after the configured time.= +7. Optional: Protect your rail network with the Protection Landmarks (one Landmark at least every 16 nodes/meters).= +8. Place a Minecart in front of the buffer and check whether it starts after the configured time.= +9. Drop items into the Minecart and punch the cart to start it, or 'sneak+click' the Minecart to get the items back.= +Allow to dig/place rails in Minecart Landmark areas= +Minecart= +Minecart (Sneak+Click to pick up)= +Minecart Cart= +Minecart Hopper= +Minecart Landmark= +Minecart Railway Buffer= +Minecart, the lean railway transportation automation system= +Primary used to transport items. You can drop items into the Minecart and punch the cart to get started. Sneak+click the cart to get the items back= +Protect your rails with the Landmarks (one Landmark at least every 16 blocks near the rail)= +Station name= +Stop time/sec= +Summary= +Used as buffer on both rail ends. Needed to be able to record the cart routes= +Used to load/unload Minecart. The Hopper can push/pull items to/from chests and drop/pickup items to/from Minecarts. To unload a Minecart place the hopper below the rail. To load the Minecart, place the hopper right next to the Minecart.= +[minecart] Area is protected!= +[minecart] Please start at a Railway Buffer!= +[minecart] Recording canceled!= +[minecart] Route stored!= +[minecart] Start route recording!= +connected to= \ No newline at end of file diff --git a/minecart/mod.conf b/minecart/mod.conf new file mode 100644 index 0000000..7b9a9ac --- /dev/null +++ b/minecart/mod.conf @@ -0,0 +1,4 @@ +name=minecart +depends = default,carts +optional_depends = doc +description = Minecart, the lean railway transportation automation system diff --git a/minecart/protection.lua b/minecart/protection.lua new file mode 100644 index 0000000..0f93d35 --- /dev/null +++ b/minecart/protection.lua @@ -0,0 +1,198 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +local S = minecart.S +local RANGE = 8 + +local IsNodeUnderObservation = {} + +-- Register all nodes, which should be protected by the "minecart:landmark" +function minecart.register_protected_node(name) + IsNodeUnderObservation[name] = true +end + +local function landmark_found(pos, name, range) + local pos1 = {x=pos.x-range, y=pos.y-range, z=pos.z-range} + local pos2 = {x=pos.x+range, y=pos.y+range, z=pos.z+range} + for _,npos in ipairs(minetest.find_nodes_in_area(pos1, pos2, {"minecart:landmark"})) do + if minetest.get_meta(npos):get_string("owner") ~= name then + return true + end + end + return false +end + +local function is_protected(pos, name, range) + if minetest.check_player_privs(name, "minecart") + or not landmark_found(pos, name, range) then + return false + end + return true +end + +local old_is_protected = minetest.is_protected + +function minetest.is_protected(pos, name) + local node = minetest.get_node(pos) + if IsNodeUnderObservation[node.name] and is_protected(pos, name, RANGE) then + return true + end + return old_is_protected(pos, name) +end + +minetest.register_node("minecart:landmark", { + description = S("Minecart Landmark"), + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-3/16, -8/16, -3/16, 3/16, 4/16, 3/16}, + {-2/16, 4/16, -3/16, 2/16, 5/16, 3/16}, + }, + }, + tiles = { + 'default_mossycobble.png', + 'default_mossycobble.png', + 'default_mossycobble.png', + 'default_mossycobble.png', + 'default_mossycobble.png^minecart_protect.png', + 'default_mossycobble.png^minecart_protect.png', + }, + after_place_node = function(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name()) + if is_protected(pos, placer:get_player_name(), RANGE+3) then + minetest.remove_node(pos) + return true + end + end, + + can_dig = function(pos, digger) + local meta = minetest.get_meta(pos) + if meta:get_string("owner") == digger:get_player_name() then + return true + end + if minetest.check_player_privs(digger:get_player_name(), "minecart") then + return true + end + minetest.chat_send_player(digger:get_player_name(), + S("[minecart] Area is protected!").." (owner: "..meta:get_string("owner")..")") + return false + end, + + paramtype2 = "facedir", + sunlight_propagates = true, + groups = {cracky = 3, stone = 1}, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_craft({ + output = "minecart:landmark 6", + recipe = { + {"", "default:mossycobble", ""}, + {"", "default:mossycobble", ""}, + {"", "default:mossycobble", ""}, + }, +}) + +minetest.register_node("minecart:ballast", { + description = "Minecart Ballast", + tiles = {"minecart_ballast.png"}, + groups = {crumbly = 1, cracky = 3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_node("minecart:ballast_slope", { + description = "Minecart Ballast Slope", + tiles = {"minecart_ballast.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, -4/16, 8/16}, + {-8/16, -4/16, -4/16, 8/16, 0/16, 8/16}, + {-8/16, 0/16, 0/16, 8/16, 4/16, 8/16}, + {-8/16, 4/16, 4/16, 8/16, 8/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + paramtype2 = "facedir", + groups = {crumbly = 1, cracky = 3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_node("minecart:ballast_ramp", { + description = "Minecart Ballast Ramp", + tiles = {"minecart_ballast.png"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + {-8/16, -4/16, -4/16, 8/16, 12/16, 8/16}, + {-8/16, 0/16, 0/16, 8/16, 16/16, 8/16}, + {-8/16, 4/16, 4/16, 8/16, 20/16, 8/16}, + }, + }, + selection_box = { + type = "fixed", + fixed = {-8/16, -8/16, -8/16, 8/16, 8/16, 8/16}, + }, + paramtype2 = "facedir", + groups = {crumbly = 1, cracky = 3}, + sounds = default.node_sound_stone_defaults(), +}) + +minetest.register_craft({ + output = "minecart:ballast 6", + recipe = { + {"", "", ""}, + {"default:cobble", "default:stone", "default:cobble"}, + {"default:cobble", "default:stone", "default:cobble"}, + }, +}) + +minetest.register_craft({ + output = "minecart:ballast_slope 6", + recipe = { + {"", "", "default:cobble"}, + {"", "default:stone", "default:cobble"}, + {"default:cobble", "default:stone", "default:cobble"}, + }, +}) + +minetest.register_craft({ + output = "minecart:ballast_ramp 2", + recipe = { + {"", "", ""}, + {"minecart:ballast_slope", "", ""}, + {"minecart:ballast", "", ""}, + }, +}) + +minetest.register_privilege("minecart", { + description = S("Allow to dig/place rails in Minecart Landmark areas"), + give_to_singleplayer = false, + give_to_admin = true, +}) + +minecart.register_protected_node("carts:rail") +minecart.register_protected_node("carts:powerrail") +minecart.register_protected_node("carts:brakerail") +minecart.register_protected_node("minecart:buffer") +minecart.register_protected_node("minecart:ballast") +minecart.register_protected_node("minecart:ballast_slope") +minecart.register_protected_node("minecart:ballast_ramp") diff --git a/minecart/routes.lua b/minecart/routes.lua new file mode 100644 index 0000000..556286f --- /dev/null +++ b/minecart/routes.lua @@ -0,0 +1,291 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos +local S = minecart.S + +local CartsOnRail = minecart.CartsOnRail + +-- +-- Helper functions +-- +local function get_object_id(object) + for id, entity in pairs(minetest.luaentities) do + if entity.object == object then + return id + end + end +end + +local function get_route_key(pos, player_name) + local pos1 = minetest.find_node_near(pos, 1, {"minecart:buffer"}) + if pos1 then + local meta = minetest.get_meta(pos1) + if player_name == nil or player_name == meta:get_string("owner") then + return P2S(pos1) + end + end +end + +-- +-- Recording +-- +function minecart.add_cart_to_monitoring(obj, owner, cargo) + --print("add_cart_to_monitoring", dump(cargo)) + local self = obj:get_luaentity() + self.myID = get_object_id(obj) + self.owner = owner + local pos = self.object:get_pos() + CartsOnRail[self.myID] = { + start_key = get_route_key(pos), + start_pos = pos, + stopped = true, + owner = owner, + entity_name = self.name, + cargo = cargo, + } + return self.myID +end + +function minecart.start_recording(self, pos, vel, puncher) + -- Player punches cart to start the trip + if puncher:get_player_name() == self.driver and vector.equals(vel, {x=0, y=0, z=0}) then + self.start_key = get_route_key(pos, self.driver) + if self.start_key then + self.waypoints = {} + self.junctions = {} + self.recording = true + self.next_time = minetest.get_us_time() + 1000000 + minetest.chat_send_player(self.driver, S("[minecart] Start route recording!")) + end + end +end + +function minecart.store_next_waypoint(self, pos, vel) + if self.start_key and self.recording and self.driver and + self.next_time < minetest.get_us_time() then + self.next_time = minetest.get_us_time() + 1000000 + self.waypoints[#self.waypoints+1] = {P2S(vector.round(pos)), P2S(vector.round(vel))} + + local dest_pos = get_route_key(pos, self.driver) + if vector.equals(vel, {x=0, y=0, z=0}) and dest_pos then + if self.start_key ~= dest_pos then + local route = { + waypoints = self.waypoints, + dest_pos = dest_pos, + junctions = self.junctions, + } + minecart.store_route(self.start_key, route) + minetest.chat_send_player(self.driver, S("[minecart] Route stored!")) + else + minetest.chat_send_player(self.driver, S("[minecart] Recording canceled!")) + end + self.recording = false + self.waypoints = nil + self.junctions = nil + end + elseif self.recording and not self.driver then + self.recording = false + self.waypoints = nil + self.junctions = nil + end +end + +function minecart.set_junction(self, pos, dir, switch_keys) + local junctions = CartsOnRail[self.myID] and CartsOnRail[self.myID].junctions + if junctions then + if self.junctions then + self.junctions[minetest.pos_to_string(vector.round(pos))] = {dir, switch_keys} + end + end +end + +function minecart.get_junction(self, pos, dir) + local junctions = CartsOnRail[self.myID] and CartsOnRail[self.myID].junctions + if junctions then + local data = junctions[minetest.pos_to_string(vector.round(pos))] + if data then + return data[1], data[2] + end + end + return dir +end + +-- +-- Normal operation +-- +function minecart.start_run(self, pos, vel, driver) + if vector.equals(vel, {x=0, y=0, z=0}) then + local start_key = get_route_key(pos) + if not start_key then + if driver then -- Punched from inside the cart + -- Don't start the cart + self.velocity = {x=0, y=0, z=0} + minetest.chat_send_player(driver, S("[minecart] Please start at a Railway Buffer!")) + return + end + -- Add also carts without route to be able to restore last pos/vel + minetest.log("info", "[minecart] Cart "..self.myID.." started.") + --print("start_run", dump(CartsOnRail[self.myID])) + CartsOnRail[self.myID].stopped = false + else -- Add cart to monitoring + minetest.log("info", "[minecart] Cart "..self.myID.." started.") + --print("start_run", dump(CartsOnRail[self.myID])) + local item = CartsOnRail[self.myID] + item.start_time = minetest.get_gametime() + item.start_key = start_key + item.stopped = false + item.junctions = minecart.get_route(start_key).junctions + end + end +end + +function minecart.attach_cargo(self, pos) + local data = CartsOnRail[self.myID] + if data then + data.attached_items = {} + for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do + local entity = obj_:get_luaentity() + if not obj_:is_player() and entity and entity.name == "__builtin:item" then + obj_:remove() + data.attached_items[#data.attached_items + 1] = entity.itemstring + end + end + end +end + +function minecart.detach_cargo(self, pos, data) + -- Spawn loaded items again + if data.attached_items then + for _,item in ipairs(data.attached_items) do + minetest.add_item(pos, ItemStack(item)) + end + end +end + +function minecart.stopped(self, pos) + local data = CartsOnRail[self.myID] + if data and not data.stopped then + minecart.detach_cargo(self, pos, data) + data.stopped = true + data.start_key = get_route_key(pos) + data.start_pos = pos + data.start_time = nil + minetest.log("info", "[minecart] Cart "..self.myID.." stopped.") + if self.sound_handle then + minetest.sound_stop(self.sound_handle) + end + return data.cargo or {} -- for node based carts + end +end + +function minecart.on_dig(self) + if self and self.myID then + CartsOnRail[self.myID] = nil + end +end + +-- +-- Monitoring +-- +local function spawn_cart(pos, vel, item) +-- local node = minetest.get_node(pos) +-- if not minetest.tValidCarts[node.name] then + local pos2 = vector.round(pos) + if carts:is_rail(pos2) or carts:is_rail({x = pos2.x, y = pos2.y-1, z = pos2.z}) then + local obj = minetest.add_entity(pos, item.entity_name or "minecart:cart", nil) + obj:set_velocity(vel) + local id = minecart.add_cart_to_monitoring(obj, item.owner) + minetest.log("info", "[minecart] Cart "..id.." spawned again.") + return id + end +end + +local function calc_pos_and_vel(item) + if item.start_time and item.start_key then + local run_time = minetest.get_gametime() - item.start_time + local waypoints = minecart.get_route(item.start_key).waypoints + local waypoint = waypoints[run_time] + if waypoint then + return minetest.string_to_pos(waypoint[1]), minetest.string_to_pos(waypoint[2]) + end + end + if item.last_pos then + return item.last_pos, item.last_vel + end + return item.start_pos, {x=0, y=0, z=0} +end + +local function monitoring() + local to_be_added = {} + for key, item in pairs(CartsOnRail) do + --print("Cart:", key, P2S(item.start_pos), item.owner) + if not item.recording then + local entity = minetest.luaentities[key] + if entity then -- cart in loaded area + local pos = entity.object:get_pos() + local vel = entity.object:get_velocity() + if not minetest.get_node_or_nil(pos) then -- in unloaded area + minetest.log("info", "[minecart] Cart "..key.." virtualized.") + if entity.sound_handle then + minetest.sound_stop(entity.sound_handle) + end + if vector.equals(vel, {x=0, y=0, z=0}) then + minecart.attach_cargo(entity, pos) + end + entity.object:remove() + end + -- store last pos from cart without route + item.last_pos, item.last_vel = pos, vel + else -- cart in unloaded area + local pos, vel = calc_pos_and_vel(item) + if pos and vel then + if minetest.get_node_or_nil(pos) then -- in loaded area + local id = spawn_cart(pos, vel, item) + if id then + to_be_added[id] = table.copy(item) + CartsOnRail[key] = nil + end + end + else + CartsOnRail[key] = nil + end + end + end + end + -- table maintenance + for key,val in pairs(to_be_added) do + CartsOnRail[key] = val + end + minetest.after(1, monitoring) +end +minetest.after(1, monitoring) + +minecart.calc_pos_and_vel = calc_pos_and_vel + +-- +-- API function to get a list of cart data with current position and speed. +-- +function minecart.get_cart_list() + local tbl = {} + for id, item in pairs(CartsOnRail) do + local pos, speed = calc_pos_and_vel(item) + tbl[#tbl+1] = {pos = pos, speed = speed, id = id} + end + return tbl +end + +-- minecart.get_route_key(pos, player_name) +minecart.get_route_key = get_route_key diff --git a/minecart/screenshot.png b/minecart/screenshot.png new file mode 100644 index 0000000..247e462 Binary files /dev/null and b/minecart/screenshot.png differ diff --git a/minecart/settingtypes.txt b/minecart/settingtypes.txt new file mode 100644 index 0000000..f377c97 --- /dev/null +++ b/minecart/settingtypes.txt @@ -0,0 +1,2 @@ +# If enabled, allows the complete automation of Minecarts by means of Hopper and station stop times. +minecart_hopper_enabled (Hopper enabled) bool true diff --git a/minecart/storage.lua b/minecart/storage.lua new file mode 100644 index 0000000..dc2016a --- /dev/null +++ b/minecart/storage.lua @@ -0,0 +1,85 @@ +--[[ + + Minecart + ======== + + Copyright (C) 2019-2020 Joachim Stolberg + + MIT + See license.txt for more information + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end +local S2P = minetest.string_to_pos +local S = minecart.S + +local DAYS_VALID = (30 * 72) -- 30 real days + +local storage = minetest.get_mod_storage() + +local function data_maintenance() + minetest.log("info", "[MOD] minecart maintenance") + local day_count = minetest.get_day_count() + local tbl = storage:to_table() + for key,s in pairs(tbl.fields) do + local route = minetest.deserialize(s) + if not route.waypoints or not route.best_before or route.best_before < day_count then + storage:set_string(key, "") + else + minetest.log("info", "[minecart] Route: start="..key.." length="..#(route.waypoints)) + end + end +end +minetest.after(1, data_maintenance) + + +-- Store data of running carts +minecart.CartsOnRail = {} + +for key,val in pairs(minetest.deserialize(storage:get_string("CartsOnRail")) or {}) do + -- use invalid keys to force the cart spawning + minecart.CartsOnRail[-key] = val +end + +minetest.register_on_shutdown(function() + data_maintenance() + storage:set_string("CartsOnRail", minetest.serialize(minecart.CartsOnRail)) +end) + +-- All positions as "pos_to_string" string +--Routes = { +-- start_pos = { +-- waypoints = {{spos, svel}, {spos, svel}, ...}, +-- dest_pos = spos, +-- junctions = { +-- {spos = num}, +-- {spos = num}, +-- }, +-- best_before = num +-- }, +-- start_pos = {...}, +--} +local Routes = {} +local NEW_ROUTE = {waypoints = {}, junctions = {}} + +function minecart.store_route(key, route) + Routes[key] = table.copy(route) + Routes[key].best_before = minetest.get_day_count() + DAYS_VALID + storage:set_string(key, minetest.serialize(Routes[key])) +end + +function minecart.get_route(key) + Routes[key] = Routes[key] or minetest.deserialize(storage:get_string(key)) or NEW_ROUTE + Routes[key].best_before = minetest.get_day_count() + DAYS_VALID + return Routes[key] +end + +function minecart.del_route(key) + Routes[key] = nil -- remove from memory + storage:set_string(key, "") -- and from storage +end + + diff --git a/minecart/textures/minecart_appl_hopper.png b/minecart/textures/minecart_appl_hopper.png new file mode 100644 index 0000000..7c703e2 Binary files /dev/null and b/minecart/textures/minecart_appl_hopper.png differ diff --git a/minecart/textures/minecart_appl_hopper_right.png b/minecart/textures/minecart_appl_hopper_right.png new file mode 100644 index 0000000..5e8c302 Binary files /dev/null and b/minecart/textures/minecart_appl_hopper_right.png differ diff --git a/minecart/textures/minecart_appl_hopper_top.png b/minecart/textures/minecart_appl_hopper_top.png new file mode 100644 index 0000000..97ce3c2 Binary files /dev/null and b/minecart/textures/minecart_appl_hopper_top.png differ diff --git a/minecart/textures/minecart_ballast.png b/minecart/textures/minecart_ballast.png new file mode 100644 index 0000000..9bca948 Binary files /dev/null and b/minecart/textures/minecart_ballast.png differ diff --git a/minecart/textures/minecart_buffer.png b/minecart/textures/minecart_buffer.png new file mode 100644 index 0000000..1bb752e Binary files /dev/null and b/minecart/textures/minecart_buffer.png differ diff --git a/minecart/textures/minecart_cart.png b/minecart/textures/minecart_cart.png new file mode 100644 index 0000000..621b8d2 Binary files /dev/null and b/minecart/textures/minecart_cart.png differ diff --git a/minecart/textures/minecart_doc_image.png b/minecart/textures/minecart_doc_image.png new file mode 100644 index 0000000..209b412 Binary files /dev/null and b/minecart/textures/minecart_doc_image.png differ diff --git a/minecart/textures/minecart_logo.png b/minecart/textures/minecart_logo.png new file mode 100644 index 0000000..f7e2e6c Binary files /dev/null and b/minecart/textures/minecart_logo.png differ diff --git a/minecart/textures/minecart_protect.png b/minecart/textures/minecart_protect.png new file mode 100644 index 0000000..def72c7 Binary files /dev/null and b/minecart/textures/minecart_protect.png differ diff --git a/minecart/textures/shrink.py b/minecart/textures/shrink.py new file mode 100644 index 0000000..96863b9 --- /dev/null +++ b/minecart/textures/shrink.py @@ -0,0 +1,16 @@ +import os, fnmatch + + +print ">>> Convert" +for filename in os.listdir("./"): + if fnmatch.fnmatch(filename, "*.png"): + print(filename) + os.system("pngquant --skip-if-larger --quality=8-32 --output ./%s.new ./%s" % (filename, filename)) + +print "\n>>> Copy" +for filename in os.listdir("./"): + if fnmatch.fnmatch(filename, "*.new"): + print(filename) + os.remove("./" + filename[:-4]) + os.rename("./" + filename, "./" + filename[:-4]) + diff --git a/modpack.conf b/modpack.conf new file mode 100644 index 0000000..0bf8230 --- /dev/null +++ b/modpack.conf @@ -0,0 +1,3 @@ +name = techage +description = Techage, go through 4 tech ages in search of wealth and power + diff --git a/safer_lua/COPYING.txt b/safer_lua/COPYING.txt new file mode 100644 index 0000000..d99f436 --- /dev/null +++ b/safer_lua/COPYING.txt @@ -0,0 +1,28 @@ +The safer_lua mod for Minetest is + +Copyright (C) 2017-2018 Joachim Stolberg + +License of source code +---------------------- + +This mod is free software; you can redistribute and/or +modify it under the terms of the GNU Lesser General Public License version 2.1 or later +published by the Free Software Foundation. + +This mod 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this mod; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301, USA. + + +License of media (textures, sounds and documentation) +----------------------------------------------------- + +All textures, sounds and documentation files are licensed under the +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/safer_lua/LICENSE.txt b/safer_lua/LICENSE.txt new file mode 100644 index 0000000..4362b49 --- /dev/null +++ b/safer_lua/LICENSE.txt @@ -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. + + + Copyright (C) + + 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. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/safer_lua/data_struct.lua b/safer_lua/data_struct.lua new file mode 100644 index 0000000..03bbe82 --- /dev/null +++ b/safer_lua/data_struct.lua @@ -0,0 +1,364 @@ +--[[ + + SaferLua [safer_lua] + ==================== + + Copyright (C) 2018 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + data_struct.lua: + + see https://github.com/joe7575/techpack/wiki/Data-Structures + +]]-- + +safer_lua.DataStructHelp = [[ + Data structures as a secure shell over the LUA table type. + see https://github.com/joe7575/techpack/wiki/Data-Structures + + 'Arrays' are lists of elements, which can be addressed + by means of an index: + + a = Array(1,2,3,4) --> {1,2,3,4} + a.add(6) --> {1,2,3,4,6} + a.set(2, 8) --> {1,8,3,4,6} + a.insert(5,7) --> {1,8,3,4,7,6} + a.remove(3) --> {1,8,4,7,6} + a.insert(1, "hello") --> {"hello",1,8,4,7,6} + a.size() --> function returns 6 + a.memsize() --> return returns 10 + a.next() --> for loop iterator function + a.sort(reverse) --> sort the array elements in place + + Unlike arrays, which are indexed by a range of numbers, + 'stores' are indexed by keys: + + s = Store("a",4,"b",5) --> {a = 4, b = 5} + s.set("val", 12) --> {a = 4, b = 5, val = 12} + s.get("val") --> returns 12 + s.set(0, "hello") --> {a = 4, b = 5, val = 12, [0] = "hello"} + s.del("val") --> {[0] = "hello"} + s.size() --> function returns 4 + s.memsize() --> function returns 8 + s.next() --> for loop iterator function + s.keys(order) --> return an array with the keys + + A 'set' is an unordered collection with no duplicate + elements. + + s = Set("Tom", "Lucy") + --> {Tom = true, Lucy = true} + s.del("Tom") --> {Lucy = true} + s.add("Susi") --> {Lucy = true, Susi = true} + s.has("Susi") --> function returns `true` + s.has("Mike") --> function returns `false` + s.size() --> function returns 2 + s.memsize() --> function returns 8 + s.next() --> for loop iterator function +]] + +local function var_count(v) + if type(v) == "number" then + return 1 + elseif type(v) == "boolean" then + return 1 + elseif v == nil then + return 0 + elseif type(v) == "string" then + return #v + elseif type(v) == "table" then + return v.memsize() + else + return nil + end +end + + +function safer_lua.Store(...) + + local new_t = {} + local mt = {} + + local MemSize = 0 + local Size = 0 + local Data = {} + + mt.__newindex = function(t, k, v) return end + + mt.count = var_count + + new_t.set = function(k,v) + if type(k) == "number" then + if rawget(Data, k) then -- has entry? + MemSize = MemSize - mt.count(rawget(Data, k)) + else + Size = Size + 1 + end + MemSize = MemSize + mt.count(v) + rawset(Data, k, v) + elseif type(k) == "string" then + if rawget(Data, k) then -- has entry? + MemSize = MemSize - mt.count(rawget(Data, k)) + else + MemSize = MemSize + mt.count(k) + Size = Size + 1 + end + MemSize = MemSize + mt.count(v) + rawset(Data, k, v) + end + end + + new_t.get = function(k) + return rawget(Data, k) + end + + new_t.del = function(k) + if rawget(Data, k) then -- has entry? + MemSize = MemSize - mt.count(k) + MemSize = MemSize - mt.count(rawget(Data, k)) + rawset(Data, k, nil) + Size = Size - 1 + end + end + + new_t.memsize = function(t) + return MemSize + end + + new_t.size = function(t) + return Size + end + + new_t.next = function(t) + local n = nil + return function () + n = next(Data, n) + if n then return n, Data[n] end + end + end + + new_t.keys = function(order) + local keyset = {} + local n = 0 + local size = 0 + + for k,v in pairs(Data) do + n = n + 1 + keyset[n] = k + size = size + var_count(k) + end + + if order == "up" then + table.sort(keyset, function(a,b) return a > b end) + elseif order == "down" then + table.sort(keyset) + end + local a = safer_lua.Array() + a.__load(size, keyset) + return a + end + + new_t.__dump = function() + -- remove the not serializable meta data + return {Type = "Store", Size = Size, MemSize = MemSize, Data = Data} + end + + new_t.__load = function(size, memsize, data) + Size = size + MemSize = memsize + Data = data + end + + for idx = 1,select('#',...),2 do + local k,v = select(idx,...),select(idx+1,...) + new_t.set(k,v) + end + + return setmetatable(new_t, mt) +end + + +function safer_lua.Array(...) + + local new_t = {} + local mt = {} + + local MemSize = 0 + local Data = {} + + mt.__newindex = function(t, k, v) return end + + mt.count = var_count + + for idx = 1,select('#',...) do + local v = select(idx,...) + local cnt = mt.count(v) + if cnt then + MemSize = MemSize + cnt + rawset(Data, idx, v) + end + end + + new_t.add = function(v) + MemSize = MemSize + mt.count(v) + local i = #Data + 1 + table.insert(Data, i, v) + end + + new_t.set = function(i,v) + i = math.min(#Data, i) + MemSize = MemSize - mt.count(rawget(Data, i)) + MemSize = MemSize + mt.count(v) + rawset(Data, i, v) + end + + new_t.get = function(i) + return Data[i] + end + + new_t.insert = function(i, v) + MemSize = MemSize + mt.count(v) + i = math.min(#Data, i) + table.insert(Data, i, v) + end + + new_t.remove = function(i) + local v = table.remove(Data, i) + MemSize = MemSize - mt.count(v) + return v + end + + new_t.sort = function(reverse) + if reverse then + table.sort(Data, function(a,b) return a > b end) + else + table.sort(Data) + end + end + + new_t.memsize = function(t) + return MemSize + end + + new_t.size = function(t) + return #Data + end + + new_t.next = function(t) + local i = 0 + local n = #Data + return function () + i = i + 1 + if i <= n then return i, Data[i] end + end + end + + new_t.__dump = function() + -- remove the not serializable meta data + return {Type = "Array", MemSize = MemSize, Data = Data} + end + + new_t.__load = function(memsize, data) + MemSize = memsize + Data = data + end + + return setmetatable(new_t, mt) +end + + +function safer_lua.Set(...) + + local new_t = {} + local mt = {} + + local MemSize = 0 + local Size = 0 + local Data = {} + + mt.__newindex = function(t, k, v) return end + + mt.count = var_count + + for idx = 1,select('#',...) do + local v = select(idx,...) + local cnt = mt.count(v) + if cnt then + MemSize = MemSize + cnt + Size = Size + 1 + rawset(Data, v, true) + end + end + + new_t.add = function(k) + MemSize = MemSize + mt.count(k) + rawset(Data, k, true) + Size = Size + 1 + end + + new_t.del = function(k) + MemSize = MemSize - mt.count(k) + rawset(Data, k, nil) + Size = Size - 1 + end + + new_t.has = function(k) + return rawget(Data, k) == true + end + + new_t.memsize = function(t) + return MemSize + end + + new_t.size = function(t) + return Size + end + + new_t.next = function(t) + local i = 0 + local n = nil + return function () + i = i + 1 + n = next(Data, n) + if n then return i, n end + end + end + + new_t.__dump = function() + -- remove the not serializable meta data + return {Type = "Set", Size = Size, MemSize = MemSize, Data = Data} + end + + new_t.__load = function(size, memsize, data) + Size = size + MemSize = memsize + Data = data + end + + return setmetatable(new_t, mt) +end + + +-- remove the not serializable meta data +function safer_lua.datastruct_to_table(ds) + return ds.__dump() +end + +-- add the not serializable meta data again +function safer_lua.table_to_datastruct(tbl) + if tbl.Type == "Store" then + local s = safer_lua.Store() + s.__load(tbl.Size, tbl.MemSize, tbl.Data) + return s + elseif tbl.Type == "Set" then + local s = safer_lua.Set() + s.__load(tbl.Size, tbl.MemSize, tbl.Data) + return s + elseif tbl.Type == "Array" then + local a = safer_lua.Array() + a.__load(tbl.MemSize, tbl.Data) + return a + end +end \ No newline at end of file diff --git a/safer_lua/demo.lua b/safer_lua/demo.lua new file mode 100644 index 0000000..e42d8a1 --- /dev/null +++ b/safer_lua/demo.lua @@ -0,0 +1,70 @@ +--[[ + + SaferLua [safer_lua] + ==================== + + Copyright (C) 2018-2020 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + Example demo code + +]]-- + + +-- demo function 1 +local function output(self, s) + print(self.meta.name, s) +end + +-- demo function 2 +local function add(self, param1, param2) + return param1 + param2 +end + +-- for Lua interpreter errors +local function error(pos, s) + print("[Safer Lua] "..(s or "")) +end + +-- init function code block +local init = [[ + -- init code here + + sum = 0 + $output("Hello world!") +]] + +-- loop function code block +local loop = [[ + -- loop code here + + sum = $add(1, sum) + $output(sum) +]] + +-- runtime environment +local env = { + output = output, + add = add, +} + +-- runtime meta data (protected for the running Lua script) +env.meta = {num = 1, name = "Joe"} + +-- used for ingame positions +local pos = {x = 0, y = 0, z = 0} + +-- elapsed game time +local elapsed = 1 + +-- compile the Lus script to byte code (only once) +local code = safer_lua.init(pos, init, loop, env, error) + +if code then + for i=1, 10 do + -- execute the byte code + safer_lua.run_loop(pos, elapsed, code, error) + end +end diff --git a/safer_lua/depends.txt b/safer_lua/depends.txt new file mode 100644 index 0000000..e69de29 diff --git a/safer_lua/description.txt b/safer_lua/description.txt new file mode 100644 index 0000000..97257ee --- /dev/null +++ b/safer_lua/description.txt @@ -0,0 +1,4 @@ +SaferLua [safer_lua], a subset of the language Lua for safe and secure Lua sandboxes + + + diff --git a/safer_lua/environ.lua b/safer_lua/environ.lua new file mode 100644 index 0000000..4a0fb51 --- /dev/null +++ b/safer_lua/environ.lua @@ -0,0 +1,211 @@ +--[[ + + SaferLua [safer_lua] + ==================== + + Copyright (C) 2018 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + environ.lua: + +]]-- + +safer_lua.MaxCodeSize = 5000 -- size if source code in bytes +safer_lua.MaxTableSize = 1000 -- sum over all table sizes +safer_lua.MaxExeTime = 5000 -- max. execution time in us + +local function memsize() + return safer_lua.MaxTableSize +end + +local function range(from, to) + return function(expired_at,last) + assert(expired_at > minetest.get_us_time(), "Runtime limit exceeded") + if last >= to then + return nil + else + return last+1 + end + end, minetest.get_us_time() + safer_lua.MaxExeTime, from-1 +end + +local BASE_ENV = { + Array = safer_lua.Array, + Store = safer_lua.Store, + Set = safer_lua.Set, + memsize = memsize, + range = range, + math = { + floor = math.floor, + abs = math.abs, + max = math.max, + min = math.min, + random = math.random, + }, + string = { + byte = string.byte, + char = string.char, + find = string.find, + format = string.format, + gmatch = string.gmatch, + gsub = string.gsub, + len = string.len, + lower = string.lower, + match = string.match, + rep = string.rep, + sub = string.sub, + upper = string.upper, + split = string.split, + trim = string.trim, + }, + tonumber = tonumber, + tostring = tostring, + unpack = unpack, + type = type, + ticks = 0, +} + +local function map(dest, source) + for k,v in pairs(source) do + dest[k] = v + end + return dest +end + +local function calc_used_mem_size(env) + local size = 0 + for key,val in pairs(env) do + if type(val) == "table" and val.size ~= nil then + size = size + val.size() or 0 + end + end + return size +end + +function safer_lua.config(max_code_size, max_table_size) + safer_lua.MaxCodeSize = max_code_size + safer_lua.MaxTableSize = max_table_size +end + +local function format_error_str(str, label) + local tbl = {} + for s in str:gmatch("[^\r\n]+") do + s = s:match("^%s*(.-)%s*$") + if s:find("function 'xpcall'") then + break + elseif s:find(".-%.lua:%d+:(.+)") then + local err = s:gsub(".-%.lua:%d+:%s*(.+)", "extern: %1") + table.insert(tbl, err) + elseif s:find('%[string ".-"%]') then + local line, err = s:match('^%[string ".-"%]:(%d+): (.+)$') + table.insert(tbl, label..":"..line..": "..err) + elseif s:find('%(load%):(%d+):') then + local line, err = s:match('%(load%):(%d+): (.+)$') + table.insert(tbl, label..":"..line..": "..err) + end + end + return "Error: "..table.concat(tbl, "\n >> ") +end + +local function format_error(err, label) + if err:find("stack overflow") then + return "Error: Stack overflow due to recursive function calls!" + end + return format_error_str(err, label) +end + +local function compile(pos, text, label, err_clbk) + if safer_lua:check(pos, text, label, err_clbk) == 0 then + text = text:gsub("%$", "S:") + local code, err = loadstring(text) + if not code then + err_clbk(pos, format_error(err, label)) + else + return code + end + end +end + +------------------------------------------------------------------------------- +-- Standard init/loop controller +------------------------------------------------------------------------------- +function safer_lua.init(pos, init, loop, environ, err_clbk) + if (#init + #loop) > safer_lua.MaxCodeSize then + err_clbk(pos, "Error: Code size limit exceeded") + return + end + local code = compile(pos, init, "init", err_clbk, 0) + if code then + local env = table.copy(BASE_ENV) + env.S = {} + env.S = map(env.S, environ) + setfenv(code, env) + local res, err = xpcall(code, debug.traceback) + if not res then + err_clbk(pos, format_error(err, "init")) + else + env = getfenv(code) + code = compile(pos, loop, "loop", err_clbk) + if code then + setfenv(code, env) + return code + end + end + end +end + +function safer_lua.run_loop(pos, elapsed, code, err_clbk) + local env = getfenv(code) + env.elapsed = elapsed + if elapsed < 0 then -- event? + env.event = true + else + env.event = false + env.ticks = env.ticks + 1 + end + local res, err = xpcall(code, debug.traceback) + if calc_used_mem_size(env) > safer_lua.MaxTableSize then + err_clbk(pos, "Error: Data memory limit exceeded") + return false + end + if not res then + err_clbk(pos, format_error(err, "loop")) + return false + end + return true +end + +------------------------------------------------------------------------------- +-- Endless/Coroutine controller +------------------------------------------------------------------------------- +local function thread(pos, code, err_clbk) + while true do + local res, err = xpcall(code, debug.traceback) + if not res then + err_clbk(pos, format_error(err, "loop")) + return false + end + local env = getfenv(code) + if calc_used_mem_size(env) > safer_lua.MaxTableSize then + err_clbk(pos, "Error: Memory limit exceeded") + return false + end + coroutine.yield() + end +end + +function safer_lua.co_create(pos, init, loop, environ, err_clbk) + local code = safer_lua.init(pos, init, loop, environ, err_clbk) + return coroutine.create(thread), code +end + +function safer_lua.co_resume(pos, co, code, err_clbk) + local res, err = coroutine.resume(co, pos, code, err_clbk) + if not res then + err_clbk(pos, format_error(err, "loop")) + return false + end + return true +end diff --git a/safer_lua/init.lua b/safer_lua/init.lua new file mode 100644 index 0000000..0dde11d --- /dev/null +++ b/safer_lua/init.lua @@ -0,0 +1,24 @@ +--[[ + + SaferLua [safer_lua] + ==================== + + Copyright (C) 2018-2020 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + environ.lua: + +]]-- + +safer_lua = {} + +-- Version for compatibility checks, see readme.md/history +safer_lua.version = 1.0 + +dofile(minetest.get_modpath("safer_lua") .. "/data_struct.lua") +dofile(minetest.get_modpath("safer_lua") .. "/scanner.lua") +dofile(minetest.get_modpath("safer_lua") .. "/environ.lua") +-- only for demo purposes +--dofile(minetest.get_modpath("safer_lua") .. "/demo.lua") \ No newline at end of file diff --git a/safer_lua/mod.conf b/safer_lua/mod.conf new file mode 100644 index 0000000..d319b89 --- /dev/null +++ b/safer_lua/mod.conf @@ -0,0 +1 @@ +name=safer_lua diff --git a/safer_lua/readme.md b/safer_lua/readme.md new file mode 100644 index 0000000..e157656 --- /dev/null +++ b/safer_lua/readme.md @@ -0,0 +1,20 @@ +SaferLua [safer_lua] +==================== + +A subset of the language Lua for safe and secure Lua sandboxes with: + - limited code length + - limited execution time + - limited memory use + - limited posibilities to call functions + +### License +Copyright (C) 2018-2020 Joachim Stolberg +Code: Licensed under the GNU LGPL version 2.1 or later. See LICENSE.txt + + +### Dependencies +none + +### History +- 2018-06-24 v0.01 * first draft +- 2020-03-14 v1.00 * extracted from TechPack and released diff --git a/safer_lua/scanner.lua b/safer_lua/scanner.lua new file mode 100644 index 0000000..a95a23b --- /dev/null +++ b/safer_lua/scanner.lua @@ -0,0 +1,141 @@ +--[[ + + SaferLua [safer_lua] + ==================== + + Copyright (C) 2018 Joachim Stolberg + + LGPLv2.1+ + See LICENSE.txt for more information + + scanner.lua: + +]]-- + +local function trim(s) + return (s:gsub("^%s*(.-)%s*$", "%1")) +end + +function safer_lua:word(ch, pttrn) + local word = "" + while ch:match(pttrn) do + word = word .. ch + self.pos = self.pos + 1 + ch = self.line:sub(self.pos, self.pos) + end + return word +end + +function safer_lua:string(pttrn) + self.pos = self.pos + 1 + local ch = self.line:sub(self.pos, self.pos) + while not ch:match(pttrn) and self.pos < #self.line do + if ch == "\\" then + self.pos = self.pos + 1 + end + self.pos = self.pos + 1 + ch = self.line:sub(self.pos, self.pos) + end + self.pos = self.pos + 1 + -- result is not needed +end + +local function lines(str) + local t = {} + local function helper(line) + table.insert(t, line) + return "" + end + helper((str:gsub("(.-)\r?\n", helper))) + return t +end + +function safer_lua:scanner(text) + local lToken = {} + for idx, line in ipairs(lines(text)) do + self.line = line + self.pos = 1 + self.line = trim(self.line) + self.line = self.line:split("--", true)[1] + table.insert(lToken, idx) -- line number + if self.line then + -- devide line in tokens + while true do + if self.pos > #self.line then break end + local ch = self.line:sub(self.pos, self.pos) + if ch:match("[%u%l_]") then -- identifier? + table.insert(lToken, self:word(ch, "[%w_]")) + elseif ch:match("[%d]") then -- number? + table.insert(lToken, self:word(ch, "[%d%xx]")) + elseif ch:match("'") then -- string? + self:string("'") + elseif ch:match('"') then -- string? + self:string('"') + elseif ch:match("[%s]") then -- Space? + self.pos = self.pos + 1 + elseif ch:match("[:{}]") then -- critical tokens? + table.insert(lToken,ch) + self.pos = self.pos + 1 + else + self.pos = self.pos + 1 + end + end + end + end + return lToken +end + +local InvalidKeywords = { + ["while"] = true, + ["repeat"] = true, + ["until"] = true, + ["for"] = true, + ["range"] = true, + --["function"] = true, + ["_G"] = true, + ["__load"] = true, + ["__dump"] = true, +} + +local InvalidChars = { + [":"] = true, + ["{"] = true, + ["["] = true, + ["]"] = true, + ["}"] = true, +} + +function safer_lua:check(pos, text, label, err_clbk) + local lToken = self:scanner(text) + local lineno = 0 + local errno = 0 + for idx,token in ipairs(lToken) do + if type(token) == "number" then + lineno = token + elseif InvalidKeywords[token] then + if token == "for" then + -- invalid for statement? + if lToken[idx + 3] == "in" and lToken[idx + 5] == "next" then + -- + elseif lToken[idx + 2] == "in" and lToken[idx + 3] == "range" then + -- + else + err_clbk(pos, label..":"..lineno..": Invalid use of 'for'") + errno = errno + 1 + end + elseif token == "range" then + if lToken[idx - 1] ~= "in" then + err_clbk(pos, label..":"..lineno..": Invalid use of 'range'") + errno = errno + 1 + end + else + err_clbk(pos, label..":"..lineno..": Invalid keyword '"..token.."'") + errno = errno + 1 + end + elseif InvalidChars[token] then + err_clbk(pos, label..":"..lineno..": Invalid character '"..token.."'") + errno = errno + 1 + end + end + return errno +end diff --git a/signs_bot/COPYING.txt b/signs_bot/COPYING.txt new file mode 100644 index 0000000..61d3233 --- /dev/null +++ b/signs_bot/COPYING.txt @@ -0,0 +1,28 @@ +The Signs Bot mod for Minetest is + +Copyright (C) 2019 Joachim Stolberg + +License of source code +---------------------- + +This mod is free software; you can redistribute and/or +modify it under the terms of the GNU General Public License version 3 or later +published by the Free Software Foundation. + +This mod 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 +General Public License for more details. + +You should have received a copy of the GNU General Public +License along with this mod; if not, write to the +Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +Boston, MA 02110-1301, USA. + + +License of media (textures, sounds and documentation) +----------------------------------------------------- + +All textures, sounds and documentation files are licensed under the +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +http://creativecommons.org/licenses/by-sa/3.0/ diff --git a/signs_bot/LICENSE.txt b/signs_bot/LICENSE.txt new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/signs_bot/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, 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 +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If 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 convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU 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 +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/signs_bot/README.md b/signs_bot/README.md new file mode 100644 index 0000000..808d949 --- /dev/null +++ b/signs_bot/README.md @@ -0,0 +1,169 @@ +Signs Bot [signs_bot] +===================== + +**A robot controlled by signs.** + +Browse on: ![GitHub](https://github.com/joe7575/signs_bot) + +Download: ![GitHub](https://github.com/joe7575/signs_bot/archive/master.zip) + +![Signs Bot](https://github.com/joe7575/signs_bot/blob/master/screenshot.png) + + +The bot can only be controlled by signs that are placed in its path. +The bot starts running after starting until it encounters a sign. There, the commands are then processed on the sign. +The bot can also put himself signs in the way, which he then works off. +There is also a sign that can be programmed by the player, which then are processed by the bot. + +There are also the following blocks: +- Sensors: These can send a signal to an actuator if they are connected to the actuator. +- Actuators: These perform an action when they receive a signal from a sensor. + +Sensors must be connected (paired) with actuators. This is what the Connection Tool does. Click on both blocks one after the other. +A successful pairing is indicated by a ping / pong noise. +When pairing, the state of the actuator is important. In the case of the bot box, for example, the states "on" and "off", in the case of the control unit 1,2,3,4, etc. +The state of the actuator is saved with the pairing and restored by the signal. For example, the robot can be switched on via a node sensor. + +An actuator can receive signals from many sensors. A sensor can only be connected to an actuator. However, if several actuators are to be controlled by one sensor, a signal extender block must be used. This connects to a sensor when it is placed next to the sensor. This extender can then be paired with another actuator. + +Sensors are: +- Bot Sensor: Sends a signal when the robot passes by +- Node Sensor: Sends a signal when it detects a change (tree, cactus, flower, etc.) in front of the sensor (over 3 positions) +- Crop Sensor: Sends a signal when, for example, the wheat is fully grown +- Bot Chest: Sends a signal depending on the chest state. Possible states are "empty", "not empty", "almost full". The state to be sent is defined while pairing. + +Actuators are: +- Control Unit: Can place up to 4 signs and steer the bot e.g. in different directions. +- Signs Bot Box: Can be turned off and on + +In addition, there are currently the following blocks: +- The duplicator is used to copy Command Signs, i.e. the signs with their own commands. +- Bot Flap: The "cat flap" is a door for the bot, which he opens automatically and closes behind him. +- Sensor Extender for controlling additional actuators from one sensor signal +- A Timer can be used to start the Bot cyclically +- A Delayer can be used to delay and queue signals + +More information: +- Using the signs "take" and "add", the bot can pick items from Chests and put them in. The signs must be placed on the box. So far, only a few blocks are supported with Inventory. +- The Control Unit can be charged with up to 4 labels. To do this, place a label next to the Control Unit and click on the Control Unit. The sign is only stored under this number. +- The inventory of the Signs Bot Box is intended to represent the inventory of the Robot. As long as the robot is on the road, of course you have no access. + +The copy function can be used to clone node cubes up to 5x3x3 nodes. There is the pattern shield for the template position and the copy shield for the "3x3x3" copy. Since the bot also copies air blocks, the function can also be used for mining or tunnels. The items to be placed must be in the inventory. Items that the bot degrades are in Inventory afterwards. If there are missing items in the inventory during copying, he will set "missing items" blocks, which dissolve into air when degrading. + +In-game help: +The mod has an in-game help to all blocks and signs. Therefore, it is highly recommended that you have installed the mods 'doc' and 'unified_inventory'. + +### Commands: +The commands are also all described as help in the "Sign command" node. +All blocks or signs that are set are taken from the bot inventory. +Any blocks or signs removed will be added back to the Bot Inventory. +For all Inventory commands applies: If the inventory stack specified by is full, so that nothing more can be done, or just empty, so that nothing more can be removed, the next slot will automatically be used. + + move - to follow one or more steps forward without signs + cond_move - walk to the next sign and work it off + turn_left - turn left + turn_right - turn right + turn_around - turn around + backward - one step backward + turn_off - turn off the robot / back to the box + pause - wait one or more seconds + move_up - move up (maximum 2 times) + move_down - move down + take_item - take one or more items from a box + add_item - put one or more items in a box + add_fuel - for furnaces or similar + place_front - Set block in front of the robot + place_left - Set block to the left + place_right - set block to the right + place_below - set block under the robot + place_above - set block above the robot + dig_front - remove block in front of the robot + dig_left - remove block on the left + dig_right - remove block on the right + dig_below - dig block under the robot + dig_above - dig block above the robot + place_sign - set sign + place_sign_behind - put a sign behind the bot + dig_sign - remove the sign + trash_sign - Remove the sign, clear data and add to the item Inventory + stop - Bot stops until the shield is removed + pickup_items - pickup items (in a 3x3 field) + drop_items - drop items + harvest - harvest a 3x3 field (farming) + cutting - cut a 3x3 flower field + sow_seed - a 3x3 field sowing / planting + plant_sapling - plant a sapling in front of the robot + pattern - save the blocks behind the shield (up to 5x3x3) as template + copy - make a copy of "pattern". Size is e.g. 3x3 (see ingame help) + punch_cart - Punch a rail cart to start it + +#### Flow control commands + + jump