Replace creation of new Helper instances in Utils

This commit is contained in:
Brady 2018-09-24 18:50:29 -05:00
parent 2a8575caa8
commit 30b63abb73
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 9 additions and 2 deletions

View File

@ -35,6 +35,11 @@ import net.minecraft.util.text.TextFormatting;
*/
public interface Helper {
/**
* Instance of {@link Helper}. Used for static-context reference.
*/
Helper HELPER = new Helper() {};
ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format(
"%s[%sBaritone%s]%s",
TextFormatting.DARK_PURPLE,

View File

@ -27,6 +27,8 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import static baritone.utils.Helper.HELPER;
/**
* @author Brady
* @since 8/1/2018 12:56 AM
@ -115,12 +117,12 @@ public final class Utils {
}
public static double playerDistanceToCenter(BlockPos pos) {
EntityPlayerSP player = (new Helper() {}).player();
EntityPlayerSP player = HELPER.player();
return distanceToCenter(pos, player.posX, player.posY, player.posZ);
}
public static double playerFlatDistanceToCenter(BlockPos pos) {
EntityPlayerSP player = (new Helper() {}).player();
EntityPlayerSP player = HELPER.player();
return distanceToCenter(pos, player.posX, pos.getY() + 0.5, player.posZ);
}