Skip to content

Commit

Permalink
Migrate Scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Aug 3, 2024
1 parent 326bd4b commit af4d023
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ interface PlayerListOverlayAccess extends VanillaBufferAccess {
LegacyBuffer getPlayerListOverlayBuffer();
}

interface ScoreBoardOverlayAccess extends VanillaBufferAccess {

LegacyBuffer getScoreBoardOverlayBuffer();
}

interface BossHealthOverlayAccess extends VanillaBufferAccess {
LegacyBuffer getHotbarOverlayBuffer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.ScoreboardComponent;
import dev.tr7zw.exordium.components.vanilla.VignetteComponent;
import dev.tr7zw.exordium.versionless.config.Config;
import lombok.NoArgsConstructor;
Expand All @@ -29,10 +30,7 @@ public void initialize() {
registerBuffer(CrosshairComponent.getId(), new CrosshairComponent(), () -> inst.config.crosshairSettings);
registerBuffer(VignetteComponent.getId(), new VignetteComponent(), () -> inst.config.vignetteSettings);
registerBuffer(ExperienceComponent.getId(), new ExperienceComponent(), () -> inst.config.experienceSettings);

// vanillaBuffers.put(new ResourceLocation("scoreboard"),
// gui -> ((ScoreBoardOverlayAccess) gui).getScoreBoardOverlayBuffer());

registerBuffer(ScoreboardComponent.getId(), new ScoreboardComponent(), () -> inst.config.scoreboardSettings);
registerBuffer(HotbarComponent.getId(), new HotbarComponent(), () -> inst.config.hotbarSettings);
registerBuffer(ChatComponent.getId(), new ChatComponent(), () -> inst.config.chatSettings);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.tr7zw.exordium.components.vanilla;

import java.util.Objects;

import dev.tr7zw.exordium.components.BufferComponent;
import dev.tr7zw.exordium.util.ScoreboardHelper;
import dev.tr7zw.exordium.util.ScoreboardHelper.ScoreboardState;
import dev.tr7zw.util.NMSHelper;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;

public class ScoreboardComponent implements BufferComponent<Void> {

private static final Minecraft minecraft = Minecraft.getInstance();
@Getter
private static final ResourceLocation id = NMSHelper.getResourceLocation("minecraft", "scoreboard");

private String scoreboardState = null;

@Override
public void captureState(Void context) {
scoreboardState = "" + ScoreboardHelper.getScoreboardData();
}

@Override
public boolean hasChanged(int tickCount, Void context) {
ScoreboardState cur = ScoreboardHelper.getScoreboardData();
return !Objects.equals(scoreboardState, "" + cur); // dirty workaround
}

}
43 changes: 7 additions & 36 deletions src/main/java/dev/tr7zw/exordium/mixin/ScoreboardMixin.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,31 @@
package dev.tr7zw.exordium.mixin;

import java.util.Objects;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;

import dev.tr7zw.exordium.ExordiumModBase;
import dev.tr7zw.exordium.access.VanillaBufferAccess.ScoreBoardOverlayAccess;
import dev.tr7zw.exordium.render.BufferedComponent;
import dev.tr7zw.exordium.render.LegacyBuffer;
import dev.tr7zw.exordium.util.ScoreboardHelper;
import dev.tr7zw.exordium.util.ScoreboardHelper.ScoreboardState;
import net.minecraft.client.Minecraft;
import dev.tr7zw.exordium.components.BufferInstance;
import dev.tr7zw.exordium.components.vanilla.ScoreboardComponent;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.world.scores.Objective;

@Mixin(Gui.class)
public class ScoreboardMixin implements ScoreBoardOverlayAccess {

@Shadow
private Minecraft minecraft;
private String scoreboardState = null;

private LegacyBuffer scoreboardBuffer = new LegacyBuffer(true,
() -> ExordiumModBase.instance.config.scoreboardSettings) {

@Override
public boolean shouldRenderNextCappedFrame() {
ScoreboardState cur = ScoreboardHelper.getScoreboardData();
return !Objects.equals(scoreboardState, "" + cur); // dirty workaround
}

@Override
public void captureState() {
scoreboardState = "" + ScoreboardHelper.getScoreboardData();
}
};
public class ScoreboardMixin {

@WrapOperation(method = "renderScoreboardSidebar", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;displayScoreboardSidebar(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/world/scores/Objective;)V"), })
private void displayScoreboardSidebarWrapper(Gui gui, GuiGraphics guiGraphics, Objective objective,
final Operation<Void> operation) {
if (!scoreboardBuffer.render()) {
BufferInstance<Void> buffer = ExordiumModBase.instance.getBufferManager()
.getBufferInstance(ScoreboardComponent.getId(), Void.class);
if (!buffer.renderBuffer(0, null)) {
operation.call(gui, guiGraphics, objective);
}
scoreboardBuffer.renderEnd();
}

@Override
public LegacyBuffer getScoreBoardOverlayBuffer() {
return scoreboardBuffer;
buffer.postRender(null);
}

}

0 comments on commit af4d023

Please sign in to comment.