Basically I attempt to transfer a stack of zero items from the chest into an inventory in every direction. If the turtle is the only block around with an inventory, then when the transfer completes without throwing an error you know you're facing the right direction.
local function enderGetWorldDirection()
--This is a string compare, hence the weird layout
if not (peripheral.getType("front") == "ender_chest") then error("ERROR: Enderchest could not be found") end
local failed
local errReturn
local chest = peripheral.wrap("front")
local retVal = nil
-- directions are reversed from standard values because your facing an opposite direction to the chests direction toward you
local directionTable = {
[1] = "WEST",
[2] = "EAST",
[3] = "SOUTH",
[4] = "NORTH"
}
for i = 1, 4, 1 do
failed, errReturn = pcall(chest.pushItem, i, 0)
if (err == 0) then
assert(retVal)
if retVal == nil then
retVal = i
end
end
end
assert(not returnVal)
return directionTable[retVal]
end
It's really sketchy but it does work.
Edited by Quadrapod, 16 December 2015 - 12:10 AM.











