diff --git a/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/ResourcePackInterceptor.java b/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/ResourcePackInterceptor.java index 77ee45e..180c942 100644 --- a/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/ResourcePackInterceptor.java +++ b/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/ResourcePackInterceptor.java @@ -1,5 +1,10 @@ package io.gitlab.jfronny.libjf.data.manipulation.api; +import io.gitlab.jfronny.commons.concurrent.ScopedValue; +import io.gitlab.jfronny.commons.throwable.ExceptionWrapper; +import io.gitlab.jfronny.commons.throwable.ThrowingRunnable; +import io.gitlab.jfronny.commons.throwable.ThrowingSupplier; +import io.gitlab.jfronny.libjf.data.manipulation.impl.ResourcePackHook; import net.minecraft.resource.InputSupplier; import net.minecraft.resource.ResourcePack; import net.minecraft.resource.ResourceType; @@ -15,6 +20,22 @@ import java.util.function.Supplier; * Register as a libjf:resource_pack_interceptor entrypoint. */ public interface ResourcePackInterceptor { + static TVal disable(ThrowingSupplier then) throws TEx { + try { + return io.gitlab.jfronny.commons.concurrent.ScopedValue.getWhere(ResourcePackHook.DISABLED, true, then.orThrow()); + } catch (ExceptionWrapper ew) { + throw (TEx) ExceptionWrapper.unwrap(ew); + } + } + + static void disable(ThrowingRunnable then) throws TEx { + try { + ScopedValue.runWhere(ResourcePackHook.DISABLED, true, then.orThrow()); + } catch (ExceptionWrapper ew) { + throw (TEx) ExceptionWrapper.unwrap(ew); + } + } + default InputSupplier openRoot(String[] fileName, InputSupplier previous, ResourcePack pack) { return previous; } diff --git a/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/UserResourceEvents.java b/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/UserResourceEvents.java index 8b75305..944b063 100644 --- a/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/UserResourceEvents.java +++ b/libjf-data-manipulation-v0/src/main/java/io/gitlab/jfronny/libjf/data/manipulation/api/UserResourceEvents.java @@ -21,19 +21,11 @@ import java.util.function.Supplier; @Deprecated public class UserResourceEvents { public static TVal disable(ThrowingSupplier then) throws TEx { - try { - return ScopedValue.getWhere(ResourcePackHook.DISABLED, true, then.orThrow()); - } catch (ExceptionWrapper ew) { - throw (TEx) ExceptionWrapper.unwrap(ew); - } + return ResourcePackInterceptor.disable(then); } public static void disable(ThrowingRunnable then) throws TEx { - try { - ScopedValue.runWhere(ResourcePackHook.DISABLED, true, then.orThrow()); - } catch (ExceptionWrapper ew) { - throw (TEx) ExceptionWrapper.unwrap(ew); - } + ResourcePackInterceptor.disable(then); } public static final Event OPEN_ROOT = EventFactory.createArrayBacked(OpenRoot.class,