-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Null references had struck again! (cherry picked from commit 56a55bc)
- Loading branch information
1 parent
2ec7280
commit 7cad577
Showing
3 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...github/startsmercury/visual_snowy_leaves/impl/client/util/SequencedCompletableFuture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.startsmercury.visual_snowy_leaves.impl.client.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Consumer; | ||
import java.util.function.IntFunction; | ||
|
||
public final class SequencedCompletableFuture { | ||
public static <T> CompletableFuture<List<T>> tryFilter( | ||
final Collection<? extends CompletableFuture<? extends T>> actions, | ||
final Consumer<? super Throwable> catcher | ||
) { | ||
return tryFilter(actions, ArrayList::new, catcher); | ||
} | ||
|
||
public static <C extends Collection<T>, T> CompletableFuture<C> tryFilter( | ||
final Collection<? extends CompletableFuture<? extends T>> actions, | ||
final IntFunction<C> collectionProvider, | ||
final Consumer<? super Throwable> catcher | ||
) { | ||
final C collection; | ||
final CompletableFuture<?>[] buffer; | ||
|
||
{ | ||
final var n = actions.size(); | ||
collection = collectionProvider.apply(n); | ||
buffer = new CompletableFuture[n]; | ||
} | ||
|
||
var idx = 0; | ||
for (final var action : actions) { | ||
buffer[idx++] = action.handle((result, throwable) -> { | ||
if (throwable != null) { | ||
catcher.accept(throwable); | ||
} else { | ||
collection.add(result); | ||
} | ||
|
||
return (Void) null; | ||
}); | ||
} | ||
|
||
return CompletableFuture.allOf(buffer).thenApply(x -> collection); | ||
} | ||
|
||
private SequencedCompletableFuture() {} | ||
} |
17 changes: 17 additions & 0 deletions
17
...rtsmercury/visual_snowy_leaves/impl/client/util/UnknownBlockStateDefinitionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.startsmercury.visual_snowy_leaves.impl.client.util; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class UnknownBlockStateDefinitionException extends RuntimeException { | ||
private final ResourceLocation resourceLocation; | ||
|
||
public UnknownBlockStateDefinitionException(final ResourceLocation resourceLocation) { | ||
super(resourceLocation.toString()); | ||
|
||
this.resourceLocation = resourceLocation; | ||
} | ||
|
||
public ResourceLocation getResourceLocation() { | ||
return this.resourceLocation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters