inside a packet there is information about the sender's public IP and MAC and the receiver's public IP and MAC
An (IP) packet header stores the sender's IP address (public or private, possibly translated) and the destination's IP address (public or private, possibly translated). It does not hold any MAC addresses.
MAC addresses are part of the frame header used on MAC-based networks on the data link layer (L2) for delivery inside that network.
at each hop, the sender's and receiver's MAC are changed along the way.
It may appear like that but it isn't really. As per above, a MAC frame is used in some networks for local delivery, but not in all networks. Regardless of its form, an IP packet is always encapsulated by some kind of data link layer frame as its payload.
Each hop that receives a packet discards the encapsulating frame, routes the packet and re-encapsulates it as required for the egress network. Ingress and egress frames may look very similar to each other (apart from source & destination L2 addresses), but they may also be vastly different since IP may be transported by a wide variety of L2 networks.
how will it know which device to deliver the packet to?
The last hop delivers the packet by IP address. If a MAC address is required it's looked up using ARP (IPv4) or NDP (IPv6).