This commit is contained in:
Logan Darklock
2019-09-06 03:59:10 -07:00
parent 69e3481a32
commit 8a001a2438
100 changed files with 2065 additions and 1341 deletions

View File

@@ -113,9 +113,6 @@ public class Baritone implements IBaritone {
memoryBehavior = new MemoryBehavior(this);
inventoryBehavior = new InventoryBehavior(this);
inputOverrideHandler = new InputOverrideHandler(this);
DefaultCommands.commands.forEach(CommandManager.REGISTRY::register);
new BaritoneChatControl(this);
}
this.pathingControlManager = new PathingControlManager(this);
@@ -138,6 +135,9 @@ public class Baritone implements IBaritone {
}
this.initialized = true;
DefaultCommands.COMMANDS.forEach(CommandManager.REGISTRY::register);
new BaritoneChatControl(this);
}
@Override

View File

@@ -133,7 +133,7 @@ public final class InventoryBehavior extends Behavior {
}
public boolean selectThrowawayForLocation(boolean select, int x, int y, int z) {
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z, ctx.world().getBlockState(new BlockPos(x, y, z)));
IBlockState maybe = baritone.getBuilderProcess().placeAt(x, y, z, baritone.bsi.get0(x, y, z));
if (maybe != null && throwaway(select, stack -> stack.getItem() instanceof ItemBlock && maybe.equals(((ItemBlock) stack.getItem()).getBlock().getStateForPlacement(ctx.world(), ctx.playerFeet(), EnumFacing.UP, (float) ctx.player().posX, (float) ctx.player().posY, (float) ctx.player().posZ, stack.getItem().getMetadata(stack.getMetadata()), ctx.player())))) {
return true; // gotem
}

View File

