Golf Your Favorite Minecraft Tool

20

2

In Minecraft, the default item textures are all reasonably simple 16×16 pixel images, which makes them seem ideal for golfing.

Below are simplified textures of the five "core" diamond tools in Minecraft: pickaxe, shovel, axe, sword, and hoe.

The images shown are enlarged to show their detail. Click on an image to view its correctly sized 16×16 pixel version.

pickaxe shovel axe sword hoe

To make golfing easier, I've modified each of them from the originals to only use the five same 24-bit RGB colors:

  • R=75 G=82 B=73 for the background.
  • R=51 G=235 B=203 for the diamond tool heads.
  • R=14 G=63 B=54 for the diamond outlines.
  • R=137 G=103 B=39 for the wooden handle core.
  • R=40 G=30 B=11 for the wooden handle outlines.

Choose your favorite tool out of the five and write a program that outputs its simplified 16×16 pixel texture in any common lossless truecolor image format (such as bpm, png, ppm, etc.).

So, for example, if you chose the axe, you would write a program that outputs this image: axe example

No input should be taken and a web connection should not be required. The image can be output as a file with the name of your choice, or the raw image file data can be output to stdout, or you can simply display the image.

You only need to choose one of the five images. The program that outputs any one of the five images in the fewest number of bytes is the winner.

You may write programs for more than one of the images, but only the one with the minimum number of bytes counts towards your score. If there's a tie, the highest voted post wins.


If you enjoy PPCG and play Minecraft, I invite you to come join our trial Minecraft server. Just ask in the dedicated chatroom.

Calvin's Hobbies

Posted 2015-06-11T01:15:36.663

Reputation: 84 000

5"Enlarged to show detail." I can only think of cereal boxes. – Alex A. – 2015-06-11T04:17:57.440

I think there may be some compression issues or you have some typos in the colours. Mathematica claims, these five colours are used (at least for the shovel): [[76 82 73] [26 63 54] [106 234 204] [39 30 13] [133 102 45]] – Martin Ender – 2015-06-11T12:21:28.987

@MartinBüttner Are you sure? I re-downloaded the shovel image and made sure that the 5 colors are correct. I also made sure there were exactly 5 colors. imgur may be compressing the enlarged images but those are not the ones you should be using.

– Calvin's Hobbies – 2015-06-11T18:37:22.790

@Calvin'sHobbies Is input allowed? – user41805 – 2015-10-06T17:46:15.823

Answers

6

CJam, 119 bytes

I've chosen the shovel.

'P3NGSGN255N]o67T"vîþáy$<OW¥ÓNZ"256b9b~99T]2/e~W%"LRI?6jêÌ'
f-":i3/f=F,_W%:)+{)/(\:~}%{G/({)S*S+oNo}%1>\:~+}G*

Test it here.

This program prints a PPM file to STDOUT.

I used this script to help with encoding the image. (This is mostly for myself if I need to reuse it later.)

The basic idea is to unroll the image along antidiagonals and then use run-length encoding. With this technique, the shovel contains the fewest runs. For reference the number of runs per image (in the order given in the challenge) is:

{60, 26, 38, 43, 37}

I'll add more explanation when I'm done golfing this.

Martin Ender

Posted 2015-06-11T01:15:36.663

Reputation: 184 808

7

JavaScript ES6, 353 bytes

document.write(`<p style="width:1px;height:1px;box-shadow:${'931a31b31841940a40b40c41951a51b50c50d51e53f52b61c60d60e62f63c73d70e70f71b83c82d83e81a93b92c939a3aa2ba38b39b2ab37c38c29c36d37d28d35e36e27e34f35f26f34g35g3'.replace(/.../g,e=>(p=parseInt)(e[0],17)+`px ${p(e[1],17)}px 0 #${['33EBCB','0E3F36','896727','281E0B'][e[2]]},`)}9px 9px 0 8px #4B5249"`)

This heavily abuses CSS3 box-shadows to create a pixelized version of the image, in this case the Minecraft hoe. The Stack Snippet below uses ES5 for easy testing and is somewhat ungolfed (You'll have to zoom in to see it well).

s='931a31b31841940a40b40c41951a51b50c50d51e53f52b61c60d60e62f63c73d70e70f71b83c82d83e81a93b92c939a3aa2ba38b39b2ab37c38c29c36d37d28d35e36e27e34f35f26f34g35g3'.replace(/.../g,function(e){
  return parseInt(e[0],17)+'px '+parseInt(e[1],17)+'px 0 #'+['33EBCB','0E3F36','896727','281E0B'][e[2]]+','
})
document.write('<p style="width:1px;height:1px;box-shadow:'+s+'9px 9px 0 8px #4B5249"')

NinjaBearMonkey

Posted 2015-06-11T01:15:36.663

Reputation: 9 925

Could this be shortened by using base64 encoding instead of hex? – lirtosiast – 2015-06-11T03:34:09.717

6The largest source image is 297 bytes. Kinda sad to be over that :) – J B – 2015-06-11T07:40:23.043

@JB It's [kolmogorov-complexity] for a reason ;) – NinjaBearMonkey – 2015-06-11T16:45:30.517

@ThomasKwa Doesn't base64 actually make it longer? (It's actually base-17 because there's gs near the end.) – NinjaBearMonkey – 2015-06-11T16:46:45.897

I don't know how expensive interpreting base64 encoding is in Javascript, but the string literal itself should be 2/3rds the size in base64 as in hex. – lirtosiast – 2015-06-11T16:51:09.327

2

Since this is a minecraft problem, I will do a command block solution: 50 characters

summon ItemFrame ~1 ~0 ~0 {Item:{id:diamond_axe}}

creates an item frame showing an axe.

Lucas

Posted 2015-06-11T01:15:36.663

Reputation: 665

2You need to output an image. – Deusovi – 2015-09-08T01:23:55.760

1The image is outputted on screen as part of the game. – Lucas – 2015-09-12T04:24:15.530

1Because of perspective, it will never be a perfect image - it's supposed to be pixelart too, only 16x16. – Deusovi – 2015-09-12T05:11:15.900

3I think this qualifies as a standard loophole - same as getting the image from an external source. I think it would have been alright to summon blocks to act as the pixels, with the colors as close as possible. – Calvin's Hobbies – 2015-09-22T22:06:17.383

1I count this as a language feature. – Lucas – 2015-09-25T20:40:58.513

You're supposed to output the simplified images, not the original Minecraft texture – ManfP – 2018-03-19T10:10:43.520

1I'm not sure if this is valid because if I change the texture back for my game and run this command from a command block. it will not display the correct image. Also -2 bytes by getting rid of the 0s in ~0; ~ behaves identically to ~0. – HyperNeutrino – 2018-03-19T12:10:27.970

1

Minecraft 18w11a (.mcfunction), 757 bytes

fill ~ ~ ~ ~15 ~ ~15 ice
fill ~13 ~ ~13 ~7 ~ ~11 cyan_wool
fill ~12 ~ ~14 ~10 ~ ~8 cyan_wool
fill ~12 ~ ~13 ~10 ~ ~11 diamond_block
fill ~11 ~ ~12 ~9 ~ ~10 diamond_block
fill ~10 ~ ~11 ~8 ~ ~9 diamond_block
fill ~3 ~ ~4 ~1 ~ ~2 dirt
setblock ~3 ~ ~4 oak_planks
setblock ~2 ~ ~3 oak_planks
clone ~3 ~ ~4 ~1 ~ ~2 ~4 ~ ~5
setblock ~4 ~ ~5 oak_planks
setblock ~4 ~ ~7 ice
setblock ~6 ~ ~5 ice
clone ~6 ~ ~5 ~4 ~ ~7 ~7 ~ ~8
setblock ~9 ~ ~10 diamond_block
setblock ~4 ~ ~4 dirt
setblock ~3 ~ ~5 dirt
setblock ~7 ~ ~7 dirt
setblock ~6 ~ ~8 dirt
setblock ~1 ~ ~2 ice
fill ~12 ~ ~9 ~12 ~ ~8 ice
setblock ~11 ~ ~8 ice
fill ~8 ~ ~13 ~7 ~ ~13 ice
setblock ~7 ~ ~12 ice
fill ~ ~ ~ ~15 ~ ~15 light_gray_concrete replace ice
fill ~ ~ ~ ~9 ~ ~10 dark_oak_bark replace dirt

Of course someone had to answer the question with Minecraft. Place answer inside of a datapack, and run with /function <packname>:<filename>. The shovel is drawn relative to you in the +X and +Z direction. Colors are wrong but I'll count that as a language limitation ;)

But the shovel is actually made out of wood and diamonds!!!!

Output

Shoveled

quat

Posted 2015-06-11T01:15:36.663

Reputation: 1 211

oh hey, that's cool! – quat – 2018-03-19T14:51:28.863

1

Python 3, 483 bytes

I chose to make the sword

from PIL import Image as IG, ImageColor as IC
s=IG.new('RGB',(16,16))
w='#6b6727'
b='#4b5249'
d='#33ebcb'
a='#0e3f36'
n='#281e0b'
t=b*13+a*3+b*12+a+d*2+a+b*11+a+d*3+a+b*10+a+d*3+a+b+b*9+a+d*3+a+b*2+b*8+a+d*3+a+b*3+b*2+a*2+b*3+a+d*3+a+b*4+b*2+a+d+a+b+a+d*3+a+b*5+b*3+a+d+a+d*3+a+b*6+b*3+a+d+a+d*2+a+b*7+b*4+a+d+a*2+b*8+b*3+n+w+a+d*2+a+b*7+b*2+n+w+n+b+a*2+d+a+b*6+a*2+w+n+b*4+a*2+b*6+a+d+a+b*13+a*3+b*13
s.putdata([IC.getrgb(t[i:i+7]) for i in range(0,len(t),7)])
s.save('s.png','PNG')

here is the output: enter image description here

I created a string for each color, and combined them to get a string of hexadecimal numbers. Then I used the python image library to convert that string into an image.

Anthony Roitman

Posted 2015-06-11T01:15:36.663

Reputation: 91