I am trying to make a printer with sheep. I have a double chest for the printer input and sheep correspond to the slots in the chest. There are 54 sheep corresponding to the 54 slots. What command can I run to make the color of wool in a specific slot in a chest the same color as the corresponding sheep? And how can I copy it 54 times so I can do it for each slot/sheep?
Minecraft – How to change the color of a sheep to match a block of wool in a chest
minecraft-commandsminecraft-java-edition
Related Solutions
No.
Hitting a sheep in the head will cause no wool to be dropped until it is killed, when it will drop 1 block of wool. Furthermore, hitting a sheep in the head will not kill it any quicker, but it may relive tension and angst caused by a creeper.
Shearing a sheep with the shears item will result in 2-4 wool blocks being dropped, again, regardless of attack location.
This is a known problem in computer science called dithering: your picture has too many colors for the target format or display to show (for example animated GIFs are limited to 256 colors) so what you can do is simulate the colors in between through juxtaposition.
Dithering might not work very well if your picture is going to be seen from up close; you can also near to the closest color from those 16. Again, this is a solved problem and a computer can do the maths for you.
Here's what you can do to get the best results a computer can give you.
- Get Gimp, install it and open it.
- Get a picture of the wool palette in your texture on screen; just opening it in an image viewer or the browser is fine. Keep it unobscured from all of the open dialogues, including the ones we're about to open.
- Open the palette editor (Windows → Dockable dialogues → Palette)
- On the bottom bar of the palette editor hit the create palette button.
- In the new dialogue that pops up, call the picture Minecraft.
- From the main Toolbox, double click the primary color from the color chooser (it should be the large black rectangle obscuring the white one.) You should get a color picker. Don't close the color picker. If you close it, simply double click that rectangle again.
- Find the eyedropper button next to the HTML notation textbox. Click it.
- Move your mouse over the picture from step 2. Press and hold the left mouse button, then move it around. You will see that the color picker changes the current selection to reflect the color that's under your mouse. Mouse over the first of the 16 colors of wool in your texture pack and finally release the left mouse button. Repeat the process until you get a satisfying representative color for that wool block.
- Go to the Minecraft palette window, right click in the middle and choose New color from FG to add the current color to the palette.
- Repeat steps 8 and 9 for each of the 16 shades of wool. If you want to use more than that (e.g. ender blocks or netherrack or what have you), do the same for those blocks, too.
- Close the color picker.
- Open the picture you want to convert.
- Size the picture down (Image → Scale Image...) so that you get 1 pixel per block (i.e. if your picture in Minecraft will be 40×30 blocks wide, scale the image down to 40×30 pixels).
- Finally we get to the business part. Open Image → Mode → Indexed...
- Choose Use custom palette
- From the palette list (the one in step 3), drag the Minecraft one and drop it on the palette chooser (the button with the tiny colored rectangles.)
- Choose if you want dithering or not. You will probably want either Floyd-Steinberg (reduced color bleed) or No dithering.
- Hit Ok.
Now the picture tells you what block you should use where in your final result. You can zoom with Ctrl-Mousewheel and pan around with middle click. Now you just have to go minecraft the picture together with wool.
For example, here's how this process changes a picture of the color spectrum with Floyd-Steinberg (reduced color bleed) and these wool colors:
original
result
If you don't like the dithering, you can turn that off and approximate every pixel with the closest color:
original
result
...so yeah, feel free to consider this picture as proof that the Minecraft selection of wool dyes is not the very best ever. Here is the same image with the same algorithm and the same number of colors; all that changes is the 16 specific colors:
original
result
Of course, the more complex the starting picture, the more disappointing the result will be. Picking the right picture matters. Cropping it to the part with more details helps too.
Here's another example: kitten.
→ →
Okay, that doesn't look too good, but while you are using GIMP you might as well make use of it. The background is midway green and yellow, so maybe you can consider shifting the hue of the image (Colors → Hue-Saturation) towards either one of those two colors. For bonus points you might even try and just do that to the background using the various selections tools (this is no GIMP tutorial!).
For example:
→ →
Related Topic
- Minecraft – Command block check chest
- Minecraft – How to detect a wool block with a color
- Minecraft – Place items in specific slots
- Minecraft – Copy and change item names in chest
- Minecraft – I have a problem where I tag snowballs but the tag dissapears when the snowball is in the air
- Minecraft – The case of the dead sheep
Best Answer
The problem this comes down to is: How do I loop through the elements of an NBT array? Luckily I already have an answer to that: Dynamically sized NBT array
The "tedious method" would in your case require 864 (54×16) commands, like this:
That's very tedious. It's probably slightly better for performance than what I'm about to suggest, but it's not well generalisable for other cases and it's not as clever. ;)
I'll assume here that all slots are filled, so index and slot number are identical. If that is not the case, you'll have to use something like the "search" method from my linked post. I'll also assume that all the sheep have their desired slot number saved in a scoreboard called "
slot
". You'll have to target them properly somehow, a scoreboard is a good idea for that.First, copy the entire chest's
Items
array somewhere else:And initialise a scoreboard to 0:
Now you need a loop, I would suggest a function with recursive calls for this. I'll call mine
fabian:copy_sheep
. Here is the complete function:Explanation:
Due to an oversight in the NBT path syntax
items[0]{id:"minecraft:white_wool"}
does not work. Therefore you need to first copy that tag somewhere else, in this casefabian:sheep curr_item
.Then you check every sheep for having the same value in the scoreboard "
slot
" as the fake player "$current
". You can't use@e[scores={…}]
here, because you need a dynamic number. When the sheep matches, it checks if the current item's ID is"white_wool"
and if yes, sets itsColor
tag to0
(which is white). Then this repeats for"orange_wool"
andColor:1
and so on. This effectively means: Colour the sheep according to the current wool item.The rest of the function increases the current slot counter, removes the first entry from the copied item list and continues the loop if there is an entry left. The reason why this is needed is that you can't dynamically access an array index based on a scoreboard value, so you need move the element forwards as many times as you want and then read from the fixed index 0.
Note that you need to do the setup again before repeating this process (except for the scoreboard creation).
I tried it here with a single chest, but it works the same with any inventory: