ComputerCraft
ComputerCraft copied to clipboard
Add turtle.getTurn()
With this function you can get the Direction of a Turtle. The return value is a number, because it can be used in Loops. Here are the return value: 1 4 2 3
Note: This is not compatible to #462. If it get merged, I will change case 42 to case 44.
It might be worth looking at the discussion in #383. I'm won't re-iterate what was said there, but it does highlight some conceptual problems with such a function.
What essentially was said in that PR was turtles having the ability to get their direction is giving them "magic" knowledge. And I have to agree with this, this doesn't seem like something that belongs in a turtle, as they don't have any sort of "compass" built in.
Think of it this way: a player get's teleported randomly in a radius 10000 blocks away from his base, and has to find his way back. Assuming the player is unfamiliar with the land around him, how is he supposed to know which way to start walking? Players aren't given a direction unless they open the debug screen, which is comparable to a GPS. And even then, the player has to do some small movements to figure out which way is +X, and +Z (the rest from there can be assumed).
One of the things brought up in #383 was turtles should be able to do what players can do, I.E. read a compass. And I absolutely agree with this. If a player can get their direction just by looking at a compass, then so should a turtle.
So what I would recommend is turning a compass into a peripheral, and THEN if it is equipped, provide this as a method (and maybe a radiusFromSpawn
method too? ;D).
EDIT: radiusFromSpawn
would be much, maybe just directionToSpawn
, which just gives the general direction towards spawn.
I don't support this, getting a turtle orientation pretty much falls in the same category as getting a turtle coordinate, which you can only get with GPS. You can get turtle orientation using two GPS calls and some maths.
Without GPS and since ComputerCraft 1.76 you can get Direction of a Turtle, by placing a block with facing block.state and then inspect it :
pastebin get KE8cUP8x compas
https://pastebin.com/KE8cUP8x
ex:
Put a chest in the first slot of Turtle inventory, then run this command
compas 1
Two parts:
-
Turtles could have knowledge of world direction because blocks in Minecraft all have world direction knowledge. The cracks of breaking blocks and the textures of the tops of blocks can be used to find cardinal directions.
-
A
turtle.getTurn()
function ought to use the same system as math for angle measure. That means either 1, 2, 3, and 4 (for the four cardinal directions) or 0, 90, 180, and 270 (for angle measures) would be returned, but most to follow conventions, rotations in math are done counterclockwise. That means the output should be:
..1.. 2..4 ..3..
Can one of the admins verify this patch?