Skip to content

Commit

Permalink
Fix Show Player
Browse files Browse the repository at this point in the history
  • Loading branch information
hashalite committed Jul 13, 2023
1 parent b2f6429 commit 5fc28c7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/main/java/net/xolt/freecam/mixins/WorldRendererMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package net.xolt.freecam.mixins;


import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.xolt.freecam.Freecam;
import net.xolt.freecam.config.ModConfig;
import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -17,10 +19,20 @@
@Mixin(WorldRenderer.class)
public class WorldRendererMixin {

@Inject(method = "renderEntity", at = @At("HEAD"), cancellable = true)
private void onRenderEntity(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, CallbackInfo ci) {
if (entity == MC.player && Freecam.isEnabled() && !ModConfig.INSTANCE.visual.showPlayer) {
ci.cancel();
@Shadow
@Final
private BufferBuilderStorage bufferBuilders;

// Makes the player render if showPlayer is enabled.
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;checkEmpty(Lnet/minecraft/client/util/math/MatrixStack;)V", ordinal = 0))
private void onRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) {
if (Freecam.isEnabled() && ModConfig.INSTANCE.visual.showPlayer) {
Vec3d cameraPos = camera.getPos();
renderEntity(MC.player, cameraPos.x, cameraPos.y, cameraPos.z, tickDelta, matrices, bufferBuilders.getEntityVertexConsumers());
}
}

@Shadow
private void renderEntity(Entity entity, double cameraX, double cameraY, double cameraZ, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers) {
}
}

0 comments on commit 5fc28c7

Please sign in to comment.