Skip to content

Commit

Permalink
Sodium support??? + update?????
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Dec 29, 2022
1 parent e7f1cf4 commit 1d90316
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.1.0
version=7.2.0
maven_group=net.ludocrypt
archives_base_name=limlib
2 changes: 1 addition & 1 deletion limlib_effects/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.1.0
version=7.2.0
maven_group=net.ludocrypt
archives_base_name=limlib-effects
2 changes: 1 addition & 1 deletion limlib_registry/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.1.0
version=7.2.0
maven_group=net.ludocrypt
archives_base_name=limlib-registry
2 changes: 1 addition & 1 deletion limlib_render/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.1.0
version=7.2.0
maven_group=net.ludocrypt
archives_base_name=limlib-render
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
package net.ludocrypt.limlib.render.mixin.render;

import java.util.List;
import java.util.Optional;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.framebuffer.Framebuffer;
import com.mojang.blaze3d.framebuffer.SimpleFramebuffer;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferRenderer;
import com.mojang.blaze3d.vertex.Tessellator;
import com.mojang.blaze3d.vertex.VertexBuffer;
import com.mojang.blaze3d.vertex.VertexFormat.DrawMode;
import com.mojang.blaze3d.vertex.VertexFormats;
import com.mojang.datafixers.util.Pair;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.ludocrypt.limlib.render.LimlibRender;
import net.ludocrypt.limlib.render.access.BakedModelAccess;
import net.ludocrypt.limlib.render.access.BuiltChunkAccess;
import net.ludocrypt.limlib.render.access.WorldRendererAccess;
import net.ludocrypt.limlib.render.compat.SodiumBridge;
import net.ludocrypt.limlib.render.mixin.render.gui.GameRendererAccessor;
import net.ludocrypt.limlib.render.mixin.render.gui.GameRendererAccessorTwo;
import net.ludocrypt.limlib.render.skybox.Skybox;
import net.ludocrypt.limlib.render.special.SpecialModelRenderer;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilderStorage;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.ShaderProgram;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
Expand All @@ -40,6 +52,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.random.RandomGenerator;

@Mixin(value = WorldRenderer.class, priority = 900)
public abstract class WorldRendererMixin implements WorldRendererAccess {
Expand Down Expand Up @@ -164,6 +177,66 @@ public void renderBlocks(MatrixStack matrices, Matrix4f positionMatrix) {
ChunkBuilder.BuiltChunk builtChunk = chunkInfo.chunk;
((BuiltChunkAccess) builtChunk).getSpecialModelBuffers().forEach((modelRenderer, vertexBuffer) -> renderBuffer(matrices, positionMatrix, modelRenderer, vertexBuffer, builtChunk.getOrigin()));
}
} else {
Iterable<BlockPos> iterable = BlockPos.iterateOutwards(client.player.getBlockPos(), 10, 10, 10);
List<BlockState> dontCheckStates = Lists.newArrayList();

for (BlockPos pos : iterable) {
BlockState state = world.getBlockState(pos);
if (!dontCheckStates.contains(state)) {
List<Pair<SpecialModelRenderer, BakedModel>> models = ((BakedModelAccess) client.getBakedModelManager().getBlockModels().getModel(state)).getModels(state);
if (!models.isEmpty()) {

Camera camera = client.gameRenderer.getCamera();
matrices.push();
matrices.translate(pos.getX() - camera.getPos().getX(), pos.getY() - camera.getPos().getY(), pos.getZ() - camera.getPos().getZ());

MatrixStack matrix = new MatrixStack();
matrix.multiplyMatrix(matrices.peek().getPosition().copy());

RenderSystem.disableTexture();
RenderSystem.depthMask(true);
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
RenderSystem.blendFuncSeparate(GlStateManager.class_4535.SRC_ALPHA, GlStateManager.class_4534.ONE_MINUS_SRC_ALPHA, GlStateManager.class_4535.ONE, GlStateManager.class_4534.ONE_MINUS_SRC_ALPHA);
RenderSystem.polygonOffset(3.0F, 3.0F);
RenderSystem.enablePolygonOffset();
client.gameRenderer.getLightmapTextureManager().enable();

models.forEach((renderPair) -> {
SpecialModelRenderer modelRenderer = renderPair.getFirst();
BakedModel model = renderPair.getSecond();

ShaderProgram shader = LimlibRender.LOADED_SHADERS.get(modelRenderer);
RenderSystem.setShader(() -> shader);
modelRenderer.setup(matrix, shader);

if (shader.getUniform("renderAsEntity") != null) {
shader.getUniform("renderAsEntity").setFloat(0.0F);
}

BufferBuilder bufferBuilder = Tessellator.getInstance().getBufferBuilder();
bufferBuilder.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);

RandomGenerator random = RandomGenerator.createLegacy(state.getRenderingSeed(pos));

client.getBlockRenderManager().getModelRenderer().render(world, model, state, pos, matrix, bufferBuilder, true, random, state.getRenderingSeed(pos), OverlayTexture.DEFAULT_UV);

BufferRenderer.drawWithShader(bufferBuilder.end());
});

client.gameRenderer.getLightmapTextureManager().disable();
RenderSystem.polygonOffset(0.0F, 0.0F);
RenderSystem.disablePolygonOffset();
RenderSystem.disableBlend();
RenderSystem.enableTexture();

matrices.pop();
} else {
dontCheckStates.add(state);
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion limlib_world/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.1.0
version=7.2.0
maven_group=net.ludocrypt
archives_base_name=limlib-world

0 comments on commit 1d90316

Please sign in to comment.