baritone/src/main/java/baritone/utils/Helper.java

102 lines
3.3 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-08 03:16:53 +00:00
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
2018-08-08 03:16:53 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2018-08-08 03:16:53 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-08 03:16:53 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.utils;
2018-08-01 17:10:48 +00:00
2018-08-22 20:15:56 +00:00
import baritone.Baritone;
import baritone.utils.pathing.BetterBlockPos;
2018-09-03 16:15:18 +00:00
import net.minecraft.block.BlockSlab;
2018-08-01 17:10:48 +00:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
2018-08-06 04:42:17 +00:00
import net.minecraft.util.math.Vec3d;
2018-08-09 00:04:01 +00:00
import net.minecraft.util.text.ITextComponent;
2018-08-05 23:56:21 +00:00
import net.minecraft.util.text.TextComponentString;
2018-08-24 01:43:37 +00:00
import net.minecraft.util.text.TextFormatting;
2018-08-09 00:04:01 +00:00
2018-08-01 17:10:48 +00:00
/**
* @author Brady
* @since 8/1/2018 12:18 AM
*/
public interface Helper {
ITextComponent MESSAGE_PREFIX = new TextComponentString(String.format(
"%s[%sBaritone%s]%s",
TextFormatting.DARK_PURPLE,
TextFormatting.LIGHT_PURPLE,
TextFormatting.DARK_PURPLE,
TextFormatting.GRAY
));
2018-08-24 01:43:37 +00:00
2018-08-01 17:10:48 +00:00
Minecraft mc = Minecraft.getMinecraft();
2018-08-04 18:49:52 +00:00
default EntityPlayerSP player() {
return mc.player;
}
default WorldClient world() {
2018-08-04 18:49:52 +00:00
return mc.world;
}
default BetterBlockPos playerFeet() {
2018-08-13 14:05:28 +00:00
// TODO find a better way to deal with soul sand!!!!!
BetterBlockPos feet = new BetterBlockPos(player().posX, player().posY + 0.1251, player().posZ);
2018-09-03 16:15:18 +00:00
if (BlockStateInterface.get(feet).getBlock() instanceof BlockSlab) {
return feet.up();
2018-09-03 16:15:18 +00:00
}
return feet;
2018-08-02 14:01:34 +00:00
}
2018-08-09 21:35:42 +00:00
default Vec3d playerFeetAsVec() {
return new Vec3d(player().posX, player().posY, player().posZ);
}
2018-08-06 04:42:17 +00:00
default Vec3d playerHead() {
return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ);
}
default Rotation playerRotations() {
return new Rotation(player().rotationYaw, player().rotationPitch);
2018-08-06 04:42:17 +00:00
}
2018-09-11 20:45:43 +00:00
/**
* Send a message to chat only if chatDebug is on
*
2018-09-11 20:45:43 +00:00
* @param message
*/
default void logDebug(String message) {
2018-08-14 22:04:41 +00:00
if (!Baritone.settings().chatDebug.get()) {
2018-08-14 03:17:16 +00:00
System.out.println("Suppressed debug message:");
System.out.println(message);
2018-09-11 20:45:43 +00:00
return;
2018-08-14 03:17:16 +00:00
}
2018-09-11 20:45:43 +00:00
logDirect(message);
}
2018-08-09 00:04:01 +00:00
2018-09-11 20:45:43 +00:00
/**
* Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command)
*
2018-09-11 20:45:43 +00:00
* @param message
*/
default void logDirect(String message) {
2018-08-24 01:43:37 +00:00
ITextComponent component = MESSAGE_PREFIX.createCopy();
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(new TextComponentString(" " + message));
mc.ingameGUI.getChatGUI().printChatMessage(component);
2018-08-05 23:56:21 +00:00
}
2018-08-01 17:10:48 +00:00
}