diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-03-29 23:12:14 -0700 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2023-03-29 23:12:14 -0700 |
commit | 81ee44c7b9297e24cf7b3e8be3452d06d4d7a7ac (patch) | |
tree | ce0352c615677bd5b9bebfcdfbca1a72bd6ebc6d /src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java | |
parent | b0d1aa6d5076738965f1f0fd9df98c6cd5bf946f (diff) | |
download | Iceberg-81ee44c7b9297e24cf7b3e8be3452d06d4d7a7ac.tar.gz Iceberg-81ee44c7b9297e24cf7b3e8be3452d06d4d7a7ac.tar.bz2 Iceberg-81ee44c7b9297e24cf7b3e8be3452d06d4d7a7ac.zip |
Fixed several 3d item preview issues.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java index b8f5fde..e0ae33a 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java +++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java @@ -1,20 +1,58 @@ package com.anthonyhilyard.iceberg.renderer; +import org.apache.commons.lang3.exception.ExceptionUtils; + +import com.anthonyhilyard.iceberg.Loader; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.impl.util.version.VersionPredicateParser; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -public final class CheckedBufferSource implements MultiBufferSource +public class CheckedBufferSource implements MultiBufferSource { - private boolean hasRendered = false; - private final MultiBufferSource bufferSource; + protected boolean hasRendered = false; + protected final MultiBufferSource bufferSource; + + private static Boolean useSodiumVersion = null; - public CheckedBufferSource(MultiBufferSource bufferSource) + protected CheckedBufferSource(MultiBufferSource bufferSource) { this.bufferSource = bufferSource; } + public static CheckedBufferSource create(MultiBufferSource bufferSource) + { + if (useSodiumVersion == null) + { + try + { + // If Sodium 0.4.9 is installed, use the Sodium implementation. + useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicateParser.parse("0.4.9").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion()); + } + catch (Exception e) + { + Loader.LOGGER.error(ExceptionUtils.getStackTrace(e)); + } + } + + if (useSodiumVersion) + { + // Instantiate the Sodium implementation using reflection. + try + { + return (CheckedBufferSource) Class.forName("com.anthonyhilyard.iceberg.renderer.CheckedBufferSourceSodium").getDeclaredConstructor(MultiBufferSource.class).newInstance(bufferSource); + } + catch (Exception e) + { + Loader.LOGGER.error(ExceptionUtils.getStackTrace(e)); + } + } + + return new CheckedBufferSource(bufferSource); + } + @Override public VertexConsumer getBuffer(RenderType renderType) { @@ -65,4 +103,4 @@ public final class CheckedBufferSource implements MultiBufferSource { hasRendered = false; } -}
\ No newline at end of file +} |