Skip to content

Commit

Permalink
fix: splits bar not renderering with lunar client
Browse files Browse the repository at this point in the history
  • Loading branch information
AsoDesu committed Apr 21, 2024
1 parent 9266648 commit d45bce1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/main/java/net/asodev/islandutils/IslandUtilsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import net.asodev.islandutils.modules.plobby.PlobbyFeatures;
import net.asodev.islandutils.modules.plobby.PlobbyJoinCodeCopy;
import net.asodev.islandutils.modules.splits.SplitManager;
import net.asodev.islandutils.modules.splits.ui.SplitUI;
import net.asodev.islandutils.state.Game;
import net.asodev.islandutils.state.MccIslandState;
import net.asodev.islandutils.util.ChatUtils;
import net.asodev.islandutils.util.IslandUtilsCommand;
import net.asodev.islandutils.util.MusicUtil;
import net.asodev.islandutils.util.Utils;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -49,6 +51,10 @@ public void onInitializeClient() {
IslandUtilsCommand.register();
DiscordPresenceUpdator.init();
PlobbyJoinCodeCopy.register();

if (Utils.isLunarClient()) {
SplitUI.setupFallbackRenderer();
}
}

public static void onJoinMCCI(boolean isProduction) {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/net/asodev/islandutils/mixins/BossUIMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.asodev.islandutils.mixins;

import net.asodev.islandutils.modules.splits.ui.SplitUI;
import net.asodev.islandutils.state.MccIslandState;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.BossHealthOverlay;
import net.minecraft.client.gui.components.LerpingBossEvent;
Expand All @@ -11,6 +12,9 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand All @@ -27,7 +31,16 @@ public class BossUIMixin {

@Inject(method = "render", at = @At("HEAD"))
private void render(GuiGraphics guiGraphics, CallbackInfo ci) {
SplitUI.renderInstance(guiGraphics, this.events);
if (!MccIslandState.isOnline()) return;

List<LerpingBossEvent> list = new ArrayList<>(events.values());
Collections.reverse(list);
int size = list.size();
for (LerpingBossEvent event : list) {
if (!event.getName().getString().equals("")) break;
size--;
}
SplitUI.renderInstance(guiGraphics, size);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,9 @@ public DojoSplitUI(LevelTimer timer) {
}

@Override
public void render(GuiGraphics guiGraphics, Collection<LerpingBossEvent> events) {
List<LerpingBossEvent> list = new ArrayList<>(events.stream().toList());
Collections.reverse(list);
int size = list.size();
for (LerpingBossEvent event : list) {
if (!event.getName().getString().equals("")) break;
size--;
}

public void render(GuiGraphics guiGraphics, int bossBars) {
int x = (guiGraphics.guiWidth() / 2) - (MCC_BAR_WIDTH / 2);
int y = Double.valueOf((size * 18.5)).intValue();
int y = Double.valueOf((bossBars * 18.5)).intValue();
guiGraphics.blit(BAR_TEXTURE, x, y, 0, 0, this.width(), this.height());

renderLevelName(guiGraphics, x, y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.asodev.islandutils.modules.splits.ui;

import net.asodev.islandutils.modules.splits.LevelTimer;
import net.asodev.islandutils.util.ChatUtils;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.LerpingBossEvent;

Expand All @@ -9,10 +11,17 @@
import java.util.UUID;

public interface SplitUI {
void render(GuiGraphics guiGraphics, Collection<LerpingBossEvent> events);
void render(GuiGraphics guiGraphics, int bossBars);

public static void renderInstance(GuiGraphics guiGraphics, Map<UUID, LerpingBossEvent> events) {
public static void renderInstance(GuiGraphics guiGraphics, int bossBars) {
LevelTimer instance = LevelTimer.getInstance();
if (instance != null && instance.getUI() != null) instance.getUI().render(guiGraphics, events.values());
if (instance != null && instance.getUI() != null) instance.getUI().render(guiGraphics, bossBars);
}

static void setupFallbackRenderer() {
ChatUtils.debug("Setup fallback renderer for SplitUI");
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
renderInstance(drawContext, 1);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.isxander.yacl3.api.OptionGroup;
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
import net.asodev.islandutils.options.saving.Ignore;
import net.asodev.islandutils.util.Utils;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.chat.Component;

Expand Down Expand Up @@ -41,7 +42,7 @@ public boolean showChannelSwitchers() {
return channelSwitchers;
}
public boolean isDebugMode() {
return debugMode && !FabricLoader.getInstance().isModLoaded("ichor");
return debugMode && !Utils.isLunarClient();
}

@Override
Expand Down Expand Up @@ -86,7 +87,7 @@ public ConfigCategory getCategory() {
.name(Component.translatable("text.autoconfig.islandutils.option.debugMode"))
.description(OptionDescription.of(Component.translatable("text.autoconfig.islandutils.option.debugMode.@Tooltip")))
.controller(TickBoxControllerBuilder::create)
.available(!FabricLoader.getInstance().isModLoaded("ichor")) // disable on lunar client
.available(!Utils.isLunarClient()) // disable on lunar client
.binding(defaults.debugMode, () -> debugMode, value -> this.debugMode = value)
.build();

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/asodev/islandutils/util/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.asodev.islandutils.util;

import net.asodev.islandutils.util.resourcepack.ResourcePackOptions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -91,4 +92,8 @@ public static String calculateSha256(String input) {
}
return output;
}

public static boolean isLunarClient() {
return FabricLoader.getInstance().isModLoaded("ichor");
}
}

0 comments on commit d45bce1

Please sign in to comment.