How to set a wool block with color

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, May 21, 2016.

  1. I know how to set a block, but how would I set the wool color?
     
  2. I am unsure if this still works or not, but give it a shot.
    • Get the block in the event you are going to place
    • Set the data #setData, and specify a DyeColor then retrieve the data (accepts byte values)

    Usage of this would be as such.

    Code (Text):

    setData(DyeColor.RED.getData())
     
     
    • Agree Agree x 1
  3. boolean setTypeIdAndData(int type, byte data, boolean applyPhysics)
    Deprecated.

    void setData(byte data)
    Deprecated.

    void setData(byte data, boolean applyPhysics)
    Deprecated.

    Although these methods are deprecated, they still do work. Spigot is pretty lenient about deprecated methods, so this should work. If you'd like to take the non-deprecated route, you can use something along the lines of:


    Code (Text):
    Block block;
    MaterialData state = b.getState().getData();

    if (state instanceof Wool) {

        Wool w = (Wool) state;
        w.setColor(DyeColor.BLACK);

    } else {

    // if the block isn't wool
    }
     
  4. Ok, i know i said i knew how to place it, but appearantly it is different with wool, How would i do so?

    Edit: Never mind i figured it out
    Code (Text):


                        i.setType(Material.WOOL);
                        Wool wooli = (Wool) i;
                        wooli.setColor(DyeColor.BLUE);
     
     
    #4 TheGamerPlayz, May 21, 2016
    Last edited: May 21, 2016