fix: make UserResourceEvents.disable available in ResourcePackInterceptor API
This commit is contained in:
parent
c015071742
commit
897b11aa25
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user