[MOD 0.11.x] canInsert() that returns a count

Topics and discussion about specific mods
Post Reply
Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

[MOD 0.11.x] canInsert() that returns a count

Post by Rseding91 »

This isn't so much a mod its self as it is a function for modders to use. It's a function that takes an entity, a table of inventory indexes and a item stack and returns a table with the ["count"] that can be inserted and the count of slots ["slots"] that will get used by inserting that many of the stack.


Example usage:

Code: Select all

local result = canInsert(game.player, {[1] = 2}, {name = "iron-ore", count = 5000})
-- "2" for player inventory index 2 (the main inventory)

if result["count"] > 0 then
	game.player.print("Inserting: " .. result["count"] .. " iron-ore using: " .. result["slots"] .. " empty slots.")
	game.player.insert({name = "iron-ore", count = result["count"]})
end
For a more complex usage example see my mod "Faster Spilling" -> here


Current version: 1.1.0
code
File download:
canInsert.zip
(622 Bytes) Downloaded 286 times
Last edited by Rseding91 on Sat Nov 01, 2014 4:35 pm, edited 3 times in total.
If you want to get ahold of me I'm almost always on Discord.

User avatar
SHiRKiT
Filter Inserter
Filter Inserter
Posts: 706
Joined: Mon Jul 14, 2014 11:52 pm
Contact:

Re: [MOD 0.10.x] canInsert() that returns a count

Post by SHiRKiT »

Maybe there should be a shared library for that? I know FreeER did something like this. Maybe there could be a Github repo to store those methods that people judge useful.

Post Reply

Return to “Mods”