OpenMods / OpenPeripheral

https://openmods.info
MIT License
67 stars 25 forks source link

Add possibility to get charge of fluid tanks #84

Closed hron84 closed 10 years ago

hron84 commented 10 years ago

It would be useful if tanks can be queryed to which amount of liquids contained inside. Technically it is possible, because IFluidTank exposes correspondent infos: https://github.com/MinecraftForge/MinecraftForge/blob/master/src/main/java/net/minecraftforge/fluids/IFluidTank.java but it requires access not only to IFluidHandler but an IFluidTank interface. too. I do not know it is possible or not.

theoriginalbit commented 10 years ago

You can already get information from tanks. Here is the information you can get

theoriginalbit commented 10 years ago

oh to expand the getTankInfo on the IFluidHandler is better the description of what it does

Returns an array of objects which represent the internal tanks. These objects cannot be used to
manipulate the internal tanks. See {@link FluidTankInfo}.

And this is the method that we expose, as you already know from issue 83.

hron84 commented 10 years ago

Ahh. I usually discover lua tables with table.foreach(tbl, print) but it only listed rawName, that is why i assumed capacity and amount is not available.

theoriginalbit commented 10 years ago

table.foreach doesn't do what you think it does clearly. It has to be in a loop I believe just like pairs.

Best method of checking things in a table

for k,v in pairs(tbl) do
  print(k, ' = ', v)
end

you may have to place a sleep in after the print if there are lots of items in the table. all depends on the table you're wanting to display.

personally I like to use

for k,v in pairs(tbl) do
  print(k, ' = ', v)
  os.pullEvent("key")
end

as this allows me to have it wait for me to press a key before showing the next element.