-
Notifications
You must be signed in to change notification settings - Fork 497
/
FacadeRenderHelper.java
224 lines (192 loc) · 8.29 KB
/
FacadeRenderHelper.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
/**
* 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.transport.render;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.render.ITextureStates;
import buildcraft.core.CoreConstants;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.FacadePluggable;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TransportConstants;
public final class FacadeRenderHelper {
private static final float zFightOffset = 1F / 4096F;
private static final float[][] zeroStateFacade = new float[3][2];
private static final float[][] zeroStateSupport = new float[3][2];
private static final float[] xOffsets = new float[6];
private static final float[] yOffsets = new float[6];
private static final float[] zOffsets = new float[6];
/**
* Deactivate constructor
*/
private FacadeRenderHelper() {
}
static {
// X START - END
zeroStateFacade[0][0] = 0.0F;
zeroStateFacade[0][1] = 1.0F;
// Y START - END
zeroStateFacade[1][0] = 0.0F;
zeroStateFacade[1][1] = TransportConstants.FACADE_THICKNESS;
// Z START - END
zeroStateFacade[2][0] = 0.0F;
zeroStateFacade[2][1] = 1.0F;
// X START - END
zeroStateSupport[0][0] = CoreConstants.PIPE_MIN_POS;
zeroStateSupport[0][1] = CoreConstants.PIPE_MAX_POS;
// Y START - END
zeroStateSupport[1][0] = TransportConstants.FACADE_THICKNESS;
zeroStateSupport[1][1] = CoreConstants.PIPE_MIN_POS;
// Z START - END
zeroStateSupport[2][0] = CoreConstants.PIPE_MIN_POS;
zeroStateSupport[2][1] = CoreConstants.PIPE_MAX_POS;
xOffsets[0] = zFightOffset;
xOffsets[1] = zFightOffset;
xOffsets[2] = 0;
xOffsets[3] = 0;
xOffsets[4] = 0;
xOffsets[5] = 0;
yOffsets[0] = 0;
yOffsets[1] = 0;
yOffsets[2] = zFightOffset;
yOffsets[3] = zFightOffset;
yOffsets[4] = 0;
yOffsets[5] = 0;
zOffsets[0] = zFightOffset;
zOffsets[1] = zFightOffset;
zOffsets[2] = 0;
zOffsets[3] = 0;
zOffsets[4] = 0;
zOffsets[5] = 0;
}
private static void setRenderBounds(RenderBlocks renderblocks, float[][] rotated, ForgeDirection side) {
renderblocks.setRenderBounds(
rotated[0][0] + xOffsets[side.ordinal()],
rotated[1][0] + yOffsets[side.ordinal()],
rotated[2][0] + zOffsets[side.ordinal()],
rotated[0][1] - xOffsets[side.ordinal()],
rotated[1][1] - yOffsets[side.ordinal()],
rotated[2][1] - zOffsets[side.ordinal()]);
}
public static void pipeFacadeRenderer(RenderBlocks renderblocks, ITextureStates blockStateMachine, TileGenericPipe tile, PipeRenderState state, int x, int y, int z) {
ITextureStates textureManager = blockStateMachine;
IIcon[] textures = ((TextureStateManager) textureManager.getTextureState()).popArray();
//block_statemachine.setRenderAllSides();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (!(tile.getPipePluggable(direction) instanceof FacadePluggable)) {
continue;
}
FacadePluggable pluggable = (FacadePluggable) tile.getPipePluggable(direction);
Block renderBlock = pluggable.getRenderingBlock();
if (renderBlock != null) {
// If the facade is meant to render in the current pass
if (renderBlock.canRenderInPass(PipeRendererWorld.renderPass)) {
int renderMeta = pluggable.getRenderingMeta();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
textures[side.ordinal()] = renderBlock.getIcon(side.ordinal(), renderMeta);
if (side == direction || side == direction.getOpposite()) {
blockStateMachine.setRenderSide(side, true);
} else {
if (!(tile.getPipePluggable(side) instanceof FacadePluggable)) {
blockStateMachine.setRenderSide(side, true);
} else {
FacadePluggable pluggable2 = (FacadePluggable) tile.getPipePluggable(side);
blockStateMachine.setRenderSide(side, pluggable2.getRenderingBlock() == null);
}
}
}
if (renderBlock.getRenderType() == 31) {
if ((renderMeta & 12) == 4) {
renderblocks.uvRotateEast = 1;
renderblocks.uvRotateWest = 1;
renderblocks.uvRotateTop = 1;
renderblocks.uvRotateBottom = 1;
} else if ((renderMeta & 12) == 8) {
renderblocks.uvRotateSouth = 1;
renderblocks.uvRotateNorth = 1;
}
}
BlockGenericPipe.facadeRenderColor = renderBlock.getRenderColor(renderMeta);
// Hollow facade
if (pluggable.isHollow()) {
renderblocks.field_152631_f = true;
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
rotated[2][0] = 0.0F;
rotated[2][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MIN_POS - zFightOffset * 4;
rotated[0][1] = CoreConstants.PIPE_MAX_POS + zFightOffset * 4;
rotated[2][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = 0.0F;
rotated[0][1] = CoreConstants.PIPE_MIN_POS - zFightOffset * 2;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
rotated = MatrixTranformations.deepClone(zeroStateFacade);
rotated[0][0] = CoreConstants.PIPE_MAX_POS + zFightOffset * 2;
rotated[0][1] = 1F;
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
renderblocks.field_152631_f = false;
} else { // Solid facade
float[][] rotated = MatrixTranformations.deepClone(zeroStateFacade);
MatrixTranformations.transform(rotated, direction);
setRenderBounds(renderblocks, rotated, direction);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
}
BlockGenericPipe.facadeRenderColor = -1;
if (renderBlock.getRenderType() == 31) {
renderblocks.uvRotateSouth = 0;
renderblocks.uvRotateEast = 0;
renderblocks.uvRotateWest = 0;
renderblocks.uvRotateNorth = 0;
renderblocks.uvRotateTop = 0;
renderblocks.uvRotateBottom = 0;
}
}
}
BlockGenericPipe.facadeRenderColor = -1;
}
((TextureStateManager) textureManager.getTextureState()).pushArray();
blockStateMachine.setRenderAllSides();
textureManager.getTextureState().set(BuildCraftTransport.instance.pipeIconProvider.getIcon(PipeIconProvider.TYPE.PipeStructureCobblestone.ordinal())); // Structure Pipe
// Always render connectors in pass 0
if (PipeRendererWorld.renderPass == 0) {
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (tile.getPipePluggable(direction) instanceof FacadePluggable) {
FacadePluggable pluggable = (FacadePluggable) tile.getPipePluggable(direction);
if (!pluggable.isHollow()) {
float[][] rotated = MatrixTranformations.deepClone(zeroStateSupport);
MatrixTranformations.transform(rotated, direction);
renderblocks.setRenderBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
renderblocks.renderStandardBlock(blockStateMachine.getBlock(), x, y, z);
}
}
}
}
}
}