Ability to create out-of-world LuaItemStacks.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Ability to create out-of-world LuaItemStacks.
What?
The ability to create / store a LuaItemStack via script without the stack being associated to an entity on the map.
Why?
For mods it would often be benefitial to be able to store a non-simple ItemStack (i.e. armor-with-grid, item-with-tags, item-with-inventory, etc) without having to worry about the stack becoming invalid from outside influence. The current "hack" i have to use for this is an invisible, indestructible chest, but as that has to exist somewhere on the map it's not safe from other mods that e.g. delete "unused" chunks.
Other examples are building a blueprint from string, which currently requires an itemstack to get access to the blueprint methods, or managing a temporary bonus inventory.
How?
Stacks might be created via game.create_stack() and stored for as long as the lua state holds a reference to the stack - as obviously mods can't be trusted to properly call .destroy() on things they don't use anymore. Obviously stacks would have to be storable in global.
Again, i realize this would probably be a lot of work to implement, so if it's unfeasible i'd still be happy just knowing why, or how good of an example i'd have to come up with to make it feasible :).
The ability to create / store a LuaItemStack via script without the stack being associated to an entity on the map.
Why?
For mods it would often be benefitial to be able to store a non-simple ItemStack (i.e. armor-with-grid, item-with-tags, item-with-inventory, etc) without having to worry about the stack becoming invalid from outside influence. The current "hack" i have to use for this is an invisible, indestructible chest, but as that has to exist somewhere on the map it's not safe from other mods that e.g. delete "unused" chunks.
Other examples are building a blueprint from string, which currently requires an itemstack to get access to the blueprint methods, or managing a temporary bonus inventory.
How?
Stacks might be created via game.create_stack() and stored for as long as the lua state holds a reference to the stack - as obviously mods can't be trusted to properly call .destroy() on things they don't use anymore. Obviously stacks would have to be storable in global.
Again, i realize this would probably be a lot of work to implement, so if it's unfeasible i'd still be happy just knowing why, or how good of an example i'd have to come up with to make it feasible :).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Ability to create out-of-world LuaItemStacks.
I'd like to vote for this as a request too -- some sort of item storage for mods.
The current pre-release version of Blueprint Extensions works around this for now with some trickery: See Util.get_dummy_surface(), Util.store_item() and Util.clear_item() in the 0.2.2 source code. That said, this is entirely a hack and it'd be great if it were unnecessary.
The current pre-release version of Blueprint Extensions works around this for now with some trickery: See Util.get_dummy_surface(), Util.store_item() and Util.clear_item() in the 0.2.2 source code. That said, this is entirely a hack and it'd be great if it were unnecessary.
- TelemakFactorio
- Long Handed Inserter
- Posts: 53
- Joined: Fri Oct 14, 2016 4:30 pm
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
An itemstack is basically an array of size 2 containing a prototype name and a quantity.
So that you can create itemstacks everywhere anytime.
Maybe I have not understood the request ?
So that you can create itemstacks everywhere anytime.
Maybe I have not understood the request ?
Re: Ability to create out-of-world LuaItemStacks.
This alone is not sufficient for a lot of cases, like if the item in question is a blueprint (book).TelemakFactorio wrote: ↑Mon Oct 29, 2018 10:40 pm An itemstack is basically an array of size 2 containing a prototype name and a quantity.
So that you can create itemstacks everywhere anytime.
Maybe I have not understood the request ?
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
See the Api doc for a full list of item stack properties. Ammo, durability, blueprints, armor grids, etcpp. There are quite a few things and it would be nice if mods weren't forced to use ugly hacks or build a script only item decoder...TelemakFactorio wrote: ↑Mon Oct 29, 2018 10:40 pm An itemstack is basically an array of size 2 containing a prototype name and a quantity.
So that you can create itemstacks everywhere anytime.
Maybe I have not understood the request ?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- TelemakFactorio
- Long Handed Inserter
- Posts: 53
- Joined: Fri Oct 14, 2016 4:30 pm
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
Right ! An itemStack controller would be appreciated for sure.
Re: Ability to create out-of-world LuaItemStacks.
Perhaps this is already possible? An item with inventory that has the hidden flag? That would avoid the invisible on map hack and its problems.
Edit: on second thoughts then you have the problem that it ties to a player
Edit: on second thoughts then you have the problem that it ties to a player
Shameless mod plugging: Ribbon Maze
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
Any stack that has to "exist" in the "world" somehow has some sort of problem. That's why i wrote this request for lua-state stack support :).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Ability to create out-of-world LuaItemStacks.
One of my oldest pull requests just got accepted which allows this. It should be in the next version. Main additions are: LuaGameScript::create_inventory, LuaInventory::resize, LuaInventory::destroy. Obviously once you've created an inventory you can use its slots as you wish. You can't destroy or resize inventories other than those created from create_inventory.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
That sounds awesome. Just out of curiosity, *how* old was the pull? Also i'm guessing that if i "lose" the reference to such an inventory it's auto-destroyed? And all inventories are "private" (i.e. other mods can't mess them up)?Boodals wrote: ↑Tue Apr 14, 2020 11:23 am One of my oldest pull requests just got accepted which allows this. It should be in the next version. Main additions are: LuaGameScript::create_inventory, LuaInventory::resize, LuaInventory::destroy. Obviously once you've created an inventory you can use its slots as you wish. You can't destroy or resize inventories other than those created from create_inventory.
+ Thanks!!
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Ability to create out-of-world LuaItemStacks.
I made the pull request on 16th Feb 2019, hoping it would make it into 0.17.eradicator wrote: ↑Tue Apr 14, 2020 9:33 pm That sounds awesome. Just out of curiosity, *how* old was the pull? Also i'm guessing that if i "lose" the reference to such an inventory it's auto-destroyed? And all inventories are "private" (i.e. other mods can't mess them up)?
If you lose the reference, it isn't destroyed. I tried to make that work, but there was no way to do it that wouldn't cause desyncs (I think because garbage collection is not deterministic). Rseding added game.get_script_inventories, similar to rendering.get_all_ids, so they are not lost forever, but the potential to "lose" references is the main reason it wasn't accepted for so long.
Because of game.get_script_inventories, they are not strictly private, but i'd be surprised if a mod blindly interacted with any script inventories, similar to renderings.
Re: Ability to create out-of-world LuaItemStacks.
What's wrong with just using a table, and re-applying the values you need on an as-needed basis?
Re: Ability to create out-of-world LuaItemStacks.
You lose all the meta information about the item. Equipment in armor, blueprints in blueprint books, entities in blueprints, health, durability. Items in items-with-inventory and so on.
If you want to get ahold of me I'm almost always on Discord.
- eradicator
- Smart Inserter
- Posts: 5207
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Ability to create out-of-world LuaItemStacks.
"rendering.clear()" is pretty awesome destructive and i've heared of both accidential and deliberate usage of that. Though kinda off-topic, and with only "get them all" for inventories at least the accidential part can't (shouln't...) happen. I'm curious though, how would one use get_script_inventories without a method to identify which inventory belongs to "me" and which doesn't? Assuming they're just standard inventories without a name or UID or anything?
I pondered the idea but was never desperate enough to do it. The sheer amount of code to completely reimplement all possible item properties of every item type is daring enough. And to top it off there's read-only stuff like item_number so the thing would be forever stuck being only 95% correct.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Ability to create out-of-world LuaItemStacks.
eradicator wrote: ↑Thu Apr 16, 2020 10:54 pm I'm curious though, how would one use get_script_inventories without a method to identify which inventory belongs to "me" and which doesn't? Assuming they're just standard inventories without a name or UID or anything?
If you want to get ahold of me I'm almost always on Discord.