The Predator Explained Part 2 - Calculating Color Values

Channel:
Subscribers:
108,000
Published on ● Video Link: https://www.youtube.com/watch?v=suycNzH_Ttg



Minecraft
Game:
Minecraft (2011)
Duration: 10:37
403 views
22


We continue the exploration of the monstrosity that is the Predator Active Camouflage system in Vanilla Minecraft. This time we'll look at how the color values for blocks are added up and averaged - quite an advanced piece of logic.

More details on the color conversion into scoreboard values, and the reasons for the bit number reduction. Thanks to The Redstone Scientist for the question:

What we're trying to do is do all the calculations using one scoreboard, rather than 4 (R, G, B and count). If we couldn't do that, we'd require four times as many detection commands to run every tick, which would be a significant increase in lag.

So in order to do that, I need to cram 3 8-bit color values plus one 5-bit count into one 32-bit scoreboard value (or actually 31-bit, since there's one sign bit). so 8+8+8+5 is still 29, which should fit comfortably! The problem is we now want to add like 10 of these values, which suddenly makes those 8-bit color values turn into 13-bit color values, and now it doesn't fit anymore.

So we're reducing the amount of bits in each color value, to get fewer digits, in order to fit them all into a 32-bit value - we reduce each 8-bit color value down to a 5-bit color value before mashing them all together into one value.

In terms of actual code, that calculation looks like this:

command += "scoreboard players add @p " + scoreboard + " ";
int r = block.xside.r / 8;
int g = block.xside.g / 8;
int b = block.xside.b / 8;
int n = (1 << (9 * 3)) | (r << (9 * 2)) | (g << 9) | b;
command += toString(n);

Circuit board background by Yuri Samoilov (https://www.flickr.com/photos/110751683@N02/14011462899) used under a Creative Commons CC-BY 2.0 License (https://creativecommons.org/licenses/by/2.0/)

Outro music "The Fire" by Amarante (http://amarante.bandcamp.com) licensed under Creative Commons: By Attribution 3.0 (http://creativecommons.org/licenses/by/3.0/)

You can find all my inventions and maps at my web site, http://www.slicedlime.tv

Leave me a comment, or find me elsewhere:
Twitter: http://twitter.com/slicedlime
Facebook: https://www.facebook.com/SlicedlimeYT
Reddit: http://reddit.com/u/sliced_lime
PlanetMinecraft: http://www.planetminecraft.com/member/slicedlime/







Tags:
Minecraft (Award-Winning Work)
Predator (Film)
Predator (Film Character)
Camouflage
Active Camouflage
Chameleon (Animal)
Command Block
Redstone
Explanation
slicedlime
Bit operation
Bitwise shift
scoreboard
operation



Other Statistics

Minecraft Statistics For slicedlime

At present, slicedlime has 16,383,613 views spread across 1,632 videos for Minecraft, with His channel publishing over 18 days worth of content for the game. This makes up 80.75% of Minecraft content that slicedlime has uploaded to YouTube.