-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipeTransportRendererPower.java
159 lines (131 loc) · 6.12 KB
/
PipeTransportRendererPower.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
package buildcraft.transport.client.render;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumFacing.AxisDirection;
import net.minecraft.util.Vec3;
import buildcraft.core.lib.EntityResizableCuboid;
import buildcraft.core.lib.client.render.RenderResizableCuboid;
import buildcraft.core.lib.client.render.RenderUtils;
import buildcraft.core.lib.utils.Utils;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportPower;
public class PipeTransportRendererPower extends PipeTransportRenderer<PipeTransportPower> {
/** The number of pixels the power moves by per millisecond */
public static final double FLOW_MULTIPLIER = 0.048;
public static final short POWER_STAGES = PipeTransportPower.POWER_STAGES;
@Override
public void render(Pipe<PipeTransportPower> pipe, double x, double y, double z, float f) {
PipeTransportPower pow = pipe.transport;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GlStateManager.disableLighting();
// GL11.glEnable(GL11.GL_BLEND);
GL11.glTranslatef((float) x, (float) y, (float) z);
Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture);
// Used for the centre rendering
short centerPower = 0;
short[] power = pow.displayPower;
short[] flow = pow.displayFlow;
for (int i = 0; i < 6; i++) {
short d = power[i];
if (d > centerPower) {
centerPower = d;
}
}
if (centerPower > 0) {
long ms = System.currentTimeMillis();
long diff = ms - pow.clientLastDisplayTime;
if (pow.clientLastDisplayTime == 0 || diff <= 0) {
diff = 1;
}
pow.clientLastDisplayTime = ms;
for (int i = 0; i < 6; i++) {
EnumFacing face = EnumFacing.values()[i];
if (!pipe.getTile().isPipeConnected(face)) {
continue;
}
double actualDiff = flow[i] * diff * FLOW_MULTIPLIER;
double connectionDiff = face.getAxisDirection() == AxisDirection.POSITIVE ? actualDiff : -actualDiff;
pow.clientDisplayFlow[i] += connectionDiff;
while (pow.clientDisplayFlow[i] < 0) {
pow.clientDisplayFlow[i] += 16;
}
while (pow.clientDisplayFlow[i] > 16) {
pow.clientDisplayFlow[i] -= 16;
}
pow.clientDisplayFlowCentre = pow.clientDisplayFlowCentre.add(Utils.convert(face, actualDiff / 2));
renderSidePower(face, power[i], pow.clientDisplayFlow[i], centerPower);
}
for (Axis axis : Axis.values()) {
double value = Utils.getValue(pow.clientDisplayFlowCentre, axis);
while (value < 0) {
value += 16;
}
while (value > 16) {
value -= 16;
}
pow.clientDisplayFlowCentre = Utils.withValue(pow.clientDisplayFlowCentre, axis, value);
}
renderCenterPower(centerPower, pow.clientDisplayFlowCentre);
}
GlStateManager.enableLighting();
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private static void renderSidePower(EnumFacing face, short stage, double flow, short centerStage) {
if (stage <= 0) {
return;
}
double width = 0.5 * stage / (double) POWER_STAGES;
double centerRadius = 0.25 * centerStage / (double) POWER_STAGES;
Vec3 center = Utils.VEC_HALF.add(Utils.convert(face, 0.25 + centerRadius / 2d));
face = Utils.convertPositive(face);
Vec3 size = Utils.VEC_ONE.subtract(Utils.convert(face));
size = Utils.multiply(size, width);
size = size.add(Utils.convert(face, 0.5 - centerRadius));
EntityResizableCuboid cuboid = new EntityResizableCuboid(null);
cuboid.setSize(size);
cuboid.texture = PipeIconProvider.TYPE.Power_Normal.getIcon();
cuboid.makeClient();
double offsetNonFlow = 0;// 8 - textureWidth / 2;
double offsetFlow = flow;
Vec3 textureOffset = new Vec3(offsetNonFlow, offsetNonFlow, offsetNonFlow);
textureOffset = textureOffset.add(Utils.convert(face, -offsetNonFlow));
textureOffset = textureOffset.add(Utils.convert(face, offsetFlow));
cuboid.textureOffsetX = textureOffset.xCoord;
cuboid.textureOffsetY = textureOffset.yCoord;
cuboid.textureOffsetZ = textureOffset.zCoord;
GL11.glPushMatrix();
RenderUtils.translate(center);
// Tessellator.getInstance().getWorldRenderer().setBrightness(0xFFFFFFFF);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 0xF0, 0xF0);
RenderResizableCuboid.INSTANCE.renderCubeFromCentre(cuboid);
GL11.glPopMatrix();
}
private static void renderCenterPower(short stage, Vec3 centerFlow) {
if (stage <= 0) {
return;
}
double width = 0.5 * stage / (double) POWER_STAGES;
Vec3 size = new Vec3(width, width, width);
Vec3 pos = Utils.VEC_HALF;
EntityResizableCuboid erc = new EntityResizableCuboid(null);
erc.setSize(size);
erc.texture = PipeIconProvider.TYPE.Power_Normal.getIcon();
erc.textureOffsetX = centerFlow.xCoord;
erc.textureOffsetY = centerFlow.yCoord;
erc.textureOffsetZ = centerFlow.zCoord;
GL11.glPushMatrix();
RenderUtils.translate(pos);
// Tessellator.getInstance().getWorldRenderer().setBrightness(0xFFFFFFFF);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 0xF0, 0xF0);
RenderResizableCuboid.INSTANCE.renderCubeFromCentre(erc);
GL11.glPopMatrix();
}
}