Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Mob Farm Touch Screen Control w/Remote RS Timer PC
- --v1.2 by SemlerPDX Sept2024
- -- pastebin get GyWbhYEK startup
- --Peripheral Sides
- redstoneSide = "bottom"
- monitorSide = "front"
- detectorSide = "top"
- modemSide = "back"
- --rednet protocol and computer IDs
- protocolCMD = "MobFarmCMD"
- controlPC = 22 --id of (this) farm control PC
- remotePC = 20 --id of remote redstone timer PC
- --Remote Command Keywords
- msgOpenComms = "opencomms"
- msgConfirmed = "copycopy"
- msgDenied = "samestate"
- commandOn = "on"
- commandOff = "off"
- local messageOn = {" "," ","T","U","R","N"," ","O","N"," "," "," "}
- local messageOff = {" "," ","T","U","R","N"," ","O","F","F"," "," "}
- local messageString = messageOn
- local commandString = commandOff
- local isOnline = 1 -- initial toggle will invert this for "off" state before main loop
- --Init
- term.clear()
- term.setCursorPos(1,1)
- monitor = peripheral.wrap(monitorSide)
- detector = peripheral.wrap(detectorSide)
- modem = peripheral.wrap(modemSide)
- rednet.open(modemSide)
- --Rednet Receive Requested Message
- local function NetReceive(msg)
- id,message = rednet.receive(protocolCMD,timeout)
- if message ~= nil then
- if msg == message then
- return true
- else
- return false
- end
- end
- end
- --Rednet Send with Receipt Confirmation
- local function NetSend(toID,msg,rcv,ccode)
- rednet.send(toID,msg,protocolCMD)
- if rcv then
- returnReceipt = NetReceive(ccode)
- if returnReceipt then
- return true
- else
- return false
- end
- end
- end
- --Toggle Remote RS Timer via Rednet with Return Confirmation
- local function ToggleTimer(toID,msg)
- while true do
- commsOpen = NetSend(toID,msgOpenComms,true,msgConfirmed)
- if commsOpen then
- commsOut = NetSend(toID,msg,true,msgConfirmed)
- return commsOut
- end
- sleep(1)
- end
- end
- --Toggle Monitor Display and Mob Farm Online State
- local function ToggleState(stateNew)
- if stateNew == 1 then
- stateNew = 0
- messageString = messageOn
- commandString = commandOff
- monitor.setBackgroundColor(colors.red)
- else
- stateNew = 1
- messageString = messageOff
- commandString = commandOn
- monitor.setBackgroundColor(colors.green)
- end
- rs.setAnalogOutput(redstoneSide,stateNew)
- monitor.clear()
- for y=1,12 do
- monitor.setCursorPos(4,y)
- monitor.write(messageString[y])
- end
- ToggleTimer(remotePC,commandString)
- return stateNew
- end
- local function DetectTouch()
- event,side,xPos,yPos = os.pullEvent("monitor_touch")
- end
- local function DetectPlayers()
- while true do
- sleep(1)
- playerPresent = detector.isPlayersInRange(8)
- if not playerPresent then
- return false
- end
- end
- end
- --MAIN
- while true do
- isOnline = ToggleState(isOnline)
- if isOnline == 1 then
- controlFunction = parallel.waitForAny(DetectTouch,DetectPlayers)
- if controlFunction == 2 then
- term.write("No player is present - shutting down mob farm...")
- end
- else
- DetectTouch()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement