diff options
-rw-r--r-- | build.gradle | 70 | ||||
-rw-r--r-- | gradle.properties | 11 | ||||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.properties | 2 | ||||
-rw-r--r-- | settings.gradle | 1 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java | 10 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/mixin/ItemRendererMixin.java | 5 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 138 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java | 7 | ||||
-rw-r--r-- | src/main/resources/skyblocker.mixins.json | 3 |
9 files changed, 212 insertions, 35 deletions
diff --git a/build.gradle b/build.gradle index 2a4a0af2..a711062e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,27 +1,33 @@ plugins { - id 'fabric-loom' version '0.5-SNAPSHOT' + id 'fabric-loom' version '0.6-SNAPSHOT' id 'maven-publish' } -group = project.maven_group -version = project.mod_version +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group repositories { - jcenter() - maven { - url "https://maven.falseresync.ru" + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. + flatDir { + dirs 'libs' } } dependencies { + implementation 'com.google.code.gson:gson:2.8.6' + // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" - // Cloth API include "me.shedaniel.cloth:config-2:${project.cloth_api_version}" modApi("me.shedaniel.cloth:config-2:${project.cloth_api_version}") { @@ -36,29 +42,42 @@ dependencies { // Mod Menu modImplementation "io.github.prospector:modmenu:${project.mod_menu_version}" -} -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. + // You may need to force-disable transitiveness on them. } processResources { inputs.property "version", project.version - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } +} - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too + // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. + // We'll use that if it's available, but otherwise we'll use the older option. + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion } } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. withSourcesJar() } @@ -68,13 +87,12 @@ jar { } } +// configure the maven publication publishing { publications { mavenJava(MavenPublication) { - artifact(jar) { - builtBy remapJar - } - artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar"){ + // add all the jars that should be included when publishing to maven + artifact(remapJar) { builtBy remapJar } artifact(sourcesJar) { @@ -83,7 +101,11 @@ publishing { } } + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. repositories { - + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. } } diff --git a/gradle.properties b/gradle.properties index 349bddf8..fca4137a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties (https://modmuss50.me/fabric.html) -minecraft_version=1.16.5 -yarn_mappings=1.16.5+build.1 -loader_version=0.11.1 -fabric_api_version=0.29.3+1.16 + minecraft_version=1.16.5 + yarn_mappings=1.16.5+build.5 + loader_version=0.11.3 +fabric_api_version=0.29.3+1.16 +fabric_version=0.31.0+1.16 # APIs ## Cloth Api (https://www.curseforge.com/minecraft/mc-mods/cloth-config/files) cloth_api_version=4.8.3 @@ -18,3 +19,5 @@ mod_menu_version=1.14.13+build.21 mod_version = 1.0.5 maven_group = me.xmrvizzy archives_base_name = skyblocker + +org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_281
\ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be52383e..442d9132 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index 5b60df3d..f91a4fe7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' diff --git a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java index efd746e7..8be9fb3d 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java +++ b/src/main/java/me/xmrvizzy/skyblocker/SkyblockerMod.java @@ -1,21 +1,27 @@ package me.xmrvizzy.skyblocker; +import java.util.Map; + import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.HotbarSlotLock; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.minecraft.client.MinecraftClient; - +import me.xmrvizzy.skyblocker.skyblock.item.PriceInfoTooltip; public class SkyblockerMod implements ClientModInitializer { public static final String NAMESPACE = "skyblocker"; private static int TICKS = 0; - + public static Map prices = PriceInfoTooltip.downloadPrices(); @Override public void onInitializeClient() { HotbarSlotLock.init(); SkyblockerConfig.init(); + + } + public static void onTick() { MinecraftClient client = MinecraftClient.getInstance(); if (client == null) return; diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/ItemRendererMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/ItemRendererMixin.java index 1992db89..eaac1c9c 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/mixin/ItemRendererMixin.java +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/ItemRendererMixin.java @@ -4,12 +4,14 @@ import com.mojang.blaze3d.systems.RenderSystem; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.utils.ItemUtils; import me.xmrvizzy.skyblocker.utils.Utils; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.item.ItemRenderer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; +import net.minecraft.text.LiteralText; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -27,6 +29,7 @@ public abstract class ItemRendererMixin { @Inject(method = "renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD")) public void renderItemBar(TextRenderer renderer, ItemStack stack, int x, int y, @Nullable String countLabel, CallbackInfo ci) { + if (Utils.isSkyblock && SkyblockerConfig.get().locations.dwarvenMines.enableDrillFuel) { if (!stack.isEmpty()) { CompoundTag tag = stack.getTag(); @@ -34,7 +37,7 @@ public abstract class ItemRendererMixin { if (tag.getCompound("ExtraAttributes").contains("drill_fuel")) { float current = 3000.0F; float max = 3000.0F; - + for (String line : ItemUtils.getTooltipStrings(stack)) { if (line.contains("Fuel: ")) { String clear = Pattern.compile("[^0-9 /]").matcher(line).replaceAll("").trim(); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java new file mode 100644 index 00000000..51b30c23 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -0,0 +1,138 @@ +package me.xmrvizzy.skyblocker.skyblock.item; + + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import java.util.zip.GZIPInputStream; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; + + +import me.xmrvizzy.skyblocker.SkyblockerMod; + +public class PriceInfoTooltip { + + public static void onInjectTooltip(ItemStack stack, TooltipContext context, List<Text> list) { + String name = getInternalNameForItem(stack); + + try { + + if(SkyblockerMod.prices != null && SkyblockerMod.prices.containsKey(name)){ + if(!list.toString().contains("Lowest BIN Price")){ + Double price = round((Double)SkyblockerMod.prices.get(name), 2); + + list.add(new LiteralText("Lowest BIN Price: " + price).formatted(Formatting.GOLD)); + } + } + }catch(Exception e) { + + } + + } + public static double round(double value, int places) { + if (places < 0) throw new IllegalArgumentException(); + + BigDecimal bd = new BigDecimal(value); + bd = bd.setScale(places, RoundingMode.HALF_UP); + return bd.doubleValue(); + } + public static String getInternalNameForItem(ItemStack stack) { + if(stack == null) return null; + CompoundTag tag = stack.getTag(); + return getInternalnameFromNBT(tag); + } + + public static String getInternalnameFromNBT(CompoundTag tag) { + String internalname = null; + if(tag != null && tag.contains("ExtraAttributes", 10)) { + CompoundTag ea = tag.getCompound("ExtraAttributes"); + + if(ea.contains("id", 8)) { + internalname = ea.getString("id").replaceAll(":", "-"); + } else { + return null; + } + + + if("ENCHANTED_BOOK".equals(internalname)) { + CompoundTag enchants = ea.getCompound("enchantments"); + + for(String enchname : enchants.getKeys()) { + internalname = enchname.toUpperCase() + ";" + enchants.getInt(enchname); + break; + } + } + } + + return internalname; + } + + public static Map downloadPrices() { + try { + downloadUsingStream("https://moulberry.codes/auction_averages_lbin/1day.json.gz", "1day.json.gz"); + decompressGzipFile("1day.json.gz", "1day.json"); + Gson gson = new Gson(); + Reader reader = Files.newBufferedReader(Paths.get("1day.json")); + // convert JSON file to map + Map<?, ?> map = gson.fromJson(reader, Map.class); + return map; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + private static void decompressGzipFile(String gzipFile, String newFile) { + try { + FileInputStream fis = new FileInputStream(gzipFile); + GZIPInputStream gis = new GZIPInputStream(fis); + FileOutputStream fos = new FileOutputStream(newFile); + byte[] buffer = new byte[1024]; + int len; + while((len = gis.read(buffer)) != -1){ + fos.write(buffer, 0, len); + } + //close resources + fos.close(); + gis.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + private static void downloadUsingStream(String urlStr, String file) throws IOException{ + URL url = new URL(urlStr); + BufferedInputStream bis = new BufferedInputStream(url.openStream()); + FileOutputStream fis = new FileOutputStream(file); + byte[] buffer = new byte[1024]; + int count=0; + while((count = bis.read(buffer,0,1024)) != -1) + { + fis.write(buffer, 0, count); + } + fis.close(); + bis.close(); + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java index 719e4e4f..ef1390e6 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java @@ -4,6 +4,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.Attribute; +import me.xmrvizzy.skyblocker.skyblock.item.PriceInfoTooltip; +import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.ScoreboardObjective; @@ -57,7 +59,10 @@ public class Utils { if (sidebar.isEmpty()) return; if (sidebar.get(sidebar.size() - 1).equals("www.hypixel.net")) { - if (sidebar.get(0).contains("SKYBLOCK")) isSkyblock = true; + if (sidebar.get(0).contains("SKYBLOCK")){ + ItemTooltipCallback.EVENT.register(PriceInfoTooltip::onInjectTooltip); + isSkyblock = true; + } else isSkyblock = false; if (isSkyblock && string.contains("The Catacombs")) isDungeons = true; diff --git a/src/main/resources/skyblocker.mixins.json b/src/main/resources/skyblocker.mixins.json index 3e904f73..4a7691a7 100644 --- a/src/main/resources/skyblocker.mixins.json +++ b/src/main/resources/skyblocker.mixins.json @@ -9,7 +9,8 @@ "ClientPlayNetworkHandlerMixin", "InGameHudMixin", "ItemRendererMixin", - "MinecraftClientMixin" + "MinecraftClientMixin", + ], "injectors": { "defaultRequire": 1 |