Skip to content

Commit

Permalink
Merge branch '1.21/dev' into 1.21/stable
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Nov 17, 2024
2 parents e102297 + 7b362d1 commit ff29b4e
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 549 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ plugins {
id("fabric-loom") version ("1.8.9") apply (false)
}

val MINECRAFT_VERSION by extra { "1.21.1" }
val NEOFORGE_VERSION by extra { "21.1.79" }
val MINECRAFT_VERSION by extra { "1.21.3" }
val NEOFORGE_VERSION by extra { "21.3.0-beta" }
val FABRIC_LOADER_VERSION by extra { "0.16.9" }
val FABRIC_API_VERSION by extra { "0.108.0+1.21.1" }
val FABRIC_API_VERSION by extra { "0.108.0+1.21.3" }

// This value can be set to null to disable Parchment.
val PARCHMENT_VERSION by extra { null }
Expand All @@ -15,7 +15,7 @@ val PARCHMENT_VERSION by extra { null }
val MAVEN_GROUP by extra { "me.flashyreese.mods" }
val ARCHIVE_NAME by extra { "sodium-extra" }
val MOD_VERSION by extra { "0.6.0" }
val SODIUM_VERSION by extra { "mc1.21.1-0.6.0" }
val SODIUM_VERSION by extra { "mc1.21.3-0.6.0" }

