package openperipheral.integration.vanilla;

import java.util.List;
import java.util.Map;

import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import openperipheral.api.helpers.ItemStackMetaProviderSimple;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

public class ItemPotionMetaProvider extends ItemStackMetaProviderSimple<ItemPotion> {

	@Override
	public String getKey() {
		return "potion";
	}

	@Override
	public Object getMeta(ItemPotion target, ItemStack stack) {
		@SuppressWarnings("unchecked")
		final List<PotionEffect> effects = target.getEffects(stack);

		final Map<String, Object> results = Maps.newHashMap();

		results.put("splash", ItemPotion.isSplash(stack.getItemDamage()));

		final List<Map<String, Object>> effectsInfo = Lists.newArrayList();

		for (PotionEffect effect : effects) {
			final Map<String, Object> entry = Maps.newHashMap();

			entry.put("duration", effect.getDuration() / 20); // ticks!
			entry.put("amplifier", effect.getAmplifier());
			entry.put("effect", getPotionInfo(effect.getPotionID()));

			effectsInfo.add(entry);
		}

		results.put("effects", effectsInfo);

		return results;
	}

	public static Map<String, Object> getPotionInfo(int potionId) {
		if (potionId < 0 || potionId >= Potion.potionTypes.length) return null;

		final Map<String, Object> result = Maps.newHashMap();

		final Potion potion = Potion.potionTypes[potionId];
		result.put("name", potion.getName());
		result.put("instant", potion.isInstant());
		result.put("color", potion.getLiquidColor());

		return result;
	}
}

@@ -604,105 +604,8 @@
 ) %7B%0A
-%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09final List%3CPotionEffect%3E effects = target.getEffects(stack);%0A%0A
 %09%09fi
@@ -799,16 +799,138 @@
 ist();%0A%0A
+%09%09@SuppressWarnings(%22unchecked%22)%0A%09%09final List%3CPotionEffect%3E effects = target.getEffects(stack);%0A%09%09if (effects != null) %7B%0A%09
 %09%09for (P
@@ -964,16 +964,17 @@
 s) %7B%0A%09%09%09
+%09
 final Ma
@@ -1015,24 +1015,25 @@
 HashMap();%0A%0A
+%09
 %09%09%09entry.put
@@ -1083,16 +1083,17 @@
  ticks!%0A
+%09
 %09%09%09entry
@@ -1137,16 +1137,17 @@
 ());%0A%09%09%09
+%09
 entry.pu
@@ -1200,16 +1200,17 @@
 ));%0A%0A%09%09%09
+%09
 effectsI
@@ -1225,16 +1225,21 @@
 entry);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%09r

Fix #22