Why is there no block.setState()?

Discussion in 'Plugin Development' started by skiithaw, Feb 21, 2018.

Thread Status:
Not open for further replies.
  1. Wherever I look on google, there's people left and right holding guns to peoples heads for suggesting to use block.getData() because of it being depreciated.

    The alternative is to use block.getState(), but there's a problem. Unlike getData, it doesn't have an equivalent setter counterpart. Why is that? (I can't do block.setState(BlockState), and I'd really like to).

    Just like in worldEdit, I'd like to be able to make a selection, copy all data within it and store it for later pasting. However this is proving quite a task with blocks that have special data (especially doors omg).

    Right now, I am admittedly using the disgusting deprecated function and it works to a certain extent. It copies signs being on walls, wool colour, stair orientation and material, and all that good stuff. But it bugs doors and pops torches.

    On a related topic, is there an efficient/tidy way to store block data that isn't in its state (like a chest of items, a signs text, a torch orientation)?

    My solution would be to have a hashmap for each possible type, so:
    Signtext <int to string>
    ChestContents <int to Inventory>
    etc

    And then as I loop through the 3 dimensional for loop, the overall position is used as the key for each entry.
    So if there's a chest at x:3 y:0 z:2, the hashmap gets the inventory added through the key "6". etc
     
  2. Offline

    Zombie_Striker

    @skiithaw
    The reason the method is deprecated is because all the numbers are just 'magic values', because blocks can accept 'invalid' data values. The reason we recommend using it is because there really isn't a better alternative.
    1. No, the only way to get the contents of the inventory is to use the state object.
    2. Also no, as the lines of the sign are stored only in the state
    3. Yes. Torch orientation is related to the torches data value, so you can use Block#getData to get the number representing its direction.
     
Thread Status:
Not open for further replies.

Share This Page