Skip to content

Commit

Permalink
Migrate BossOverlay/fix ids
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Aug 3, 2024
1 parent 24d3b63 commit 3e9aac3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 90 deletions.
12 changes: 12 additions & 0 deletions src/main/java/dev/tr7zw/exordium/access/BossOverlayAccess.java
Original file line number Diff line number Diff line change
@@ -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<UUID, LerpingBossEvent> getEvents();

}
12 changes: 0 additions & 12 deletions src/main/java/dev/tr7zw/exordium/access/VanillaBufferAccess.java

This file was deleted.

20 changes: 4 additions & 16 deletions src/main/java/dev/tr7zw/exordium/components/BufferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BossOverlayAccess> {

@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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> playerInfoHashes = new ArrayList<>();
private int headerHash = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class VignetteComponent implements BufferComponent<Float> {

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;
Expand Down
57 changes: 4 additions & 53 deletions src/main/java/dev/tr7zw/exordium/mixin/BossHealthOverlayMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> 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<UUID, LerpingBossEvent> 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;
}
}
15 changes: 8 additions & 7 deletions src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Void> original) {
VanillaBufferAccess.BossHealthOverlayAccess overlayAccess = (VanillaBufferAccess.BossHealthOverlayAccess) this
.getBossOverlay();
LegacyBuffer hotbarOverlayBuffer = overlayAccess.getHotbarOverlayBuffer();
if (!hotbarOverlayBuffer.render()) {
BossOverlayAccess overlayAccess = (BossOverlayAccess) this.getBossOverlay();
@SuppressWarnings("unchecked")
BufferInstance<BossOverlayAccess> 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"))
Expand Down

0 comments on commit 3e9aac3

Please sign in to comment.