mirror of https://github.com/cabaletta/baritone
54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
/*
|
|
* 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.pathing;
|
|
|
|
import baritone.Baritone;
|
|
import baritone.api.pathing.calc.IPath;
|
|
import baritone.api.utils.BetterBlockPos;
|
|
import baritone.api.utils.IPlayerContext;
|
|
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
|
|
|
|
public final class Favoring {
|
|
private final Long2DoubleOpenHashMap favorings;
|
|
|
|
public Favoring(IPlayerContext ctx, IPath previous) {
|
|
this(previous);
|
|
for (Avoidance avoid : Avoidance.create(ctx)) {
|
|
avoid.applySpherical(favorings);
|
|
}
|
|
System.out.println("Favoring size: " + favorings.size());
|
|
}
|
|
|
|
public Favoring(IPath previous) { // create one just from previous path, no mob avoidances
|
|
favorings = new Long2DoubleOpenHashMap();
|
|
favorings.defaultReturnValue(1.0D);
|
|
double coeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
|
|
if (coeff != 1D && previous != null) {
|
|
previous.positions().forEach(pos -> favorings.put(BetterBlockPos.longHash(pos), coeff));
|
|
}
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return favorings.isEmpty();
|
|
}
|
|
|
|
public double calculate(long hash) {
|
|
return favorings.get(hash);
|
|
}
|
|
}
|