it builds

This commit is contained in:
Leijurv 2018-08-01 12:48:12 -04:00
parent f83adb7d81
commit 9201b99853
No known key found for this signature in database
GPG Key ID: 0936202430AE187C
7 changed files with 90 additions and 145 deletions

View File

@ -5,7 +5,6 @@
*/
package baritone;
import baritone.movement.Combat;
import baritone.movement.MovementManager;
import baritone.pathfinding.Path;
import baritone.pathfinding.PathFinder;
@ -42,7 +41,6 @@ public class Baritone {
public static BlockPos playerFeet = null;
public static World world = null;
public static boolean allowDiagonal = true;
public static boolean farf5 = false;
public static boolean slowPath = false;
@ -151,7 +149,6 @@ public class Baritone {
hasThrowaway = ActionPlaceOrBreak.hasthrowaway();
ManagerTick.tickPath = true;
Manager.tick(LookManager.class);
BlockPos ts = whatAreYouLookingAt();
if (ts != null) {
Memory.scanBlock(ts);
@ -277,7 +274,6 @@ public class Baritone {
*/
public static void cancelPath() {
nextPath = null;
Combat.target = null;
currentBuilder = null;
clearPath();
}
@ -397,18 +393,18 @@ public class Baritone {
if (pos == null) {
return;
}
Block block = Baritone.get(pos).getBlock();
if (block.equals(Block.getBlockById(0))) {
IBlockState state = Baritone.get(pos);
if (state.getBlock().equals(Block.getBlockById(0))) {
return;
}
switchtotool(block);
switchtotool(state);
}
public static void switchtotool(Block b) {
public static void switchtotool(IBlockState b) {
Baritone.switchtotool(b, new ToolSet());
}
public static void switchtotool(Block b, ToolSet ts) {
public static void switchtotool(IBlockState b, ToolSet ts) {
Minecraft.getMinecraft().player.inventory.currentItem = ts.getBestSlot(b);
}
@ -429,7 +425,6 @@ public class Baritone {
list.add("§5[§dBaritone§5]§f");
Class<LookManager> c = LookManager.class;
list.add("§r[§" + (Manager.enabled(c) ? "a" : "c") + c.getSimpleName() + "§r]");
list.add("");
list.add("Current goal: " + goal);
list.add("");

View File

@ -130,7 +130,7 @@ public abstract class ActionPlaceOrBreak extends Action {
return false;
}*/
if (Baritone.whatAreYouLookingAt() != null) {
Baritone.switchtotool(Baritone.get(Baritone.whatAreYouLookingAt()).getBlock());
Baritone.switchtotool(Baritone.get(Baritone.whatAreYouLookingAt()));
}
MovementManager.isLeftClick = true;//hold down left click
if (canWalkThrough(positionsToBreak[i])) {

View File

@ -9,24 +9,27 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
/**
*
* @author galdara
*/
public class Schematic {
private final HashMap<BlockPos, Block> schematicBlocks;
private final int width;
private final int height;
private final int length;
public Schematic(HashMap<BlockPos, Block> blocks, int width, int height, int length) {
schematicBlocks = blocks;
this.width = width;
this.height = height;
this.length = length;
}
public Schematic(Block type, int desiredWidth) {
if (type == null) {
throw new IllegalArgumentException();
@ -41,32 +44,7 @@ public class Schematic {
schematicBlocks.put(new BlockPos(desiredWidth / 2, i, 0), type);
}
}
public Schematic(Block type, int desiredWidth, boolean rightFacing, boolean dots) {
if (type == null) {
throw new IllegalArgumentException();
}
int size = (desiredWidth - 1) / 2;
width = size * 2 + 1;
height = 1;
length = width;
schematicBlocks = new HashMap();
for (int x = 0; x < width; x++) {
schematicBlocks.put(new BlockPos(x, 0, size), type);
schematicBlocks.put(new BlockPos(size, 0, x), type);
}
for (int x = 0; x < size; x++) {
schematicBlocks.put(new BlockPos(rightFacing ? x + size + 1 : x, 0, 0), type);
schematicBlocks.put(new BlockPos(0, 0, rightFacing ? x : x + size + 1), type);
schematicBlocks.put(new BlockPos(width - 1, 0, rightFacing ? x + size + 1 : x), type);
schematicBlocks.put(new BlockPos(rightFacing ? x : x + size + 1, 0, width - 1), type);
}
if (dots) {
schematicBlocks.put(new BlockPos(size / 2, 0, size / 2), type);
schematicBlocks.put(new BlockPos(size / 2 + size + 1, 0, size / 2), type);
schematicBlocks.put(new BlockPos(size / 2 + size + 1, 0, size / 2 + size + 1), type);
schematicBlocks.put(new BlockPos(size / 2, 0, size / 2 + size + 1), type);
}
}
/**
* Tuple links the BlockPos and Block to one another.
*
@ -75,10 +53,11 @@ public class Schematic {
*/
public Tuple<BlockPos, Block> getTupleFromBlockPos(BlockPos blockPos) {
if (schematicBlocks.containsKey(blockPos)) {
return new Tuple<BlockPos, Block>(blockPos, schematicBlocks.get(blockPos));
return new Tuple<>(blockPos, schematicBlocks.get(blockPos));
}
return null;
}
/**
* Gets given block type in schematic from a BlockPos
*
@ -88,6 +67,7 @@ public class Schematic {
public Block getBlockFromBlockPos(BlockPos blockPos) {
return schematicBlocks.get(blockPos);
}
/**
* Gives the length along the X axis
*
@ -96,6 +76,7 @@ public class Schematic {
public int getWidth() {
return width;
}
/**
* Gives the height along the y axis
*
@ -104,6 +85,7 @@ public class Schematic {
public int getHeight() {
return height;
}
/**
* Gives the length along the z axis
*
@ -112,6 +94,7 @@ public class Schematic {
public int getLength() {
return length;
}
public ArrayList<Entry<BlockPos, Block>> getEntries() {
return new ArrayList(schematicBlocks.entrySet());
}

View File

@ -5,24 +5,25 @@
*/
package baritone.schematic;
import baritone.Baritone;
import baritone.pathfinding.goals.GoalComposite;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map.Entry;
import baritone.Baritone;
import baritone.pathfinding.goals.GoalComposite;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class SchematicBuilder {
ArrayList<Tuple<BlockPos, Block>> plan = new ArrayList();
BlockPos offset;
Schematic schematic;
public SchematicBuilder(Schematic schematic, BlockPos offset) {
this.schematic = schematic;
this.offset = offset;
@ -30,6 +31,7 @@ public class SchematicBuilder {
plan.add(new Tuple(offset(entry.getKey()), entry.getValue()));
}
}
public void tick() {
HashSet<BlockPos> goal = getAllBlocksToPlaceShiftedUp();
//Out.log("Ticking " + goal);
@ -42,8 +44,9 @@ public class SchematicBuilder {
//Out.gui("done building", Out.Mode.Standard);
}
}
public HashSet<BlockPos> getAllBlocksToPlaceShiftedUp() {
HashSet<BlockPos> toPlace = new HashSet<BlockPos>();
HashSet<BlockPos> toPlace = new HashSet<>();
Block air = Block.getBlockById(0);
for (int y = 0; y < schematic.getHeight(); y++) {
for (int x = 0; x < schematic.getWidth(); x++) {
@ -63,6 +66,7 @@ public class SchematicBuilder {
}
return toPlace.isEmpty() ? null : toPlace;
}
private BlockPos offset(BlockPos original) {
return new BlockPos(original.getX() + offset.getX(), original.getY() + offset.getY(), original.getZ() + offset.getZ());
}

View File

@ -5,6 +5,7 @@
*/
package baritone.schematic;
import baritone.util.Out;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
@ -13,7 +14,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import baritone.util.Out;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompressedStreamTools;
@ -25,8 +25,10 @@ import net.minecraft.util.math.BlockPos;
* @author galdara
*/
public class SchematicLoader {
public static File schematicDir;
private static final HashMap<File, Schematic> cachedSchematics = new HashMap<File, Schematic>();
private static final HashMap<File, Schematic> cachedSchematics = new HashMap<>();
private SchematicLoader() {
schematicDir = new File(Minecraft.getMinecraft().mcDataDir, "schematics");
schematicDir.mkdir();
@ -43,9 +45,11 @@ public class SchematicLoader {
}
}
}
public static SchematicLoader getLoader() {
return new SchematicLoader();
}
public final Schematic loadFromFile(File nbtFile) throws FileNotFoundException, IOException {
if (cachedSchematics.containsKey(nbtFile)) {
return cachedSchematics.get(nbtFile);
@ -59,7 +63,7 @@ public class SchematicLoader {
length = compound.getInteger("Length");
byte[][][] blocks = new byte[width][height][length], data = new byte[width][height][length];
byte[] rawBlocks = compound.getByteArray("Blocks");
HashMap<BlockPos, Block> blocksMap = new HashMap<BlockPos, Block>();
HashMap<BlockPos, Block> blocksMap = new HashMap<>();
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++) {

View File

@ -5,12 +5,16 @@
*/
package baritone.util;
import baritone.inventory.AnotherStealer;
import baritone.schematic.SchematicBuilder;
import baritone.Baritone;
import baritone.mining.MickeyMine;
import baritone.pathfinding.goals.GoalBlock;
import baritone.pathfinding.goals.GoalGetToBlock;
import baritone.pathfinding.goals.GoalXZ;
import baritone.pathfinding.goals.GoalYLevel;
import baritone.schematic.Schematic;
import baritone.schematic.SchematicBuilder;
import baritone.schematic.SchematicLoader;
import baritone.inventory.SmeltingTask;
import baritone.inventory.CraftingTask;
import baritone.ui.LookManager;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
@ -19,24 +23,10 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Random;
import baritone.movement.Combat;
import baritone.strategy.EarlyGameStrategy;
import baritone.ui.LookManager;
import baritone.Baritone;
import baritone.movement.Parkour;
import baritone.mining.MickeyMine;
import baritone.pathfinding.goals.GoalBlock;
import baritone.pathfinding.goals.GoalGetToBlock;
import baritone.pathfinding.goals.GoalXZ;
import baritone.pathfinding.goals.GoalYLevel;
import baritone.ui.AimBow;
import baritone.ui.Screenshot;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
/**
@ -44,15 +34,18 @@ import net.minecraft.util.math.BlockPos;
* @author avecowa
*/
public class ChatCommand {
private static WorldClient theWorld() {
return Minecraft.getMinecraft().world;
}
private static EntityPlayerSP thePlayer() {
return Minecraft.getMinecraft().player;
}
private static ArrayList<Field> fields;
private static ArrayList<Method> methods;
private static Method DONTYOUDARE;
static {
DONTYOUDARE = null;
// try {
@ -67,10 +60,9 @@ public class ChatCommand {
addMethods(ChatCommand.class);
addMethods(MCEdit.class);
addFields(Baritone.class);
addFields(Combat.class);
addFields(SmeltingTask.class);
addFields(LookManager.class);
}
public static void addFields(Class<?> c) {
Field[] temp = c.getFields();
for (Field f : temp) {
@ -79,6 +71,7 @@ public class ChatCommand {
}
}
}
public static void addMethods(Class<?> c) {
Method[] temp = c.getDeclaredMethods();
for (Method m : temp) {
@ -87,6 +80,7 @@ public class ChatCommand {
}
}
}
public static boolean message(String message) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Out.log("MSG: " + message);
String text = (message.charAt(0) == '/' ? message.substring(1) : message).trim();
@ -109,6 +103,7 @@ public class ChatCommand {
}
return false;
}
public static String set(String message) throws IllegalArgumentException, IllegalAccessException {
int argc = message.split(" ").length;
if (argc <= 1) {
@ -129,6 +124,7 @@ public class ChatCommand {
}
return "THATS NOT A THING";
}
public static String importfrom(String message) throws ClassNotFoundException {
String[] args = message.split(" ");
if (args.length != 3 || (!"m".equals(args[1]) && !"f".equals(args[1]))) {
@ -142,77 +138,38 @@ public class ChatCommand {
}
return "Added from " + c;
}
public static String death(String message) {
Baritone.goal = new GoalBlock(Baritone.death);
return "Set goal to " + Baritone.goal;
}
public static String craft(String message) {
String spec = message.substring(5).trim();
if (spec.length() > 0) {
String item = spec.split(" ")[0];
String amt = spec.split(" ")[1];
ItemStack stack = new ItemStack(Item.getByNameOrId(item), Integer.parseInt(amt));
Out.log(CraftingTask.findOrCreateCraftingTask(stack));
}
return "k";
}
public static String smelt(String message) {
String spec = message.substring(5).trim();
if (spec.length() > 0) {
String item = spec.split(" ")[0];
String amt = spec.split(" ")[1];
ItemStack stack = new ItemStack(Item.getByNameOrId(item), Integer.parseInt(amt));
new SmeltingTask(stack).begin();
} else {
new SmeltingTask(Minecraft.getMinecraft().player.getCurrentEquippedItem()).begin();
}
return "k";
}
public static String containeritem(String message) {
CraftingTask.getRecipeFromItem(thePlayer().getCurrentEquippedItem().getItem());
return "k";
}
public static String ore(String message) {
MickeyMine.toggleOre(message.substring(3).trim());
return "";
}
public static String parkour(String message) {
return "Parkour: " + Manager.toggle(Parkour.class);
}
public static String mine(String message) {
return "Mreow mine: " + Manager.toggle(MickeyMine.class);
}
public static String fullauto(String message) {
return "Full Auto: " + Manager.toggle(EarlyGameStrategy.class);
}
public static String record(String message) {
return "Record: " + Manager.toggle(Screenshot.class);
}
public static String wizard(String message) {
return "YOURE A LIZARD HARRY " + (Baritone.isThereAnythingInProgress ^= true);
}
public static String actuallyTalk(String message) {
Baritone.actuallyPutMessagesInChat ^= true;
return "toggled to " + Baritone.actuallyPutMessagesInChat;
}
public static String allowPlaceOrBreak(String message) {
return adventure(message);
}
public static String arrowPearl(String message) {
if (AimBow.lastBlock != null) {
Baritone.goal = new GoalXZ(AimBow.lastBlock.getX(), AimBow.lastBlock.getZ());
Baritone.findPathInNewThread(false);
return "Aiming: Pathing to X" + AimBow.lastBlock.getX() + ", Z" + AimBow.lastBlock.getZ();
} else {
return "Aiming: You need to be holding a bow!";
}
}
public static String adventure(String message) {
return "allowBreakOrPlace: " + (Baritone.allowBreakOrPlace ^= true);
}
public static String steal(String message) {
return stealer(message);
}
public static String save(String message) {
String t = message.substring(4).trim();
if (Baritone.goal == null) {
@ -224,9 +181,11 @@ public class ChatCommand {
Memory.goalMemory.put(t, ((GoalBlock) Baritone.goal).pos());
return "Saved " + Baritone.goal + " under " + t;
}
public static String load(String message) {
return "Set goal to " + (Baritone.goal = new GoalBlock(Memory.goalMemory.get(message.substring(4).trim())));
}
public static String random(String message) {
double dist = Double.parseDouble(message.substring("random direction".length()).trim());
double ang = new Random().nextDouble() * Math.PI * 2;
@ -237,30 +196,27 @@ public class ChatCommand {
Baritone.goal = new GoalXZ(x, z);
return "Set goal to " + Baritone.goal;
}
public static String findgo(String message) {
return Memory.findGoCommand(message.substring(6).trim());
}
public static String find(String message) {
return Memory.findCommand(message.substring(4).trim());
}
public static String look(String message) {
LookManager.lookAtBlock(new BlockPos(0, 0, 0), true);
return "";
}
public static String cancel(String message) {
Baritone.cancelPath();
Combat.mobHunting = false;
Combat.mobKilling = false;
Baritone.plsCancel = true;
for (Class c : Baritone.managers) {
Manager.cancel(c);
}
Manager.cancel(LookManager.class);
return Baritone.isThereAnythingInProgress ? "Cancelled it, but btw I'm pathfinding right now" : "Cancelled it";
}
public static String cancelfurnace(String message) {
SmeltingTask.clearInProgress();
return "k =)";
}
public static String st(String message) {
WorldClient theWorld = theWorld();
EntityPlayerSP thePlayer = thePlayer();
@ -270,14 +226,16 @@ public class ChatCommand {
Out.gui(Baritone.info(playerFeet.up()), Out.Mode.Minimal);
return "";
}
public static String setgoal(String message) {
return goal(message);
}
public static String goal(String message) {
Baritone.plsCancel = false;
int ind = message.indexOf(' ') + 1;
if (ind == 0) {
Baritone.goal = new GoalBlock(thePlayer().playerFeet());
Baritone.goal = new GoalBlock(Baritone.playerFeet);
return "Set goal to " + Baritone.goal;
}
String[] strs = message.substring(ind).split(" ");
@ -309,42 +267,45 @@ public class ChatCommand {
}
return "Set goal to " + Baritone.goal;
}
public static String gotoblock(String message) {
return Memory.gotoCommand(message.substring(4).trim().toLowerCase());
}
public static String kill(String message) {
return Combat.killCommand(message.substring(4).trim().toLowerCase());
}
public static String player(String message) {
return Memory.playerCommand(message.substring(6).trim());
}
public static String thisway(String message) {
return "Set goal to " + (Baritone.goal = LookManager.fromAngleAndDirection(Double.parseDouble(message.substring(7).trim())));
}
public static String path(String message) {
Baritone.plsCancel = false;
String[] split = message.split(" ");
Baritone.findPathInNewThread(thePlayer().playerFeet(), split.length > 1 ? Boolean.parseBoolean(split[1]) : true);
Baritone.findPathInNewThread(Baritone.playerFeet, split.length > 1 ? Boolean.parseBoolean(split[1]) : true);
return "";
}
public static String hardness(String message) {
BlockPos bp = Baritone.whatAreYouLookingAt();
return bp == null ? "0" : (1 / theWorld().getBlockState(bp).getBlock().getPlayerRelativeBlockHardness(thePlayer(), theWorld(), Baritone.whatAreYouLookingAt())) + "";
return bp == null ? "0" : (1 / theWorld().getBlockState(bp).getBlock().getPlayerRelativeBlockHardness(theWorld().getBlockState(bp), thePlayer(), theWorld(), Baritone.whatAreYouLookingAt())) + "";
}
public static String info(String message) {
return Baritone.info(Baritone.whatAreYouLookingAt());
}
public static String toggle(String message) throws IllegalArgumentException, IllegalAccessException {
return set(message);
}
public static String stealer(String message) {
return "stealer: " + Manager.toggle(AnotherStealer.class);
}
public static String printtag(String message) throws IOException {
Schematic sch = SchematicLoader.getLoader().loadFromFile(new File("/Users/galdara/Downloads/schematics/Bakery.schematic"));
Baritone.currentBuilder = new SchematicBuilder(sch, Baritone.playerFeet);
return "printed schematic to console.";
}
public static String samplebuild(String message) {
int size = 5;
BlockPos pl = Baritone.playerFeet;
@ -352,21 +313,12 @@ public class ChatCommand {
Baritone.currentBuilder = new SchematicBuilder(new Schematic(Block.getBlockFromName("dirt"), size), center);
return "ok";
}
public static String pinwheel(String message) {
if (true) {
return "haha. no.";
}
int size = 5;
BlockPos pl = Baritone.playerFeet;
BlockPos center = new BlockPos(pl.getX() - size, pl.getY(), pl.getZ() - size);
Baritone.currentBuilder = new SchematicBuilder(new Schematic(Block.getBlockFromName("dirt"), size * 2 + 1, false, true), center);
return "ok";
}
public static String getToGoal(String message) {
Baritone.plsCancel = false;
int ind = message.indexOf(' ') + 1;
if (ind == 0) {
Baritone.goal = new GoalGetToBlock(thePlayer().playerFeet());
Baritone.goal = new GoalGetToBlock(Baritone.playerFeet);
return "Set goal to " + Baritone.goal;
}
String[] strs = message.substring(ind).split(" ");
@ -392,10 +344,12 @@ public class ChatCommand {
}
return "Set goal to " + Baritone.goal;
}
public static String debug(String message) {
Out.mode = Out.Mode.Debug;
return "Set mode to debug";
}
public static String chatMode(String message) {
String[] args = message.split(" ");
if (args.length == 1) {

View File

@ -6,7 +6,7 @@
package baritone.util;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.text.TextComponentString;
/**
* This class serves the purpose of filtering what messages get send to the chat
@ -15,6 +15,7 @@ import net.minecraft.util.ChatComponentText;
* @author avecowa
*/
public class Out {
/**
* Out has an Mode at all times. The Mode determines behavior of of the
* filter.
@ -53,6 +54,7 @@ public class Out {
Ludicrous
}
public static Mode mode = Mode.Standard;
/**
* Logs a message to the standard system output. Before writing it runs a
* stacktrace and appends the class and line number of the calling method to
@ -69,6 +71,7 @@ public class Out {
chatRaw("§5[§dLog§5|§2" + trace + "§5]§f " + o.toString());
}
}
/**
* Prints a message to the client's chat GUI. Messages will not be displayed
* if their Mode is a lower importance than the set mode.
@ -104,9 +107,11 @@ public class Out {
chatRaw(message);
}
}
private static void chatRaw(String s) {
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(s));
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(s));
}
private static String trace() {
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
StackTraceElement trace = stack[3];