Buckets:
| package com.example.examplemod; | |
| import com.mojang.blaze3d.systems.RenderSystem; | |
| 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.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; | |
| import net.minecraft.client.MinecraftClient; | |
| import net.minecraft.client.option.KeyBinding; | |
| import net.minecraft.client.util.InputUtil; | |
| import net.minecraft.text.Text; | |
| import org.lwjgl.glfw.GLFW; | |
| /** | |
| * Client-only entrypoint. Registered in fabric.mod.json under | |
| * "entrypoints" -> "client". Keybinding + HUD render APIs unchanged | |
| * across 1.21.7 - 1.21.11. | |
| */ | |
| public class ExampleModClient implements ClientModInitializer { | |
| private static KeyBinding toggleHudKey; | |
| private static boolean hudVisible = true; | |
| public void onInitializeClient() { | |
| // Register a keybinding (default: 'H'), shown in Controls menu under "key.categories.examplemod" | |
| toggleHudKey = KeyBindingHelper.registerKeyBinding(new KeyBinding( | |
| "key.examplemod.toggle_hud", | |
| InputUtil.Type.KEYSYM, | |
| GLFW.GLFW_KEY_H, | |
| "key.categories.examplemod" | |
| )); | |
| // Check every client tick whether the key was pressed | |
| ClientTickEvents.END_CLIENT_TICK.register(client -> { | |
| while (toggleHudKey.wasPressed()) { | |
| hudVisible = !hudVisible; | |
| if (client.player != null) { | |
| client.player.sendMessage( | |
| Text.literal("HUD " + (hudVisible ? "enabled" : "disabled")), true); | |
| } | |
| } | |
| }); | |
| // Draw a simple overlay each frame | |
| HudRenderCallback.EVENT.register(this::onHudRender); | |
| } | |
| private void onHudRender(net.minecraft.client.gui.DrawContext context, net.minecraft.client.render.RenderTickCounter tickCounter) { | |
| if (!hudVisible) return; | |
| MinecraftClient client = MinecraftClient.getInstance(); | |
| if (client.player == null) return; | |
| RenderSystem.enableBlend(); | |
| int x = 10; | |
| int y = 10; | |
| context.drawText(client.textRenderer, | |
| Text.literal("ExampleMod active"), | |
| x, y, 0xFFFFFF, true); | |
| // Show current held item name below it | |
| var heldStack = client.player.getMainHandStack(); | |
| if (!heldStack.isEmpty()) { | |
| context.drawText(client.textRenderer, | |
| Text.literal("Holding: " + heldStack.getName().getString()), | |
| x, y + 12, 0xAAAAAA, true); | |
| } | |
| } | |
| } | |
Xet Storage Details
- Size:
- 2.66 kB
- Xet hash:
- 514a0e7e46950e298bcedefd5d87c6f66fc0f5775b40235fd0d50a76bf48ac79
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.