diff --git a/src/main/java/me/cortex/voxy/client/VoxyClient.java b/src/main/java/me/cortex/voxy/client/VoxyClient.java index 033c3a5c..559b840b 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyClient.java +++ b/src/main/java/me/cortex/voxy/client/VoxyClient.java @@ -1,5 +1,7 @@ package me.cortex.voxy.client; +import me.cortex.voxy.client.core.IGetVoxyRenderSystem; +import me.cortex.voxy.client.core.VoxyRenderSystem; import me.cortex.voxy.client.core.gl.Capabilities; import me.cortex.voxy.client.core.model.bakery.BudgetBufferRenderer; import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer; @@ -8,8 +10,16 @@ import me.cortex.voxy.commonImpl.VoxyCommon; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.debug.DebugScreenDisplayer; import net.minecraft.client.gui.components.debug.DebugScreenEntries; +import net.minecraft.client.gui.components.debug.DebugScreenEntry; import net.minecraft.resources.Identifier; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.chunk.LevelChunk; +import org.jspecify.annotations.Nullable; + import java.util.HashSet; import java.util.function.Consumer; import java.util.function.Function; @@ -43,6 +53,27 @@ public class VoxyClient implements ClientModInitializer { @Override public void onInitializeClient() { + DebugScreenEntries.register(Identifier.fromNamespaceAndPath("voxy", "version"), new DebugScreenEntry() { + @Override + public void display(DebugScreenDisplayer lines, @Nullable Level level, @Nullable LevelChunk levelChunk, @Nullable LevelChunk levelChunk2) { + if (!VoxyCommon.isAvailable()) { + lines.addLine(ChatFormatting.RED + "voxy-"+VoxyCommon.MOD_VERSION);//Voxy installed, not avalible + return; + } + var instance = VoxyCommon.getInstance(); + if (instance == null) { + lines.addLine(ChatFormatting.YELLOW + "voxy-" + VoxyCommon.MOD_VERSION);//Voxy avalible, no instance active + return; + } + VoxyRenderSystem vrs = null; + var wr = Minecraft.getInstance().levelRenderer; + if (wr != null) vrs = ((IGetVoxyRenderSystem) wr).getVoxyRenderSystem(); + + //Voxy instance active + lines.addLine((vrs==null?ChatFormatting.DARK_GREEN:ChatFormatting.GREEN)+"voxy-"+VoxyCommon.MOD_VERSION); + } + }); + DebugScreenEntries.register(Identifier.fromNamespaceAndPath("voxy","debug"), new VoxyDebugScreenEntry()); ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { if (VoxyCommon.isAvailable()) { diff --git a/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java b/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java index f452e9eb..36f75016 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java +++ b/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java @@ -19,21 +19,18 @@ public class VoxyDebugScreenEntry implements DebugScreenEntry { @Override public void display(DebugScreenDisplayer lines, @Nullable Level world, @Nullable LevelChunk clientChunk, @Nullable LevelChunk chunk) { if (!VoxyCommon.isAvailable()) { - lines.addLine(ChatFormatting.RED + "voxy-"+VoxyCommon.MOD_VERSION);//Voxy installed, not avalible return; } + var instance = VoxyCommon.getInstance(); if (instance == null) { - lines.addLine(ChatFormatting.YELLOW + "voxy-" + VoxyCommon.MOD_VERSION);//Voxy avalible, no instance active return; } + VoxyRenderSystem vrs = null; var wr = Minecraft.getInstance().levelRenderer; if (wr != null) vrs = ((IGetVoxyRenderSystem) wr).getVoxyRenderSystem(); - //Voxy instance active - lines.addLine((vrs==null?ChatFormatting.DARK_GREEN:ChatFormatting.GREEN)+"voxy-"+VoxyCommon.MOD_VERSION); - //lines.addLineToSection(); List instanceLines = new ArrayList<>(); instance.addDebug(instanceLines); diff --git a/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinDebugScreenEntryList.java b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinDebugScreenEntryList.java new file mode 100644 index 00000000..66f30264 --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/mixin/minecraft/MixinDebugScreenEntryList.java @@ -0,0 +1,28 @@ +package me.cortex.voxy.client.mixin.minecraft; + +import net.minecraft.client.gui.components.debug.DebugScreenEntryList; +import net.minecraft.resources.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(DebugScreenEntryList.class) +public abstract class MixinDebugScreenEntryList { + @Shadow @Final private List currentlyEnabled; + @Shadow public abstract boolean isOverlayVisible(); + + @Inject(method = "rebuildCurrentList", at = @At(value = "INVOKE", target = "Ljava/util/List;sort(Ljava/util/Comparator;)V")) + private void voxy$injectVersionDisplay(CallbackInfo cir) { + if (this.isOverlayVisible()) { + var id = Identifier.fromNamespaceAndPath("voxy", "version"); + if (!this.currentlyEnabled.contains(id)) { + this.currentlyEnabled.add(id); + } + } + } +} diff --git a/src/main/resources/client.voxy.mixins.json b/src/main/resources/client.voxy.mixins.json index 7fc41118..b79aee4e 100644 --- a/src/main/resources/client.voxy.mixins.json +++ b/src/main/resources/client.voxy.mixins.json @@ -21,6 +21,7 @@ "minecraft.MixinClientCommonPacketListenerImpl", "minecraft.MixinClientLevel", "minecraft.MixinClientPacketListener", + "minecraft.MixinDebugScreenEntryList", "minecraft.MixinFogRenderer", "minecraft.MixinGlDebug", "minecraft.MixinLevelRenderer",