Files
src
ucm
build.gradle
gradle.properties
settings.gradle
stun.zip
Code
24 891
src/client/java/com/kodari/directionalcombat/client/DirectionalCombatClient.java
package com.kodari.directionalcombat.client;
import com.kodari.directionalcombat.CombatStyle;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.resources.Identifier;
public final class DirectionalCombatClient implements ClientModInitializer {
public static CombatStyle.Direction swingDirection = CombatStyle.Direction.NEUTRAL;
public static boolean jumpSwing;
public static boolean airborneSwing;
@Override
public void onInitializeClient() {
HudElementRegistry.addLast(Identifier.fromNamespaceAndPath("directional_combat", "attack_indicator"), (graphics, deltaTracker) -> {
Minecraft client = Minecraft.getInstance();
if (client.player == null || CombatStyle.weapon(client.player.getMainHandItem()) == CombatStyle.Weapon.NONE) return;
CombatStyle.Weapon weapon = CombatStyle.weapon(client.player.getMainHandItem());
boolean swinging = client.player.isSwinging();
CombatStyle.Direction direction = swinging ? swingDirection : CombatStyle.direction(client.player.input.keyPresses);
boolean jumping = swinging ? jumpSwing : !client.player.onGround() && (weapon == CombatStyle.Weapon.AXE || weapon == CombatStyle.Weapon.SHOVEL);
boolean airborne = swinging ? airborneSwing : !client.player.onGround();
int x = graphics.guiWidth() / 2 + 12;
int y = graphics.guiHeight() / 2 - 5;
drawIcon(graphics, x, y, switch (weapon) {
case SWORD -> new String[]{"..#..", "..#..", ".###.", ".###.", "..#..", "..#..", ".###.", "..#..", "..#.."};
case AXE -> new String[]{".###.", "####.", "####.", ".##..", "..#..", "..#..", "..#..", "..#..", "..#.."};
case SHOVEL -> new String[]{".###.", "#####", "#####", ".###.", "..#..", "..#..", "..#..", "..#..", "..#.."};
case SPEAR -> new String[]{"..#..", ".###.", "..#..", "..#..", "..#..", "..#..", "..#..", "..#..", "..#.."};
case MACE -> new String[]{"#.#.#", ".###.", "#####", ".###.", "..#..", "..#..", "..#..", "..#..", "..#.."};
case NONE -> new String[0];
}, 0xFFE6E6E6);
String[] attack = jumping ? new String[]{"..#..", "..#..", "..#..", "#.#.#", ".###.", "..#..", ".#.#."}
: airborne ? new String[]{"..#..", ".###.", "#.#.#", "..#..", "..#..", "..#..", "....."}
: switch (direction) {
case LEFT -> new String[]{".....", "..#..", ".#...", "#####", ".#...", "..#..", "....."};
case RIGHT -> new String[]{".....", "..#..", "...#.", "#####", "...#.", "..#..", "....."};
case FORWARD -> new String[]{"..#..", ".###.", "#.#.#", "..#..", "..#..", "..#..", "....."};
case BACKWARD -> new String[]{".....", "#####", ".....", "..#..", "#.#.#", ".###.", "..#.."};
case NEUTRAL -> new String[]{"..#..", "..#..", "..#..", "..#..", "#.#.#", ".###.", "..#.."};
};
drawIcon(graphics, x + 7, y + 1, attack, jumping ? 0xFFFFBE6B : airborne ? 0xFF8EE7FF : 0xFFFFFFFF);
});
}
private static void drawIcon(GuiGraphicsExtractor graphics, int x, int y, String[] rows, int color) {
for (int row = 0; row < rows.length; row++) {
for (int column = 0; column < rows[row].length(); column++) {
if (rows[row].charAt(column) == '#') {
graphics.fill(x + column + 1, y + row + 1, x + column + 2, y + row + 2, 0xB0000000);
}
}
}
for (int row = 0; row < rows.length; row++) {
for (int column = 0; column < rows[row].length(); column++) {
if (rows[row].charAt(column) == '#') {
graphics.fill(x + column, y + row, x + column + 1, y + row + 1, color);
}
}
}
}
}
