implements https://github.com/CanaryModTeam/CanaryLib/commit/a99b05c68460460d8feb650b9ba1dafe1bfc5d0c