diff --git a/common/src/api/java/dev/vexor/radium/frapi/impl/renderer/VanillaModelEncoder.java b/common/src/api/java/dev/vexor/radium/frapi/impl/renderer/VanillaModelEncoder.java index 582f2ca0..d7d604ec 100644 --- a/common/src/api/java/dev/vexor/radium/frapi/impl/renderer/VanillaModelEncoder.java +++ b/common/src/api/java/dev/vexor/radium/frapi/impl/renderer/VanillaModelEncoder.java @@ -16,15 +16,19 @@ package dev.vexor.radium.frapi.impl.renderer; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Predicate; import java.util.function.Supplier; +import java.util.stream.Collectors; import dev.vexor.radium.compat.mojang.minecraft.random.RandomSource; import net.legacyfabric.fabric.api.util.TriState; +import net.minecraft.block.*; import org.jetbrains.annotations.Nullable; -import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.util.math.Direction; @@ -42,29 +46,76 @@ public class VanillaModelEncoder { private static final RenderMaterial STANDARD_MATERIAL = Renderer.get().materialFinder().shadeMode(ShadeMode.VANILLA).find(); private static final RenderMaterial NO_AO_MATERIAL = Renderer.get().materialFinder().shadeMode(ShadeMode.VANILLA).ambientOcclusion(TriState.FALSE).find(); - public static void emitBlockQuads(QuadEmitter emitter, BakedModel model, @Nullable BlockState state, Predicate<@Nullable Direction> cullTest) { - final RenderMaterial defaultMaterial = model.useAmbientOcclusion() ? STANDARD_MATERIAL : NO_AO_MATERIAL; + public static void emitBlockQuads(QuadEmitter emitter, BakedModel model, @Nullable BlockState state, Predicate<@Nullable Direction> cullTest) { + final RenderMaterial defaultMaterial = model.useAmbientOcclusion() ? STANDARD_MATERIAL : NO_AO_MATERIAL; - for (int i = 0; i <= ModelHelper.NULL_FACE_ID; i++) { - final Direction cullFace = ModelHelper.faceFromIndex(i); + for (int i = 0; i <= ModelHelper.NULL_FACE_ID; i++) { + final Direction cullFace = ModelHelper.faceFromIndex(i); - if (cullTest.test(cullFace)) { - // Skip entire quad list if possible. - continue; - } + if (cullTest.test(cullFace)) { + continue; + } - final List quads; + final List quads; if (cullFace != null) { quads = model.getByDirection(cullFace); } else { quads = model.getQuads(); } - - for (final BakedQuad quad : quads) { - emitter.fromVanilla(quad, defaultMaterial, cullFace); - emitter.emit(); + + Set allowedFaces = Arrays.stream(Direction.values()).collect(Collectors.toSet()); + + for (Class clazz : FILTER) { + if (clazz.isInstance(state.getBlock())) { + allowedFaces = findAllowedFaces(quads); + break; + } + } + + if (cullFace != null) { + for (final BakedQuad quad : quads) { + emitter.fromVanilla(quad, defaultMaterial, cullFace); + emitter.emit(); + } + } else { + for (final BakedQuad quad : quads) { + if (allowedFaces.contains(quad.getFace())) { + emitter.fromVanilla(quad, defaultMaterial, cullFace); + emitter.emit(); + } + } + } + } + } + + /** + * Finds allowed faces from a list of baked quads + * + * @param quads quads to find the allowed faces from + * @return the allowed faces + */ + private static Set findAllowedFaces(List quads) { + Set allowedFaces = new HashSet<>(); + + for (BakedQuad quad : quads) { + Direction faceDirection = quad.getFace(); + + if (faceDirection == Direction.NORTH || faceDirection == Direction.SOUTH) { + if (!allowedFaces.contains(Direction.NORTH)) { + allowedFaces.add(Direction.NORTH); + } + } else if (faceDirection == Direction.WEST || faceDirection == Direction.EAST) { + if (!allowedFaces.contains(Direction.EAST)) { + allowedFaces.add(Direction.EAST); + } + } else { + allowedFaces.add(faceDirection); } - } - } + } + + return allowedFaces; + } + + private static final Class[] FILTER = { PlantBlock.class, Growable.class, GrassBlock.class }; } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/gl/device/GLRenderDevice.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/gl/device/GLRenderDevice.java index 93dd30d7..b43e7091 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/gl/device/GLRenderDevice.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/gl/device/GLRenderDevice.java @@ -39,8 +39,6 @@ public void makeActive() { this.stateTracker.clear(); this.isActive = true; - - GlStateManager.disableCull(); } @Override diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/light/data/LightDataAccess.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/light/data/LightDataAccess.java index d247b50b..fa4647c7 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/model/light/data/LightDataAccess.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/model/light/data/LightDataAccess.java @@ -69,7 +69,7 @@ protected int compute(int x, int y, int z) { boolean em = block.getLightLevel() != 0; boolean op = block.isFullBlock() || block.getOpacity() != 0; boolean fo = block.isNormalBlock(); - boolean fc = block.renderAsNormalBlock(); + boolean fc = block.isFullCube(); int lu = state.getBlock().getLightLevel(); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/SodiumWorldRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/SodiumWorldRenderer.java index 066f8dac..ce701b38 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/SodiumWorldRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/SodiumWorldRenderer.java @@ -96,9 +96,9 @@ public void setLevel(ClientWorld level) { } // If we have a level is already loaded, unload the renderer - // if (this.level != null) { - // this.unloadLevel(); - // } + if (this.level != null) { + this.unloadLevel(); + } // If we're loading a new level, load the renderer if (level != null) { @@ -249,6 +249,8 @@ private void processChunkEvents() { * Performs a render pass for the given {@link RenderLayer} and draws all visible chunks for it. */ public void drawChunkLayer(RenderLayer renderLayer, ChunkRenderMatrices matrices, double x, double y, double z) { + GlStateManager.disableCull(); + this.renderSectionManager.renderLayer(matrices, DefaultTerrainRenderPasses.fromLayer(renderLayer), x, y, z); } diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java index 1e160206..eb3f2df7 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/pipeline/BlockRenderer.java @@ -28,6 +28,7 @@ import net.legacyfabric.fabric.api.util.TriState; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.FlowerBlock; import net.minecraft.client.render.model.BakedModel; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; @@ -70,7 +71,6 @@ public void release() { public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockPos origin) { this.state = state; this.pos = pos; - this.randomSeed = 42L; this.posOffset.set(origin.getX(), origin.getY(), origin.getZ()); diff --git a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java index 72af4048..cb93cafc 100644 --- a/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java +++ b/common/src/main/java/net/caffeinemc/mods/sodium/client/render/frapi/render/AbstractBlockRenderContext.java @@ -2,6 +2,7 @@ import dev.vexor.radium.compat.mojang.minecraft.random.RandomSource; import dev.vexor.radium.compat.mojang.minecraft.render.LightTexture; +import dev.vexor.radium.frapi.api.renderer.v1.material.BlendMode; import net.caffeinemc.mods.sodium.client.model.light.LightMode; import net.caffeinemc.mods.sodium.client.model.light.LightPipeline; import net.caffeinemc.mods.sodium.client.model.light.LightPipelineProvider;