Milo: remote learn + remove logger

This commit is contained in:
kepler155c@gmail.com
2019-01-22 15:50:37 -05:00
parent e4cfba5750
commit 4276ea533f
13 changed files with 363 additions and 282 deletions

View File

@@ -0,0 +1,26 @@
local Sound = require('sound')
local args = { ... }
local context = args[1]
local function learn()
context:sendRequest({
request = 'craft',
slot = 15,
})
end
context.responseHandlers['craft'] = function(response)
if response.success then
Sound.play('entity.item.pickup')
else
Sound.play('entity.villager.no')
end
end
return {
menuItem = 'Learn Recipe',
callback = function()
learn()
end,
}

View File

@@ -0,0 +1,45 @@
local Event = require('event')
local device = _G.device
local os = _G.os
local args = { ... }
local context = args[1]
local SHIELD_SLOT = 2
Event.addRoutine(function()
local lastTransfer
while true do
local sleepTime = 1.5
if lastTransfer and os.clock() - lastTransfer < 3 then
sleepTime = .25
end
os.sleep(context.socket and sleepTime or 5)
if context.state.deposit then
local neural = device.neuralInterface
local inv = context.state.useShield and 'getEquipment' or 'getInventory'
if not neural or not neural[inv] then
_G._debug('missing Introspection module')
elseif context.state.server and (context.state.useShield or context.state.slot) then
local s, m = pcall(function()
local method = neural[inv]
local item = method and method().list()[context.state.useShield and SHIELD_SLOT or context.state.slot]
if item then
if context:sendRequest({
request = 'deposit',
slot = context.state.useShield and 'shield' or context.state.slot,
count = item.count,
}) then
lastTransfer = os.clock()
end
end
end)
if not s and m then
_G._debug(m)
end
end
end
end
end)

View File

@@ -81,7 +81,7 @@ function page:depositAll()
for slot, item in pairs(inv) do
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
context.page:sendRequest({
context:sendRequest({
request = 'deposit',
slot = slot,
count = item.count,
@@ -94,12 +94,15 @@ function page:eventHandler(event)
if event.type == 'checkbox_change' and event.element.formKey == 'includeHotbar' then
context.state.depositAll.includeHotbar = event.checked
page:updateInventoryList()
elseif event.type == 'form_complete' then
Config.update('miloRemote', context.state)
page:depositAll()
UI:setPreviousPage()
elseif event.type == 'form_cancel' then
UI:setPreviousPage()
else
return UI.Page.eventHandler(self, event)
end