package org.squiddev.plethora.integration.vanilla.meta;

import com.google.common.collect.Maps;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBanner;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntityBanner;
import org.squiddev.plethora.api.meta.BasicMetaProvider;
import org.squiddev.plethora.api.meta.IMetaProvider;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;

@IMetaProvider.Inject(value = ItemStack.class, namespace = "banner")
public class MetaItemBanner extends BasicMetaProvider<ItemStack> {
	@Nonnull
	@Override
	public Map<Object, Object> getMeta(@Nonnull ItemStack stack) {
		if (!(stack.getItem() instanceof ItemBanner)) return Collections.emptyMap();

		int idx = 0;
		Map<Object, Object> out = Maps.newHashMap();

		NBTTagCompound tag = stack.getSubCompound("BlockEntityTag", false);
		if (tag != null && tag.hasKey("Patterns")) {
			NBTTagList nbttaglist = tag.getTagList("Patterns", 10);

			for (int i = 0; i < nbttaglist.tagCount() && i < 6; ++i) {
				NBTTagCompound patternTag = nbttaglist.getCompoundTagAt(i);

				EnumDyeColor color = EnumDyeColor.byDyeDamage(patternTag.getInteger("Color"));
				TileEntityBanner.EnumBannerPattern pattern = TileEntityBanner.EnumBannerPattern.getPatternByID(patternTag.getString("Pattern"));

				if (pattern != null) {
					Map<String, String> entry = Maps.newHashMap();
					entry.put("id", pattern.getPatternID());
					entry.put("name", pattern.getPatternName());
					entry.put("colour", color.toString());
					entry.put("color", color.toString());

					out.put(++idx, entry);
				}
			}
		}

		return out;
	}
}

@@ -328,24 +328,90 @@
 tityBanner;%0A
+import net.minecraftforge.fml.common.ObfuscationReflectionHelper;%0A
 import org.s
@@ -1399,43 +1399,8 @@
 n = 
-TileEntityBanner.EnumBannerPattern.
 getP
@@ -1574,58 +1574,193 @@
 ));%0A
+%0A
 %09%09%09%09%09
-entry.put(%22name%22, patt
+// patternName%0A%09%09%09%09%09String name = ObfuscationReflectionHelp
 er
-n
 .getP
-atternName()
+rivateValue(TileEntityBanner.EnumBannerPattern.class, pattern, %22field_177284_N%22);%0A%09%09%09%09%09entry.put(%22name%22, name
 );%0A
+%0A
 %09%09%09%09
@@ -1903,11 +1903,271 @@
  out;%0A%09%7D
+%0A%0A%09private static TileEntityBanner.EnumBannerPattern getPatternByID(String id) %7B%0A%09%09for (TileEntityBanner.EnumBannerPattern pattern : TileEntityBanner.EnumBannerPattern.values()) %7B%0A%09%09%09if (pattern.getPatternID().equals(id)) return pattern;%0A%09%09%7D%0A%0A%09%09return null;%0A%09%7D
 %0A%7D%0A

Fix using client only methods