/
MinerVisualRenderer.java
118 lines (95 loc) · 4.09 KB
/
MinerVisualRenderer.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
package mekanism.client.render;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer.DisplayInteger;
import mekanism.client.render.MekanismRenderer.Model3D;
import mekanism.common.tile.TileEntityDigitalMiner;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.init.Blocks;
public final class MinerVisualRenderer {
private static final double offset = 0.01;
private static Minecraft mc = Minecraft.getMinecraft();
private static Map<MinerRenderData, DisplayInteger> cachedVisuals = new HashMap<>();
public static void render(TileEntityDigitalMiner miner) {
MekanismRenderHelper renderHelper = new MekanismRenderHelper(true)
.translate(getX(miner.getPos().getX()), getY(miner.getPos().getY()), getZ(miner.getPos().getZ())).enableBlendPreset().enableGlow().enableCull().colorAlpha(0.8F);
mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
getList(new MinerRenderData(miner)).render();
renderHelper.cleanup();
}
private static DisplayInteger getList(MinerRenderData data) {
if (cachedVisuals.containsKey(data)) {
return cachedVisuals.get(data);
}
DisplayInteger display = DisplayInteger.createAndStart();
cachedVisuals.put(data, display);
List<Model3D> models = new ArrayList<>();
if (data.radius <= 64) {
for (int x = -data.radius; x <= data.radius; x++) {
for (int y = data.minY - data.yCoord; y <= data.maxY - data.yCoord; y++) {
for (int z = -data.radius; z <= data.radius; z++) {
if (x == -data.radius || x == data.radius || y == data.minY - data.yCoord || y == data.maxY - data.yCoord || z == -data.radius || z == data.radius) {
models.add(createModel(new Coord4D(x, y, z, mc.world.provider.getDimension())));
}
}
}
}
}
for (Model3D model : models) {
MekanismRenderer.renderObject(model);
}
DisplayInteger.endList();
return display;
}
private static Model3D createModel(Coord4D rel) {
Model3D toReturn = new Model3D();
toReturn.setBlockBounds(rel.x + 0.4, rel.y + 0.4, rel.z + 0.4, rel.x + 0.6, rel.y + 0.6, rel.z + 0.6);
toReturn.baseBlock = Blocks.WATER;
toReturn.setTexture(MekanismRenderer.getColorIcon(EnumColor.WHITE));
return toReturn;
}
private static double getX(int x) {
return x - TileEntityRendererDispatcher.staticPlayerX;
}
private static double getY(int y) {
return y - TileEntityRendererDispatcher.staticPlayerY;
}
private static double getZ(int z) {
return z - TileEntityRendererDispatcher.staticPlayerZ;
}
public static class MinerRenderData {
public int minY;
public int maxY;
public int radius;
public int yCoord;
public MinerRenderData(int min, int max, int rad, int y) {
minY = min;
maxY = max;
radius = rad;
yCoord = y;
}
public MinerRenderData(TileEntityDigitalMiner miner) {
this(miner.minY, miner.maxY, miner.getRadius(), miner.getPos().getY());
}
@Override
public boolean equals(Object data) {
return data instanceof MinerRenderData && ((MinerRenderData) data).minY == minY && ((MinerRenderData) data).maxY == maxY &&
((MinerRenderData) data).radius == radius && ((MinerRenderData) data).yCoord == yCoord;
}
@Override
public int hashCode() {
int code = 1;
code = 31 * code + minY;
code = 31 * code + maxY;
code = 31 * code + radius;
code = 31 * code + yCoord;
return code;
}
}
}