From 3e9aac3fe11ee549dced40923bc16846b72bf632 Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sat, 3 Aug 2024 03:02:01 +0200 Subject: [PATCH] Migrate BossOverlay/fix ids --- .../exordium/access/BossOverlayAccess.java | 12 ++++ .../exordium/access/VanillaBufferAccess.java | 12 ---- .../exordium/components/BufferManager.java | 20 ++----- .../vanilla/BossHealthBarComponent.java | 35 ++++++++++++ .../vanilla/PlayerListComponent.java | 2 +- .../components/vanilla/VignetteComponent.java | 2 +- .../mixin/BossHealthOverlayMixin.java | 57 ++----------------- .../dev/tr7zw/exordium/mixin/GuiMixin.java | 15 ++--- 8 files changed, 65 insertions(+), 90 deletions(-) create mode 100644 src/main/java/dev/tr7zw/exordium/access/BossOverlayAccess.java delete mode 100644 src/main/java/dev/tr7zw/exordium/access/VanillaBufferAccess.java create mode 100644 src/main/java/dev/tr7zw/exordium/components/vanilla/BossHealthBarComponent.java diff --git a/src/main/java/dev/tr7zw/exordium/access/BossOverlayAccess.java b/src/main/java/dev/tr7zw/exordium/access/BossOverlayAccess.java new file mode 100644 index 0000000..e7ecf0c --- /dev/null +++ b/src/main/java/dev/tr7zw/exordium/access/BossOverlayAccess.java @@ -0,0 +1,12 @@ +package dev.tr7zw.exordium.access; + +import java.util.Map; +import java.util.UUID; + +import net.minecraft.client.gui.components.LerpingBossEvent; + +public interface BossOverlayAccess { + + Map getEvents(); + +} diff --git a/src/main/java/dev/tr7zw/exordium/access/VanillaBufferAccess.java b/src/main/java/dev/tr7zw/exordium/access/VanillaBufferAccess.java deleted file mode 100644 index fd803c9..0000000 --- a/src/main/java/dev/tr7zw/exordium/access/VanillaBufferAccess.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.tr7zw.exordium.access; - -import dev.tr7zw.exordium.render.LegacyBuffer; -import net.minecraft.client.gui.GuiGraphics; - -public interface VanillaBufferAccess { - - interface BossHealthOverlayAccess extends VanillaBufferAccess { - LegacyBuffer getHotbarOverlayBuffer(); - } - -} diff --git a/src/main/java/dev/tr7zw/exordium/components/BufferManager.java b/src/main/java/dev/tr7zw/exordium/components/BufferManager.java index 8d71ceb..7089126 100644 --- a/src/main/java/dev/tr7zw/exordium/components/BufferManager.java +++ b/src/main/java/dev/tr7zw/exordium/components/BufferManager.java @@ -5,11 +5,13 @@ import java.util.function.Supplier; import dev.tr7zw.exordium.ExordiumModBase; +import dev.tr7zw.exordium.components.vanilla.BossHealthBarComponent; import dev.tr7zw.exordium.components.vanilla.ChatComponent; import dev.tr7zw.exordium.components.vanilla.CrosshairComponent; import dev.tr7zw.exordium.components.vanilla.DebugOverlayComponent; import dev.tr7zw.exordium.components.vanilla.ExperienceComponent; import dev.tr7zw.exordium.components.vanilla.HotbarComponent; +import dev.tr7zw.exordium.components.vanilla.PlayerListComponent; import dev.tr7zw.exordium.components.vanilla.ScoreboardComponent; import dev.tr7zw.exordium.components.vanilla.VignetteComponent; import dev.tr7zw.exordium.versionless.config.Config; @@ -33,23 +35,9 @@ public void initialize() { registerBuffer(ScoreboardComponent.getId(), new ScoreboardComponent(), () -> inst.config.scoreboardSettings); registerBuffer(HotbarComponent.getId(), new HotbarComponent(), () -> inst.config.hotbarSettings); registerBuffer(ChatComponent.getId(), new ChatComponent(), () -> inst.config.chatSettings); + registerBuffer(PlayerListComponent.getId(), new PlayerListComponent(), () -> inst.config.tablistSettings); + registerBuffer(BossHealthBarComponent.getId(), new BossHealthBarComponent(), () -> inst.config.bossbarSettings); -// registerCustomHandler(new ResourceLocation("player_list"), data -> { -// GuiAccess guiAccess = (GuiAccess) minecraft.gui; -// TablistAccess tablistAccess = (TablistAccess) guiAccess.getPlayerTabOverlay(); -// Scoreboard scoreboard = minecraft.level.getScoreboard(); -// tablistAccess.updateState(scoreboard, scoreboard.getDisplayObjective(DisplaySlot.LIST)); -// BufferedComponent bufferedComponent = tablistAccess.getPlayerListOverlayBuffer(); -// if (bufferedComponent.render()) { -// data.cancel().set(true); -// } -// }); -// registerCustomEndHandler(new ResourceLocation("player_list"), () -> { -// GuiAccess guiAccess = (GuiAccess) minecraft.gui; -// TablistAccess tabAccess = (TablistAccess) guiAccess.getPlayerTabOverlay(); -// BufferedComponent bufferedComponent = tabAccess.getPlayerListOverlayBuffer(); -// bufferedComponent.renderEnd(); -// }); } @SuppressWarnings("unchecked") diff --git a/src/main/java/dev/tr7zw/exordium/components/vanilla/BossHealthBarComponent.java b/src/main/java/dev/tr7zw/exordium/components/vanilla/BossHealthBarComponent.java new file mode 100644 index 0000000..369c5f8 --- /dev/null +++ b/src/main/java/dev/tr7zw/exordium/components/vanilla/BossHealthBarComponent.java @@ -0,0 +1,35 @@ +package dev.tr7zw.exordium.components.vanilla; + +import java.util.Map; +import java.util.UUID; + +import dev.tr7zw.exordium.access.BossEventBufferAccess; +import dev.tr7zw.exordium.access.BossOverlayAccess; +import dev.tr7zw.exordium.components.BufferComponent; +import dev.tr7zw.util.NMSHelper; +import lombok.Getter; +import net.minecraft.client.gui.components.LerpingBossEvent; +import net.minecraft.resources.ResourceLocation; + +public class BossHealthBarComponent implements BufferComponent { + + @Getter + private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "boss_bar"); + + @Override + public void captureState(BossOverlayAccess context) { + for (LerpingBossEvent value : context.getEvents().values()) { + ((BossEventBufferAccess) value).exordium_captureState(); + } + } + + @Override + public boolean hasChanged(int tickCount, BossOverlayAccess context) { + for (LerpingBossEvent value : context.getEvents().values()) { + if (((BossEventBufferAccess) value).exordium_needsRender()) + return true; + } + return false; + } + +} diff --git a/src/main/java/dev/tr7zw/exordium/components/vanilla/PlayerListComponent.java b/src/main/java/dev/tr7zw/exordium/components/vanilla/PlayerListComponent.java index aa53609..c2843cf 100644 --- a/src/main/java/dev/tr7zw/exordium/components/vanilla/PlayerListComponent.java +++ b/src/main/java/dev/tr7zw/exordium/components/vanilla/PlayerListComponent.java @@ -26,7 +26,7 @@ public class PlayerListComponent private static final Minecraft minecraft = Minecraft.getInstance(); @Getter - private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "crosshair"); + private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "player_list"); private List playerInfoHashes = new ArrayList<>(); private int headerHash = 0; diff --git a/src/main/java/dev/tr7zw/exordium/components/vanilla/VignetteComponent.java b/src/main/java/dev/tr7zw/exordium/components/vanilla/VignetteComponent.java index 0ea06d6..c19a9e9 100644 --- a/src/main/java/dev/tr7zw/exordium/components/vanilla/VignetteComponent.java +++ b/src/main/java/dev/tr7zw/exordium/components/vanilla/VignetteComponent.java @@ -11,7 +11,7 @@ public class VignetteComponent implements BufferComponent { private static final Minecraft MINECRAFT = Minecraft.getInstance(); @Getter - private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "crosshair"); + private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "vignette"); private float exordium_state = 0f; private float exordium_lastVignetteBrightness = 1.0F; diff --git a/src/main/java/dev/tr7zw/exordium/mixin/BossHealthOverlayMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/BossHealthOverlayMixin.java index 77da483..36bc6ea 100644 --- a/src/main/java/dev/tr7zw/exordium/mixin/BossHealthOverlayMixin.java +++ b/src/main/java/dev/tr7zw/exordium/mixin/BossHealthOverlayMixin.java @@ -6,67 +6,18 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import dev.tr7zw.exordium.ExordiumModBase; -import dev.tr7zw.exordium.access.BossEventBufferAccess; -import dev.tr7zw.exordium.access.VanillaBufferAccess; -import dev.tr7zw.exordium.render.LegacyBuffer; +import dev.tr7zw.exordium.access.BossOverlayAccess; +import lombok.Getter; import net.minecraft.client.gui.components.BossHealthOverlay; import net.minecraft.client.gui.components.LerpingBossEvent; -import net.minecraft.network.protocol.game.ClientboundBossEventPacket; @Mixin(BossHealthOverlay.class) -public class BossHealthOverlayMixin implements VanillaBufferAccess.BossHealthOverlayAccess { - /* - * @WrapOperation(method = "render", at = @At(value = "INVOKE", target = - * "Lnet/minecraft/client/gui/components/BossHealthOverlay;drawBar(Lnet/minecraft/client/gui/GuiGraphics;IILnet/minecraft/world/BossEvent;)V" - * )) private void wrapBossHealthDrawBar(BossHealthOverlay overlay, GuiGraphics - * guiGraphics, int i, int j, BossEvent event, final Operation operation) - * { BufferedComponent buffer = ((BossEventBufferAccess) - * event).exordium_getBuffered(); - * - * if (!buffer.render()) { operation.call(overlay, guiGraphics, i, j, event); } - * buffer.renderEnd(); } - */ +public class BossHealthOverlayMixin implements BossOverlayAccess { @Shadow @Final + @Getter private Map events; - @Unique - private final LegacyBuffer chatBufferedComponent = new LegacyBuffer( - () -> ExordiumModBase.instance.config.bossbarSettings) { - @Override - public boolean shouldRenderNextCappedFrame() { - for (LerpingBossEvent value : BossHealthOverlayMixin.this.events.values()) { - if (((BossEventBufferAccess) value).exordium_needsRender()) - return true; - } - return false; - } - - @Override - public void captureState() { - for (LerpingBossEvent value : BossHealthOverlayMixin.this.events.values()) { - ((BossEventBufferAccess) value).exordium_captureState(); - } - } - }; - - @Unique - boolean outdated = false; - - @Override - public LegacyBuffer getHotbarOverlayBuffer() { - return chatBufferedComponent; - } - - @Inject(method = "update", at = @At("RETURN")) - private void onUpdate(ClientboundBossEventPacket packet, CallbackInfo ci) { - outdated = true; - } } diff --git a/src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java b/src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java index a8ac931..8af9af1 100644 --- a/src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java +++ b/src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java @@ -10,14 +10,14 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import dev.tr7zw.exordium.ExordiumModBase; +import dev.tr7zw.exordium.access.BossOverlayAccess; import dev.tr7zw.exordium.access.ChatAccess; import dev.tr7zw.exordium.access.GuiAccess; import dev.tr7zw.exordium.access.TablistAccess; -import dev.tr7zw.exordium.access.VanillaBufferAccess; import dev.tr7zw.exordium.components.BufferInstance; +import dev.tr7zw.exordium.components.vanilla.BossHealthBarComponent; import dev.tr7zw.exordium.components.vanilla.PlayerListComponent; import dev.tr7zw.exordium.components.vanilla.PlayerListComponent.PlayerListContext; -import dev.tr7zw.exordium.render.LegacyBuffer; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.BossHealthOverlay; @@ -68,13 +68,14 @@ private void renderTablistWrapper(PlayerTabOverlay instance, GuiGraphics guiGrap @WrapOperation(method = "method_55808", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/BossHealthOverlay;render(Lnet/minecraft/client/gui/GuiGraphics;)V")) private void renderBossBarWrapper(BossHealthOverlay instance, GuiGraphics guiGraphics, Operation original) { - VanillaBufferAccess.BossHealthOverlayAccess overlayAccess = (VanillaBufferAccess.BossHealthOverlayAccess) this - .getBossOverlay(); - LegacyBuffer hotbarOverlayBuffer = overlayAccess.getHotbarOverlayBuffer(); - if (!hotbarOverlayBuffer.render()) { + BossOverlayAccess overlayAccess = (BossOverlayAccess) this.getBossOverlay(); + @SuppressWarnings("unchecked") + BufferInstance buffer = ExordiumModBase.instance.getBufferManager() + .getBufferInstance(BossHealthBarComponent.getId(), BossOverlayAccess.class); + if (!buffer.renderBuffer(tickCount, overlayAccess)) { original.call(instance, guiGraphics); } - hotbarOverlayBuffer.renderEnd(); + buffer.postRender(overlayAccess); } @Inject(method = "render", at = @At(value = "TAIL"))