Posted 14 April 2016 - 02:34 AM
You can skip my intro if you want, it is kinda long….
Hi, so let me start this off by saying that I'm playing on the Direwolf20 pack, Minecraft version 1.6.4. What I'm attempting to do is automate the removal of saplings from a barrel into a Forestry fermenter. The way I go about doing this is I have my computer wrap the barrel its next to as well as the fermenter over rednet. My program basically checks if there is more than 63 items in the barrel (I'm going to explain this part a little as well) and that there are "no items" in the "first" slot in the Fermenter. Now, this is where my issue occurs.
Thanks to OpenPeripherals, I'm actually able to check the inventories on these objects, but thanks to OpenPeripherals being the way it is, I use the .getAllStacks() method, assuming that this will ALWAYS return all the inventories, even if there isn't anything in them. NO. I AM WRONG. That method will only return a table IF there is something in the fermenter's inventory. However, lets say in my head I map slot 1 to where the saplings go, and slot 2 for fertilizer. Sounds simple, yeah? Well, no, it isn't. The method returns a table, first containing an index for each slot, then each slots information in another table. However. lets say I have no saplings (slot 1 is empty), you might assume that there would just be un-initialized information in the table. Well, no, slot one on the table now gathers information from slot 2, the fertilizer.
–Skip to here!–
My issue is this: when using OpenPeripheral's getAllStacks() methods, how do I account for an empty inventory slot, thus breaking my program (as follows)?
So, a quick rundown, I init all my variables, I run update everytime to get current information, I then use that information to pass some checks on whether or not to output redstone to draw some saplings out of the barrel and into my fermenter. You might notice, that I'm checking that the item in the first slot's name is Fertilizer. This is because if there is no item where the saplings are (usually slot 1), the new slot 1 is where the fertilizer goes (slot 2).
A list of what I'm using for this setup:
Oh, last thing I wanted to mention, due to the way OpenPeripherals returns the amount of items in a barrel, 64 is the largest number I can get. even if I have a barrel full of 4096 items.
Edit: I should probably mention, the reason I went with this setup was because I wanted to ALWAYS have items in my barrel, since these "$#!7**" factorization barrels cannot be locked to keep their item, and I don't want excess logs/apples getting thrown in there if it's empty, I'm trying to toggle the redstone for a pipe only when the inventory is low and that I have the stock. I also don't want to flood the ThermalExpansion itemduct with numerous amounts of items.
Hi, so let me start this off by saying that I'm playing on the Direwolf20 pack, Minecraft version 1.6.4. What I'm attempting to do is automate the removal of saplings from a barrel into a Forestry fermenter. The way I go about doing this is I have my computer wrap the barrel its next to as well as the fermenter over rednet. My program basically checks if there is more than 63 items in the barrel (I'm going to explain this part a little as well) and that there are "no items" in the "first" slot in the Fermenter. Now, this is where my issue occurs.
Thanks to OpenPeripherals, I'm actually able to check the inventories on these objects, but thanks to OpenPeripherals being the way it is, I use the .getAllStacks() method, assuming that this will ALWAYS return all the inventories, even if there isn't anything in them. NO. I AM WRONG. That method will only return a table IF there is something in the fermenter's inventory. However, lets say in my head I map slot 1 to where the saplings go, and slot 2 for fertilizer. Sounds simple, yeah? Well, no, it isn't. The method returns a table, first containing an index for each slot, then each slots information in another table. However. lets say I have no saplings (slot 1 is empty), you might assume that there would just be un-initialized information in the table. Well, no, slot one on the table now gathers information from slot 2, the fertilizer.
–Skip to here!–
My issue is this: when using OpenPeripheral's getAllStacks() methods, how do I account for an empty inventory slot, thus breaking my program (as follows)?
local barrel = peripheral.wrap("left")
local ferm = peripheral.wrap("factory_3_0")
local barInv = 0
local fermInv = 0
local fermTab = ferm.getAllStacks()
local barTab = barrel.getAllStacks()
function update()
barTab = barrel.getAllStacks()
fermTab = ferm.getAllStacks()
barInv = barTab[2].qty
fermInv = fermTab[1].qty
term.clear()
term.setCursorPos(1,1)
print("Barrel: "..barInv)
print("Fermenter: "..fermInv.." ("..fermTab[1].name..")")
end
function checkAmount()
if (barInv > 63 and fermTab[1].name == "Fertilizer") then
redstone.setOutput("bottom", true)
sleep(2)
redstone.setOutput("bottom", false)
end
end
function mainLoop()
while true do
update()
checkAmount()
sleep(20)
end
end
So, a quick rundown, I init all my variables, I run update everytime to get current information, I then use that information to pass some checks on whether or not to output redstone to draw some saplings out of the barrel and into my fermenter. You might notice, that I'm checking that the item in the first slot's name is Fertilizer. This is because if there is no item where the saplings are (usually slot 1), the new slot 1 is where the fertilizer goes (slot 2).
A list of what I'm using for this setup:
- Factorization Barrels (I don't have JABBA :( )
- ThermalExpansion ItemDucts
- ComputerCraft computers
- ProjectRed redstone cables
Oh, last thing I wanted to mention, due to the way OpenPeripherals returns the amount of items in a barrel, 64 is the largest number I can get. even if I have a barrel full of 4096 items.
Edit: I should probably mention, the reason I went with this setup was because I wanted to ALWAYS have items in my barrel, since these "$#!7**" factorization barrels cannot be locked to keep their item, and I don't want excess logs/apples getting thrown in there if it's empty, I'm trying to toggle the redstone for a pipe only when the inventory is low and that I have the stock. I also don't want to flood the ThermalExpansion itemduct with numerous amounts of items.
Edited on 14 April 2016 - 12:49 AM