-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderEntityBlock.java
199 lines (159 loc) · 5.38 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
/**
* Copyright (c) SpaceToad, 2011 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 buildcraft.core.EntityBlock;
import net.minecraft.block.Block;
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.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class RenderEntityBlock extends Render {
public static RenderEntityBlock INSTANCE = new RenderEntityBlock();
@Override
protected ResourceLocation func_110775_a(Entity entity) {
throw new UnsupportedOperationException("Not supported yet.");
}
public static class BlockInterface {
public double minX;
public double minY;
public double minZ;
public double maxX;
public double maxY;
public double maxZ;
public Block baseBlock = Block.sand;
public Icon texture = null;
public Icon getBlockTextureFromSide(int i) {
if (texture == null)
return baseBlock.getBlockTextureFromSide(i);
else
return texture;
}
public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k) {
return baseBlock.getBlockBrightness(iblockaccess, i, j, k);
}
}
private RenderEntityBlock() {
}
@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;
BlockInterface util = new BlockInterface();
util.texture = entity.texture;
func_110776_a(TextureMap.field_110575_b);
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, lightX, lightY, lightZ, false, true);
GL11.glEnable(2896 /* GL_LIGHTING */);
GL11.glPopMatrix();
}
}
}
}
public void renderBlock(BlockInterface block, IBlockAccess blockAccess, int i, int j, int k, boolean doLight, boolean doTessellating) {
float f = 0.5F;
float f1 = 1.0F;
float f2 = 0.8F;
float f3 = 0.6F;
renderBlocks.renderMaxX = block.maxX;
renderBlocks.renderMinX = block.minX;
renderBlocks.renderMaxY = block.maxY;
renderBlocks.renderMinY = block.minY;
renderBlocks.renderMaxZ = block.maxZ;
renderBlocks.renderMinZ = block.minZ;
renderBlocks.enableAO = false;
Tessellator tessellator = Tessellator.instance;
if (doTessellating) {
tessellator.startDrawingQuads();
}
float f4 = 0, f5 = 0;
if (doLight) {
f4 = block.getBlockBrightness(blockAccess, i, j, k);
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f * f5, f * f5, f * f5);
}
renderBlocks.renderFaceYNeg(null, 0, 0, 0, block.getBlockTextureFromSide(0));
if (doLight) {
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f1 * f5, f1 * f5, f1 * f5);
}
renderBlocks.renderFaceYPos(null, 0, 0, 0, block.getBlockTextureFromSide(1));
if (doLight) {
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
}
renderBlocks.renderFaceZNeg(null, 0, 0, 0, block.getBlockTextureFromSide(2));
if (doLight) {
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
}
renderBlocks.renderFaceZPos(null, 0, 0, 0, block.getBlockTextureFromSide(3));
if (doLight) {
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
}
renderBlocks.renderFaceXNeg(null, 0, 0, 0, block.getBlockTextureFromSide(4));
if (doLight) {
f5 = block.getBlockBrightness(blockAccess, i, j, k);
if (f5 < f4) {
f5 = f4;
}
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
}
renderBlocks.renderFaceXPos(null, 0, 0, 0, block.getBlockTextureFromSide(5));
if (doTessellating) {
tessellator.draw();
}
}
}