Does anyone know any way of getting a player's looking vector given their username? I don't mind if it involves using invisible armor stands or something weird, or using crazy amounts of @e testfor commands on the x-rot and y-rot, but I can't for the life of me figure out how to do it.
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Getting the block the player is looking at
Started by moomoomoo3O9, 30 May 2016 - 12:52 PMPosted 30 May 2016 - 02:52 PM
I actually may have asked this question before, but now that I've started using 1.8.9, I know this should be possible with some command computer trickery.
Does anyone know any way of getting a player's looking vector given their username? I don't mind if it involves using invisible armor stands or something weird, or using crazy amounts of @e testfor commands on the x-rot and y-rot, but I can't for the life of me figure out how to do it.
Does anyone know any way of getting a player's looking vector given their username? I don't mind if it involves using invisible armor stands or something weird, or using crazy amounts of @e testfor commands on the x-rot and y-rot, but I can't for the life of me figure out how to do it.
Posted 30 May 2016 - 02:56 PM
SquidDev used OpenPeripherals. I do not think it's possible with a command computer, although I could be mistaken.
Posted 30 May 2016 - 04:07 PM
It is possible to do, but you would need to do a lot of work to check for it. I made something that checks for the block you are looking at on a 2D plane (=> Only on a static Y axis). It would be a lot harder to check for blocks in a 3D area. You would need to scan the area around a player, then do some trigonometry to get the blocks the player might be looking at, and then check wich of those blocks is the closest to the player.
You can get the player's position using armorStands, you would need to teleport a armorStand to the player, then get the armorStands' NBT, then parse the armorStand's NBT to get the position and rotation of the player/armorStand.
I made an API for that but its not 100% done yet and not released, and pretty complicated to install, i could talk you though via PM.
You can get the player's position using armorStands, you would need to teleport a armorStand to the player, then get the armorStands' NBT, then parse the armorStand's NBT to get the position and rotation of the player/armorStand.
I made an API for that but its not 100% done yet and not released, and pretty complicated to install, i could talk you though via PM.
Edited on 30 May 2016 - 02:08 PM
Posted 30 May 2016 - 04:14 PM
get the armorStands' NBT
Can you elaborate on this a bit? I'd love to know how to get NBT data from an entity. It'd help me with a project I'm working on.
Posted 30 May 2016 - 04:45 PM
get the armorStands' NBT
Can you elaborate on this a bit? I'd love to know how to get NBT data from an entity. It'd help me with a project I'm working on.
I'm pretty sure you can use /entitydata @e[selector] {} (in the same way you can use /tp @p ~ ~ ~ to get position). This will return a string which contains the NBT which can then be parsed. OpenPeripherals' sensor also allows getting look vector and look position which might be easier though.
Posted 30 May 2016 - 05:57 PM
{…}
I'm pretty sure you can use /entitydata @e[selector] {} (in the same way you can use /tp @p ~ ~ ~ to get position). This will return a string which contains the NBT which can then be parsed. OpenPeripherals' sensor also allows getting look vector and look position which might be easier though.
Yes, thats the way. I never worked with OP's Sensor, but in any case it should be easier to use. Teleporting the ArmorStand and getting its position takes 1/10th of a second for Command-Processing, plus the calculations for the NBT Parsing.
You should remember that the ArmorStand blocks all mouse interactions of the player, wich is usually a bad thing. However, you can use this for detecting the item the player (right) clicks with. If the Inventory-Slots of an ArmorStand are enabled and you right click with an item in your hand on that ArmorStand, it will be put in the ArmorStand's hand. This can be detected, too, with the entity data-command.
If you want to learn more about all the informations you can get out of the NBT, you should check out the wiki. (here)
Edited on 30 May 2016 - 03:58 PM
Posted 30 May 2016 - 06:06 PM
I solved this by doingYou should remember that the ArmorStand blocks all mouse interactions of the player, which is usually a bad thing.
commands.tp( "@e[type=ArmorStand,name=pData] @p" )
commands.tp( "@e[type=ArmorStand,name=pData] ~ ~2 ~" )
Which teleports the armor stand to the player, then moves it up 2 blocks (the difference in coordinates is accounted for in the program). However, I'm having slight difficulties with the @e parameters, it wants to move all the armor stands, not just the one I named pData.Edited on 30 May 2016 - 04:07 PM
Posted 30 May 2016 - 06:37 PM
I solved this by doingYou should remember that the ArmorStand blocks all mouse interactions of the player, which is usually a bad thing.Which teleports the armor stand to the player, then moves it up 2 blocks (the difference in coordinates is accounted for in the program). However, I'm having slight difficulties with the @e parameters, it wants to move all the armor stands, not just the one I named pData.commands.tp( "@e[type=ArmorStand,name=pData] @p" ) commands.tp( "@e[type=ArmorStand,name=pData] ~ ~2 ~" )
Really good idea to teleport the ArmorStand up a little. You might even get this one in one command by using
/execute @ ~ ~2 ~ /tp @ ~ ~ ~
You can limit the amount of ArmorStands that get teleported to someone by setting a maximum for the amount of entities. The parameter is c (for Count) and the value is the maximum of entities to be effected by the command.
@e[type=ArmorStand,name=pData,c=X]
The problem might be something else, though. I would suspect that all of your ArmorStands are called pData. Might be something else though.Posted 31 May 2016 - 02:29 AM
Since I just got this working and implemented (Thanks a ton guys, especially Wergat! You'll be credited in my program once I release anything with your code in it.), I thought I'd provide the code to convert pitch/yaw minecraft gives you to the x,y,z components of a vec3 minecraft would use. In case anyone else stumbles upon this thread and wants to do that, I thought I'd save you the work. It's based on this stack overflow thread, though it's a tad different because minecraft is a bit silly sometimes.
local xzLen=-math.cos(math.rad(yaw)) --Cuts down on a cos call
local x,y,z=xzLen*math.sin(-math.rad(pitch+180)),math.sin(math.rad(-yaw)),xzLen*math.cos(math.rad(pitch+180))
Edited on 31 May 2016 - 01:20 AM