Skip to content

Commit f4c2a32

Browse files
committed
Added render utility for translating the camera relative to the player
1 parent 294a4c7 commit f4c2a32

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/main/java/com/falsepattern/lib/util/RenderUtil.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.falsepattern.lib.util;
2222

2323
import com.falsepattern.lib.StableAPI;
24-
import lombok.NoArgsConstructor;
2524
import lombok.SneakyThrows;
2625
import lombok.experimental.UtilityClass;
2726
import lombok.val;
@@ -31,9 +30,9 @@
3130
import net.minecraft.util.Timer;
3231
import cpw.mods.fml.relauncher.ReflectionHelper;
3332
import cpw.mods.fml.relauncher.SideOnly;
33+
import org.lwjgl.opengl.GL11;
3434

3535
import static cpw.mods.fml.relauncher.Side.CLIENT;
36-
import static lombok.AccessLevel.PRIVATE;
3736
import static net.minecraft.client.Minecraft.getMinecraft;
3837

3938
@SideOnly(CLIENT)
@@ -42,6 +41,18 @@
4241
public final class RenderUtil {
4342
private static final Timer MINECRAFT_TIMER = getMinecraftTimer();
4443

44+
@StableAPI.Expose(since = "0.12.0")
45+
public static void setGLTranslationRelativeToPlayer() {
46+
val player = getMinecraft().thePlayer;
47+
val partialTick = partialTick();
48+
49+
val offsetX = (float) (player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTick);
50+
val offsetY = (float) (player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTick);
51+
val offsetZ = (float) (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTick);
52+
53+
GL11.glTranslatef(-offsetX, -offsetY, -offsetZ);
54+
}
55+
4556
@StableAPI.Expose(since = "0.10.0")
4657
public static IIcon getFullTextureIcon(String iconName, int width, int height) {
4758
return new IIcon() {

0 commit comments

Comments
 (0)