Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 173
src/client/java/com/kodari/elytraindicator/ElytraIndicatorClient.java
package com.kodari.elytraindicator;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.EntityHitResult;
public final class ElytraIndicatorClient implements ClientModInitializer {
private static final String MOD_ID = "elytra_indicator";
private static boolean chestSlotTracked;
private static boolean lastChestplateEquipped;
private static long chestStatusUntil;
private static boolean showIndicator;
private static MinecraftClient client;
@Override
public void onInitializeClient() {
ClientTickEvents.END_CLIENT_TICK.register(minecraftClient -> {
client = minecraftClient;
if (minecraftClient.player == null) {
chestSlotTracked = false;
lastChestplateEquipped = false;
chestStatusUntil = 0;
showIndicator = false;
return;
}
ItemStack chestStack = minecraftClient.player.getEquippedStack(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
boolean hasChestplate = chestItem != Items.AIR && !chestStack.isOf(Items.ELYTRA);
if (chestSlotTracked
&& hasChestplate != lastChestplateEquipped) {
chestStatusUntil = System.currentTimeMillis() + 1800L;
}
lastChestplateEquipped = hasChestplate;
chestSlotTracked = true;
showIndicator = shouldShowIndicator(minecraftClient, chestStack);
});
HudElementRegistry.addLast(Identifier.of(MOD_ID, "player_indicator"), (context, tickCounter) -> {
if (!showIndicator || client == null) {
return;
}
int centerX = context.getScaledWindowWidth() / 2;
int top = context.getScaledWindowHeight() / 2 - 21;
int color = 0xFFFF2020;
context.fill(centerX - 4, top, centerX + 4, top + 3, color);
context.fill(centerX - 6, top + 3, centerX + 6, top + 6, color);
context.fill(centerX - 7, top + 6, centerX + 7, top + 9, color);
context.fill(centerX - 6, top + 9, centerX + 6, top + 12, color);
context.fill(centerX - 4, top + 12, centerX + 4, top + 15, color);
});
HudElementRegistry.addLast(Identifier.of(MOD_ID, "chestplate_status"), (context, tickCounter) -> {
if (client == null || System.currentTimeMillis() >= chestStatusUntil) {
return;
}
String status = lastChestplateEquipped ? "CHESTPLATE EQUIPPED" : "NO CHESTPLATE";
int x = (context.getScaledWindowWidth() - client.textRenderer.getWidth(status)) / 2;
int y = context.getScaledWindowHeight() / 2 + 12;
int color = lastChestplateEquipped ? 0xFF55FF55 : 0xFFFF5555;
context.drawText(client.textRenderer, status, x, y, color, true);
});
}
private static boolean shouldShowIndicator(MinecraftClient client, ItemStack chestStack) {
if (!chestStack.isOf(Items.ELYTRA)
|| !(client.crosshairTarget instanceof EntityHitResult hit)
|| !(hit.getEntity() instanceof PlayerEntity target)
|| target == client.player) {
return false;
}
double heightDifference = client.player.getY() - target.getY();
return heightDifference >= 1.5 && heightDifference <= 8.0;
}
}