Skip to content

Instantly share code, notes, and snippets.

@ExtraPerry
Last active April 28, 2024 00:34
Show Gist options
  • Save ExtraPerry/ffc88d883d141823e12cbf1ed8731dd2 to your computer and use it in GitHub Desktop.
Save ExtraPerry/ffc88d883d141823e12cbf1ed8731dd2 to your computer and use it in GitHub Desktop.
Computer Craft dialing program for the SG Journey Minecraft Mod (This one primarily used for the ATM-9 modpack).
ADDRESSES = {
{"Abydos", {26, 6, 14, 31, 11, 29, 0}},
{"Chulak", {8, 1, 22, 14, 36, 19, 0}},
{"Cavum Tenebrae", {18, 7, 3, 36, 25, 15, 0}},
{"Lantea", {18, 20, 1, 15, 14, 7, 19, 0}},
{"Overworld", {27, 25, 4, 35, 10, 28, 0}},
{"Nether", {27, 23, 4, 34, 12, 28, 0}},
{"End", {13, 24, 2, 19, 3, 30, 0}},
{"Aether", {8, 7, 2, 17, 6, 21, 0}},
{"Twilight Forest", {36, 33, 16, 25, 7, 14, 0}},
{"Lost City", {13, 4, 27, 8, 19, 3, 0}},
{"Glacio", {26, 20, 4, 36, 9, 27, 0}},
{"ATM Mining", {25, 33, 20, 7, 37, 17, 0}},
{"ATM Other", {12, 23, 36, 13, 21, 16, 0}},
{"ATM Beyond", {27, 5, 2, 23, 17, 38, 0}},
{"Alfeim", {4, 9, 13, 11, 20, 7, 0}},
{"Everbright", {24, 23, 37, 26, 35, 12, 0}},
{"Everdawn", {5, 7, 10, 16, 26, 21, 0}},
{"Otherside", {4, 13, 27, 12, 24, 17, 0}},
{"Undergarden", {2, 4, 6, 31, 21, 35, 0}},
{"Voidscape", {26, 5, 4, 11, 2, 37, 0}}
};
INTERFACE_TYPES = {
"basic_Interface",
"crystal_Interface",
"advanced_crystal_Interface"
};
STARGATE_TYPES = {
"sgjourney:classic_stargate",
"sgjourney:milky_way_stargate",
"sgjourney:pegasus_stargate",
"sgjourney:universe_stargate",
"sgjourney:tollan_stargate"
};
function ClearScreen()
term.clear();
term.setCursorPos(1, 1);
end
ClearScreen();
--Function argument calls--
local arg = {...};
IsFastDial = false;
for _,v in pairs(arg) do
if v == "--fast" then
IsFastDial = true;
elseif v then
error("Bad flag [" .. v .. "] failed to initialise", 0);
end
end
--Find the proper Interface--
InterfaceType = INTERFACE_TYPES[1];
Interface = peripheral.find(InterfaceType);
if Interface == nil then
print("\"" .. INTERFACE_TYPES[1] .. "\" was not found attempting to find another");
InterfaceType = INTERFACE_TYPES[2];
Interface = peripheral.find(InterfaceType);
elseif Interface == nil then
print("\"" .. INTERFACE_TYPES[2] .. "\" was not found attempting to find another");
InterfaceType = INTERFACE_TYPES[3];
Interface = peripheral.find(InterfaceType);
elseif Interface == nil then
print("\"" .. INTERFACE_TYPES[3] .. "\" was not found attempting to find another");
error("No Interfaces were found", 0);
end
print("\"" .. InterfaceType .. "\" was found");
StargateType = Interface.getStargateType();
print("Interface Type : " .. InterfaceType);
print("Stargate Type : " .. StargateType);
print("\n");
--Check if selected stargate and flags can be used by current Interface--
if (IsFastDial == true or StargateType ~= STARGATE_TYPES[2]) and InterfaceType == INTERFACE_TYPES[1] then
error("\"" .. INTERFACE_TYPES[1] .. "\" can only be used with \"" .. STARGATE_TYPES[2] "\" in default manual dial mode", 0);
end
--Close Stargate and/or Reset Cheverons--
function Reset()
Interface.disconnectStargate();
if Interface.isStargateConnected() then
os.sleep(2.75);
end
end
--Call an address and try to make a connection--
function Dial(address)
Reset();
local addressLength = #address;
if StargateType ~= STARGATE_TYPES[4] then
if addressLength == 8 then
Interface.setChevronConfiguration({0, 1, 2, 3, 4, 6, 7, 8, 5});
elseif addressLength == 9 then
Interface.setChevronConfiguration({0, 1, 2, 3, 4, 5, 6, 7, 8});
end
end
local start = Interface.getChevronsEngaged() + 1;
if StargateType == STARGATE_TYPES[2] and IsFastDial == false then
for chevron = start,addressLength,1
do
local symbol = address[chevron];
if chevron % 2 == 0 then
Interface.rotateClockwise(symbol);
else
Interface.rotateAntiClockwise(symbol);
end
while(not Interface.isCurrentSymbol(symbol))
do
os.sleep(0);
end
Interface.endRotation();
os.sleep(1);
Interface.openChevron();
os.sleep(0.5)
if chevron < addressLength then
Interface.encodeChevron();
end
os.sleep(0.5);
Interface.closeChevron();
sleep(1);
end
else
for chevron = start,addressLength,1
do
local symbol = address[chevron];
Interface.engageSymbol(symbol);
os.sleep(0.25);
end
end
end
--Player Input--
print("Avaiting input:");
for k,v in ipairs(ADDRESSES) do
print(k .. " : " .. v[1]);
end
input = tonumber(io.read());
os.sleep(0);
local addressLength = #ADDRESSES;
if input < 1 or input > addressLength then
error("Entered value is incorrect", 0);
end
if #ADDRESSES[input][2] > 7 and InterfaceType == INTERFACE_TYPES[1] then
error("Cannot dial 8 or 9 chevron address with \"" .. INTERFACE_TYPES[1] .. "\" please upgrade to \"" .. INTERFACE_TYPES[2] .. "\" or \"" .. INTERFACE_TYPES[3] .. "\"");
end
Dial(ADDRESSES[input][2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment