use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class LoginWrapper method wrapperReceived.
private <T extends NetworkEvent> void wrapperReceived(final T packet) {
// we don't care about channel registration change events on this channel
if (packet instanceof NetworkEvent.ChannelRegistrationChangeEvent)
return;
final NetworkEvent.Context wrappedContext = packet.getSource().get();
final FriendlyByteBuf payload = packet.getPayload();
ResourceLocation targetNetworkReceiver = NetworkConstants.FML_HANDSHAKE_RESOURCE;
FriendlyByteBuf data = null;
if (payload != null) {
targetNetworkReceiver = payload.readResourceLocation();
final int payloadLength = payload.readVarInt();
data = new FriendlyByteBuf(payload.readBytes(payloadLength));
}
final int loginSequence = packet.getLoginIndex();
LOGGER.debug(HandshakeHandler.FMLHSMARKER, "Recieved login wrapper packet event for channel {} with index {}", targetNetworkReceiver, loginSequence);
final NetworkEvent.Context context = new NetworkEvent.Context(wrappedContext.getNetworkManager(), wrappedContext.getDirection(), (rl, buf) -> {
LOGGER.debug(HandshakeHandler.FMLHSMARKER, "Dispatching wrapped packet reply for channel {} with index {}", rl, loginSequence);
wrappedContext.getPacketDispatcher().sendPacket(WRAPPER, this.wrapPacket(rl, buf));
});
final NetworkEvent.LoginPayloadEvent loginPayloadEvent = new NetworkEvent.LoginPayloadEvent(data, () -> context, loginSequence);
NetworkRegistry.findTarget(targetNetworkReceiver).ifPresent(ni -> {
ni.dispatchLoginPacket(loginPayloadEvent);
wrappedContext.setPacketHandled(context.getPacketHandled());
});
}
use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class LoginWrapper method wrapPacket.
private FriendlyByteBuf wrapPacket(final ResourceLocation rl, final FriendlyByteBuf buf) {
FriendlyByteBuf pb = new FriendlyByteBuf(Unpooled.buffer(buf.capacity()));
pb.writeResourceLocation(rl);
pb.writeVarInt(buf.readableBytes());
pb.writeBytes(buf);
return pb;
}
use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class LoginWrapper method sendServerToClientLoginPacket.
void sendServerToClientLoginPacket(final ResourceLocation resourceLocation, final FriendlyByteBuf buffer, final int index, final Connection manager) {
FriendlyByteBuf pb = wrapPacket(resourceLocation, buffer);
manager.send(NetworkDirection.LOGIN_TO_CLIENT.buildPacket(Pair.of(pb, index), WRAPPER).getThis());
}
use of net.minecraft.network.FriendlyByteBuf in project MinecraftForge by MinecraftForge.
the class SimpleChannel method networkLoginGather.
private void networkLoginGather(final NetworkEvent.GatherLoginPayloadsEvent gatherEvent) {
loginPackets.forEach(packetGenerator -> {
packetGenerator.apply(gatherEvent.isLocal()).forEach(p -> {
FriendlyByteBuf pb = new FriendlyByteBuf(Unpooled.buffer());
this.indexedCodec.build(p.getRight(), pb);
gatherEvent.add(pb, this.instance.getChannelName(), p.getLeft());
});
});
}
use of net.minecraft.network.FriendlyByteBuf in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method copyPacket.
public static FriendlyByteBuf copyPacket(Packet<?> original) {
try {
FriendlyByteBuf copier = new FriendlyByteBuf(Unpooled.buffer());
original.write(copier);
return copier;
} catch (Throwable ex) {
com.denizenscript.denizen.utilities.debugging.Debug.echoError(ex);
return null;
}
}
Aggregations