first commit
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
package lul.flummi.championoverlay;
|
||||
|
||||
import com.mikitellurium.telluriumforge.registry.IdentifierProvider;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ChampionOverlay implements ModInitializer {
|
||||
|
||||
private static final String MOD_ID = "championoverlay";
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
private static final IdentifierProvider registrationHelper = () -> MOD_ID;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
}
|
||||
|
||||
public static String modId() {
|
||||
return MOD_ID;
|
||||
}
|
||||
|
||||
public static Logger logger() {
|
||||
return LOGGER;
|
||||
}
|
||||
|
||||
public static Identifier getModIdentifier(String path) {
|
||||
return registrationHelper.modIdentifier(path);
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/lul/flummi/championoverlay/Client.java
Normal file
14
src/main/java/lul/flummi/championoverlay/Client.java
Normal file
@ -0,0 +1,14 @@
|
||||
package lul.flummi.championoverlay;
|
||||
|
||||
import lul.flummi.championoverlay.event.ModEvents;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public class Client implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ChampionOverlay.logger().info("Starting client");
|
||||
ModEvents.register();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package lul.flummi.championoverlay.client.rendering;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public class OverlayRenderer {
|
||||
public static void renderOverlay(DrawContext context, float deltaTick) {
|
||||
MinecraftClient Instance = MinecraftClient.getInstance();
|
||||
ClientPlayerEntity player = Instance.player;
|
||||
|
||||
if (Instance.player == null || Instance.options.hudHidden)
|
||||
return;
|
||||
|
||||
ItemStack mainHandItem = player.getMainHandStack();
|
||||
|
||||
double ItemCombatXp = 0;
|
||||
int ChampionExp = 0;
|
||||
String ChampionLevel = "null";
|
||||
String ChampionPercent = "0%";
|
||||
int ChampionExpCumu = 0;
|
||||
|
||||
if (mainHandItem != null) {
|
||||
NbtCompound tags = mainHandItem.getNbt();
|
||||
if (tags == null || !tags.contains("ExtraAttributes", 10))
|
||||
return;
|
||||
|
||||
NbtCompound extraAttributes = tags.getCompound("ExtraAttributes");
|
||||
if (extraAttributes == null || !extraAttributes.contains("champion_combat_xp"))
|
||||
return;
|
||||
|
||||
ItemCombatXp = extraAttributes.getDouble("champion_combat_xp");
|
||||
|
||||
if (ItemCombatXp < 50000) {
|
||||
ChampionExp = 50000;
|
||||
ChampionLevel = "I";
|
||||
} else if (ItemCombatXp < 100000) {
|
||||
ChampionExp = 100000;
|
||||
ChampionExpCumu = 50000;
|
||||
ChampionLevel = "II";
|
||||
} else if (ItemCombatXp < 250000) {
|
||||
ChampionExp = 250000;
|
||||
ChampionExpCumu = 100000;
|
||||
ChampionLevel = "III";
|
||||
} else if (ItemCombatXp < 500000) {
|
||||
ChampionExp = 500000;
|
||||
ChampionExpCumu = 250000;
|
||||
ChampionLevel = "IV";
|
||||
} else if (ItemCombatXp < 1000000) {
|
||||
ChampionExp = 1000000;
|
||||
ChampionExpCumu = 500000;
|
||||
ChampionLevel = "V";
|
||||
} else if (ItemCombatXp < 1500000) {
|
||||
ChampionExp = 1500000;
|
||||
ChampionExpCumu = 1000000;
|
||||
ChampionLevel = "VI";
|
||||
} else if (ItemCombatXp < 2000000) {
|
||||
ChampionExp = 2000000;
|
||||
ChampionExpCumu = 1500000;
|
||||
ChampionLevel = "VII";
|
||||
} else if (ItemCombatXp < 2500000) {
|
||||
ChampionExp = 2500000;
|
||||
ChampionExpCumu = 2000000;
|
||||
ChampionLevel = "VIII";
|
||||
} else if (ItemCombatXp < 3000000) {
|
||||
ChampionExp = 3000000;
|
||||
ChampionExpCumu = 2500000;
|
||||
ChampionLevel = "IX";
|
||||
} else if (ItemCombatXp > 3000000) {
|
||||
ChampionExp = -1;
|
||||
ChampionExpCumu = 3000000;
|
||||
ChampionLevel = "X";
|
||||
}
|
||||
|
||||
ChampionPercent = new DecimalFormat("##.00")
|
||||
.format((ItemCombatXp - ChampionExpCumu) / (ChampionExp - ChampionExpCumu) * 100);
|
||||
}
|
||||
|
||||
// show hud
|
||||
if(ItemCombatXp > 0) {
|
||||
NumberFormat format = NumberFormat.getIntegerInstance();
|
||||
|
||||
TextRenderer textRenderer = Instance.textRenderer;
|
||||
String text = "Champion " + ChampionLevel + ": "
|
||||
+ format.format(ItemCombatXp) + " / "
|
||||
+ (ChampionExp == -1 ? "Maxed" : format.format(ChampionExp) + " (" + ChampionPercent + "%)");
|
||||
int width = context.getScaledWindowWidth();
|
||||
int height = context.getScaledWindowHeight();
|
||||
int textWidth = textRenderer.getWidth(text);
|
||||
|
||||
int xPos = width / 2 - textWidth / 2;
|
||||
int yPos = height - 90;
|
||||
|
||||
context.drawTextWithShadow(textRenderer, text, xPos, yPos, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package lul.flummi.championoverlay.event;
|
||||
|
||||
import lul.flummi.championoverlay.client.rendering.OverlayRenderer;
|
||||
import com.mikitellurium.telluriumforge.event.EventHelper;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
|
||||
public class ModEvents {
|
||||
|
||||
private static final EventHelper HELPER = new EventHelper();
|
||||
|
||||
public static void register() {
|
||||
HELPER.addListener(HudRenderCallback.EVENT, OverlayRenderer::renderOverlay).registerAll();
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
12
src/main/resources/championoverlay.mixins.json
Normal file
12
src/main/resources/championoverlay.mixins.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "lul.flummi.championoverlay.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"client": [
|
||||
]
|
||||
}
|
39
src/main/resources/fabric.mod.json
Normal file
39
src/main/resources/fabric.mod.json
Normal file
@ -0,0 +1,39 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "championoverlay",
|
||||
"version": "${version}",
|
||||
"name": "Champion Overlay",
|
||||
"description": "Show progress from championenchantment",
|
||||
"authors": [
|
||||
"Flummi"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "",
|
||||
"sources": ""
|
||||
},
|
||||
"license": "MIT License",
|
||||
"icon": "assets/championoverlay/championoverlay_icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"lul.flummi.championoverlay.ChampionOverlay"
|
||||
],
|
||||
"client": [
|
||||
"lul.flummi.championoverlay.Client"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"championoverlay.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.15.1",
|
||||
"minecraft": "~1.20.4",
|
||||
"java": ">=17",
|
||||
"fabric-api": "*",
|
||||
"fabric-key-binding-api-v1": "*",
|
||||
"telluriumforge": ">=1.2.1"
|
||||
},
|
||||
"suggests": {
|
||||
"another-mod": "*"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user