Merge branch 'master' into builder
This commit is contained in:
@@ -80,7 +80,7 @@ public class InventoryBehavior extends Behavior {
|
||||
continue;
|
||||
}
|
||||
if (klass.isInstance(stack.getItem())) {
|
||||
double speed = ToolSet.calculateStrVsBlock(stack, against.getDefaultState()); // takes into account enchants
|
||||
double speed = ToolSet.calculateSpeedVsBlock(stack, against.getDefaultState()); // takes into account enchants
|
||||
if (speed > bestSpeed) {
|
||||
bestSpeed = speed;
|
||||
bestInd = i;
|
||||
|
||||
@@ -21,6 +21,7 @@ import baritone.Baritone;
|
||||
import baritone.api.event.events.BlockInteractEvent;
|
||||
import baritone.api.event.events.PacketEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.event.events.type.EventState;
|
||||
import baritone.cache.ContainerMemory;
|
||||
import baritone.cache.Waypoint;
|
||||
@@ -47,6 +48,8 @@ import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* doesn't work for horse inventories :^)
|
||||
*
|
||||
* @author Brady
|
||||
* @since 8/6/2018
|
||||
*/
|
||||
@@ -60,6 +63,14 @@ public final class MemoryBehavior extends Behavior {
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
enderChestWindowId = null;
|
||||
futureInventories.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||
if (event.getState() == EventState.PRE) {
|
||||
@@ -98,7 +109,6 @@ public final class MemoryBehavior extends Behavior {
|
||||
}
|
||||
|
||||
if (p instanceof CPacketCloseWindow) {
|
||||
updateInventory();
|
||||
getCurrent().save();
|
||||
}
|
||||
}
|
||||
@@ -133,7 +143,6 @@ public final class MemoryBehavior extends Behavior {
|
||||
}
|
||||
|
||||
if (p instanceof SPacketCloseWindow) {
|
||||
updateInventory();
|
||||
getCurrent().save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.event.events.PathEvent;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.event.events.*;
|
||||
import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
@@ -101,6 +98,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
dispatchEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerSprintState(SprintStateEvent event) {
|
||||
if (current != null) {
|
||||
event.setState(current.isSprinting());
|
||||
}
|
||||
}
|
||||
|
||||
private void tickPath() {
|
||||
if (pauseRequestedLastTick && safeToCancel) {
|
||||
pauseRequestedLastTick = false;
|
||||
|
||||
@@ -121,6 +121,11 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
listeners.forEach(l -> l.onPlayerRotationMove(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerSprintState(SprintStateEvent event) {
|
||||
listeners.forEach(l -> l.onPlayerSprintState(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockInteract(BlockInteractEvent event) {
|
||||
listeners.forEach(l -> l.onBlockInteract(event));
|
||||
|
||||
@@ -79,6 +79,8 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
private PathingBehavior behavior;
|
||||
private IPlayerContext ctx;
|
||||
|
||||
private boolean sprintNextTick;
|
||||
|
||||
public PathExecutor(PathingBehavior behavior, IPath path) {
|
||||
this.behavior = behavior;
|
||||
this.ctx = behavior.ctx;
|
||||
@@ -269,7 +271,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
onTick();
|
||||
return true;
|
||||
} else {
|
||||
sprintIfRequested();
|
||||
sprintNextTick = shouldSprintNextTick();
|
||||
ticksOnCurrent++;
|
||||
if (ticksOnCurrent > currentMovementOriginalCostEstimate + Baritone.settings().movementTimeoutTicks.get()) {
|
||||
// only cancel if the total time has exceeded the initial estimate
|
||||
@@ -371,21 +373,17 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sprintIfRequested() {
|
||||
private boolean shouldSprintNextTick() {
|
||||
// first and foremost, if allowSprint is off, or if we don't have enough hunger, don't try and sprint
|
||||
if (!new CalculationContext(behavior.baritone).canSprint) {
|
||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
||||
ctx.player().setSprinting(false);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// if the movement requested sprinting, then we're done
|
||||
if (behavior.baritone.getInputOverrideHandler().isInputForcedDown(Input.SPRINT)) {
|
||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.SPRINT, false);
|
||||
if (!ctx.player().isSprinting()) {
|
||||
ctx.player().setSprinting(true);
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// we'll take it from here, no need for minecraft to see we're holding down control and sprint for us
|
||||
@@ -397,30 +395,23 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
|
||||
if (((MovementDescend) current).safeMode()) {
|
||||
logDebug("Sprinting would be unsafe");
|
||||
ctx.player().setSprinting(false);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
IMovement next = path.movements().get(pathPosition + 1);
|
||||
if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) {
|
||||
// a descend then an ascend in the same direction
|
||||
if (!ctx.player().isSprinting()) {
|
||||
ctx.player().setSprinting(true);
|
||||
}
|
||||
pathPosition++;
|
||||
// okay to skip clearKeys and / or onChangeInPathPosition here since this isn't possible to repeat, since it's asymmetric
|
||||
logDebug("Skipping descend to straight ascend");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (canSprintInto(ctx, current, next)) {
|
||||
if (ctx.playerFeet().equals(current.getDest())) {
|
||||
pathPosition++;
|
||||
onChangeInPathPosition();
|
||||
}
|
||||
if (!ctx.player().isSprinting()) {
|
||||
ctx.player().setSprinting(true);
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
//logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection()));
|
||||
}
|
||||
@@ -430,14 +421,11 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
BlockPos center = current.getSrc().up();
|
||||
if (ctx.player().posY >= center.getY()) { // playerFeet adds 0.1251 to account for soul sand
|
||||
behavior.baritone.getInputOverrideHandler().setInputForceState(Input.JUMP, false);
|
||||
if (!ctx.player().isSprinting()) {
|
||||
ctx.player().setSprinting(true);
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.player().setSprinting(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean canSprintInto(IPlayerContext ctx, IMovement current, IMovement next) {
|
||||
@@ -532,4 +520,8 @@ public class PathExecutor implements IPathExecutor, Helper {
|
||||
public Set<BlockPos> toWalkInto() {
|
||||
return Collections.unmodifiableSet(toWalkInto);
|
||||
}
|
||||
|
||||
public boolean isSprinting() {
|
||||
return sprintNextTick;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,15 @@ import net.minecraft.world.GameType;
|
||||
import net.minecraft.world.WorldSettings;
|
||||
import net.minecraft.world.WorldType;
|
||||
|
||||
/**
|
||||
* Responsible for automatically testing Baritone's pathing algorithm by automatically creating a world with a specific
|
||||
* seed, setting a specified goal, and only allowing a certain amount of ticks to pass before the pathing test is
|
||||
* considered a failure. In order to test locally, docker may be used, or through an IDE: Create a run config which runs
|
||||
* in a separate directory from the primary one (./run), and set the enrivonmental variable {@code BARITONE_AUTO_TEST}
|
||||
* to {@code true}.
|
||||
*
|
||||
* @author leijurv, Brady
|
||||
*/
|
||||
public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
|
||||
|
||||
public static final BaritoneAutoTest INSTANCE = new BaritoneAutoTest();
|
||||
|
||||
@@ -23,16 +23,10 @@ import baritone.api.utils.IPlayerContext;
|
||||
|
||||
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
||||
|
||||
public static final double DEFAULT_PRIORITY = 0;
|
||||
|
||||
protected final Baritone baritone;
|
||||
protected final IPlayerContext ctx;
|
||||
private final double priority;
|
||||
|
||||
public BaritoneProcessHelper(Baritone baritone) {
|
||||
this(baritone, DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
public BaritoneProcessHelper(Baritone baritone, double priority) {
|
||||
this.baritone = baritone;
|
||||
this.ctx = baritone.getPlayerContext();
|
||||
@@ -40,11 +34,6 @@ public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper
|
||||
baritone.getPathingControlManager().registerProcess(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Baritone associatedWith() {
|
||||
return baritone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return false;
|
||||
|
||||
@@ -103,7 +103,7 @@ public class ToolSet {
|
||||
IBlockState blockState = b.getDefaultState();
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = player.inventory.getStackInSlot(i);
|
||||
double v = calculateStrVsBlock(itemStack, blockState);
|
||||
double v = calculateSpeedVsBlock(itemStack, blockState);
|
||||
if (v > value) {
|
||||
value = v;
|
||||
best = i;
|
||||
@@ -128,7 +128,7 @@ public class ToolSet {
|
||||
*/
|
||||
private double getBestDestructionTime(Block b) {
|
||||
ItemStack stack = player.inventory.getStackInSlot(getBestSlot(b));
|
||||
return calculateStrVsBlock(stack, b.getDefaultState());
|
||||
return calculateSpeedVsBlock(stack, b.getDefaultState());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,7 +138,7 @@ public class ToolSet {
|
||||
* @param state the blockstate to be mined
|
||||
* @return how long it would take in ticks
|
||||
*/
|
||||
public static double calculateStrVsBlock(ItemStack item, IBlockState state) {
|
||||
public static double calculateSpeedVsBlock(ItemStack item, IBlockState state) {
|
||||
float hardness = state.getBlockHardness(null, null);
|
||||
if (hardness < 0) {
|
||||
return -1;
|
||||
@@ -154,11 +154,10 @@ public class ToolSet {
|
||||
|
||||
speed /= hardness;
|
||||
if (state.getMaterial().isToolNotRequired() || (!item.isEmpty() && item.canHarvestBlock(state))) {
|
||||
speed /= 30;
|
||||
return speed / 30;
|
||||
} else {
|
||||
speed /= 100;
|
||||
return speed / 100;
|
||||
}
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IPlayerContext} that provides information about the local player.
|
||||
* Implementation of {@link IPlayerContext} that provides information about the primary player.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 11/12/2018
|
||||
|
||||
@@ -27,6 +27,8 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.GameType;
|
||||
|
||||
/**
|
||||
* Implementation of {@link IPlayerController} that chains to the primary player controller's methods
|
||||
*
|
||||
* @author Brady
|
||||
* @since 12/14/2018
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user