package codechicken.lib.render;

import codechicken.lib.colour.Colour;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;

/**
 * Created by covers1624 on 15/01/2017.
 * TODO, Maybe merge with CCRS??
 */
public class CCRSConsumer implements IVertexConsumer {

    private final CCRenderState ccrs;
    private BlockPos offset = BlockPos.ORIGIN;

    public CCRSConsumer(CCRenderState ccrs) {
        this.ccrs = ccrs;
    }

    @Override
    public VertexFormat getVertexFormat() {
        return ccrs.getVertexFormat();
    }

    @Override
    public void setTexture(TextureAtlasSprite texture) {
        ccrs.sprite = texture;
    }

    @Override
    public void put(int e, float... data) {
        VertexFormat format = getVertexFormat();

        VertexFormatElement fmte = format.getElement(e);
        switch (fmte.getUsage()) {
            case POSITION:
                ccrs.vert.vec.set(data).add(offset);
                break;
            case UV:
                if (fmte.getIndex() == 0) {
                    ccrs.vert.uv.set(data[0], data[1]);
                } else {
                    ccrs.brightness = (int) (data[1] * 65535 / 32) << 20 | (int) (data[0] * 65535 / 32) << 4;
                }
                break;
            case COLOR:
                ccrs.colour = Colour.packRGBA(data);
                break;
            case NORMAL:
                ccrs.normal.set(data);
                break;
            case PADDING:
                break;
            default:
                throw new UnsupportedOperationException("Generic vertex format element");
        }
        if (e == format.getElementCount() - 1) {
            ccrs.writeVert();
        }
    }

    public void setOffset(BlockPos offset) {
        this.offset = new BlockPos(offset);
    }

    @Override
    public void setQuadTint(int tint) {
    }

    @Override
    public void setQuadOrientation(EnumFacing orientation) {
    }

    @Override
    public void setApplyDiffuseLighting(boolean diffuse) {
    }
}

@@ -64,16 +64,52 @@
 Colour;%0A
+import codechicken.lib.vec.Vector3;%0A
 import n
@@ -620,24 +620,23 @@
 private 
-BlockPos
+Vector3
  offset 
@@ -641,23 +641,20 @@
 t = 
-BlockPos.ORIGIN
+Vector3.zero
 ;%0A%0A 
@@ -1993,24 +1993,105 @@
    %7D%0A    %7D%0A%0A
+    public void setOffset(Vector3 offset) %7B%0A        this.offset = offset;%0A    %7D%0A%0A
     public v
@@ -2145,20 +2145,28 @@
 ffset = 
-new 
+Vector3.from
 BlockPos

Move CCRSConsumer to a Vector3 offset backend.