add computercraft stuff

This commit is contained in:
LordMZTE 2022-03-06 00:25:27 +01:00
parent 264ec6bca3
commit a8e35502ac
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
19 changed files with 315 additions and 3 deletions

View File

@ -0,0 +1,11 @@
# Remote Control Turtle
## How to install
1. Put the Program in the Remote Folder on a pocket computer with an ender modem
2. Put the Program in the Turtle Folder on a turtle with an ender modem on the left and a pickaxe on the right
3. Adjust the `remoteID` variable in the turtle program to the ID of your remote
4. Adjust the `turtleID` variable in the remote program to the ID of your turtle
___
## How to use
- Turn the remote and the turtle on, the available commands should be shown on the remote

View File

@ -0,0 +1,129 @@
rednet.open "back"
local turtle_id = 0
local actions = {
[keys.w] = function()
send_remote(turtle.forward())
end,
[keys.a] = function()
send_remote(turtle.turnLeft())
end,
[keys.s] = function()
send_remote(turtle.back())
end,
[keys.d] = function()
send_remote(turtle.turnRight())
end,
[keys.space] = function()
send_remote(turtle.up())
end,
[keys.leftShift] = function()
send_remote(turtle.down())
end,
[keys.b] = function()
send_remote(turtle.dig())
end,
[keys.p] = function()
send_remote(turtle.place())
end,
[keys.t] = function()
send_remote(turtle.digUp())
end,
[keys.g] = function()
send_remote(turtle.digDown())
end,
[keys.z] = function()
send_remote(turtle.placeUp())
end,
[keys.h] = function()
send_remote(turtle.placeDown())
end,
[keys.h] = function()
send_remote(turtle.placeDown())
end,
[keys.q] = function()
send_remote(turtle.drop())
end,
[keys.c] = function()
send_remote(turtle.suck())
end,
[keys.i] = function()
for i = 1, 16 do
turtle.select(i)
local item = turtle.getItemDetail()
if item ~= nil then
send_remote(i .. ": " .. item.name .. " " .. item.count)
end
end
end,
[keys.e] = function()
for i = 1, 16 do
turtle.select(i)
turtle.drop()
send_remote(i)
end
end,
}
local function reset_output()
term.clear()
term.setCursorPos(1, 1)
print "WASD Space Shift = Move"
print "Q = Drop"
print "C = Collect"
print "B/Z/H = Break/Up/Down"
print "P/U/J = Place/Up/Down"
print "1-0 / * - + , . = Select Slot"
print "F = Refuel"
print "I = Show Inventory"
print "E = Empty Inventory"
end
reset_output()
local function send(msg)
msg = string.dump(msg)
rednet.send(turtle_id, msg, "rcturtle")
end
local function set_slot(num)
send(function()
local id, val = rednet.receive()
turtle.select(val)
send_remote(val)
end)
rednet.send(turtle_id, num)
end
while true do
parallel.waitForAny(function()
local _, msg = rednet.receive "rcremote"
reset_output()
print(msg)
end, function()
local _, key = os.pullEvent "key"
local action = actions[key];
if action then
send(action)
end
end, function()
local _, char = os.pullEvent "char"
local slots = {
["0"] = 10,
["/"] = 11,
["*"] = 12,
["-"] = 13,
["+"] = 14,
[","] = 15,
["."] = 16,
}
if slots[char] then
set_slot(slots[char])
elseif tonumber(char) then
set_slot(tonumber(char))
end
end)
end

View File

@ -0,0 +1,21 @@
rednet.open "left"
remote_id = 1
function _G.send_remote(msg)
rednet.send(remote_id, msg, "rcremote")
end
term.clear()
term.setCursorPos(1, 1)
print("ID: " .. os.getComputerID())
while true do
id, message, protocol = rednet.receive "rcturtle"
local f, err = loadstring(message)
if err then
print("invalid command", message)
send_remote(false)
else
f()
end
end

View File

