Skip to content

Commit

Permalink
Fix codec mistake, clean up rotation code again
Browse files Browse the repository at this point in the history
  • Loading branch information
AMereBagatelle committed Jun 3, 2024
1 parent 4419906 commit 03532ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public Rotation(boolean skyboxRotation, Map<Long, Quaternionf> mapping, Map<Long
this.speed = speed;
}

public void rotateStack(PoseStack matrixStack, long currentTime, ClientLevel world) {
public void rotateStack(PoseStack matrixStack, ClientLevel world) {
long currentTime = world.getDayTime() % duration;
// static
var possibleMappingKeyframes = Utils.findClosestKeyframes(mapping, currentTime);
Quaternionf mappingRot = new Quaternionf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.blaze3d.vertex.*;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.mods.nuit.components.Blend;
import io.github.amerebagatelle.mods.nuit.components.Conditions;
import io.github.amerebagatelle.mods.nuit.components.Decorations;
import io.github.amerebagatelle.mods.nuit.components.Properties;
Expand All @@ -19,34 +20,36 @@
public class DecorationBox extends AbstractSkybox {
public static Codec<DecorationBox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(DecorationBox::getProperties),
Conditions.CODEC.optionalFieldOf("blend", Conditions.of()).forGetter(DecorationBox::getConditions),
Decorations.CODEC.fieldOf("decorations").forGetter(DecorationBox::getDecorations)
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(DecorationBox::getConditions),
Decorations.CODEC.fieldOf("decorations").forGetter(DecorationBox::getDecorations),
Blend.CODEC.optionalFieldOf("blend", Blend.decorations()).forGetter(DecorationBox::getBlend)
).apply(instance, DecorationBox::new));

private Decorations decorations;
private Blend blend;

protected DecorationBox() {
}

public DecorationBox(Properties properties, Conditions conditions, Decorations decorations) {
public DecorationBox(Properties properties, Conditions conditions, Decorations decorations, Blend blend) {
this.properties = properties;
this.conditions = conditions;
this.decorations = decorations;
this.blend = blend;
}

@Override
public void render(LevelRendererAccessor levelRendererAccessor, PoseStack poseStack, Matrix4f matrix4f, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback) {
RenderSystem.enableBlend();
var world = Minecraft.getInstance().level;
assert world != null;
long currentTime = world.getDayTime() % this.decorations.getRotation().getDuration();

// Custom Blender
this.decorations.getBlend().applyBlendFunc(alpha);
this.blend.applyBlendFunc(alpha);
poseStack.pushPose();

// static
this.decorations.getRotation().rotateStack(poseStack, currentTime, world);
this.properties.getRotation().rotateStack(poseStack, world);

// Iris Compat
//poseStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(IrisCompat.getSunPathRotation()));
Expand Down Expand Up @@ -117,4 +120,8 @@ public void renderStars(LevelRendererAccessor levelRendererAccessor, float tickD
public Decorations getDecorations() {
return decorations;
}

public Blend getBlend() {
return blend;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ public final void render(LevelRendererAccessor worldRendererAccess, PoseStack ma
this.blend.applyBlendFunc(this.alpha);

ClientLevel world = Objects.requireNonNull(Minecraft.getInstance().level);
long currentTime = world.getDayTime() % this.rotation.getDuration();

matrixStack.pushPose();

// static
this.rotation.rotateStack(matrixStack, currentTime, world);
this.rotation.rotateStack(matrixStack, world);

this.renderSkybox(worldRendererAccess, matrixStack, tickDelta, camera, thickFog, fogCallback);
matrixStack.popPose();
Expand Down

0 comments on commit 03532ab

Please sign in to comment.