diff --git a/build.gradle b/build.gradle index 35cfb60..ce3ff1e 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,10 @@ repositories { name = 'Up-Mods' url = 'https://maven.uuid.gg/releases' } + maven { + name = "Ladysnake" + url = 'https://maven.ladysnake.org/releases' + } } loom { @@ -79,6 +83,9 @@ dependencies { modImplementation libs.libzoomer modCompileOnly libs.wrench.wrapper + modCompileOnly libs.bundles.trinkets + modLocalRuntime libs.bundles.trinkets + include libs.libzoomer include libs.wrench.wrapper } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 230221c..7a33a64 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,6 +11,9 @@ libzoomer = "0.10.0+1.21" wrench_wrapper = "0.4.0" modmenu = "11.0.1" +trinkets = "3.10.0" +cca = "6.1.1" + [libraries] minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } parchment = { module = "org.parchmentmc.data:parchment-1.21", version.ref = "parchment" } @@ -21,8 +24,13 @@ libzoomer = { module = "io.github.ennuil.libzoomer:libzoomer-fabric", version.re wrench_wrapper = { module = "io.github.ennuil:wrench_wrapper", version.ref = "wrench_wrapper" } modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" } +trinkets = { module = "dev.emi:trinkets", version.ref = "trinkets" } +cca_base = { module = "org.ladysnake.cardinal-components-api:cardinal-components-base", version.ref = "cca" } +cca_entity = { module = "org.ladysnake.cardinal-components-api:cardinal-components-entity", version.ref = "cca" } + # If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". [bundles] +trinkets = ["trinkets", "cca_base", "cca_entity"] [plugins] quilt_loom = { id = "org.quiltmc.loom", version.ref = "quilt_loom" } diff --git a/src/main/java/io/github/ennuil/ok_zoomer/OkZoomerClientMod.java b/src/main/java/io/github/ennuil/ok_zoomer/OkZoomerClientMod.java index d62ec4d..aded108 100644 --- a/src/main/java/io/github/ennuil/ok_zoomer/OkZoomerClientMod.java +++ b/src/main/java/io/github/ennuil/ok_zoomer/OkZoomerClientMod.java @@ -1,5 +1,6 @@ package io.github.ennuil.ok_zoomer; +import io.github.ennuil.ok_zoomer.compat.TrinketsCompat; import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager; import io.github.ennuil.ok_zoomer.events.*; import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds; @@ -9,6 +10,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.loader.api.FabricLoader; // This class is responsible for registering the commands and packets public class OkZoomerClientMod implements ClientModInitializer { @@ -34,5 +36,10 @@ public void onInitializeClient() { ClientLifecycleEvents.CLIENT_STARTED.register(ApplyLoadOnceOptionsEvent::readyClient); ClientTickEvents.END_CLIENT_TICK.register(OpenScreenEvent::endClientTick); ClientCommandRegistrationCallback.EVENT.register(RegisterCommands::registerCommands); + + // mod compat + if(FabricLoader.getInstance().isModLoaded("trinkets")) { + TrinketsCompat.init(); + } } } diff --git a/src/main/java/io/github/ennuil/ok_zoomer/compat/TrinketsCompat.java b/src/main/java/io/github/ennuil/ok_zoomer/compat/TrinketsCompat.java new file mode 100644 index 0000000..936e752 --- /dev/null +++ b/src/main/java/io/github/ennuil/ok_zoomer/compat/TrinketsCompat.java @@ -0,0 +1,14 @@ +package io.github.ennuil.ok_zoomer.compat; + +import dev.emi.trinkets.api.TrinketsApi; +import io.github.ennuil.ok_zoomer.utils.ZoomUtils; + +public class TrinketsCompat { + + public static void init() { + ZoomUtils.addSpyglassProvider(player -> { + // Trinkets inventory is an AutoSyncedComponent and therefore safe to query on the client + return player.getComponent(TrinketsApi.TRINKET_COMPONENT).isEquipped(ZoomUtils.IS_VALID_SPYGLASS); + }); + } +} diff --git a/src/main/java/io/github/ennuil/ok_zoomer/events/ManageZoomEvent.java b/src/main/java/io/github/ennuil/ok_zoomer/events/ManageZoomEvent.java index dc3134f..59f0eb8 100644 --- a/src/main/java/io/github/ennuil/ok_zoomer/events/ManageZoomEvent.java +++ b/src/main/java/io/github/ennuil/ok_zoomer/events/ManageZoomEvent.java @@ -5,7 +5,6 @@ import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds; import io.github.ennuil.ok_zoomer.packets.ZoomPackets; import io.github.ennuil.ok_zoomer.utils.ZoomUtils; -import net.fabricmc.fabric.api.tag.client.v1.ClientTags; import net.minecraft.client.Minecraft; import net.minecraft.sounds.SoundEvents; @@ -26,9 +25,7 @@ public static void startClientTick(Minecraft minecraft) { (switch (OkZoomerConfigManager.CONFIG.features.spyglassMode.value()) { case REQUIRE_ITEM, BOTH -> true; default -> false; - } && !minecraft.player.getInventory().contains( - stack -> ClientTags.isInWithLocalFallback(ZoomUtils.ZOOM_DEPENDENCIES_TAG, stack.getItem()) - )); + } && !ZoomUtils.hasSpyglass(minecraft.player)); if (disableZoom) { ZoomUtils.ZOOMER_ZOOM.setZooming(false); diff --git a/src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java b/src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java index 9ca2542..8f7f51c 100644 --- a/src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java +++ b/src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java @@ -7,18 +7,23 @@ import io.github.ennuil.ok_zoomer.config.OkZoomerConfigManager; import io.github.ennuil.ok_zoomer.key_binds.ZoomKeyBinds; import io.github.ennuil.ok_zoomer.packets.ZoomPackets; +import net.fabricmc.fabric.api.tag.client.v1.ClientTags; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.toasts.SystemToast; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.function.Predicate; + // The class that contains most of the logic behind the zoom itself public class ZoomUtils { // The logger, used everywhere to print messages to the console @@ -36,10 +41,14 @@ public class ZoomUtils { public static final TagKey ZOOM_DEPENDENCIES_TAG = TagKey.create(Registries.ITEM, ZoomUtils.id("zoom_dependencies")); + public static final Predicate IS_VALID_SPYGLASS = stack -> ClientTags.isInWithLocalFallback(ZoomUtils.ZOOM_DEPENDENCIES_TAG, stack.getItem()); + public static int zoomStep = 0; private static boolean openCommandScreen = false; + private static Predicate hasSpyglass = player -> player.getInventory().contains(IS_VALID_SPYGLASS); + // The method used for changing the zoom divisor, used by zoom scrolling and the key binds public static void changeZoomDivisor(boolean increase) { //If the zoom is disabled, don't allow for zoom scrolling @@ -120,4 +129,12 @@ public static void setOpenCommandScreen(boolean openCommandScreen) { public static ResourceLocation id(String path) { return ModUtils.id(path); } + + public static boolean hasSpyglass(LocalPlayer player) { + return hasSpyglass.test(player); + } + + public static void addSpyglassProvider(Predicate provider) { + hasSpyglass = hasSpyglass.or(provider); + } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 942007a..0634bee 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -36,8 +36,9 @@ "quilt" ], "dependencies": [ - "fabric-api(required)#{curseforge:306612}{modrinth:P7dR8mSH}", - "libzoomer(embedded)#(ignore:curseforge){modrinth:UuqHBjf9}" + "fabric-api(required){curseforge:306612}{modrinth:P7dR8mSH}", + "libzoomer(embedded){modrinth:UuqHBjf9}#(ignore:curseforge)", + "trinkets(optional){curseforge:341284}{modrinth:5aaWibi9}" ] } }