fix: make UserResourceEvents.disable available in ResourcePackInterceptor API
All checks were successful
ci/woodpecker/push/vitepress Pipeline was successful
ci/woodpecker/push/jfmod Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-09-30 20:08:05 +02:00
parent c015071742
commit 897b11aa25
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 23 additions and 10 deletions

View File

@ -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, TEx extends Throwable> TVal disable(ThrowingSupplier<TVal, TEx> 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 <TEx extends Throwable> void disable(ThrowingRunnable<TEx> then) throws TEx {
try {
ScopedValue.runWhere(ResourcePackHook.DISABLED, true, then.orThrow());
} catch (ExceptionWrapper ew) {
throw (TEx) ExceptionWrapper.unwrap(ew);
}
}
default InputSupplier<InputStream> openRoot(String[] fileName, InputSupplier<InputStream> previous, ResourcePack pack) {
return previous;
}

View File

@ -21,19 +21,11 @@ import java.util.function.Supplier;
@Deprecated
public class UserResourceEvents {
public static <TVal, TEx extends Throwable> TVal disable(ThrowingSupplier<TVal, TEx> 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 <TEx extends Throwable> void disable(ThrowingRunnable<TEx> 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<OpenRoot> OPEN_ROOT = EventFactory.createArrayBacked(OpenRoot.class,