Skip to content

Commit

Permalink
add trinkets compat
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Aug 1, 2024
1 parent ebd4dd5 commit a6f30a0
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ repositories {
name = 'Up-Mods'
url = 'https://maven.uuid.gg/releases'
}
maven {
name = "Ladysnake"
url = 'https://maven.ladysnake.org/releases'
}
}

loom {
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/github/ennuil/ok_zoomer/utils/ZoomUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,10 +41,14 @@ public class ZoomUtils {

public static final TagKey<Item> ZOOM_DEPENDENCIES_TAG = TagKey.create(Registries.ITEM, ZoomUtils.id("zoom_dependencies"));

public static final Predicate<ItemStack> 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<LocalPlayer> 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
Expand Down Expand Up @@ -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<LocalPlayer> provider) {
hasSpyglass = hasSpyglass.or(provider);
}
}
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
]
}
}
Expand Down

0 comments on commit a6f30a0

Please sign in to comment.