Solved Color a Glass Block

Discussion in 'Spigot Plugin Development' started by Dulcinea, May 13, 2016.

  1. Hello Guys, I tried and search for everything on this topic. I don't know anymore where to look.
    As simple as the title, I need to set the color on a Glass Block (or put a colored glass block).

    Let's say I put a Glass Block somewhere, given coordinates x, y, z and a world.

    Code (Text):
    Location loc = new Location(world, x, y, z);
    Block b = world.getBlockAt(loc);
    b.setType(Material.GLASS);
    A transparent block has been put there.
    Now it's the moment to give it a color:

    Code (Text):
    b.setData((byte) (c)); // Where c I tried from 0 to 20, doesn't work
    b.setData(DyeColor.RED.getData()); // Doesn't work
    Deprecated but should still work. Since I read the block can be casted to Wool, I tried this:

    Code (Text):
    if (b.getState().getData() instanceof Wool) { //If the block is wool:
     DyeColor color = ((Wool) b.getState().getData()).getColor();
     }
    but I can't find the Wool class.

    I tried using MaterialData but even that doesn't work, and many say those functions are yet poorly documented. What am I doing wrong? On the server it is easy, /give user item data... but I can't assign data properties inside my plugin.
    Please help!
     
  2. You can only colour stained glass - not regular glass
     
    • Useful Useful x 1
  3. The only way I could see this happening is if you make a resource pack and change the green to red.
     
  4. Code (Text):
    ItemStack item = new ItemStack(this.mat, this.amount, (short) this.data);
    You can use this code for solve your problems
     
  5. OMG...
    Thank you KingDragonRider...!!!
     
  6. You need to set the Durability of the block to the sub id of the glass color you want and you can not set the color of glass, only of stained glass.