Skip to content

Commit

Permalink
Merge pull request #708 from BigloBot/main
Browse files Browse the repository at this point in the history
Profile Viewer
  • Loading branch information
kevinthegreat1 authored Jun 30, 2024
2 parents bc773c7 + d824171 commit b75bfdb
Show file tree
Hide file tree
Showing 59 changed files with 2,539 additions and 74 deletions.
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipManager;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen;
import de.hysky.skyblocker.skyblock.rift.TheRift;
import de.hysky.skyblocker.skyblock.searchoverlay.SearchOverManager;
import de.hysky.skyblocker.skyblock.shortcut.Shortcuts;
Expand Down Expand Up @@ -105,6 +106,7 @@ public void onInitializeClient() {
Utils.init();
SkyblockerConfigManager.init();
SkyblockerScreen.initClass();
ProfileViewerScreen.initClass();
Tips.init();
NEURepoManager.init();
//ImageRepoLoader.init();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/de/hysky/skyblocker/mixins/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import de.hysky.skyblocker.injected.SkyblockerStack;
import de.hysky.skyblocker.skyblock.PetCache.PetInfo;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.minecraft.client.MinecraftClient;
import net.minecraft.component.ComponentHolder;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -108,8 +110,8 @@ public abstract class ItemStackMixin implements ComponentHolder, SkyblockerStack
}

