Jump to content




Block Selection Using Immibis's Adventure Map Interface


  • You cannot reply to this topic
5 replies to this topic

#1 moomoomoo3O9

  • Members
  • 82 posts
  • LocationPork roll land

Posted 20 January 2014 - 12:06 PM

I saw Immibis's Adventure Map Interface, and I loved it. I wrote a few Worldedit-esque programs, some that emulated //removenear (which could be changed to replacenear by adding a variable), some that were used like //set using the adventure map interface, one that made flat bedrock and emptied the chunk within X radius...etc. (So I do know a decent amount about coding in CC, even if I didn't make an account here)

I want to make a program functionally similar to WorldEdit's normal cuboid selector (because the poly or spheroid selector is far beyond my ability) but I need to know how to use the normalized direction vector from a player (ent.getLooking(x, y, z) returns it) to find out what block the player is looking at. From what I understand, what needs to be done is:

1) Extend out the vector linearly. (This is where I have a problem!)
2) Detect all blocks within that line. (This is trivial if I can get the co-ords)
3) If the line hits a block, end it (break or return)

So, does anyone with more knowledge than me about vectors know how that would be written?

(And if anyone wants to help me in programming this, I would love to see how someone who's a better coder than me could do it)

Edited by moomoomoo309, 20 January 2014 - 12:31 PM.


#2 moomoomoo3O9

  • Members
  • 82 posts
  • LocationPork roll land

Posted 25 January 2014 - 12:45 PM

I figured it out, so in case anyone wants to do something similar, I'll post the code here!
Code


#3 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 26 January 2014 - 11:52 AM

Just a note on this section of your code:

--this will prevent a too long without yielding error
iteration=iteration+1
if iteration==100000 then
  break
end

You could have replaced that entire block with:
sleep(0)

The sleep(0) will also prevent a too long without yielding, as any call to sleep yields, if even for just a split second.

Edited by surferpup, 26 January 2014 - 11:53 AM.


#4 moomoomoo3O9

  • Members
  • 82 posts
  • LocationPork roll land

Posted 27 January 2014 - 03:55 PM

View Postsurferpup, on 26 January 2014 - 11:52 AM, said:

Just a note on this section of your code:

--this will prevent a too long without yielding error
iteration=iteration+1
if iteration==100000 then
  break
end

You could have replaced that entire block with:
sleep(0)

The sleep(0) will also prevent a too long without yielding, as any call to sleep yields, if even for just a split second.
Actually, that code shouldn't occur at all if the code is working correctly, it's so your computer doesn't pointlessly calculate to find a block that doesn't exist. (I.E. The player is looking into the sky)

#5 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 27 January 2014 - 04:30 PM

View Postmoomoomoo309, on 27 January 2014 - 03:55 PM, said:

Actually, that code shouldn't occur at all if the code is working correctly, it's so your computer doesn't pointlessly calculate to find a block that doesn't exist. (I.E. The player is looking into the sky)

According to the comment in the code I was referring to, the intent of the coder was to figure out how to avoid going too long without yielding. The iteration loop can easily be replaced with a sleep(0) if you are concerned about going too long without yielding rather than what was used. There are, of course, far better ways of dealing with yielding issues, I was commenting on the one chosen.

Edited by surferpup, 27 January 2014 - 04:33 PM.


#6 moomoomoo3O9

  • Members
  • 82 posts
  • LocationPork roll land

Posted 27 January 2014 - 05:13 PM

View Postsurferpup, on 27 January 2014 - 04:30 PM, said:

View Postmoomoomoo309, on 27 January 2014 - 03:55 PM, said:

Actually, that code shouldn't occur at all if the code is working correctly, it's so your computer doesn't pointlessly calculate to find a block that doesn't exist. (I.E. The player is looking into the sky)

According to the comment in the code I was referring to, the intent of the coder was to figure out how to avoid going too long without yielding. The iteration loop can easily be replaced with a sleep(0) if you are concerned about going too long without yielding rather than what was used. There are, of course, far better ways of dealing with yielding issues, I was commenting on the one chosen.
Ah I see, sorry for being unclear.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users