Question Need help: Working with block(& ItemStack) Data

Discussion in 'Plugin Help/Development/Requests' started by meowxiik, Jan 10, 2015.

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

    meowxiik

    There are few things, which I still can't figure out, and I would be pleased, if you can answer me them.

    1. Why is difference between Block.getData() and ItemStack.getData() (The first one doesn't retrieves the number in brackets(I mean this->"WOOL(2)"))
    2. How to convert ItemStack to Block and Block into ItemStack
    3. How is this thing in breackets actually called. (MetaData? I am not sure)
    4. CraftBlock{chunk=CraftChunk{x=-1z=0}, x=-2,y=63,z=15,type=QUARTZ_STAIRS, data=5}
    I guess, the type is actual Material of the ItemStack and data is the number in brackets, is it right?
    5. How to set Data for block (undeprecated way)
     
  2. Offline

    pie_flavor

    1. ItemStack.getData() returns the MaterialData, and MaterialData.getData() gets the number. Block.getData() just returns the data, as the equivalent of MaterialData for blocks is BlockState.
    2. Not sure how you would turn an itemstack into a Block, but you can use Block.getState().getData().toItemStack(amount) for the reverse.
    3. It's called the damage value.
    4. Right.
    5. Deprecated doesn't really matter here. Just ignore it. It's deprecated for "magic value" which means it's based on an arbitrary number that Minecraft can change. I expect in 1.9 they will migrate damage value to text the same as item ID. But, if you need to work with items that are more than a byte (like spawn eggs) then you can use getDurability() and setDurability() as those set the exact same value.
    P.S. (open)
    You:
    1
    2
    3
    Me:
    [list=1][*]
    [*]
    [*][/list]
     
  3. Offline

    meowxiik

    Thanks! It really helped me. :)
     
Thread Status:
Not open for further replies.

Share This Page