Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

The Ultimate Random php Question

Comments in 'Plugin Development' started by Samueljh1, Apr 26, 2015.

  1. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    OK, I Really want to know what
    PHP:
    >>
    means! I've seen it a few times, and this was my reaction: o_O

    Lol :p

    I tried to look it up but i just found random craaaaap :eek:

    I cri.
    LDX likes this.
  2. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That means shift the binary representation right. Each time you shift the binary right you divide by two.
    $a >> $b
    That would be $a divided by 2 $b times. So $a/2^$b
    EvolSoft and LDX like this.
  3. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    OK thanks :D if you look at my NPC spawning thread, why is it needed for getting the chunk?? :)
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Because you are switching the block coordinate to the chunk coordinate. A chunk is 16*256*16. 16 is 2^4, so we want to shift over by four places in the binary representation. So we have $chunkX = $x >> 4, and $chunkZ = $z >> 4
    LDX likes this.
  5. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Mind = nuked
    iJoshuaHD likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Because chunks are 16*16 groups of X/Z-coordinates. Therefore, we call 0 to 15 index #0, 16 to 31 index #1, -16 to -1 index #-1, vice versa.
    In order to convert the coordinates (0-15) to the index (0), we divide the coordinates by 16 and get the floor of the quotient (floor of x = the greatest integer smaller than x). However, using division is actually a very slow process. We can look at bit shfiting instead.

    For simplicity, suppose we have a 16-bit system. (That's impossible for PocketMine because PHP won't compile on 16-bit systems)
    As you may know, in computers, numbers are saved in binary form. 0 is presented as `0000000000000000`, and 1 is presented as `00000000000000001`. 16 is presented as `0000000000010000`, and -1 is presented as `1111111111111111`. If the bits are shifted to the right by 4, it is divided by four (16 becomes ....01 and 0 becomes ....00 and -1 becomes .....111). So it is faster for computers.
    LDX likes this.
  7. Samueljh1
    Offline

    Samueljh1 Active Member Plugin Developer

    Joined:
    Jan 9, 2015
    Posts:
    316
    Plugins:
    5
    Minecraft User:
    Samueljh1_
    Mind = atomically nuked o_O
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why are you banned?
  9. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    701
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    Spam
    Code:
    @Intyre * 200....
    x)
    Samueljh1 and Legoboy0215 like this.

Share This Page

Advertisement