Solved Changing stained clay Color

Discussion in 'Plugin Development' started by Sneling, Nov 19, 2014.

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

    Sneling

    Hello,

    I was trying to change a block to stained clay, with a specific color, but I can't get how to do it, even at looking at the docs.

    Code:java
    1. if(block.getTypeId() == plugin.getConfig().getInt("floor_block")){
    2. ItemStack stack = new ItemStack(Material.STAINED_CLAY, 1, (short) 5);
    3. MaterialData newBlock = stack.getData();
    4. block.setTypeIdAndData(Material.STAINED_CLAY, arg1, true);
    5. }


    I can't find a way to get the stack data in byte, for "arg1".

    Please help,
    Sneling
     
  2. Offline

    Skionz

    Sneling What? Do you mean turn a String to a byte? Byte.parseByte(String)?
     
  3. Offline

    Sneling

    Skionz What I want is to get a way to put a certain color on a stained clay block, no matter what the way to it is. And I try your thing, it returns an error. I think byte is not the way for getting to it.
     
  4. Offline

    Skionz

    It will throw an error if the String cannot be turned into a byte.
     
  5. Offline

    Sneling

    Skionz Isn't there an another way for coloring a stained clay?
     
  6. Offline

    Dudemister1999

    Sneling

    Code:java
    1.  
    2. //For ItemStacks
    3. ItemStack item = new ItemStack(Material.STAINED_CLAY, 1, (byte)colour);
    4.  
    5. //If it's an existing stack
    6. item.setData((byte)colour);
    7.  


    Code:java
    1.  
    2. //If you know the block is stained clay
    3. Block block = world.getBlockAt(x, y, z);
    4.  
    5. //Otherwise
    6. Block block = world.getBlockAt(x, y, z).setType(Material.STAINED_CLAY);
    7.  
    8. //Set the data (Where the colour value is stored in clay
    9. block.setData((byte)colour);
    10. [syntax]
    11.  
    12. Note this might not be correct, because I don't have an IDE available at the moment.[/syntax]
     
  7. Offline

    Sneling

    Dudemister1999 Yeah, thanks. I have finally achieved to figure it out, and you're code is exactly what I had :)
     
Thread Status:
Not open for further replies.

Share This Page