diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8c1be967..d1212f7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,8 +24,4 @@ Please keep pull requests to one topic. If you notice another issue to fix or fe create a separate request for it. This helps the maintainers to review your code. We value your contributions and appreciate your efforts in helping us maintain a high-quality codebase. Thank you for -contributing to our project! - -## Testing - -See [testing.md](docs/testing.md). \ No newline at end of file +contributing to our project! \ No newline at end of file diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/api/skyboxes/NuitSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/api/skyboxes/NuitSkybox.java index c1b21834..0f347def 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/api/skyboxes/NuitSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/api/skyboxes/NuitSkybox.java @@ -1,7 +1,6 @@ package io.github.amerebagatelle.mods.nuit.api.skyboxes; import io.github.amerebagatelle.mods.nuit.components.Conditions; -import io.github.amerebagatelle.mods.nuit.components.Decorations; import io.github.amerebagatelle.mods.nuit.components.Properties; public interface NuitSkybox extends Skybox { @@ -12,7 +11,5 @@ public interface NuitSkybox extends Skybox { Properties getProperties(); Conditions getConditions(); - - Decorations getDecorations(); } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Decorations.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Decorations.java index 49df93ce..fa95aa5c 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Decorations.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Decorations.java @@ -16,26 +16,20 @@ public class Decorations { ResourceLocation.CODEC.optionalFieldOf("moon", LevelRendererAccessor.getMoonPhases()).forGetter(Decorations::getMoonTexture), Codec.BOOL.optionalFieldOf("showSun", false).forGetter(Decorations::isSunEnabled), Codec.BOOL.optionalFieldOf("showMoon", false).forGetter(Decorations::isMoonEnabled), - Codec.BOOL.optionalFieldOf("showStars", false).forGetter(Decorations::isStarsEnabled), - Rotation.CODEC.optionalFieldOf("rotation", Rotation.decorations()).forGetter(Decorations::getRotation), - Blend.CODEC.optionalFieldOf("blend", Blend.decorations()).forGetter(Decorations::getBlend) + Codec.BOOL.optionalFieldOf("showStars", false).forGetter(Decorations::isStarsEnabled) ).apply(instance, Decorations::new)); private final ResourceLocation sunTexture; private final ResourceLocation moonTexture; private final boolean sunEnabled; private final boolean moonEnabled; private final boolean starsEnabled; - private final Rotation rotation; - private final Blend blend; - public Decorations(ResourceLocation sun, ResourceLocation moon, boolean sunEnabled, boolean moonEnabled, boolean starsEnabled, Rotation rotation, Blend blend) { + public Decorations(ResourceLocation sun, ResourceLocation moon, boolean sunEnabled, boolean moonEnabled, boolean starsEnabled) { this.sunTexture = sun; this.moonTexture = moon; this.sunEnabled = sunEnabled; this.moonEnabled = moonEnabled; this.starsEnabled = starsEnabled; - this.rotation = rotation; - this.blend = blend; } public ResourceLocation getSunTexture() { @@ -58,16 +52,8 @@ public boolean isStarsEnabled() { return this.starsEnabled; } - public Rotation getRotation() { - return rotation; - } - - public Blend getBlend() { - return blend; - } - public static Decorations of() { - return new Decorations(LevelRendererAccessor.getSun(), LevelRendererAccessor.getMoonPhases(), false, false, false, Rotation.decorations(), Blend.decorations()); + return new Decorations(LevelRendererAccessor.getSun(), LevelRendererAccessor.getMoonPhases(), false, false, false); } } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Rotation.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Rotation.java index 627ea42d..22f893fd 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Rotation.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/components/Rotation.java @@ -45,7 +45,8 @@ public Rotation(boolean skyboxRotation, Map mapping, Map skybox instanceof AbstractSkybox abstractSkybox && abstractSkybox.getDecorations().getRotation().getSkyboxRotation())) { + if (SkyboxManager.getInstance().isEnabled() && SkyboxManager.getInstance().getActiveSkyboxes().stream().anyMatch(skybox -> skybox instanceof DecorationBox decorBox && decorBox.getProperties().getRotation().getSkyboxRotation())) { return Mth.positiveModulo(instance.getDayTime() / 24000F + 0.75F, 1); } return instance.getTimeOfDay(v); @@ -63,7 +63,7 @@ private static void redirectSetShaderFogColor(float red, float green, float blue @Redirect(method = "setupColor", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getSunAngle(F)F")) private static float nuit$redirectSkyAngleRadian(ClientLevel instance, float v) { - if (SkyboxManager.getInstance().isEnabled() && SkyboxManager.getInstance().getActiveSkyboxes().stream().anyMatch(skybox -> skybox instanceof AbstractSkybox abstractSkybox && abstractSkybox.getDecorations().getRotation().getSkyboxRotation())) { + if (SkyboxManager.getInstance().isEnabled() && SkyboxManager.getInstance().getActiveSkyboxes().stream().anyMatch(skybox -> skybox instanceof DecorationBox decorBox && decorBox.getProperties().getRotation().getSkyboxRotation())) { float skyAngle = Mth.positiveModulo(instance.getDayTime() / 24000F + 0.75F, 1); return skyAngle * (float) (Math.PI * 2); } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/AbstractSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/AbstractSkybox.java index a92f5e57..23626b12 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/AbstractSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/AbstractSkybox.java @@ -1,22 +1,16 @@ package io.github.amerebagatelle.mods.nuit.skybox; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; import io.github.amerebagatelle.mods.nuit.NuitClient; import io.github.amerebagatelle.mods.nuit.api.skyboxes.NuitSkybox; 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.components.Weather; -import io.github.amerebagatelle.mods.nuit.mixin.LevelRendererAccessor; import io.github.amerebagatelle.mods.nuit.util.Utils; import it.unimi.dsi.fastutil.longs.Long2FloatOpenHashMap; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.renderer.FogRenderer; -import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.registries.Registries; import net.minecraft.util.Mth; import net.minecraft.util.Tuple; @@ -24,7 +18,6 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.material.FogType; -import org.joml.Matrix4f; import java.util.Map; import java.util.Objects; @@ -43,7 +36,6 @@ public abstract class AbstractSkybox implements NuitSkybox { public transient float alpha; protected Properties properties = Properties.of(); protected Conditions conditions = Conditions.of(); - protected Decorations decorations = Decorations.of(); protected boolean unexpectedConditionTransition = false; protected long lastTime = -2; @@ -59,10 +51,9 @@ public abstract class AbstractSkybox implements NuitSkybox { protected AbstractSkybox() { } - protected AbstractSkybox(Properties properties, Conditions conditions, Decorations decorations) { + protected AbstractSkybox(Properties properties, Conditions conditions) { this.properties = properties; this.conditions = conditions; - this.decorations = decorations; } @Override @@ -249,77 +240,6 @@ protected boolean checkWeather() { return (this.conditions.getWeathers().isExcludes() ^ this.conditions.getWeathers().getEntries().contains(Weather.CLEAR)) && !world.isRaining() && !world.isThundering(); } - public void renderDecorations(LevelRendererAccessor worldRendererAccess, PoseStack matrixStack, Matrix4f projectionMatrix, float tickDelta, BufferBuilder bufferBuilder, float alpha, 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); - matrixStack.pushPose(); - - // static - this.decorations.getRotation().rotateStack(matrixStack, currentTime, world); - - // Iris Compat - //matrixStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(IrisCompat.getSunPathRotation())); - //matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(world.getSkyAngle(tickDelta) * 360.0F * this.decorations.getRotation().getRotationSpeed())); - - Matrix4f matrix4f2 = matrixStack.last().pose(); - RenderSystem.setShader(GameRenderer::getPositionTexShader); - // Sun - if (this.decorations.isSunEnabled()) { - RenderSystem.setShaderTexture(0, this.decorations.getSunTexture()); - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix4f2, -30.0F, 100.0F, -30.0F).uv(0.0F, 0.0F).endVertex(); - bufferBuilder.vertex(matrix4f2, 30.0F, 100.0F, -30.0F).uv(1.0F, 0.0F).endVertex(); - bufferBuilder.vertex(matrix4f2, 30.0F, 100.0F, 30.0F).uv(1.0F, 1.0F).endVertex(); - bufferBuilder.vertex(matrix4f2, -30.0F, 100.0F, 30.0F).uv(0.0F, 1.0F).endVertex(); - BufferUploader.drawWithShader(bufferBuilder.end()); - } - // Moon - if (this.decorations.isMoonEnabled()) { - RenderSystem.setShaderTexture(0, this.decorations.getMoonTexture()); - int moonPhase = world.getMoonPhase(); - int xCoord = moonPhase % 4; - int yCoord = moonPhase / 4 % 2; - float startX = xCoord / 4.0F; - float startY = yCoord / 2.0F; - float endX = (xCoord + 1) / 4.0F; - float endY = (yCoord + 1) / 2.0F; - bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); - bufferBuilder.vertex(matrix4f2, -20.0F, -100.0F, 20.0F).uv(endX, endY).endVertex(); - bufferBuilder.vertex(matrix4f2, 20.0F, -100.0F, 20.0F).uv(startX, endY).endVertex(); - bufferBuilder.vertex(matrix4f2, 20.0F, -100.0F, -20.0F).uv(startX, startY).endVertex(); - bufferBuilder.vertex(matrix4f2, -20.0F, -100.0F, -20.0F).uv(endX, startY).endVertex(); - BufferUploader.drawWithShader(bufferBuilder.end()); - } - // Stars - if (this.decorations.isStarsEnabled()) { - float i = 1.0F - world.getRainLevel(tickDelta); - float brightness = world.getStarBrightness(tickDelta) * i; - if (brightness > 0.0F) { - RenderSystem.setShaderColor(brightness, brightness, brightness, brightness); - FogRenderer.setupNoFog(); - worldRendererAccess.getStarsBuffer().bind(); - worldRendererAccess.getStarsBuffer().drawWithShader(matrixStack.last().pose(), projectionMatrix, GameRenderer.getPositionShader()); - VertexBuffer.unbind(); - fogCallback.run(); - } - } - matrixStack.popPose(); - - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - RenderSystem.disableBlend(); - RenderSystem.defaultBlendFunc(); - } - - @Override - public Decorations getDecorations() { - return this.decorations; - } - @Override public Properties getProperties() { return this.properties; diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/MonoColorSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/MonoColorSkybox.java index b7d4bd35..54d6613a 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/MonoColorSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/MonoColorSkybox.java @@ -5,7 +5,10 @@ import com.mojang.math.Axis; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import io.github.amerebagatelle.mods.nuit.components.*; +import io.github.amerebagatelle.mods.nuit.components.Blend; +import io.github.amerebagatelle.mods.nuit.components.Conditions; +import io.github.amerebagatelle.mods.nuit.components.Properties; +import io.github.amerebagatelle.mods.nuit.components.RGBA; import io.github.amerebagatelle.mods.nuit.mixin.LevelRendererAccessor; import net.minecraft.client.Camera; import net.minecraft.client.renderer.GameRenderer; @@ -15,15 +18,14 @@ public class MonoColorSkybox extends AbstractSkybox { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties), Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions), - Decorations.CODEC.optionalFieldOf("decorations", Decorations.of()).forGetter(AbstractSkybox::getDecorations), RGBA.CODEC.optionalFieldOf("color", RGBA.of()).forGetter(MonoColorSkybox::getColor), Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(MonoColorSkybox::getBlend) ).apply(instance, MonoColorSkybox::new)); public RGBA color; public Blend blend; - public MonoColorSkybox(Properties properties, Conditions conditions, Decorations decorations, RGBA color, Blend blend) { - super(properties, conditions, decorations); + public MonoColorSkybox(Properties properties, Conditions conditions, RGBA color, Blend blend) { + super(properties, conditions); this.color = color; this.blend = blend; } @@ -64,8 +66,6 @@ public void render(LevelRendererAccessor worldRendererAccess, PoseStack matrices } BufferUploader.drawWithShader(bufferBuilder.end()); - this.renderDecorations(worldRendererAccess, matrices, projectionMatrix, tickDelta, bufferBuilder, this.alpha, fogCallback); - RenderSystem.disableBlend(); RenderSystem.depthMask(true); } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/SkyboxType.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/SkyboxType.java index bd00ed80..10756c9d 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/SkyboxType.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/SkyboxType.java @@ -5,6 +5,7 @@ import com.mojang.serialization.Codec; import io.github.amerebagatelle.mods.nuit.NuitClient; import io.github.amerebagatelle.mods.nuit.api.skyboxes.Skybox; +import io.github.amerebagatelle.mods.nuit.skybox.decorations.DecorationBox; import io.github.amerebagatelle.mods.nuit.skybox.textured.MultiTexturedSkybox; import io.github.amerebagatelle.mods.nuit.skybox.textured.SquareTexturedSkybox; import io.github.amerebagatelle.mods.nuit.skybox.vanilla.EndSkybox; @@ -28,6 +29,8 @@ public class SkyboxType { public static final SkyboxType SQUARE_TEXTURED_SKYBOX; public static final SkyboxType MULTI_TEXTURED_SKYBOX; + public static final SkyboxType DECORATION_BOX; + static { SKYBOX_ID_CODEC = Codec.STRING.xmap((s) -> { if (!s.contains(":")) { @@ -48,6 +51,8 @@ public class SkyboxType { MONO_COLOR_SKYBOX = new SkyboxType<>("monocolor", 1, MonoColorSkybox.CODEC); SQUARE_TEXTURED_SKYBOX = new SkyboxType<>("square-textured", 1, SquareTexturedSkybox.CODEC); MULTI_TEXTURED_SKYBOX = new SkyboxType<>("multi-textured", 1, MultiTexturedSkybox.CODEC); + + DECORATION_BOX = new SkyboxType<>("decorations", 1, DecorationBox.CODEC); } private final BiMap> codecBiMap; @@ -68,6 +73,7 @@ public static void register(Consumer> function) { function.accept(MONO_COLOR_SKYBOX); function.accept(SQUARE_TEXTURED_SKYBOX); function.accept(MULTI_TEXTURED_SKYBOX); + function.accept(DECORATION_BOX); } public String getName() { diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/decorations/DecorationBox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/decorations/DecorationBox.java new file mode 100644 index 00000000..92e64371 --- /dev/null +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/decorations/DecorationBox.java @@ -0,0 +1,127 @@ +package io.github.amerebagatelle.mods.nuit.skybox.decorations; + +import com.mojang.blaze3d.systems.RenderSystem; +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; +import io.github.amerebagatelle.mods.nuit.mixin.LevelRendererAccessor; +import io.github.amerebagatelle.mods.nuit.skybox.AbstractSkybox; +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.renderer.FogRenderer; +import net.minecraft.client.renderer.GameRenderer; +import org.joml.Matrix4f; + +public class DecorationBox extends AbstractSkybox { + public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Properties.CODEC.fieldOf("properties").forGetter(DecorationBox::getProperties), + 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, 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; + + // Custom Blender + this.blend.applyBlendFunc(alpha); + poseStack.pushPose(); + + // static + this.properties.getRotation().rotateStack(poseStack, world); + + // Iris Compat + //poseStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(IrisCompat.getSunPathRotation())); + //poseStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(world.getSkyAngle(tickDelta) * 360.0F * this.decorations.getRotation().getRotationSpeed())); + + Matrix4f matrix4f2 = poseStack.last().pose(); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); + // Sun + if (this.decorations.isSunEnabled()) { + renderSun(bufferBuilder, matrix4f2); + } + // Moon + if (this.decorations.isMoonEnabled()) { + renderMoon(bufferBuilder, matrix4f2); + } + // Stars + if (this.decorations.isStarsEnabled()) { + renderStars(levelRendererAccessor, tickDelta, poseStack, matrix4f); + } + poseStack.popPose(); + + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + RenderSystem.disableBlend(); + RenderSystem.defaultBlendFunc(); + } + + public void renderSun(BufferBuilder bufferBuilder, Matrix4f matrix4f) { + RenderSystem.setShaderTexture(0, this.decorations.getSunTexture()); + 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(); + bufferBuilder.vertex(matrix4f, 30.0F, 100.0F, 30.0F).uv(1.0F, 1.0F).endVertex(); + bufferBuilder.vertex(matrix4f, -30.0F, 100.0F, 30.0F).uv(0.0F, 1.0F).endVertex(); + BufferUploader.drawWithShader(bufferBuilder.end()); + } + + public void renderMoon(BufferBuilder bufferBuilder, Matrix4f matrix4f) { + RenderSystem.setShaderTexture(0, this.decorations.getMoonTexture()); + int moonPhase = Minecraft.getInstance().level.getMoonPhase(); + int xCoord = moonPhase % 4; + int yCoord = moonPhase / 4 % 2; + float startX = xCoord / 4.0F; + float startY = yCoord / 2.0F; + float endX = (xCoord + 1) / 4.0F; + float endY = (yCoord + 1) / 2.0F; + bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX); + bufferBuilder.vertex(matrix4f, -20.0F, -100.0F, 20.0F).uv(endX, endY).endVertex(); + bufferBuilder.vertex(matrix4f, 20.0F, -100.0F, 20.0F).uv(startX, endY).endVertex(); + bufferBuilder.vertex(matrix4f, 20.0F, -100.0F, -20.0F).uv(startX, startY).endVertex(); + bufferBuilder.vertex(matrix4f, -20.0F, -100.0F, -20.0F).uv(endX, startY).endVertex(); + BufferUploader.drawWithShader(bufferBuilder.end()); + } + + public void renderStars(LevelRendererAccessor levelRendererAccessor, float tickDelta, PoseStack poseStack, Matrix4f matrix4f) { + ClientLevel world = Minecraft.getInstance().level; + float i = 1.0F - world.getRainLevel(tickDelta); + float brightness = world.getStarBrightness(tickDelta) * i; + if (brightness > 0.0F) { + RenderSystem.setShaderColor(brightness, brightness, brightness, brightness); + FogRenderer.setupNoFog(); + levelRendererAccessor.getStarsBuffer().bind(); + levelRendererAccessor.getStarsBuffer().drawWithShader(poseStack.last().pose(), matrix4f, GameRenderer.getPositionShader()); + VertexBuffer.unbind(); + } + } + + public Decorations getDecorations() { + return decorations; + } + + public Blend getBlend() { + return blend; + } +} \ No newline at end of file diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/MultiTexturedSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/MultiTexturedSkybox.java index 0dac3af2..9c2632ed 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/MultiTexturedSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/MultiTexturedSkybox.java @@ -19,7 +19,6 @@ public class MultiTexturedSkybox extends TexturedSkybox { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties), Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions), - Decorations.CODEC.optionalFieldOf("decorations", Decorations.of()).forGetter(AbstractSkybox::getDecorations), Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(TexturedSkybox::getBlend), AnimatableTexture.CODEC.listOf().optionalFieldOf("animatableTextures", new ArrayList<>()).forGetter(MultiTexturedSkybox::getAnimations) ).apply(instance, MultiTexturedSkybox::new)); @@ -28,8 +27,8 @@ public class MultiTexturedSkybox extends TexturedSkybox { private final float quadSize = 100F; private final UVRange quad = new UVRange(-this.quadSize, -this.quadSize, this.quadSize, this.quadSize); - public MultiTexturedSkybox(Properties properties, Conditions conditions, Decorations decorations, Blend blend, List animatableTextures) { - super(properties, conditions, decorations, blend); + public MultiTexturedSkybox(Properties properties, Conditions conditions, Blend blend, List animatableTextures) { + super(properties, conditions, blend); this.animatableTextures = animatableTextures; } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/SquareTexturedSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/SquareTexturedSkybox.java index 53a90f56..00604b0b 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/SquareTexturedSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/SquareTexturedSkybox.java @@ -16,14 +16,13 @@ public class SquareTexturedSkybox extends TexturedSkybox { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties), Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions), - Decorations.CODEC.optionalFieldOf("decorations", Decorations.of()).forGetter(AbstractSkybox::getDecorations), Blend.CODEC.optionalFieldOf("blend", Blend.normal()).forGetter(TexturedSkybox::getBlend), Texture.CODEC.fieldOf("texture").forGetter(SquareTexturedSkybox::getTexture) ).apply(instance, SquareTexturedSkybox::new)); protected Texture texture; - public SquareTexturedSkybox(Properties properties, Conditions conditions, Decorations decorations, Blend blend, Texture texture) { - super(properties, conditions, decorations, blend); + public SquareTexturedSkybox(Properties properties, Conditions conditions, Blend blend, Texture texture) { + super(properties, conditions, blend); this.texture = texture; } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/TexturedSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/TexturedSkybox.java index d45c109d..f723b257 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/TexturedSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/textured/TexturedSkybox.java @@ -1,11 +1,12 @@ package io.github.amerebagatelle.mods.nuit.skybox.textured; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; import io.github.amerebagatelle.mods.nuit.api.skyboxes.RotatableSkybox; -import io.github.amerebagatelle.mods.nuit.components.*; +import io.github.amerebagatelle.mods.nuit.components.Blend; +import io.github.amerebagatelle.mods.nuit.components.Conditions; +import io.github.amerebagatelle.mods.nuit.components.Properties; +import io.github.amerebagatelle.mods.nuit.components.Rotation; import io.github.amerebagatelle.mods.nuit.mixin.LevelRendererAccessor; import io.github.amerebagatelle.mods.nuit.skybox.AbstractSkybox; import net.minecraft.client.Camera; @@ -23,8 +24,8 @@ public abstract class TexturedSkybox extends AbstractSkybox implements Rotatable protected TexturedSkybox() { } - protected TexturedSkybox(Properties properties, Conditions conditions, Decorations decorations, Blend blend) { - super(properties, conditions, decorations); + protected TexturedSkybox(Properties properties, Conditions conditions, Blend blend) { + super(properties, conditions); this.blend = blend; this.rotation = properties.getRotation(); } @@ -45,20 +46,15 @@ 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(); - BufferBuilder bufferBuilder = Tesselator.getInstance().getBuilder(); - - this.renderDecorations(worldRendererAccess, matrixStack, projectionMatrix, tickDelta, bufferBuilder, this.alpha, fogCallback); - RenderSystem.depthMask(true); RenderSystem.disableBlend(); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/EndSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/EndSkybox.java index c1b9d55f..13428dca 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/EndSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/EndSkybox.java @@ -6,7 +6,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; 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; @@ -18,12 +17,11 @@ public class EndSkybox extends AbstractSkybox { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties), - Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions), - Decorations.CODEC.optionalFieldOf("decorations", Decorations.of()).forGetter(AbstractSkybox::getDecorations) + Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions) ).apply(instance, EndSkybox::new)); - public EndSkybox(Properties properties, Conditions conditions, Decorations decorations) { - super(properties, conditions, decorations); + public EndSkybox(Properties properties, Conditions conditions) { + super(properties, conditions); } @Override @@ -70,8 +68,6 @@ public void render(LevelRendererAccessor worldRendererAccess, PoseStack matrices } BufferUploader.drawWithShader(bufferBuilder.end()); - this.renderDecorations(worldRendererAccess, matrices, projectionMatrix, tickDelta, bufferBuilder, this.alpha, fogCallback); - RenderSystem.depthMask(true); RenderSystem.disableBlend(); } diff --git a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/OverworldSkybox.java b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/OverworldSkybox.java index 33236b8d..acf9f459 100644 --- a/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/OverworldSkybox.java +++ b/common/src/main/java/io/github/amerebagatelle/mods/nuit/skybox/vanilla/OverworldSkybox.java @@ -8,10 +8,10 @@ import io.github.amerebagatelle.mods.nuit.SkyboxManager; import io.github.amerebagatelle.mods.nuit.api.NuitApi; 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; +import io.github.amerebagatelle.mods.nuit.skybox.decorations.DecorationBox; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -25,12 +25,11 @@ public class OverworldSkybox extends AbstractSkybox { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Properties.CODEC.fieldOf("properties").forGetter(AbstractSkybox::getProperties), - Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions), - Decorations.CODEC.optionalFieldOf("decorations", Decorations.of()).forGetter(AbstractSkybox::getDecorations) + Conditions.CODEC.optionalFieldOf("conditions", Conditions.of()).forGetter(AbstractSkybox::getConditions) ).apply(instance, OverworldSkybox::new)); - public OverworldSkybox(Properties properties, Conditions conditions, Decorations decorations) { - super(properties, conditions, decorations); + public OverworldSkybox(Properties properties, Conditions conditions) { + super(properties, conditions); } @Override @@ -61,7 +60,7 @@ public void render(LevelRendererAccessor worldRendererAccess, PoseStack matrices float skyAngle = world.getTimeOfDay(tickDelta); float skyAngleRadian = world.getSunAngle(tickDelta); - if (SkyboxManager.getInstance().isEnabled() && NuitApi.getInstance().getActiveSkyboxes().stream().anyMatch(skybox -> skybox instanceof AbstractSkybox abstractSkybox && abstractSkybox.getDecorations().getRotation().getSkyboxRotation())) { + if (SkyboxManager.getInstance().isEnabled() && NuitApi.getInstance().getActiveSkyboxes().stream().anyMatch(skybox -> skybox instanceof DecorationBox decorationBox && decorationBox.getProperties().getRotation().getSkyboxRotation())) { skyAngle = Mth.positiveModulo(world.getDayTime() / 24000F + 0.75F, 1); skyAngleRadian = skyAngle * (float) (Math.PI * 2); } @@ -93,9 +92,6 @@ public void render(LevelRendererAccessor worldRendererAccess, PoseStack matrices matrices.popPose(); } - - this.renderDecorations(worldRendererAccess, matrices, projectionMatrix, tickDelta, bufferBuilder, this.alpha, fogCallback); - // Dark Sky RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 1.0F); double d = client.player.getEyePosition(tickDelta).y - world.getLevelData().getHorizonHeight(world); diff --git a/docs/testing.md b/docs/testing.md deleted file mode 100644 index f4d98937..00000000 --- a/docs/testing.md +++ /dev/null @@ -1,23 +0,0 @@ -# Nuit Testing Documentation - -All of these tests will be run before a release, but the - -## Unit Tests - -The unit tests are run on every PR. They are not exhaustive of every possibility. -They also cannot test the most important parts of the mod, as this is a largely visual mod. - -## Visual Tests - -In the root directory, there is a folder called `testpacks/`. This folder contains several resource packs useful for -testing the mod. Below is documentation for the purpose of each of the resource packs. - -### [MonoColorSkybox](../testpacks/MonoColorSkybox) - -Tests the basic functionality of the Mono Colored Skybox. The pack should cause the sky to go from green to blue to red -over the course of the day. - -### [SquareTexturedSkybox](../testpacks/SquareTexturedSkybox) - -Tests the basic functionality of the Square Textured Skybox. The pack should cause the sky to turn into the skybox -between the times 0 and 2000 (by Minecraft tick time). All the faces should be rotated correctly. \ No newline at end of file diff --git a/testpacks/SquareTexturedSkybox/assets/nuit/sky/decorationbox.json b/testpacks/SquareTexturedSkybox/assets/nuit/sky/decorationbox.json new file mode 100644 index 00000000..abfb56f8 --- /dev/null +++ b/testpacks/SquareTexturedSkybox/assets/nuit/sky/decorationbox.json @@ -0,0 +1,34 @@ +{ + "schemaVersion": 1, + "type": "decorations", + "properties": { + "layer": 1, + "fade": { + "alwaysOn": true, + "keyFrames": { + "0": 0, + "12000": 1.0, + "23999": 0 + } + }, + "rotation": { + "mapping": { + "0": [ + 0, + 0, + 90 + ] + }, + "axis": { + "0": [ + 0, + 0, + 0 + ] + } + } + }, + "decorations": { + "showSun": true + } +} \ No newline at end of file diff --git a/testpacks/SquareTexturedSkybox/assets/nuit/sky/squaretexturedskybox.json b/testpacks/SquareTexturedSkybox/assets/nuit/sky/squaretexturedskybox.json index 186f3e74..c2556360 100644 --- a/testpacks/SquareTexturedSkybox/assets/nuit/sky/squaretexturedskybox.json +++ b/testpacks/SquareTexturedSkybox/assets/nuit/sky/squaretexturedskybox.json @@ -29,25 +29,5 @@ }, "conditions": { }, - "decorations": { - "showSun": true, - "showMoon": true, - "rotation": { - "mapping": { - "0": [ - 0, - 90, - 0 - ] - }, - "axis": { - "0": [ - 0, - 45, - 0 - ] - } - } - }, "texture": "nuit:sky/test_texture.png" } \ No newline at end of file