Skip to content

Commit

Permalink
Use the camera for distance checks. Fix #153 and maybe #119
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed May 17, 2024
1 parent 6aa0f27 commit 20dc9f5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int
if (!SkinLayersModBase.config.enableSkulls)
return;
if (Minecraft.getInstance().player != null && livingEntity
.distanceToSqr(Minecraft.getInstance().player) > SkinLayersModBase.config.renderDistanceLOD
.distanceToSqr(Minecraft.getInstance().gameRenderer.getMainCamera().getPosition()) > SkinLayersModBase.config.renderDistanceLOD
* SkinLayersModBase.config.renderDistanceLOD) {
return; // too far away
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public void setModelProperties(AbstractClientPlayer abstractClientPlayer, Callba
this.addLayer(new CustomLayerFeatureRenderer(this));
loaded = true;
}
if (Minecraft.getInstance().player == null || Minecraft.getInstance().player
.distanceToSqr(abstractClientPlayer) > SkinLayersModBase.config.renderDistanceLOD
if (Minecraft.getInstance().player == null || abstractClientPlayer
.distanceToSqr(Minecraft.getInstance().gameRenderer.getMainCamera().getPosition()) > SkinLayersModBase.config.renderDistanceLOD
* SkinLayersModBase.config.renderDistanceLOD) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.phys.Vec3;
// spotless:off
//#if MC >= 11700
import net.minecraft.client.model.SkullModelBase;
Expand Down Expand Up @@ -55,11 +57,11 @@ public class SkullBlockEntityRendererMixin {
@Inject(method = "render", at = @At("HEAD"))
public void render(SkullBlockEntity skullBlockEntity, float f, PoseStack poseStack,
MultiBufferSource multiBufferSource, int i, int j, CallbackInfo info) {
LocalPlayer player = Minecraft.getInstance().player;
Vec3 camera = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
if (!SkinLayersModBase.config.enableSkulls)
return;
if (internalDistToCenterSqr(skullBlockEntity.getBlockPos(), (int) player.getX(), (int) player.getY(),
(int) player.getZ()) < SkinLayersModBase.config.renderDistanceLOD
if (internalDistToCenterSqr(skullBlockEntity.getBlockPos(), (int) camera.x(), (int) camera.y(),
(int) camera.z()) < SkinLayersModBase.config.renderDistanceLOD
* SkinLayersModBase.config.renderDistanceLOD) {
lastSkull = (SkullSettings) skullBlockEntity;
GameProfile gameProfile = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int
if (mc.level == null) {
return; // in a menu or something and the model gets rendered
}
if (mc.player.distanceToSqr(player) > SkinLayersModBase.config.renderDistanceLOD
if (player.distanceToSqr(mc.gameRenderer.getMainCamera().getPosition()) > SkinLayersModBase.config.renderDistanceLOD
* SkinLayersModBase.config.renderDistanceLOD)
return;

Expand Down

0 comments on commit 20dc9f5

Please sign in to comment.