get Energy

This commit is contained in:
2025-08-02 19:41:21 +02:00
parent b259cc5fc6
commit 72930c4452

View File

@ -1,7 +1,59 @@
local typeOfPeripheral = peripheral.getType("left")
local function getPeripheralType(direction)
local peripheralType = peripheral.getType(direction)
if not peripheralType then
print("No peripheral found in that direction.")
return nil
end
return peripheralType
end
print("Type of peripheral on the left: " .. typeOfPeripheral)
local function findPeripheral(typeOfPeripheral)
local peripheral = peripheral.find(typeOfPeripheral)
if not peripheral then
print("No peripheral found in that direction.")
return nil
end
return peripheral
end
local storageEnergy = typeOfPeripheral.getStoredEnergy() --- IGNORE ---
local function uraniniteReactorStorageEnergy(peripheral)
if peripheral.getStoredEnergy then
return peripheral.getStoredEnergy()
else
print("The peripheral does not support getting stored energy.")
return nil
end
end
print("Storage energy: " .. storageEnergy)
local function checkDirectionIsValid(direction)
if not direction or direction == "quit" or direction == "exit" then
print("No direction specified, exiting.")
return false
end
return true
end
print("Enter the direction of the peripheral (left, right, top, bottom, front, back):")
local direction = io.read()
if not checkDirectionIsValid(direction) then
return
end
local typeOfPeripheral = getPeripheralType(direction)
if not typeOfPeripheral then
print("No peripheral found in that direction.")
return
end
local peripheral = findPeripheral(typeOfPeripheral)
if not peripheral then
print("No peripheral found of type: " .. typeOfPeripheral)
return
end
if peripheral == "uraninite_reactor" then
local energy = uraniniteReactorStorageEnergy(peripheral)
print("Stored energy in uranium reactor: " .. energy)
else
print("Peripheral type is not a uranium reactor, cannot get stored energy.")
end