6
6
import net .minecraft .client .*;
7
7
import net .minecraft .client .util .math .*;
8
8
import net .minecraft .client .world .*;
9
+ import net .minecraft .entity .*;
9
10
import net .minecraft .util .*;
10
11
import net .minecraft .util .math .*;
11
12
import org .jgrapht .*;
18
19
@ Environment (EnvType .CLIENT )
19
20
public class ClientPastelNetworkManager implements PastelNetworkManager <ClientWorld , PastelNetwork <ClientWorld >>, Clearable {
20
21
22
+ protected static final int MAX_RENDER_DISTANCE_SQUARED = 48 * 48 ;
23
+
21
24
private final List <PastelNetwork <ClientWorld >> networks = new ArrayList <>();
22
25
23
26
@ Override
@@ -34,6 +37,13 @@ public PastelNetwork<ClientWorld> createNetwork(ClientWorld world, UUID uuid) {
34
37
35
38
public void renderLines (WorldRenderContext context ) {
36
39
MinecraftClient client = MinecraftClient .getInstance ();
40
+
41
+ Entity cameraEntity = client .cameraEntity ;
42
+ if (cameraEntity == null ) {
43
+ return ;
44
+ }
45
+ BlockPos cameraEntityPos = cameraEntity .getBlockPos ();
46
+
37
47
for (PastelNetwork <ClientWorld > network : this .networks ) {
38
48
if (network .getWorld ().getDimension () != context .world ().getDimension ()) continue ;
39
49
Graph <BlockPos , DefaultEdge > graph = network .getGraph ();
@@ -44,6 +54,11 @@ public void renderLines(WorldRenderContext context) {
44
54
BlockPos source = graph .getEdgeSource (edge );
45
55
BlockPos target = graph .getEdgeTarget (edge );
46
56
57
+ // do not render lines that are far away to save a few fps
58
+ if (cameraEntityPos .getSquaredDistance (source ) > MAX_RENDER_DISTANCE_SQUARED && cameraEntityPos .getSquaredDistance (target ) > MAX_RENDER_DISTANCE_SQUARED ) {
59
+ continue ;
60
+ }
61
+
47
62
final MatrixStack matrices = context .matrixStack ();
48
63
final Vec3d pos = context .camera ().getPos ();
49
64
matrices .push ();
@@ -70,4 +85,18 @@ public void clear() {
70
85
this .networks .clear ();
71
86
}
72
87
88
+ @ Override
89
+ public void removeNetwork (UUID uuid ) {
90
+ PastelNetwork <ClientWorld > foundNetwork = null ;
91
+ for (PastelNetwork <ClientWorld > network : this .networks ) {
92
+ if (network .uuid .equals (uuid )) {
93
+ foundNetwork = network ;
94
+ break ;
95
+ }
96
+ }
97
+ if (foundNetwork != null ) {
98
+ this .networks .remove (foundNetwork );
99
+ }
100
+ }
101
+
73
102
}
0 commit comments