use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.
the class ClientLoginNetworkAddon method handlePacket.
private boolean handlePacket(int queryId, Identifier channelName, PacketByteBuf originalBuf) {
this.logger.debug("Handling inbound login response with id {} and channel with name {}", queryId, channelName);
if (this.firstResponse) {
// Register global handlers
for (Map.Entry<Identifier, ClientLoginNetworking.QueryRequestReceiver> entry : ClientNetworkingImpl.LOGIN.getReceivers().entrySet()) {
ClientLoginNetworking.registerReceiver(entry.getKey(), entry.getValue());
}
ClientLoginConnectionEvents.QUERY_START.invoker().onLoginQueryStart(this.handler, this.client);
this.firstResponse = false;
}
@Nullable ClientLoginNetworking.QueryRequestReceiver handler = this.getHandler(channelName);
if (handler == null) {
return false;
}
PacketByteBuf buf = PacketByteBufs.slice(originalBuf);
var futureListeners = new ArrayList<GenericFutureListener<? extends Future<? super Void>>>();
try {
CompletableFuture<@Nullable PacketByteBuf> future = handler.receive(this.client, this.handler, buf, futureListeners::add);
future.thenAccept(result -> {
var packet = new LoginQueryResponseC2SPacket(queryId, result);
GenericFutureListener<? extends Future<? super Void>> listener = null;
for (GenericFutureListener<? extends Future<? super Void>> each : futureListeners) {
listener = FutureListeners.union(listener, each);
}
this.handler.getConnection().send(packet, listener);
});
} catch (Throwable ex) {
this.logger.error("Encountered exception while handling in channel with name \"{}\"", channelName, ex);
throw ex;
}
return true;
}
use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.
the class AbstractChanneledNetworkAddon method handle.
// always supposed to handle async!
protected boolean handle(Identifier channelName, PacketByteBuf originalBuf) {
this.logger.debug("Handling inbound packet from channel with name \"{}\"", channelName);
// Handle reserved packets
if (NetworkingImpl.REGISTER_CHANNEL.equals(channelName)) {
this.receiveRegistration(true, PacketByteBufs.slice(originalBuf));
return true;
}
if (NetworkingImpl.UNREGISTER_CHANNEL.equals(channelName)) {
this.receiveRegistration(false, PacketByteBufs.slice(originalBuf));
return true;
}
@Nullable H handler = this.getHandler(channelName);
if (handler == null) {
return false;
}
PacketByteBuf buf = PacketByteBufs.slice(originalBuf);
try {
this.receive(handler, buf);
} catch (Throwable ex) {
this.logger.error("Encountered exception while handling in channel with name \"{}\"", channelName, ex);
throw ex;
}
return true;
}
use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.
the class NetworkingPlayPacketTest method sendToTestChannel.
public static void sendToTestChannel(ServerPlayerEntity player, String stuff) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeText(new LiteralText(stuff));
ServerPlayNetworking.send(player, TEST_CHANNEL, buf);
NetworkingTestMods.LOGGER.info("Sent custom payload packet in {}", TEST_CHANNEL);
}
use of net.minecraft.network.PacketByteBuf in project Hypnotic-Client by Hypnotic-Development.
the class Criticals method getEntity.
public static Entity getEntity(PlayerInteractEntityC2SPacket packet) {
PacketByteBuf packetBuf = new PacketByteBuf(Unpooled.buffer());
packet.write(packetBuf);
return mc.world.getEntityById(packetBuf.readVarInt());
}
use of net.minecraft.network.PacketByteBuf in project Paradise-Lost by devs-immortal.
the class AetherNonLivingEntity method createSpawnPacket.
@Override
public final Packet<?> createSpawnPacket() {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
Identifier id = this.createSpawnPacket(buf);
for (ServerPlayerEntity playerEntity : ((ServerWorld) this.world).getPlayers()) {
ServerSidePacketRegistry.INSTANCE.sendToPlayer(playerEntity, id, buf);
}
return new EntitySpawnS2CPacket(this);
}
Aggregations