82327c1d |
1 | package net.encode.wurmesp.feature; |
2 | |
3 | import com.wurmonline.client.game.PlayerPosition; |
4 | import net.encode.wurmesp.WurmEspMod; |
5 | import net.encode.wurmesp.util.RenderUtils; |
6 | import net.encode.wurmesp.util.TerrainUtils; |
7 | |
8 | public class FeatureTilesCloseBy |
9 | extends Feature { |
10 | @Override |
11 | public void refresh() { |
12 | WurmEspMod._closeByTerrain.clear(); |
13 | WurmEspMod._terrainBuffer = this.world.getNearTerrainBuffer(); |
14 | PlayerPosition pos = this.world.getPlayer().getPos(); |
15 | int px = pos.getTileX(); |
16 | int py = pos.getTileY(); |
17 | int size = 6; |
18 | int sx = px - size / 2; |
19 | int sy = py - size / 2; |
20 | float ox = this.world.getRenderOriginX(); |
21 | float oy = this.world.getRenderOriginY(); |
22 | for (int x = 0; x < size + 1; ++x) { |
23 | for (int y = 0; y < size + 1; ++y) { |
24 | float tileX = x + sx; |
25 | float tileY = y + sy; |
26 | float curX = tileX * 4.0f - ox; |
27 | float curY = tileY * 4.0f - oy; |
28 | float nextX = (tileX + 1.0f) * 4.0f - ox; |
29 | float nextY = (tileY + 1.0f) * 4.0f - oy; |
30 | float x0 = curX + 0.1f; |
31 | float y0 = curY + 0.1f; |
32 | float x1 = nextX - 0.1f; |
33 | float y1 = nextY - 0.1f; |
34 | float z0 = WurmEspMod._terrainBuffer.getHeight((int)tileX, (int)tileY); |
35 | float z1 = WurmEspMod._terrainBuffer.getHeight((int)tileX + 1, (int)tileY); |
36 | float z2 = WurmEspMod._terrainBuffer.getHeight((int)tileX, (int)tileY + 1); |
37 | float z3 = WurmEspMod._terrainBuffer.getHeight((int)tileX + 1, (int)tileY + 1); |
38 | WurmEspMod._closeByTerrain.add(new float[]{x0, z0, y0, x1, z1, y0, x0, z2, y1, x1, z3, y1}); |
39 | } |
40 | } |
41 | } |
42 | |
43 | @Override |
44 | public void queue() { |
45 | if (WurmEspMod._closeByTerrain == null) { |
46 | return; |
47 | } |
48 | WurmEspMod._closeByTerrain.forEach(t -> { |
49 | float[] color = TerrainUtils.isFlat(t) ? new float[]{0.0f, 1.0f, 0.0f, 0.5f} : new float[]{1.0f, 1.0f, 0.0f, 0.5f}; |
50 | int[] indexdata = new int[]{1, 0, 0, 2, 2, 3, 3, 1}; |
51 | RenderUtils.renderPrimitiveLines(4, t, indexdata, this.queuePick, color); |
52 | }); |
53 | } |
54 | } |
55 | |