Skip to content

Commit

Permalink
Update KnowledgesNetworking.java
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Mar 9, 2024
1 parent ffaa00b commit d4e017e
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
package net.krlite.knowledges.networking;

import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.krlite.knowledges.KnowledgesCommon;
import net.krlite.knowledges.impl.representable.KnowledgesBlockRepresentable;
import net.krlite.knowledges.impl.representable.KnowledgesEntityRepresentable;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;

public class KnowledgesNetworking {
public static final Identifier PACKET_PEEK_BLOCK = identifier("packet_peek_block");
public static final Identifier PACKET_PEEK_ENTITY = identifier("packet_peek_entity");
public static final Identifier PACKET_RECEIVE_DATA = identifier("packet_receive_data");

public static Identifier identifier(String path) {
return new Identifier(KnowledgesCommon.ID + "_networking", path);
}

public static void register() {
ServerPlayNetworking.registerGlobalReceiver(PACKET_PEEK_BLOCK, (server, player, handler, buf, responseSender) -> {
KnowledgesBlockRepresentable.onRequest(buf, player, server::execute, compound -> {
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(compound);
responseSender.sendPacket(PACKET_RECEIVE_DATA, data);
});
});
ServerPlayNetworking.registerGlobalReceiver(PACKET_PEEK_ENTITY, (server, player, handler, buf, responseSender) -> {
KnowledgesEntityRepresentable.onRequest(buf, player, server::execute, compound -> {
PacketByteBuf data = PacketByteBufs.create();
data.writeNbt(compound);
responseSender.sendPacket(PACKET_RECEIVE_DATA, data);
});
});
}
}

0 comments on commit d4e017e

Please sign in to comment.