Galacticraft icon indicating copy to clipboard operation
Galacticraft copied to clipboard

refactor: make use of Mth methods

Open Roelymole opened this issue 9 months ago • 0 comments

This is an attempt to make the math faster and more readable by utilizing some of the methods offered by the net.minecraft.util.Mth class as well as other math related optimizations.

Notable changes:

  • Use Mth.clamp(x, L, U) rather than Math.min(Math.max(x, L), U) or Math.max(Math.min(x, U), L) for example.
  • Use existing Mth.DEG_TO_RAD or Mth.RAD_TO_DEG rather than defining Constant.RADIANS_TO_DEGREES ourselves.
  • Use Mth.PI rather than (float) Math.PI as well as other constants such as Mth.HALF_PI and Mth.TWO_PI.
  • Prefer Mth.sin and Mth.cos over Math.sin and Math.cos, which should be faster as these methods use cached values.
  • Make use of trigonometric identities to simplify calculations.
  • Change some doubles to floats where it seems like they should have been floats in the first place.

Roelymole avatar Mar 23 '25 11:03 Roelymole