1 package com.irtimaled.bbor.client.renderers;
3 import com.irtimaled.bbor.client.Camera;
4 import net.minecraft.client.render.BufferBuilder;
5 import net.minecraft.client.render.Tessellator;
6 import net.minecraft.client.render.VertexFormat;
7 import net.minecraft.client.render.VertexFormats;
8 import net.minecraft.client.util.math.MatrixStack;
12 public class Renderer {
13 private final VertexFormat.DrawMode glMode;
15 static Renderer startLines() {
16 return new Renderer(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR);
19 static Renderer startLineLoop() {
20 return new Renderer(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
23 public static Renderer startQuads() {
24 return new Renderer(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
27 public static Renderer startTextured() {
28 return new Renderer(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
31 private static final Tessellator tessellator = Tessellator.getInstance();
32 private static final BufferBuilder bufferBuilder = tessellator.getBuffer();
38 private MatrixStack matrixStack;
40 private Renderer(VertexFormat.DrawMode glMode, VertexFormat vertexFormat) {
41 bufferBuilder.begin(glMode, vertexFormat);
45 public Renderer setMatrixStack(MatrixStack stack) {
46 this.matrixStack = stack;
51 public Renderer setColor(Color color) {
52 return setColor(color.getRed(), color.getGreen(), color.getBlue())
53 .setAlpha(color.getAlpha());
56 public Renderer setColor(int red, int green, int blue) {
63 public Renderer setAlpha(int alpha) {
68 Renderer addPoint(OffsetPoint point) {
69 return addPoint(point.getX(), point.getY(), point.getZ());
72 public Renderer addPoints(OffsetPoint[] points) {
73 Renderer renderer = this;
74 for (OffsetPoint point : points) {
75 renderer = renderer.addPoint(point);
80 public Renderer addPoint(double x, double y, double z) {
89 public Renderer addPoint(double x, double y, double z, double u, double v) {
97 public void render() {
98 if (glMode == VertexFormat.DrawMode.QUADS) {
99 bufferBuilder.setCameraPosition((float) Camera.getX(), (float) Camera.getY(), (float) Camera.getZ());
105 private void pos(double x, double y, double z) {
106 bufferBuilder.vertex(matrixStack.peek().getModel(), (float) x, (float) y, (float) z);
109 private void tex(double u, double v) {
110 bufferBuilder.texture((float) u, (float) v);
113 private void color() {
114 bufferBuilder.color(red / 255F, green / 255F, blue / 255F, alpha / 255F);
118 bufferBuilder.next();