Solved Block Data

Discussion in 'Plugin Development' started by ERROR372, Oct 11, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ERROR372

    Alright, maybe I'm just missing something obvious, and I didn't see it in the update stuff. But I have a few plugins that do these things:

    - Gets & Sets the type of a block (such as a specific sapling or specific wool color)
    - Sets a crops growth stage


    The API and my code says that anything related to ID and Data are Deprecated with the reason "Magic Value" (completely unhelpful, by the way). So how do I go about setting the block type if it has data?
     
  2. Offline

    Syd

    For the Item/Block ID stuff you should use the Material Enum instead of numbers.
    However, for data values you have no other way in setting them than using a plain number.

    Btw. magic value means a value, which doesn't tell you what it actually means (e.g. you couldn't know that 1 means stone, without looking up a table).
    And as ItemIDs are removed with update 1.7, it's time to switch to the Material enum. ;)
     
  3. Offline

    ERROR372

    Syd

    So what do I do for Saplings? All Material has is "Sapling". I need it to be a specific sapling, because I'm doing a bonemeal plugin that insta-grows stuff like old bonemeal. So I have to remove the sapling, and attempt to grow the tree. If the tree growth fails, put the sapling back. Just using Material.SAPLING can't possibly do this for all tree types.

    And then for tall grass, I noticed that it does the desert dead shrub. I need it to be tall grass, because it'll be in a plains biome.



    I appreciate the help, just this 1.6.4 update has really got me confused x_x

    T3h Cr33p3r


    Yes, but with 1.6.4, you can't assign a data value to blocks... All of the setData(), getData(), setTypeId(), and getTypeId() are Deprecated and therefore unuseable.

    T3h Cr33p3r

    You do realize that deprecated methods usually lose their support and entire code portions, right? Why do you think plugins that don't get updated don't work anymore? Because the methods they used got deprecated and removed...

    T3h Cr33p3r

    Because say, with crops... They have multiple stages of growth. How can I know when to stop giving them bonemeal when I can't know what stage of growth they are at (done by doing getData())? With trees... when I remove the sapling so the tree will generate there, how can I replace the specific sapling if the growTree() or whatever the method is fails?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. ERROR372 Have you tried setting their durability to the value you want? Thats what I use and it works perfect.

    T3h Cr33p3r Not really. The item ids will get removed in 1.7 , mojang is working on a new way item ids work to add support for mods. Itemids will now look like this: minecraft:<item name>, so mods can do: modname:<item name>. Also explaining deprecation as something that is added just to say "you can still use it but its not the best way", no, it mostly has a reason why they deprecate stuff. And by the way, there's no need to "laughing and facepalming" it's very disrespectfull and annoying.
     
  5. Offline

    Syd

    ERROR372
    Just use getData() and setData(), even if they may be removed soon.
    There is currently no other way for this.
    Just keep an eye on future Bukkit updates, to see if there are any changes related to this methods.

    T3h Cr33p3r
    ItemIDs, like we know them, will cease to exist in 1.7. They may still exist internally, but they aren't reliable for users anymore and may change their assignments in some cases (e.g. between worlds).
     
  6. False. This code is actually working :
    Code:java
    1. Block block;
    2. if(block.getState().getData() instanceof Wool) {
    3. BlockState bs = block.getState();
    4. Wool wool = (Wool) bs.getData();
    5. wool.setColor(DyeColor.MAGENTA);
    6. bs.update();
    7. }

    It is changing the color of any wool into Magenta.

    However, I actually didn't find out how to serialize this block.
     
  7. Offline

    ERROR372

    CaptainBern

    I have not tried setting the durability, I will see if that works (which you said it does). If it does, yay! I'm sure durability isn't going away any time soon =P

    Syd

    Okay. Thanks for letting me know. Being a Computer Science major, I know to avoid deprecation, since support for the code will eventually be lost. Didn't know if I was just missing something obvious in the API and such. I appreciate your help! Hope they get something set up in the Material class soon.

    Paulo_Desticraft

    Thing with that code are the two instances of getData(). Those have been deprecated, so eventually we won't be able to use them.




    Thanks for your help everyone. Good to see I can just leave my code alone for the most part right now!
     
  8. Offline

    Syd

  9. Syd Of course, the methods I showed aren't actually deprecated, because they don't return any id or byte, juste a MaterialData or a Class<? extends MaterialData> (like the Wool class). I suggest you to use my method to change the data of a block.

    If someone found how to serialize a block, I'll appriate that he gives me the method.

    Thanks,

    Paulo.
     
  10. Offline

    Ultimate_n00b

    I use durability to set this.
     
  11. T3h Cr33p3r Just a way to do that by bukkit. The old way was too serialize the id and the data. But now, I don't see any way to store the data in a file.
     
Thread Status:
Not open for further replies.

Share This Page