-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSpecialModelLoaderEvents.java
More file actions
60 lines (50 loc) · 2.57 KB
/
SpecialModelLoaderEvents.java
File metadata and controls
60 lines (50 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package dev.felnull.specialmodelloader.api.event;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.ResourceManager;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
public final class SpecialModelLoaderEvents {
public static final Event<LoadScope> LOAD_SCOPE = EventFactory.createArrayBacked(LoadScope.class, loadScopes -> {
BiPredicate<ResourceManager, Identifier> predicate = Arrays.stream(loadScopes)
.map(LoadScope::provideLoadScopePredicate)
.reduce(BiPredicate::or)
.orElseGet(() -> (res, loc) -> false);
return () -> predicate;
});
public static final Event<AsyncLoadScope> LOAD_SCOPE_ASYNC = EventFactory.createArrayBacked(AsyncLoadScope.class,
loadScopes -> (resourceManager, executor) -> Arrays.stream(loadScopes)
.map(it -> it.provideAsyncLoadScopePredicate(resourceManager, executor))
.reduce((cf1, cf2) -> cf1.thenCombineAsync(cf2, Predicate::or, executor))
.orElseGet(() -> CompletableFuture.completedFuture((Predicate<Identifier>) loc -> false)));
public interface LoadScope {
/**
* It must return a Predicate to check if the given resource location is Load
* Scope.<br/>
* This method is called from the rendering thread, but the Predicate test is
* called asynchronously, so be careful not to have side effects.
*
* @return A predicate to check if the location is a Load Scope.
*/
BiPredicate<ResourceManager, Identifier> provideLoadScopePredicate();
}
public interface AsyncLoadScope {
/**
* Must return a CompletableFuture that obtains a Predicate to check if the
* given resource location is Load Scope.<br/>
* his method is called from the rendering thread, but the Predicate test is
* called asynchronously, so be careful not to have side effects.
*
* @param resourceManager Resource Manager
* @param executor Executor
* @return A CompletableFuture that takes a predicate to check if the location
* is a load scope.
*/
CompletableFuture<Predicate<Identifier>> provideAsyncLoadScopePredicate(ResourceManager resourceManager,
Executor executor);
}
}