[Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.2] [lua_inv]

Post Reply
User avatar
Noodlemire
Member
Posts: 61
Joined: Sun May 27, 2018 00:07
GitHub: Noodlemire
In-game: Noodlemire

[Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.2] [lua_inv]

by Noodlemire » Post

!Warning!: This is an abomination.

!Warning!: There is no way to automatically make this mod compatible with others. Support for any other mod that uses inventories or formspecs will probably need to be manually created in the near (or far) future.

!Warning!: This mod will replace and delete players' previous inventories, if they existed. It will attempt to import old items to the new system, but there is currently no way to put them back. USE THIS MOD IN A FRESH WORLD unless you either never remove lua_inv, or you're fine with an inventory wipe.

This mod attempts to create a total replacement for Minetest's entire inventory system. This does not just provide polishing or workarounds for the various shortcomings of Minetest's inventories. Instead, absolutely everything is custom-made in Lua. MetaData, ItemStacks, and Inventory objects are all created from scratch in this system, granting it total control over the very nature of these objects.

So why was this made in the first place? As mentioned previously, Minetest's regular inventory system has a variety of shortcomings and missing features. Some have somewhat decent workarounds, but others are virtually impossible, and there are times where a workaround just doesn't provide a proper solution. Below this is a list of some, but not all of the particular shortcomings that inspired lua_inv.
  • Items that can change their appearances. The common workaround is to create an entire registration for every single possible visual state that the item can have. This can work on a small or medium scale, but it has the potential to either be excessive, or unworkable if you don't know every possible visual at the time of registration.
  • Items that have animated sprites. There is normally no true workaround for this, except to give up and just use a still image.
  • Stackable items that can have durability applied to them. In normal Minetest, count and wear are mutually exclusive, and there is no true, bug-free way to implement having them both be together.
  • Inventory callbacks that apply to Lua functions. By default, move/put/take callbacks are completely bypassed by Lua code, or by just picking up an item off of the ground, unless the programmer of each inventory-related mod goes out of their way to try to respect these. In some cases, they might as well not exist.
By creating lua_inventory, the above features and more are finally possible. Every object that this new system uses is built from the ground-up to be more configurable and feature-rich than anything in Minetest's inventories.
  • You can use ItemStack's MetaData to set the "inventory_image" field to any image file, allowing item images to be changed at any time.
  • You can set _lua_inv_animation() in any item's definition, and this will allow it to be animated in inventory, hotbar, wielded_item, and item entity forms. There are even Meta fields to change the item's animation parameters at any time.
  • Setting count and wear on an object is supported natively. Just give tool_capabilities to a craftitem's definition, and it will be provided automatically.
  • Everything has a callback you can set to allow changes, or make things happen upon changes, even including the MetaData. These callbacks apply to all Lua functions as one would expect. Methods to bypass them do exist and aren't even that complicated. However, programmers now have to go out of their way to bypass the callbacks- not the other way around.
  • Full circular parent/child relationships. Wherever applicable, each object is given a read-only "parent" field, which can be used to check its owner. From just a MetaData object, you can fetch the ItemStack that owns it, the Inventory that owns the ItemStack and even the player/node that owns the Inventory.
  • In a similar manner, all ItemStacks are passed via reference, rather than copy, unless specified otherwise. You don't need to "commit" changes to an ItemStack, the same way you need to in regular Minetest.
  • The on_use function on an item's definition will no longer replace the usual digging behavior.
  • There is a "Dynamic Formspec" system in place. You can create essentially custom formspec elements by using pre-existing ones as building blocks. You can easily change the very layout of a formspec as needed, and create semi-persistent data with the help of a single MetaData object owned by the formspec as a whole, usable by every individual FormspecElement.
  • And more! Check the provided api.txt document for details about how everything is used.
Required mods:
  • Default: Chests, Furnaces, Bookshelves
  • Vessels: Vessel Shelves
To help with testing, players with the "debug" privilege are able to use the "/testitems" command. This will provide a few items to test features like stackwear, dynamic inventory images, and animated inventory images. Repository: https://github.com/Noodlemire/lua_inv
Liscense: LGPL 2.1, https://github.com/Noodlemire/lua_inv/blob/master/LICENSE.txt
Download (Latest): https://mega.nz/file/Cm5X3KqB#ibciyX87zjQQFFC9ulVV7u-Iir6BoSTsXvlstyxadu8
Last edited by Noodlemire on Thu Sep 02, 2021 23:20, edited 3 times in total.

User avatar
Noodlemire
Member
Posts: 61
Joined: Sun May 27, 2018 00:07
GitHub: Noodlemire
In-game: Noodlemire

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [lua_inv]

by Noodlemire » Post

Version 1.0.1 brings a few various patches. Most notably, the hotbar is *probably* fixed so that it displays properly on different-sized screens. In addition, default furnaces are now supported, which are probably the most important inventory to have for a standard survival experience. Many things have also been fixed for mobile users, with imperfections.

See the full changelog.txt for details.

Download: https://mega.nz/file/vmxmwBja#S6Jzhrg7xApJacXLcNgouyFKhUB5Id-JUnfIzcy8YQM

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.1] [lua_inv]

by runs » Post

best do this improvements in c++ engine.

Make short and constant PRs please.

User avatar
Noodlemire
Member
Posts: 61
Joined: Sun May 27, 2018 00:07
GitHub: Noodlemire
In-game: Noodlemire

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.1] [lua_inv]

by Noodlemire » Post

runs wrote:
Wed Sep 01, 2021 20:06
best do this improvements in c++ engine.