@@ -291,11 +291,6 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
return hasPath() && !pausedThisTick;
}
@Override
public boolean hasPath() {
return current != null;
}
@Override
public PathExecutor getCurrent() {
return current;

View File

@@ -17,7 +17,9 @@
package baritone.cache;
import baritone.api.cache.ICachedWorld;
import baritone.api.cache.IWorldScanner;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.IPlayerContext;
import baritone.utils.accessor.IBlockStateContainer;
@@ -26,6 +28,7 @@ import net.minecraft.client.multiplayer.ChunkProviderClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import java.util.ArrayList;
@@ -35,6 +38,8 @@ import java.util.Comparator;
import java.util.List;
import java.util.stream.IntStream;
import static java.util.Objects.nonNull;
public enum WorldScanner implements IWorldScanner {
INSTANCE;
@@ -44,6 +49,11 @@ public enum WorldScanner implements IWorldScanner {
@Override
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, BlockOptionalMetaLookup filter, int max, int yLevelThreshold, int maxSearchRadius) {
ArrayList<BlockPos> res = new ArrayList<>();
if (filter.blocks().isEmpty()) {
return res;
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
int maxSearchRadiusSq = maxSearchRadius * maxSearchRadius;
@@ -79,8 +89,8 @@ public enum WorldScanner implements IWorldScanner {
}
}
if ((allUnloaded && foundChunks)
|| (res.size() >= max
&& (searchRadiusSq > maxSearchRadiusSq || (searchRadiusSq > 1 && foundWithinY)))
|| (res.size() >= max
&& (searchRadiusSq > maxSearchRadiusSq || (searchRadiusSq > 1 && foundWithinY)))
) {
return res;
}
@@ -90,6 +100,10 @@ public enum WorldScanner implements IWorldScanner {
@Override
public List<BlockPos> scanChunk(IPlayerContext ctx, BlockOptionalMetaLookup filter, ChunkPos pos, int max, int yLevelThreshold) {
if (filter.blocks().isEmpty()) {
return Collections.emptyList();
}
ChunkProviderClient chunkProvider = (ChunkProviderClient) ctx.world().getChunkProvider();
Chunk chunk = chunkProvider.getLoadedChunk(pos.x, pos.z);
int playerY = ctx.playerFeet().getY();
@@ -121,7 +135,7 @@ public enum WorldScanner implements IWorldScanner {
for (int i = 0; i < imax; i++) {
IBlockState state = bsc.getAtPalette(storage[i]);
if (filter.has(state)) {
int y = yReal | (i >> 8 & 15);
int y = yReal | ((i >> 8) & 15);
if (result.size() >= max) {
if (Math.abs(y - playerY) < yLevelThreshold) {
foundWithinY = true;
@@ -133,10 +147,32 @@ public enum WorldScanner implements IWorldScanner {
}
}
}
result.add(new BlockPos(chunkX | (i & 15), y, chunkZ | (i >> 4 & 15)));
result.add(new BlockPos(chunkX | (i & 15), y, chunkZ | ((i >> 4) & 15)));
}
}
}
return foundWithinY;
}
public int repack(IPlayerContext ctx) {
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int queued = 0;
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
Chunk chunk = chunkProvider.getLoadedChunk(x, z);
if (nonNull(chunk) && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
return queued;
}
}

View File

@@ -177,7 +177,7 @@ public interface MovementHelper extends ActionCosts, Helper {
return block.isPassable(null, null);
}
static boolean isReplacable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
static boolean isReplaceable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
// for MovementTraverse and MovementAscend
// block double plant defaults to true when the block doesn't match, so don't need to check that case
// all other overrides just return true or false
@@ -207,6 +207,11 @@ public interface MovementHelper extends ActionCosts, Helper {
return state.getMaterial().isReplaceable();
}
@Deprecated
static boolean isReplacable(int x, int y, int z, IBlockState state, BlockStateInterface bsi) {
return isReplaceable(x, y, z, state, bsi);
}
static boolean isDoorPassable(IPlayerContext ctx, BlockPos doorPos, BlockPos playerPos) {
if (playerPos.equals(doorPos)) {
return false;

View File

@@ -73,7 +73,7 @@ public class MovementAscend extends Movement {
if (additionalPlacementCost >= COST_INF) {
return COST_INF;
}
if (!MovementHelper.isReplacable(destX, y, destZ, toPlace, context.bsi)) {
if (!MovementHelper.isReplaceable(destX, y, destZ, toPlace, context.bsi)) {
return COST_INF;
}
boolean foundPlaceOption = false;

View File

@@ -152,7 +152,7 @@ public class MovementParkour extends Movement {
return;
}
IBlockState toReplace = context.get(destX, y - 1, destZ);
if (!MovementHelper.isReplacable(destX, y - 1, destZ, toReplace, context.bsi)) {
if (!MovementHelper.isReplaceable(destX, y - 1, destZ, toReplace, context.bsi)) {
return;
}
if (!checkOvershootSafety(context.bsi, destX + xDiff, y, destZ + zDiff)) {

View File

@@ -111,7 +111,7 @@ public class MovementTraverse extends Movement {
if (srcDown == Blocks.LADDER || srcDown == Blocks.VINE) {
return COST_INF;
}
if (MovementHelper.isReplacable(destX, y - 1, destZ, destOn, context.bsi)) {
if (MovementHelper.isReplaceable(destX, y - 1, destZ, destOn, context.bsi)) {
boolean throughWater = MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock());
if (MovementHelper.isWater(destOn.getBlock()) && throughWater) {
// this happens when assume walk on water is true and this is a traverse in water, which isn't allowed

View File

@@ -79,6 +79,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private int ticks;
private boolean paused;
private int layer;
private List<IBlockState> approxPlaceable;
public BuilderProcess(Baritone baritone) {
super(baritone);
@@ -147,6 +148,11 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
build("clear area", new FillSchematic(widthX, heightY, lengthZ, Blocks.AIR.getDefaultState()), origin);
}
@Override
public List<IBlockState> getApproxPlaceable() {
return new ArrayList<>(approxPlaceable);
}
private static ISchematic parse(NBTTagCompound schematic) {
return Baritone.settings().mapArtMode.value ? new MapArtSchematic(schematic) : new Schematic(schematic);
}
@@ -163,7 +169,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
if (!schematic.inSchematic(x - origin.getX(), y - origin.getY(), z - origin.getZ(), current)) {
return null;
}
IBlockState state = schematic.desiredState(x - origin.getX(), y - origin.getY(), z - origin.getZ(), current);
IBlockState state = schematic.desiredState(x - origin.getX(), y - origin.getY(), z - origin.getZ(), current, this.approxPlaceable);
if (state.getBlock() == Blocks.AIR) {
return null;
}
@@ -214,7 +220,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
}
private Optional<Placement> searchForPlacables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
private Optional<Placement> searchForPlaceables(BuilderCalculationContext bcc, List<IBlockState> desirableOnHotbar) {
BetterBlockPos center = ctx.playerFeet();
for (int dx = -5; dx <= 5; dx++) {
for (int dy = -5; dy <= 1; dy++) {
@@ -227,7 +233,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
continue; // irrelevant
}
IBlockState curr = bcc.bsi.get0(x, y, z);
if (MovementHelper.isReplacable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) {
if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) {
if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() == Blocks.AIR) {
continue;
}
@@ -247,7 +253,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
for (EnumFacing against : EnumFacing.values()) {
BetterBlockPos placeAgainstPos = new BetterBlockPos(x, y, z).offset(against);
IBlockState placeAgainstState = bsi.get0(placeAgainstPos);
if (MovementHelper.isReplacable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
if (MovementHelper.isReplaceable(placeAgainstPos.x, placeAgainstPos.y, placeAgainstPos.z, placeAgainstState, bsi)) {
continue;
}
if (!ctx.world().mayPlace(toPlace.getBlock(), new BetterBlockPos(x, y, z), false, against, null)) {
@@ -304,16 +310,16 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private static Vec3d[] aabbSideMultipliers(EnumFacing side) {
switch (side) {
case UP:
return new Vec3d[] {new Vec3d(0.5, 1, 0.5), new Vec3d(0.1, 1, 0.5), new Vec3d(0.9, 1, 0.5), new Vec3d(0.5, 1, 0.1), new Vec3d(0.5, 1, 0.9)};
return new Vec3d[]{new Vec3d(0.5, 1, 0.5), new Vec3d(0.1, 1, 0.5), new Vec3d(0.9, 1, 0.5), new Vec3d(0.5, 1, 0.1), new Vec3d(0.5, 1, 0.9)};
case DOWN:
return new Vec3d[] {new Vec3d(0.5, 0, 0.5), new Vec3d(0.1, 0, 0.5), new Vec3d(0.9, 0, 0.5), new Vec3d(0.5, 0, 0.1), new Vec3d(0.5, 0, 0.9)};
return new Vec3d[]{new Vec3d(0.5, 0, 0.5), new Vec3d(0.1, 0, 0.5), new Vec3d(0.9, 0, 0.5), new Vec3d(0.5, 0, 0.1), new Vec3d(0.5, 0, 0.9)};
case NORTH:
case SOUTH:
case EAST:
case WEST:
double x = side.getXOffset() == 0 ? 0.5 : (1 + side.getXOffset()) / 2D;
double z = side.getZOffset() == 0 ? 0.5 : (1 + side.getZOffset()) / 2D;
return new Vec3d[] {new Vec3d(x, 0.25, z), new Vec3d(x, 0.75, z)};
return new Vec3d[]{new Vec3d(x, 0.25, z), new Vec3d(x, 0.75, z)};
default: // null
throw new IllegalStateException();
}
@@ -321,6 +327,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
approxPlaceable = approxPlaceable(36);
if (baritone.getInputOverrideHandler().isInputForcedDown(Input.CLICK_LEFT)) {
ticks = 5;
} else {
@@ -348,8 +355,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
schematic = new ISchematic() {
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current) {
return realSchematic.desiredState(x, y, z, current);
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
return realSchematic.desiredState(x, y, z, current, BuilderProcess.this.approxPlaceable);
}
@Override
@@ -416,7 +423,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<IBlockState> desirableOnHotbar = new ArrayList<>();
Optional<Placement> toPlace = searchForPlacables(bcc, desirableOnHotbar);
Optional<Placement> toPlace = searchForPlaceables(bcc, desirableOnHotbar);
if (toPlace.isPresent() && isSafeToCancel && ctx.player().onGround && ticks <= 0) {
Rotation rot = toPlace.get().rot;
baritone.getLookBehavior().updateTarget(rot, true);
@@ -428,14 +435,13 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<IBlockState> approxPlacable = placable(36);
if (Baritone.settings().allowInventory.value) {
ArrayList<Integer> usefulSlots = new ArrayList<>();
List<IBlockState> noValidHotbarOption = new ArrayList<>();
outer:
for (IBlockState desired : desirableOnHotbar) {
for (int i = 0; i < 9; i++) {
if (valid(approxPlacable.get(i), desired)) {
if (valid(approxPlaceable.get(i), desired)) {
usefulSlots.add(i);
continue outer;
}
@@ -446,7 +452,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
outer:
for (int i = 9; i < 36; i++) {
for (IBlockState desired : noValidHotbarOption) {
if (valid(approxPlacable.get(i), desired)) {
if (valid(approxPlaceable.get(i), desired)) {
baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
break outer;
}
@@ -454,9 +460,9 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
}
Goal goal = assemble(bcc, approxPlacable.subList(0, 9));
Goal goal = assemble(bcc, approxPlaceable.subList(0, 9));
if (goal == null) {
goal = assemble(bcc, approxPlacable); // we're far away, so assume that we have our whole inventory to recalculate placable properly
goal = assemble(bcc, approxPlaceable); // we're far away, so assume that we have our whole inventory to recalculate placeable properly
if (goal == null) {
logDirect("Unable to do it. Pausing. resume to resume, cancel to cancel");
paused = true;
@@ -528,7 +534,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) { // check if its in render distance, not if its in cache
// we can directly observe this block, it is in render distance
if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current))) {
if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable))) {
observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ));
} else {
incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ));
@@ -553,14 +559,14 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
}
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlacable) {
private Goal assemble(BuilderCalculationContext bcc, List<IBlockState> approxPlaceable) {
List<BetterBlockPos> placeable = new ArrayList<>();
List<BetterBlockPos> breakable = new ArrayList<>();
List<BetterBlockPos> sourceLiquids = new ArrayList<>();
incorrectPositions.forEach(pos -> {
IBlockState state = bcc.bsi.get0(pos);
if (state.getBlock() instanceof BlockAir) {
if (approxPlacable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
if (approxPlaceable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
placeable.add(pos);
}
} else {
@@ -642,8 +648,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
if (ctx.world().getBlockState(pos).getBlock() != Blocks.AIR) { // TODO can this even happen?
return new GoalPlace(pos);
}
IBlockState current = ctx.world().getBlockState(pos.up());
boolean allowSameLevel = current.getBlock() != Blocks.AIR;
boolean allowSameLevel = ctx.world().getBlockState(pos.up()).getBlock() != Blocks.AIR;
IBlockState current = ctx.world().getBlockState(pos);
for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP) {
//noinspection ConstantConditions
if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && ctx.world().mayPlace(bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ(), current).getBlock(), pos, false, facing, null)) {
@@ -727,7 +733,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
return paused ? "Builder Paused" : "Building " + name;
}
private List<IBlockState> placable(int size) {
private List<IBlockState> approxPlaceable(int size) {
List<IBlockState> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
ItemStack stack = ctx.player().inventory.mainInventory.get(i);
@@ -751,7 +757,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
}
public class BuilderCalculationContext extends CalculationContext {
private final List<IBlockState> placable;
private final List<IBlockState> placeable;
private final ISchematic schematic;
private final int originX;
private final int originY;
@@ -759,7 +765,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
public BuilderCalculationContext() {
super(BuilderProcess.this.baritone, true); // wew lad
this.placable = placable(9);
this.placeable = approxPlaceable(9);
this.schematic = BuilderProcess.this.schematic;
this.originX = origin.getX();
this.originY = origin.getY();
@@ -771,7 +777,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private IBlockState getSchematic(int x, int y, int z, IBlockState current) {
if (schematic.inSchematic(x - originX, y - originY, z - originZ, current)) {
return schematic.desiredState(x - originX, y - originY, z - originZ, current);
return schematic.desiredState(x - originX, y - originY, z - originZ, current, BuilderProcess.this.approxPlaceable);
} else {
return null;
}
@@ -790,7 +796,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
// this won't be a schematic block, this will be a throwaway
return placeBlockCost * 2; // we're going to have to break it eventually
}
if (placable.contains(sch)) {
if (placeable.contains(sch)) {
return 0; // thats right we gonna make it FREE to place a block where it should go in a structure
// no place block penalty at all 😎
// i'm such an idiot that i just tried to copy and paste the epic gamer moment emoji too

View File

@@ -87,7 +87,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
.filter(this::followable)
.filter(this.filter)
.distinct()
.collect(Collectors.toCollection(ArrayList::new));
.collect(Collectors.toList());
}
@Override

View File

@@ -320,6 +320,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(
BlockUtils.blockToString(block),
Baritone.settings().maxCachedWorldScanCount.value,
@@ -414,11 +415,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
@Override
public void mineByName(int quantity, String... blocks) {
mine(quantity, new BlockOptionalMetaLookup(
Arrays.stream(Objects.requireNonNull(blocks))
.map(BlockOptionalMeta::new)
.toArray(BlockOptionalMeta[]::new)
));
mine(quantity, new BlockOptionalMetaLookup(blocks));
}
@Override

View File

@@ -3,10 +3,12 @@ package baritone.selection;
import baritone.api.event.events.RenderEvent;
import baritone.api.event.listener.AbstractGameEventListener;
import baritone.api.selection.ISelection;
import baritone.api.utils.IRenderer;
import baritone.utils.IRenderer;
import net.minecraft.util.math.AxisAlignedBB;
public class SelectionRenderer implements IRenderer, AbstractGameEventListener {
public static final double SELECTION_BOX_EXPANSION = .005D;
private final SelectionManager manager;
SelectionRenderer(SelectionManager manager) {
@@ -26,7 +28,7 @@ public class SelectionRenderer implements IRenderer, AbstractGameEventListener {
IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth);
for (ISelection selection : selections) {
IRenderer.drawAABB(selection.aabb(), .005f);
IRenderer.drawAABB(selection.aabb(), SELECTION_BOX_EXPANSION);
}
if (settings.renderSelectionCorners.value) {

View File

@@ -22,7 +22,6 @@ import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalTwoBlocks;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.IRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;

View File

@@ -0,0 +1,117 @@
/*
* 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
* 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,
* 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils;
import baritone.api.BaritoneAPI;
import baritone.api.IBaritone;
import baritone.api.Settings;
import baritone.api.utils.Helper;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.AxisAlignedBB;
import java.awt.Color;
import static org.lwjgl.opengl.GL11.GL_LINES;
import static org.lwjgl.opengl.GL11.GL_ONE;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_ZERO;
public interface IRenderer {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
RenderManager renderManager = Helper.mc.getRenderManager();
IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
Settings settings = BaritoneAPI.getSettings();
static void glColor(Color color, float alpha) {
float[] colorComponents = color.getColorComponents(null);
GlStateManager.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha);
}
static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
GlStateManager.enableBlend();
GlStateManager.disableLighting();
GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
glColor(color, alpha);
GlStateManager.glLineWidth(lineWidth);
GlStateManager.disableTexture2D();
GlStateManager.depthMask(false);
if (ignoreDepth) {
GlStateManager.disableDepth();
}
}
static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
startLines(color, .4f, lineWidth, ignoreDepth);
}
static void endLines(boolean ignoredDepth) {
if (ignoredDepth) {
GlStateManager.enableDepth();
}
GlStateManager.depthMask(true);
GlStateManager.enableTexture2D();
GlStateManager.enableLighting();
GlStateManager.disableBlend();
}
static void drawAABB(AxisAlignedBB aabb) {
AxisAlignedBB toDraw = aabb.offset(-renderManager.viewerPosX, -renderManager.viewerPosY, -renderManager.viewerPosZ);
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION);
// bottom
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
// top
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
// corners
buffer.pos(toDraw.minX, toDraw.minY, toDraw.minZ).endVertex();
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.minZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.maxX, toDraw.maxY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.minY, toDraw.maxZ).endVertex();
buffer.pos(toDraw.minX, toDraw.maxY, toDraw.maxZ).endVertex();
tessellator.draw();
}
static void drawAABB(AxisAlignedBB aabb, double expand) {
drawAABB(aabb.grow(expand, expand, expand));
}
}

View File

@@ -29,7 +29,6 @@ import baritone.api.pathing.goals.GoalXZ;
import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper;
import baritone.api.utils.IRenderer;
import baritone.api.utils.interfaces.IGoalRenderPos;
import baritone.behavior.PathingBehavior;
import baritone.pathing.path.PathExecutor;
@@ -205,7 +204,7 @@ public final class PathRenderer implements IRenderer {
toDraw = state.getSelectedBoundingBox(player.world, pos);
}
IRenderer.drawAABB(toDraw, .002f);
IRenderer.drawAABB(toDraw, .002D);
});
IRenderer.endLines(settings.renderSelectionBoxesIgnoreDepth.value);

View File

@@ -30,7 +30,7 @@ import static java.util.Arrays.asList;
public class AxisCommand extends Command {
public AxisCommand() {
super(asList("axis", "highway"), "Set a goal to the axes");
super(asList("axis", "highway"));
}
@Override
@@ -46,6 +46,11 @@ public class AxisCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Set a goal to the axes";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -30,7 +30,7 @@ import static java.util.Arrays.asList;
public class BlacklistCommand extends Command {
public BlacklistCommand() {
super("blacklist", "Blacklist closest block");
super("blacklist");
}
@Override
@@ -54,6 +54,11 @@ public class BlacklistCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Blacklist closest block";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -37,7 +37,7 @@ public class BuildCommand extends Command {
private static final File schematicsDir = new File(Minecraft.getMinecraft().gameDir, "schematics");
public BuildCommand() {
super("build", "Build a schematic");
super("build");
}
@Override
@@ -81,6 +81,11 @@ public class BuildCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Build a schematic";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class CancelCommand extends Command {
public CancelCommand() {
super(asList("cancel", "stop"), "Cancel what Baritone is currently doing");
super(asList("cancel", "stop"));
}
@Override
@@ -43,6 +43,11 @@ public class CancelCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Cancel what Baritone is currently doing";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -36,7 +36,7 @@ import static java.util.Arrays.asList;
public class ChestsCommand extends Command {
public ChestsCommand() {
super("chests", "Display remembered inventories");
super("chests");
}
@Override
@@ -69,6 +69,11 @@ public class ChestsCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Display remembered inventories";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -33,7 +33,7 @@ import static java.util.Arrays.asList;
public class ClearareaCommand extends Command {
public ClearareaCommand() {
super("cleararea", "Clear an area of all blocks");
super("cleararea");
}
@Override
@@ -65,6 +65,11 @@ public class ClearareaCommand extends Command {
return args.tabCompleteDatatype(RelativeBlockPos.class);
}
@Override
public String getShortDesc() {
return "Clear an area of all blocks";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class ClickCommand extends Command {
public ClickCommand() {
super("click", "Open click");
super("click");
}
@Override
@@ -43,6 +43,11 @@ public class ClickCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Open click";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -33,7 +33,7 @@ import static java.util.Objects.isNull;
public class ComeCommand extends Command {
public ComeCommand() {
super("come", "Start heading towards your camera");
super("come");
}
@Override
@@ -54,12 +54,17 @@ public class ComeCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Start heading towards your camera";
}
@Override
public List<String> getLongDesc() {
return asList(
"The come command tells Baritone to head towards your camera.",
"",
"I'm... not actually sure how useful this is, to be honest.",
"This can be useful in hacked clients where freecam doesn't move your player position.",
"",
"Usage:",
"> come"

View File

@@ -27,15 +27,18 @@ import java.util.List;
import java.util.stream.Stream;
public class CommandAlias extends Command {
private final String shortDesc;
public final String target;
public CommandAlias(List<String> names, String shortDesc, String target) {
super(names, shortDesc);
super(names);
this.shortDesc = shortDesc;
this.target = target;
}
public CommandAlias(String name, String shortDesc, String target) {
super(name, shortDesc);
super(name);
this.shortDesc = shortDesc;
this.target = target;
}
@@ -49,6 +52,11 @@ public class CommandAlias extends Command {
return CommandManager.tabComplete(String.format("%s %s", target, args.rawRest()));
}
@Override
public String getShortDesc() {
return shortDesc;
}
@Override
public List<String> getLongDesc() {
return Collections.singletonList(String.format("This command is an alias, for: %s ...", target));

View File

@@ -18,7 +18,6 @@
package baritone.utils.command.defaults;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.manager.CommandManager;
import java.util.Collections;
import java.util.List;
@@ -26,7 +25,7 @@ import java.util.List;
import static java.util.Arrays.asList;
public class DefaultCommands {
public static final List<Command> commands = Collections.unmodifiableList(asList(
public static final List<Command> COMMANDS = Collections.unmodifiableList(asList(
new HelpCommand(),
new SetCommand(),
new CommandAlias(asList("modified", "mod", "baritone", "modifiedsettings"), "List modified settings", "set modified"),

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class EmptyCommand extends Command {
public EmptyCommand() {
super(asList("name1", "name2"), "Short description");
super(asList("name1", "name2"));
}
@Override
@@ -41,6 +41,11 @@ public class EmptyCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Short description";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -30,7 +30,7 @@ import static java.util.Arrays.asList;
public class ExploreCommand extends Command {
public ExploreCommand() {
super("explore", "Explore things");
super("explore");
}
@Override
@@ -58,6 +58,11 @@ public class ExploreCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Explore things";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -34,7 +34,7 @@ import static java.util.Arrays.asList;
public class ExploreFilterCommand extends Command {
public ExploreFilterCommand() {
super("explorefilter", "Explore chunks from a json");
super("explorefilter");
}
@Override
@@ -73,6 +73,11 @@ public class ExploreFilterCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Explore chunks from a json";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class FarmCommand extends Command {
public FarmCommand() {
super("farm", "Farm nearby crops");
super("farm");
}
@Override
@@ -43,6 +43,11 @@ public class FarmCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Farm nearby crops";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -32,7 +32,7 @@ import static java.util.Arrays.asList;
public class FindCommand extends Command {
public FindCommand() {
super("find", "Find positions of a certain block");
super("find");
}
@Override
@@ -65,6 +65,11 @@ public class FindCommand extends Command {
return args.tabCompleteDatatype(BlockById.class);
}
@Override
public String getShortDesc() {
return "Find positions of a certain block";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -44,7 +44,7 @@ import static java.util.Objects.nonNull;
public class FollowCommand extends Command {
public FollowCommand() {
super("follow", "Follow entity things");
super("follow");
}
@Override
@@ -131,6 +131,11 @@ public class FollowCommand extends Command {
}
}
@Override
public String getShortDesc() {
return "Follow entity things";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -29,7 +29,7 @@ import static java.util.Arrays.asList;
public class ForceCancelCommand extends Command {
public ForceCancelCommand() {
super("forcecancel", "Force cancel");
super("forcecancel");
}
@Override
@@ -46,6 +46,11 @@ public class ForceCancelCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Force cancel";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class GcCommand extends Command {
public GcCommand() {
super("gc", "Call System.gc()");
super("gc");
}
@Override
@@ -45,6 +45,11 @@ public class GcCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Call System.gc()";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -36,7 +36,7 @@ import static java.util.Objects.nonNull;
public class GoalCommand extends Command {
public GoalCommand() {
super("goal", "Set or clear the goal");
super("goal");
}
@Override
@@ -86,6 +86,11 @@ public class GoalCommand extends Command {
return helper.filterPrefix(args.getString()).stream();
}
@Override
public String getShortDesc() {
return "Set or clear the goal";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -24,12 +24,12 @@ import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.pagination.Paginator;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.utils.command.manager.CommandManager;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -41,7 +41,7 @@ import static java.util.Objects.isNull;
public class HelpCommand extends Command {
public HelpCommand() {
super(asList("help", "?"), "View all commands or help on specific ones");
super(asList("help", "?"));
}
@Override
@@ -53,40 +53,35 @@ public class HelpCommand extends Command {
args, new Paginator<>(
CommandManager.REGISTRY.descendingStream()
.filter(command -> !command.hiddenFromHelp())
.collect(Collectors.toCollection(ArrayList::new))
.collect(Collectors.toList())
),
() -> logDirect("All Baritone commands (clickable):"),
command -> {
String names = String.join("/", command.names);
String name = command.names.get(0);
return new TextComponentString(name) {{
getStyle()
.setColor(TextFormatting.GRAY)
.setHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponentString("") {{
getStyle().setColor(TextFormatting.GRAY);
ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
appendSibling(new TextComponentString(names + "\n") {{
getStyle().setColor(TextFormatting.WHITE);
}});
ITextComponent namesComponent = new TextComponentString(names);
namesComponent.getStyle().setColor(TextFormatting.WHITE);
appendText(command.shortDesc);
appendText("\n\nClick to view full help");
}}
))
.setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + String.format("help %s", command.names.get(0))
));
ITextComponent hoverComponent = new TextComponentString("");
hoverComponent.getStyle().setColor(TextFormatting.GRAY);
hoverComponent.appendSibling(namesComponent);
hoverComponent.appendText("\n" + command.getShortDesc());
hoverComponent.appendText("\n\nClick to view full help");
String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.names.get(0));
appendSibling(new TextComponentString(" - " + command.shortDesc) {{
getStyle().setColor(TextFormatting.DARK_GRAY);
}});
}};
ITextComponent component = new TextComponentString(name);
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(shortDescComponent);
component.getStyle()
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent))
.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, clickCommand));
return component;
},
FORCE_COMMAND_PREFIX + "help"
FORCE_COMMAND_PREFIX + label
);
} else {
String commandName = args.getString().toLowerCase();
@@ -96,16 +91,18 @@ public class HelpCommand extends Command {
throw new CommandNotFoundException(commandName);
}
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.shortDesc));
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc()));
logDirect("");
command.getLongDesc().forEach(this::logDirect);
logDirect("");
logDirect(new TextComponentString("Click to return to the help menu") {{
getStyle().setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + "help"
));
}});
ITextComponent returnComponent = new TextComponentString("Click to return to the help menu");
returnComponent.getStyle().setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + label
));
logDirect(returnComponent);
}
}
@@ -118,6 +115,11 @@ public class HelpCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "View all commands or help on specific ones";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -33,7 +33,7 @@ import static java.util.Objects.isNull;
public class InvertCommand extends Command {
public InvertCommand() {
super("invert", "Run away from the current goal");
super("invert");
}
@Override
@@ -62,6 +62,11 @@ public class InvertCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Run away from the current goal";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -23,6 +23,7 @@ import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.BlockById;
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.cache.WorldScanner;
import java.util.ArrayList;
import java.util.List;
@@ -32,7 +33,7 @@ import static java.util.Arrays.asList;
public class MineCommand extends Command {
public MineCommand() {
super("mine", "Mine some blocks");
super("mine");
}
@Override
@@ -45,6 +46,7 @@ public class MineCommand extends Command {
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
}
WorldScanner.INSTANCE.repack(ctx);
baritone.getMineProcess().mine(quantity, boms.toArray(new BlockOptionalMeta[0]));
logDirect(String.format("Mining %s", boms.toString()));
}
@@ -54,13 +56,24 @@ public class MineCommand extends Command {
return args.tabCompleteDatatype(BlockById.class);
}
@Override
public String getShortDesc() {
return "Mine some blocks";
}
@Override
public List<String> getLongDesc() {
return asList(
"The mine command allows you to tell Baritone to search for and mine individual blocks.",
"",
"The specified blocks can be ores (which are commonly cached), or any other block.",
"",
"Also see the legitMine settings (see #set l legitMine).",
"",
"Usage:",
"> "
"> mine diamond_ore - Mines all diamonds it can find.",
"> mine redstone_ore lit_redstone_ore - Mines redstone ore.",
"> mine log:0 - Mines only oak logs."
);
}
}

View File

@@ -26,6 +26,7 @@ import baritone.api.utils.command.datatypes.RelativeGoal;
import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.cache.WorldScanner;
import java.util.List;
import java.util.stream.Stream;
@@ -35,7 +36,7 @@ import static java.util.Objects.isNull;
public class PathCommand extends Command {
public PathCommand() {
super("path", "Start heading towards a goal");
super(asList("path", "goto"));
}
@Override
@@ -51,6 +52,7 @@ public class PathCommand extends Command {
}
args.requireMax(0);
WorldScanner.INSTANCE.repack(ctx);
customGoalProcess.setGoalAndPath(goal);
logDirect("Now pathing");
}
@@ -77,6 +79,11 @@ public class PathCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Start heading towards a goal";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -79,7 +79,7 @@ public class PauseResumeCommands {
}
);
pauseCommand = new Command("pause", "Pauses Baritone until you use resume") {
pauseCommand = new Command("pause") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
@@ -97,6 +97,11 @@ public class PauseResumeCommands {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Pauses Baritone until you use resume";
}
@Override
public List<String> getLongDesc() {
return asList(
@@ -110,7 +115,7 @@ public class PauseResumeCommands {
}
};
resumeCommand = new Command("resume", "Resumes Baritone after a pause") {
resumeCommand = new Command("resume") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
@@ -128,6 +133,11 @@ public class PauseResumeCommands {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Resumes Baritone after a pause";
}
@Override
public List<String> getLongDesc() {
return asList(
@@ -139,7 +149,7 @@ public class PauseResumeCommands {
}
};
pausedCommand = new Command("paused", "Tells you if Baritone is paused") {
pausedCommand = new Command("paused") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
@@ -152,6 +162,11 @@ public class PauseResumeCommands {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Tells you if Baritone is paused";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -33,7 +33,7 @@ import static java.util.Objects.isNull;
public class ProcCommand extends Command {
public ProcCommand() {
super("proc", "View process state information");
super("proc");
}
@Override
@@ -69,6 +69,11 @@ public class ProcCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "View process state information";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class ReloadAllCommand extends Command {
public ReloadAllCommand() {
super("reloadall", "Reloads Baritone's cache for this world");
super("reloadall");
}
@Override
@@ -43,6 +43,11 @@ public class ReloadAllCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Reloads Baritone's cache for this world";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -29,7 +29,7 @@ import static java.util.Arrays.asList;
public class RenderCommand extends Command {
public RenderCommand() {
super("render", "Fix glitched chunks");
super("render");
}
@Override
@@ -55,6 +55,11 @@ public class RenderCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Fix glitched chunks";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -18,47 +18,24 @@
package baritone.utils.command.defaults;
import baritone.api.Settings;
import baritone.api.cache.ICachedWorld;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunkProvider;
import baritone.cache.WorldScanner;
import java.util.List;
import java.util.stream.Stream;
import static java.util.Arrays.asList;
import static java.util.Objects.nonNull;
public class RepackCommand extends Command {
public RepackCommand() {
super(asList("repack", "rescan"), "Re-cache chunks");
super(asList("repack", "rescan"));
}
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
IChunkProvider chunkProvider = ctx.world().getChunkProvider();
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
BetterBlockPos playerPos = ctx.playerFeet();
int playerChunkX = playerPos.getX() >> 4;
int playerChunkZ = playerPos.getZ() >> 4;
int queued = 0;
for (int x = playerChunkX - 40; x <= playerChunkX + 40; x++) {
for (int z = playerChunkZ - 40; z <= playerChunkZ + 40; z++) {
Chunk chunk = chunkProvider.getLoadedChunk(x, z);
if (nonNull(chunk) && !chunk.isEmpty()) {
queued++;
cachedWorld.queueForPacking(chunk);
}
}
}
logDirect(String.format("Queued %d chunks for repacking", queued));
logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
}
@Override
@@ -66,6 +43,11 @@ public class RepackCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Re-cache chunks";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class SaveAllCommand extends Command {
public SaveAllCommand() {
super("saveall", "Saves Baritone's cache for this world");
super("saveall");
}
@Override
@@ -43,6 +43,11 @@ public class SaveAllCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Saves Baritone's cache for this world";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -28,7 +28,7 @@ import static java.util.Arrays.asList;
public class SchematicaCommand extends Command {
public SchematicaCommand() {
super("schematica", "Opens a Schematica schematic?");
super("schematica");
}
@Override
@@ -42,10 +42,15 @@ public class SchematicaCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Builds the loaded schematic";
}
@Override
public List<String> getLongDesc() {
return asList(
"I'm not actually sure what this does.",
"Builds the schematica currently open in Schematica.",
"",
"Usage:",
"> schematica"

View File

@@ -20,7 +20,7 @@ package baritone.utils.command.defaults;
import baritone.api.Settings;
import baritone.api.event.events.RenderEvent;
import baritone.api.schematic.CompositeSchematic;
import baritone.api.schematic.FillBomSchematic;
import baritone.api.schematic.FillSchematic;
import baritone.api.schematic.ReplaceSchematic;
import baritone.api.schematic.ShellSchematic;
import baritone.api.schematic.WallsSchematic;
@@ -29,7 +29,6 @@ import baritone.api.selection.ISelectionManager;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import baritone.api.utils.BlockOptionalMetaLookup;
import baritone.api.utils.IRenderer;
import baritone.api.utils.ISchematic;
import baritone.api.utils.command.Command;
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
@@ -39,6 +38,7 @@ import baritone.api.utils.command.exception.CommandInvalidStateException;
import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.utils.IRenderer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
@@ -59,7 +59,7 @@ public class SelCommand extends Command {
private BetterBlockPos pos1 = null;
public SelCommand() {
super(asList("sel", "selection", "s"), "WorldEdit-like commands");
super(asList("sel", "selection", "s"));
}
@Override
@@ -118,10 +118,13 @@ public class SelCommand extends Command {
List<BlockOptionalMeta> replacesList = new ArrayList<>();
while (args.has()) {
replacesList.add(type);
while (args.has(2)) {
replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
}
type = args.getDatatypeFor(ForBlockOptionalMeta.class);
replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
} else {
args.requireMax(0);
@@ -149,7 +152,7 @@ public class SelCommand extends Command {
Vec3i size = selection.size();
BetterBlockPos min = selection.min();
ISchematic schematic = new FillBomSchematic(baritone, size.getX(), size.getY(), size.getZ(), type);
ISchematic schematic = new FillSchematic(baritone, size.getX(), size.getY(), size.getZ(), type);
if (action == Action.WALLS) {
schematic = new WallsSchematic(baritone, schematic);
@@ -242,6 +245,11 @@ public class SelCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "WorldEdit-like commands";
}
@Override
public List<String> getLongDesc() {
return asList(
@@ -263,7 +271,7 @@ public class SelCommand extends Command {
"> sel walls/w [block] - Fill in the walls of the selection with a specified block.",
"> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.",
"> sel cleararea/ca - Basically 'set air'.",
"> sel replace/r <place> <break...> - Replaces, with 'place', all blocks listed after it.",
"> sel replace/r <blocks...> <with> - Replaces blocks with another block.",
"",
"> sel expand <target> <direction> <blocks> - Expand the targets.",
"> sel contract <target> <direction> <blocks> - Contract the targets.",

View File

@@ -24,18 +24,17 @@ import baritone.api.utils.command.exception.CommandInvalidTypeException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.helpers.pagination.Paginator;
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.HoverEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static baritone.api.utils.SettingsUtil.settingDefaultToString;
import static baritone.api.utils.SettingsUtil.settingTypeToString;
import static baritone.api.utils.SettingsUtil.settingValueToString;
import static baritone.api.utils.command.BaritoneChatControl.FORCE_COMMAND_PREFIX;
@@ -46,7 +45,7 @@ import static java.util.stream.Stream.of;
public class SetCommand extends Command {
public SetCommand() {
super(asList("set", "setting", "settings"), "View or change settings");
super(asList("set", "setting", "settings"));
}
@Override
@@ -71,7 +70,7 @@ public class SetCommand extends Command {
.filter(s -> !s.getName().equals("logger"))
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
.collect(Collectors.toCollection(ArrayList<Settings.Setting>::new));
.collect(Collectors.toList());
Paginator.paginate(
args,
@@ -81,31 +80,29 @@ public class SetCommand extends Command {
? String.format("All %ssettings containing the string '%s':", viewModified ? "modified " : "", search)
: String.format("All %ssettings:", viewModified ? "modified " : "")
),
setting -> new TextComponentString(setting.getName()) {{
getStyle()
.setColor(TextFormatting.GRAY)
.setHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponentString("") {{
getStyle().setColor(TextFormatting.GRAY);
appendText(setting.getName());
appendText(String.format("\nType: %s", settingTypeToString(setting)));
appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
setting -> {
ITextComponent typeComponent = new TextComponentString(String.format(
" (%s)",
settingTypeToString(setting)
));
typeComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
if (setting.value != setting.defaultValue) {
appendText(String.format("\n\nDefault:\n%s", settingDefaultToString(setting)));
}
}}
))
.setClickEvent(new ClickEvent(
ClickEvent.Action.SUGGEST_COMMAND,
settings.prefix.value + String.format("set %s ", setting.getName())
));
ITextComponent hoverComponent = new TextComponentString("");
hoverComponent.getStyle().setColor(TextFormatting.GRAY);
hoverComponent.appendText(setting.getName());
hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting)));
hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
String commandSuggestion = settings.prefix.value + String.format("set %s ", setting.getName());
appendSibling(new TextComponentString(String.format(" (%s)", settingTypeToString(setting))) {{
getStyle().setColor(TextFormatting.DARK_GRAY);
}});
}},
ITextComponent component = new TextComponentString(setting.getName());
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(typeComponent);
component.getStyle()
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent))
.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion));
return component;
},
FORCE_COMMAND_PREFIX + "set " + arg + " " + search
);
@@ -187,18 +184,19 @@ public class SetCommand extends Command {
));
}
logDirect(new TextComponentString(String.format("Old value: %s", oldValue)) {{
getStyle()
.setColor(TextFormatting.GRAY)
.setHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponentString("Click to set the setting back to this value")
))
.setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)
));
}});
ITextComponent oldValueComponent = new TextComponentString(String.format("Old value: %s", oldValue));
oldValueComponent.getStyle()
.setColor(TextFormatting.GRAY)
.setHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new TextComponentString("Click to set the setting back to this value")
))
.setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)
));
logDirect(oldValueComponent);
if ((setting.getName().equals("chatControl") && !(Boolean) setting.value && !settings.chatControlAnyway.value) ||
setting.getName().equals("chatControlAnyway") && !(Boolean) setting.value && !settings.chatControl.value) {
@@ -260,6 +258,11 @@ public class SetCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "View or change settings";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -29,7 +29,7 @@ import static java.util.Arrays.asList;
public class ThisWayCommand extends Command {
public ThisWayCommand() {
super(asList("thisway", "forward"), "Travel in your current direction");
super(asList("thisway", "forward"));
}
@Override
@@ -51,6 +51,11 @@ public class ThisWayCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Travel in your current direction";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -30,7 +30,7 @@ import static java.util.Arrays.asList;
public class TunnelCommand extends Command {
public TunnelCommand() {
super("tunnel", "Set a goal to tunnel in your current direction");
super("tunnel");
}
@Override
@@ -51,6 +51,11 @@ public class TunnelCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Set a goal to tunnel in your current direction";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -30,7 +30,7 @@ import static java.util.Objects.isNull;
public class VersionCommand extends Command {
public VersionCommand() {
super("version", "View the Baritone version");
super("version");
}
@Override
@@ -51,6 +51,11 @@ public class VersionCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "View the Baritone version";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -50,7 +50,7 @@ import static java.util.Arrays.asList;
public class WaypointsCommand extends Command {
public WaypointsCommand() {
super(asList("waypoints", "waypoint", "wp"), "Manage waypoints");
super(asList("waypoints", "waypoint", "wp"));
}
@Override
@@ -87,7 +87,7 @@ public class WaypointsCommand extends Command {
FORCE_COMMAND_PREFIX,
label,
_action.names[0],
waypoint.getTag().names[0],
waypoint.getTag().getName(),
waypoint.getCreationTimestamp()
))
);
@@ -99,7 +99,7 @@ public class WaypointsCommand extends Command {
toComponent.apply(waypoint, action == Action.LIST ? Action.INFO : action);
if (action == Action.LIST) {
IWaypoint.Tag tag = args.has() ? ForWaypoints.getTagByName(args.peekString()) : null;
IWaypoint.Tag tag = args.has() ? IWaypoint.Tag.getByName(args.peekString()) : null;
if (tag != null) {
args.get();
@@ -125,7 +125,7 @@ public class WaypointsCommand extends Command {
FORCE_COMMAND_PREFIX,
label,
action.names[0],
tag != null ? " " + tag.names[0] : ""
tag != null ? " " + tag.getName() : ""
)
);
} else {
@@ -137,7 +137,7 @@ public class WaypointsCommand extends Command {
);
}
} else if (action == Action.SAVE) {
IWaypoint.Tag tag = ForWaypoints.getTagByName(args.getString());
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
if (tag == null) {
throw new CommandInvalidStateException(String.format("'%s' is not a tag ", args.consumedString()));
@@ -159,7 +159,7 @@ public class WaypointsCommand extends Command {
logDirect(component);
} else if (action == Action.CLEAR) {
args.requireMax(1);
IWaypoint.Tag tag = ForWaypoints.getTagByName(args.getString());
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(tag);
for (IWaypoint waypoint : waypoints) {
@@ -221,7 +221,7 @@ public class WaypointsCommand extends Command {
"%s%s delete %s @ %d",
FORCE_COMMAND_PREFIX,
label,
waypoint.getTag().names[0],
waypoint.getTag().getName(),
waypoint.getCreationTimestamp()
)
));
@@ -232,7 +232,7 @@ public class WaypointsCommand extends Command {
"%s%s goal %s @ %d",
FORCE_COMMAND_PREFIX,
label,
waypoint.getTag().names[0],
waypoint.getTag().getName(),
waypoint.getCreationTimestamp()
)
));
@@ -275,7 +275,7 @@ public class WaypointsCommand extends Command {
if (args.hasExactlyOne()) {
if (action == Action.LIST || action == Action.SAVE || action == Action.CLEAR) {
return new TabCompleteHelper()
.append(ForWaypoints.getTagNames())
.append(IWaypoint.Tag.getAllNames())
.sortAlphabetically()
.filterPrefix(args.getString())
.stream();
@@ -293,6 +293,11 @@ public class WaypointsCommand extends Command {
return Stream.empty();
}
@Override
public String getShortDesc() {
return "Manage waypoints";
}
@Override
public List<String> getLongDesc() {
return asList(

View File

@@ -19,7 +19,8 @@ package baritone.utils.schematic;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import java.util.List;
public class FillSchematic implements ISchematic {
private final int widthX;
@@ -35,7 +36,7 @@ public class FillSchematic implements ISchematic {
}
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current) {
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
return state;
}

View File

@@ -22,6 +22,8 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
public class Schematic implements ISchematic {
public final int widthX;
public final int heightY;
@@ -68,7 +70,7 @@ public class Schematic implements ISchematic {
}
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current) {
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
return states[x][z][y];
}

View File

@@ -23,6 +23,8 @@ import com.github.lunatrius.schematica.client.world.SchematicWorld;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import java.util.List;
public final class SchematicAdapter implements ISchematic {
private final SchematicWorld schematic;
@@ -31,7 +33,7 @@ public final class SchematicAdapter implements ISchematic {
}
@Override
public IBlockState desiredState(int x, int y, int z, IBlockState current) {
public IBlockState desiredState(int x, int y, int z, IBlockState current, List<IBlockState> approxPlaceable) {
return schematic.getSchematic().getBlockState(new BlockPos(x, y, z));
}