package com.scottkillen.mod.dendrology.compat.chisel;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.scottkillen.mod.koresample.common.util.multiblock.SubBlockManager;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import java.util.List;

public final class ChiselWoodSubBlockManager implements SubBlockManager
{
    private final String speciesName;
    private final List<IIcon> icons = Lists.newArrayListWithCapacity(16);
    private static final ImmutableList<String> TEXTURES = ImmutableList
            .of("clean", "short", "vertical", "vertical-uneven", "parquet", "fancy", "blinds", "panel-nails",
                    "double-side", "crate", "crate-fancy", "crateex", "large", "chaotic-hor", "chaotic", "double-top");

    public ChiselWoodSubBlockManager(String speciesName)
    {
        this.speciesName = speciesName;
    }

    @Override
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return meta != 9 || side != 0 && side != 1 ? icons.get(meta) : icons.get(15);
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister iconRegister)
    {
        icons.clear();

        for (final String texture : TEXTURES)
            icons.add(iconRegister.registerIcon(String.format("chisel:planks-%s/%s", speciesName, texture)));
    }

    @SuppressWarnings("unchecked")
    @Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item item, CreativeTabs unused, List subBlocks)
    {
        final int numSubBlocks = TEXTURES.size() - 1;
        for (int i = 0; i < numSubBlocks; i++)
            //noinspection ObjectAllocationInLoop
            subBlocks.add(new ItemStack(item, 1, i));
    }

    @Override
    public String toString()
    {
        return Objects.toStringHelper(this).add("speciesName", speciesName).add("icons", icons).toString();
    }
}

@@ -1247,32 +1247,93 @@
 int meta)%0A    %7B%0A
+        final int meta1 = meta %3C 0 %7C%7C meta %3E= 16 ? 0 : meta;%0A
         return m
@@ -1335,16 +1335,17 @@
 urn meta
+1
  != 9 %7C%7C
@@ -1384,16 +1384,17 @@
 get(meta
+1
 ) : icon

Fix for BluSunrize/ImmersiveEngineering passing garbage in and not handling resulting exception.