Search in sources :

Example 51 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class GuiClick method onRender.

public void onRender() {
    GlStateManager.getFloat(GL_MODELVIEW_MATRIX, (FloatBuffer) MODELVIEW.clear());
    GlStateManager.getFloat(GL_PROJECTION_MATRIX, (FloatBuffer) PROJECTION.clear());
    GlStateManager.glGetInteger(GL_VIEWPORT, (IntBuffer) VIEWPORT.clear());
    if (currentMouseOver != null) {
        Entity e = mc.getRenderViewEntity();
        // drawSingleSelectionBox WHEN?
        PathRenderer.drawManySelectionBoxes(e, Collections.singletonList(currentMouseOver), Color.CYAN);
        if (clickStart != null && !clickStart.equals(currentMouseOver)) {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
            GlStateManager.color(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F);
            GlStateManager.glLineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
            GlStateManager.disableTexture2D();
            GlStateManager.depthMask(false);
            GlStateManager.disableDepth();
            BetterBlockPos a = new BetterBlockPos(currentMouseOver);
            BetterBlockPos b = new BetterBlockPos(clickStart);
            IRenderer.drawAABB(new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));
            GlStateManager.enableDepth();
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Example 52 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class BetterBlockPosTest method benchN.

public void benchN() {
    BlockPos pos = new BlockPos(1, 2, 3);
    BetterBlockPos pos2 = new BetterBlockPos(1, 2, 3);
    try {
        // give GC some time
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    long before1 = System.nanoTime() / 1000000L;
    for (int i = 0; i < 1000000; i++) {
        pos.up(0);
        pos.up(1);
        pos.up(2);
        pos.up(3);
        pos.up(4);
    }
    long after1 = System.nanoTime() / 1000000L;
    try {
        // give GC some time
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    long before2 = System.nanoTime() / 1000000L;
    for (int i = 0; i < 1000000; i++) {
        pos2.up(0);
        pos2.up(1);
        pos2.up(2);
        pos2.up(3);
        pos2.up(4);
    }
    long after2 = System.nanoTime() / 1000000L;
    System.out.println((after1 - before1) + " " + (after2 - before2));
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 53 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class BetterBlockPosTest method benchOne.

public void benchOne() {
    BlockPos pos = new BlockPos(1, 2, 3);
    BetterBlockPos pos2 = new BetterBlockPos(1, 2, 3);
    try {
        // give GC some time
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    long before1 = System.nanoTime() / 1000000L;
    for (int i = 0; i < 1000000; i++) {
        pos.up();
    }
    long after1 = System.nanoTime() / 1000000L;
    try {
        // give GC some time
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    long before2 = System.nanoTime() / 1000000L;
    for (int i = 0; i < 1000000; i++) {
        pos2.up();
    }
    long after2 = System.nanoTime() / 1000000L;
    System.out.println((after1 - before1) + " " + (after2 - before2));
}
Also used : BetterBlockPos(baritone.api.utils.BetterBlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 54 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class BetterBlockPosTest method testSimple.

// disabled since this is a benchmark, not really a test. also including it makes the tests take 50 seconds for no reason
/*@Test
    public void benchMulti() {
        System.out.println("Benching up()");
        for (int i = 0; i < 10; i++) {
            // eliminate any advantage to going first
            benchOne();
        }
        System.out.println("Benching up(int)");
        for (int i = 0; i < 10; i++) {
            // eliminate any advantage to going first
            benchN();
            assertTrue(i<10);
        }
    }*/
/**
 * Make sure BetterBlockPos behaves just like BlockPos
 */
@Test
public void testSimple() {
    BlockPos pos = new BlockPos(1, 2, 3);
    BetterBlockPos better = new BetterBlockPos(1, 2, 3);
    assertEquals(pos, better);
    assertEquals(pos.up(), better.up());
    assertEquals(pos.down(), better.down());
    assertEquals(pos.north(), better.north());
    assertEquals(pos.south(), better.south());
    assertEquals(pos.east(), better.east());
    assertEquals(pos.west(), better.west());
    for (EnumFacing dir : EnumFacing.values()) {
        assertEquals(pos.offset(dir), better.offset(dir));
        assertEquals(pos.offset(dir, 0), pos);
        assertEquals(better.offset(dir, 0), better);
        for (int i = -10; i < 10; i++) {
            assertEquals(pos.offset(dir, i), better.offset(dir, i));
        }
        assertTrue(better.offset(dir, 0) == better);
    }
    for (int i = -10; i < 10; i++) {
        assertEquals(pos.up(i), better.up(i));
        assertEquals(pos.down(i), better.down(i));
        assertEquals(pos.north(i), better.north(i));
        assertEquals(pos.south(i), better.south(i));
        assertEquals(pos.east(i), better.east(i));
        assertEquals(pos.west(i), better.west(i));
    }
    assertTrue(better.offset(null, 0) == better);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BetterBlockPos(baritone.api.utils.BetterBlockPos) BetterBlockPos(baritone.api.utils.BetterBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Test(org.junit.Test)

Example 55 with BetterBlockPos

use of baritone.api.utils.BetterBlockPos in project baritone by cabaletta.

the class PathingBehavior method tickPath.

private void tickPath() {
    pausedThisTick = false;
    if (pauseRequestedLastTick && safeToCancel) {
        pauseRequestedLastTick = false;
        if (unpausedLastTick) {
            baritone.getInputOverrideHandler().clearAllKeys();
            baritone.getInputOverrideHandler().getBlockBreakHelper().stopBreakingBlock();
        }
        unpausedLastTick = false;
        pausedThisTick = true;
        return;
    }
    unpausedLastTick = true;
    if (cancelRequested) {
        cancelRequested = false;
        baritone.getInputOverrideHandler().clearAllKeys();
    }
    synchronized (pathPlanLock) {
        synchronized (pathCalcLock) {
            if (inProgress != null) {
                // we are calculating
                // are we calculating the right thing though? 🤔
                BetterBlockPos calcFrom = inProgress.getStart();
                Optional<IPath> currentBest = inProgress.bestPathSoFar();
                if (// if current ends in inProgress's start, then we're ok
                (current == null || !current.getPath().getDest().equals(calcFrom)) && !calcFrom.equals(ctx.playerFeet()) && // if current starts in our playerFeet or pathStart, then we're ok
                !calcFrom.equals(expectedSegmentStart) && // if
                (!currentBest.isPresent() || (!currentBest.get().positions().contains(ctx.playerFeet()) && !currentBest.get().positions().contains(expectedSegmentStart)))) {
                    // when it was *just* started, currentBest will be empty so we need to also check calcFrom since that's always present
                    // cancellation doesn't dispatch any events
                    inProgress.cancel();
                }
            }
        }
        if (current == null) {
            return;
        }
        safeToCancel = current.onTick();
        if (current.failed() || current.finished()) {
            current = null;
            if (goal == null || goal.isInGoal(ctx.playerFeet())) {
                logDebug("All done. At " + goal);
                queuePathEvent(PathEvent.AT_GOAL);
                next = null;
                if (Baritone.settings().disconnectOnArrival.value) {
                    ctx.world().sendQuittingDisconnectingPacket();
                }
                return;
            }
            if (next != null && !next.getPath().positions().contains(ctx.playerFeet()) && !next.getPath().positions().contains(expectedSegmentStart)) {
                // can contain either one
                // if the current path failed, we may not actually be on the next one, so make sure
                logDebug("Discarding next path as it does not contain current position");
                // for example if we had a nicely planned ahead path that starts where current ends
                // that's all fine and good
                // but if we fail in the middle of current
                // we're nowhere close to our planned ahead path
                // so need to discard it sadly.
                queuePathEvent(PathEvent.DISCARD_NEXT);
                next = null;
            }
            if (next != null) {
                logDebug("Continuing on to planned next path");
                queuePathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT);
                current = next;
                next = null;
                // don't waste a tick doing nothing, get started right away
                current.onTick();
                return;
            }
            // at this point, current just ended, but we aren't in the goal and have no plan for the future
            synchronized (pathCalcLock) {
                if (inProgress != null) {
                    queuePathEvent(PathEvent.PATH_FINISHED_NEXT_STILL_CALCULATING);
                    return;
                }
                // we aren't calculating
                queuePathEvent(PathEvent.CALC_STARTED);
                findPathInNewThread(expectedSegmentStart, true, context);
            }
            return;
        }
        // at this point, we know current is in progress
        if (safeToCancel && next != null && next.snipsnapifpossible()) {
            // a movement just ended; jump directly onto the next path
            logDebug("Splicing into planned next path early...");
            queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
            current = next;
            next = null;
            current.onTick();
            return;
        }
        if (Baritone.settings().splicePath.value) {
            current = current.trySplice(next);
        }
        if (next != null && current.getPath().getDest().equals(next.getPath().getDest())) {
            next = null;
        }
        synchronized (pathCalcLock) {
            if (inProgress != null) {
                // if we aren't calculating right now
                return;
            }
            if (next != null) {
                // and we have no plan for what to do next
                return;
            }
            if (goal == null || goal.isInGoal(current.getPath().getDest())) {
                // and this path doesn't get us all the way there
                return;
            }
            if (ticksRemainingInSegment(false).get() < Baritone.settings().planningTickLookahead.value) {
                // and this path has 7.5 seconds or less left
                // don't include the current movement so a very long last movement (e.g. descend) doesn't trip it up
                // if we actually included current, it wouldn't start planning ahead until the last movement was done, if the last movement took more than 7.5 seconds on its own
                logDebug("Path almost over. Planning ahead...");
                queuePathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED);
                findPathInNewThread(current.getPath().getDest(), false, context);
            }
        }
    }
}
Also used : IPath(baritone.api.pathing.calc.IPath) BetterBlockPos(baritone.api.utils.BetterBlockPos)

Aggregations

BetterBlockPos (baritone.api.utils.BetterBlockPos)57 IBlockState (net.minecraft.block.state.IBlockState)15 Goal (baritone.api.pathing.goals.Goal)14 BlockPos (net.minecraft.util.math.BlockPos)10 CommandInvalidStateException (baritone.api.command.exception.CommandInvalidStateException)9 IWaypoint (baritone.api.cache.IWaypoint)6 GoalBlock (baritone.api.pathing.goals.GoalBlock)6 Waypoint (baritone.api.cache.Waypoint)5 Rotation (baritone.api.utils.Rotation)5 EnumFacing (net.minecraft.util.EnumFacing)5 IBaritone (baritone.api.IBaritone)4 Command (baritone.api.command.Command)4 IArgConsumer (baritone.api.command.argument.IArgConsumer)4 ForBlockOptionalMeta (baritone.api.command.datatypes.ForBlockOptionalMeta)4 RelativeBlockPos (baritone.api.command.datatypes.RelativeBlockPos)4 RelativeGoal (baritone.api.command.datatypes.RelativeGoal)4 CommandException (baritone.api.command.exception.CommandException)4 CommandInvalidTypeException (baritone.api.command.exception.CommandInvalidTypeException)4 IPath (baritone.api.pathing.calc.IPath)4 PathingCommand (baritone.api.process.PathingCommand)4