-
Notifications
You must be signed in to change notification settings - Fork 497
/
RenderEntityBlock.java
213 lines (175 loc) · 5.58 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
/**
* Copyright (c) 2011-2015, 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 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 x, double y, double z, float f, float f1) {
doRenderBlock((EntityBlock) entity, x, y, z);
}
public void doRenderBlock(EntityBlock entity, double x, double y, double z) {
if (entity.isDead) {
return;
}
shadowSize = entity.shadowSize;
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) x, (float) y, (float) z);
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);
renderBlock(util);
GL11.glPopMatrix();
}
}
}
}
public void renderBlock(RenderInfo info) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
renderBlocks.setRenderBounds(info.minX, info.minY, info.minZ, info.maxX, info.maxY, info.maxZ);
if (info.renderSide[0]) {
tessellator.setNormal(0, -1, 0);
renderBlocks.renderFaceYNeg(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(0));
}
if (info.renderSide[1]) {
tessellator.setNormal(0, 1, 0);
renderBlocks.renderFaceYPos(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(1));
}
if (info.renderSide[2]) {
tessellator.setNormal(0, 0, -1);
renderBlocks.renderFaceZNeg(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(2));
}
if (info.renderSide[3]) {
tessellator.setNormal(0, 0, 1);
renderBlocks.renderFaceZPos(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(3));
}
if (info.renderSide[4]) {
tessellator.setNormal(-1, 0, 0);
renderBlocks.renderFaceXNeg(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(4));
}
if (info.renderSide[5]) {
tessellator.setNormal(1, 0, 0);
renderBlocks.renderFaceXPos(info.baseBlock, 0, 0, 0, info.getBlockTextureFromSide(5));
}
tessellator.draw();
}
}