Search in sources :

Example 56 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class SyncMultiModelPacket method createS2CPacket.

public static PacketByteBuf createS2CPacket(Entity entity, IHasMultiModel hasMultiModel) {
    PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
    passedData.writeInt(entity.getEntityId());
    passedData.writeString(hasMultiModel.getTextureHolder(Layer.SKIN, Part.HEAD).getTextureName());
    for (Part part : Part.values()) {
        passedData.writeString(hasMultiModel.getTextureHolder(Layer.INNER, part).getTextureName());
    }
    passedData.writeEnumConstant(hasMultiModel.getColor());
    passedData.writeBoolean(hasMultiModel.isContract());
    return passedData;
}
Also used : Part(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel.Part) PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 57 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class SyncMultiModelPacket method createC2SPacket.

public static PacketByteBuf createC2SPacket(Entity entity, IHasMultiModel hasMultiModel) {
    PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
    passedData.writeInt(entity.getEntityId());
    passedData.writeString(hasMultiModel.getTextureHolder(Layer.SKIN, Part.HEAD).getTextureName());
    for (Part part : Part.values()) {
        passedData.writeString(hasMultiModel.getTextureHolder(Layer.INNER, part).getTextureName());
    }
    passedData.writeEnumConstant(hasMultiModel.getColor());
    passedData.writeBoolean(hasMultiModel.isContract());
    return passedData;
}
Also used : Part(net.sistr.littlemaidmodelloader.entity.compound.IHasMultiModel.Part) PacketByteBuf(net.minecraft.network.PacketByteBuf)

Example 58 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project LittleMaidModelLoader-Fabric by SistrScarlet.

the class CustomMobSpawnPacket method receiveS2CPacket.

@Environment(EnvType.CLIENT)
public static void receiveS2CPacket(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) {
    int id = buf.readVarInt();
    UUID uuid = buf.readUuid();
    int entityTypeId = buf.readVarInt();
    double x = buf.readDouble();
    double y = buf.readDouble();
    double z = buf.readDouble();
    float yaw = (buf.readByte() * 360F) / 256F;
    float pitch = (buf.readByte() * 360F) / 256F;
    float headYaw = (buf.readByte() * 360F) / 256F;
    float velocityX = buf.readShort() / 8000F;
    float velocityY = buf.readShort() / 8000F;
    float velocityZ = buf.readShort() / 8000F;
    // そのまんまbuf渡すと、spawnが実行されるまでの間に読み込めなくなるため、コピーする
    PacketByteBuf additional = new PacketByteBuf(buf.copy());
    client.execute(() -> spawn(id, uuid, entityTypeId, x, y, z, yaw, pitch, headYaw, velocityX, velocityY, velocityZ, additional));
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) UUID(java.util.UUID) Environment(net.fabricmc.api.Environment)

Example 59 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project Carrier by GabrielOlvH.

the class MixinClientPlayerEntity method carrier_sendPacket.

@Inject(method = "tick", at = @At("RETURN"))
private void carrier_sendPacket(CallbackInfo ci) {
    if (lastPressed != pressed) {
        lastPressed = pressed;
        PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
        buf.writeBoolean(pressed);
        ClientSidePacketRegistry.INSTANCE.sendToServer(Carrier.SET_CAN_CARRY_PACKET, buf);
    }
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 60 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project quilt-standard-libraries by QuiltMC.

the class NetworkingImpl method init.

public static void init(ModContainer mod) {
    // Login setup
    ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
        // Send early registration packet
        PacketByteBuf buf = PacketByteBufs.create();
        Collection<Identifier> channelsNames = ServerPlayNetworking.getGlobalReceivers();
        buf.writeVarInt(channelsNames.size());
        for (Identifier id : channelsNames) {
            buf.writeIdentifier(id);
        }
        sender.sendPacket(EARLY_REGISTRATION_CHANNEL, buf);
        sender.sendPacket(EARLY_REGISTRATION_CHANNEL_FABRIC, buf);
        NetworkingImpl.LOGGER.debug("Sent accepted channels to the client for \"{}\"", handler.getConnectionInfo());
    });
    ServerLoginNetworking.registerGlobalReceiver(EARLY_REGISTRATION_CHANNEL, NetworkingImpl::receiveEarlyRegistration);
    ServerLoginNetworking.registerGlobalReceiver(EARLY_REGISTRATION_CHANNEL_FABRIC, NetworkingImpl::receiveEarlyRegistration);
}
Also used : Identifier(net.minecraft.util.Identifier) PacketByteBuf(net.minecraft.network.PacketByteBuf)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)117 PlayerEntity (net.minecraft.entity.player.PlayerEntity)21 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)14 Identifier (net.minecraft.util.Identifier)8 NbtCompound (net.minecraft.nbt.NbtCompound)7 Environment (net.fabricmc.api.Environment)5 CustomPayloadC2SPacket (net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)5 CustomPayloadS2CPacket (net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket)4 Nullable (org.jetbrains.annotations.Nullable)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 JSONSource (de.modprog.blockmeter.util.JSONSource)2 Map (java.util.Map)2 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)2 LivingEntity (net.minecraft.entity.LivingEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ParticleType (net.minecraft.particle.ParticleType)2 LiteralText (net.minecraft.text.LiteralText)2