Skip to content

Commit

Permalink
Add NetworkHandle and bumped ByteCodecs
Browse files Browse the repository at this point in the history
<log>Added NetworkHandle and bumped ByteCodecs</log>
  • Loading branch information
ThatGravyBoat committed Jun 26, 2024
1 parent 24cbe58 commit 682e386
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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);
};
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 682e386

Please sign in to comment.