tweaks and shatter

This commit is contained in:
kepler155c
2018-11-03 04:47:52 -04:00
parent 047c2cdddb
commit aa66b1c663
6 changed files with 573 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ _G.requireInjector(_ENV)
local Config = require('config')
local Util = require('util')
local InventoryAdapter = require('chestAdapter18')
local device = _G.device
local os = _G.os
@@ -16,23 +17,51 @@ local sensor = device['plethora:sensor'] or
turtle.equip('right', 'plethora:module:3') and device['plethora:sensor'] or
error('Plethora sensor required')
local dispenser = device['minecraft:dispenser_89'] or
error('Dispenser not found')
local integrator = device['redstone_integrator_131'] or
error('Integrator not found')
local function pulse()
integrator.setOutput('north', true)
os.sleep(.25)
integrator.setOutput('north', false)
end
local function turnOffWater()
local list = dispenser.list()
if list[1].name == 'minecraft:bucket' then
pulse()
os.sleep(2)
end
end
local function turnOnWater()
if dispenser.list()[1].name == 'minecraft:water_bucket' then
pulse()
end
end
local function getCowCount()
local blocks = sensor.sense()
local grown = 0
local babies = 0
local xpCount = 0
Util.filterInplace(blocks, function(v)
if v.name == 'Cow' then
if v.y > -.5 then grown = grown + 1 end
if v.y < -.5 then babies = babies + 1 end
return v.y > -.5
elseif v.name == 'XPOrb' then
xpCount = xpCount + 1
end
end)
Util.print('%d grown, %d babies', grown, babies)
Util.print('%d grown, %d babies, %d xp', grown, babies, xpCount)
return #blocks
return #blocks, xpCount
end
local function butcher()
@@ -60,17 +89,30 @@ local function breed()
end
end
local chest = InventoryAdapter({ side = 'top', direction = 'down' }) or
error('missing chest above')
turtle.run(function()
turnOffWater()
repeat
if getCowCount() > config.max_cows then
local cowCount, xpCount = getCowCount()
if cowCount > config.max_cows then
turtle.setStatus('Butchering')
butcher()
elseif turtle.getItemCount('minecraft:wheat') == 0 then
turtle.setStatus('Out of wheat')
if chest:provide({ name = 'minecraft:wheat' }, 64) == 0 then
turtle.setStatus('Out of wheat')
end
else
turtle.setStatus('Breeding')
breed()
end
if xpCount > 2 then
turnOnWater()
os.sleep(8)
turnOffWater()
end
os.sleep(5)
until turtle.isAborted()
end)

31
apps/glassesDriver.lua Normal file
View File

@@ -0,0 +1,31 @@
_G.requireInjector(_ENV)
local device = _G.device
local kernel = _G.kernel
local os = _G.os
local glasses = require('shatter')
glasses.name = 'glasses'
glasses.type = 'rayban'
glasses.size = 'face'
device.glasses = glasses
glasses.setTextScale(.5)
glasses.setSize(100, 40)
kernel.hook({ 'glasses_click', 'glasses_up', 'glasses_drag' }, function(event, eventData)
local sx, sy = 6, 9
local scale = glasses.getTextScale()
local ox, oy = math.ceil(scale*sx), math.ceil(scale*sy)
local lookup = {
glasses_click = 'monitor_touch',
glasses_up = 'monitor_up',
glasses_drag = 'monitor_drag',
}
local x, y = math.floor(eventData[2]/ox) + 1, math.floor(eventData[3]/oy) + 1
os.queueEvent(lookup[event], 'glasses', x, y)
glasses.setCursorPos(x, y)
glasses.write('X ' .. eventData[3])
end)

View File

@@ -28,8 +28,9 @@ local monitor
local defaultEnv = Util.shallowCopy(_ENV)
defaultEnv.multishell = multishell
if args[2] then
if args[3] then
monitor = _G.device[args[3]]
elseif args[2] then
monitor = peripheral.wrap(args[2]) or syntax()
else
monitor = peripheral.find('monitor') or syntax()

View File

@@ -12,10 +12,6 @@ local peripheral = _G.peripheral
local printError = _G.printError
local turtle = _G.turtle
if not device.wireless_modem then
error('Modem is required')
end
if not turtle then
error('Can only be run on a turtle')
end
@@ -236,16 +232,18 @@ local function pickupHost(socket)
end
end
Event.addRoutine(function()
while true do
print('waiting for connection on port 5222')
local socket = Socket.server(5222)
if device.wireless_modem then
Event.addRoutine(function()
while true do
print('waiting for connection on port 5222')
local socket = Socket.server(5222)
print('pickup: connection from ' .. socket.dhost)
print('pickup: connection from ' .. socket.dhost)
Event.addRoutine(function() pickupHost(socket) end)
end
end)
Event.addRoutine(function() pickupHost(socket) end)
end
end)
end
local function eachEntry(t, fn)

View File

@@ -94,6 +94,7 @@ local function getPoint()
if not gpt then
mainPage.statusBar:timedStatus('Unable to get location', 3)
end
gpt.y = gpt.y - 1
return gpt
end