better gps setup + option icon change
This commit is contained in:
@@ -21,29 +21,31 @@ local function build()
|
||||
not turtle.has(CABLE, 4) or
|
||||
not turtle.has(ENDER_MODEM, 4) then
|
||||
error([[Place into inventory:
|
||||
* 8 Wired modem (blocks)
|
||||
* 4 Network cables
|
||||
* 5 Wired modem (blocks)
|
||||
* 8 Network cables
|
||||
* 4 Ender modems]])
|
||||
end
|
||||
|
||||
local blocks = {
|
||||
{ x = 1, y = 0, z = 0, b = WIRED_MODEM },
|
||||
{ x = 0, y = 0, z = 0, b = WIRED_MODEM },
|
||||
|
||||
{ x = 1, y = 0, z = 0, b = CABLE },
|
||||
{ x = 2, y = 0, z = 0, b = CABLE },
|
||||
{ x = 2, y = 1, z = 0, b = CABLE },
|
||||
{ x = 2, y = 2, z = 0, b = WIRED_MODEM },
|
||||
{ x = 2, y = 3, z = 0, b = ENDER_MODEM },
|
||||
|
||||
{ x = -1, y = 0, z = 0, b = WIRED_MODEM },
|
||||
{ x = -1, y = 0, z = 0, b = CABLE },
|
||||
{ x = -2, y = 0, z = 0, b = CABLE },
|
||||
{ x = -2, y = 1, z = 0, b = CABLE },
|
||||
{ x = -2, y = 2, z = 0, b = WIRED_MODEM },
|
||||
{ x = -2, y = 3, z = 0, b = ENDER_MODEM },
|
||||
|
||||
{ x = 0, y = 0, z = 1, b = WIRED_MODEM },
|
||||
{ x = 0, y = 0, z = 1, b = CABLE },
|
||||
{ x = 0, y = 0, z = 2, b = WIRED_MODEM },
|
||||
{ x = 0, y = 1, z = 2, b = ENDER_MODEM },
|
||||
|
||||
{ x = 0, y = 0, z = -1, b = WIRED_MODEM },
|
||||
{ x = 0, y = 0, z = -1, b = CABLE },
|
||||
{ x = 0, y = 0, z = -2, b = WIRED_MODEM },
|
||||
{ x = 0, y = 1, z = -2, b = ENDER_MODEM },
|
||||
}
|
||||
@@ -73,36 +75,42 @@ local function server()
|
||||
for k, modem in pairs(modems) do
|
||||
Util.merge(modem, peripheral.wrap(k))
|
||||
modem.open(gps.CHANNEL_GPS)
|
||||
--modem.open(999)
|
||||
end
|
||||
|
||||
local function getPosition(computerId, modem, distance)
|
||||
local computer = memoize(computers, computerId, function() return { } end)
|
||||
table.insert(computer, {
|
||||
position = vector.new(modem.x, modem.y, modem.z),
|
||||
distance = distance,
|
||||
})
|
||||
if #computer == 4 then
|
||||
local pt = GPS.trilaterate(computer)
|
||||
if pt then
|
||||
positions[computerId] = pt
|
||||
term.clear()
|
||||
for k,v in pairs(positions) do
|
||||
Util.print('ID: %d: %s %s %s', k, v.x, v.y, v.z)
|
||||
end
|
||||
end
|
||||
computers[computerId] = nil
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
|
||||
local e, side, channel, computerId, message, distance = os.pullEvent( "modem_message" )
|
||||
if e == "modem_message" then
|
||||
-- We received a message from a modem
|
||||
local side, channel, computerId, sMessage, distance = p1, p2, p3, p4, p5
|
||||
if channel == gps.CHANNEL_GPS and sMessage == "PING" and distance then
|
||||
-- We received a ping message on the GPS channel, send a response
|
||||
local modem = modems[side]
|
||||
if modem then
|
||||
local computer = memoize(computers, computerId, function() return { } end)
|
||||
table.insert(computer, {
|
||||
position = vector.new(modem.x, modem.y, modem.z), distance = distance
|
||||
})
|
||||
if #computer == 4 then
|
||||
local pt = GPS.trilaterate(computer)
|
||||
if pt then
|
||||
positions[computerId] = pt
|
||||
term.clear()
|
||||
for k,v in pairs(positions) do
|
||||
Util.print('ID: %d: %s %s %s', k, v.x, v.y, v.z)
|
||||
end
|
||||
end
|
||||
computers[computerId] = nil
|
||||
end
|
||||
if distance and modems[side] then
|
||||
if channel == gps.CHANNEL_GPS and message == "PING" then
|
||||
for _, modem in pairs(modems) do
|
||||
modem.transmit( computerId, gps.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
modem.transmit(computerId, gps.CHANNEL_GPS, { modem.x, modem.y, modem.z })
|
||||
end
|
||||
getPosition(computerId, modems[side], distance)
|
||||
end
|
||||
|
||||
--if channel == gps.CHANNEL_GPS or channel == 999 then
|
||||
-- getPosition(computerId, modems[side], distance)
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -113,7 +121,7 @@ if args[1] == 'build' then
|
||||
|
||||
turtle.setPoint({ x = 0, y = -y, z = 0, heading = 0 })
|
||||
build()
|
||||
turtle._goto({ x = 0, y = 0, z = 0, heading = 0 })
|
||||
turtle._goto({ x = 0, y = 1, z = 0, heading = 0 })
|
||||
|
||||
print('Activate all modems')
|
||||
print('Press enter when ready')
|
||||
@@ -138,5 +146,5 @@ elseif args[1] == 'server' then
|
||||
|
||||
else
|
||||
|
||||
error('Syntax: gps [build|server]')
|
||||
error('Syntax: gpsServer [build | server]')
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ local page = UI.Page {
|
||||
{ text = 'Edit', event = 'details' },
|
||||
{ text = 'Refresh', event = 'refresh', x = -12 },
|
||||
{
|
||||
text = '\206',
|
||||
text = '\187',
|
||||
x = -3,
|
||||
dropdown = {
|
||||
{ text = 'Setup', event = 'network' },
|
||||
@@ -58,6 +58,8 @@ local page = UI.Page {
|
||||
backgroundFocusColor = colors.cyan,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'eject',
|
||||
[ 'up' ] = 'grid_up',
|
||||
[ 'down' ] = 'grid_down',
|
||||
},
|
||||
},
|
||||
storageStatus = UI.Text {
|
||||
@@ -216,6 +218,12 @@ function page:eventHandler(event)
|
||||
UI:setPage('item', item)
|
||||
end
|
||||
|
||||
elseif event.type == 'grid_up' then
|
||||
self.grid:emit({ type = 'scroll_up' })
|
||||
|
||||
elseif event.type == 'grid_down' then
|
||||
self.grid:emit({ type = 'scroll_down' })
|
||||
|
||||
elseif event.type == 'refresh' then
|
||||
self:refresh()
|
||||
self.grid:draw()
|
||||
@@ -253,6 +261,7 @@ function page:eventHandler(event)
|
||||
self.filter = nil
|
||||
end
|
||||
self:applyFilter()
|
||||
self.grid:setIndex(1)
|
||||
self.grid:draw()
|
||||
self.statusBar.filter:focus()
|
||||
|
||||
|
||||
45
miners/blockMiner.lua
Normal file
45
miners/blockMiner.lua
Normal file
@@ -0,0 +1,45 @@
|
||||
local GPS = require("gps")
|
||||
local Point = require("point")
|
||||
local Util = require("util")
|
||||
|
||||
local peripheral = _G.peripheral
|
||||
local turtle = _G.turtle
|
||||
|
||||
local args = {...}
|
||||
local block = args[1] or error("Syntax: blockMiner [item name]")
|
||||
|
||||
local function equip(side, item, rawName)
|
||||
local equipped = Peripheral.lookup('side/' .. side)
|
||||
|
||||
if equipped and equipped.type == item then
|
||||
return true
|
||||
end
|
||||
|
||||
if not turtle.equip(side, rawName or item) then
|
||||
if not turtle.selectSlotWithQuantity(0) then
|
||||
error('No slots available')
|
||||
end
|
||||
turtle.equip(side)
|
||||
if not turtle.equip(side, item) then
|
||||
error('Unable to equip ' .. item)
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
local function scan()
|
||||
equip("left", "plethora:module:2")
|
||||
return peripheral.call("left", "scan")
|
||||
end
|
||||
|
||||
if turtle.isEquipped("modem") ~= "right" then
|
||||
equip("right", "computercraft:advanced_modem")
|
||||
end
|
||||
|
||||
local pt = GPS.getPoint(2) or error("GPS not found")
|
||||
equip("left", "plethora:module")
|
||||
local facing = peripheral.call("left", "getBlockMeta", 0, 0, 0).state.facing
|
||||
pt.heading = Point.facings[facing].heading
|
||||
turtle.setPoint(pt, true)
|
||||
equip("left", "minecraft:diamond_pickaxe")
|
||||
Reference in New Issue
Block a user