~jordanreger/cc

0fa78a1e923c58b8c076962007b5b0c94f4a378c — Jordan Reger 3 months ago 468a0ed
feat: add automatic_door directory
4 files changed, 57 insertions(+), 0 deletions(-)

M README.md
A automatic_doors/README.md
A automatic_doors/client.lua
A automatic_doors/receiver.lua
M README.md => README.md +3 -0
@@ 1,6 1,9 @@
# ~jordanreger/cc
This is a collection of my one-off [computercraft](https://tweaked.cc) scripts.

## automatic door system
To read more about the automatic door system, please move to the [`automatic_doors`](https://git.sr.ht/~jordanreger/tree/main/automatic_doors) directory.

## srht.lua
This script allows you to get other scripts from the [paste tool](https://paste.sr.ht). To download this onto your computer in Minecraft, run the following:


A automatic_doors/README.md => automatic_doors/README.md +4 -0
@@ 0,0 1,4 @@
# Computercraft Automatic Doors
By utilising a GPS cluster, a wireless pocket computer, iron doors, and a receiver computer, you can make a flawless security system that opens the doors to your house just by walking "into" them.

> todo(jordanreger): add photos of setup
\ No newline at end of file

A automatic_doors/client.lua => automatic_doors/client.lua +29 -0
@@ 0,0 1,29 @@
rednet.open("back")

local receiver_id = -- add your receiver's computer id here

rednet.send(receiver_id, "gps")
local r_id, r_pos = rednet.receive()

local r_x, r_y, r_z = r_pos[1], r_pos[2], r_pos[3]
local receiver = vector.new(r_x, r_y, r_z)

local x, y, z = gps.locate()
local client = vector.new(x, y, z)

function update_pos()
    x, y, z = gps.locate()
    client = vector.new(x, y, z)
end

while true do
    local displacement = receiver - client
    if ((displacement.x > 0) and (displacement.x < 2)) and ((displacement.y < 2) and (displacement.y > 0)) and ((displacement.z > -1) and (displacement.z < 1)) then
        rednet.send(receiver_id, "open")
    end
    
    if((displacement.x < 0) and (displacement.x > -2)) and ((displacement.y < 2) and (displacement.y > 0)) and ((displacement.z > -1) and (displacement.z < 1)) then
        rednet.send(receiver_id, "open")
    end
    update_pos()
end
\ No newline at end of file

A automatic_doors/receiver.lua => automatic_doors/receiver.lua +21 -0
@@ 0,0 1,21 @@
rednet.open("right")

local client_id = -- add your client's computer id here

while true do
    local id, message = rednet.receive()

    if id == client_id and message == "gps" then
        local x, y, z = gps.locate()
        local pos = {x, y, z}
        rednet.send(client_id, pos)
    end

    if id == client_id and message == "open" then
        rs.setOutput("bottom", true)
        rs.setOutput("left", true)
        sleep(0.1)
        rs.setOutput("bottom", false)
        rs.setOutput("left", false)
    end
end
\ No newline at end of file