The Lucky Hat is a craftable item in the Shipwrecked DLC, exclusive to Woodlegs. It can be found in the Nautical Tab and requires 4 Bone Shards, 3 Cloth and 10 Dubloons to be crafted. While equipped, it will reveal a new X Marks the Spot treasure every 800 seconds (slightly more than 1 Day and a half).
This is based on the changes to the durability, so removing and re-equipping the hat will not reduce or increase this time. If worn by a non player character, such as a Wildbore or a Prime Ape, it only has a 66% chance to spawn a treasure. Sewing Kits repair its durability by 50%.