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

How to change block direction

Comments in 'Plugin Development' started by Creeperface, Aug 5, 2016.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    HI i want to make //rotate command in my world edit but idk how to change face of all rotatable blocks :/

    blocks like chest, furnace, pupking are easy but what about rails, stairs, doors, liquid or trapdoors? i have no idea
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
  3. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    These blocks generally may not have common rules about their damage value. Implement them one by one. Minecraft Wiki's article about Data values has a centralized source of information about damage values.
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    thx :) i already checked whese files. I know how to work with numbers but i dont know how to work with bits :D

    stairs:
    0x1 and 0x2 - A two-bit field containing a value from 0 to 3 specifying the direction of the stairs' full-block side
    • 0: East
    • 1: West
    • 2: South
    • 3: North
    0x4 - Set if stairs are upside-down

    can you give me example how to check if are bits set? :D and how to get direction from 0x1 or 0x2? :D
  6. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Use bitwise operators.
    http://stackoverflow.com/documentation/php/1687/operators/18019/bitwise-operators

    P.S. Look at who wrote that example! sodoc.PNG
  7. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    can you explain me why is it 0x08 if bit is 0x4 ?

    PHP:
    (block->getDamage() & 0x08) > 0
    Last edited: Aug 5, 2016
  8. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Where?
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    In trapdoor. There is 0x4 if its open i Think
  10. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    I don't know. @PEMapModder added that. I think I should ask him.

    According to @PEMapModder, https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/block/Trapdoor.php#L31 is the result of his experiment. This might be no longer correct though. As of MCPE 0.15.3, trapdoor rotation has some problems when opened, so since the MCPE developers are making such mistakes as well, I think we should not blame him.
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    But i dont understand how to check if a bit is set :/ how long is Black's meta? (e.g. 10100011)
  12. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    A block's meta/damage value is a nibble, i.e. half a byte, i.e. 4 bits long.
    Therefore there are four bits to check: $damage&1, $damage&2, $damage&4 and $damage&8.
  13. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    can you give me specific example? Idk how many bits have every block :/
  14. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Every block has a damage value. The damage value consists of 4 bits, namely damage&1, damage&2, damage&4 and damage&8. These four bits are used differently in different blocks. For example, in wool, all four bits (with 16 permutations) are used to identify the 16 types of colors. In leaves, the damage&8 bit is used to identify whether the leaf is placed by player (no-decay bit), and the other 3 bits (with 8 permutations) are used to identify the leaf type. In tripwire hooks, the lowest two bits are used for 4-side direction indication, the damage&4 bit for whether the tripwire is double-hooked, and the damage&8 for activation; you can use damage&3 to get the lowest two bits together, and check them against the four directions. In buttons, however, the lowest 3 bits are used for 6-side direction indication, and the highest bit for activation; use damage&7 to get the lowest three bits together, but note that these direction codes are different from that of tripwire hooks.
    Therefore, to rotate, there is no general rule, and you must implement it per block type.
    Creeperface likes this.

Share This Page

Advertisement