From 1d90316722b0b79b8b72f2819eebfa26f26f3a1b Mon Sep 17 00:00:00 2001 From: LudoCrypt <60561627+LudoCrypt@users.noreply.github.com> Date: Thu, 29 Dec 2022 10:43:55 -0600 Subject: [PATCH] Sodium support??? + update????? --- gradle.properties | 2 +- limlib_effects/gradle.properties | 2 +- limlib_registry/gradle.properties | 2 +- limlib_render/gradle.properties | 2 +- .../mixin/render/WorldRendererMixin.java | 73 +++++++++++++++++++ limlib_world/gradle.properties | 2 +- 6 files changed, 78 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index b6790b8..53ea1c5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file diff --git a/limlib_effects/gradle.properties b/limlib_effects/gradle.properties index 340a7bf..058861a 100644 --- a/limlib_effects/gradle.properties +++ b/limlib_effects/gradle.properties @@ -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 \ No newline at end of file diff --git a/limlib_registry/gradle.properties b/limlib_registry/gradle.properties index 2c49487..2f0d551 100644 --- a/limlib_registry/gradle.properties +++ b/limlib_registry/gradle.properties @@ -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 \ No newline at end of file diff --git a/limlib_render/gradle.properties b/limlib_render/gradle.properties index 29c8fe0..912840e 100644 --- a/limlib_render/gradle.properties +++ b/limlib_render/gradle.properties @@ -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 \ No newline at end of file diff --git a/limlib_render/src/main/java/net/ludocrypt/limlib/render/mixin/render/WorldRendererMixin.java b/limlib_render/src/main/java/net/ludocrypt/limlib/render/mixin/render/WorldRendererMixin.java index cbb691f..b59b8c8 100644 --- a/limlib_render/src/main/java/net/ludocrypt/limlib/render/mixin/render/WorldRendererMixin.java +++ b/limlib_render/src/main/java/net/ludocrypt/limlib/render/mixin/render/WorldRendererMixin.java @@ -1,5 +1,6 @@ package net.ludocrypt.limlib.render.mixin.render; +import java.util.List; import java.util.Optional; import org.spongepowered.asm.mixin.Final; @@ -7,15 +8,23 @@ 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; @@ -23,13 +32,16 @@ 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; @@ -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 { @@ -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 iterable = BlockPos.iterateOutwards(client.player.getBlockPos(), 10, 10, 10); + List dontCheckStates = Lists.newArrayList(); + + for (BlockPos pos : iterable) { + BlockState state = world.getBlockState(pos); + if (!dontCheckStates.contains(state)) { + List> 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); + } + } + } } } diff --git a/limlib_world/gradle.properties b/limlib_world/gradle.properties index d2ac178..ebd4f9a 100644 --- a/limlib_world/gradle.properties +++ b/limlib_world/gradle.properties @@ -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 \ No newline at end of file