1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Store custom block data

Discussion in 'Development' started by Legoboy0215, Jul 11, 2017.

  1. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    How could I store custom block data without using any external storage methods? My anti-lag plugin clears the block cache every 5 minutes, and the block object gets destructed.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I remember doing something like that when I was working on custom TNT.
    You can try using Level::setBlockExtraDataAt()
     
    Legoboy0215 likes this.
  3. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    However, it seems that getBlockExtraDataAt returns this:
    ($data << 8) | $blockId. How would I reverse that to get the value I stored? Is it even possible to reverse bitwise operations?
     
  4. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    Nvm, I opted to use Tiles with NBT instead.
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah, except that tile overload lag = 1/2 entity overload lag (totally accurate).
    You can get the value using Level::getBlockExtraDataAt()
     
  6. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    Yeah, but it is ($originalData << 8) | $blockId. So how am I gonna reverse a bitwise or and a bitshift?
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why?
     
  8. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    IDK... It just doesn't feel right. I always use NBT or any available option if I can.
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Blocks don't have NBT data; you have to use a tile if you want to use NBT.
    You also need to work around troubles like accidentally sending the tile to the client.
     
  10. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    I know. That's why I am trying to figure out a way to store data without actually using tiles (NBT) or other external storage methods.
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Yeah, a disadvantage of using tiles is that you may override/be overridden by other tiles, e.g. you can't store data for signs and chests.
    Therefore I still believe that storing externally is a good idea. PocketMine has a block metadata API, but I doubt if it even gets saved at all.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.