Examining the Minecraft source reveals the exact algorithm for determining the color of potions. Here's the function that seems to do it:
public static int getPotionColor(Collection collection)
{
int waterColor = 0x385dc6;
if (collection == null || collection.isEmpty())
{
return waterColor;
}
float r = 0.0F;
float g = 0.0F;
float b = 0.0F;
float numColors = 0.0F;
for (Iterator iterator = collection.iterator(); iterator.hasNext();)
{
PotionEffect potioneffect = (PotionEffect)iterator.next();
int potionColor = Potion.potionTypes[potioneffect.getPotionID()].getLiquidColor();
int i = 0;
while (i <= potioneffect.getAmplifier())
{
r += (float)(potionColor >> 16 & 0xff) / 255F;
g += (float)(potionColor >> 8 & 0xff) / 255F;
b += (float)(potionColor >> 0 & 0xff) / 255F;
numColors++;
i++;
}
}
r = (hBit / numColors) * 255F;
g = (mBit / numColors) * 255F;
b = (lBit / numColors) * 255F;
return (int)r << 16 | (int)g << 8 | (int)b;
}
This large, complex piece of code actually does something quite simple. It does basically just take all the different colors and average them together. Even so, it has a few extra quirks. First of all, this code checks to see if there are any potion effects to begin with. If not, it just uses the water color. I don't think that's ever used in the game, though.
It then creates a bunch of variables. Colors in Minecraft are stored in hexadecimal RGB format, so it creates a variable for red, green, and blue. It then loops through all the potions that are currently active. It then gets the amplifier, or potion level, and weights each color based on its level. Higher level potions have more influence on the resulting color.
Next is a bunch of bitwise math to average all the values, and in the end, all the values are divided by the total (to actually get an average) and spliced back into a single number, which is then returned as the particle color.
The data value for potions is 373
and the "damage value" for an extended Night Vision potion is 8262
, and you want to give quantity 1
. Using these in a command block hooked up to your button, with @p
used to select the nearest player, looks like so:
/give @p 373 1 8262
Assuming you want this button to work only once, you can put an RS NOR latch between the button and the command block, so that the button activates the SET input (optionally with a hidden button accessible only to you attached to the RESET input, for easy testing).
You may also want to use the /say
command to alert the player that they just got the potion, since in the heat of the moment it's easy to overlook something quietly popping into your inventory, if your not expecting it. They'll still have to ready and drink it.
Best Answer
Lingering potions create entities of the type "
area_effect_cloud
", so you can kill them with this command:To kill only the nearest one, use this command: