1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

Make refuelling a little more flexible

This removes the link between item size and refuel limit, meaning
working with other items (such as FE items) is a little easier.
This commit is contained in:
SquidDev 2019-04-16 10:28:10 +01:00
parent 9e9f199e55
commit 3bf47b5290
2 changed files with 15 additions and 6 deletions

View File

@ -303,7 +303,8 @@ public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull O
case 31:
{
// refuel
int count = parseCount( args, 0 );
int count = optInt( args, 0, Integer.MAX_VALUE );
if( count < 0 ) throw new LuaException( "Refuel count " + count + " out of range" );
return tryCommand( context, new TurtleRefuelCommand( count ) );
}
case 32:

View File

@ -6,19 +6,27 @@ if #tArgs > 1 then
return
elseif #tArgs > 0 then
if tArgs[1] == "all" then
nLimit = 64 * 16
nLimit = nil
else
nLimit = tonumber( tArgs[1] )
if not nLimit then
print("Invalid limit, expected a number or \"all\"")
return
end
end
end
if turtle.getFuelLevel() ~= "unlimited" then
for n=1,16 do
for n = 1, 16 do
-- Stop if we've reached the limit, or are fully refuelled.
if (nLimit and nLimit <= 0) or turtle.getFuelLevel() >= turtle.getFuelLimit() then
break
end
local nCount = turtle.getItemCount(n)
if nLimit > 0 and nCount > 0 and turtle.getFuelLevel() < turtle.getFuelLimit() then
local nBurn = math.min( nLimit, nCount )
if nCount > 0 then
turtle.select( n )
if turtle.refuel( nBurn ) then
if turtle.refuel( nLimit ) and nLimit then
local nNewCount = turtle.getItemCount(n)
nLimit = nLimit - (nCount - nNewCount)
end