Skip to content

Commit

Permalink
Change StellarCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Aug 24, 2023
1 parent 5eced07 commit ecae23a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
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;
import net.minecraft.util.math.MathHelper;
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<World> worldKey;
protected final long fullRotationTime;
protected final RegistryKey<World> 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) {
Expand All @@ -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;
}
}
}

0 comments on commit ecae23a

Please sign in to comment.