From bea1b3a15c65ff84bc107b1b78720bb68815d71a Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Tue, 24 Mar 2026 20:01:56 +0800 Subject: [PATCH 1/3] feat: camera API prototype --- .../java/cam72cam/mod/event/ClientEvents.java | 10 +++ .../java/cam72cam/mod/render/CameraUtils.java | 87 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/main/java/cam72cam/mod/render/CameraUtils.java diff --git a/src/main/java/cam72cam/mod/event/ClientEvents.java b/src/main/java/cam72cam/mod/event/ClientEvents.java index bf8480080..109da14d3 100644 --- a/src/main/java/cam72cam/mod/event/ClientEvents.java +++ b/src/main/java/cam72cam/mod/event/ClientEvents.java @@ -6,6 +6,7 @@ import cam72cam.mod.gui.helpers.GUIHelpers; import cam72cam.mod.input.Mouse; import cam72cam.mod.math.Vec3d; +import cam72cam.mod.render.CameraUtils; import cam72cam.mod.render.EntityRenderer; import cam72cam.mod.render.GlobalRender; import cam72cam.mod.render.opengl.CustomTexture; @@ -212,6 +213,15 @@ public static void onRenderMouseover(DrawBlockHighlightEvent event) { RENDER_MOUSEOVER.execute(x -> x.accept(event.getPartialTicks())); } + @SubscribeEvent + public static void onCameraSetup(EntityViewRenderEvent.CameraSetup event) { + CameraUtils.applyTranslation(event); + } + + public static void onFOVSetup(EntityViewRenderEvent.FOVModifier event) { + CameraUtils.applyFov(event); + } + @SubscribeEvent public static void onSoundLoad(SoundLoadEvent event) { SOUND_LOAD.execute(x -> x.accept(event)); diff --git a/src/main/java/cam72cam/mod/render/CameraUtils.java b/src/main/java/cam72cam/mod/render/CameraUtils.java new file mode 100644 index 000000000..812070fc9 --- /dev/null +++ b/src/main/java/cam72cam/mod/render/CameraUtils.java @@ -0,0 +1,87 @@ +package cam72cam.mod.render; + +import cam72cam.mod.MinecraftClient; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.client.event.EntityViewRenderEvent; + +public class CameraUtils { + private static float x; + private static float y; + private static float z; + + private static float fov; + + private static float yaw; + private static float pitch; + private static float roll; + + private static boolean enabled; + + public static Perspectives getPerspective() { + if (!MinecraftClient.isReady()) { + switch (Minecraft.getMinecraft().gameSettings.thirdPersonView) { + case 0: + return Perspectives.FIRST_PERSON; + case 1: + return Perspectives.THIRD_PERSON; + case 2: + return Perspectives.THIRD_PERSON_INVERTED; + } + } + + return Perspectives.FIRST_PERSON; + } + + public enum Perspectives { + FIRST_PERSON, + THIRD_PERSON, + THIRD_PERSON_INVERTED, + } + + public static void enable() { + enabled = true; + } + + public static void disable() { + enabled = false; + } + + //+X is left, +Y is top, +Z is back + public static void setThirdPersonCameraOffset(float x, float y, float z) { + CameraUtils.x = x; + CameraUtils.y = y; + CameraUtils.z = z; + } + + public static void setYawOffset(float yaw) { + CameraUtils.yaw = yaw; + } + + public static void setPitchOffset(float pitch) { + CameraUtils.pitch = pitch; + } + + public static void setRollOffset(float roll) { + CameraUtils.roll = roll; + } + + public static void setFov(float fov) { + CameraUtils.fov = fov; + } + + public static void applyTranslation(EntityViewRenderEvent.CameraSetup event) { + if (enabled) { + GlStateManager.translate(x, y, z); + event.setYaw(yaw); + event.setPitch(pitch); + event.setRoll(roll); + } + } + + public static void applyFov(EntityViewRenderEvent.FOVModifier event) { + if (enabled) { + event.setFOV(fov); + } + } +} From c685fdfe8c3701181a5c76d127fbd72ba5d1e0e6 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Wed, 25 Mar 2026 20:49:12 +0800 Subject: [PATCH 2/3] feat: implementation of SmoothFloat --- src/main/java/cam72cam/mod/ModCore.java | 10 ++ .../java/cam72cam/mod/render/CameraUtils.java | 129 +++++++++----- .../java/cam72cam/mod/render/SmoothFloat.java | 167 ++++++++++++++++++ 3 files changed, 265 insertions(+), 41 deletions(-) create mode 100644 src/main/java/cam72cam/mod/render/SmoothFloat.java diff --git a/src/main/java/cam72cam/mod/ModCore.java b/src/main/java/cam72cam/mod/ModCore.java index aceb15296..db621e106 100644 --- a/src/main/java/cam72cam/mod/ModCore.java +++ b/src/main/java/cam72cam/mod/ModCore.java @@ -6,9 +6,11 @@ import cam72cam.mod.event.ClientEvents; import cam72cam.mod.gui.GuiRegistry; import cam72cam.mod.input.Mouse; +import cam72cam.mod.render.SmoothFloat; import cam72cam.mod.net.Packet; import cam72cam.mod.net.PacketDirection; import cam72cam.mod.render.BlockRender; +import cam72cam.mod.render.CameraUtils; import cam72cam.mod.render.Light; import cam72cam.mod.resource.Identifier; import cam72cam.mod.text.Command; @@ -290,6 +292,14 @@ public void clientEvent(ModEvent event) { }); BlockRender.onPostColorSetup(); ClientEvents.fireReload(); + ClientEvents.TICK.subscribe(SmoothFloat::onClientTick); + { + CameraUtils.Controller controller = CameraUtils.getController(); + ClientEvents.SCROLL.subscribe( e -> { + controller.setThirdPersonZOffset(controller.getThirdPersonZOffset() + (float) ( e * 5), 20); + return true; + }); + } break; } diff --git a/src/main/java/cam72cam/mod/render/CameraUtils.java b/src/main/java/cam72cam/mod/render/CameraUtils.java index 812070fc9..a1b69b2f8 100644 --- a/src/main/java/cam72cam/mod/render/CameraUtils.java +++ b/src/main/java/cam72cam/mod/render/CameraUtils.java @@ -5,18 +5,11 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraftforge.client.event.EntityViewRenderEvent; -public class CameraUtils { - private static float x; - private static float y; - private static float z; - - private static float fov; - - private static float yaw; - private static float pitch; - private static float roll; +import java.util.ArrayList; +import java.util.List; - private static boolean enabled; +public class CameraUtils { + private static final List controllers = new ArrayList<>(); public static Perspectives getPerspective() { if (!MinecraftClient.isReady()) { @@ -39,49 +32,103 @@ public enum Perspectives { THIRD_PERSON_INVERTED, } - public static void enable() { - enabled = true; + public static Controller getController() { + return new Controller(); } - public static void disable() { - enabled = false; + public static float getFov() { + return Minecraft.getMinecraft().gameSettings.fovSetting; } - //+X is left, +Y is top, +Z is back - public static void setThirdPersonCameraOffset(float x, float y, float z) { - CameraUtils.x = x; - CameraUtils.y = y; - CameraUtils.z = z; - } + public static void applyTranslation(EntityViewRenderEvent.CameraSetup event) { + if (getPerspective() == Perspectives.FIRST_PERSON) { + return; + } - public static void setYawOffset(float yaw) { - CameraUtils.yaw = yaw; - } + float x = 0, y = 0, z = 0; + float yaw = 0, pitch = 0, roll = 0; - public static void setPitchOffset(float pitch) { - CameraUtils.pitch = pitch; - } + float partialTicks = (float) event.getRenderPartialTicks(); - public static void setRollOffset(float roll) { - CameraUtils.roll = roll; - } + for (Controller controller : controllers) { + x += controller.xOffset.getValue(partialTicks); + y += controller.yOffset.getValue(partialTicks); + z += controller.zOffset.getValue(partialTicks); + yaw += controller.yawOffset.getValue(partialTicks); + pitch += controller.pitchOffset.getValue(partialTicks); + roll += controller.rollOffset.getValue(partialTicks); + } - public static void setFov(float fov) { - CameraUtils.fov = fov; + GlStateManager.translate(x, y, z); + event.setYaw(event.getYaw() + yaw); + event.setPitch(event.getPitch() + pitch); + event.setRoll(event.getRoll() + roll); } - public static void applyTranslation(EntityViewRenderEvent.CameraSetup event) { - if (enabled) { - GlStateManager.translate(x, y, z); - event.setYaw(yaw); - event.setPitch(pitch); - event.setRoll(roll); + public static void applyFov(EntityViewRenderEvent.FOVModifier event) { + float fov = 0; + for (Controller controller : controllers) { + fov += controller.fovOffset.getValue((float) event.getRenderPartialTicks()); } + event.setFOV(fov); } - public static void applyFov(EntityViewRenderEvent.FOVModifier event) { - if (enabled) { - event.setFOV(fov); + public static class Controller { + SmoothFloat xOffset; + SmoothFloat yOffset; + SmoothFloat zOffset; + + SmoothFloat yawOffset; + SmoothFloat pitchOffset; + SmoothFloat rollOffset; + + SmoothFloat fovOffset; + + private Controller() { + this.xOffset = new SmoothFloat(); + this.yOffset = new SmoothFloat(); + this.zOffset = new SmoothFloat(); + + this.yawOffset = new SmoothFloat(); + this.pitchOffset = new SmoothFloat(); + this.rollOffset = new SmoothFloat(); + + this.fovOffset = new SmoothFloat(); + + controllers.add(this); + } + + //+X is left, +Y is top, +Z is back + public void setThirdPersonXOffset(float x, float expectedTicks) { + this.xOffset.setNewValue(x, expectedTicks); + } + + public void setThirdPersonYOffset(float y, float expectedTicks) { + this.yOffset.setNewValue(y, expectedTicks); + } + + public void setThirdPersonZOffset(float z, float expectedTicks) { + this.zOffset.setNewValue(z, expectedTicks); + } + + public float getThirdPersonZOffset() { + return zOffset.getValue(0); + } + + public void setYawOffset(float yaw, float expectedTicks) { + yawOffset.setNewValue(yaw, expectedTicks); + } + + public void setPitchOffset(float pitch, float expectedTicks) { + pitchOffset.setNewValue(pitch, expectedTicks); + } + + public void setRollOffset(float roll, float expectedTicks) { + rollOffset.setNewValue(roll, expectedTicks); + } + + public void setFOV(float fov, float expectedTicks) { + fovOffset.setNewValue(fov, expectedTicks); } } } diff --git a/src/main/java/cam72cam/mod/render/SmoothFloat.java b/src/main/java/cam72cam/mod/render/SmoothFloat.java new file mode 100644 index 000000000..9a48c155a --- /dev/null +++ b/src/main/java/cam72cam/mod/render/SmoothFloat.java @@ -0,0 +1,167 @@ +//AI Generated +package cam72cam.mod.render; + +import net.minecraft.util.math.MathHelper; + +import java.lang.ref.WeakReference; +import java.util.HashSet; +import java.util.Iterator; + +/** + * A class used for smoothing input values with Hermite function + */ +public class SmoothFloat { + private static final HashSet> instances = new HashSet<>(); + + private float currentValue; + private float currentVelocity; + + private float startValue; + private float startVelocity; + + private float targetValue; + private float targetVelocity; + + private float durationTicks; + private float elapsedTicks; + private boolean active; + + public SmoothFloat() { + this(0.0f); + } + + public SmoothFloat(float value) { + this.currentValue = value; + this.currentVelocity = 0.0f; + + this.startValue = value; + this.startVelocity = 0.0f; + + this.targetValue = value; + this.targetVelocity = 0.0f; + + this.durationTicks = 0.0f; + this.elapsedTicks = 0.0f; + this.active = false; + + instances.add(new WeakReference<>(this)); + } + + public float getValue(float partialTicks) { + if (!active || durationTicks <= 0.0f) { + return currentValue; + } + + float t = MathHelper.clamp((elapsedTicks + MathHelper.clamp(partialTicks, 0, 1)) / durationTicks, 0, 1); + return evaluatePosition(t); + } + + public void setNewValue(float newValue, float expectedTicks) { + if (expectedTicks <= 0.0f) { + currentValue = newValue; + currentVelocity = 0.0f; + + startValue = newValue; + startVelocity = 0.0f; + + targetValue = newValue; + targetVelocity = 0.0f; + + durationTicks = 0.0f; + elapsedTicks = 0.0f; + active = false; + return; + } + + + float v = getCurrentVelocityAtTime(elapsedTicks, durationTicks); + + currentValue = getValue(0.0f); + + startValue = currentValue; + startVelocity = v; + + targetValue = newValue; + targetVelocity = 0.0f; + + durationTicks = expectedTicks; + elapsedTicks = 0.0f; + active = true; + } + + private void tick() { + if (!active || durationTicks <= 0.0f) { + return; + } + + elapsedTicks += 1.0f; + + if (elapsedTicks >= durationTicks) { + currentValue = targetValue; + currentVelocity = targetVelocity; + active = false; + return; + } + + float t = MathHelper.clamp(elapsedTicks / durationTicks, 0, 1); + currentValue = evaluatePosition(t); + currentVelocity = evaluateVelocity(t) / durationTicks; + } + + + public static void onClientTick() { + Iterator> it = instances.iterator(); + while (it.hasNext()) { + WeakReference ref = it.next(); + SmoothFloat instance = ref.get(); + if (instance != null) { + instance.tick(); + } else { + it.remove(); + } + } + } + + private float evaluatePosition(float t) { + t = MathHelper.clamp(t, 0, 1); + + float t2 = t * t; + float t3 = t2 * t; + + float h00 = 2.0f * t3 - 3.0f * t2 + 1.0f; + float h10 = t3 - 2.0f * t2 + t; + float h01 = -2.0f * t3 + 3.0f * t2; + float h11 = t3 - t2; + + return h00 * startValue + + h10 * startVelocity * durationTicks + + h01 * targetValue + + h11 * targetVelocity * durationTicks; + } + + private float evaluateVelocity(float t) { + t = MathHelper.clamp(t, 0, 1); + + float t2 = t * t; + + float dh00 = 6.0f * t2 - 6.0f * t; + float dh10 = 3.0f * t2 - 4.0f * t + 1.0f; + float dh01 = -6.0f * t2 + 6.0f * t; + float dh11 = 3.0f * t2 - 2.0f * t; + + return dh00 * startValue + + dh10 * startVelocity * durationTicks + + dh01 * targetValue + + dh11 * targetVelocity * durationTicks; + } + + + private float getCurrentVelocityAtTime(float elapsedTicks, float durationTicks) { + if (!active || durationTicks <= 0.0f) { + return currentVelocity; + } + + float t = MathHelper.clamp(elapsedTicks / durationTicks, 0, 1); + return evaluateVelocity(t) / durationTicks; + } +} \ No newline at end of file From 5848732be0c9c693c7e8e6f0c45c1720355bcbb9 Mon Sep 17 00:00:00 2001 From: Goldenfield192 <1437356849@qq.com> Date: Sat, 28 Mar 2026 15:54:50 +0800 Subject: [PATCH 3/3] ref: add some more utils and remove testing code --- src/main/java/cam72cam/mod/ModCore.java | 8 - .../java/cam72cam/mod/render/CameraUtils.java | 152 ++++++++++-------- .../cam72cam/mod/render/GlobalRender.java | 6 +- .../java/cam72cam/mod/render/SmoothFloat.java | 24 +-- 4 files changed, 101 insertions(+), 89 deletions(-) diff --git a/src/main/java/cam72cam/mod/ModCore.java b/src/main/java/cam72cam/mod/ModCore.java index db621e106..c3c33452e 100644 --- a/src/main/java/cam72cam/mod/ModCore.java +++ b/src/main/java/cam72cam/mod/ModCore.java @@ -10,7 +10,6 @@ import cam72cam.mod.net.Packet; import cam72cam.mod.net.PacketDirection; import cam72cam.mod.render.BlockRender; -import cam72cam.mod.render.CameraUtils; import cam72cam.mod.render.Light; import cam72cam.mod.resource.Identifier; import cam72cam.mod.text.Command; @@ -293,13 +292,6 @@ public void clientEvent(ModEvent event) { BlockRender.onPostColorSetup(); ClientEvents.fireReload(); ClientEvents.TICK.subscribe(SmoothFloat::onClientTick); - { - CameraUtils.Controller controller = CameraUtils.getController(); - ClientEvents.SCROLL.subscribe( e -> { - controller.setThirdPersonZOffset(controller.getThirdPersonZOffset() + (float) ( e * 5), 20); - return true; - }); - } break; } diff --git a/src/main/java/cam72cam/mod/render/CameraUtils.java b/src/main/java/cam72cam/mod/render/CameraUtils.java index a1b69b2f8..d9949c7f1 100644 --- a/src/main/java/cam72cam/mod/render/CameraUtils.java +++ b/src/main/java/cam72cam/mod/render/CameraUtils.java @@ -1,56 +1,91 @@ package cam72cam.mod.render; import cam72cam.mod.MinecraftClient; +import cam72cam.mod.math.Vec3d; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraftforge.client.event.EntityViewRenderEvent; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class CameraUtils { private static final List controllers = new ArrayList<>(); + private static float cameraRoll; + private static boolean cameraColliding; - public static Perspectives getPerspective() { - if (!MinecraftClient.isReady()) { + public static Perspective getPerspective() { + if (MinecraftClient.isReady()) { switch (Minecraft.getMinecraft().gameSettings.thirdPersonView) { case 0: - return Perspectives.FIRST_PERSON; + return Perspective.FIRST_PERSON; case 1: - return Perspectives.THIRD_PERSON; + return Perspective.THIRD_PERSON; case 2: - return Perspectives.THIRD_PERSON_INVERTED; + return Perspective.THIRD_PERSON_INVERTED; } } - return Perspectives.FIRST_PERSON; + return Perspective.FIRST_PERSON; } - public enum Perspectives { - FIRST_PERSON, - THIRD_PERSON, - THIRD_PERSON_INVERTED, - } - - public static Controller getController() { - return new Controller(); + public static void setPerspective(Perspective perspective) { + if (MinecraftClient.isReady()) { + switch (perspective) { + case FIRST_PERSON: + Minecraft.getMinecraft().gameSettings.thirdPersonView = 0; + return; + case THIRD_PERSON: + Minecraft.getMinecraft().gameSettings.thirdPersonView = 1; + return; + case THIRD_PERSON_INVERTED: + Minecraft.getMinecraft().gameSettings.thirdPersonView = 2; + } + } } public static float getFov() { return Minecraft.getMinecraft().gameSettings.fovSetting; } + /** Get global position of the player's eyes (with partialTicks taken into account) */ + public static Vec3d getCameraPos(float partialTicks) { + net.minecraft.entity.Entity playerRender = Minecraft.getMinecraft().getRenderViewEntity(); + double d0 = playerRender.lastTickPosX + (playerRender.posX - playerRender.lastTickPosX) * partialTicks; + double d1 = playerRender.lastTickPosY + (playerRender.posY - playerRender.lastTickPosY) * partialTicks; + double d2 = playerRender.lastTickPosZ + (playerRender.posZ - playerRender.lastTickPosZ) * partialTicks; + return new Vec3d(d0, d1, d2); + } + + public static float getCameraYaw(float partialTicks) { + net.minecraft.entity.Entity playerRender = Minecraft.getMinecraft().getRenderViewEntity(); + return playerRender.prevRotationYaw + (playerRender.rotationYaw - playerRender.prevRotationYaw) * partialTicks; + } + + public static float getCameraPitch(float partialTicks) { + net.minecraft.entity.Entity playerRender = Minecraft.getMinecraft().getRenderViewEntity(); + return playerRender.prevRotationPitch + (playerRender.rotationPitch - playerRender.prevRotationPitch) * partialTicks; + } + + public static float getCameraRoll() { + return cameraRoll; + } + + public static Controller newController(Perspective... activeIn) { + return new Controller(Arrays.asList(activeIn)); + } + public static void applyTranslation(EntityViewRenderEvent.CameraSetup event) { - if (getPerspective() == Perspectives.FIRST_PERSON) { - return; - } + cameraRoll = event.getRoll(); float x = 0, y = 0, z = 0; float yaw = 0, pitch = 0, roll = 0; float partialTicks = (float) event.getRenderPartialTicks(); + Perspective perspective = getPerspective(); for (Controller controller : controllers) { + if (!controller.perspectives.contains(perspective)) + continue; x += controller.xOffset.getValue(partialTicks); y += controller.yOffset.getValue(partialTicks); z += controller.zOffset.getValue(partialTicks); @@ -60,9 +95,9 @@ public static void applyTranslation(EntityViewRenderEvent.CameraSetup event) { } GlStateManager.translate(x, y, z); - event.setYaw(event.getYaw() + yaw); - event.setPitch(event.getPitch() + pitch); - event.setRoll(event.getRoll() + roll); + event.setYaw(yaw); + event.setPitch(pitch); + event.setRoll(roll); } public static void applyFov(EntityViewRenderEvent.FOVModifier event) { @@ -73,62 +108,41 @@ public static void applyFov(EntityViewRenderEvent.FOVModifier event) { event.setFOV(fov); } - public static class Controller { - SmoothFloat xOffset; - SmoothFloat yOffset; - SmoothFloat zOffset; - - SmoothFloat yawOffset; - SmoothFloat pitchOffset; - SmoothFloat rollOffset; - - SmoothFloat fovOffset; - - private Controller() { - this.xOffset = new SmoothFloat(); - this.yOffset = new SmoothFloat(); - this.zOffset = new SmoothFloat(); - - this.yawOffset = new SmoothFloat(); - this.pitchOffset = new SmoothFloat(); - this.rollOffset = new SmoothFloat(); - - this.fovOffset = new SmoothFloat(); - - controllers.add(this); - } + public enum Perspective { + FIRST_PERSON, + THIRD_PERSON, + THIRD_PERSON_INVERTED, + } + public static class Controller { //+X is left, +Y is top, +Z is back - public void setThirdPersonXOffset(float x, float expectedTicks) { - this.xOffset.setNewValue(x, expectedTicks); - } + public final SmoothFloat xOffset; + public final SmoothFloat yOffset; + public final SmoothFloat zOffset; - public void setThirdPersonYOffset(float y, float expectedTicks) { - this.yOffset.setNewValue(y, expectedTicks); - } + //Roll is the first to be applied, then pitch, then yaw + public final SmoothFloat rollOffset; + public final SmoothFloat pitchOffset; + public final SmoothFloat yawOffset; - public void setThirdPersonZOffset(float z, float expectedTicks) { - this.zOffset.setNewValue(z, expectedTicks); - } + public final SmoothFloat fovOffset; - public float getThirdPersonZOffset() { - return zOffset.getValue(0); - } + final List perspectives; - public void setYawOffset(float yaw, float expectedTicks) { - yawOffset.setNewValue(yaw, expectedTicks); - } + private Controller(List perspectives) { + this.xOffset = new SmoothFloat(0); + this.yOffset = new SmoothFloat(0); + this.zOffset = new SmoothFloat(0); - public void setPitchOffset(float pitch, float expectedTicks) { - pitchOffset.setNewValue(pitch, expectedTicks); - } + this.yawOffset = new SmoothFloat(0); + this.pitchOffset = new SmoothFloat(0); + this.rollOffset = new SmoothFloat(0); - public void setRollOffset(float roll, float expectedTicks) { - rollOffset.setNewValue(roll, expectedTicks); - } + this.fovOffset = new SmoothFloat(0); - public void setFOV(float fov, float expectedTicks) { - fovOffset.setNewValue(fov, expectedTicks); + this.perspectives = perspectives; + + controllers.add(this); } } } diff --git a/src/main/java/cam72cam/mod/render/GlobalRender.java b/src/main/java/cam72cam/mod/render/GlobalRender.java index 865bbe960..53f0501c1 100644 --- a/src/main/java/cam72cam/mod/render/GlobalRender.java +++ b/src/main/java/cam72cam/mod/render/GlobalRender.java @@ -76,7 +76,11 @@ public static boolean isTransparentPass() { return MinecraftForgeClient.getRenderPass() != 0; } - /** Get global position of the player's eyes (with partialTicks taken into account) */ + /** + * Get global position of the player's eyes (with partialTicks taken into account) + * @deprecated use the one in CameraUtils + * */ + @Deprecated public static Vec3d getCameraPos(float partialTicks) { net.minecraft.entity.Entity playerRender = Minecraft.getMinecraft().getRenderViewEntity(); double d0 = playerRender.lastTickPosX + (playerRender.posX - playerRender.lastTickPosX) * partialTicks; diff --git a/src/main/java/cam72cam/mod/render/SmoothFloat.java b/src/main/java/cam72cam/mod/render/SmoothFloat.java index 9a48c155a..c310d8a1f 100644 --- a/src/main/java/cam72cam/mod/render/SmoothFloat.java +++ b/src/main/java/cam72cam/mod/render/SmoothFloat.java @@ -1,17 +1,20 @@ -//AI Generated package cam72cam.mod.render; import net.minecraft.util.math.MathHelper; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import java.lang.ref.WeakReference; -import java.util.HashSet; +import java.util.Deque; import java.util.Iterator; +import java.util.concurrent.ConcurrentLinkedDeque; /** - * A class used for smoothing input values with Hermite function + * A class for smoothing input values with Hermite function (3t^2 - 2t^3) */ +@SideOnly(Side.CLIENT) public class SmoothFloat { - private static final HashSet> instances = new HashSet<>(); + private static final Deque> instances = new ConcurrentLinkedDeque<>(); private float currentValue; private float currentVelocity; @@ -26,10 +29,6 @@ public class SmoothFloat { private float elapsedTicks; private boolean active; - public SmoothFloat() { - this(0.0f); - } - public SmoothFloat(float value) { this.currentValue = value; this.currentVelocity = 0.0f; @@ -56,8 +55,13 @@ public float getValue(float partialTicks) { return evaluatePosition(t); } + public float getTargetValue() { + return targetValue; + } + public void setNewValue(float newValue, float expectedTicks) { if (expectedTicks <= 0.0f) { + //If we want to set it instantly currentValue = newValue; currentVelocity = 0.0f; @@ -73,7 +77,7 @@ public void setNewValue(float newValue, float expectedTicks) { return; } - + //Or use current velocity float v = getCurrentVelocityAtTime(elapsedTicks, durationTicks); currentValue = getValue(0.0f); @@ -108,7 +112,6 @@ private void tick() { currentVelocity = evaluateVelocity(t) / durationTicks; } - public static void onClientTick() { Iterator> it = instances.iterator(); while (it.hasNext()) { @@ -155,7 +158,6 @@ private float evaluateVelocity(float t) { + dh11 * targetVelocity * durationTicks; } - private float getCurrentVelocityAtTime(float elapsedTicks, float durationTicks) { if (!active || durationTicks <= 0.0f) { return currentVelocity;