neural cleanup

This commit is contained in:
kepler155c@gmail.com
2019-04-30 23:02:49 -04:00
parent 7549c4e620
commit 0ec0c63ba6
15 changed files with 82 additions and 144 deletions

View File

@@ -1,6 +1,7 @@
local Point = require('point')
local neural = require('neural.interface')
local Point = require('point')
local Sound = require('sound')
local Util = require('util')
local Util = require('util')
local device = _G.device
local os = _G.os
@@ -8,25 +9,17 @@ local os = _G.os
local scanner = device['plethora:scanner']
local sensor = device['plethora:sensor']
local id = sensor.getID()
local function dropOff()
print('dropping')
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')
neural.walkTo({ x = b.x, y = 0, z = b.z })
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)
@@ -36,13 +29,24 @@ local function dropOff()
end
end
local function pickup(id)
local b = sensor.getMetaByID(id)
if b then
neural.walkTo(b)
local amount = sensor.getEquipment().suck()
print('sucked: ' .. amount)
if amount > 0 then
Sound.play('entity.item.pickup')
return true
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.name == 'Item' then
--s.x = Util.round(s.x)
--s.z = Util.round(s.z)
acc[s.id] = s
end
return acc
@@ -52,32 +56,17 @@ while true do
while true do
local b = Point.closest(pt, sensed)
if not b then
os.sleep(5)
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)
if pickup(b.id) then
pt = b
local amount = sensor.getEquipment().suck(1)
print('sucked: ' .. amount)
if amount == 0 then
amount = sensor.getEquipment().suck(2)
if amount == 0 then
print('dropping')
dropOff()
break
end
end
Sound.play('entity.item.pickup')
else
dropOff()
break
end
end
os.sleep(5)
end