allprojects {
apply(plugin = "java")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public static CaffeineConfig mixinConfig() {
.addMixinOption("optimizations", true)
.addMixinOption("optimizations.beacon_beam_rendering", true)
.addMixinOption("optimizations.draw_helpers", false)
.addMixinOption("optimizations.fast_weather", false)
.addMixinOption("particle", true)
.addMixinOption("prevent_shaders", true)
.addMixinOption("profiler", true)
.addMixinOption("reduce_resolution_on_mac", true)
.addMixinOption("render", true)
.addMixinOption("render.block", true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package me.flashyreese.mods.sodiumextra.mixin.fog;

import com.mojang.blaze3d.systems.RenderSystem;
import me.flashyreese.mods.sodiumextra.client.SodiumExtraClientMod;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.FogParameters;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.material.FogType;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FogRenderer.class)
public abstract class MixinFogRenderer {
@Shadow
@Nullable
protected static FogRenderer.MobEffectFogFunction getPriorityFogFunction(Entity entity, float f) {
private static FogRenderer.MobEffectFogFunction getPriorityFogFunction(Entity entity, float f) {
return null;
}

@Inject(method = "setupFog", at = @At(value = "TAIL"))
private static void applyFog(Camera camera, FogRenderer.FogMode fogType, float viewDistance, boolean thickFog, float tickDelta, CallbackInfo ci) {
@Inject(method = "setupFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogParameters;<init>(FFLcom/mojang/blaze3d/shaders/FogShape;FFFF)V", shift = At.Shift.AFTER), cancellable = true)
private static void applyFog(Camera camera, FogRenderer.FogMode fogMode, Vector4f vector4f, float f, boolean thickFog, float tickDelta, CallbackInfoReturnable<FogParameters> cir) {
Entity entity = camera.getEntity();
SodiumExtraClientMod.options().renderSettings.dimensionFogDistanceMap.putIfAbsent(entity.level().dimensionType().effectsLocation(), 0);
int fogDistance = SodiumExtraClientMod.options().renderSettings.multiDimensionFogControl ? SodiumExtraClientMod.options().renderSettings.dimensionFogDistanceMap.get(entity.level().dimensionType().effectsLocation()) : SodiumExtraClientMod.options().renderSettings.fogDistance;
FogRenderer.MobEffectFogFunction mobEffectFogFunction = getPriorityFogFunction(entity, tickDelta);
if (fogDistance == 0 || mobEffectFogFunction != null) {
return;
}
if (camera.getFluidInCamera() == FogType.NONE && (thickFog || fogType == FogRenderer.FogMode.FOG_TERRAIN)) {
if (camera.getFluidInCamera() == FogType.NONE && (thickFog || fogMode == FogRenderer.FogMode.FOG_TERRAIN)) {
float fogStart = (float) SodiumExtraClientMod.options().renderSettings.fogStart / 100;
if (fogDistance == 33) {
RenderSystem.setShaderFogColor(1f, 1f, 1f, 0f);
//RenderSystem.setShaderFogStart(Short.MAX_VALUE - 1 * fogStart);
//RenderSystem.setShaderFogEnd(Short.MAX_VALUE);
cir.setReturnValue(FogParameters.NO_FOG);
} else {
RenderSystem.setShaderFogStart(fogDistance * 16 * fogStart);
RenderSystem.setShaderFogEnd((fogDistance + 1) * 16);
FogParameters ci = cir.getReturnValue();
FogParameters newFogParameters = new FogParameters(fogDistance * 16 * fogStart, (fogDistance + 1) * 16, ci.shape(), ci.red(), ci.green(), ci.blue(), ci.alpha());
cir.setReturnValue(newFogParameters);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

@Mixin(FogRenderer.class)
public class MixinFogRenderer {
@ModifyArg(method = "setupFog", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderFogStart(F)V"), index = 0)
private static float modifySetShaderFogStart(float original) {
float fogStart = (float) SodiumExtraClientMod.options().renderSettings.fogStart / 100;
return original * fogStart;
@ModifyArg(method = "setupFog", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogParameters;<init>(FFLcom/mojang/blaze3d/shaders/FogShape;FFFF)V"), index = 0)
private static float setupFog(float fogStart) {
return fogStart * ((float) SodiumExtraClientMod.options().renderSettings.fogStart / 100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.function.Function;

@Mixin(value = GuiGraphics.class, priority = 1500)
public abstract class MixinGuiGraphics {

Expand All @@ -33,10 +35,6 @@ public abstract class MixinGuiGraphics {
@Final
private MultiBufferSource.BufferSource bufferSource;

@Shadow
@Deprecated
protected abstract void flushIfUnmanaged();

/**
* @author FlashyReese
* @reason Impl Sodium's vertex writer
Expand Down Expand Up @@ -107,7 +105,6 @@ public void fill(RenderType type, int x1, int y1, int x2, int y2, int z, int col

writer.push(stack, buffer, 4, ColorVertex.FORMAT);
}
this.flushIfUnmanaged();
ci.cancel();
}

Expand All @@ -116,68 +113,35 @@ public void fill(RenderType type, int x1, int y1, int x2, int y2, int z, int col
* @author FlashyReese
* @reason Impl Sodium's vertex writer
*/
@Inject(method = "innerBlit(Lnet/minecraft/resources/ResourceLocation;IIIIIFFFF)V", at = @At(value = "HEAD"), cancellable = true)
public void drawTexturedQuad(ResourceLocation texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, CallbackInfo ci) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
@Inject(method = "innerBlit", at = @At(value = "HEAD"), cancellable = true)
public void innerBlit(Function<ResourceLocation, RenderType> function, ResourceLocation resourceLocation, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color, CallbackInfo ci) {
RenderType renderType = function.apply(resourceLocation);
Matrix4f matrix4f = this.pose.last().pose();
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
VertexBufferWriter writer = VertexBufferWriter.of(bufferBuilder);
VertexConsumer vertexConsumer = this.bufferSource.getBuffer(renderType);
vertexConsumer.addVertex(matrix4f, (float)x1, (float)y1, 0.0F).setUv(u1, v1).setColor(color);
vertexConsumer.addVertex(matrix4f, (float)x1, (float)y2, 0.0F).setUv(u1, v2).setColor(color);
vertexConsumer.addVertex(matrix4f, (float)x2, (float)y2, 0.0F).setUv(u2, v2).setColor(color);
vertexConsumer.addVertex(matrix4f, (float)x2, (float)y1, 0.0F).setUv(u2, v1).setColor(color);

VertexBufferWriter writer = VertexBufferWriter.of(vertexConsumer);
try (MemoryStack stack = MemoryStack.stackPush()) {
final long buffer = stack.nmalloc(4 * TextureVertex.STRIDE);
long ptr = buffer;

TextureVertex.write(ptr, matrix4f, x1, y1, z, u1, v1);
TextureVertex.write(ptr, matrix4f, x1, y1, 0.0F, u1, v1);
ptr += TextureVertex.STRIDE;

TextureVertex.write(ptr, matrix4f, x1, y2, z, u1, v2);
TextureVertex.write(ptr, matrix4f, x1, y2, 0.0F, u1, v2);
ptr += TextureVertex.STRIDE;

TextureVertex.write(ptr, matrix4f, x2, y2, z, u2, v2);
TextureVertex.write(ptr, matrix4f, x2, y2, 0.0F, u2, v2);
ptr += TextureVertex.STRIDE;

TextureVertex.write(ptr, matrix4f, x2, y1, z, u2, v1);
TextureVertex.write(ptr, matrix4f, x2, y1, 0.0F, u2, v1);
ptr += TextureVertex.STRIDE;

writer.push(stack, buffer, 4, TextureVertex.FORMAT);
}
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());
ci.cancel();
}

/**
* @author FlashyReese
* @reason Impl Sodium's vertex writer
*/
@Inject(method = "innerBlit(Lnet/minecraft/resources/ResourceLocation;IIIIIFFFFFFFF)V", at = @At(value = "HEAD"), cancellable = true)
public void drawTexturedQuad(ResourceLocation texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, float red, float green, float blue, float alpha, CallbackInfo ci) {
RenderSystem.setShaderTexture(0, texture);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.enableBlend();
Matrix4f matrix4f = this.pose.last().pose();
BufferBuilder bufferBuilder = Tesselator.getInstance().begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
VertexBufferWriter writer = VertexBufferWriter.of(bufferBuilder);
int color = ColorABGR.pack(red, green, blue, alpha);
try (MemoryStack stack = MemoryStack.stackPush()) {
final long buffer = stack.nmalloc(4 * TextureColorVertex.STRIDE);
long ptr = buffer;

TextureColorVertex.write(ptr, matrix4f, x1, y1, z, color, u1, v1);
ptr += TextureColorVertex.STRIDE;

TextureColorVertex.write(ptr, matrix4f, x1, y2, z, color, u1, v2);
ptr += TextureColorVertex.STRIDE;

TextureColorVertex.write(ptr, matrix4f, x2, y2, z, color, u2, v2);
ptr += TextureColorVertex.STRIDE;

TextureColorVertex.write(ptr, matrix4f, x2, y1, z, color, u2, v1);
ptr += TextureColorVertex.STRIDE;

writer.push(stack, buffer, 4, TextureColorVertex.FORMAT);
}
BufferUploader.drawWithShader(bufferBuilder.buildOrThrow());
RenderSystem.disableBlend();
ci.cancel();
}
}
Loading

0 comments on commit ff29b4e

Please sign in to comment.