use of com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor in project SpeedRunIGT by RedLime.
the class MinecraftClientMixin method onInit.
/**
* Add import font system
*/
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/debug/DebugRenderer;<init>(Lnet/minecraft/client/MinecraftClient;)V", shift = At.Shift.BEFORE))
public void onInit(RunArgs args, CallbackInfo ci) {
this.resourceManager.registerListener(new SinglePreparationResourceReloadListener<Map<Identifier, List<Font>>>() {
@Override
protected Map<Identifier, List<Font>> prepare(ResourceManager manager, Profiler profiler) {
SpeedRunIGT.FONT_MAPS.clear();
try {
HashMap<Identifier, List<Font>> map = new HashMap<>();
File[] fontFiles = SpeedRunIGT.FONT_PATH.toFile().listFiles();
if (fontFiles == null)
return new HashMap<>();
for (File file : Arrays.stream(fontFiles).filter(file -> file.getName().endsWith(".ttf")).collect(Collectors.toList())) {
File config = SpeedRunIGT.FONT_PATH.resolve(file.getName().substring(0, file.getName().length() - 4) + ".json").toFile();
if (config.exists()) {
FontUtils.addFont(map, file, config);
} else {
FontUtils.addFont(map, file, null);
}
}
return map;
} catch (Throwable e) {
return new HashMap<>();
}
}
@Override
protected void apply(Map<Identifier, List<Font>> loader, ResourceManager manager, Profiler profiler) {
try {
FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) MinecraftClient.getInstance()).getFontManager();
for (Map.Entry<Identifier, List<Font>> listEntry : loader.entrySet()) {
FontStorage fontStorage = new FontStorage(fontManager.getTextureManager(), listEntry.getKey());
fontStorage.setFonts(listEntry.getValue());
fontManager.getFontStorages().put(listEntry.getKey(), fontStorage);
}
TimerDrawer.fontHeightMap.clear();
} catch (Throwable e) {
SpeedRunIGT.error("Error! failed import timer fonts!");
e.printStackTrace();
}
}
});
}
use of com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor in project SpeedRunIGT by RedLime.
the class TimerDrawer method draw.
public void draw() {
if (!toggle)
return;
client.getProfiler().push("create");
MutableText igtText = getIGTText();
MutableText rtaText = getRTAText();
client.getProfiler().swap("font");
// 폰트 조정
float fontHeight = 8;
FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
if (getTimerFont() != MinecraftClient.DEFAULT_FONT_ID && fontManager.getFontStorages().containsKey(getTimerFont())) {
rtaText.setStyle(rtaText.getStyle().withFont(getTimerFont()));
igtText.setStyle(igtText.getStyle().withFont(getTimerFont()));
fontHeight = fontHeightMap.computeIfAbsent(getTimerFont().toString(), key -> {
RenderableGlyph glyph = ((FontStorageAccessor) fontManager.getFontStorages().get(getTimerFont())).invokeRenderableGlyph('I');
return glyph.getHeight() / glyph.getOversample();
});
}
// 초기 값 조정
client.getProfiler().swap("init");
TimerElement igtTimerElement = new TimerElement();
TimerElement rtaTimerElement = new TimerElement();
rtaTimerElement.init(rtaXPos, rtaYPos, rtaScale, rtaText, rtaColor, rtaDecoration, fontHeight);
igtTimerElement.init(igtXPos, igtYPos, igtScale, igtText, igtColor, igtDecoration, fontHeight);
MatrixStack matrixStack = new MatrixStack();
// 배경 렌더
client.getProfiler().swap("background");
if (bgOpacity > 0.01f) {
Position rtaMin = new Position(rtaTimerElement.getPosition().getX() - rtaPadding, rtaTimerElement.getPosition().getY() - rtaPadding);
Position rtaMax = new Position(rtaMin.getX() + rtaTimerElement.getScaledTextWidth() + ((rtaPadding - 1) + rtaPadding), rtaMin.getY() + rtaTimerElement.getScaledTextHeight() + ((rtaPadding - 1) + rtaPadding));
Position igtMin = new Position(igtTimerElement.getPosition().getX() - igtPadding, igtTimerElement.getPosition().getY() - igtPadding);
Position igtMax = new Position(igtMin.getX() + igtTimerElement.getScaledTextWidth() + ((igtPadding - 1) + igtPadding), igtMin.getY() + igtTimerElement.getScaledTextHeight() + ((igtPadding - 1) + igtPadding));
int opacity = BackgroundHelper.ColorMixer.getArgb((int) (bgOpacity * 255), 0, 0, 0);
if (rtaMin.getX() < igtMax.getX() && rtaMin.getY() < igtMax.getY() && igtMin.getX() < rtaMax.getX() && igtMin.getY() < rtaMax.getY()) {
DrawableHelper.fill(matrixStack, Math.min(rtaMin.getX(), igtMin.getX()), Math.min(rtaMin.getY(), igtMin.getY()), Math.max(rtaMax.getX(), igtMax.getX()), Math.max(rtaMax.getY(), igtMax.getY()), opacity);
} else {
if (rtaScale != 0)
DrawableHelper.fill(matrixStack, rtaMin.getX(), rtaMin.getY(), rtaMax.getX(), rtaMax.getY(), opacity);
if (igtScale != 0)
DrawableHelper.fill(matrixStack, igtMin.getX(), igtMin.getY(), igtMax.getX(), igtMax.getY(), opacity);
}
}
// 렌더
client.getProfiler().swap("draw");
if (igtScale != 0)
igtTimerElement.draw(matrixStack, translateZ);
if (rtaScale != 0)
rtaTimerElement.draw(matrixStack, translateZ);
client.getProfiler().pop();
}
Aggregations