Page 1 of 1

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

Posted: Wed Aug 20, 2014 9:09 am
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

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

Posted: Wed Aug 20, 2014 2:21 pm
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.