No chat to show

This project's files are all here to explore.

Files
src
build.gradle
gradle.properties
settings.gradle
Code
12 642
src/client/java/com/kodari/uhcpvp/UhcPvPClient.java
package com.kodari.uhcpvp;

import com.kodari.uhcpvp.combat.WebActions;
import com.kodari.uhcpvp.command.FriendCommands;
import com.kodari.uhcpvp.config.ConfigManager;
import com.kodari.uhcpvp.config.UhcConfig;
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.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public final class UhcPvPClient implements ClientModInitializer {
    private static KeyBinding autoWebKey;
    private static KeyBinding autoCobwebKey;
    private static KeyBinding webModeKey;
    private static KeyBinding stunSlamKey;
    private static KeyBinding headWebKey;
    private static KeyBinding pressurePlateWebKey;
    private static KeyBinding autoDrainKey;

    @Override
    public void onInitializeClient() {
        KeyBinding.Category category = KeyBinding.Category.create(Identifier.of(UhcPvPMod.MOD_ID, "controls"));
        autoWebKey = register("key.uhcpvp.auto_web", GLFW.GLFW_KEY_G, category);
        autoCobwebKey = register("key.uhcpvp.auto_cobweb", GLFW.GLFW_KEY_H, category);
        webModeKey = register("key.uhcpvp.web_mode", GLFW.GLFW_KEY_J, category);
        stunSlamKey = register("key.uhcpvp.stun_slam", GLFW.GLFW_KEY_K, category);
        headWebKey = register("key.uhcpvp.head_web", GLFW.GLFW_KEY_L, category);
        pressurePlateWebKey = register("key.uhcpvp.pressure_plate_web", GLFW.GLFW_KEY_O, category);
        autoDrainKey = register("key.uhcpvp.auto_drain", GLFW.GLFW_KEY_P, category);

        FriendCommands.register();
        ClientTickEvents.END_CLIENT_TICK.register(UhcPvPClient::tick);
    }

    private static KeyBinding register(String translationKey, int keyCode, KeyBinding.Category category) {
        return KeyBindingHelper.registerKeyBinding(new KeyBinding(translationKey, keyCode, category));
    }

    private static void tick(MinecraftClient client) {
        if (client.player == null || client.world == null || client.currentScreen != null) {
            return;
        }

        UhcConfig config = ConfigManager.get();
        if (autoWebKey.wasPressed()) {
            config.autoWebEnabled = !config.autoWebEnabled;
            ConfigManager.save();
        }
        if (autoCobwebKey.wasPressed()) {
            config.autoCobwebEnabled = !config.autoCobwebEnabled;
            ConfigManager.save();
        }
        if (webModeKey.wasPressed()) {
            config.webMode = config.webMode == UhcConfig.WebMode.MANUAL
                    ? UhcConfig.WebMode.AUTOMATIC
                    : UhcConfig.WebMode.MANUAL;
            ConfigManager.save();
        }
        if (autoDrainKey.wasPressed()) {
            config.autoDrainEnabled = !config.autoDrainEnabled;
            ConfigManager.save();
        }
        if (stunSlamKey.wasPressed()) {
            WebActions.stunSlam(client, config);
        }
        if (headWebKey.wasPressed()) {
            WebActions.headWeb(client, config);
        }
        if (pressurePlateWebKey.wasPressed()) {
            WebActions.pressurePlateWeb(client, config);
        }
        if (config.autoWebEnabled || config.autoCobwebEnabled) {
            WebActions.tickWeb(client, config);
        }
        if (config.autoDrainEnabled) {
            WebActions.tickDrain(client, config);
        }
    }
}