-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipeRendererTESR.java
117 lines (92 loc) · 4.6 KB
/
PipeRendererTESR.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
/** 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.transport.client.render;
import com.google.common.base.Throwables;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.EnumFacing;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftCore.RenderMode;
import buildcraft.api.core.BCLog;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.pluggable.PipePluggable;
import buildcraft.transport.*;
import buildcraft.transport.client.model.PipeModelCacheWire;
import buildcraft.transport.client.model.PipeModelCacheWire.PipeWireKey;
public class PipeRendererTESR extends TileEntitySpecialRenderer<TileGenericPipe> {
public PipeRendererTESR() {}
@SuppressWarnings("unchecked")
@Override
public void renderTileEntityAt(TileGenericPipe pipe, double x, double y, double z, float f, int argumentthatisalwaysminusone) {
if (BuildCraftCore.render == RenderMode.NoDynamic) {
return;
}
if (pipe.pipe == null) return;
if (pipe.pipe.container == null) return;
Minecraft.getMinecraft().mcProfiler.startSection("bc");
Minecraft.getMinecraft().mcProfiler.startSection("pipe");
Minecraft.getMinecraft().mcProfiler.startSection("wire");
renderWire(pipe, x, y, z);
Minecraft.getMinecraft().mcProfiler.endStartSection("pluggable");
renderPluggables(pipe, x, y, z);
Minecraft.getMinecraft().mcProfiler.endStartSection("contents");
IPipeTile.PipeType pipeType = pipe.getPipeType();
try {
if (pipeType == IPipeTile.PipeType.ITEM) {
PipeRendererItems.renderItemPipe((Pipe<PipeTransportItems>) pipe.pipe, x, y, z, f);
} else if (pipeType == IPipeTile.PipeType.FLUID) {
PipeRendererFluids.renderFluidPipe((Pipe<PipeTransportFluids>) pipe.pipe, x, y, z);
} else if (pipeType == IPipeTile.PipeType.POWER) {
PipeRendererPower.renderPowerPipe((Pipe<PipeTransportPower>) pipe.pipe, x, y, z);
} /* else if (pipeType == PipeType.STRUCTURE) { // no object to render in a structure pipe; } */
} catch (Throwable t) {
BCLog.logger.warn("A crash! Oh no!", t);
throw Throwables.propagate(t);
} finally {
Minecraft.getMinecraft().mcProfiler.endSection();
Minecraft.getMinecraft().mcProfiler.endSection();
Minecraft.getMinecraft().mcProfiler.endSection();
}
}
private static void renderWire(TileGenericPipe pipe, double x, double y, double z) {
PipeWireKey key = new PipeWireKey(pipe.renderState);
RenderHelper.disableStandardItemLighting();
TileEntityRendererDispatcher.instance.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
PipeModelCacheWire.cacheAll.renderDisplayList(key);
GL11.glPopMatrix();
RenderHelper.enableStandardItemLighting();
}
private void renderPluggables(TileGenericPipe pipe, double x, double y, double z) {
TileEntityRendererDispatcher.instance.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
for (EnumFacing direction : EnumFacing.VALUES) {
PipePluggable pluggable = pipe.getPipePluggable(direction);
if (pluggable != null && pluggable.getDynamicRenderer() != null) {
pluggable.getDynamicRenderer().renderDynamicPluggable(pipe.getPipe(), direction, pluggable, x, y, z);
}
}
}
public boolean isOpenOrientation(PipeRenderState state, EnumFacing direction) {
int connections = 0;
EnumFacing targetOrientation = null;
for (EnumFacing o : EnumFacing.VALUES) {
if (state.pipeConnectionMatrix.isConnected(o)) {
connections++;
if (connections == 1) {
targetOrientation = o;
}
}
}
if (connections > 1 || targetOrientation == null) {
return false;
}
return targetOrientation.getOpposite() == direction;
}
}