diff --git a/common/src/main/java/com/teamresourceful/resourcefullib/common/network/base/NetworkHandle.java b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/base/NetworkHandle.java new file mode 100644 index 0000000..f57abdc --- /dev/null +++ b/common/src/main/java/com/teamresourceful/resourcefullib/common/network/base/NetworkHandle.java @@ -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 > Function handle(Consumer handler) { + return message -> () -> handler.accept(message); + } + + public static , O> Function handle(Function processor, Consumer handler) { + return message -> { + var processed = processor.apply(message); + return () -> handler.accept(processed); + }; + } + + public static > Function> handle(BiConsumer handler) { + return message -> player -> handler.accept(message, player); + } + + public static , O> Function> handle(Function processor, BiConsumer handler) { + return message -> { + var processed = processor.apply(message); + return player -> handler.accept(processed, player); + }; + } +} diff --git a/gradle.properties b/gradle.properties index 5e38558..91ccd90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_api_version=0.100.1+1.21 neoforge_version=21.0.0-beta yabn_version=1.0.3 -bytecodecs_version=1.1.1 +bytecodecs_version=1.1.2 ## Mod Version nightly=false