// Path: src/main/java/alexiil/mc/mod/load/baked/BakedRender.java
// public abstract class BakedRender extends BakedTickable {
//     public abstract void evaluateVariables(MinecraftDisplayerRenderer renderer);
// 
//     public abstract void render(MinecraftDisplayerRenderer renderer);
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         render(renderer);
//     }
// 
//     public abstract String getLocation();
// }
// 
// Path: src/main/java/alexiil/mc/mod/load/baked/BakedRenderingPart.java
// public class BakedRenderingPart extends BakedTickable {
//     public final BakedInsn[] instructions;
//     public final BakedRender render;
//     public final INodeBoolean shouldRender;
// 
//     public BakedRenderingPart(BakedInsn[] instructions, BakedRender render, INodeBoolean shouldRender) {
//         this.instructions = instructions;
//         this.render = render;
//         if (render == null) throw new NullPointerException("render");
//         this.shouldRender = shouldRender;
//     }
// 
//     public void render(MinecraftDisplayerRenderer renderer) {
//         GL11.glPushMatrix();
//         GL11.glMatrixMode(GL11.GL_PROJECTION);
//         GL11.glPushMatrix();
//         GL11.glMatrixMode(GL11.GL_MODELVIEW);
//         render.evaluateVariables(renderer);
//         for (BakedInsn insn : instructions) {
//             insn.render();
//         }
//         render.render(renderer);
//         GL11.glPopMatrix();
//         GL11.glMatrixMode(GL11.GL_PROJECTION);
//         GL11.glPopMatrix();
//         GL11.glMatrixMode(GL11.GL_MODELVIEW);
//     }
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         if (shouldRender.evaluate()) {
//             render(renderer);
//         }
//     }
// 
//     @Override
//     public void preLoad(MinecraftDisplayerRenderer renderer) {
//         super.preLoad(renderer);
// 
//         for (BakedInsn insn : instructions) {
//             insn.preLoad(renderer);
//         }
// 
//         render.preLoad(renderer);
//     }
// }
// 
// Path: src/main/java/alexiil/mc/mod/load/baked/insn/BakedInsn.java
// public abstract class BakedInsn extends BakedTickable {
//     public abstract void render();
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         render();
//     }
// }


import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.util.ResourceLocation;
import alexiil.mc.mod.load.baked.BakedRender;
import alexiil.mc.mod.load.baked.BakedRenderingPart;
import alexiil.mc.mod.load.baked.insn.BakedInsn;
import buildcraft.lib.expression.FunctionContext;
import buildcraft.lib.expression.GenericExpressionCompiler;
import buildcraft.lib.expression.api.IExpressionNode.INodeBoolean;
import buildcraft.lib.expression.api.InvalidExpressionException;
import buildcraft.lib.expression.node.value.NodeConstantBoolean;
        this.shouldRender = consolidateFunction(json, "should_render", context, parent == null ? null : parent.shouldRender, "true");
    }

    @Override
    public void setLocation(ResourceLocation location) {
        super.setLocation(location);
        location = this.resourceLocation;
        image.setLocation(location);
        for (JsonInsn insn : instructions) {
            insn.setLocation(location);
        }
    }

    @Override
    protected BakedRenderingPart actuallyBake(FunctionContext context) throws InvalidExpressionException {
        List<BakedInsn> args = new ArrayList<>();

        JsonRender element = image;

        context = new FunctionContext(context);

        BakedRender actualRender = element.bake(context);
        args.addAll(element.bakeInstructions(context));

        if (instructions != null) {
            for (JsonInsn insn : instructions) {
                args.add(insn.bake(context));
            }
        }

// Path: src/main/java/alexiil/mc/mod/load/baked/BakedRender.java
// public abstract class BakedRender extends BakedTickable {
//     public abstract void evaluateVariables(MinecraftDisplayerRenderer renderer);
// 
//     public abstract void render(MinecraftDisplayerRenderer renderer);
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         render(renderer);
//     }
// 
//     public abstract String getLocation();
// }
// 
// Path: src/main/java/alexiil/mc/mod/load/baked/BakedRenderingPart.java
// public class BakedRenderingPart extends BakedTickable {
//     public final BakedInsn[] instructions;
//     public final BakedRender render;
//     public final INodeBoolean shouldRender;
// 
//     public BakedRenderingPart(BakedInsn[] instructions, BakedRender render, INodeBoolean shouldRender) {
//         this.instructions = instructions;
//         this.render = render;
//         if (render == null) throw new NullPointerException("render");
//         this.shouldRender = shouldRender;
//     }
// 
//     public void render(MinecraftDisplayerRenderer renderer) {
//         GL11.glPushMatrix();
//         GL11.glMatrixMode(GL11.GL_PROJECTION);
//         GL11.glPushMatrix();
//         GL11.glMatrixMode(GL11.GL_MODELVIEW);
//         render.evaluateVariables(renderer);
//         for (BakedInsn insn : instructions) {
//             insn.render();
//         }
//         render.render(renderer);
//         GL11.glPopMatrix();
//         GL11.glMatrixMode(GL11.GL_PROJECTION);
//         GL11.glPopMatrix();
//         GL11.glMatrixMode(GL11.GL_MODELVIEW);
//     }
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         if (shouldRender.evaluate()) {
//             render(renderer);
//         }
//     }
// 
//     @Override
//     public void preLoad(MinecraftDisplayerRenderer renderer) {
//         super.preLoad(renderer);
// 
//         for (BakedInsn insn : instructions) {
//             insn.preLoad(renderer);
//         }
// 
//         render.preLoad(renderer);
//     }
// }
// 
// Path: src/main/java/alexiil/mc/mod/load/baked/insn/BakedInsn.java
// public abstract class BakedInsn extends BakedTickable {
//     public abstract void render();
// 
//     @Override
//     public void tick(MinecraftDisplayerRenderer renderer) {
//         render();
//     }
// }


// Path: src/main/java/alexiil/mc/mod/load/json/JsonRenderingPart.java
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.util.ResourceLocation;
import alexiil.mc.mod.load.baked.BakedRender;
import alexiil.mc.mod.load.baked.BakedRenderingPart;
import alexiil.mc.mod.load.baked.insn.BakedInsn;
import buildcraft.lib.expression.FunctionContext;
import buildcraft.lib.expression.GenericExpressionCompiler;
import buildcraft.lib.expression.api.IExpressionNode.INodeBoolean;
import buildcraft.lib.expression.api.InvalidExpressionException;
import buildcraft.lib.expression.node.value.NodeConstantBoolean;

        this.shouldRender = consolidateFunction(json, "should_render", context, parent == null ? null : parent.shouldRender, "true");
    }

    @Override
    public void setLocation(ResourceLocation location) {
        super.setLocation(location);
        location = this.resourceLocation;
        image.setLocation(location);
        for (JsonInsn insn : instructions) {
            insn.setLocation(location);
        }
    }

    @Override
    protected BakedRenderingPart actuallyBake(FunctionContext context) throws InvalidExpressionException {
        List<BakedInsn> args = new ArrayList<>();

        JsonRender element = image;

        context = new FunctionContext(context);

        BakedRender actualRender = element.bake(context);
        args.addAll(element.bakeInstructions(context));

        if (instructions != null) {
            for (JsonInsn insn : instructions) {
                args.add(insn.bake(context));
            }
        }

        BakedInsn[] instructions = args.toArray(new BakedInsn[args.size()]);