This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
thorgot's profile picture

[1.4.7] turtle.refuel() uses getContainerItem() instead of getContainerItemStack(), losing item damage information on fuel

Started by thorgot, 21 January 2013 - 10:38 AM
thorgot #1
Posted 21 January 2013 - 11:38 AM
ComputerCraft Version Information: 1.4.7 Client

Description of Bug: Putting in a big lava bucket from my mod and using turtle.refuel() empties the bucket of all liquid in it but only adds 1000 fuel to the turtle

Steps to Reproduce Bug: See above. Program I used was:


turtle.refuel( 1 )
print(turtle.getFuelLevel())

How to Fix the Bug:

This occurs because of the use of getContainerItem() instead of getContainerItemStack() in the refuel code in CC.

getContainerItem() works fine for fuel items which don't use damage to store any information, but for mods like mine, where this information is used to store how much fuel is left in the bucket, using getContainerItem() loses this extra information and just empties the bucket.

getContainerItemStack() on the other hand preserves this information while working in all cases getContainerItem works. You'll should null check the return value of it to be safe, but I think this is a 2 or 3 line fix overall.

KingLemming made the same change to ThermalExpansion to fix a similar interaction (for which I am grateful to him). I'd love to fix this on my end but I don't think there's anything I can do.

Thoughts?
Cloudy #2
Posted 21 January 2013 - 01:19 PM
Will be changed for the next version.

In the mean time, if you REALLY wanted to work round it on your side, you can use the turtle refuel event to handle the refuel yourself.
thorgot #3
Posted 21 January 2013 - 05:37 PM
Will be changed for the next version.

In the mean time, if you REALLY wanted to work round it on your side, you can use the turtle refuel event to handle the refuel yourself.


Thank you for fixing it for the next version.

I was playing around with fixing it in the meantime in the way you recommended, but I can't seem to find the API as source anywhere. I tried using BON as suggested several places on these forums, which allowed me to fix the problem with something like this:


public void refuelEvents(TurtleRefuel event) {
    etc
    event.setHandled();
    etc
}

However, doing it this way I can't run with my mod unless CC is installed.

Some mods like railcraft, TE, and buildcraft have APIs you can use without having the full mod installed. Does CC have something similar? Or am I missing some way of including the API without the entire mod?
Cloudy #4
Posted 21 January 2013 - 08:51 PM
An API like that isn't really appropriate for ComputerCraft - and that kind of event would require it in any case. It's possible to conditionally load a mod interface conditionally - look into FMLPostInitilizationEvent. You could load a CC proxy with an interface in your code.

Either way it is fixed in the next version.
thorgot #5
Posted 22 January 2013 - 04:34 AM
Understood. Thanks again.