Skip to content

Commit

Permalink
Port to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed May 21, 2024
1 parent 70cc373 commit bda318c
Show file tree
Hide file tree
Showing 70 changed files with 412 additions and 489 deletions.
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ plugins {
id("fabric-loom") version("1.6.6") apply(false)
}

val MINECRAFT_VERSION by extra { "1.20.6" }
val NEOFORGE_VERSION by extra { "20.6.57-beta" }
val FABRIC_LOADER_VERSION by extra { "0.15.10" }
val FABRIC_API_VERSION by extra { "0.97.5+1.20.5" }
val MINECRAFT_VERSION by extra { "1.20.1" }
val NEOFORGE_VERSION by extra { "47.2.23" }
val FABRIC_LOADER_VERSION by extra { "0.15.6" }
val FABRIC_API_VERSION by extra { "0.92.0+1.20.1" }

// https://semver.org/
val MOD_VERSION by extra { "0.6.0" }
Expand All @@ -24,7 +24,7 @@ tasks.withType<JavaCompile> {
subprojects {
apply(plugin = "maven-publish")

java.toolchain.languageVersion = JavaLanguageVersion.of(21)
java.toolchain.languageVersion = JavaLanguageVersion.of(17)


fun createVersionString(): String {
Expand Down Expand Up @@ -54,7 +54,7 @@ subprojects {
}

tasks.processResources {
filesMatching("META-INF/neoforge.mods.toml") {
filesMatching("META-INF/mods.toml") {
expand(mapOf("version" to createVersionString()))
}
}
Expand All @@ -64,7 +64,7 @@ subprojects {

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
options.release.set(17)
}

// Disables Gradle's custom module metadata from being published to maven. The
Expand All @@ -73,4 +73,4 @@ subprojects {
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.network.chat.Style;
import net.minecraft.util.FormattedCharSequence;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -241,6 +242,7 @@ private void rebuildGUIOptions() {
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
this.updateControls();

super.renderBackground(graphics);
super.render(graphics, this.prompt != null ? -1 : mouseX, this.prompt != null ? -1 : mouseY, delta);

if (this.hoveredElement != null) {
Expand Down Expand Up @@ -442,9 +444,9 @@ public Dim2i getDimensions() {
static {
DONATION_PROMPT_MESSAGE = List.of(
FormattedText.composite(Component.literal("Hello!")),
FormattedText.composite(Component.literal("It seems that you've been enjoying "), Component.literal("Sodium").withColor(0x27eb92), Component.literal(", the free and open-source optimization mod for Minecraft.")),
FormattedText.composite(Component.literal("Mods like these are complex. They require "), Component.literal("thousands of hours").withColor(0xff6e00), Component.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")),
FormattedText.composite(Component.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Component.literal("buying us a coffee").withColor(0xed49ce), Component.literal(".")),
FormattedText.composite(Component.literal("It seems that you've been enjoying "), Component.literal("Sodium").withStyle(Style.EMPTY.withColor(0x27eb92)), Component.literal(", the free and open-source optimization mod for Minecraft.")),
FormattedText.composite(Component.literal("Mods like these are complex. They require "), Component.literal("thousands of hours").withStyle(Style.EMPTY.withColor(0xff6e00)), Component.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")),
FormattedText.composite(Component.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Component.literal("buying us a coffee").withStyle(Style.EMPTY.withColor(0xed49ce)), Component.literal(".")),
FormattedText.composite(Component.literal("And thanks again for using our mod! We hope it helps you (and your computer.)"))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ColorProviderRegistry(BlockColors blockColors) {
// TODO: Allow mods to install their own color resolvers here
private void installOverrides() {
this.registerBlocks(DefaultColorProviders.GrassColorProvider.BLOCKS,
Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.SHORT_GRASS, Blocks.POTTED_FERN,
Blocks.GRASS_BLOCK, Blocks.FERN, Blocks.GRASS, Blocks.POTTED_FERN,
Blocks.PINK_PETALS, Blocks.SUGAR_CANE, Blocks.LARGE_FERN, Blocks.TALL_GRASS);

this.registerBlocks(DefaultColorProviders.FoliageColorProvider.BLOCKS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static void renderBlockEntity(PoseStack matrices,

PoseStack.Pose entry = matrices.last();
VertexConsumer transformer = new SheetedDecalTextureGenerator(bufferBuilder,
entry, 1.0f);
entry.pose(), entry.normal(), 1.0f);

consumer = (layer) -> layer.affectsCrumbling() ? VertexMultiConsumer.create(transformer, immediate.getBuffer(layer)) : immediate.getBuffer(layer);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public void render(LevelSlice level, FluidState fluidState, BlockPos blockPos, B
u1 = sprite.getU(0.0f);
v1 = sprite.getV(0.0f);
u2 = u1;
v2 = sprite.getV(1.0f);
u3 = sprite.getU(1.0f);
v2 = sprite.getV(16.0f);
u3 = sprite.getU(16.0f);
v3 = v2;
u4 = u3;
v4 = v1;
Expand All @@ -182,14 +182,14 @@ public void render(LevelSlice level, FluidState fluidState, BlockPos blockPos, B
float dir = (float) Mth.atan2(velocity.z, velocity.x) - (1.5707964f);
float sin = Mth.sin(dir) * 0.25F;
float cos = Mth.cos(dir) * 0.25F;
u1 = sprite.getU(0.5F + (-cos - sin));
v1 = sprite.getV(0.5F + -cos + sin);
u2 = sprite.getU(0.5F + -cos + sin);
v2 = sprite.getV(0.5F + cos + sin);
u3 = sprite.getU(0.5F + cos + sin);
v3 = sprite.getV(0.5F + (cos - sin));
u4 = sprite.getU(0.5F + (cos - sin));
v4 = sprite.getV(0.5F + (-cos - sin));
u1 = sprite.getU(8.0F + (-cos - sin) * 16.0F);
v1 = sprite.getV(8.0F + (-cos + sin) * 16.0F);
u2 = sprite.getU(8.0F + (-cos + sin) * 16.0F);
v2 = sprite.getV(8.0F + (cos + sin) * 16.0F);
u3 = sprite.getU(8.0F + (cos + sin) * 16.0F);
v3 = sprite.getV(8.0F + (cos - sin) * 16.0F);
u4 = sprite.getU(8.0F + (cos - sin) * 16.0F);
v4 = sprite.getV(8.0F + (-cos - sin) * 16.0F);
}

float uAvg = (u1 + u2 + u3 + u4) / 4.0F;
Expand Down Expand Up @@ -337,11 +337,11 @@ && isAlignedEquals(southEastHeight, southWestHeight)
}
}

float u1 = sprite.getU(0.0F);
float u2 = sprite.getU(0.5F);
float v1 = sprite.getV((1.0F - c1) * 0.5F);
float v2 = sprite.getV((1.0F - c2) * 0.5F);
float v3 = sprite.getV(0.5F);
float u1 = sprite.getU(0.0D);
float u2 = sprite.getU(8.0D);
float v1 = sprite.getV((1.0F - c1) * 16.0F * 0.5F);
float v2 = sprite.getV((1.0F - c2) * 16.0F * 0.5F);
float v3 = sprite.getV(8.0D);

quad.setSprite(sprite);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke
throw fillCrashInfo(CrashReport.forThrowable(ex, "Encountered exception while building chunk meshes"), slice, blockPos);
}

SodiumPlatformHelpers.INSTANCE.renderAdditionalRenderers(renderContext.getRenderers(), type -> buffers.get(DefaultMaterials.forRenderLayer(type)).asFallbackVertexConsumer(DefaultMaterials.forRenderLayer(type), collector),
slice);
if (SodiumPlatformHelpers.INSTANCE.shouldRenderIE(renderContext.getOrigin())) {
SodiumPlatformHelpers.INSTANCE.renderConnectionsInSection(buffers, slice, renderContext.getOrigin());
}

blockRenderer.release();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void renderModel(ItemStack itemStack, ItemDisplayContext transformMode, b
this.transformMode = transformMode;
this.poseStack = poseStack;
matPosition = poseStack.last().pose();
trustedNormals = poseStack.last().trustedNormals;
trustedNormals = true;
matNormal = poseStack.last().normal();
this.bufferSource = bufferSource;
this.lightmap = lightmap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void renderModel(BlockAndTintGetter blockView, BakedModel model, BlockSta

this.vertexConsumer = buffer;
this.matPosition = poseStack.last().pose();
this.trustedNormals = poseStack.last().trustedNormals;
this.trustedNormals = true;
this.matNormal = poseStack.last().normal();
this.overlay = overlay;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m
int newLight = mergeLighting(quad.getLight(i), light);

// The packed transformed normal vector
int normal = MatrixHelper.transformNormal(matNormal, matrices.trustedNormals, quad.getAccurateNormal(i));
int normal = MatrixHelper.transformNormal(matNormal, true, quad.getAccurateNormal(i));

// The transformed position vector
float xt = MatrixHelper.transformPositionX(matPosition, x, y, z);
Expand Down Expand Up @@ -76,7 +76,7 @@ public static void writeQuadVertices(VertexBufferWriter writer, PoseStack.Pose m
float fG;
float fB;

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

float brightness = brightnessTable[i];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ private static void prepareVertices(PoseStack.Pose matrices, ModelCuboid cuboid)
}

private static void prepareNormals(PoseStack.Pose matrices) {
CUBE_NORMALS[FACE_NEG_Y] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.DOWN);
CUBE_NORMALS[FACE_POS_Y] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.UP);
CUBE_NORMALS[FACE_NEG_Z] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.NORTH);
CUBE_NORMALS[FACE_POS_Z] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.SOUTH);
CUBE_NORMALS[FACE_POS_X] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.WEST);
CUBE_NORMALS[FACE_NEG_X] = MatrixHelper.transformNormal(matrices.normal(), matrices.trustedNormals, Direction.EAST);
CUBE_NORMALS[FACE_NEG_Y] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.DOWN);
CUBE_NORMALS[FACE_POS_Y] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.UP);
CUBE_NORMALS[FACE_NEG_Z] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.NORTH);
CUBE_NORMALS[FACE_POS_Z] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.SOUTH);
CUBE_NORMALS[FACE_POS_X] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.WEST);
CUBE_NORMALS[FACE_NEG_X] = MatrixHelper.transformNormal(matrices.normal(), true, Direction.EAST);

// When mirroring is used, the normals for EAST and WEST are swapped.
CUBE_NORMALS_MIRRORED[FACE_NEG_Y] = CUBE_NORMALS[FACE_NEG_Y];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.caffeinemc.mods.sodium.client.services;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.caffeinemc.mods.sodium.client.model.color.ColorProviderRegistry;
import net.caffeinemc.mods.sodium.client.model.light.LightPipelineProvider;
Expand Down Expand Up @@ -41,7 +42,7 @@ public interface SodiumPlatformHelpers {

Path getConfigDir();

Object getRenderData(Level level, BoundingBox pos, BlockEntity value);
Object getRenderData(Level level, ChunkPos pos, BlockEntity value);

boolean isDevelopmentEnvironment();

Expand All @@ -63,7 +64,7 @@ public interface SodiumPlatformHelpers {

boolean renderFluidFromVanilla();

void runChunkLayerEvents(RenderType renderLayer, LevelRenderer levelRenderer, Matrix4f modelMatrix, Matrix4f projectionMatrix, int ticks, Camera mainCamera, Frustum cullingFrustum);
void runChunkLayerEvents(RenderType renderLayer, LevelRenderer levelRenderer, PoseStack modelMatrix, Matrix4f projectionMatrix, int ticks, Camera mainCamera, Frustum cullingFrustum);

FluidRenderer createPlatformFluidRenderer(ColorProviderRegistry colorRegistry, LightPipelineProvider lightPipelineProvider);

Expand All @@ -76,10 +77,4 @@ public interface SodiumPlatformHelpers {
void renderConnectionsInSection(ChunkBuildBuffers buffers, LevelSlice worldSlice, SectionPos position);

boolean shouldRenderIE(SectionPos position);

void renderAdditionalRenderers(List<?> renderers, Function<RenderType, VertexConsumer> typeToConsumer, LevelSlice slice);

List<?> getExtraRenderers(Level level, BlockPos origin);

Object getLightManager(LevelChunk chunk, SectionPos pos);
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ public static ChunkRenderContext prepare(Level level, SectionPos pos, ClonedChun
}
}

Object modelData = SodiumPlatformHelpers.INSTANCE.getRenderData(level, box, null);
List<?> renderers = SodiumPlatformHelpers.INSTANCE.getExtraRenderers(level, pos.origin());
Object modelData = SodiumPlatformHelpers.INSTANCE.getRenderData(level, pos.chunk(), null);

return new ChunkRenderContext(pos, sections, box, modelData, renderers);
return new ChunkRenderContext(pos, sections, box, modelData);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ public class ChunkRenderContext {
private final ClonedChunkSection[] sections;
private final BoundingBox volume;
private final Object modelData;
private final List<?> renderers;

public ChunkRenderContext(SectionPos origin, ClonedChunkSection[] sections, BoundingBox volume, Object modelData, List<?> renderers) {
public ChunkRenderContext(SectionPos origin, ClonedChunkSection[] sections, BoundingBox volume, Object modelData) {
this.origin = origin;
this.sections = sections;
this.volume = volume;
this.modelData = modelData;
this.renderers = renderers;
}

public ClonedChunkSection[] getSections() {
Expand All @@ -35,8 +33,4 @@ public BoundingBox getVolume() {
public Object getModelData() {
return modelData;
}

public List<?> getRenderers() {
return renderers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public ClonedChunkSection(Level level, LevelChunk chunk, @Nullable LevelChunkSec

Int2ReferenceMap<BlockEntity> blockEntityMap = null;
Int2ReferenceMap<Object> blockEntityRenderDataMap = null;
auxLightManager = SodiumPlatformHelpers.INSTANCE.getLightManager(chunk, pos);

// Not required on 1.20.4 and below.
auxLightManager = null;

if (section != null) {
if (!section.hasOnlyAir()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.caffeinemc.mods.sodium.mixin.core;

import com.mojang.realmsclient.client.RealmsClient;
import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
import net.caffeinemc.mods.sodium.client.checks.ResourcePackScanner;
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfig;
import net.minecraft.server.packs.resources.ReloadInstance;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import org.lwjgl.opengl.GL32C;
Expand Down Expand Up @@ -74,8 +77,8 @@ private void postRender(boolean tick, CallbackInfo ci) {
/**
* Check for problematic core shader resource packs after the initial game launch.
*/
@Inject(method = "buildInitialScreens", at = @At("TAIL"))
private void postInit(CallbackInfoReturnable<Runnable> cir) {
@Inject(method = "setInitialScreen", at = @At("TAIL"))
private void postInit(RealmsClient realmsClient, ReloadInstance reloadInstance, GameConfig.QuickPlayData quickPlayData, CallbackInfo ci) {
ResourcePackScanner.checkIfCoreShaderLoaded(this.resourceManager);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.caffeinemc.mods.sodium.mixin.core.gui;

import net.minecraft.client.multiplayer.LevelLoadStatusManager;
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(LevelLoadStatusManager.class)
public class LevelLoadStatusManagerMixin {
@Mixin(ReceivingLevelScreen.class)
public class ReceivingLevelScreenMixin {
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/LocalPlayer;blockPosition()Lnet/minecraft/core/BlockPos;"))
private BlockPos redirect$getPlayerBlockPosition(LocalPlayer instance) {
// Ensure the "eye" position (which the chunk rendering code is actually concerned about) is used instead of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private void useFasterVertexConsumer(RenderType renderType, CallbackInfoReturnab

@ModifyVariable(method = {
"method_24213",
"lambda$endBatch$0"
"lambda$endBatch$0",
"m_109916_"
}, require = 1, at = @At(value = "LOAD", ordinal = 0))
private VertexConsumer changeComparedVertexConsumer(VertexConsumer vertexConsumer) {
if (vertexConsumer instanceof DirectBufferBuilder bufferBuilder) {
Expand Down

0 comments on commit bda318c

Please sign in to comment.