proper formatting
All checks were successful
build / build (push) Successful in 1m23s

This commit is contained in:
Flummi 2023-06-07 15:07:56 +02:00
parent d98070f7c0
commit 3358404a0f
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
12 changed files with 562 additions and 387 deletions

View File

@ -1,48 +0,0 @@
package lel.flummi.skilloverlay.api;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lel.flummi.skilloverlay.api.records.Skills;
import lel.flummi.skilloverlay.api.records.Skills.Skill;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class ApiSkills {
public static HashMap<String, Skill> SKILLS;
public static void init() {
String apikey = skilloverlayconfig.get().general.apiKey;
String apiurl = "https://api.hypixel.net/resources/skyblock/skills?key=" + apikey;
if(apikey.length() > 0) {
Skills skills = ApiSkills.updateSkills(apiurl);
if(skills != null) {
SKILLS = skills.skills();
}
else {
System.out.println("leer uff");
}
}
}
public static Skills updateSkills(String apiurl) {
if(apiurl.length() == 0)
return null;
try {
URL url = new URL(apiurl);
InputStreamReader reader = new InputStreamReader(url.openStream());
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
return gson.fromJson(reader, Skills.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -4,6 +4,8 @@ import net.minecraft.client.MinecraftClient;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@ -14,8 +16,20 @@ import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class PlayerProfile {
public static Member PROFILE;
private static Timer timerTask;
private static boolean timerSet;
public static void init(Boolean timer) {
if (timer && !timerSet) {
timerTask = new Timer("Timer");
timerTask.scheduleAtFixedRate(new TimerTask() {
public void run() {
PlayerProfile.init(false);
}
}, 1000L, 1000L * 60L);
timerSet = true;
}
public static void init() {
String apikey = skilloverlayconfig.get().general.apiKey;
String uuid = MinecraftClient.getInstance().getSession().getUuidOrNull().toString().replace("-", "");
String apiurl = "https://api.hypixel.net/skyblock/profiles?key=" + apikey + "&uuid=" + uuid;
@ -25,11 +39,12 @@ public class PlayerProfile {
if (profile != null) {
profile.profiles().removeIf(p -> !p.selected());
PROFILE = profile.profiles().get(0).members().get(uuid);
}
else {
} else {
System.out.println("leer uff");
}
}
System.out.println("API update! (every minute)");
}
public static Profile updateProfile(String apiurl) {

View File

@ -0,0 +1,47 @@
package lel.flummi.skilloverlay.api;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lel.flummi.skilloverlay.api.records.Skills;
import lel.flummi.skilloverlay.api.records.Skills.Skill;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class PlayerSkills {
public static HashMap<String, Skill> SKILLS;
public static void init() {
String apikey = skilloverlayconfig.get().general.apiKey;
String apiurl = "https://api.hypixel.net/resources/skyblock/skills?key=" + apikey;
if (apikey.length() > 0) {
Skills skills = PlayerSkills.updateSkills(apiurl);
if (skills != null) {
SKILLS = skills.skills();
} else {
System.out.println("leer uff");
}
}
}
public static Skills updateSkills(String apiurl) {
if (apiurl.length() == 0)
return null;
try {
URL url = new URL(apiurl);
InputStreamReader reader = new InputStreamReader(url.openStream());
Gson gson = new GsonBuilder()
.serializeNulls()
.create();
return gson.fromJson(reader, Skills.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -7,16 +7,14 @@ import com.google.gson.annotations.SerializedName;
public record Profile(
boolean success,
List<Profiles> profiles
) {
List<Profiles> profiles) {
public record Profiles(
@SerializedName("profile_id") String profileId,
@SerializedName("last_save") long lastSave,
HashMap<String, Member> members,
boolean selected
) {
boolean selected) {
public record Member(
double experience_skill_farming
){}
float experience_skill_farming) {
}
}
}

View File

@ -3,31 +3,32 @@ package lel.flummi.skilloverlay.api.records;
import java.util.HashMap;
import java.util.List;
import lel.flummi.skilloverlay.utils.SkillInfo;
public record Skills(
HashMap<String, Skill> skills
) {
HashMap<String, Skill> skills) {
public record Skill(
String name,
int maxLevel,
List<Level> levels
) {
List<Level> levels) {
public record Level(
int level,
long totalExpRequired
) {}
float totalExpRequired) {
}
public int getLevel(double exp) {
public SkillInfo getLevel(float exp) {
int aktLevel = 0;
for (Level tmp : this.levels()) {
System.out.println((exp > tmp.totalExpRequired) + "; exp: " + exp + "; ter: " + tmp.totalExpRequired);
if (exp < tmp.totalExpRequired) {
return aktLevel;
// int level, float totalXp, float currentXp, float currentXpMax
return new SkillInfo(aktLevel, tmp.totalExpRequired, exp, tmp.totalExpRequired);
}
aktLevel = tmp.level;
}
return 0;
}
return null;
}
}
}

View File

@ -6,7 +6,9 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -16,9 +18,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Environment(EnvType.CLIENT)
@Mixin(InGameHud.class)
public abstract class GameRenderMixin {
@Shadow @Final private MinecraftClient client;
@Shadow
@Final
private MinecraftClient client;
@Inject(at = @At("RETURN"), method = "render")
@Inject(method = "render", at = @At("RETURN"))
private void render(MatrixStack matrices, float tickDelta, CallbackInfo ci) {
skilloverlay.OVERLAY.render(matrices, client);
}

View File

@ -8,8 +8,10 @@ import net.minecraft.util.Formatting;
import net.minecraft.client.gui.DrawableHelper;
import com.mojang.blaze3d.systems.RenderSystem;
//import lel.flummi.skilloverlay.skilloverlay;
import lel.flummi.skilloverlay.api.PlayerProfile;
import lel.flummi.skilloverlay.api.PlayerSkills;
import lel.flummi.skilloverlay.utils.LerpUtils;
import lel.flummi.skilloverlay.utils.SkillInfo;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -35,12 +37,23 @@ public class FarmingOverlay extends DrawableHelper {
private ArrayList<Float> cropsOverLastXSeconds = new ArrayList<>();
private String cropName;
private SkillInfo skillInfo = null;
private SkillInfo skillInfoLast = null;
private float lastTotalXp = -1;
private boolean isFarming = false;
private final LinkedList<Float> xpGainQueue = new LinkedList<>();
private float xpGainHourLast = -1;
private float xpGainHour = -1;
private int xpGainTimer = 0;
public FarmingOverlay() {
/*HudRenderCallback.EVENT.register((matrixStack, tickDelta) -> {
if(client.player == null)
return;
this.render(matrixStack, client);
});*/
/*
* HudRenderCallback.EVENT.register((matrixStack, tickDelta) -> {
* if(client.player == null)
* return;
* this.render(matrixStack, client);
* });
*/
}
public void render(MatrixStack matrixStack, MinecraftClient client) {
@ -60,10 +73,11 @@ public class FarmingOverlay extends DrawableHelper {
this.lastUpdate = System.currentTimeMillis();
ItemStack heldItem = client.player.getMainHandStack();
String internalName = "";
this.counter = 0;
this.counter = -1;
boolean holdingFarmItem = false;
this.cultivatingLast = cultivating;
this.cultivating = 0;
xpGainHourLast = xpGainHour;
// System.out.println(skilloverlay.PROFILE.data().skills().get("farming").level());
@ -90,8 +104,7 @@ public class FarmingOverlay extends DrawableHelper {
cultivating = ea.getInt("farmed_cultivating");
this.counterQueue.add(0, this.counter);
}
}
else
} else
holdingFarmItem = false;
}
@ -128,6 +141,50 @@ public class FarmingOverlay extends DrawableHelper {
}
}
skillInfoLast = skillInfo;
skillInfo = PlayerSkills.SKILLS.get("FARMING").getLevel(PlayerProfile.PROFILE.experience_skill_farming());
if (skillInfo != null) {
float totalXp = skillInfo.totalXp;
if (lastTotalXp > 0) {
float delta = totalXp - lastTotalXp;
if (delta > 0 && delta < 1000) {
xpGainTimer = 3;
xpGainQueue.add(0, delta);
while (xpGainQueue.size() > 30) {
xpGainQueue.removeLast();
}
float totalGain = 0;
for (float f : xpGainQueue)
totalGain += f;
xpGainHour = totalGain * (60 * 60) / xpGainQueue.size();
isFarming = true;
} else if (xpGainTimer > 0) {
xpGainTimer--;
xpGainQueue.add(0, 0f);
while (xpGainQueue.size() > 30) {
xpGainQueue.removeLast();
}
float totalGain = 0;
for (float f : xpGainQueue)
totalGain += f;
xpGainHour = totalGain * (60 * 60) / xpGainQueue.size();
isFarming = true;
} else if (delta <= 0) {
isFarming = false;
}
lastTotalXp = totalXp;
}
}
while (this.counterQueue.size() >= 4) {
this.counterQueue.removeLast();
}
@ -198,19 +255,84 @@ public class FarmingOverlay extends DrawableHelper {
overlayStringList.add(new OverlayString(this.cropName + "/m", "N/A"));
} else {
float cpsInterp = interp(this.cropsPerSecond, this.cropsPerSecondLast);
overlayStringList.add(new OverlayString(this.cropName + "/m", String.format("%,.2f", cpsInterp * 60 * 30)));
overlayStringList
.add(new OverlayString(this.cropName + "/m", String.format("%,.2f", cpsInterp * 60 * 30)));
}
}
if (this.cultivatingTier <= 9 && this.cultivating > 0) {
int counterInterp = (int) interp(this.cultivating, this.cultivatingLast);
overlayStringList.add(new OverlayString("Cultivating", format.format(counterInterp) + "/" + this.cultivatingTierAmount));
overlayStringList.add(
new OverlayString("Cultivating", format.format(counterInterp) + "/" + this.cultivatingTierAmount));
}
if (this.cultivatingTier == 10) {
int counterInterp = (int) interp(this.cultivating, this.cultivatingLast);
overlayStringList.add(new OverlayString("Cultivating", format.format(counterInterp)));
}
// xp
float xpInterp = xpGainHour;
if (xpGainHourLast == xpGainHour && xpGainHour <= 0) {
overlayStringList.add(new OverlayString("XP/h", "N/A"));
} else {
xpInterp = interp(xpGainHour, xpGainHourLast);
overlayStringList.add(new OverlayString("XP/h",
format.format(xpInterp) + (isFarming ? "" : Formatting.RED + " (PAUSED)")));
}
// skillinfo
if (skillInfo != null && skillInfo.level < 60) {
StringBuilder levelStr = new StringBuilder(skillInfo.level);
levelStr.append(Formatting.GRAY)
.append("[");
float progress = skillInfo.currentXp / skillInfo.currentXpMax;
if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) {
progress = interp(progress, skillInfoLast.currentXp / skillInfoLast.currentXpMax);
}
float lines = 25;
for (int i = 0; i < lines; i++) {
if (i / lines < progress) {
levelStr.append(Formatting.YELLOW);
} else {
levelStr.append(Formatting.DARK_GRAY);
}
levelStr.append('|');
}
levelStr.append(Formatting.GRAY)
.append("] ")
.append(Formatting.YELLOW)
.append((int) (progress * 100))
.append("%");
int current = (int) skillInfo.currentXp;
if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) {
current = (int) interp(current, skillInfoLast.currentXp);
}
int remaining = (int) (skillInfo.currentXpMax - skillInfo.currentXp);
if (skillInfoLast != null && skillInfo.currentXpMax == skillInfoLast.currentXpMax) {
remaining = (int) interp(remaining, (int) (skillInfoLast.currentXpMax - skillInfoLast.currentXp));
}
overlayStringList.add(new OverlayString("Farming", levelStr.toString()));
overlayStringList.add(new OverlayString("Current XP", format.format(current)));
if (remaining < 0) {
overlayStringList.add(new OverlayString("Remaining XP", "Maxed!"));
// overlayStringList.add(new OverlayString("ETA", "Maxed!"));
} else {
overlayStringList.add(new OverlayString("Remaining XP", format.format(remaining)));
if (xpGainHour < 1000) {
// overlayStringList.add(new OverlayString("ETA", "N/A"));
} else {
// overlayStringList.add(new OverlayString("ETA", );
}
}
}
float yaw = client.player.getYaw();
float pitch = client.player.getPitch();
yaw %= 360;
@ -235,29 +357,23 @@ public class FarmingOverlay extends DrawableHelper {
int xAxis = 10;
int yAxis = 200;
// Get the longest string in the array
int longestString = 0;
int BoxWidth = 0;
for (OverlayString s : overlayStringList) {
String combined = s.toString();
if (combined.length() > longestString) {
longestString = combined.length();
BoxWidth = this.client.textRenderer.getWidth(combined);
}
}
if (!overlayStringList.isEmpty()) {
int BoxWidth = overlayStringList.stream().map(t -> this.client.textRenderer.getWidth(t.toString()))
.max(Integer::compareTo).get();
int lineHeight = this.client.textRenderer.fontHeight + 2;
int offset = 5;
DrawableHelper.fill(matrixStack, xAxis, yAxis, xAxis + BoxWidth + 10,
DrawableHelper.fill(matrixStack, xAxis, yAxis, xAxis + BoxWidth + (offset * 2),
yAxis + ((lineHeight + 1) * overlayStringList.size()), 0x64000000);
for (OverlayString line : overlayStringList) {
int offset = 5;
this.client.textRenderer.drawWithShadow(this.matrixStack, line.toString(), xAxis + offset, yAxis + offset, 0xFFFFFF);
this.client.textRenderer.drawWithShadow(this.matrixStack, line.toString(), xAxis + offset,
yAxis + offset,
0xFFFFFF);
yAxis += lineHeight;
}
}
}
private float interp(float now, float last) {
float interp = now;

View File

@ -1,10 +1,11 @@
package lel.flummi.skilloverlay;
import net.fabricmc.api.ModInitializer;
//import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import lel.flummi.skilloverlay.overlays.FarmingOverlay;
import lel.flummi.skilloverlay.api.PlayerProfile;
import lel.flummi.skilloverlay.api.ApiSkills;
import lel.flummi.skilloverlay.api.PlayerSkills;
import lel.flummi.skilloverlay.config.skilloverlayconfig;
public class skilloverlay implements ModInitializer {
@ -18,7 +19,15 @@ public class skilloverlay implements ModInitializer {
skilloverlayconfig.init();
OVERLAY = new FarmingOverlay();
ApiSkills.init();
PlayerProfile.init();
PlayerSkills.init();
PlayerProfile.init(false);
/*
* ClientReceiveMessageEvents.ALLOW_GAME.register((message, overlay) -> {
* System.out.println("message: " + message.getContent() + "; overlay: " +
* overlay);
* return true;
* });
*/
}
}

View File

@ -0,0 +1,16 @@
package lel.flummi.skilloverlay.utils;
public class SkillInfo {
public final int level;
public final float totalXp;
public final float currentXp;
public final float currentXpMax;
public boolean fromApi = true;
public SkillInfo(int level, float totalXp, float currentXp, float currentXpMax) {
this.level = level;
this.totalXp = totalXp;
this.currentXp = currentXp;
this.currentXpMax = currentXpMax;
}
}

View File

@ -0,0 +1,17 @@
package lel.flummi.skilloverlay.utils;
public class XPInformation {
private static final XPInformation INSTANCE = new XPInformation();
public static XPInformation getInstance() {
return INSTANCE;
}
public static class SkillInfo {
public int level;
public float totalXp;
public float currentXp;
public float currentXpMax;
public boolean fromApi = false;
}
}