Files
src
manifest.kod
Code
12 949
src/client/java/com/anibenadam/client/AnibenadamClient.java
package com.anibenadam.client;
import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.Positioning;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.layers.Layers;
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.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
public final class AnibenadamClient implements ClientModInitializer {
public static final String MOD_ID = "anibenadam";
private static final KeyBinding.Category CATEGORY = KeyBinding.Category.create(Identifier.of(MOD_ID, "main"));
private static KeyBinding openClient;
private static KeyBinding toggleHud;
private static KeyBinding selectCrystals;
private static KeyBinding selectAnchor;
private static KeyBinding selectGlowstone;
private static boolean settingsLoaded;
@Override
public void onInitializeClient() {
openClient = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.anibenadam.open_client", GLFW.GLFW_KEY_RIGHT_SHIFT, CATEGORY)
);
toggleHud = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.anibenadam.toggle_hud", GLFW.GLFW_KEY_H, CATEGORY)
);
selectCrystals = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.anibenadam.select_crystals", GLFW.GLFW_KEY_C, CATEGORY)
);
selectAnchor = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.anibenadam.select_anchor", GLFW.GLFW_KEY_X, CATEGORY)
);
selectGlowstone = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.anibenadam.select_glowstone", GLFW.GLFW_KEY_Z, CATEGORY)
);
HudElementRegistry.addLast(Identifier.of(MOD_ID, "combat_hud"), AnibenadamHud::render);
this.registerTitleScreenButton();
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!settingsLoaded) {
ClientSettings.load(client.runDirectory);
PerformanceProfile.applyIfConfigured(client);
settingsLoaded = true;
}
if (openClient.wasPressed()) {
client.setScreen(new ClientDashboardScreen());
}
if (toggleHud.wasPressed()) {
ClientSettings.Feature feature = ClientSettings.Feature.HUD_OVERLAY;
ClientSettings.setEnabled(feature, !ClientSettings.enabled(feature));
}
if (client.player != null) {
if (selectCrystals.wasPressed()) {
selectHotbarItem(client.player.getInventory(), Items.END_CRYSTAL);
}
if (selectAnchor.wasPressed()) {
selectHotbarItem(client.player.getInventory(), Items.RESPAWN_ANCHOR);
}
if (selectGlowstone.wasPressed()) {
selectHotbarItem(client.player.getInventory(), Items.GLOWSTONE);
}
}
});
}
private static void selectHotbarItem(PlayerInventory inventory, Item item) {
for (int slot = 0; slot < PlayerInventory.HOTBAR_SIZE; slot++) {
if (inventory.getStack(slot).isOf(item)) {
inventory.setSelectedSlot(slot);
return;
}
}
}
private void registerTitleScreenButton() {
Layers.add(UIContainers::verticalFlow, instance -> {
FlowLayout launcher = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
ButtonComponent button = UIComponents.button(Text.literal("ANIBENADAM CLIENT"), clicked ->
MinecraftClient.getInstance().setScreen(new ClientDashboardScreen())
);
button.renderer(ButtonComponent.Renderer.flat(0xE0132236, 0xF01D4263, 0xC0101722));
launcher.child(button);
launcher.positioning(Positioning.absolute(10, 10));
instance.adapter.rootComponent.child(launcher);
}, TitleScreen.class);
}
}