Skip to content

Commit

Permalink
change: Refactor decorations properties
Browse files Browse the repository at this point in the history
Gets rid of the Decoration class and just moves everything into the skybox type
  • Loading branch information
FlashyReese committed Jun 11, 2024
1 parent 3e00b02 commit 3bca92c
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ public String toString() {
public static Properties of() {
return new Properties(0, Fade.of(), 20, 20, Fog.of(), true, Rotation.of());
}

public static Properties decorations() {
return new Properties(0, Fade.of(), 20, 20, Fog.of(), true, Rotation.decorations());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class MonoColorSkybox extends AbstractSkybox {
public static Codec<MonoColorSkybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.of()).forGetter(AbstractSkybox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions),
RGBA.CODEC.optionalFieldOf("color", RGBA.of()).forGetter(MonoColorSkybox::getColor),
Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(MonoColorSkybox::getBlend)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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;
import io.github.amerebagatelle.mods.nuit.mixin.LevelRendererAccessor;
import io.github.amerebagatelle.mods.nuit.skybox.AbstractSkybox;
Expand All @@ -15,26 +14,35 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.resources.ResourceLocation;
import org.joml.Matrix4f;

public class DecorationBox extends AbstractSkybox {
public static Codec<DecorationBox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(DecorationBox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.decorations()).forGetter(DecorationBox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(DecorationBox::getConditions),
Decorations.CODEC.fieldOf("decorations").forGetter(DecorationBox::getDecorations),
ResourceLocation.CODEC.optionalFieldOf("sun", LevelRendererAccessor.getSun()).forGetter(DecorationBox::getSunTexture),
ResourceLocation.CODEC.optionalFieldOf("moon", LevelRendererAccessor.getMoonPhases()).forGetter(DecorationBox::getMoonTexture),
Codec.BOOL.optionalFieldOf("showSun", false).forGetter(DecorationBox::isSunEnabled),
Codec.BOOL.optionalFieldOf("showMoon", false).forGetter(DecorationBox::isMoonEnabled),
Codec.BOOL.optionalFieldOf("showStars", false).forGetter(DecorationBox::isStarsEnabled),
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, Blend blend) {
private final ResourceLocation sunTexture;
private final ResourceLocation moonTexture;
private final boolean sunEnabled;
private final boolean moonEnabled;
private final boolean starsEnabled;
private final Blend blend;

public DecorationBox(Properties properties, Conditions conditions, ResourceLocation sun, ResourceLocation moon, boolean sunEnabled, boolean moonEnabled, boolean starsEnabled, Blend blend) {
this.properties = properties;
this.conditions = conditions;
this.decorations = decorations;
this.sunTexture = sun;
this.moonTexture = moon;
this.sunEnabled = sunEnabled;
this.moonEnabled = moonEnabled;
this.starsEnabled = starsEnabled;
this.blend = blend;
}

Expand All @@ -59,15 +67,15 @@ public void render(LevelRendererAccessor levelRendererAccessor, PoseStack poseSt
RenderSystem.setShader(GameRenderer::getPositionTexShader);
BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder();
// Sun
if (this.decorations.isSunEnabled()) {
if (this.sunEnabled) {
this.renderSun(bufferBuilder, matrix4f2);
}
// Moon
if (this.decorations.isMoonEnabled()) {
if (this.moonEnabled) {
this.renderMoon(bufferBuilder, matrix4f2);
}
// Stars
if (this.decorations.isStarsEnabled()) {
if (this.starsEnabled) {
this.renderStars(levelRendererAccessor, tickDelta, poseStack, matrix4f);
}
poseStack.popPose();
Expand All @@ -78,7 +86,7 @@ public void render(LevelRendererAccessor levelRendererAccessor, PoseStack poseSt
}

public void renderSun(BufferBuilder bufferBuilder, Matrix4f matrix4f) {
RenderSystem.setShaderTexture(0, this.decorations.getSunTexture());
RenderSystem.setShaderTexture(0, this.sunTexture);
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
bufferBuilder.vertex(matrix4f, -30.0F, 100.0F, -30.0F).uv(0.0F, 0.0F).endVertex();
bufferBuilder.vertex(matrix4f, 30.0F, 100.0F, -30.0F).uv(1.0F, 0.0F).endVertex();
Expand All @@ -88,7 +96,7 @@ public void renderSun(BufferBuilder bufferBuilder, Matrix4f matrix4f) {
}

public void renderMoon(BufferBuilder bufferBuilder, Matrix4f matrix4f) {
RenderSystem.setShaderTexture(0, this.decorations.getMoonTexture());
RenderSystem.setShaderTexture(0, this.moonTexture);
int moonPhase = Minecraft.getInstance().level.getMoonPhase();
int xCoord = moonPhase % 4;
int yCoord = moonPhase / 4 % 2;
Expand Down Expand Up @@ -117,8 +125,25 @@ public void renderStars(LevelRendererAccessor levelRendererAccessor, float tickD
}
}

public Decorations getDecorations() {
return decorations;

public ResourceLocation getSunTexture() {
return this.sunTexture;
}

public ResourceLocation getMoonTexture() {
return this.moonTexture;
}

public boolean isSunEnabled() {
return this.sunEnabled;
}

public boolean isMoonEnabled() {
return this.moonEnabled;
}

public boolean isStarsEnabled() {
return this.starsEnabled;
}

public Blend getBlend() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class MultiTexturedSkybox extends TexturedSkybox {
public static Codec<MultiTexturedSkybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.of()).forGetter(AbstractSkybox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions),
Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(TexturedSkybox::getBlend),
AnimatableTexture.CODEC.listOf().optionalFieldOf("animatableTextures", new ArrayList<>()).forGetter(MultiTexturedSkybox::getAnimations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class SquareTexturedSkybox extends TexturedSkybox {
public static Codec<SquareTexturedSkybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.of()).forGetter(AbstractSkybox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions),
Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(TexturedSkybox::getBlend),
Texture.CODEC.fieldOf("texture").forGetter(SquareTexturedSkybox::getTexture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public abstract class TexturedSkybox extends AbstractSkybox implements Rotatable
public Rotation rotation;
public Blend blend;

protected TexturedSkybox() {
}

protected TexturedSkybox(Properties properties, Conditions conditions, Blend blend) {
super(properties, conditions);
this.blend = blend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class EndSkybox extends AbstractSkybox {
public static Codec<EndSkybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.of()).forGetter(AbstractSkybox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions)
).apply(instance, EndSkybox::new));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class OverworldSkybox extends AbstractSkybox {
public static Codec<OverworldSkybox> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties),
Properties.CODEC.optionalFieldOf("properties", Properties.of()).forGetter(AbstractSkybox::getProperties),
Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions)
).apply(instance, OverworldSkybox::new));

Expand Down

0 comments on commit 3bca92c

Please sign in to comment.