Skip to content

Commit

Permalink
change: Fix fade
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Apr 28, 2024
1 parent 96e742b commit e08a80d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public static Skybox parseSkyboxJson(ResourceLocation id, JsonObject jsonObject)
}

SkyboxType<? extends Skybox> type = SkyboxType.REGISTRY.get(metadata.getType());
//Preconditions.checkNotNull(type, "Unknown skybox type: " + metadata.getType().getPath().replace('_', '-'));
if (type == null) {
NuitClient.getLogger().warn("Unknown skybox type: {}", metadata.getType().getPath().replace('_', '-'));
NuitClient.getLogger().warn("Skipping skybox {} with unknown type {}", id.toString(), metadata.getType().getPath().replace('_', '-'));
return null;
}
return type.getCodec(metadata.getSchemaVersion()).decode(JsonOps.INSTANCE, jsonObject).getOrThrow().getFirst();
Expand Down Expand Up @@ -141,7 +140,6 @@ public List<Skybox> getActiveSkyboxes() {
return this.activeSkyboxes;
}

//todo: implement this
@Override
public void tick(net.minecraft.client.multiplayer.ClientLevel client) {
StreamSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.mods.nuit.util.Utils;
import it.unimi.dsi.fastutil.longs.Long2FloatArrayMap;

import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -38,7 +39,7 @@ private void validateDuration(long duration) {
}

private Map<Long, Float> parseKeyFrames(Map<String, Float> keyFramesParsed) {
Map<Long, Float> parsedKeyFrames = new LinkedHashMap<>();
Map<Long, Float> parsedKeyFrames = new Long2FloatArrayMap();
for (Map.Entry<String, Float> entry : keyFramesParsed.entrySet()) {
try {
long keyFrame = Long.parseLong(entry.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public float updateAlpha() {
this.conditionAlpha = Utils.calculateConditionAlphaValue(1f, 0f, this.conditionAlpha, condition ? this.properties.getTransitionInDuration() : this.properties.getTransitionOutDuration(), condition);
} else {
Tuple<Long, Long> keyFrames = Utils.findClosestKeyframes(this.properties.getFade().getKeyFrames(), currentTime);
fadeAlpha = Utils.calculateInterpolatedAlpha(currentTime, keyFrames.getA(), keyFrames.getA(), this.properties.getFade().getKeyFrames().get(keyFrames.getA()), this.properties.getFade().getKeyFrames().get(keyFrames.getB()));
fadeAlpha = Utils.calculateInterpolatedAlpha(currentTime, keyFrames.getA(), keyFrames.getB(), this.properties.getFade().getKeyFrames().get(keyFrames.getA()), this.properties.getFade().getKeyFrames().get(keyFrames.getB()));

if (this.lastTime == currentTime - 1 || this.lastTime == currentTime) { // Check if time is ticking or if time is same (doDaylightCycle gamerule)
this.conditionAlpha = Utils.calculateConditionAlphaValue(1f, 0f, this.conditionAlpha, condition ? this.properties.getTransitionInDuration() : this.properties.getTransitionOutDuration(), condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,20 @@ public void renderSkybox(LevelRendererAccessor worldRendererAccess, PoseStack ma
// 4 = east
// 5 = west
// List of UV ranges for each face of the cube
UVRange faceUVRange = new UVRange(0, 0, 1.0F / 3.0F, 1.0F / 2.0F);
UVRange faceUVRange = Utils.TEXTURE_FACES[i];
matrices.pushPose();

if (i == 1) {
faceUVRange = new UVRange(1.0F / 3.0F, 1.0F / 2.0F, 2.0F / 3.0F, 1);
matrices.mulPose(Axis.XP.rotationDegrees(90.0F));
} else if (i == 2) {
faceUVRange = new UVRange(2.0F / 3.0F, 0, 1, 1.0F / 2.0F);
matrices.mulPose(Axis.XP.rotationDegrees(-90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(180.0F));
} else if (i == 3) {
faceUVRange = new UVRange(1.0F / 3.0F, 0, 2.0F / 3.0F, 1.0F / 2.0F);
matrices.mulPose(Axis.XP.rotationDegrees(180.0F));
} else if (i == 4) {
faceUVRange = new UVRange(2.0F / 3.0F, 1.0F / 2.0F, 1, 1);
matrices.mulPose(Axis.ZP.rotationDegrees(90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(-90.0F));
} else if (i == 5) {
faceUVRange = new UVRange(0, 1.0F / 2.0F, 1.0F / 3.0F, 1);
matrices.mulPose(Axis.ZP.rotationDegrees(-90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(90.0F));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.amerebagatelle.mods.nuit.skybox.*;
import io.github.amerebagatelle.mods.nuit.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.mods.nuit.skyboxes.SkyboxType;
import io.github.amerebagatelle.mods.nuit.util.Utils;
import net.minecraft.client.Camera;
import org.joml.Matrix4f;

Expand Down Expand Up @@ -43,32 +44,27 @@ public void renderSkybox(LevelRendererAccessor worldRendererAccess, PoseStack ma
BufferBuilder bufferBuilder = tessellator.getBuilder();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
RenderSystem.setShaderTexture(0, this.texture.getTextureId());
for (int i = 0; i < 6; ++i) {
for (int face = 0; face < 6; face++) {
// 0 = bottom
// 1 = north
// 2 = south
// 3 = top
// 4 = east
// 5 = west
UVRange tex = this.texture.withUV(0, 0, 1.0F / 3.0F, 1.0F / 2.0F);
UVRange tex = Utils.TEXTURE_FACES[face];
matrices.pushPose();

if (i == 1) {
tex = this.texture.withUV(1.0F / 3.0F, 1.0F / 2.0F, 2.0F / 3.0F, 1);
if (face == 1) {
matrices.mulPose(Axis.XP.rotationDegrees(90.0F));
} else if (i == 2) {
tex = this.texture.withUV(2.0F / 3.0F, 0, 1, 1.0F / 2.0F);
} else if (face == 2) {
matrices.mulPose(Axis.XP.rotationDegrees(-90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(180.0F));
} else if (i == 3) {
tex = this.texture.withUV(1.0F / 3.0F, 0, 2.0F / 3.0F, 1.0F / 2.0F);
} else if (face == 3) {
matrices.mulPose(Axis.XP.rotationDegrees(180.0F));
} else if (i == 4) {
tex = this.texture.withUV(2.0F / 3.0F, 1.0F / 2.0F, 1, 1);
} else if (face == 4) {
matrices.mulPose(Axis.ZP.rotationDegrees(90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(-90.0F));
} else if (i == 5) {
tex = this.texture.withUV(0, 1.0F / 2.0F, 1.0F / 3.0F, 1);
} else if (face == 5) {
matrices.mulPose(Axis.ZP.rotationDegrees(-90.0F));
matrices.mulPose(Axis.YP.rotationDegrees(90.0F));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
import java.util.Optional;

public class Utils {
public static final UVRange[] TEXTURE_FACES = new UVRange[] {
new UVRange(0, 0, 1.0F / 3.0F, 1.0F / 2.0F), // bottom
new UVRange(1.0F / 3.0F, 1.0F / 2.0F, 2.0F / 3.0F, 1), // north
new UVRange(2.0F / 3.0F, 0, 1, 1.0F / 2.0F), // south
new UVRange(1.0F / 3.0F, 0, 2.0F / 3.0F, 1.0F / 2.0F), // top
new UVRange(2.0F / 3.0F, 1.0F / 2.0F, 1, 1), // east
new UVRange(0, 1.0F / 2.0F, 1.0F / 3.0F, 1) // west
};


/**
* Maps input intersection to output intersection, does so by taking in input and output UV ranges and then mapping the input intersection to the output intersection.
Expand Down

0 comments on commit e08a80d

Please sign in to comment.