Skip to content

Commit

Permalink
Fix compat with Forge events
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed May 6, 2024
1 parent 990b254 commit c2af47b
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 83 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = VanillaHUD
mod_id = vanillahud
mod_version = 2.2.0
mod_version = 2.2.1
mod_archives_name=VanillaHUD

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
Expand Down
3 changes: 2 additions & 1 deletion src/dummy/java/club/sk1er/patcher/config/PatcherConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.sk1er.patcher.config;

public class PatcherConfig {

public static boolean tabHeightAllow;
public static int tabHeight;
}
55 changes: 54 additions & 1 deletion src/main/java/org/polyfrost/vanillahud/VanillaHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import Apec.Components.Gui.GuiIngame.ApecGuiIngameForge;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.events.event.TickEvent;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.libs.universal.UMinecraft;
import cc.polyfrost.oneconfig.utils.Notifications;
import net.minecraft.client.Minecraft;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.common.Loader;
import org.polyfrost.vanillahud.config.ModConfig;
import org.polyfrost.vanillahud.hud.*;
import org.polyfrost.vanillahud.utils.TabListManager;

import java.util.ArrayList;
Expand All @@ -20,12 +26,16 @@ public class VanillaHUD {
public static ModConfig modConfig;
private static boolean apec = false;
public static boolean isPatcher = false;
private static boolean isSBA = false;
private static boolean inSkyblock = false;
public static ArrayList<Mod> mods = new ArrayList<>();
private int tickAmount = 0;

@net.minecraftforge.fml.common.Mod.EventHandler
public void onFMLInitialization(net.minecraftforge.fml.common.event.FMLInitializationEvent event) {
modConfig = new ModConfig();
TabListManager.asyncUpdateList();
EventManager.INSTANCE.register(this);
}

@net.minecraftforge.fml.common.Mod.EventHandler
Expand All @@ -39,9 +49,52 @@ public void onPostInit(net.minecraftforge.fml.common.event.FMLPostInitialization
}
apec = Loader.isModLoaded("apec");
isPatcher = Loader.isModLoaded("patcher");
isSBA = Loader.isModLoaded("skyblockaddons") || Loader.isModLoaded("sbaunofficial");
}

@Subscribe
private void onTick(TickEvent event) {
if (event.stage == Stage.START) {
tickAmount++;
if (tickAmount % 20 == 0) {
if (UMinecraft.getPlayer() != null) {
Minecraft mc = Minecraft.getMinecraft();
if (mc != null && mc.theWorld != null && !mc.isSingleplayer()) {
ScoreObjective scoreboardObj = mc.theWorld.getScoreboard().getObjectiveInDisplaySlot(1);
if (scoreboardObj != null) {
String scObjName = cleanSB(scoreboardObj.getDisplayName());
if (scObjName.contains("SKYBLOCK")) {
inSkyblock = true;
return;
}
}
}
inSkyblock = false;
}

tickAmount = 0;
}
}
}

private static String cleanSB(String scoreboard) {
char[] nvString = StringUtils.stripControlCodes(scoreboard).toCharArray();
StringBuilder cleaned = new StringBuilder();

for (char c : nvString) {
if ((int) c > 20 && (int) c < 127) {
cleaned.append(c);
}
}

return cleaned.toString();
}

public static boolean isApec() {
return apec && Minecraft.getMinecraft().ingameGUI instanceof ApecGuiIngameForge;
}

public static boolean inSBASkyblock() {
return inSkyblock && isSBA;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.EntityRenderer;
import org.polyfrost.vanillahud.VanillaHUD;
import org.polyfrost.vanillahud.hud.TabList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -13,6 +14,9 @@
public class EntityRendererMixin {
@Inject(method = "updateCameraAndRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiIngame;renderGameOverlay(F)V", shift = At.Shift.AFTER))
private void draw(float partialTicks, long nanoTime, CallbackInfo ci) {
if (VanillaHUD.inSBASkyblock()) {
return;
}
TabList.isGuiIngame = false;
((GuiIngameForgeAccessor) Minecraft.getMinecraft().ingameGUI).drawPlayerList(UResolution.getScaledWidth(), UResolution.getScaledHeight());
}
Expand Down
Loading

0 comments on commit c2af47b

Please sign in to comment.