Skip to content

Commit

Permalink
Fix #1 by disableing culling while in spectator, since in that mode w…
Browse files Browse the repository at this point in the history
…alls are kinda not a thing.

TODO: Could go through walls till it pops out of a wall and then cancel once it goes back into a wall, but this has to do for now.
  • Loading branch information
tr7zw committed Feb 23, 2021
1 parent b947d99 commit 990f7f5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/dev/tr7zw/entityculling/CullTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ public void run() {
Thread.sleep(sleepDelay);

if (client.world != null && client.player != null && client.player.age > 10) {
Vec3d camera = EntityCullingMod.instance.debug ? client.player.getCameraPosVec(client.getTickDelta())
Vec3d camera = EntityCullingMod.instance.debug
? client.player.getCameraPosVec(client.getTickDelta())
: client.gameRenderer.getCamera().getPos();
if (requestCull || !lastPos.equals(camera)) {
requestCull = false;
lastPos = camera;
culling.resetCache();
boolean spectator = client.player.isSpectator();
for (int x = -3; x <= 3; x++) {
for (int z = -3; z <= 3; z++) {
WorldChunk chunk = client.world.getChunk(client.player.chunkX + x,
client.player.chunkZ + z);
for (Entry<BlockPos, BlockEntity> entry : chunk.getBlockEntities().entrySet()) {
Cullable cullable = (Cullable) entry.getValue();
if (!cullable.isForcedVisible()) {
if (spectator) {
cullable.setCulled(false);
continue;
}
BlockPos pos = entry.getKey();
boolean visible = culling.isAABBVisible(
new Vec3d(pos.getX(), pos.getY(), pos.getZ()), blockAABB, camera,
Expand All @@ -59,14 +65,15 @@ public void run() {
while (iterable.hasNext()) {
try {
entity = iterable.next();
}catch(NullPointerException npe) {
break; // We are not synced to the main thread, so NPE's are allowed here and way less overhead probably
} catch (NullPointerException npe) {
break; // We are not synced to the main thread, so NPE's are allowed here and way less
// overhead probably than trying to sync stuff up for no really good reason
}
Cullable cullable = (Cullable) entity;
if (!cullable.isForcedVisible()) {
if(entity.isGlowing()) {
if (spectator || entity.isGlowing()) {
cullable.setCulled(false);
}else {
} else {
Box boundingBox = entity.getVisibilityBoundingBox();
boolean visible = culling.isAABBVisible(
new Vec3d(entity.getPos().getX(), entity.getPos().getY(),
Expand Down

0 comments on commit 990f7f5

Please sign in to comment.