├── API.txt ├── LICENSE.txt ├── README.txt ├── changelog.txt ├── depends.txt ├── food.lua ├── functions.lua ├── init.lua ├── legacy.lua ├── sounds └── hunger_eat.ogg └── textures └── hunger_statbar_poisen.png /API.txt: -------------------------------------------------------------------------------- 1 | -- Register food with given values to change eating actions 2 | 3 | hunger.register_food(name, saturation, replace_with_item, poisen, heal, sound) 4 | -- name: item name, e.g. "default:apple" 5 | -- saturation: amount of added saturation 6 | -- replace_with_item: item name that get returned after eating (can be nil) 7 | -- poisen: duration in seconds (1hp damage per second, player can't die) (can be nil) 8 | -- heal: added HP when eating this food (can be nil) 9 | -- sound: costum eating sound (replaces default eating sound) (can be nil) 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Minetest mod "Hunger" 2 | ===================== 3 | Version: 1.1.3 4 | 5 | (c) Copyright BlockMen (2015) 6 | 7 | 8 | About this mod: 9 | ~~~~~~~~~~~~~~~ 10 | This mod adds hunger mechanics to Minetest, which are based on player actions and on time. 11 | Also it changes the eating in Minetest, e.g. an Apple does not restore Health, but it rises your saturation. 12 | Example: 1 apple fills up the hunger bar by 1 "bread" (statbar symbol). 13 | Although the statbar show 20 hunger points (10 breads) on the HUD you can fill it up to 30 points. 14 | 15 | By default it supports a lot of food already (see full list below) and food that for registered via the API. 16 | For more information how to register more food see API.txt 17 | 18 | Information: 19 | This mod depends on the "Better HUD" mod (https://github.com/BlockMen/hud) to provide information about your current saturation. 20 | 21 | 22 | For Modders: 23 | ~~~~~~~~~~~~ 24 | This mod alters the behavior of minetest.item_eat(). 25 | All callbacks that are registered via minetest.register_on_item_eat() are called AFTER this mod actions, so the itemstack 26 | will have changed already when callbacks are called. You can get the original itemstack as 6th parameter of your function then. 27 | 28 | License: 29 | ~~~~~~~~ 30 | (c) Copyright BlockMen (2015) 31 | 32 | 33 | Code: 34 | Licensed under the GNU LGPL version 2.1 or higher. 35 | You can redistribute it and/or modify it under 36 | the terms of the GNU Lesser General Public License 37 | as published by the Free Software Foundation; 38 | 39 | You should have received a copy of the GNU Lesser General Public 40 | License along with this library; if not, write to the Free Software 41 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 42 | 43 | See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt 44 | 45 | 46 | Textures: 47 | hunger_statbar_poisen.png - BlockMen (CC-BY 3.0) 48 | 49 | Sounds: 50 | hunger_eat.ogg - BlockMen (CC-BY 3.0) 51 | 52 | 53 | Github: 54 | ~~~~~~~ 55 | https://github.com/BlockMen/hunger 56 | 57 | Forum: 58 | ~~~~~~ 59 | - 60 | 61 | Changelog: 62 | ~~~~~~~~~~ 63 | see changelog.txt 64 | 65 | 66 | Dependencies: 67 | ~~~~~~~~~~~~~ 68 | - Default 69 | - Farming 70 | - Better HUD (https://github.com/BlockMen/hud) 71 | 72 | 73 | Supported food/mods: 74 | ~~~~~~~~~~~~~~~~~~~~ 75 | - Apples (default) 76 | - Animalmaterials (mobf modpack) 77 | - Bread (default) 78 | - Bushes 79 | - bushes_classic 80 | - Creatures 81 | - Dwarves (beer and such) 82 | - Docfarming 83 | - Fishing 84 | - Farming plus 85 | - Farming (default and Tenplus1's fork) 86 | - Food 87 | - fruit 88 | - Glooptest 89 | - JKMod 90 | - kpgmobs 91 | - Mobfcooking 92 | - Mooretrees 93 | - Mtfoods 94 | - mushroom 95 | - mush45 96 | - Seaplants (sea) 97 | - Simple mobs 98 | -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | 1.0 2 | --- 3 | - Partly rewritten (based on Better HUD hunger mechanics) 4 | - Added API to register food 5 | - Added eating sounds 6 | - Hungerbar image changes when poisend 7 | 8 | 1.1 9 | --- 10 | - Fixed healing after death 11 | - Fixed healing while drowning 12 | - Fixed crashed caused by Pipeworks mod 13 | - Added wrapper for minetest.item_eat(). see Readme.txt for more informations 14 | - Updated HUD-API usage 15 | - Added beans of Farming Redo 16 | 17 | 1.1.1 18 | ----- 19 | - Fixed unhandled exception (reported by Martin_Devil) 20 | - Added support for mtg mushrooms 21 | 22 | 1.1.2 23 | ----- 24 | - Fixed crash on invalid values given 25 | 26 | 1.1.3 27 | ----- 28 | - Prevent server crash caused by specific usernames (by beyondlimits) 29 | -------------------------------------------------------------------------------- /depends.txt: -------------------------------------------------------------------------------- 1 | default 2 | hud 3 | animalmaterials? 4 | bucket? 5 | bushes? 6 | bushes_classic? 7 | cooking? 8 | creatures? 9 | docfarming? 10 | dwarves? 11 | ethereal? 12 | farming? 13 | farming_plus? 14 | ferns? 15 | fishing? 16 | flowers? 17 | fruit? 18 | glooptest? 19 | jkanimals? 20 | jkfarming? 21 | jkwine? 22 | kpgmobs? 23 | mobfcooking? 24 | mobs? 25 | moretrees? 26 | mtfoods? 27 | mush45? 28 | mushroom? 29 | pizza? 30 | seaplants? 31 | -------------------------------------------------------------------------------- /food.lua: -------------------------------------------------------------------------------- 1 | local register_food = hunger.register_food 2 | 3 | register_food("default:apple", 2) 4 | 5 | if minetest.get_modpath("farming") ~= nil then 6 | register_food("farming:bread", 4) 7 | end 8 | 9 | if minetest.get_modpath("flowers") ~= nil then 10 | register_food("flowers:mushroom_brown", 1) 11 | register_food("flowers:mushroom_red", 1, "", 3) 12 | end 13 | 14 | if minetest.get_modpath("mobs") ~= nil then 15 | if mobs.mod ~= nil and mobs.mod == "redo" then 16 | register_food("mobs:cheese", 4) 17 | register_food("mobs:meat", 8) 18 | register_food("mobs:meat_raw", 4) 19 | register_food("mobs:rat_cooked", 4) 20 | register_food("mobs:honey", 2) 21 | register_food("mobs:pork_raw", 3, "", 3) 22 | register_food("mobs:pork_cooked", 8) 23 | register_food("mobs:chicken_cooked", 6) 24 | register_food("mobs:chicken_raw", 2, "", 3) 25 | register_food("mobs:chicken_egg_fried", 2) 26 | if minetest.get_modpath("bucket") then 27 | register_food("mobs:bucket_milk", 3, "bucket:bucket_empty") 28 | end 29 | else 30 | register_food("mobs:meat", 6) 31 | register_food("mobs:meat_raw", 3) 32 | register_food("mobs:rat_cooked", 5) 33 | end 34 | end 35 | 36 | if minetest.get_modpath("moretrees") ~= nil then 37 | register_food("moretrees:coconut_milk", 1) 38 | register_food("moretrees:raw_coconut", 2) 39 | register_food("moretrees:acorn_muffin", 3) 40 | register_food("moretrees:spruce_nuts", 1) 41 | register_food("moretrees:pine_nuts", 1) 42 | register_food("moretrees:fir_nuts", 1) 43 | end 44 | 45 | if minetest.get_modpath("dwarves") ~= nil then 46 | register_food("dwarves:beer", 2) 47 | register_food("dwarves:apple_cider", 1) 48 | register_food("dwarves:midus", 2) 49 | register_food("dwarves:tequila", 2) 50 | register_food("dwarves:tequila_with_lime", 2) 51 | register_food("dwarves:sake", 2) 52 | end 53 | 54 | if minetest.get_modpath("animalmaterials") ~= nil then 55 | register_food("animalmaterials:milk", 2) 56 | register_food("animalmaterials:meat_raw", 3) 57 | register_food("animalmaterials:meat_pork", 3) 58 | register_food("animalmaterials:meat_beef", 3) 59 | register_food("animalmaterials:meat_chicken", 3) 60 | register_food("animalmaterials:meat_lamb", 3) 61 | register_food("animalmaterials:meat_venison", 3) 62 | register_food("animalmaterials:meat_undead", 3, "", 3) 63 | register_food("animalmaterials:meat_toxic", 3, "", 5) 64 | register_food("animalmaterials:meat_ostrich", 3) 65 | register_food("animalmaterials:fish_bluewhite", 2) 66 | register_food("animalmaterials:fish_clownfish", 2) 67 | end 68 | 69 | if minetest.get_modpath("fishing") ~= nil then 70 | register_food("fishing:fish_raw", 2) 71 | register_food("fishing:fish_cooked", 5) 72 | register_food("fishing:sushi", 6) 73 | register_food("fishing:shark", 4) 74 | register_food("fishing:shark_cooked", 8) 75 | register_food("fishing:pike", 4) 76 | register_food("fishing:pike_cooked", 8) 77 | end 78 | 79 | if minetest.get_modpath("glooptest") ~= nil then 80 | register_food("glooptest:kalite_lump", 1) 81 | end 82 | 83 | if minetest.get_modpath("bushes") ~= nil then 84 | register_food("bushes:sugar", 1) 85 | register_food("bushes:strawberry", 2) 86 | register_food("bushes:berry_pie_raw", 3) 87 | register_food("bushes:berry_pie_cooked", 4) 88 | register_food("bushes:basket_pies", 15) 89 | end 90 | 91 | if minetest.get_modpath("bushes_classic") then 92 | -- bushes_classic mod, as found in the plantlife modpack 93 | local berries = { 94 | "strawberry", 95 | "blackberry", 96 | "blueberry", 97 | "raspberry", 98 | "gooseberry", 99 | "mixed_berry"} 100 | for _, berry in ipairs(berries) do 101 | if berry ~= "mixed_berry" then 102 | register_food("bushes:"..berry, 1) 103 | end 104 | register_food("bushes:"..berry.."_pie_raw", 2) 105 | register_food("bushes:"..berry.."_pie_cooked", 5) 106 | register_food("bushes:basket_"..berry, 15) 107 | end 108 | end 109 | 110 | if minetest.get_modpath("mushroom") ~= nil then 111 | register_food("mushroom:brown", 1) 112 | register_food("mushroom:red", 1, "", 3) 113 | -- mushroom potions: red = strong poison, brown = light restorative 114 | if minetest.get_modpath("vessels") then 115 | register_food("mushroom:brown_essence", 1, "vessels:glass_bottle", nil, 4) 116 | register_food("mushroom:poison", 1, "vessels:glass_bottle", 10) 117 | end 118 | end 119 | 120 | if minetest.get_modpath("docfarming") ~= nil then 121 | register_food("docfarming:carrot", 3) 122 | register_food("docfarming:cucumber", 2) 123 | register_food("docfarming:corn", 3) 124 | register_food("docfarming:potato", 4) 125 | register_food("docfarming:bakedpotato", 5) 126 | register_food("docfarming:raspberry", 3) 127 | end 128 | 129 | if minetest.get_modpath("farming_plus") ~= nil then 130 | register_food("farming_plus:carrot_item", 3) 131 | register_food("farming_plus:banana", 2) 132 | register_food("farming_plus:orange_item", 2) 133 | register_food("farming:pumpkin_bread", 4) 134 | register_food("farming_plus:strawberry_item", 2) 135 | register_food("farming_plus:tomato_item", 2) 136 | register_food("farming_plus:potato_item", 4) 137 | register_food("farming_plus:rhubarb_item", 2) 138 | end 139 | 140 | if minetest.get_modpath("mtfoods") ~= nil then 141 | register_food("mtfoods:dandelion_milk", 1) 142 | register_food("mtfoods:sugar", 1) 143 | register_food("mtfoods:short_bread", 4) 144 | register_food("mtfoods:cream", 1) 145 | register_food("mtfoods:chocolate", 2) 146 | register_food("mtfoods:cupcake", 2) 147 | register_food("mtfoods:strawberry_shortcake", 2) 148 | register_food("mtfoods:cake", 3) 149 | register_food("mtfoods:chocolate_cake", 3) 150 | register_food("mtfoods:carrot_cake", 3) 151 | register_food("mtfoods:pie_crust", 3) 152 | register_food("mtfoods:apple_pie", 3) 153 | register_food("mtfoods:rhubarb_pie", 2) 154 | register_food("mtfoods:banana_pie", 3) 155 | register_food("mtfoods:pumpkin_pie", 3) 156 | register_food("mtfoods:cookies", 2) 157 | register_food("mtfoods:mlt_burger", 5) 158 | register_food("mtfoods:potato_slices", 2) 159 | register_food("mtfoods:potato_chips", 3) 160 | --mtfoods:medicine 161 | register_food("mtfoods:casserole", 3) 162 | register_food("mtfoods:glass_flute", 2) 163 | register_food("mtfoods:orange_juice", 2) 164 | register_food("mtfoods:apple_juice", 2) 165 | register_food("mtfoods:apple_cider", 2) 166 | register_food("mtfoods:cider_rack", 2) 167 | end 168 | 169 | if minetest.get_modpath("fruit") ~= nil then 170 | register_food("fruit:apple", 2) 171 | register_food("fruit:pear", 2) 172 | register_food("fruit:bananna", 3) 173 | register_food("fruit:orange", 2) 174 | end 175 | 176 | if minetest.get_modpath("mush45") ~= nil then 177 | register_food("mush45:meal", 4) 178 | end 179 | 180 | if minetest.get_modpath("seaplants") ~= nil then 181 | register_food("seaplants:kelpgreen", 1) 182 | register_food("seaplants:kelpbrown", 1) 183 | register_food("seaplants:seagrassgreen", 1) 184 | register_food("seaplants:seagrassred", 1) 185 | register_food("seaplants:seasaladmix", 6) 186 | register_food("seaplants:kelpgreensalad", 1) 187 | register_food("seaplants:kelpbrownsalad", 1) 188 | register_food("seaplants:seagrassgreensalad", 1) 189 | register_food("seaplants:seagrassgreensalad", 1) 190 | end 191 | 192 | if minetest.get_modpath("mobfcooking") ~= nil then 193 | register_food("mobfcooking:cooked_pork", 6) 194 | register_food("mobfcooking:cooked_ostrich", 6) 195 | register_food("mobfcooking:cooked_beef", 6) 196 | register_food("mobfcooking:cooked_chicken", 6) 197 | register_food("mobfcooking:cooked_lamb", 6) 198 | register_food("mobfcooking:cooked_venison", 6) 199 | register_food("mobfcooking:cooked_fish", 6) 200 | end 201 | 202 | if minetest.get_modpath("creatures") ~= nil then 203 | register_food("creatures:meat", 6) 204 | register_food("creatures:flesh", 3) 205 | register_food("creatures:rotten_flesh", 3, "", 3) 206 | end 207 | 208 | if minetest.get_modpath("ethereal") then 209 | register_food("ethereal:strawberry", 1) 210 | register_food("ethereal:banana", 4) 211 | register_food("ethereal:pine_nuts", 1) 212 | register_food("ethereal:bamboo_sprout", 0, "", 3) 213 | register_food("ethereal:fern_tubers", 1) 214 | register_food("ethereal:banana_bread", 7) 215 | register_food("ethereal:mushroom_plant", 2) 216 | register_food("ethereal:coconut_slice", 2) 217 | register_food("ethereal:golden_apple", 4, "", nil, 10) 218 | register_food("ethereal:wild_onion_plant", 2) 219 | register_food("ethereal:mushroom_soup", 4, "ethereal:bowl") 220 | register_food("ethereal:mushroom_soup_cooked", 6, "ethereal:bowl") 221 | register_food("ethereal:hearty_stew", 6, "ethereal:bowl", 3) 222 | register_food("ethereal:hearty_stew_cooked", 10, "ethereal:bowl") 223 | if minetest.get_modpath("bucket") then 224 | register_food("ethereal:bucket_cactus", 2, "bucket:bucket_empty") 225 | end 226 | register_food("ethereal:fish_raw", 2) 227 | register_food("ethereal:fish_cooked", 5) 228 | register_food("ethereal:seaweed", 1) 229 | register_food("ethereal:yellowleaves", 1, "", nil, 1) 230 | register_food("ethereal:sashimi", 4) 231 | end 232 | 233 | if minetest.get_modpath("farming") and farming.mod == "redo" then 234 | register_food("farming:bread", 6) 235 | register_food("farming:potato", 1) 236 | register_food("farming:baked_potato", 6) 237 | register_food("farming:cucumber", 4) 238 | register_food("farming:tomato", 4) 239 | register_food("farming:carrot", 3) 240 | register_food("farming:carrot_gold", 6, "", nil, 8) 241 | register_food("farming:corn", 3) 242 | register_food("farming:corn_cob", 5) 243 | register_food("farming:melon_slice", 2) 244 | register_food("farming:pumpkin_slice", 1) 245 | register_food("farming:pumpkin_bread", 9) 246 | register_food("farming:coffee_cup", 2, "farming:drinking_cup") 247 | register_food("farming:coffee_cup_hot", 3, "farming:drinking_cup", nil, 2) 248 | register_food("farming:cookie", 2) 249 | register_food("farming:chocolate_dark", 3) 250 | register_food("farming:donut", 4) 251 | register_food("farming:donut_chocolate", 6) 252 | register_food("farming:donut_apple", 6) 253 | register_food("farming:raspberries", 1) 254 | register_food("farming:blueberries", 1) 255 | register_food("farming:muffin_blueberry", 4) 256 | if minetest.get_modpath("vessels") then 257 | register_food("farming:smoothie_raspberry", 2, "vessels:drinking_glass") 258 | end 259 | register_food("farming:rhubarb", 1) 260 | register_food("farming:rhubarb_pie", 6) 261 | register_food("farming:beans", 1) 262 | end 263 | 264 | if minetest.get_modpath("kpgmobs") ~= nil then 265 | register_food("kpgmobs:uley", 3) 266 | register_food("kpgmobs:meat", 6) 267 | register_food("kpgmobs:rat_cooked", 5) 268 | register_food("kpgmobs:med_cooked", 4) 269 | if minetest.get_modpath("bucket") then 270 | register_food("kpgmobs:bucket_milk", 4, "bucket:bucket_empty") 271 | end 272 | end 273 | 274 | if minetest.get_modpath("jkfarming") ~= nil then 275 | register_food("jkfarming:carrot", 3) 276 | register_food("jkfarming:corn", 3) 277 | register_food("jkfarming:melon_part", 2) 278 | register_food("jkfarming:cake", 3) 279 | end 280 | 281 | if minetest.get_modpath("jkanimals") ~= nil then 282 | register_food("jkanimals:meat", 6) 283 | end 284 | 285 | if minetest.get_modpath("jkwine") ~= nil then 286 | register_food("jkwine:grapes", 2) 287 | register_food("jkwine:winebottle", 1) 288 | end 289 | 290 | if minetest.get_modpath("cooking") ~= nil then 291 | register_food("cooking:meat_beef_cooked", 4) 292 | register_food("cooking:fish_bluewhite_cooked", 3) 293 | register_food("cooking:fish_clownfish_cooked", 1) 294 | register_food("cooking:meat_chicken_cooked", 2) 295 | register_food("cooking:meat_cooked", 2) 296 | register_food("cooking:meat_pork_cooked", 3) 297 | register_food("cooking:meat_toxic_cooked", -3) 298 | register_food("cooking:meat_venison_cooked", 3) 299 | register_food("cooking:meat_undead_cooked", 1) 300 | end 301 | 302 | -- ferns mod of plantlife_modpack 303 | if minetest.get_modpath("ferns") ~= nil then 304 | register_food("ferns:fiddlehead", 1, "", 1) 305 | register_food("ferns:fiddlehead_roasted", 3) 306 | register_food("ferns:ferntuber_roasted", 3) 307 | register_food("ferns:horsetail_01", 1) 308 | end 309 | 310 | if minetest.get_modpath("pizza") ~= nil then 311 | register_food("pizza:pizza", 30, "", nil, 30) 312 | register_food("pizza:pizzaslice", 5, "", nil, 5) 313 | end 314 | -------------------------------------------------------------------------------- /functions.lua: -------------------------------------------------------------------------------- 1 | -- read/write 2 | function hunger.read(player) 3 | local inv = player:get_inventory() 4 | if not inv then 5 | return nil 6 | end 7 | local hgp = inv:get_stack("hunger", 1):get_count() 8 | if hgp == 0 then 9 | hgp = 21 10 | inv:set_stack("hunger", 1, ItemStack({name = ":", count = hgp})) 11 | else 12 | hgp = hgp 13 | end 14 | if tonumber(hgp) > HUNGER_MAX + 1 then 15 | hgp = HUNGER_MAX + 1 16 | end 17 | return hgp - 1 18 | end 19 | 20 | function hunger.save(player) 21 | local inv = player:get_inventory() 22 | local name = player:get_player_name() 23 | local value = hunger.players[name].lvl 24 | if not inv or not value then 25 | return nil 26 | end 27 | if value > HUNGER_MAX then 28 | value = HUNGER_MAX 29 | end 30 | if value < 0 then 31 | value = 0 32 | end 33 | inv:set_stack("hunger", 1, ItemStack({name = ":", count = value + 1})) 34 | return true 35 | end 36 | 37 | function hunger.update_hunger(player, new_lvl) 38 | local name = player:get_player_name() or nil 39 | if not name then 40 | return false 41 | end 42 | if minetest.setting_getbool("enable_damage") == false then 43 | hunger.players[name] = 20 44 | return 45 | end 46 | local lvl = hunger.players[name].lvl 47 | if new_lvl then 48 | lvl = new_lvl 49 | end 50 | if lvl > HUNGER_MAX then 51 | lvl = HUNGER_MAX 52 | end 53 | hunger.players[name].lvl = lvl 54 | if lvl > 20 then 55 | lvl = 20 56 | end 57 | hud.change_item(player, "hunger", {number = lvl}) 58 | hunger.save(player) 59 | end 60 | local update_hunger = hunger.update_hunger 61 | 62 | -- player-action based hunger changes 63 | function hunger.handle_node_actions(pos, oldnode, player, ext) 64 | if not player or not player:is_player() then 65 | return 66 | end 67 | local name = player:get_player_name() 68 | if not name or not hunger.players[name] then 69 | return 70 | end 71 | 72 | local exhaus = hunger.players[name].exhaus 73 | if not exhaus then 74 | hunger.players[name].exhaus = 0 75 | --return 76 | end 77 | 78 | local new = HUNGER_EXHAUST_PLACE 79 | 80 | -- placenode event 81 | if not ext then 82 | new = HUNGER_EXHAUST_DIG 83 | end 84 | 85 | -- assume its send by action_timer(globalstep) 86 | if not pos and not oldnode then 87 | new = HUNGER_EXHAUST_MOVE 88 | end 89 | 90 | exhaus = exhaus + new 91 | 92 | if exhaus > HUNGER_EXHAUST_LVL then 93 | exhaus = 0 94 | local h = tonumber(hunger.players[name].lvl) 95 | if h > 0 then 96 | update_hunger(player, h - 1) 97 | end 98 | end 99 | 100 | hunger.players[name].exhaus = exhaus 101 | end 102 | 103 | 104 | -- Time based hunger functions 105 | local hunger_timer = 0 106 | local health_timer = 0 107 | local action_timer = 0 108 | 109 | local function hunger_globaltimer(dtime) 110 | hunger_timer = hunger_timer + dtime 111 | health_timer = health_timer + dtime 112 | action_timer = action_timer + dtime 113 | 114 | if action_timer > HUNGER_MOVE_TICK then 115 | for _,player in ipairs(minetest.get_connected_players()) do 116 | local controls = player:get_player_control() 117 | -- Determine if the player is walking 118 | if controls.up or controls.down or controls.left or controls.right then 119 | hunger.handle_node_actions(nil, nil, player) 120 | end 121 | end 122 | action_timer = 0 123 | end 124 | 125 | -- lower saturation by 1 point after second(s) 126 | if hunger_timer > HUNGER_TICK then 127 | for _,player in ipairs(minetest.get_connected_players()) do 128 | local name = player:get_player_name() 129 | local tab = hunger.players[name] 130 | if tab then 131 | local hunger = tab.lvl 132 | if hunger > 0 then 133 | update_hunger(player, hunger - 1) 134 | end 135 | end 136 | end 137 | hunger_timer = 0 138 | end 139 | 140 | -- heal or damage player, depending on saturation 141 | if health_timer > HUNGER_HEALTH_TICK then 142 | for _,player in ipairs(minetest.get_connected_players()) do 143 | local name = player:get_player_name() 144 | local tab = hunger.players[name] 145 | if tab then 146 | local air = player:get_breath() or 0 147 | local hp = player:get_hp() 148 | 149 | -- heal player by 1 hp if not dead and saturation is > 15 (of 30) player is not drowning 150 | if tonumber(tab.lvl) > HUNGER_HEAL_LVL and hp > 0 and air > 0 then 151 | player:set_hp(hp + HUNGER_HEAL) 152 | end 153 | 154 | -- or damage player by 1 hp if saturation is < 2 (of 30) 155 | if tonumber(tab.lvl) < HUNGER_STARVE_LVL then 156 | player:set_hp(hp - HUNGER_STARVE) 157 | end 158 | end 159 | end 160 | 161 | health_timer = 0 162 | end 163 | end 164 | 165 | if minetest.setting_getbool("enable_damage") then 166 | minetest.register_globalstep(hunger_globaltimer) 167 | end 168 | 169 | 170 | -- food functions 171 | local food = hunger.food 172 | 173 | function hunger.register_food(name, hunger_change, replace_with_item, poisen, heal, sound) 174 | food[name] = {} 175 | food[name].saturation = hunger_change -- hunger points added 176 | food[name].replace = replace_with_item -- what item is given back after eating 177 | food[name].poisen = poisen -- time its poisening 178 | food[name].healing = heal -- amount of HP 179 | food[name].sound = sound -- special sound that is played when eating 180 | end 181 | 182 | -- Poison player 183 | local function poisenp(tick, time, time_left, player) 184 | time_left = time_left + tick 185 | if time_left < time then 186 | minetest.after(tick, poisenp, tick, time, time_left, player) 187 | else 188 | hud.change_item(player, "hunger", {text = "hud_hunger_fg.png"}) 189 | end 190 | local hp = player:get_hp() -1 or 0 191 | if hp > 0 then 192 | player:set_hp(hp) 193 | end 194 | end 195 | 196 | -- wrapper for minetest.item_eat (this way we make sure other mods can't break this one) 197 | local org_eat = core.do_item_eat 198 | core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) 199 | local old_itemstack = itemstack 200 | itemstack = hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) 201 | for _, callback in pairs(core.registered_on_item_eats) do 202 | local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack) 203 | if result then 204 | return result 205 | end 206 | end 207 | return itemstack 208 | end 209 | 210 | function hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) 211 | local item = itemstack:get_name() 212 | local def = food[item] 213 | if not def then 214 | def = {} 215 | if type(hp_change) ~= "number" then 216 | hp_change = 1 217 | core.log("error", "Wrong on_use() definition for item '" .. item .. "'") 218 | end 219 | def.saturation = hp_change * 1.3 220 | def.replace = replace_with_item 221 | end 222 | local func = hunger.item_eat(def.saturation, def.replace, def.poisen, def.healing, def.sound) 223 | return func(itemstack, user, pointed_thing) 224 | end 225 | 226 | function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound) 227 | return function(itemstack, user, pointed_thing) 228 | if itemstack:take_item() ~= nil and user ~= nil then 229 | local name = user:get_player_name() 230 | if not hunger.players[name] then 231 | return itemstack 232 | end 233 | local sat = tonumber(hunger.players[name].lvl or 0) 234 | local hp = user:get_hp() 235 | -- Saturation 236 | if sat < HUNGER_MAX and hunger_change then 237 | sat = sat + hunger_change 238 | hunger.update_hunger(user, sat) 239 | end 240 | -- Healing 241 | if hp < 20 and heal then 242 | hp = hp + heal 243 | if hp > 20 then 244 | hp = 20 245 | end 246 | user:set_hp(hp) 247 | end 248 | -- Poison 249 | if poisen then 250 | hud.change_item(user, "hunger", {text = "hunger_statbar_poisen.png"}) 251 | poisenp(1.0, poisen, 0, user) 252 | end 253 | 254 | -- eating sound 255 | if not sound then 256 | sound = "hunger_eat" 257 | end 258 | minetest.sound_play(sound, {to_player = name, gain = 0.7}) 259 | 260 | if replace_with_item then 261 | if itemstack:is_empty() then 262 | itemstack:add_item(replace_with_item) 263 | else 264 | local inv = user:get_inventory() 265 | if inv:room_for_item("main", {name=replace_with_item}) then 266 | inv:add_item("main", replace_with_item) 267 | else 268 | local pos = user:getpos() 269 | pos.y = math.floor(pos.y + 0.5) 270 | core.add_item(pos, replace_with_item) 271 | end 272 | end 273 | end 274 | end 275 | 276 | return itemstack 277 | end 278 | end 279 | -------------------------------------------------------------------------------- /init.lua: -------------------------------------------------------------------------------- 1 | hunger = {} 2 | hunger.players = {} 3 | hunger.food = {} 4 | 5 | HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken 6 | HUNGER_HEALTH_TICK = 4 -- time in seconds after player gets healed/damaged 7 | HUNGER_MOVE_TICK = 0.5 -- time in seconds after the movement is checked 8 | 9 | HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node 10 | HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed 11 | HUNGER_EXHAUST_MOVE = 1.5 -- exhaustion increased this value if player movement detected 12 | HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player saturation gets lowered 13 | 14 | HUNGER_HEAL = 1 -- number of HP player gets healed after HUNGER_HEALTH_TICK 15 | HUNGER_HEAL_LVL = 15 -- lower level of saturation needed to get healed 16 | HUNGER_STARVE = 1 -- number of HP player gets damaged by hunger after HUNGER_HEALTH_TICK 17 | HUNGER_STARVE_LVL = 3 -- level of staturation that causes starving 18 | 19 | HUNGER_MAX = 30 -- maximum level of saturation 20 | 21 | 22 | local modpath = minetest.get_modpath("hunger") 23 | dofile(modpath .. "/functions.lua") 24 | dofile(modpath .. "/food.lua") 25 | dofile(modpath .. "/legacy.lua") 26 | 27 | 28 | -- Callbacks 29 | if minetest.setting_getbool("enable_damage") then 30 | minetest.register_on_joinplayer(function(player) 31 | local inv = player:get_inventory() 32 | inv:set_size("hunger", 1) 33 | 34 | local name = player:get_player_name() 35 | hunger.players[name] = {} 36 | hunger.players[name].lvl = hunger.read(player) 37 | hunger.players[name].exhaus = 0 38 | local lvl = hunger.players[name].lvl 39 | if lvl > 20 then 40 | lvl = 20 41 | end 42 | minetest.after(0.8, function() 43 | hud.swap_statbar(player, "hunger", "air") 44 | hud.change_item(player, "hunger", {number = lvl, max = 20}) 45 | end) 46 | end) 47 | 48 | -- for exhaustion 49 | minetest.register_on_placenode(hunger.handle_node_actions) 50 | minetest.register_on_dignode(hunger.handle_node_actions) 51 | minetest.register_on_respawnplayer(function(player) 52 | hunger.update_hunger(player, 20) 53 | end) 54 | end 55 | -------------------------------------------------------------------------------- /legacy.lua: -------------------------------------------------------------------------------- 1 | hud.item_eat = hunger.item_eat 2 | hud.set_hunger = hunger.save 3 | hud.get_hunger = hunger.load 4 | hud.save_hunger = hunger.save 5 | hud.load_hunger = hunger.load -------------------------------------------------------------------------------- /sounds/hunger_eat.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlockMen/hunger/a380daca31f02f5684185ba3fde7d97eae63791e/sounds/hunger_eat.ogg -------------------------------------------------------------------------------- /textures/hunger_statbar_poisen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlockMen/hunger/a380daca31f02f5684185ba3fde7d97eae63791e/textures/hunger_statbar_poisen.png --------------------------------------------------------------------------------