Hide Hotbar Mod
Документация и исходный код мода для точечного скрытия интерфейса.
Hide Hotbar Mod
Мод добавляет горячую клавишу (F7), которая позволяет скрыть нижнюю панель интерфейса (хотбар, сердечки, голод, броню, воздух), а также полоску опыта и уровень. При этом прицел, чат, рука персонажа и эффекты зелий остаются полностью видимыми.
Версия мода для Minecraft 1.21.11
В версии 1.21.11 разработчики Mojang изменили структуру рендеринга. Отрисовка опыта была вынесена, поэтому для полной очистки низа экрана требуется перехватывать три разных метода: renderMainHud, renderStatusBars и renderExperienceBar.
1. Главный клиентский класс
Файл: src/main/java/dev/lutsu/hidehotbar/HideHotbarModClient.java
package dev.lutsu.hidehotbar;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;
public class HideHotbarModClient implements ClientModInitializer {
public static KeyBinding toggleHudKeyBinding;
private static boolean hotbarHidden = false;
@Override
public void onInitializeClient() {
toggleHudKeyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.hidehotbar.toggle_hud",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_F7,
KeyBinding.Category.MISC
));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (toggleHudKeyBinding.wasPressed()) {
hotbarHidden = !hotbarHidden;
if (client.player != null) {
client.player.sendMessage(Text.literal(hotbarHidden ? "Хотбар скрыт" : "Хотбар отображается"), true);
}
}
});
}
public static boolean isHotbarHidden() {
return hotbarHidden;
}
}2. Миксин для интерфейса
Файл: src/main/java/dev/lutsu/hidehotbar/mixin/InGameHudMixin.java
package dev.lutsu.hidehotbar.mixin;
import dev.lutsu.hidehotbar.HideHotbarModClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(InGameHud.class)
public class InGameHudMixin {
@Inject(method = "renderMainHud", at = @At("HEAD"), cancellable = true)
private void onRenderMainHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
if (HideHotbarModClient.isHotbarHidden()) {
ci.cancel();
}
}
@Inject(method = "renderStatusBars", at = @At("HEAD"), cancellable = true)
private void onRenderStatusBars(DrawContext context, CallbackInfo ci) {
if (HideHotbarModClient.isHotbarHidden()) {
ci.cancel();
}
}
}Версия мода для Minecraft 1.21.7
В более ранней версии 1.21.7 архитектура InGameHud имеет небольшое отличие в распределении задач рендеринга. Для точечного скрытия достаточно использовать только два инжекта, так как полоска опыта на этой версии контролируется смежными методами.
1. Главный клиентский класс
Код класса HideHotbarModClient.java идентичен версии 1.21.11 (использует регистрацию кнопки через Fabric API на F7).
2. Миксин для интерфейса
Файл: src/main/java/dev/lutsu/hidehotbar/mixin/InGameHudMixin.java
package dev.lutsu.hidehotbar.mixin;
import dev.lutsu.hidehotbar.HideHotbarModClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(InGameHud.class)
public class InGameHudMixin {
@Inject(method = "renderMainHud", at = @At("HEAD"), cancellable = true)
private void onRenderMainHud(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
if (HideHotbarModClient.isHotbarHidden()) {
ci.cancel();
}
}
@Inject(method = "renderStatusBars", at = @At("HEAD"), cancellable = true)
private void onRenderStatusBars(DrawContext context, CallbackInfo ci) {
if (HideHotbarModClient.isHotbarHidden()) {
ci.cancel();
}
}
}Конфигурация миксинов hidehotbar.mixins.json
Для 1.21.11 версии файл конфигурации должен подключать только один класс миксина:
{
"required": true,
"package": "dev.lutsu.hidehotbar.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"InGameHudMixin"
],
"injectors": {
"defaultRequire": 1
}
}Для 1.21.7 версии файл конфигурации должен подключать два класса миксина:
{
"required": true,
"package": "dev.lutsu.hidehotbar.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"InGameHudMixin",
"ExperienceBarMixin"
],
"injectors": {
"defaultRequire": 1
}
}