@Unique
private boolean skyblocker$shouldProcess() {
return Utils.isOnSkyblock() && SkyblockerConfigManager.get().mining.enableDrillFuel && ItemUtils.hasCustomDurability((ItemStack) (Object) this);
private boolean skyblocker$shouldProcess() { // Durability bar renders atop of tooltips in ProfileViewer so disable on this screen
return !(MinecraftClient.getInstance().currentScreen instanceof ProfileViewerScreen) && Utils.isOnSkyblock() && SkyblockerConfigManager.get().mining.enableDrillFuel && ItemUtils.hasCustomDurability((ItemStack) (Object) this);
}

@Unique
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/de/hysky/skyblocker/skyblock/PetCache.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package de.hysky.skyblocker.skyblock;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.Optional;

import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
Expand All @@ -26,6 +14,16 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.screen.slot.Slot;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

/**
* Doesn't work with auto pet right now because thats complicated.
Expand Down Expand Up @@ -135,12 +133,13 @@ public static PetInfo getCurrentPet() {
return CACHED_PETS.containsKey(uuid) && CACHED_PETS.get(uuid).containsKey(profileId) ? CACHED_PETS.get(uuid).get(profileId) : null;
}

public record PetInfo(String type, double exp, String tier, Optional<String> uuid) {
public record PetInfo(String type, double exp, String tier, Optional<String> uuid, Optional<String> item) {
public static final Codec<PetInfo> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.STRING.fieldOf("type").forGetter(PetInfo::type),
Codec.DOUBLE.fieldOf("exp").forGetter(PetInfo::exp),
Codec.STRING.fieldOf("tier").forGetter(PetInfo::tier),
Codec.STRING.optionalFieldOf("uuid").forGetter(PetInfo::uuid))
Codec.STRING.optionalFieldOf("uuid").forGetter(PetInfo::uuid),
Codec.STRING.optionalFieldOf("heldItem").forGetter(PetInfo::item))
.apply(instance, PetInfo::new));
private static final Codec<Object2ObjectOpenHashMap<String, Object2ObjectOpenHashMap<String, PetInfo>>> SERIALIZATION_CODEC = Codec.unboundedMap(Codec.STRING,
Codec.unboundedMap(Codec.STRING, CODEC).xmap(Object2ObjectOpenHashMap::new, Object2ObjectOpenHashMap::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private static void checkMessageForDeaths(String message) {
if (s.equals("You")) return MinecraftClient.getInstance().getSession().getUsername(); //This will be wrong if the dead player is called 'You' but that's unlikely
else return s;
});
ProfileUtils.updateProfile(whoDied).thenAccept(player -> firstDeathHasSpiritPet = hasSpiritPet(player, whoDied));
ProfileUtils.updateProfileByName(whoDied).thenAccept(player -> firstDeathHasSpiritPet = hasSpiritPet(player, whoDied));
}

private static void checkMessageForWatcher(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.regex.Pattern;

public class ItemStackBuilder {
private static final Pattern SKULL_UUID_PATTERN = Pattern.compile("(?<=SkullOwner:\\{)Id:\"(.{36})\"");
private static final Pattern SKULL_TEXTURE_PATTERN = Pattern.compile("(?<=Properties:\\{textures:\\[0:\\{Value:)\"(.+?)\"");
public static final Pattern SKULL_UUID_PATTERN = Pattern.compile("(?<=SkullOwner:\\{)Id:\"(.{36})\"");
public static final Pattern SKULL_TEXTURE_PATTERN = Pattern.compile("(?<=Properties:\\{textures:\\[0:\\{Value:)\"(.+?)\"");
private static final Pattern COLOR_PATTERN = Pattern.compile("color:(\\d+)");
private static final Pattern EXPLOSION_COLOR_PATTERN = Pattern.compile("\\{Explosion:\\{(?:Type:[0-9a-z]+,)?Colors:\\[(?<color>[0-9]+)]\\}");
private static Map<String, Map<Rarity, PetNumbers>> petNums;
Expand Down Expand Up @@ -138,7 +138,7 @@ private static List<Pair<String, String>> petData(String internalName) {
return list;
}

private static String injectData(String string, List<Pair<String, String>> injectors) {
public static String injectData(String string, List<Pair<String, String>> injectors) {
for (Pair<String, String> injector : injectors) {
string = string.replaceAll(injector.getLeft(), injector.getRight());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package de.hysky.skyblocker.skyblock.profileviewer;

import com.mojang.blaze3d.systems.RenderSystem;
import de.hysky.skyblocker.skyblock.profileviewer.utils.SkullCreator;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.Map;

public class ProfileViewerNavButton extends ClickableWidget {
private final static Identifier BUTTON_TEXTURES_TOGGLED = Identifier.of("container/creative_inventory/tab_top_selected_2");
private final static Identifier BUTTON_TEXTURES = Identifier.of("container/creative_inventory/tab_top_unselected_2");
private boolean toggled;
private final int index;
private final ProfileViewerScreen screen;
private final ItemStack icon;

private static final Map<String, ItemStack> HEAD_ICON = Map.ofEntries(
Map.entry("Skills", Ico.IRON_SWORD),
Map.entry("Slayers", SkullCreator.createSkull("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHBzOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzkzMzZkN2NjOTVjYmY2Njg5ZjVlOGM5NTQyOTRlYzhkMWVmYzQ5NGE0MDMxMzI1YmI0MjdiYzgxZDU2YTQ4NGQifX19")),
Map.entry("Pets", Ico.BONE),
Map.entry("Dungeons", SkullCreator.createSkull("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHBzOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzliNTY4OTViOTY1OTg5NmFkNjQ3ZjU4NTk5MjM4YWY1MzJkNDZkYjljMWIwMzg5YjhiYmViNzA5OTlkYWIzM2QifX19")),
Map.entry("Inventories", Ico.E_CHEST),
Map.entry("Collections", Ico.PAINTING)
);

public ProfileViewerNavButton(ProfileViewerScreen screen, String tabName, int index, boolean toggled) {
super(-100, -100, 28, 32, Text.empty());
this.screen = screen;
this.toggled = toggled;
this.index = index;
this.icon = HEAD_ICON.getOrDefault(tabName, Ico.BARRIER);
}

@Override
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
RenderSystem.disableDepthTest();

context.drawGuiTexture(toggled ? BUTTON_TEXTURES_TOGGLED : BUTTON_TEXTURES, this.getX(), this.getY(), this.width, this.height - ((this.toggled) ? 0 : 4));
context.drawItem(this.icon, this.getX() + 6, this.getY() + (this.toggled ? 7 : 9));

RenderSystem.enableDepthTest();
}

@Override
public void onClick(double mouseX, double mouseY) {
screen.onNavButtonClick(this);
}

@Override
protected void appendClickableNarrations(NarrationMessageBuilder builder) {}

public void setToggled(boolean toggled) {
this.toggled = toggled;
}

public int getIndex() {
return index;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.hysky.skyblocker.skyblock.profileviewer;

import de.hysky.skyblocker.skyblock.profileviewer.utils.SubPageSelectButton;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ClickableWidget;

import java.util.List;

public interface ProfileViewerPage {
void render(DrawContext context, int mouseX, int mouseY, float delta, int rootX, int rootY);
default List<ClickableWidget> getButtons() {
return null;
}
default void onNavButtonClick(SubPageSelectButton selectButton) {}
default void markWidgetsAsVisible() {}
default void markWidgetsAsInvisible() {}
default void nextPage() {}
default void previousPage() {}
}
Loading

0 comments on commit b75bfdb

Please sign in to comment.