Use WorldRenderEvents if available (#680)
* Use WorldRenderEvents if available Fixes an issue when Canvas is installed * Improve code * Depend only on fabric-rendering-v1 * Use fabricApi.module
This commit is contained in:
1 parent
a83548876a
commit
566d2a7bca
5 files changed
+50
-6
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package carpet.utils;
|
||||
|
||||
import carpet.network.CarpetClient;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.SemanticVersion;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
import net.fabricmc.loader.api.VersionParsingException;
|
||||
|
||||
public class FabricAPIHooks {
|
||||
|
||||
public static final boolean WORLD_RENDER_EVENTS = hasMod("fabric-rendering-v1", "1.5.0");
|
||||
|
||||
private FabricAPIHooks() {
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
if (WORLD_RENDER_EVENTS) {
|
||||
WorldRenderEvents.BEFORE_DEBUG_RENDER.register(context -> {
|
||||
if (CarpetClient.shapes != null) {
|
||||
RenderSystem.pushMatrix();
|
||||
CarpetClient.shapes.render(context.camera(), context.tickDelta());
|
||||
RenderSystem.popMatrix();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasMod(String id, String minimumVersion) {
|
||||
return FabricLoader.getInstance().getModContainer(id).map(m -> {
|
||||
Version version = m.getMetadata().getVersion();
|
||||
|
||||
if (version instanceof SemanticVersion) {
|
||||
try {
|
||||
return ((SemanticVersion) version).compareTo(SemanticVersion.parse(minimumVersion)) >= 0;
|
||||
} catch (VersionParsingException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}).orElse(false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user