summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/render/TessellatorWrapper.java
blob: c9937e4ba66f6814d10b49592ae3a5c5e74822ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package jp.plusplus.fbs.render;

import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;

/**
 * Created by plusplus_F on 2015/06/28.
 * なんで!!!てってれーたーには!!!!面描画メソッドが!!!!用意されてないんですか!!!!!1111
 */
public class TessellatorWrapper {
    private static Tessellator tessellator=Tessellator.instance;
    private static boolean isBlockRender;

    public static void SetBlockRender(boolean flag){
        isBlockRender=flag;
    }

    public static void DrawXPos(float bx, float by, float bz, float my, float mz, IIcon icon){
        float minU=icon.getInterpolatedU(16*bz);
        float maxU=icon.getInterpolatedU(16*mz);
        float minV=icon.getInterpolatedV(16*my);
        float maxV=icon.getInterpolatedV(16*by);

        if(isBlockRender){
            tessellator.setNormal(1.0f, 0.0f, 0.0f);
            tessellator.addVertexWithUV(bx, my, bz, minU, minV);
            tessellator.addVertexWithUV(bx, my, mz, maxU, minV);
            tessellator.addVertexWithUV(bx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, by, bz, minU, maxV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(1.0f, 0.0f, 0.0f);
            tessellator.addVertexWithUV(bx, my, bz, minU, minV);
            tessellator.addVertexWithUV(bx, my, mz, maxU, minV);
            tessellator.addVertexWithUV(bx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, by, bz, minU, maxV);
            tessellator.draw();
        }
    }
    public static void DrawXNeg(float bx, float by, float bz, float my, float mz, IIcon icon){
        float minU=icon.getInterpolatedU(16 * bz);
        float maxU=icon.getInterpolatedU(16 * mz);
        float minV=icon.getInterpolatedV(16 * my);
        float maxV=icon.getInterpolatedV(16 * by);

        if(isBlockRender){
            tessellator.setNormal(-1.0f, 0.0f, 0.0f);
            tessellator.addVertexWithUV(bx, my, bz, minU, minV);
            tessellator.addVertexWithUV(bx, by, bz, minU, maxV);
            tessellator.addVertexWithUV(bx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, my, mz, maxU, minV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(-1.0f, 0.0f, 0.0f);
            tessellator.addVertexWithUV(bx, my, bz, minU, minV);
            tessellator.addVertexWithUV(bx, by, bz, minU, maxV);
            tessellator.addVertexWithUV(bx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, my, mz, maxU, minV);
            tessellator.draw();
        }
    }

    public static void DrawYPos(float bx, float by, float bz, float mx, float mz, IIcon icon){
        float minU=icon.getInterpolatedU(16 * bx);
        float maxU=icon.getInterpolatedU(16 * mx);
        float minV=icon.getInterpolatedV(16 * bz);
        float maxV=icon.getInterpolatedV(16 * mz);

        if(isBlockRender){
            tessellator.setNormal(0.0f, 1.0f, 0.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(bx, by, mz, minU, maxV);
            tessellator.addVertexWithUV(mx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(0.0f, 1.0f, 0.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(bx, by, mz, minU, maxV);
            tessellator.addVertexWithUV(mx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.draw();
        }
    }
    public static void DrawYNeg(float bx, float by, float bz, float mx, float mz, IIcon icon){
        float minU=icon.getInterpolatedU(16 * bx);
        float maxU=icon.getInterpolatedU(16 * mx);
        float minV=icon.getInterpolatedV(16 * bz);
        float maxV=icon.getInterpolatedV(16 * mz);

        if(isBlockRender){
            tessellator.setNormal(0.0f,-1.0f,0.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.addVertexWithUV(mx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, by, mz, minU, maxV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(0.0f,-1.0f,0.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.addVertexWithUV(mx, by, mz, maxU, maxV);
            tessellator.addVertexWithUV(bx, by, mz, minU, maxV);
            tessellator.draw();
        }
    }

    public static void DrawZPos(float bx, float by, float bz, float mx, float my, IIcon icon){
        float minU=icon.getInterpolatedU(16 * bx);
        float maxU=icon.getInterpolatedU(16 * mx);
        float minV=icon.getInterpolatedV(16 * by);
        float maxV=icon.getInterpolatedV(16 * my);

        if(isBlockRender){
            tessellator.setNormal(0.0f,0.0f,1.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.addVertexWithUV(mx, my, bz, maxU, maxV);
            tessellator.addVertexWithUV(bx, my, bz, minU, maxV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(0.0f,0.0f,1.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.addVertexWithUV(mx, my, bz, maxU, maxV);
            tessellator.addVertexWithUV(bx, my, bz, minU, maxV);
            tessellator.draw();
        }
    }
    public static void DrawZNeg(float bx, float by, float bz, float mx, float my, IIcon icon){
        float minU=icon.getInterpolatedU(16*bx);
        float maxU=icon.getInterpolatedU(16*mx);
        float minV=icon.getInterpolatedV(16 * by);
        float maxV=icon.getInterpolatedV(16*my);

        if(isBlockRender){
            tessellator.setNormal(0.0f, 0.0f, -1.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(bx, my, bz, minU, maxV);
            tessellator.addVertexWithUV(mx, my, bz, maxU, maxV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
        }
        else{
            tessellator.startDrawingQuads();
            tessellator.setNormal(0.0f, 0.0f, -1.0f);
            tessellator.addVertexWithUV(bx, by, bz, minU, minV);
            tessellator.addVertexWithUV(bx, my, bz, minU, maxV);
            tessellator.addVertexWithUV(mx, my, bz, maxU, maxV);
            tessellator.addVertexWithUV(mx, by, bz, maxU, minV);
            tessellator.draw();
        }
    }

    public static void DrawAllFaces(float bx, float by, float bz, float mx, float my, float mz, IIcon icon) {
        DrawYNeg(bx, by, bz, mx, mz, icon);
        DrawYPos(bx, my, bz, mx, mz, icon);
        DrawZNeg(bx, by, bz, mx, my, icon);
        DrawZPos(bx, by, mz, mx, my, icon);
        DrawXNeg(bx, by, bz, my, mz, icon);
        DrawXPos(mx, by, bz, my, mz, icon);
    }

}