package codechicken.lib.render.pipeline;

import codechicken.lib.colour.ColourRGBA;
import codechicken.lib.render.CCRenderState;

public class ColourMultiplier implements IVertexOperation {

    private static ColourMultiplier instance = new ColourMultiplier(-1);

    public static ColourMultiplier instance(int colour) {
        instance.colour = colour;
        return instance;
    }

    public static final int operationIndex = CCRenderState.registerOperation();
    public int colour;

    public ColourMultiplier(int colour) {
        this.colour = colour;
    }

    @Override
    public boolean load(CCRenderState state) {
        if (colour == -1) {
            return false;
        }

        state.pipeline.addDependency(state.colourAttrib);
        return true;
    }

    @Override
    public void operate(CCRenderState state) {
        state.colour = ColourRGBA.multiply(state.colour, colour);
    }

    @Override
    public int operationID() {
        return operationIndex;
    }
}

@@ -195,32 +195,44 @@
  private static 
+ThreadLocal%3C
 ColourMultiplier
@@ -223,32 +223,33 @@
 ColourMultiplier
+%3E
  instance = new 
@@ -241,18 +241,49 @@
 instance
+s
  =
+ ThreadLocal.withInitial(() -%3E
  new Col
@@ -299,16 +299,17 @@
 lier(-1)
+)
 ;%0A%0A    p
@@ -353,32 +353,85 @@
 e(int colour) %7B%0A
+        ColourMultiplier instance = instances.get();%0A
         instance

Fix concurrency issues with ColourMultiplier