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

83 lines
2.9 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 General Public License as published by
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-01 17:10:48 +00:00
package baritone.bot.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
2018-08-09 00:04:01 +00:00
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.gui.GuiUtilRenderComponents;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.init.Blocks;
2018-08-02 14:01:34 +00:00
import net.minecraft.util.math.BlockPos;
2018-08-09 00:04:01 +00:00
import net.minecraft.util.math.MathHelper;
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-01 17:10:48 +00:00
2018-08-09 00:04:01 +00:00
import java.util.List;
2018-08-01 17:10:48 +00:00
/**
* @author Brady
* @since 8/1/2018 12:18 AM
*/
public interface Helper {
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;
}
2018-08-02 14:01:34 +00:00
default BlockPos playerFeet() {
2018-08-13 14:05:28 +00:00
// TODO find a better way to deal with soul sand!!!!!
BlockPos feet = new BlockPos(player().posX, player().posY + 0.1251, player().posZ);
/*if (BlockStateInterface.get(feet).getBlock().equals(Blocks.SOUL_SAND) && player().posY > feet.getY() + 0.874999) {
return feet.up();
2018-08-13 14:05:28 +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-08-05 23:56:21 +00:00
default void displayChatMessageRaw(String message) {
2018-08-09 00:04:01 +00:00
GuiNewChat gui = mc.ingameGUI.getChatGUI();
int normalMaxWidth = MathHelper.floor((float) gui.getChatWidth() / gui.getChatScale());
int widthWithStyleFormat = normalMaxWidth - 2;
List<ITextComponent> list = GuiUtilRenderComponents.splitText(new TextComponentString("§5[§dBaritone§5]§7 " + message), widthWithStyleFormat,
this.mc.fontRenderer, false, true);
for (ITextComponent component : list) {
gui.printChatMessage(new TextComponentString("§7" + component.getUnformattedText()));
}
2018-08-05 23:56:21 +00:00
}
2018-08-01 17:10:48 +00:00
}