Skip to content

Commit 8fef2d0

Browse files
authored
Merge pull request #344 from Wyvest/main
cache `currentTimeMillis`
2 parents 5269dd5 + 09064e4 commit 8fef2d0

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎src/main/java/dev/tr7zw/entityculling/EntityCullingModBase.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public abstract class EntityCullingModBase extends EntityCullingVersionlessBase
3636
private int tickCounter = 0;
3737
public double lastTickTime = 0;
3838
private boolean freezeCamera = false;
39+
public static volatile long tickTimeMs = System.currentTimeMillis();
3940
// preallocation sizes, adding a small buffer to hopefully avoid any resizing during runtime
4041
private static final int PREALLOC_BUFFER = 10;
4142
private int lastEntityCount = 0;
@@ -77,6 +78,7 @@ private void requestCull() {
7778
}
7879

7980
public void clientTick() {
81+
tickTimeMs = System.currentTimeMillis();
8082
// late init
8183
if (!lateInit) {
8284
lateInit = true;

‎src/main/java/dev/tr7zw/entityculling/mixin/BlockEntityRenderDispatcherMixin.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void tryExtractRenderState(BlockEntity blockEntity, float partialTicks,
7474
return;
7575
}
7676
if (blockEntity instanceof Cullable cullable) {
77-
if (!cullable.isForcedVisible() && cullable.isCulled()) {
77+
if (cullable.isCulled() && !cullable.isForcedVisible()) {
7878
EntityCullingModBase.instance.skippedBlockEntities++;
7979
info.setReturnValue(null);
8080
if (EntityCullingModBase.instance.debugCollector.isRunning()) {
@@ -113,7 +113,7 @@ public <E extends BlockEntity> void render(E blockEntity, float f, com.mojang.bl
113113
return;
114114
}
115115
116-
if (!((Cullable) blockEntity).isForcedVisible() && ((Cullable) blockEntity).isCulled()) {
116+
if (((Cullable) blockEntity).isCulled() && !((Cullable) blockEntity).isForcedVisible()) {
117117
EntityCullingModBase.instance.skippedBlockEntities++;
118118
info.cancel();
119119
return;

‎src/main/java/dev/tr7zw/entityculling/mixin/CullableMixin.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.minecraft.world.phys.*;
66
import org.spongepowered.asm.mixin.Mixin;
77

8+
import dev.tr7zw.entityculling.EntityCullingModBase;
89
import dev.tr7zw.entityculling.versionless.EntityCullingVersionlessBase;
910
import dev.tr7zw.entityculling.access.Cullable;
1011
import net.minecraft.world.entity.Entity;
@@ -31,12 +32,12 @@ public class CullableMixin implements Cullable {
3132

3233
@Override
3334
public void setTimeout() {
34-
lasttime = System.currentTimeMillis() + 1000;
35+
lasttime = EntityCullingModBase.tickTimeMs + 1000;
3536
}
3637

3738
@Override
3839
public boolean isForcedVisible() {
39-
return lasttime > System.currentTimeMillis();
40+
return lasttime > EntityCullingModBase.tickTimeMs;
4041
}
4142

4243
@Override

‎src/main/java/dev/tr7zw/entityculling/mixin/WorldRendererMixin.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private void extractEntityRedir(Entity entity, float partialTick,
5151
return;
5252
}
5353
Cullable cullable = (Cullable) entity;
54-
if (!cullable.isForcedVisible() && cullable.isCulled() && !NMSCullingHelper.ignoresCulling(entity)) {
54+
if (cullable.isCulled() && !cullable.isForcedVisible() && !NMSCullingHelper.ignoresCulling(entity)) {
5555
EntityCullingModBase.instance.skippedEntities++;
5656
var state = new net.minecraft.client.renderer.entity.state.EntityRenderState();
5757

@@ -158,7 +158,7 @@ private void renderEntity(Entity entity, double cameraX, double cameraY, double
158158
return;
159159
}
160160
Cullable cullable = (Cullable) entity;
161-
if (!cullable.isForcedVisible() && cullable.isCulled() && !NMSCullingHelper.ignoresCulling(entity)) {
161+
if (cullable.isCulled() && !cullable.isForcedVisible() && !NMSCullingHelper.ignoresCulling(entity)) {
162162
if (this.entityCulling$entityRenderDispatcher.getRenderer(entity) instanceof net.minecraft.client.renderer.entity.EntityRenderer entityRenderer
163163
&& entityRenderer instanceof dev.tr7zw.entityculling.access.EntityRendererInter entityRendererInter) {
164164
if (EntityCullingModBase.instance.config.renderNametagsThroughWalls && matrices != null

0 commit comments

Comments
 (0)