Skip to content

Commit

Permalink
Fix Chat/Bossbar not hiding, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Jan 24, 2025
1 parent 8ebbb6c commit b46cfff
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 38 deletions.
4 changes: 4 additions & 0 deletions src/main/java/dev/tr7zw/exordium/access/ChatAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public interface ChatAccess {

int getLinesPerPage();

int getTickCount();

void setTickCount(int ticks);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface BufferComponent<T> {

public void captureState(T context);

public boolean hasChanged(int tickCount, T context);
public boolean hasChanged(T context);

public default boolean enabled(Config.ComponentSettings settings) {
return settings.isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public boolean enabled() {
* @param context
* @return
*/
public boolean renderBuffer(int ticks, T context, GuiGraphics guiGraphics) {
public boolean renderBuffer(T context, GuiGraphics guiGraphics) {
if (!enabled()) {
// not enabled, skip
return false;
Expand All @@ -56,7 +56,7 @@ public boolean renderBuffer(int ticks, T context, GuiGraphics guiGraphics) {
return false;
}

boolean updateFrame = buffer.screenChanged() || (pacing.isCooldownOver() && hasUpdate(ticks, context));
boolean updateFrame = buffer.screenChanged() || (pacing.isCooldownOver() && hasUpdate(context));

if (updateFrame) {
// start capturing
Expand All @@ -72,13 +72,13 @@ public boolean renderBuffer(int ticks, T context, GuiGraphics guiGraphics) {
return true;
}

private boolean hasUpdate(int ticks, T context) {
private boolean hasUpdate(T context) {
for (Supplier<Boolean> listener : updateListeners) {
if (listener.get()) {
return true;
}
}
if (component.hasChanged(ticks, context)) {
if (component.hasChanged(context)) {
return true;
}
// nothing changed, so wait the poll rate for the next check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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;
Expand All @@ -15,16 +12,21 @@ public class BossHealthBarComponent implements BufferComponent<BossOverlayAccess

@Getter
private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "boss_bar");
private int amount = 0;

@Override
public void captureState(BossOverlayAccess context) {
amount = context.getEvents().size();
for (LerpingBossEvent value : context.getEvents().values()) {
((BossEventBufferAccess) value).exordium_captureState();
}
}

@Override
public boolean hasChanged(int tickCount, BossOverlayAccess context) {
public boolean hasChanged(BossOverlayAccess context) {
if (amount != context.getEvents().size()) {
return true;
}
for (LerpingBossEvent value : context.getEvents().values()) {
if (((BossEventBufferAccess) value).exordium_needsRender())
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ public class ChatComponent implements BufferComponent<ChatAccess> {
private int messageCount = 0;
private boolean wasFocused = false;
private GuiMessage.Line lastMessage = null;
private int lastTimer = 0;

@Override
public void captureState(ChatAccess context) {
lastMessage = context.getTrimmedMessages().isEmpty() ? null : context.getTrimmedMessages().get(0);
lastScrollbarPos = context.getChatScollbarPos();
messageCount = context.getTrimmedMessages().size();
wasFocused = context.isChatFocused();
lastTimer = context.getTickCount();
}

@Override
public boolean hasChanged(int tickCount, ChatAccess context) {
public boolean hasChanged(ChatAccess context) {
GuiMessage.Line msg = context.getTrimmedMessages().isEmpty() ? null : context.getTrimmedMessages().get(0);
boolean changed = context.getChatScollbarPos() != lastScrollbarPos
|| messageCount != context.getTrimmedMessages().size() || context.isChatFocused() != wasFocused
Expand All @@ -38,10 +40,16 @@ public boolean hasChanged(int tickCount, ChatAccess context) {
for (int o = 0; o + context.getChatScollbarPos() < context.getTrimmedMessages().size() && o < j; o++) {
GuiMessage.Line guiMessage = context.getTrimmedMessages().get(o + context.getChatScollbarPos());
if (guiMessage != null) {
int p = tickCount - guiMessage.addedTime();
int p = context.getTickCount() - guiMessage.addedTime();
if (p > 170 && p < 200) { // 180 is correct, add a tiny buffer for the frame to catch up
return true;
}
int lastDelay = lastTimer - guiMessage.addedTime();
if (lastDelay < 200 && p > 170) {
// time jumped from under 200 ticks to now being after the fadeout, update!
// This happens when you keep the chat open in 1.21.4+
return true;
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void captureState(DebugScreenOverlay debugOverlay) {
}

@Override
public boolean hasChanged(int tickCount, DebugScreenOverlay debugOverlay) {
public boolean hasChanged(DebugScreenOverlay debugOverlay) {
//#if MC >= 12002
if (wasRenderingF3 != debugOverlay.showDebugScreen()) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
return minecraft.player.experienceLevel != lastlevel || minecraft.player.experienceProgress != lastprogress;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,21 @@ public void captureState(HealthAccess context) {
}

@Override
public boolean hasChanged(int tickCount, HealthAccess context) {
public boolean hasChanged(HealthAccess context) {
boolean hasVisualEffects = minecraft.player.hasEffect(MobEffects.HUNGER)
|| minecraft.player.hasEffect(MobEffects.REGENERATION);

boolean blinking = (context.getHealthBlinkTime() > tickCount
&& (context.getHealthBlinkTime() - tickCount) / 3L % 2L == 1L);
boolean blinking = (context.getHealthBlinkTime() > context.getTickCount()
&& (context.getHealthBlinkTime() - context.getTickCount()) / 3L % 2L == 1L);
LivingEntity vehicle = context.getExordiumPlayerVehicleWithHealth();
return healthBlinking != blinking || lastRenderedHealth != context.getLastHealth()
|| lastDisplayHealth != context.getDisplayHealth() || lastArmorValue != minecraft.player.getArmorValue()
|| lastMaxVehicleHearts != context.getExordiumVehicleMaxHearts(vehicle)
|| lastVehicleHearts != (vehicle == null ? -1 : vehicle.getHealth())
|| lastAirSupply != minecraft.player.getAirSupply()
|| lastSaturation != minecraft.player.getFoodData().getSaturationLevel()
|| (hasVisualEffects || (hasVisualEffects != hadVisualEffects && lastRenderedTick != tickCount))
|| (hasVisualEffects
|| (hasVisualEffects != hadVisualEffects && lastRenderedTick != context.getTickCount()))
|| lastFoodLevel != minecraft.player.getFoodData().getFoodLevel()
|| lastExhaustionLevel != ((FoodDataAccessor) minecraft.player.getFoodData()).getExhaustionLevel()
|| lastPlayerHealth != minecraft.player.getHealth() || Mth.ceil(lastPlayerHealth) <= 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
if (minecraft.options.attackIndicator().get() == AttackIndicatorStatus.HOTBAR) {
float g = minecraft.player.getAttackStrengthScale(0.0F);
if (g != lastAttackState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void captureState(PlayerListContext context) {
}

@Override
public boolean hasChanged(int tickCount, PlayerListContext context) {
public boolean hasChanged(PlayerListContext context) {
boolean scoreboardOrObjectiveChange = scoreboardOrObjectiveChanged(context.scoreboard, context.objective);
int newHeaderHash = context.tablist().getHeader() == null ? 0
: context.tablist().getHeader().getString().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void captureState(Void context) {
}

@Override
public boolean hasChanged(int tickCount, Void context) {
public boolean hasChanged(Void context) {
ScoreboardState cur = ScoreboardHelper.getScoreboardData();
return !Objects.equals(scoreboardState, "" + cur); // dirty workaround
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void captureState(Float vignetteBrightness) {
}

@Override
public boolean hasChanged(int tickCount, Float vignetteBrightness) {
public boolean hasChanged(Float vignetteBrightness) {
if (exordium_lastVignetteBrightness != vignetteBrightness) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import dev.tr7zw.exordium.access.ChatAccess;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.ChatComponent;
Expand All @@ -24,6 +25,9 @@ public abstract class ChatComponentMixin implements ChatAccess {
private int chatScrollbarPos;
@Shadow
private Minecraft minecraft;
@Getter
@Setter
private int tickCount;

@Override
public int getChatScollbarPos() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/tr7zw/exordium/mixin/CrosshairMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void renderCrosshairStart(GuiGraphics guiGraphics, DeltaTracker delta, C
//#endif
BufferInstance<DebugScreenOverlay> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(CrosshairComponent.getId(), DebugScreenOverlay.class);
if (buffer.renderBuffer(0, debugOverlay, guiGraphics)) {
if (buffer.renderBuffer(debugOverlay, guiGraphics)) {
ci.cancel();
}

Expand All @@ -60,7 +60,7 @@ private void renderCrosshairEnd(GuiGraphics guiGraphics, DeltaTracker delta, Cal
//$$private void renderCrosshairWrapper(Gui gui, GuiGraphics guiGraphics, final Operation<Void> operation) {
//$$ BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
//$$ .getBufferInstance(CrosshairComponent.getId(), Void.class);
//$$ if (!buffer.renderBuffer(0, null, guiGraphics)) {
//$$ if (!buffer.renderBuffer(null, guiGraphics)) {
//$$ operation.call(gui, guiGraphics);
//$$ }
//$$ buffer.postRender(null, guiGraphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void renderDebugOverlayWrapper(DebugScreenOverlay overlay, GuiGraphics g
final Operation<Void> operation) {
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(DebugOverlayComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null, guiGraphics)) {
if (!buffer.renderBuffer(null, guiGraphics)) {
operation.call(overlay, guiGraphics);
}
buffer.postRender(null, guiGraphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class GuiExperienceMixin {
private void renderExperienceBarWrapper(Gui gui, GuiGraphics guiGraphics, int i, final Operation<Void> operation) {
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(ExperienceComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null, guiGraphics)) {
if (!buffer.renderBuffer(null, guiGraphics)) {
operation.call(gui, guiGraphics, i);
}
buffer.postRender(null, guiGraphics);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/tr7zw/exordium/mixin/GuiHealthMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GuiHealthMixin implements HealthAccess {
private void renderPlayerHealthWrapper(Gui gui, GuiGraphics guiGraphics, final Operation<Void> operation) {
BufferInstance<HealthAccess> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(HealthComponent.getId(), HealthAccess.class);
if (!buffer.renderBuffer(tickCount, this, guiGraphics)) {
if (!buffer.renderBuffer(this, guiGraphics)) {
operation.call(gui, guiGraphics);
renderingMountHealth = true;
renderVehicleHealth(guiGraphics);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/tr7zw/exordium/mixin/GuiHotbarMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void renderHotbarWrapper(Gui gui, GuiGraphics guiGraphics, DeltaTracker
//#endif
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(HotbarComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null, guiGraphics)) {
if (!buffer.renderBuffer(null, guiGraphics)) {
//#if MC >= 12005
operation.call(gui, guiGraphics, f);
//#else
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/tr7zw/exordium/mixin/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ private void renderChatWrapper(ChatComponent instance, GuiGraphics guiGraphics,
//#endif
final Operation<Void> operation) {
ChatAccess chatAccess = (ChatAccess) chat;
chatAccess.setTickCount(tickCount);
BufferInstance<ChatAccess> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(dev.tr7zw.exordium.components.vanilla.ChatComponent.getId(), ChatAccess.class);
if (!buffer.renderBuffer(tickCount, chatAccess, guiGraphics)) {
if (!buffer.renderBuffer(chatAccess, guiGraphics)) {
//#if MC >= 12005
operation.call(instance, guiGraphics, tickCount, j, k, b);
//#else
Expand All @@ -81,7 +82,7 @@ private void renderTablistWrapper(PlayerTabOverlay instance, GuiGraphics guiGrap
BufferInstance<PlayerListContext> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(PlayerListComponent.getId(), PlayerListContext.class);
PlayerListContext context = new PlayerListContext(tablistAccess, scoreboard, objective2);
if (!buffer.renderBuffer(tickCount, context, guiGraphics)) {
if (!buffer.renderBuffer(context, guiGraphics)) {
operation.call(instance, guiGraphics, screenWidth, scoreboard, objective2);
}
buffer.postRender(context, guiGraphics);
Expand All @@ -94,10 +95,9 @@ private void renderTablistWrapper(PlayerTabOverlay instance, GuiGraphics guiGrap
//#endif
private void renderBossBarWrapper(BossHealthOverlay instance, GuiGraphics guiGraphics, Operation<Void> original) {
BossOverlayAccess overlayAccess = (BossOverlayAccess) this.getBossOverlay();
@SuppressWarnings("unchecked")
BufferInstance<BossOverlayAccess> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(BossHealthBarComponent.getId(), BossOverlayAccess.class);
if (!buffer.renderBuffer(tickCount, overlayAccess, guiGraphics)) {
if (!buffer.renderBuffer(overlayAccess, guiGraphics)) {
original.call(instance, guiGraphics);
}
buffer.postRender(overlayAccess, guiGraphics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void displayScoreboardSidebarWrapper(Gui gui, GuiGraphics guiGraphics, O
final Operation<Void> operation) {
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(ScoreboardComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null, guiGraphics)) {
if (!buffer.renderBuffer(null, guiGraphics)) {
operation.call(gui, guiGraphics, objective);
}
buffer.postRender(null, guiGraphics);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/tr7zw/exordium/mixin/VignetteMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void renderVignetteWrapper(Gui gui, GuiGraphics guiGraphics, Entity enti
BufferInstance<Float> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(VignetteComponent.getId(), Float.class);
float brightness = ((Gui) (Object) this).vignetteBrightness;
if (!buffer.renderBuffer(0, brightness, guiGraphics)) {
if (!buffer.renderBuffer(brightness, guiGraphics)) {
if (buffer.enabled()) {
renderCustomVignette(guiGraphics);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PaperDollMixin {
private void renderCrosshairStart(float delta, CallbackInfo ci) {
BufferInstance<PaperDollComponent> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(PaperDollComponent.getId(), PaperDollComponent.class);
if (buffer.renderBuffer(0, null, null)) {
if (buffer.renderBuffer(null, null)) {
ci.cancel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void renderMinimap(HudRenderer renderer, Hud hud, GuiGraphics guiGraphic
final Operation<Void> operation) {
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(XaerosMinimapComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null, guiGraphics)) {
if (!buffer.renderBuffer(null, guiGraphics)) {
operation.call(renderer, hud, guiGraphics, tick);
}
buffer.postRender(null, guiGraphics);
Expand Down

0 comments on commit b46cfff

Please sign in to comment.