Solved Comparing dye item names to color names

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Wynnevir

Well-Known Member
Jul 9, 2017
1,015
62
48
30
Elsewhere
I have this little skript here to just change the color of a wool block when dye is clicked on it.
It works well with just comparing the name of the held item to a corresponding color on the list, however I'm running into the issue of some dye items not having their color in their name or being two words for a color(ie: light blue) ooor not matching their skript counterpart (ie: grey vs gray).
Any ideas on how I could make these dye items work without adding 14 extra lines of code to reference each one specifically?

The items that do not fit are cocoa beans, ink sack, bone meal, lapis lazuli, light blue and grey and light grey.
Using an "if" statement per item would work, but it's a lot of extra lines, and I havn't been able to think of a better way to handle this if one exists:emoji_frowning:

code_language.skript:
on rightclick with any dye:
    if event-block is any wool block:
        set {_tool} to "%player's tool%"
        set {_dye::*} to {_tool} split at " "
        add "green", "yellow", "red", "purple", "cyan", "pink", "lime", "magenta" and "orange" to {_colorlist::*}
        loop {_colorlist::*}:
            loop {_dye::*}:
                if loop-value-1 = loop-value-2:
                    set {_final} to "%loop-value-1% wool block"
                    set block at event-location to "%{_final}%" parsed as item
                    remove 1 of the player's tool from player
 
untitled.PNG

this is what spigot says about them so it looks like they should somewhat work possibly
 
Here is the proper way to do it with skript-mirror
code_language.skript:
on right click on any wool block:
  set {_color} to try (color of player's tool).getWoolColor()
  {_color} is set
  set {_blockState} to (clicked block).getState()
  set {_blockData} to {_blockState}.getData()
  {_blockData}.setColor({_color});
  {_blockState}.update();

https://gfycat.com/BriefAshamedBassethound
 
Last edited:
  • Like
Reactions: Wynnevir
Here is the proper way to do it with skript-mirror
code_language.skript:
on right click on any wool block:
  set {_color} to try (color of player's tool).getWoolColor()
  {_color} is set
  set {_blockState} to (clicked block).getState()
  set {_blockData} to {_blockState}.getData()
  {_blockData}.setColor({_color});
  {_blockState}.update();

https://gfycat.com/BriefAshamedBassethound
I appreciate that, Java's been a bit of a slow pick up for me but I want to get it down at some point^-^
 
Status
Not open for further replies.