From 4b689bd9462d29e34f7b7af59e203fbfdaeb97ee Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 28 Jun 2023 17:55:47 -0500 Subject: [PATCH] Fix `Supplier` meme --- .../baritone/behavior/ElytraBehavior.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/baritone/behavior/ElytraBehavior.java b/src/main/java/baritone/behavior/ElytraBehavior.java index 9bdb255ee..c2df278a4 100644 --- a/src/main/java/baritone/behavior/ElytraBehavior.java +++ b/src/main/java/baritone/behavior/ElytraBehavior.java @@ -871,11 +871,6 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H } } - @FunctionalInterface - private interface IntBiFunction { - T apply(int left, int right); - } - private static FloatArrayList pitchesToSolveFor(final float goodPitch, final boolean desperate) { final float minPitch = desperate ? -90 : Math.max(goodPitch - Baritone.settings().elytraPitchRange.value, -89); final float maxPitch = desperate ? 90 : Math.min(goodPitch + Baritone.settings().elytraPitchRange.value, 89); @@ -891,6 +886,21 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H return pitchValues; } + @FunctionalInterface + private interface IntBiFunction { + T apply(int left, int right); + } + + private static final class IntPair { + public final int first; + public final int second; + + public IntPair(int first, int second) { + this.first = first; + this.second = second; + } + } + private Pair solvePitch(final SolverContext context, final Vec3d goal, final int relaxation, final boolean ignoreLava) { @@ -901,30 +911,30 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H final IntBiFunction solve = (ticks, ticksBoosted) -> this.solvePitch(context, goal, relaxation, pitches.iterator(), ticks, ticksBoosted, ignoreLava); - final List> tests = new ArrayList<>(); + final List tests = new ArrayList<>(); if (context.boost.isBoosted()) { final int guaranteed = context.boost.getGuaranteedBoostTicks(); if (guaranteed == 0) { // uncertain when boost will run out final int lookahead = Math.max(4, 10 - context.boost.getMaximumBoostTicks()); - tests.add(() -> solve.apply(lookahead, 1)); - tests.add(() -> solve.apply(5, 5)); + tests.add(new IntPair(lookahead, 1)); + tests.add(new IntPair(5, 5)); } else if (guaranteed <= 5) { // boost will run out within 5 ticks - tests.add(() -> solve.apply(guaranteed + 5, guaranteed)); + tests.add(new IntPair(guaranteed + 5, guaranteed)); } else { // there's plenty of guaranteed boost - tests.add(() -> solve.apply(guaranteed + 1, guaranteed)); + tests.add(new IntPair(guaranteed + 1, guaranteed)); } } // Standard test, assume (not) boosted for entire duration final int ticks = desperate ? 3 : context.boost.isBoosted() ? Math.max(5, context.boost.getGuaranteedBoostTicks()) : Baritone.settings().elytraSimulationTicks.value; - tests.add(() -> solve.apply(ticks, context.boost.isBoosted() ? ticks : 0)); + tests.add(new IntPair(ticks, context.boost.isBoosted() ? ticks : 0)); final Optional result = tests.stream() - .map(Supplier::get) + .map(i -> solve.apply(i.first, i.second)) .filter(Objects::nonNull) .findFirst(); if (result.isPresent()) {