82327c1d |
1 | package net.encode.wurmesp.feature; |
2 | |
3 | import com.wurmonline.client.game.PlayerPosition; |
4 | import com.wurmonline.mesh.Tiles; |
5 | import java.awt.Color; |
6 | import java.util.logging.Level; |
7 | import java.util.logging.Logger; |
8 | import net.encode.wurmesp.WurmEspMod; |
9 | import net.encode.wurmesp.util.RenderUtils; |
10 | import net.encode.wurmesp.util.XrayColors; |
11 | |
12 | public class FeatureXRay |
13 | extends Feature { |
14 | @Override |
15 | public void refresh() { |
16 | if (!this.world.isOwnBodyAdded()) { |
17 | return; |
18 | } |
19 | WurmEspMod._terrain.clear(); |
20 | WurmEspMod._caveBuffer = this.world.getCaveBuffer(); |
21 | PlayerPosition pos = this.world.getPlayer().getPos(); |
22 | int px = pos.getTileX(); |
23 | int py = pos.getTileY(); |
24 | int size = WurmEspMod.xraydiameter; |
25 | int sx = px - size / 2; |
26 | int sy = py - size / 2; |
27 | float ox = this.world.getRenderOriginX(); |
28 | float oy = this.world.getRenderOriginY(); |
29 | for (int x = 0; x < size; ++x) { |
30 | for (int y = size - 1; y >= 0; --y) { |
31 | try { |
32 | int tileX = x + sx; |
33 | int tileY = y + sy; |
34 | Tiles.Tile tile = WurmEspMod._caveBuffer.getTileType(tileX, tileY); |
35 | if (tile == null || !tile.isOreCave()) continue; |
36 | Color color = XrayColors.getColorFor(tile); |
37 | float[] colorF = new float[]{(float)color.getRed() / 255.0f, (float)color.getGreen() / 255.0f, (float)color.getBlue() / 255.0f}; |
38 | float curX = (float)(tileX * 4) - ox; |
39 | float curY = (float)(tileY * 4) - oy; |
40 | float nextX = (float)((tileX + 1) * 4) - ox; |
41 | float nextY = (float)((tileY + 1) * 4) - oy; |
42 | float x0 = curX + 0.2f; |
43 | float y0 = curY + 0.2f; |
44 | float x1 = nextX - 0.2f; |
45 | float y1 = nextY - 0.2f; |
46 | WurmEspMod._terrain.add(new float[]{x0, y0, x1, y1, colorF[0], colorF[1], colorF[2]}); |
47 | continue; |
48 | } |
49 | catch (IllegalArgumentException | SecurityException ex) { |
50 | Logger.getLogger(FeatureXRay.class.getName()).log(Level.SEVERE, null, ex); |
51 | } |
52 | } |
53 | } |
54 | } |
55 | |
56 | @Override |
57 | public void queue() { |
58 | if (WurmEspMod._terrain == null) { |
59 | return; |
60 | } |
61 | WurmEspMod._terrain.stream().forEach(t -> { |
62 | float x0 = t[0]; |
63 | float y0 = t[1]; |
64 | float x1 = t[2]; |
65 | float y1 = t[3]; |
66 | |
67 | float[] color = new float[]{t[4],t[5],t[6], 1.0F}; |
68 | PlayerPosition pos = this.world.getPlayer().getPos(); |
69 | |
70 | float z0 = pos.getH(); |
71 | float z1 = z0 + 3; |
72 | |
73 | float[] vertexdata = new float[] { |
74 | x1, z0, y0, |
75 | x1, z1, y0, |
76 | x0, z1, y0, |
77 | x0, z0, y0, |
78 | x1, z0, y1, |
79 | x1, z1, y1, |
80 | x0, z1, y1, |
81 | x0, z0, y1 }; |
82 | |
83 | int[] indexdata = new int[] { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; |
84 | RenderUtils.renderPrimitiveLines(8, vertexdata, indexdata, this.queuePick, color); |
85 | }); |
86 | /* |
87 | if (!this.world.isOwnBodyAdded()) { |
88 | return; |
89 | } |
90 | WurmEspMod._terrain.clear(); |
91 | WurmEspMod._caveBuffer = this.world.getCaveBuffer(); |
92 | PlayerPosition pos = this.world.getPlayer().getPos(); |
93 | int px = pos.getTileX(); |
94 | int py = pos.getTileY(); |
95 | int size = WurmEspMod.xraydiameter; |
96 | int sx = px - size / 2; |
97 | int sy = py - size / 2; |
98 | WorldRender worldRenderer = (WorldRender)ReUtils.getField(this.world, "worldRenderer"); |
99 | CaveRender caveRenderer = (CaveRender)ReUtils.getField(worldRenderer, "caveRenderer"); |
100 | for (int x = 0; x < size; ++x) { |
101 | for (int y = size - 1; y >= 0; --y) { |
102 | try { |
103 | int tileX = x + sx; |
104 | int tileY = y + sy; |
105 | for (int side = 0; side < 7; ++side) { |
106 | IntBuffer intBuffer = IntBuffer.allocate(3); |
107 | intBuffer.put(tileX); |
108 | intBuffer.put(tileY); |
109 | intBuffer.put(side); |
110 | Class<HitNamesData> cls = HitNamesData.class; |
111 | Constructor<HitNamesData> constructor = cls.getDeclaredConstructor(IntBuffer.class, Integer.TYPE); |
112 | constructor.setAccessible(true); |
113 | HitNamesData hitNames = (HitNamesData)constructor.newInstance(intBuffer, 3); |
114 | caveRenderer.getPickedWall(hitNames).renderPicked(this.queuePick, RenderState.RENDERSTATE_DEFAULT, com.wurmonline.client.renderer.Color.GREEN); |
115 | } |
116 | continue; |
117 | } |
118 | catch (IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) { |
119 | Logger.getLogger(FeatureXRay.class.getName()).log(Level.SEVERE, null, ex); |
120 | } |
121 | } |
122 | }*/ |
123 | } |
124 | } |
125 | |