Files
src
build.gradle
Frost
gradle.properties
settings.gradle
Code
13 781
src/client/java/dev/kodari/localpvp/LocalPvpClient.java
package dev.kodari.localpvp;
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.option.KeyBinding;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
public final class LocalPvpClient implements ClientModInitializer {
private static final ModuleRegistry MODULES = new ModuleRegistry();
private static final ConfigStore CONFIG = new ConfigStore();
private static KeyBinding clickGuiKey;
private static KeyBinding cobwebKey;
private static KeyBinding crystalKey;
private static KeyBinding anchorKey;
private static KeyBinding pearlKey;
private static KeyBinding obsidianKey;
private static MinecraftClient activeClient;
@Override
public void onInitializeClient() {
KeyBinding.Category category = KeyBinding.Category.create(Identifier.of("localpvp", "main"));
clickGuiKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.clickgui", GLFW.GLFW_KEY_RIGHT_SHIFT, category));
cobwebKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.cobweb", GLFW.GLFW_KEY_G, category));
crystalKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.crystal", GLFW.GLFW_KEY_C, category));
anchorKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.anchor", GLFW.GLFW_KEY_V, category));
pearlKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.pearl", GLFW.GLFW_KEY_P, category));
obsidianKey = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.localpvp.obsidian", GLFW.GLFW_KEY_O, category));
MODULES.register(new FeatureModule("cobweb-drop", "Cobweb Underfoot", "Press G to place a web beneath your feet.", ModuleCategory.CPVP));
MODULES.register(new FeatureModule("crystal-macro", "Crystal Macro", "Press C to place a crystal on targeted obsidian or bedrock.", ModuleCategory.CPVP));
MODULES.register(new FeatureModule("safe-anchor", "Safe Anchor Charger", "Press V to charge a targeted respawn anchor; charged anchors are left untouched.", ModuleCategory.CPVP));
MODULES.register(new FeatureModule("pearl-macro", "Quick Pearl", "Press P to select and throw an ender pearl from your hotbar.", ModuleCategory.CPVP));
MODULES.register(new FeatureModule("obsidian-macro", "Quick Obsidian", "Press O to place obsidian against the targeted block.", ModuleCategory.CPVP));
MODULES.register(new FeatureModule("totem-guard", "Totem Guard", "Moves a hotbar totem into an empty offhand.", ModuleCategory.INVENTORY));
MODULES.register(new FeatureModule("mace-fall-switch", "Mace Fall Switch", "Selects a hotbar mace while descending and restores your slot on landing.", ModuleCategory.MACE));
MODULES.register(new FeatureModule("auto-sprint", "Auto Sprint", "Sprints while moving forward unless you are sneaking.", ModuleCategory.MOVEMENT));
MODULES.register(new FeatureModule("auto-gapple", "Auto Gapple", "Uses a hotbar golden apple when health falls to four hearts.", ModuleCategory.UHC));
MODULES.register(new FeatureModule("combat-hud", "Combat Status HUD", "Shows health and offhand totem status in local worlds.", ModuleCategory.HUD));
CONFIG.load(MODULES);
ClientTickEvents.END_CLIENT_TICK.register(client -> {
activeClient = client;
while (clickGuiKey.wasPressed()) {
client.setScreen(new ClickGuiScreen(MODULES, CONFIG));
}
boolean localWorld = client.isInSingleplayer() && client.player != null && client.world != null;
if (localWorld) {
PvPFeatures.tick(client, MODULES, cobwebKey, crystalKey, anchorKey, pearlKey, obsidianKey);
} else {
cobwebKey.wasPressed();
crystalKey.wasPressed();
anchorKey.wasPressed();
pearlKey.wasPressed();
obsidianKey.wasPressed();
PvPFeatures.reset(client);
}
});
HudElementRegistry.addLast(Identifier.of("localpvp", "combat_status"), (context, tickCounter) -> {
if (activeClient == null || !isLocalWorld(activeClient) || !isEnabled("combat-hud") || activeClient.player == null) {
return;
}
float health = activeClient.player.getHealth();
String totem = activeClient.player.getOffHandStack().isOf(Items.TOTEM_OF_UNDYING) ? "READY" : "NONE";
context.drawText(activeClient.textRenderer, Text.literal("HP " + health + " | TOTEM " + totem), 10, 10, 0xFF78BFFF, false);
});
}
private static boolean isLocalWorld(MinecraftClient client) {
return client.isInSingleplayer() && client.player != null && client.world != null;
}
private static boolean isEnabled(String id) {
for (FeatureModule module : MODULES.modules()) {
if (module.id().equals(id)) {
return module.enabled();
}
}
return false;
}
}