forked from BynBang/OpenPrestige
fixed bugs, memory leaks, etc
This commit is contained in:
1 parent
aa4f6b6ddc
commit
c3f8f23c1d
124 files changed
+1060
-420
No files matched your search
@@ -62,6 +62,7 @@ public class OreSimulation extends Module {
|
||||
private RegistryKey cachedDimension;
|
||||
private ClientWorld cachedWorld;
|
||||
private Frustum frustum;
|
||||
private long lastPrune;
|
||||
|
||||
@Subscribe
|
||||
public void onRender3D(Render3DEvent event) {
|
||||
@@ -69,6 +70,7 @@ public class OreSimulation extends Module {
|
||||
int centerChunkX = mc.player.getChunkPos().x;
|
||||
int centerChunkZ = mc.player.getChunkPos().z;
|
||||
int radius = this.chunks.getValue();
|
||||
this.pruneUnloadedChunks();
|
||||
|
||||
for (int ring = 0; ring <= radius; ring++) {
|
||||
for (int chunkX = -ring + centerChunkX; chunkX <= ring + centerChunkX; chunkX++) {
|
||||
@@ -82,6 +84,23 @@ public class OreSimulation extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
// Drops simulated ores of chunks that are no longer loaded so the cache cannot grow without bound.
|
||||
private void pruneUnloadedChunks() {
|
||||
long now = System.currentTimeMillis();
|
||||
ClientWorld world = mc.world;
|
||||
if (world == null || now - this.lastPrune < 5000L) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastPrune = now;
|
||||
RegistryKey dimension = world.getRegistryKey();
|
||||
this.chunkOres.keySet().removeIf(key -> {
|
||||
DimensionChunkKey chunkKey = (DimensionChunkKey)key;
|
||||
return !chunkKey.dimension().equals(dimension)
|
||||
|| world.getChunk(ChunkPos.getPackedX(chunkKey.chunkPos()), ChunkPos.getPackedZ(chunkKey.chunkPos()), ChunkStatus.FULL, false) == null;
|
||||
});
|
||||
}
|
||||
|
||||
private void renderChunk(Render3DEvent event, int chunkX, int chunkZ) {
|
||||
if (this.frustum == null || this.frustum.isVisible(new Box(chunkX << 4, -64.0, chunkZ << 4, (chunkX << 4) + 16, 320.0, (chunkZ << 4) + 16))) {
|
||||
ClientWorld world = mc.world;
|
||||
|
||||
Reference in new issue
Block a user