-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NetworkHandle and bumped ByteCodecs
<log>Added NetworkHandle and bumped ByteCodecs</log>
- Loading branch information
1 parent
24cbe58
commit 682e386
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...n/src/main/java/com/teamresourceful/resourcefullib/common/network/base/NetworkHandle.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,41 @@ | ||
package com.teamresourceful.resourcefullib.common.network.base; | ||
|
||
import com.teamresourceful.resourcefullib.common.exceptions.UtilityClassException; | ||
import com.teamresourceful.resourcefullib.common.network.Packet; | ||
import net.minecraft.world.entity.player.Player; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* These are helper methods to allow for the creation of handlers with more defined processes. | ||
*/ | ||
public final class NetworkHandle { | ||
|
||
private NetworkHandle() throws UtilityClassException { | ||
throw new UtilityClassException(); | ||
} | ||
|
||
public static <T extends Packet<T>> Function<T, Runnable> handle(Consumer<T> handler) { | ||
return message -> () -> handler.accept(message); | ||
} | ||
|
||
public static <T extends Packet<T>, O> Function<T, Runnable> handle(Function<T, O> processor, Consumer<O> handler) { | ||
return message -> { | ||
var processed = processor.apply(message); | ||
return () -> handler.accept(processed); | ||
}; | ||
} | ||
|
||
public static <T extends Packet<T>> Function<T, Consumer<Player>> handle(BiConsumer<T, Player> handler) { | ||
return message -> player -> handler.accept(message, player); | ||
} | ||
|
||
public static <T extends Packet<T>, O> Function<T, Consumer<Player>> handle(Function<T, O> processor, BiConsumer<O, Player> handler) { | ||
return message -> { | ||
var processed = processor.apply(message); | ||
return player -> handler.accept(processed, player); | ||
}; | ||
} | ||
} |
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