-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderEntityBlock.java
284 lines (227 loc) · 7.71 KB
/
RenderEntityBlock.java
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.render;
import java.util.Arrays;
import org.lwjgl.opengl.GL11;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import buildcraft.core.EntityBlock;
public final class RenderEntityBlock extends Render {
public static RenderEntityBlock INSTANCE = new RenderEntityBlock();
protected RenderBlocks renderBlocks;
private RenderEntityBlock() {
renderBlocks = field_147909_c;
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
throw new UnsupportedOperationException("Not supported yet.");
}
public static class RenderInfo {
public double minX;
public double minY;
public double minZ;
public double maxX;
public double maxY;
public double maxZ;
public Block baseBlock = Blocks.sand;
public IIcon texture = null;
public IIcon[] textureArray = null;
public boolean[] renderSide = new boolean[6];
public float light = -1f;
public int brightness = -1;
public RenderInfo() {
setRenderAllSides();
}
public RenderInfo(Block template, IIcon[] texture) {
this();
this.baseBlock = template;
this.textureArray = texture;
}
public RenderInfo(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
this();
setBounds(minX, minY, minZ, maxX, maxY, maxZ);
}
public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k) {
return baseBlock.getMixedBrightnessForBlock(iblockaccess, i, j, k);
}
public final void setBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
}
public final void setRenderSingleSide(int side) {
Arrays.fill(renderSide, false);
renderSide[side] = true;
}
public final void setRenderAllSides() {
Arrays.fill(renderSide, true);
}
public void rotate() {
double temp = minX;
minX = minZ;
minZ = temp;
temp = maxX;
maxX = maxZ;
maxZ = temp;
}
public void reverseX() {
double temp = minX;
minX = 1 - maxX;
maxX = 1 - temp;
}
public void reverseZ() {
double temp = minZ;
minZ = 1 - maxZ;
maxZ = 1 - temp;
}
public IIcon getBlockTextureFromSide(int i) {
if (texture != null) {
return texture;
}
int index = i;
if (textureArray == null || textureArray.length == 0) {
return baseBlock.getBlockTextureFromSide(index);
} else {
if (index >= textureArray.length) {
index = 0;
}
return textureArray[index];
}
}
}
@Override
public void doRender(Entity entity, double i, double j, double k, float f, float f1) {
doRenderBlock((EntityBlock) entity, i, j, k);
}
public void doRenderBlock(EntityBlock entity, double i, double j, double k) {
if (entity.isDead) {
return;
}
shadowSize = entity.shadowSize;
World world = entity.worldObj;
RenderInfo util = new RenderInfo();
util.texture = entity.texture;
bindTexture(TextureMap.locationBlocksTexture);
for (int iBase = 0; iBase < entity.iSize; ++iBase) {
for (int jBase = 0; jBase < entity.jSize; ++jBase) {
for (int kBase = 0; kBase < entity.kSize; ++kBase) {
util.minX = 0;
util.minY = 0;
util.minZ = 0;
double remainX = entity.iSize - iBase;
double remainY = entity.jSize - jBase;
double remainZ = entity.kSize - kBase;
util.maxX = remainX > 1.0 ? 1.0 : remainX;
util.maxY = remainY > 1.0 ? 1.0 : remainY;
util.maxZ = remainZ > 1.0 ? 1.0 : remainZ;
GL11.glPushMatrix();
GL11.glTranslatef((float) i, (float) j, (float) k);
GL11.glRotatef(entity.rotationX, 1, 0, 0);
GL11.glRotatef(entity.rotationY, 0, 1, 0);
GL11.glRotatef(entity.rotationZ, 0, 0, 1);
GL11.glTranslatef(iBase, jBase, kBase);
int lightX, lightY, lightZ;
lightX = (int) (Math.floor(entity.posX) + iBase);
lightY = (int) (Math.floor(entity.posY) + jBase);
lightZ = (int) (Math.floor(entity.posZ) + kBase);
GL11.glDisable(2896 /* GL_LIGHTING */);
renderBlock(util, world, 0, 0, 0, lightX, lightY, lightZ, false, true);
GL11.glEnable(2896 /* GL_LIGHTING */);
GL11.glPopMatrix();
}
}
}
}
public void renderBlock(RenderInfo info, IBlockAccess blockAccess, int x, int y, int z, boolean doLight, boolean doTessellating) {
renderBlock(info, blockAccess, x, y, z, x, y, z, doLight, doTessellating);
}
public void renderBlock(RenderInfo info, IBlockAccess blockAccess, double x, double y, double z, int lightX, int lightY, int lightZ, boolean doLight, boolean doTessellating) {
float lightBottom = 0.5F;
float lightTop = 1.0F;
float lightEastWest = 0.8F;
float lightNorthSouth = 0.6F;
Tessellator tessellator = Tessellator.instance;
boolean realDoLight = doLight;
if (blockAccess == null) {
realDoLight = false;
}
if (doTessellating)
tessellator.startDrawingQuads();
float light = 0;
if (realDoLight) {
if (info.light < 0) {
light = info.baseBlock.getMixedBrightnessForBlock(blockAccess, lightX, lightY, lightZ);
light = light + ((1.0f - light) * 0.4f);
} else {
light = info.light;
}
int brightness = 0;
if (info.brightness < 0) {
brightness = info.baseBlock.getMixedBrightnessForBlock(blockAccess, lightX, lightY, lightZ);
} else {
brightness = info.brightness;
}
tessellator.setBrightness(brightness);
tessellator.setColorOpaque_F(lightBottom * light, lightBottom * light, lightBottom * light);
} else {
// tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
if (info.brightness >= 0) {
tessellator.setBrightness(info.brightness);
}
}
renderBlocks.setRenderBounds(info.minX, info.minY, info.minZ, info.maxX, info.maxY, info.maxZ);
if (info.renderSide[0]) {
renderBlocks.renderFaceYNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(0));
}
if (realDoLight) {
tessellator.setColorOpaque_F(lightTop * light, lightTop * light, lightTop * light);
}
if (info.renderSide[1]) {
renderBlocks.renderFaceYPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(1));
}
if (realDoLight) {
tessellator.setColorOpaque_F(lightEastWest * light, lightEastWest * light, lightEastWest * light);
}
if (info.renderSide[2]) {
renderBlocks.renderFaceZNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(2));
}
if (realDoLight) {
tessellator.setColorOpaque_F(lightEastWest * light, lightEastWest * light, lightEastWest * light);
}
if (info.renderSide[3]) {
renderBlocks.renderFaceZPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(3));
}
if (realDoLight) {
tessellator.setColorOpaque_F(lightNorthSouth * light, lightNorthSouth * light, lightNorthSouth * light);
}
if (info.renderSide[4]) {
renderBlocks.renderFaceXNeg(info.baseBlock, x, y, z, info.getBlockTextureFromSide(4));
}
if (realDoLight) {
tessellator.setColorOpaque_F(lightNorthSouth * light, lightNorthSouth * light, lightNorthSouth * light);
}
if (info.renderSide[5]) {
renderBlocks.renderFaceXPos(info.baseBlock, x, y, z, info.getBlockTextureFromSide(5));
}
if (doTessellating)
tessellator.draw();
}
}