blob: e630080851a2fd3e503d680c21b6c051cddf8801 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package de.hysky.skyblocker.skyblock.chat;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.dwarven.CrystalsHudConfigScreen;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
public class ChatRuleAnnouncementScreen {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static float timer;
private static Text text = null;
public static void init() {
HudRenderCallback.EVENT.register((context, tickDelta) -> {
if (timer <= 0 || text == null) {
return;
}
render(context, tickDelta);
});
}
/**
* renders {@link ChatRuleAnnouncementScreen#text} to the middle of the top of the screen.
* @param context render context
* @param tickDelta difference from last render to remove from timer
*/
private static void render(DrawContext context, float tickDelta) {
int scale = SkyblockerConfigManager.get().messages.chatRuleConfig.announcementScale;
//decrement timer
timer -= tickDelta;
//scale text up and center
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(context.getScaledWindowWidth() / 2f, context.getScaledWindowHeight() * 0.3, 0f);
matrices.scale(scale, scale, 0f);
//render text
context.drawCenteredTextWithShadow(CLIENT.textRenderer,text,0, 0, 0xFFFFFF);
matrices.pop();
}
protected static void setText(Text newText) {
text = newText;
timer = SkyblockerConfigManager.get().messages.chatRuleConfig.announcementLength;
}
}
|