@ -0,0 +1,26 @@
# Stargate Controller
**This program can control a stargate from SGCraft with a computer**
___
## How To install:
1. move all the files and subdirectorys in this directory (except the readme) to the root computer
2. Connect Peripherals in `internal/conf.lua` and adjust the IDs in `internal/conf.lua`
3. Put Your addresses into `internal/addresses.lua`, they will be used by other programs
3. Restart the Computer or run `startup.lua`
___
## How To Use
- You should see some info on the connected monitor and the Computer
- You should see a list of available Commands, they should be pretty self explanatory
- Commands can be added simply by creating a file in the computer's root
### Commands:
- addr
- Will Allow to Dial the Stargate to an address from the address book
- close
- closes the Stargate
- dial
- allows dialing to a given address
- info
- prints some information
- iris
- controls the Stargate's iris if it is installed
- prntaddr
- prints the address book to paper using the connected printer

View File

@ -0,0 +1,15 @@
dofile "internal/addresses.lua"
dofile "internal/conf.lua"
for i, na in pairs(addresses) do
print(i, na[1])
end
input = read()
n = tonumber(input)
if n then
print(sg.dial(addresses[n][2]))
else
print "invalid"
end

View File

@ -0,0 +1,2 @@
dofile "internal/conf.lua"
print(sg.disconnect())

View File

@ -0,0 +1,2 @@
dofile "internal/conf.lua"
print(sg.dial(read()))

View File

@ -0,0 +1,9 @@
dofile "internal/conf.lua"
process, chevrons, connection = sg.stargateState()
print("Process:", process)
print("Active Chevrons:", chevrons)
print("Connection:", connection)
print("Energy:", sg.energyAvailable())
print("Remote Address:", sg.remoteAddress())
print("Local Address:", sg.localAddress())
print("Iris State:", sg.irisState())

View File

@ -0,0 +1,6 @@
--Add Addresses Here
addresses = {
{ "Spawn", "BFE8-IK6-1U" },
{ "Nether", "H9XB-FDQ-U7" },
{ "End", "S4Y9-TZL-U8" },
}

View File

@ -0,0 +1,9 @@
--Add Peripherals Here
sgName = "stargate_0"
monName = "top"
prntName = "left"
--Dont Change This
sg = peripheral.wrap(sgName)
mon = peripheral.wrap(monName)
prnt = peripheral.wrap(prntName)

View File

@ -0,0 +1,10 @@
dofile "internal/conf.lua"
print "close/open"
input = read()
if input == "close" then
print(sg.closeIris())
elseif input == "open" then
print(sg.openIris())
else
print "invalid"
end

View File

@ -0,0 +1,25 @@
dofile "internal/conf.lua"
dofile "internal/addresses.lua"
if prnt.getPaperLevel() <= 0 or prnt.getInkLevel() <= 0 then
print "Insufficient Paper/Dye"
return
end
prnt.newPage()
prnt.write("This Gate: " .. sg.localAddress())
prnt.setCursorPos(1, 3)
for k, v in pairs(addresses) do
x, z = prnt.getCursorPos()
xl, zl = prnt.getPageSize()
if zl <= z then
prnt.endPage()
prnt.newPage()
else
prnt.write("--" .. v[1] .. "--")
prnt.setCursorPos(x, z + 1)
prnt.write(v[2])
prnt.setCursorPos(x, z + 2)
end
end
prnt.endPage()

View File

@ -0,0 +1,48 @@
dofile "internal/conf.lua"
function processInput(input)
if input == "exit.lua" then
error()
end
if fs.exists(input) and string.len(input) > 0 and input ~= "startup.lua" and not fs.isDir(input) then
dofile(input)
else
print "File Not Found"
end
os.sleep(1)
end
while true do
mon.clear()
mon.setCursorPos(1, 1)
shell.run("monitor " .. monName .. " info")
term.clear()
term.setCursorPos(1, 1)
dofile "info.lua"
commands = fs.list ""
print()
print "Available Commands:"
for i, k in pairs(commands) do
if not fs.isDir(k) and k ~= "startup.lua" then
len = string.len(k)
print(string.sub(k, 1, len - 4))
end
end
print "exit"
print()
parallel.waitForAny(function()
input = read() .. ".lua"
processInput(input)
end, function()
while true do
local event = os.pullEvent()
if event == "sgStargateStateChange" or event == "sgIrisStateChange" then
break
end
end
end)
end

View File

@ -1,3 +0,0 @@
#!/bin/sh
# requires the stylua formatter to be installed
stylua $(find -name '*.lua')

2
justfile Normal file
View File

@ -0,0 +1,2 @@
format:
stylua $(find -name '*.lua')