Search in sources :

Example 1 with FriendlyByteBuf

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());
    });
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 2 with FriendlyByteBuf

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;
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf)

Example 3 with FriendlyByteBuf

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());
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf)

Example 4 with FriendlyByteBuf

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());
        });
    });
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf)

Example 5 with FriendlyByteBuf

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;
    }
}
Also used : FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf)

Aggregations

FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)22 ResourceLocation (net.minecraft.resources.ResourceLocation)8 LocationTag (com.denizenscript.denizen.objects.LocationTag)2 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)2 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.core.BlockPos)2 AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 BitSet (java.util.BitSet)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 Packet (net.minecraft.network.protocol.Packet)1 ClientboundCustomPayloadPacket (net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket)1 ClientboundLevelChunkPacket (net.minecraft.network.protocol.game.ClientboundLevelChunkPacket)1 ClientboundLevelChunkPacketData (net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData)1 ClientboundLevelChunkWithLightPacket (net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket)1 ServerboundCustomPayloadPacket (net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket)1 ClientboundCustomQueryPacket (net.minecraft.network.protocol.login.ClientboundCustomQueryPacket)1 ServerboundCustomQueryPacket (net.minecraft.network.protocol.login.ServerboundCustomQueryPacket)1