From ecae23a8f60243772d3fc2be25f49715151a4e52 Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:29:27 +0200 Subject: [PATCH] Change StellarCycle --- .../library/stellar/StellarObject.java | 8 +-- .../library/stellar/client/StellarCycle.java | 56 ++++++++++++++----- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/mmodding/mmodding_lib/library/stellar/StellarObject.java b/src/main/java/com/mmodding/mmodding_lib/library/stellar/StellarObject.java index 5b2960f..6419fb2 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/stellar/StellarObject.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/stellar/StellarObject.java @@ -24,15 +24,15 @@ public class StellarObject { private final float width; private final float height; - public StellarObject(Identifier stellarCycle, TextureLocation textureLocation, float width, float height) { + private StellarObject(Identifier stellarCycle, TextureLocation textureLocation, float width, float height) { this.stellarCycle = stellarCycle; this.textureLocation = textureLocation; this.width = width; this.height = height; } - public void register() { - RenderLayerUtils.addStellarObject(this); + public static void load(Identifier stellarCycle, TextureLocation textureLocation, float width, float height) { + RenderLayerUtils.addStellarObject(new StellarObject(stellarCycle, textureLocation, width, height)); } public StellarCycle getCycle() { @@ -57,7 +57,7 @@ public void render(MatrixStack matrices, ClientWorld world, float tickDelta) { matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(-90)); matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(this.getCycle().getXSkyAngle(this.getStatus(world).getCurrentTime()) * 360.0f)); - matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(this.getCycle().getYSkyAngle(this.getStatus(world).getCurrentTime()) * 360.0f)); + matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(this.getCycle().getYSkyAngle() * 360.0f)); Matrix4f matrix4f = matrices.peek().getModel(); RenderSystem.setShader(GameRenderer::getPositionTexShader); diff --git a/src/main/java/com/mmodding/mmodding_lib/library/stellar/client/StellarCycle.java b/src/main/java/com/mmodding/mmodding_lib/library/stellar/client/StellarCycle.java index 0aba0ea..7d4fc9d 100644 --- a/src/main/java/com/mmodding/mmodding_lib/library/stellar/client/StellarCycle.java +++ b/src/main/java/com/mmodding/mmodding_lib/library/stellar/client/StellarCycle.java @@ -1,6 +1,5 @@ package com.mmodding.mmodding_lib.library.stellar.client; -import com.mmodding.mmodding_lib.library.math.LinearFunction; import com.mmodding.mmodding_lib.library.math.MathFunction; import com.mmodding.mmodding_lib.library.utils.RegistrationUtils; import net.minecraft.util.Identifier; @@ -8,25 +7,24 @@ import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; +import org.jetbrains.annotations.ApiStatus; -public class StellarCycle { +public abstract class StellarCycle { - private final LinearFunction trajectory; - private final long fullRotationTime; - private final RegistryKey worldKey; + protected final long fullRotationTime; + protected final RegistryKey worldKey; - public StellarCycle(LinearFunction trajectory, long fullRotationTime, Identifier dimensionIdentifier) { - this.trajectory = trajectory; + private StellarCycle(long fullRotationTime, Identifier dimensionIdentifier) { this.fullRotationTime = fullRotationTime; this.worldKey = RegistryKey.of(Registry.WORLD_KEY, dimensionIdentifier); } - private StellarCycle of(float a, long fullRotationTime, Identifier dimensionIdentifier) { - return new StellarCycle(MathFunction.linear(a), fullRotationTime, dimensionIdentifier); + public StellarCycle ofAngle(float angle, long fullRotationTime, Identifier dimensionIdentifier) { + return new WithAngle(angle, fullRotationTime, dimensionIdentifier); } - private StellarCycle of(float a, float b, long fullRotationTime, Identifier dimensionIdentifier) { - return new StellarCycle(MathFunction.linear(a, b), fullRotationTime, dimensionIdentifier); + public StellarCycle ofTrajectory(MathFunction trajectory, long fullRotationTime, Identifier dimensionIdentifier) { + return new WithTrajectory(trajectory, fullRotationTime, dimensionIdentifier); } public void register(Identifier identifier) { @@ -47,7 +45,39 @@ public float getXSkyAngle(long time) { return (float) (a * 2.0 + b) / 3.0f; } - public float getYSkyAngle(long time) { - return (float) this.trajectory.getY(this.getXSkyAngle(time)); + public abstract float getYSkyAngle(); + + public static class WithAngle extends StellarCycle { + + private final float angle; + + private WithAngle(float angle, long fullRotationTime, Identifier dimensionIdentifier) { + super(fullRotationTime, dimensionIdentifier); + this.angle = angle / 360.0f; + } + + @Override + public float getYSkyAngle() { + return this.angle; + } + } + + @ApiStatus.Experimental + public static class WithTrajectory extends StellarCycle { + + private final MathFunction trajectory; + + private WithTrajectory(MathFunction trajectory, long fullRotationTime, Identifier dimensionIdentifier) { + super(fullRotationTime, dimensionIdentifier); + this.trajectory = trajectory; + } + + @Override + public float getYSkyAngle() { + /* double a = MathHelper.fractionalPart(this.trajectory.getY(1) / 360.0f - 0.25); + double b = 0.5 - Math.cos(a * Math.PI) / 2.0; + return (float) (a * 2.0 + b) / 3.0f; */ + return 0; + } } }