Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/20.1/forge' into 20.1/forge
Browse files Browse the repository at this point in the history
  • Loading branch information
nthxny committed Mar 27, 2024
2 parents 4c8c8c8 + 9022b09 commit 50ecce4
Show file tree
Hide file tree
Showing 55 changed files with 863 additions and 438 deletions.
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ fun DependencyHandlerScope.compatCompileOnly(dependency: Dependency) {
}

dependencies {
minecraft("net.minecraftforge:forge:${"minecraft_version"()}-${"forge_version"()}")
minecraft("net.neoforged:forge:${"minecraft_version"()}-${"forge_version"()}")

// Mods
compatCompileOnly(fg.deobf("curse.maven:codechickenlib-242818:${"codechicken_fileid"()}"))
compatCompileOnly(fg.deobf("curse.maven:immersiveengineering-231951:${"ie_fileid"()}"))

annotationProcessor("net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5")

compileOnly("io.github.llamalad7:mixinextras-common:0.3.5")
annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5")
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.3.5")) {
jarJar.ranged(this, "[0.3.5,)")
}

// runtime remapping at home
fileTree(extraModsDir) {
include("*.jar")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9

# Mod Properties
mod_version = 0.3.5
mod_version = 0.3.11
maven_group = toni
archives_base_name = xenon


forge_version=47.1.43
forge_version=47.1.103
loom.platform=forge

codechicken_fileid=4382729
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package me.jellysquid.mods.sodium.client.compat.ccl;

import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing;
import me.jellysquid.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder;
import me.jellysquid.mods.sodium.client.render.chunk.terrain.material.Material;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder;
import me.jellysquid.mods.sodium.client.render.chunk.vertex.format.ChunkVertexEncoder;
import me.jellysquid.mods.sodium.client.util.DirectionUtil;
import me.jellysquid.mods.sodium.client.util.ModelQuadUtil;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand Down Expand Up @@ -36,9 +39,6 @@ public final class SinkingVertexBuilder implements VertexConsumer {
private float x;
private float y;
private float z;
private float nx;
private float ny;
private float nz;
private float u;
private float v;
private int color;
Expand All @@ -48,6 +48,77 @@ public final class SinkingVertexBuilder implements VertexConsumer {
private boolean hasFixedColor = false;

private final ChunkVertexEncoder.Vertex[] sodiumVertexArray = ChunkVertexEncoder.Vertex.uninitializedQuad();
private final ModelQuadView previousQuad = new ModelQuadView() {

/**
* @param idx the index of the desired vertex
* @param offset the offset into that vertex, as an integer
* @return appropriate byte offset
*/
private int getBaseIndex(int idx, int offset) {
return (currentVertex - 4 + idx) * VERTEX_SIZE_BYTES + (offset * 4);
}

@Override
public float getX(int idx) {
return buffer.getFloat(getBaseIndex(idx, 1));
}

@Override
public float getY(int idx) {
return buffer.getFloat(getBaseIndex(idx, 2));
}

@Override
public float getZ(int idx) {
return buffer.getFloat(getBaseIndex(idx, 3));
}

@Override
public int getColor(int idx) {
return buffer.getInt(getBaseIndex(idx, 4));
}

@Override
public float getTexU(int idx) {
return buffer.getFloat(getBaseIndex(idx, 5));
}

@Override
public float getTexV(int idx) {
return buffer.getFloat(getBaseIndex(idx, 6));
}

@Override
public int getLight(int idx) {
return buffer.getInt(getBaseIndex(idx, 7));
}

@Override
public int getFlags() {
return 0;
}

@Override
public int getColorIndex() {
return 0;
}

@Override
public TextureAtlasSprite getSprite() {
return null;
}

@Override
public Direction getLightFace() {
return null;
}

@Override
public int getForgeNormal(int idx) {
return 0;
}
};

private static ByteBuffer reallocDirect(ByteBuffer old, int capacity) {
ByteBuffer newBuf = ByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder());
Expand Down Expand Up @@ -111,17 +182,11 @@ public VertexConsumer uv2(int u, int v) {
@Nonnull
@Override
public VertexConsumer normal(float x, float y, float z) {
nx = x;
ny = y;
nz = z;
return this;
}

@Override
public void endVertex() {
final Direction dir = Direction.fromDelta((int) nx, (int) ny, (int) nz);
final int normal = dir != null ? dir.ordinal() : -1;

// Make sure there is enough space for a new vertex
if ((this.buffer.capacity() - this.buffer.position()) < VERTEX_SIZE_BYTES) {
int newCapacity = this.buffer.capacity() * 2;
Expand All @@ -134,7 +199,7 @@ public void endVertex() {
ByteBuffer buffer = this.buffer;

// Write the current quad vertex's normal, position, UVs, color and raw light values
buffer.putInt(normal);
buffer.putInt(-1);
buffer.putFloat(x);
buffer.putFloat(y);
buffer.putFloat(z);
Expand All @@ -146,6 +211,16 @@ public void endVertex() {

resetCurrentVertex(); // Reset the current vertex values
currentVertex++;
if((currentVertex % 4) == 0) {
recalculateNormals();
}
}

private void recalculateNormals() {
// Look through the last 4 vertex positions, and compute a proper normal
ModelQuadFacing normal = ModelQuadUtil.findNormalFace(ModelQuadUtil.calculateNormal(this.previousQuad));
// Store this in the position for the first vertex of the quad
buffer.putInt((currentVertex - 4) * VERTEX_SIZE_BYTES, normal.ordinal());
}

public void reset() {
Expand All @@ -168,9 +243,7 @@ public boolean flush(@Nonnull ChunkModelBuilder buffers, Material material, floa

for (int quadIdx = 0; quadIdx < numQuads; quadIdx++) {
final int normal = buffer.getInt((quadIdx << 2) << 5);
final Direction dir = normal != -1 ? DirectionUtil.ALL_DIRECTIONS[normal] : null;
final ModelQuadFacing facing = dir != null ? ModelQuadFacing.fromDirection(dir) : ModelQuadFacing.UNASSIGNED;
sideCount[facing.ordinal()]++;
sideCount[normal]++;
}

/*
Expand All @@ -191,8 +264,7 @@ public boolean flush(@Nonnull ChunkModelBuilder buffers, Material material, floa

while (buffer.position() < byteSize) {
final int normal = buffer.getInt(); // Fetch first normal for pre-selecting the vertex sink
final Direction dir = normal != -1 ? DirectionUtil.ALL_DIRECTIONS[normal] : null;
final ModelQuadFacing facing = dir != null ? ModelQuadFacing.fromDirection(dir) : ModelQuadFacing.UNASSIGNED;
final ModelQuadFacing facing = ModelQuadFacing.VALUES[normal];
final int facingIdx = facing.ordinal();

final ChunkMeshBufferBuilder sink = buffers.getVertexBuffer(facing);
Expand Down Expand Up @@ -223,7 +295,6 @@ public boolean flush(@Nonnull ChunkModelBuilder buffers, Material material, floa

private void resetCurrentVertex() {
x = y = z = 0F;
nx = ny = nz = 0F;
u = v = 0F;
color = 0xFFFF_FFFF;
light = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static OptionPage quality() {
.add(OptionImpl.createBuilder(int.class, vanillaOpts)
.setName(Component.translatable("options.biomeBlendRadius"))
.setTooltip(Component.translatable("sodium.options.biome_blend.tooltip"))
.setControl(option -> new SliderControl(option, 1, 7, 1, ControlValueFormatter.biomeBlend()))
.setControl(option -> new SliderControl(option, 0, 7, 1, ControlValueFormatter.biomeBlend()))
.setBinding((opts, value) -> opts.biomeBlendRadius().set(value), opts -> opts.biomeBlendRadius().get())
.setImpact(OptionImpact.LOW)
.setFlags(OptionFlag.REQUIRES_RENDERER_RELOAD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ default boolean hasColor() {
return this.getColorIndex() != -1;
}

boolean hasAmbientOcclusion();
default boolean hasAmbientOcclusion() { return true; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.caffeinemc.mods.sodium.api.util.ColorARGB;
import net.caffeinemc.mods.sodium.api.util.ColorMixer;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;

import java.util.Arrays;

public abstract class BlendedColorProvider<T> implements ColorProvider<T> {
private static boolean shouldUseVertexBlending;

public static void checkBlendingEnabled() {
shouldUseVertexBlending = Minecraft.getInstance().options.biomeBlendRadius().get() > 0;
}

@Override
public void getColors(WorldSlice view, BlockPos pos, T state, ModelQuadView quad, int[] output) {
for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
output[vertexIndex] = this.getVertexColor(view, pos, quad, vertexIndex);
if (shouldUseVertexBlending) {
for (int vertexIndex = 0; vertexIndex < 4; vertexIndex++) {
output[vertexIndex] = this.getVertexColor(view, pos, quad, vertexIndex);
}
} else {
// Just sample the exact position of that block (like vanilla), and use the same color on all vertices
Arrays.fill(output, ColorARGB.toABGR(this.getColor(view, pos.getX(), pos.getY(), pos.getZ())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gl.device.CommandList;
import me.jellysquid.mods.sodium.client.gl.device.RenderDevice;
import me.jellysquid.mods.sodium.client.model.quad.blender.BlendedColorProvider;
import me.jellysquid.mods.sodium.client.render.chunk.ChunkRenderMatrices;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSection;
import me.jellysquid.mods.sodium.client.render.chunk.RenderSectionManager;
Expand Down Expand Up @@ -278,6 +279,8 @@ private void initRenderer(CommandList commandList) {
var window = Minecraft.getInstance().getWindow();
if(window != null)
window.updateVsync(Minecraft.getInstance().options.enableVsync().get());

BlendedColorProvider.checkBlendingEnabled();
}

// We track whether a block entity uses custom block outline rendering, so that the outline postprocessing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeConfig;
import org.embeddedt.embeddium.api.BlockRendererRegistry;
import org.embeddedt.embeddium.api.model.EmbeddiumBakedModelExtension;
import org.embeddedt.embeddium.extras.leafculling.LeafCulling;

import java.util.Arrays;
Expand Down Expand Up @@ -258,7 +259,8 @@ private void writeGeometry(BlockRenderContext ctx,
}

private LightMode getLightingMode(BlockState state, BakedModel model, BlockAndTintGetter world, BlockPos pos, RenderType renderLayer) {
if (this.useAmbientOcclusion && model.useAmbientOcclusion(state, renderLayer) && state.getLightEmission(world, pos) == 0) {
if (this.useAmbientOcclusion && model.useAmbientOcclusion(state, renderLayer)
&& (((EmbeddiumBakedModelExtension)model).useAmbientOcclusionWithLightEmission(state, renderLayer) || state.getLightEmission(world, pos) == 0)) {
return LightMode.SMOOTH;
} else {
return LightMode.FLAT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.embeddedt.embeddium.api.ChunkDataBuiltEvent;
import org.embeddedt.embeddium.chunk.MeshAppenderRenderer;
import org.embeddedt.embeddium.model.ModelDataSnapshotter;
import org.embeddedt.embeddium.model.UnwrappableBakedModel;

import java.util.Map;

Expand Down Expand Up @@ -124,6 +125,12 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke
long seed = blockState.getSeed(blockPos);
random.setSeed(seed);

// Embeddium: Ideally we'd do this before the call to getModelData, but that requires an
// LVT reordering to move "long seed" further up. We will have to do this in 21.
model = UnwrappableBakedModel.unwrapIfPossible(model, random);

random.setSeed(seed);

for (RenderType layer : model.getRenderTypes(blockState, random, modelData)) {
context.update(blockPos, modelOffset, blockState, model, seed, modelData, layer);
cache.getBlockRenderer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.jellysquid.mods.sodium.client.render.immediate.model;

import com.mojang.blaze3d.vertex.PoseStack;
import org.embeddedt.embeddium.render.matrix_stack.CachingPoseStack;
import net.caffeinemc.mods.sodium.api.math.MatrixHelper;
import net.caffeinemc.mods.sodium.api.vertex.buffer.VertexBufferWriter;
import net.caffeinemc.mods.sodium.api.vertex.format.common.ModelVertex;
Expand Down Expand Up @@ -93,6 +94,8 @@ public static void render(PoseStack matrixStack, VertexBufferWriter writer, Mode
return;
}

((CachingPoseStack)matrixStack).embeddium$setCachingEnabled(true);

matrixStack.pushPose();

part.translateAndRotate(matrixStack);
Expand All @@ -104,6 +107,8 @@ public static void render(PoseStack matrixStack, VertexBufferWriter writer, Mode
renderChildren(matrixStack, writer, light, overlay, color, children);

matrixStack.popPose();

((CachingPoseStack)matrixStack).embeddium$setCachingEnabled(false);
}

private static void renderChildren(PoseStack matrices, VertexBufferWriter writer, int light, int overlay, int color, ModelPart[] children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
public class VertexConsumerTracker {
private static final Logger LOGGER = LoggerFactory.getLogger(MODNAME + "-VertexConsumerTracker");
private static final ReferenceSet<Class<? extends VertexConsumer>> BAD_CONSUMERS = ReferenceSets.synchronize(new ReferenceOpenHashSet<>());
private static final boolean WARN_NON_VBW_CONSUMERS = Boolean.getBoolean("embeddium.logBadVertexConsumers");

public static void logBadConsumer(VertexConsumer consumer) {
if (BAD_CONSUMERS.add(consumer.getClass())) {
if (WARN_NON_VBW_CONSUMERS && BAD_CONSUMERS.add(consumer.getClass())) {
LOGGER.warn("Class {} does not support optimized vertex writing code paths, which may cause reduced rendering performance",
consumer.getClass().getName());
}
Expand Down
Loading

0 comments on commit 50ecce4

Please sign in to comment.