Make short and constant PRs please.
Heh, no. I'm a long ways off from being familiar enough with the C++ engine to be able to do anything with it. I don't even know where to start, honestly, plus I wouldn't be realistically able to code for it on my phone. (And, yes, a sizeable portion of my Lua code was written and tested on my phone.

Also, I already got this to be more functional than I ever expected while I was working on it, so I'm just going to roll with it for the foreseeable future.

User avatar
Noodlemire
Member
Posts: 61
Joined: Sun May 27, 2018 00:07
GitHub: Noodlemire
In-game: Noodlemire

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.1] [lua_inv]

by Noodlemire » Post

Version 1.0.2 brings more patches, and a notable extension to the API. Dynamic Formspecs now allow you to make simple page-based systems. These use sfinv-style tabs by default, but they can be disabled so you can make your own. Also, bookshelves and vessels shelves are now supported.

See the full changelog.txt for details.

Download: https://mega.nz/file/Cm5X3KqB#ibciyX87zjQQFFC9ulVV7u-Iir6BoSTsXvlstyxadu8

User avatar
Minix
Member
Posts: 144
Joined: Thu Nov 12, 2020 13:51
In-game: Minix

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.2] [lua_inv]

by Minix » Post

I tested the latest version with Minetest 5.4.0 and I like it, this is promising.

The 3D wielded item and animation are a nice addition, as well as the skin preview on the inventory.

There are many issues, I know this is work in progress but I will list them here:

-Wielded items are set too low on the HUD and you do not see them unless they are big like tools or if you look down, this is not even fixed by the set aspect ratio command.
-The testitems command does not work.
-This is probably common sense but it does not work with versions prior to 5.4.0, you should state that most of the features only work in 5.4.0 and greater.
-I tested the mod in development_test and the 3D wielded items show in front of you instead of your right hand side, this may require testing on other games not dependent on minetest_game like NodeCore, MineClone and others.
-The chest of all things in development_test opens and you can see items but you cannot take them out, again this requires testing on other games.
-I tested the mod on a Linux computer and noticed that some of the HUD buttons seem to be designed with smartphone players in mind, they are useful and a better user interface implementation for touchscreen devices in my opinion, but the usual shortcut key bindings like shift+left click to place items in the craft grid are missing and makes it very annoying to use on a computer.
-The inventory in creative is overridden by sfinv, I assume this is still not done.

I also noticed that the sqlite database for storing the user inventories seems to be unused by this mod at all, and instead uses a text file called lua_inv to store the inventory data in mod_storage. I know the only place where mods can save data persistently is mod_storage but I am not sure if this approach will cause performance issues for servers in the future, especially considering that most of the inventory work is being done in lua and not C++, but inventory operations are not as heavy as mapgen, so it will have to be seen.

Overall I think this is a project with lots of potential, we just need other developers to use its API to make even better things out of it. And just a side note, you are a madlad for coding on a smartphone.

User avatar
Noodlemire
Member
Posts: 61
Joined: Sun May 27, 2018 00:07
GitHub: Noodlemire
In-game: Noodlemire

Re: [Mod] Complete and Total Lua-Only Inventory Rewrite [1.0.2] [lua_inv]

by Noodlemire » Post

Minix wrote:
Mon Sep 13, 2021 04:25
-Wielded items are set too low on the HUD
They aren't set on the HUD at all. It's an entity, attached to the player's model and set to be visible in first person. This means it can't be easily fixed without instead using a specialized model that can move in accordance to where the player is looking. This is also why the wield image is weird in DevTest.
Minix wrote:
Mon Sep 13, 2021 04:25
-The testitems command does not work.
There should be a setting you can use to enable it. It's disabled by default since it essentially gives infinite pickaxes and torches, even if the pickaxes are weaker than they look.
Minix wrote:
Mon Sep 13, 2021 04:25
-I tested the mod on a Linux computer and noticed that some of the HUD buttons seem to be designed with smartphone players in mind [...] the usual shortcut key bindings like shift+left click to place items in the craft grid are missing...
This is not something I can currently fix. Formspecs do not allow me to properly check keypresses, so I had to design controls out of exclusively left clicking.
Minix wrote:
Mon Sep 13, 2021 04:25
-The chest of all things in development_test opens and you can see items but you cannot take them out...
-The inventory in creative is overridden by sfinv, I assume this is still not done.
Yeah, neither of those are implemented. EVERYTHING inventory_related will need to be ported manually due to fundamental differences in the API.
Minix wrote:
Mon Sep 13, 2021 04:25
I also noticed that the sqlite database for storing the user inventories seems to be unused by this mod at all...
I don't think I could. ItemStacks that the C++ engine use, and ItemStacks that lua_inv uses, are fundamentally different things. They have functions of similar names, and can be converted to an extent, but they're more than different enough that I generally can't just throw lua_inv ItemStacks at C++ controlled functions and expect things to just work.
Minix wrote:
Mon Sep 13, 2021 04:25
-This is probably common sense but it does not work with versions prior to 5.4.0, you should state that most of the features only work in 5.4.0 and greater.
I suppose I could make this clearer in the forum post, readme, etc. It is in the mod.conf though, so I believe it'd be clear enough to anyone on ContentDB or the in-game browser.
Minix wrote:
Mon Sep 13, 2021 04:25
Overall I think this is a project with lots of potential, we just need other developers to use its API to make even better things out of it. And just a side note, you are a madlad for coding on a smartphone.
Thank you! I do hope someone gets good use out of it at some point. Oh, and Lua coding on a phone is actually pretty easy, fun fact.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 13 guests