Skip to content

Commit ee4fcbc

Browse files
committed
pastel network connections stop to render after a certain distance to save fps
1 parent 02a0cf6 commit ee4fcbc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/main/java/de/dafuqs/spectrum/blocks/pastel_network/network/ClientPastelNetworkManager.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.minecraft.client.*;
77
import net.minecraft.client.util.math.*;
88
import net.minecraft.client.world.*;
9+
import net.minecraft.entity.*;
910
import net.minecraft.util.*;
1011
import net.minecraft.util.math.*;
1112
import org.jgrapht.*;
@@ -18,6 +19,8 @@
1819
@Environment(EnvType.CLIENT)
1920
public class ClientPastelNetworkManager implements PastelNetworkManager<ClientWorld, PastelNetwork<ClientWorld>>, Clearable {
2021

22+
protected static final int MAX_RENDER_DISTANCE_SQUARED = 48 * 48;
23+
2124
private final List<PastelNetwork<ClientWorld>> networks = new ArrayList<>();
2225

2326
@Override
@@ -34,6 +37,13 @@ public PastelNetwork<ClientWorld> createNetwork(ClientWorld world, UUID uuid) {
3437

3538
public void renderLines(WorldRenderContext context) {
3639
MinecraftClient client = MinecraftClient.getInstance();
40+
41+
Entity cameraEntity = client.cameraEntity;
42+
if (cameraEntity == null) {
43+
return;
44+
}
45+
BlockPos cameraEntityPos = cameraEntity.getBlockPos();
46+
3747
for (PastelNetwork<ClientWorld> network : this.networks) {
3848
if (network.getWorld().getDimension() != context.world().getDimension()) continue;
3949
Graph<BlockPos, DefaultEdge> graph = network.getGraph();
@@ -44,6 +54,11 @@ public void renderLines(WorldRenderContext context) {
4454
BlockPos source = graph.getEdgeSource(edge);
4555
BlockPos target = graph.getEdgeTarget(edge);
4656

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+
4762
final MatrixStack matrices = context.matrixStack();
4863
final Vec3d pos = context.camera().getPos();
4964
matrices.push();
@@ -70,4 +85,18 @@ public void clear() {
7085
this.networks.clear();
7186
}
7287

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+
73102
}

0 commit comments

Comments
 (0)