Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
15 821
src/client/java/com/kodari/tripleswap/TripleSwapClient.java
package com.kodari.tripleswap;
import com.kodari.tripleswap.mixin.MinecraftClientInvoker;
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.item.Items;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.lwjgl.glfw.GLFW;
public class TripleSwapClient implements ClientModInitializer {
private KeyBinding swapKey;
private KeyBinding skipMaceKey;
private KeyBinding axeSwapKey;
private KeyBinding pearlWindKey;
private KeyBinding pearlWindMainHandKey;
private KeyBinding spearHudToggleKey;
private KeyBinding doubleAttackKey;
private KeyBinding doubleUseKey;
private KeyBinding doubleAttackProfile2Key;
private KeyBinding doubleUseProfile2Key;
private static final java.util.PriorityQueue<Long> pendingAttacks = new java.util.PriorityQueue<>();
private static final java.util.PriorityQueue<Long> pendingUses = new java.util.PriorityQueue<>();
private static net.minecraft.client.network.ClientPlayerEntity attackPlayer;
private int stage;
private int expectedSlot;
private int attackSlot;
private int returnSlot;
private int pearlSlot;
private int windSlot;
private int waitTicks;
private int queuedAttackSlot = -1;
private boolean axeMaceKeyDown;
private int axeMaceSlot;
private int axeMaceTicks;
private long axeMaceDeadline;
@Override
public void onInitializeClient() {
swapKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.swap", GLFW.GLFW_KEY_V, KeyBinding.Category.GAMEPLAY));
skipMaceKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.skip_mace", GLFW.GLFW_KEY_Y, KeyBinding.Category.GAMEPLAY));
axeSwapKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.axe_swap", GLFW.GLFW_KEY_B, KeyBinding.Category.GAMEPLAY));
pearlWindKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.pearl_wind", GLFW.GLFW_KEY_N, KeyBinding.Category.GAMEPLAY));
pearlWindMainHandKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.pearl_wind_main_hand", GLFW.GLFW_KEY_M, KeyBinding.Category.GAMEPLAY));
spearHudToggleKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.toggle_spear_hud", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.Category.GAMEPLAY));
doubleAttackKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.double_attack", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.Category.GAMEPLAY));
doubleUseKey = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.double_use", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.Category.GAMEPLAY));
doubleAttackProfile2Key = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.double_attack_profile_2", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.Category.GAMEPLAY));
doubleUseProfile2Key = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.tripleswap.double_use_profile_2", GLFW.GLFW_KEY_UNKNOWN, KeyBinding.Category.GAMEPLAY));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.player == null || client.currentScreen != null) {
stage = 0;
queuedAttackSlot = -1;
while (swapKey.wasPressed()) { }
while (skipMaceKey.wasPressed()) { }
while (axeSwapKey.wasPressed()) { }
while (pearlWindKey.wasPressed()) { }
while (pearlWindMainHandKey.wasPressed()) { }
while (spearHudToggleKey.wasPressed()) { }
while (doubleAttackKey.wasPressed()) { }
while (doubleUseKey.wasPressed()) { }
while (doubleAttackProfile2Key.wasPressed()) { }
while (doubleUseProfile2Key.wasPressed()) { }
pendingAttacks.clear();
pendingUses.clear();
attackPlayer = null;
return;
}
while (doubleAttackKey.wasPressed()) {
((MinecraftClientInvoker) client).tripleswap$doAttack();
int delay = Math.max(0, Math.min(500, SpearHudConfig.HANDLER.instance().doubleAttackDelay));
if (delay == 0) {
((MinecraftClientInvoker) client).tripleswap$doAttack();
} else {
attackPlayer = client.player;
pendingAttacks.add(System.nanoTime() + delay * 1_000_000L);
}
}
while (doubleUseKey.wasPressed()) {
((MinecraftClientInvoker) client).tripleswap$doItemUse();
int delay = Math.max(0, Math.min(500, SpearHudConfig.HANDLER.instance().doubleUseDelay));
if (delay == 0) {
((MinecraftClientInvoker) client).tripleswap$doItemUse();
} else {
attackPlayer = client.player;
pendingUses.add(System.nanoTime() + delay * 1_000_000L);
}
}
while (doubleAttackProfile2Key.wasPressed()) {
((MinecraftClientInvoker) client).tripleswap$doAttack();
int delay = Math.max(0, Math.min(500, SpearHudConfig.HANDLER.instance().doubleAttackDelay2));
if (delay == 0) {
((MinecraftClientInvoker) client).tripleswap$doAttack();
} else {
attackPlayer = client.player;
pendingAttacks.add(System.nanoTime() + delay * 1_000_000L);
}
}
while (doubleUseProfile2Key.wasPressed()) {
((MinecraftClientInvoker) client).tripleswap$doItemUse();
int delay = Math.max(0, Math.min(500, SpearHudConfig.HANDLER.instance().doubleUseDelay2));
if (delay == 0) {
((MinecraftClientInvoker) client).tripleswap$doItemUse();
} else {
attackPlayer = client.player;
pendingUses.add(System.nanoTime() + delay * 1_000_000L);
}
}
while (spearHudToggleKey.wasPressed()) {
SpearReachHud.enabled = !SpearReachHud.enabled;
}
boolean pressed = false;
while (swapKey.wasPressed()) {
pressed = true;
}
boolean skipPressed = false;
while (skipMaceKey.wasPressed()) {
skipPressed = true;
}
boolean axePressed = false;
while (axeSwapKey.wasPressed()) {
axePressed = true;
}
boolean pearlWindPressed = false;
while (pearlWindKey.wasPressed()) {
pearlWindPressed = true;
}
boolean pearlWindMainHandPressed = false;
while (pearlWindMainHandKey.wasPressed()) {
pearlWindMainHandPressed = true;
}
var inventory = client.player.getInventory();
var config = SpearHudConfig.HANDLER.instance();
boolean axeMaceDown = config.axeMaceKey >= 0 && InputUtil.isKeyPressed(client.getWindow(), config.axeMaceKey);
boolean axeMacePressed = axeMaceDown && !axeMaceKeyDown;
axeMaceKeyDown = axeMaceDown;
if (stage != 0 && inventory.getSelectedSlot() != expectedSlot) {
stage = 0;
queuedAttackSlot = -1;
}
if ((stage == 1 || stage == 2) && (pressed || skipPressed || axePressed)) {
queuedAttackSlot = axePressed ? 7 : skipPressed ? 0 : 3;
}
if (axeMacePressed && stage == 0 && !client.player.isSpectator()) {
int axe = -1;
int mace = inventory.getStack(3).isOf(Items.MACE) ? 3 : -1;
for (int slot = 0; slot < 9; slot++) {
var stack = inventory.getStack(slot);
if (axe == -1 && (stack.isOf(Items.WOODEN_AXE) || stack.isOf(Items.STONE_AXE)
|| stack.isOf(Items.IRON_AXE) || stack.isOf(Items.GOLDEN_AXE)
|| stack.isOf(Items.DIAMOND_AXE) || stack.isOf(Items.NETHERITE_AXE))) axe = slot;
if (mace == -1 && stack.isOf(Items.MACE)) mace = slot;
}
if (axe != -1 && mace != -1) {
axeMaceSlot = mace;
expectedSlot = axe;
inventory.setSelectedSlot(axe);
((MinecraftClientInvoker) client).tripleswap$doAttack();
axeMaceTicks = 0;
axeMaceDeadline = System.nanoTime() + Math.max(0, Math.min(500, config.axeMaceDelayMs)) * 1_000_000L;
stage = 30;
}
} else if ((pearlWindPressed || pearlWindMainHandPressed) && stage == 0 && !client.player.isSpectator() && client.interactionManager != null) {
pearlSlot = -1;
windSlot = -1;
for (int slot = 0; slot < 9; slot++) {
if (pearlSlot == -1 && inventory.getStack(slot).isOf(Items.ENDER_PEARL)) {
pearlSlot = slot;
}
if (windSlot == -1 && inventory.getStack(slot).isOf(Items.WIND_CHARGE)) {
windSlot = slot;
}
}
if (pearlSlot != -1 && windSlot != -1) {
expectedSlot = pearlSlot;
inventory.setSelectedSlot(expectedSlot);