diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Constants.java | 23 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/ItemUtils.java | 26 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java (renamed from src/main/java/de/hysky/skyblocker/utils/NEURepo.java) | 32 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java | 4 |
4 files changed, 55 insertions, 30 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Constants.java b/src/main/java/de/hysky/skyblocker/utils/Constants.java index fbeb448c..f144b519 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Constants.java +++ b/src/main/java/de/hysky/skyblocker/utils/Constants.java @@ -1,8 +1,31 @@ package de.hysky.skyblocker.utils; +import java.util.function.IntFunction; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + /** * Holds generic static constants */ public interface Constants { String LEVEL_EMBLEMS = "\u2E15\u273F\u2741\u2E19\u03B1\u270E\u2615\u2616\u2663\u213B\u2694\u27B6\u26A1\u2604\u269A\u2693\u2620\u269B\u2666\u2660\u2764\u2727\u238A\u1360\u262C\u269D\u29C9\uA214\u32D6\u2E0E\u26A0\uA541\u3020\u30C4\u2948\u2622\u2623\u273E\u269C\u0BD0\u0A6D\u2742\u16C3\u3023\u10F6\u0444\u266A\u266B\u04C3\u26C1\u26C3\u16DD\uA03E\u1C6A\u03A3\u09EB\u2603\u2654\u26C2\u12DE"; + IntFunction<UnaryOperator<Style>> WITH_COLOR = color -> style -> style.withColor(color); + Supplier<MutableText> PREFIX = () -> Text.empty() + .append(Text.literal("[").formatted(Formatting.GRAY)) + .append(Text.literal("S").styled(WITH_COLOR.apply(0x00ff4c))) + .append(Text.literal("k").styled(WITH_COLOR.apply(0x02fa60))) + .append(Text.literal("y").styled(WITH_COLOR.apply(0x04f574))) + .append(Text.literal("b").styled(WITH_COLOR.apply(0x07ef88))) + .append(Text.literal("l").styled(WITH_COLOR.apply(0x09ea9c))) + .append(Text.literal("o").styled(WITH_COLOR.apply(0x0be5af))) + .append(Text.literal("c").styled(WITH_COLOR.apply(0x0de0c3))) + .append(Text.literal("k").styled(WITH_COLOR.apply(0x10dad7))) + .append(Text.literal("e").styled(WITH_COLOR.apply(0x12d5eb))) + .append(Text.literal("r").styled(WITH_COLOR.apply(0x14d0ff))) + .append(Text.literal("] ").formatted(Formatting.GRAY)); } diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index fa04acf8..50a9bcd1 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.utils; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import de.hysky.skyblocker.config.SkyblockerConfigManager; +import it.unimi.dsi.fastutil.ints.IntIntPair; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.ItemStack; @@ -105,21 +105,18 @@ public class ItemUtils { return extraAttributes != null ? extraAttributes.getString(UUID) : ""; } - @Nullable - public static Durability getDurability(@NotNull ItemStack stack) { - if (!Utils.isOnSkyblock() || !SkyblockerConfigManager.get().locations.dwarvenMines.enableDrillFuel || stack.isEmpty()) { - return null; - } - - if (getExtraAttributesOptional(stack).filter(extraAttributes -> extraAttributes.contains("drill_fuel") || extraAttributes.getString(ItemUtils.ID).equals("PICKONIMBUS")).isEmpty()) { - return null; - } + public static boolean hasCustomDurability(@NotNull ItemStack stack) { + NbtCompound extraAttributes = getExtraAttributes(stack); + return extraAttributes != null && (extraAttributes.contains("drill_fuel") || extraAttributes.getString(ID).equals("PICKONIMBUS")); + } + @Nullable + public static IntIntPair getDurability(@NotNull ItemStack stack) { int current = 0; int max = 0; String clearFormatting; - for (String line : ItemUtils.getTooltipStrings(stack)) { + for (String line : getTooltipStrings(stack)) { clearFormatting = Formatting.strip(line); if (line.contains("Fuel: ")) { if (clearFormatting != null) { @@ -127,7 +124,7 @@ public class ItemUtils { String[] split = clear.split("/"); current = Integer.parseInt(split[0]); max = Integer.parseInt(split[1]) * 1000; - return new Durability(current, max); + return IntIntPair.of(current, max); } } else if (line.contains("uses.")) { if (clearFormatting != null) { @@ -138,7 +135,7 @@ public class ItemUtils { current = Integer.parseInt(usesString); max = 5000; } - return new Durability(current, max); + return IntIntPair.of(current, max); } } } @@ -153,7 +150,4 @@ public class ItemUtils { throw new RuntimeException(e); } } - - public record Durability(int current, int max) { - } } diff --git a/src/main/java/de/hysky/skyblocker/utils/NEURepo.java b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java index 9bc6b245..6d78b3f3 100644 --- a/src/main/java/de/hysky/skyblocker/utils/NEURepo.java +++ b/src/main/java/de/hysky/skyblocker/utils/NEURepoManager.java @@ -1,7 +1,8 @@ package de.hysky.skyblocker.utils; import de.hysky.skyblocker.SkyblockerMod; -import de.hysky.skyblocker.skyblock.itemlist.ItemRegistry; +import de.hysky.skyblocker.skyblock.itemlist.ItemRepository; +import io.github.moulberry.repo.NEURepository; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.minecraft.client.MinecraftClient; @@ -21,11 +22,15 @@ import java.util.concurrent.CompletableFuture; /** * Initializes the NEU repo, which contains item metadata and fairy souls location data. Clones the repo if it does not exist and checks for updates. Use {@link #runAsyncAfterLoad(Runnable)} to run code after the repo is initialized. */ -public class NEURepo { - private static final Logger LOGGER = LoggerFactory.getLogger(NEURepo.class); +public class NEURepoManager { + private static final Logger LOGGER = LoggerFactory.getLogger(NEURepoManager.class); public static final String REMOTE_REPO_URL = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO.git"; - public static final Path LOCAL_REPO_DIR = SkyblockerMod.CONFIG_DIR.resolve("item-repo"); - private static final CompletableFuture<Void> REPO_INITIALIZED = initRepository(); + /** + * Use {@link #NEU_REPO}. + */ + private static final Path LOCAL_REPO_DIR = SkyblockerMod.CONFIG_DIR.resolve("item-repo"); // TODO rename to NotEnoughUpdates-REPO + private static final CompletableFuture<Void> REPO_INITIALIZED = loadRepository(); + public static final NEURepository NEU_REPO = NEURepository.of(LOCAL_REPO_DIR); /** * Adds command to update repository manually from ingame. @@ -41,18 +46,19 @@ public class NEURepo { })))); } - private static CompletableFuture<Void> initRepository() { + private static CompletableFuture<Void> loadRepository() { return CompletableFuture.runAsync(() -> { try { - if (Files.isDirectory(NEURepo.LOCAL_REPO_DIR)) { - try (Git localRepo = Git.open(NEURepo.LOCAL_REPO_DIR.toFile())) { + if (Files.isDirectory(NEURepoManager.LOCAL_REPO_DIR)) { + try (Git localRepo = Git.open(NEURepoManager.LOCAL_REPO_DIR.toFile())) { localRepo.pull().setRebase(true).call(); LOGGER.info("[Skyblocker] NEU Repository Updated"); } } else { - Git.cloneRepository().setURI(REMOTE_REPO_URL).setDirectory(NEURepo.LOCAL_REPO_DIR.toFile()).setBranchesToClone(List.of("refs/heads/master")).setBranch("refs/heads/master").call().close(); + Git.cloneRepository().setURI(REMOTE_REPO_URL).setDirectory(NEURepoManager.LOCAL_REPO_DIR.toFile()).setBranchesToClone(List.of("refs/heads/master")).setBranch("refs/heads/master").call().close(); LOGGER.info("[Skyblocker] NEU Repository Downloaded"); } + NEU_REPO.reload(); } catch (TransportException e){ LOGGER.error("[Skyblocker] Transport operation failed. Most likely unable to connect to the remote NEU repo on github", e); } catch (RepositoryNotFoundException e) { @@ -67,15 +73,15 @@ public class NEURepo { private static void deleteAndDownloadRepository() { CompletableFuture.runAsync(() -> { try { - ItemRegistry.filesImported = false; - File dir = NEURepo.LOCAL_REPO_DIR.toFile(); + ItemRepository.setFilesImported(false); + File dir = NEURepoManager.LOCAL_REPO_DIR.toFile(); recursiveDelete(dir); } catch (Exception ex) { if (MinecraftClient.getInstance().player != null) - MinecraftClient.getInstance().player.sendMessage(Text.translatable("skyblocker.updaterepository.failed"), false); + MinecraftClient.getInstance().player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.updaterepository.failed")), false); return; } - initRepository(); + loadRepository(); }); } diff --git a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java index 4630149c..5ab698a7 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java @@ -78,7 +78,7 @@ public class RenderHelper { * Renders the outline of a box with the specified color components and line width. * This does not use renderer since renderer draws outline using debug lines with a fixed width. */ - public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float lineWidth) { + public static void renderOutline(WorldRenderContext context, Box box, float[] colorComponents, float lineWidth, boolean throughWalls) { if (FrustumUtils.isVisible(box)) { MatrixStack matrices = context.matrixStack(); Vec3d camera = context.camera().getPos(); @@ -90,6 +90,7 @@ public class RenderHelper { RenderSystem.lineWidth(lineWidth); RenderSystem.disableCull(); RenderSystem.enableDepthTest(); + RenderSystem.depthFunc(throughWalls ? GL11.GL_ALWAYS : GL11.GL_LEQUAL); matrices.push(); matrices.translate(-camera.getX(), -camera.getY(), -camera.getZ()); @@ -102,6 +103,7 @@ public class RenderHelper { RenderSystem.lineWidth(1f); RenderSystem.enableCull(); RenderSystem.disableDepthTest(); + RenderSystem.depthFunc(GL11.GL_LEQUAL); } } |