Little Colored Wool Material Problem

Discussion in 'Plugin Development' started by deleted_91027365, Apr 21, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys (and girls :D ),

    How can I set the color of a MATERIAL?
    I want to make a little "ColorIt". So, if a Player right click a Block my Plugin gets his Item in Hand and sets his targetted block to this item.

    But my Problem: How can I set Colored Wool?
    The other code is already finish (or thinked).

    Code:
    
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
    
            if(e.getAction() == Action.RIGHT_CLICK_AIR | e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                Block loc = p.getTargetBlock(null, 600);
                loc.setType(redwool);
               
                  if(p.getItemInhand == COLORED WOOL TYPE) {
                  loc.settype(COLORED WOOL);
    }
    
            }
        }
    
    
    I also know that I dont can use an ÌtemStack as an Material and so. But how can I fix it?
     
  2. Offline

    mine-care

    Nononononono, (xD) I recomend you do event#getItem() instead of getItemInHand(), Dont compare objects with ==
    and since it is an itemstack you can compare it with an itemstack :p Have an itemstack with i.e. red wool and upon interact use itemstack.matches(otherItemstack) :p
     
  3. Offline

    nj2miami

    How is that any different?


    @dunklesToast - To set the color of a Wool BLOCK it is much more complicated then what you are doing.

    Code:
    Block block = someBlockAtSomeLocation;
    BlockState bs = block.getState();
    Wool wool = (Wool) bs.getData();
    wool.setColor(someColorToChangeInto);
    bs.setData((MaterialData) wool);
    bs.update(true);
    Also, this will never trigger unless you 'ignoreCancelled = true' in your event handler, nor should you really be checking since you are trying to change a block (why would you test for AIR)
     
    Last edited by a moderator: Apr 21, 2015
  4. Offline

    Zombie_Striker

    .getData() returns a byte, which is the color of the wool. You can also use .setData() to set the data of a block/Item. It's deprecated, but I don't think there is away around it.
     
  5. Offline

    I Al Istannen

  6. Offline

    nj2miami

    Haha, yah I meant ignore FALSE. ignore=true is default.

    The code I provided is from a plugin I use which actively works in 1.8.3

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Apr 21, 2015
  7. Offline

    mine-care

    @nj2miami there is a reason why it exists in the event, it isn't different as far as I know, I just pointed it out, it is not wrong.
     
  8. Offline

    nj2miami

    .getData() returns a MaterialData and must be cast as such in .setData()
     
  9. Offline

    mythbusterma

    @nj2miami @dunklesToast

    There is nothing stopping you from doing Block#setData(byte), and condensing that down to one line. Since he's copying the value from somewhere else, the fact that it's deprecated for "magic value" is completely irrelevant.
     
Thread Status:
Not open for further replies.

Share This Page