package ljfa.glassshards.compat;

import ljfa.glassshards.api.GlassType;
import net.minecraft.block.Block;

public class ChiselGlassHelper {
    public static void init() throws ReflectiveOperationException {
        Class<?> classModBlocks = Class.forName("com.cricketcraft.chisel.init.ModBlocks");
        
        chiselStainedGlass = (Block[])classModBlocks.getDeclaredField("stainedGlass").get(null);
        chiselStainedPane = (Block[])classModBlocks.getDeclaredField("stainedGlassPane").get(null);
        
        for(Block b: chiselStainedPane)
            ModGlassRegistry.removeDropsSet.add(b);
        
        ModGlassRegistry.helperMap.put(chiselStainedGlass[0], new ChiselTypeHandler());
    }
    
    public static class ChiselTypeHandler extends ModGlassHandler {
        @Override
        public GlassType getType(Block block, int meta) {
            return new GlassType(GlassType.mult_block, true, meta);
        }
    }
    
    private static Block[] chiselStainedGlass;
    private static Block[] chiselStainedPane;
}

@@ -601,32 +601,95 @@
 dd(b);%0A        %0A
+        for(int i = 0; i %3C chiselStainedGlass.length; i++)%0A    
         ModGlass
@@ -730,17 +730,17 @@
 edGlass%5B
-0
+i
 %5D, new C
@@ -748,20 +748,28 @@
 isel
-Type
+StainedGlass
 Handler(
 ));%0A
@@ -764,16 +764,17 @@
 Handler(
+i
 ));%0A    
@@ -810,20 +810,28 @@
 s Chisel
-Type
+StainedGlass
 Handler 
@@ -868,75 +868,486 @@
     
-@Override%0A        public GlassType getType(Block block, int meta) %7B
+private int arrayIndex;%0A        %0A        public ChiselStainedGlassHandler(int arrayIndex) %7B%0A            this.arrayIndex = arrayIndex;%0A        %7D%0A        %0A        @Override%0A        public GlassType getType(Block block, int meta) %7B%0A            // How stained glass works in Chisel:%0A            // array index = color %3E%3E 2%0A            // metadata = (color & 3) %3C%3C 2%0A            // Blame Chisel for using such hardcoded values%0A            int color = (arrayIndex %3C%3C 2) %7C (meta %3E%3E 2);
 %0A   
@@ -1404,20 +1404,21 @@
 , true, 
-meta
+color
 );%0A     

Make Chisel helper work with glass blocks