add more function for storage peripheral
zaze06 opened this issue ยท 15 comments
Useful information to include:
- Explanation of how the feature/change should work. that I can have a chest wrap a peripheral to it and get the max mum of item that can exist in it
- Some rationale/use case for a feature. My general approach to designing new features is to ask yourself "what issue are we trying to solve" and then "is this the best way to solve this issue?". this can salve to get the maximum items in a container for example I have a farm and what to know how full the storage is I have a dank above it and it can caonain about half a million items and it whole be nice to have that I get do
chest.gteMaxItems()
and it returns about half a million if the chest if my dank and way I just can't calculate it or type it in as a variabel is because I may need to upgrade it or chage storage method then that half a million is not correct and it could say for example140% full
and that whole not be correct. I will not get surprised if this is something that the team has that about and just didn't make t but it whole be nice if it existed
We can't return the maximum number of items, as that's not available to us. However, we can return the number of slots, and it should be possible for a user to determine the maximum number of items from that.
that whole be nice an I guess you do not get have the maximum stack size bucks then you would be able to return a maximum numbers of items.
local inv = peripheral.wrap("some inventory")
local slots = inv.size() -- get size in slots
local stackSize = 64 -- maximum items per slot
print("Inventory can hold", slots * stackSize "items.")
Since the generic peripheral api doesn't know what items you intend to store in an inventory, it can't guess what the stack size is (e.g. How does the peripheral know if you're going to be storing ender pearls or cobblestone? It can't know). You, however, know what the stack size will be, so you can put it in manually.
You can even write the above as a function to get the max size on demand
local function getMaxItems(inv, stackSize)
return inv.size() * stackSize
end
local chest = peripheral.wrap("chest")
local otherChest = peripheral.wrap("other chest")
print("Max items of first chest holding ender pearls:", getMaxItems(chest, 16))
print("Max items of other chest holding cobblestone:", getMaxItems(otherChest, 64))
not rely related but in what file do I found the method list for inventory Peripherals?
not rely related but in what file do I found the method list for inventory Peripherals?
Yes that whole work but is for example valila storage but if I use for example ether a /dank/null then it wholdet work because then the 64 or 16 when the stack size if more then 1k and I what this to have so I don't have to chage the program is I chage storage medium
Ahhhh I see what you're asking now. It's not that you want to get the maximum number of items storable in something like a chest, but rather like Thermal's Caches. Something where you can have multiple thousand of the same item in one "slot".
Yes, this could be particularly useful. However, I don't know the limits of the generic inventory api so I don't know if that even is data that it has access to. If it's not, integration would have to be added on a per-mod basis, which would doubtlessly be painful to add manually for every mod out there...
I feel like I remember asking about something similar in the past though (back in the Plethora days), but was answered with a, "No, it's not possible." Due to this reason.
I may be wrong but shuldent this word?
public static int getMaxItems( IItemHandler inventory )
{
int size = inventory.getSlots();
int maxItems = size*inventory.getSlotLimit(0);
return maxItems;
}
I don't know how to implement it so I can test if it isn't just having the method in the class
Looking at Dank storage (assuming that's what mod you're using), they do correctly override IItemHandler.getSlotLimit
, so it should be possible to expose that.
Don't know if people have ideas on naming and API? inventory.getItemLimit(slot)
seems the easiest, though also feels a little weird to me.
I may be wrong but shuldent this word?
public static int getMaxItems( IItemHandler inventory ) { int size = inventory.getSlots(); int maxItems = size*inventory.getSlotLimit(0); return maxItems; }
I think exposing only the getSlotLimit
function would be better (rather than size * inv.getSlotLimit(0)
. We already have access to the inventory's size on the Lua side, so we can do the multiplication there. This would allow us to get slot limit of something which may allow stacking up to the thousands (or maybe only allowed to hold 1 or 2 items) in slot 3, but has a normal slot limit in slots 1 and 2.
I don't know if any mods actually do that, but it would be useful to have in case some mod does.
so if we guna make it as a method to use then it should be like this? go thru every slot and increase the MacItems by the stack limit per slot
public static int getMaxItems( IItemHandler inventory )
{
int size = inventory.getSlots();
int maxItems = 0
for(int i = 0; i < size; I++){
maxItems += inventory.getSlotLimit(i);
}
return maxItems;
}