Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Interpret rednet signals as movement commands
- local id, message;
- function selectAndSendSlot()
- turtle.select(turtle.getSelectedSlot()%16+1)
- local block = turtle.getItemDetail();
- if block then return block.name; else return "Empty slot"; end
- end
- function deselectAndSendSlot()
- turtle.select(turtle.getSelectedSlot()%16+1)
- local block = turtle.getItemDetail();
- if block then return block.name; else return "Empty slot"; end
- end
- function observe()
- local isBlock, blockData = turtle.inspect();
- local str = "";
- if not isBlock then str = str.."Not a block\n"; end
- if blockData.name then str = str..blockData.name.."\n"; end
- if blockData.state then str = str..textutils.serializeJSON(blockData.state, true).."\n"; end
- return str;
- end
- function observeUp()
- local isBlock, blockData = turtle.inspectUp();
- local str = "";
- if not isBlock then str = str.."Not a block\n"; end
- if blockData.name then str = str..blockData.name.."\n"; end
- if blockData.state then str = str..textutils.serializeJSON(blockData.state, true).."\n"; end
- return str;
- end
- function observeDown()
- local isBlock, blockData = turtle.inspectDown();
- local str = "";
- if not isBlock then str = str.."Not a block\n"; end
- if blockData.name then str = str..blockData.name.."\n"; end
- if blockData.state then str = str..textutils.serializeJSON(blockData.state, true).."\n"; end
- return str;
- end
- local moves = {
- [32] = turtle.up,
- [340] = turtle.down,
- [87] = turtle.forward,
- [83] = turtle.back,
- [65] = turtle.turnLeft,
- [68] = turtle.turnRight,
- [82] = turtle.digUp,
- [70] = turtle.dig,
- [67] = turtle.digDown,
- [84] = turtle.placeUp,
- [71] = turtle.place,
- [86] = turtle.placeDown,
- [90] = turtle.refuel,
- [49] = selectAndSendSlot,
- [50] = deselectAndSendSlot,
- [89] = observeUp,
- [72] = observe,
- [66] = observeDown,
- [85] = turtle.suckUp,
- [74] = turtle.suck,
- [78] = turtle.suckDown,
- [73] = turtle.dropUp,
- [75] = turtle.drop,
- [77] = turtle.dropDown,
- [88] = turtle.equipRight,
- [79] = turtle.attackUp,
- [76] = turtle.attack,
- [188] = turtle.attackDown
- };
- peripheral.find("modem", rednet.open);
- while true do
- id, message = rednet.receive();
- if moves[tonumber(message)] then
- local msg = moves[tonumber(message)]();
- if tostring and tostring(msg) ~= "true" then rednet.send(id, msg); else rednet.send(id, ""); end
- else
- rednet.send(id, "Button not mapped");
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement