Skip to content

Commit

Permalink
Buildscript improvements and fix #2713
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 10, 2024
1 parent a8f0424 commit d7f4f41
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 13 deletions.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

tasks.jar {
enabled = false
}

subprojects {
apply(plugin = "maven-publish")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.caffeinemc.mods.sodium.api.util.ColorU8;
import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter;
import net.caffeinemc.mods.sodium.api.vertex.format.common.EntityVertex;
import net.caffeinemc.mods.sodium.client.render.frapi.helper.ColorHelper;
import net.caffeinemc.mods.sodium.client.services.PlatformRuntimeInformation;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.lwjgl.system.MemoryStack;
Expand All @@ -21,6 +21,8 @@ private static int mergeLighting(int stored, int calculated) {
return blockLight | (skyLight << 16);
}

private static final boolean MULTIPLY_ALPHA = PlatformRuntimeInformation.getInstance().usesAlphaMultiplication();

public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose matrices, ModelQuadView quad, int color, int light, int overlay) {
Matrix3f matNormal = matrices.normal();
Matrix4f matPosition = matrices.pose();
Expand All @@ -45,7 +47,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m
float yt = MatrixHelper.transformPositionY(matPosition, x, y, z);
float zt = MatrixHelper.transformPositionZ(matPosition, x, y, z);

EntityVertex.write(ptr, xt, yt, zt, ColorHelper.multiplyColor(color, quad.getColor(i)), quad.getTexU(i), quad.getTexV(i), overlay, newLight, normal);
EntityVertex.write(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), overlay, newLight, normal);
ptr += EntityVertex.STRIDE;
}

Expand Down Expand Up @@ -75,6 +77,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m
float fR;
float fG;
float fB;
float fA;

var normal = MatrixHelper.transformNormal(matNormal, matrices.trustedNormals, quad.getAccurateNormal(i));

Expand All @@ -90,13 +93,21 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m
fR = oR * brightness * r;
fG = oG * brightness * g;
fB = oB * brightness * b;

if (MULTIPLY_ALPHA) {
float oA = ColorU8.byteToNormalizedFloat(ColorABGR.unpackAlpha(color));
fA = oA * a;
} else {
fA = a;
}
} else {
fR = brightness * r;
fG = brightness * g;
fB = brightness * b;
fA = a;
}

int color = ColorABGR.pack(fR, fG, fB, a);
int color = ColorABGR.pack(fR, fG, fB, fA);

EntityVertex.write(ptr, xt, yt, zt, color, quad.getTexU(i), quad.getTexV(i), overlay, light[i], normal);
ptr += EntityVertex.STRIDE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package net.caffeinemc.mods.sodium.client.services;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.block.model.BakedQuad;

import java.nio.file.Path;

public interface PlatformRuntimeInformation {
Expand Down Expand Up @@ -38,4 +42,9 @@ static PlatformRuntimeInformation getInstance() {
* Returns if a mod is in the mods folder during loading.
*/
boolean isModInLoadingList(String modId);

/**
* @return Whether {@link VertexConsumer#putBulkData(PoseStack.Pose, BakedQuad, float[], float, float, float, float, int[], int, boolean)} should multiply the vertex alpha component.
*/
boolean usesAlphaMultiplication();
}
2 changes: 2 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ tasks {

manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}

remapJar.get().destinationDirectory = rootDir.resolve("build").resolve("libs")
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public boolean platformUsesRefmap() {
public boolean isModInLoadingList(String modId) {
return FabricLoader.getInstance().isModLoaded(modId);
}

@Override
public boolean usesAlphaMultiplication() {
return false;
}
}
22 changes: 12 additions & 10 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("idea")
id("net.neoforged.moddev") version "1.0.15"
id("net.neoforged.moddev") version "2.0.28-beta"
id("java-library")
}

Expand Down Expand Up @@ -97,13 +97,17 @@ tasks.jar {
manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}

tasks.jar.get().destinationDirectory = rootDir.resolve("build").resolve("libs")

neoForge {
// Specify the version of NeoForge to use.
version = NEOFORGE_VERSION

parchment {
mappingsVersion = PARCHMENT_VERSION
minecraftVersion = MINECRAFT_VERSION
if (PARCHMENT_VERSION != null) {
parchment {
minecraftVersion = MINECRAFT_VERSION
mappingsVersion = PARCHMENT_VERSION
}
}

runs {
Expand Down Expand Up @@ -143,12 +147,10 @@ tasks.named("compileTestJava").configure {
dependencies {
compileOnly(project.project(":common").sourceSets.main.get().output)
compileOnly(project.project(":common").sourceSets.getByName("api").output)
includeDep("org.sinytra.forgified-fabric-api:fabric-api-base:0.4.42+d1308dedd1")
includeDep("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:3.4.0+acb05a39d1")
includeDep("net.fabricmc:fabric_rendering_data_attachment_v1:0.3.46+1.21") {
isTransitive = false
}
includeDep("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8cd1")
includeDep("org.sinytra.forgified-fabric-api:fabric-api-base:0.4.42+d1308ded19")
includeDep("org.sinytra.forgified-fabric-api:fabric-renderer-api-v1:3.4.0+acb05a3919")
includeDep("org.sinytra.forgified-fabric-api:fabric-rendering-data-attachment-v1:0.3.48+73761d2e19")
includeDep("org.sinytra.forgified-fabric-api:fabric-block-view-api-v2:1.0.10+9afaaf8c19")
}

java.toolchain.languageVersion = JavaLanguageVersion.of(21)
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public boolean platformUsesRefmap() {
public boolean isModInLoadingList(String modId) {
return LoadingModList.get().getModFileById(modId) != null;
}

@Override
public boolean usesAlphaMultiplication() {
return true;
}
}

0 comments on commit d7f4f41

Please sign in to comment.