implements https://github.com/CanaryModTeam/CanaryLib/commit/817c1f69c879759fe2625cb656b1a7c43d0d7d73