-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/tr7zw/exordium/components/vanilla/ScoreboardComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
src/main/java/dev/tr7zw/exordium/mixin/ScoreboardMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |