foreign keyboards

This commit is contained in:
kepler155c@gmail.com
2019-04-21 23:46:04 -04:00
parent 60efe15fd9
commit 320714c2d0
6 changed files with 158 additions and 50 deletions

View File

@@ -1172,9 +1172,8 @@ function input:translate(event, code, p1, p2)
end end
elseif event == 'char' then elseif event == 'char' then
if not self.pressed[keys.leftAlt] and if not self.fired then
not self.pressed[keys.rightAlt] then self.fired = true
self.fired = true
return code -- input:toCode(code) return code -- input:toCode(code)
end end

View File

@@ -3,6 +3,7 @@ local GPS = require('gps')
local itemDB = require('core.itemDB') local itemDB = require('core.itemDB')
local Point = require('point') local Point = require('point')
local Socket = require('socket') local Socket = require('socket')
local Sound = require('sound')
local Util = require('util') local Util = require('util')
local UI = require('ui') local UI = require('ui')
@@ -21,11 +22,37 @@ local scanner = device['plethora:scanner'] or
-- hud -- hud
local canvas = glasses and glasses.canvas() local canvas = glasses and glasses.canvas()
if canvas then if canvas then
local lh
local function addText(x, y, text, color)
local th = canvas.group.addText({ x, y }, text, color or 0xa0a0a0FF)
lh = lh or th.getLineHeight()
th.setShadow(true)
th.setScale(.75)
return th
end
canvas.group = canvas.addGroup({ 4, 90 }) canvas.group = canvas.addGroup({ 4, 90 })
canvas.bg = canvas.group.addRectangle(0, 0, 60, 24, 0x00000033) canvas.group.bg = canvas.group.addRectangle(0, 0, 80, 10, 0x40404080)
canvas.text = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF) canvas.group.addLines(
canvas.text.setShadow(true) { 0, 0 },
canvas.text.setScale(.75) { 80, 0 },
{ 80, 10 },
{ 0, 10 },
{ 0, 0 },
0x202020FF,
2)
addText(20, 2, 'Swarm Miner', 0xc0c0c0FF)
local y = 15
addText(3, y, 'Turtles')
canvas.turtles = addText(60, y, '')
canvas.group.addLine({ 0, y + lh - 2 }, { 80, y + lh - 2 }, 0x404040FF, 4)
y = y + lh + 5
addText(3, y, 'Queue')
canvas.queue = addText(60, y, '')
canvas.group.addLine({ 0, y + lh - 2 }, { 80, y + lh - 2 }, 0x404040FF, 4)
end end
-- container -- container
@@ -512,9 +539,14 @@ function page:eventHandler(event)
UI.Page.eventHandler(self, event) UI.Page.eventHandler(self, event)
end end
Event.onInterval(3, function() Event.onInterval(1, function()
if not abort and not paused then if not abort and not paused then
page:scan()
local meta = scanner.getMetaOwner()
if meta.isSneaking then
page:scan()
Sound.play('entity.bobber.throw', .6)
end
end end
end) end)
@@ -541,9 +573,8 @@ Event.onInterval(1, function()
page.info:sync() page.info:sync()
if canvas then if canvas then
local text = string.format('Turtles: %s\nQueue: %s', canvas.turtles.setText(tostring(Util.size(turtles)))
Util.size(turtles), Util.size(queue)) canvas.queue.setText(tostring(Util.size(queue)))
canvas.text.setText(text)
end end
end) end)

77
ignore/mobPickup.lua Normal file
View File

@@ -0,0 +1,77 @@
local Point = require('point')
local Util = require('util')
local device = _G.device
local os = _G.os
local scanner = device['plethora:scanner']
local sensor = device['plethora:sensor']
local id = sensor.getID()
local function dropOff()
local blocks = scanner.scan()
local b = Util.find(blocks, 'name', 'minecraft:hopper')
print(not not b)
if b then
print('walking ', b.x, b.y + 1, b.z)
os.sleep(1)
sensor.walk(b.x, b.y + 1, b.z)
os.sleep(2)
repeat until not sensor.isWalking()
print('done walking')
blocks = scanner.scan()
b = Util.find(blocks, 'name', 'minecraft:hopper')
if b then
print(b.x, b.z)
end
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
print('dropped')
sensor.getEquipment().drop(1)
os.sleep(1)
end
end
end
while true do
local sensed = Util.reduce(sensor.sense(), function(acc, s)
s.y = Util.round(s.y)
if s.y == 0 and s.id ~= id then
--s.x = Util.round(s.x)
--s.z = Util.round(s.z)
acc[s.id] = s
end
return acc
end, { })
local pt = { x = 0, y = 0, z = 0 }
while true do
local b = Point.closest(pt, sensed)
if not b then
break
end
sensed[b.id] = nil
b = sensor.getMetaByID(b.id)
if b then
print('picking up ', b.x, b.y, b.z)
sensor.walk(b.x, b.y, b.z)
os.sleep(2)
repeat until not sensor.isWalking()
print('done goto')
os.sleep(.5)
pt = b
local amount = sensor.getEquipment().suck(1)
print('sucked: ' .. amount)
if amount == 0 then
print('dropping')
dropOff()
break
end
end
end
os.sleep(5)
end

