Convert color to dye color

Discussion in 'Plugin Development' started by iMarv, Mar 26, 2014.

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

    iMarv

    Hey, I am trying to mix the color of wool blocks.
    I am doing it with the Color.mixColors() method. The problem is that the output of that method is Color and I am not able to convert Color into DyeColor which is needed for Wool.setColor().

    Are there any ways to do this or am I trying it the wrong way?
     
  2. DyeColor.getByColor()
     
  3. Offline

    iMarv

    When I am using setColor(DyeColor.getByColor(color)) with the color of mixColors() on a sheep, the sheep stays white.
    Is there a limitation?

    Code:java
    1. private void checkForSheep(Block b1, Player p)
    2. {
    3. Block b2, b3;
    4.  
    5. /*
    6.   * All blocks around the pumpkin are being checked if they are a wool block*/
    7. if(checkAllDirections(b1, Material.WOOL) != b1)
    8. {
    9. /*
    10.   * If the block that is returned is not the placed block the program checks for another wool block*/
    11.  
    12. b2 = checkAllDirections(b1, Material.WOOL);
    13. b3 = checkAllDirections(b2, Material.WOOL);
    14.  
    15. if(b3 != b2)
    16. {
    17. /*
    18.   * If a second wool block is located the location of the first wool block will be the spawn location for the sheep
    19.   * The 2 wools blocks and the pumpkin are getting replaced by air */
    20. Location l = b2.getLocation();
    21. b1.setType(Material.AIR);
    22. b2.setType(Material.AIR);
    23. b3.setType(Material.AIR);
    24.  
    25. /*
    26.   * The Sheep gets spawned*/
    27. Sheep sheep = (Sheep) p.getWorld().spawnEntity(l, EntityType.SHEEP);
    28. sheep.setColor(DyeColor.getByColor(getWoolColor(b2, b3)));
    29.  
    30. }
    31. }
    32.  
    33. }
    34.  
    35. private Color getWoolColor(Block b1, Block b2)
    36. {
    37.  
    38. Wool w1 = (Wool) b1;
    39. Wool w2 = (Wool) b2;
    40.  
    41. if(w1.getColor() == w2.getColor())
    42. {
    43. /*
    44.   * If the colors of the blocks are the same, the color is getting returned*/
    45. return w1.getColor().getColor();
    46. }else{
    47. /*
    48.   * If the colors are different, they are getting mixed and returned */
    49. Color mix = w1.getColor().getColor().mixDyes(w2.getColor());
    50. return mix;
    51. }
    52. }


    I am spawning sheep by building a small structure, like when spawning snowmen. And I want to change the color of the sheep, depending on the used wool
     
  4. iMarv I've never coloured sheep before, so not exactly certain on this. But a few things I'd check would be:

    • What Color is w1 and w2?
    • What DyeColor is returned?
    I'd check both of the above for when Color is the same, and when they're different.
     
  5. Offline

    iMarv

    I think I will just color the sheep in the color of the wool block that is the closest to the head.
    Maybe I will find a way for mixing those colors, but for now I will stay with this method.

    Thank you anyways :)
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page