View File

@@ -11,10 +11,11 @@ local parallel = _G.parallel
local STARTUP_FILE = 'usr/autorun/fly.lua' local STARTUP_FILE = 'usr/autorun/fly.lua'
if not modules.launch or not modules.getMetaOwner then if not modules.launch or not modules.getMetaOwner then
error([[Required: print([[Required:
* Kinetic augment * Kinetic augment
* Entity sensor * Entity sensor
* Introspection module]]) * Introspection module]])
error('missing required item')
end end
if not fs.exists(STARTUP_FILE) then if not fs.exists(STARTUP_FILE) then

View File

@@ -41,17 +41,17 @@ local function getPoint()
end end
local targets = { local targets = {
["minecraft:emerald_ore"] = 0x46FF26AA, ["minecraft:emerald_ore"] = { "minecraft:emerald", 0 },
["minecraft:diamond_ore"] = 0x50F8FFAA, ["minecraft:diamond_ore"] = { "minecraft:diamond", 0 },
["minecraft:gold_ore"] = 0xFFDF50AA, ["minecraft:gold_ore"] = { "minecraft:gold_ingot", 0 },
["minecraft:redstone_ore"] = 0xCC121566, ["minecraft:redstone_ore"] = { "minecraft:redstone", 0 },
["minecraft:lit_redstone_ore"] = 0xCC121566, ["minecraft:lit_redstone_ore"] = { "minecraft:redstone", 0 },
["minecraft:iron_ore"] = 0xFFAC8766, ["minecraft:iron_ore"] = { "minecraft:iron_ingot", 0 },
["minecraft:lapis_ore"] = 0x0A107F66, ["minecraft:lapis_ore"] = { "minecraft:dye", 4 },
["minecraft:coal_ore"] = 0x20202066, ["minecraft:coal_ore"] = { "minecraft:coal", 0 },
["quark:biotite_ore"] = 0x02051C66, --["quark:biotite_ore"] = 0x02051C66,
["minecraft:quartz_ore"] = 0xCCCCCC66, ["minecraft:quartz_ore"] = { "minecraft:quartz", 0 },
["minecraft:glowstone"] = 0xFFDFA166 ["minecraft:glowstone"] = { "minecraft:glowstone_dust", 0 },
} }
local projecting = { } local projecting = { }
local offset = getPoint() or showRequirements('GPS') local offset = getPoint() or showRequirements('GPS')
@@ -90,21 +90,21 @@ local function update()
for _, b in pairs(blocks) do for _, b in pairs(blocks) do
if not projecting[b.id] then if not projecting[b.id] then
projecting[b.id] = b projecting[b.id] = b
--[[
b.box = canvas.addFrame({ b.box = canvas.addFrame({
pos.x - offset.x + b.x + -(pos.x % 1) + .5, pos.x - offset.x + b.x + -(pos.x % 1),
pos.y - offset.y + b.y + -(pos.y % 1) + .5, pos.y - offset.y + b.y + -(pos.y % 1),
pos.z - offset.z + b.z + -(pos.z % 1) + .5, pos.z - offset.z + b.z + -(pos.z % 1),
}) })
b.box.setDepthTested(false) b.box.setDepthTested(false)
b.box.addItem({ 0, 0 }, b.name, b.damage, 2) local target = targets[b.name]
--]] b.box.addItem({ .25, .25 }, target[1], target[2], 2)
--[[
b.box = canvas.addItem({ b.box = canvas.addItem({
pos.x - offset.x + b.x + -(pos.x % 1) + .5, pos.x - offset.x + b.x + -(pos.x % 1) + .5,
pos.y - offset.y + b.y + -(pos.y % 1) + .5, pos.y - offset.y + b.y + -(pos.y % 1) + .5,
pos.z - offset.z + b.z + -(pos.z % 1) + .5, pos.z - offset.z + b.z + -(pos.z % 1) + .5,
}, b.name, b.damage, .5) }, b.name, b.damage, .5)
--]]
b.box.setDepthTested(false) b.box.setDepthTested(false)
end end
end end