Skip to content

Commit

Permalink
- added player trail check
Browse files Browse the repository at this point in the history
  • Loading branch information
Meloweh committed Dec 2, 2021
1 parent 73c6795 commit f652734
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 21 deletions.
40 changes: 25 additions & 15 deletions src/main/java/baritone/process/BuilderProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import baritone.Baritone;
import baritone.altoclef.AltoClefSettings;
import baritone.api.BaritoneAPI;
import baritone.api.behavior.IPathingBehavior;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.pathing.movement.IMovement;
import baritone.api.pathing.path.IPathExecutor;
import baritone.api.process.IBuilderProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
Expand All @@ -36,13 +39,12 @@
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.behavior.PathingBehavior;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.NotificationHelper;
import baritone.utils.PathingCommandContext;
import baritone.pathing.path.PathExecutor;
import baritone.utils.*;
import baritone.utils.schematic.MapArtSchematic;
import baritone.utils.schematic.SchematicSystem;
import baritone.utils.schematic.schematica.SchematicaHelper;
Expand Down Expand Up @@ -96,6 +98,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
private long recalcCounter = 0;
private boolean pausedBecauseOfMissingMaterials = false;
private final Map<BlockState, Integer> protectedItems = new HashMap<>();
private Snake snake;

public BuilderProcess(Baritone baritone) {
super(baritone);
Expand Down Expand Up @@ -150,10 +153,10 @@ private void protectItemOfMissing() {
protectedItems.putAll(missing);
protectedItems.keySet().forEach(e -> {
if (!Baritone.getAltoClefSettings().isItemProtected(e.getBlock().asItem())) {
System.out.println(Baritone.getAltoClefSettings().getProtectedItems().size());
System.out.println("SET PROTECTION ");
//System.out.println(Baritone.getAltoClefSettings().getProtectedItems().size());
//System.out.println("SET PROTECTION ");
Baritone.getAltoClefSettings().protectItem(e.getBlock().asItem());
System.out.println(Baritone.getAltoClefSettings().getProtectedItems().size());
//System.out.println(Baritone.getAltoClefSettings().getProtectedItems().size());
}
});

Expand Down Expand Up @@ -658,7 +661,7 @@ public void noteInsert(final BlockPos pos) {
info.counter++;
info.brokenPreviously = false;
}
System.out.println("insert " + pos.getX() + " " + pos.getY() + " " + pos.getZ() + " c: " + getHistoryCount(pos));
//System.out.println("insert " + pos.getX() + " " + pos.getY() + " " + pos.getZ() + " c: " + getHistoryCount(pos));
} else {
blockBreakHistory.put(pos, new HistoryInfo());
}
Expand All @@ -676,6 +679,13 @@ private long getHistoryCount(final BlockPos pos) {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

protectItemOfMissing();
//if (!Baritone.getAltoClefSettings().isItemProtected(Items.DIRT))
//Baritone.getAltoClefSettings().protectItem(Items.DIRT);
Expand All @@ -688,7 +698,7 @@ public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
}
baritone.getInputOverrideHandler().clearAllKeys();
if (paused) {
System.out.println("a0");
//System.out.println("a0");
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
if (Baritone.settings().buildInLayers.value) {
Expand Down Expand Up @@ -770,7 +780,7 @@ public int lengthZ() {
layer = 0;
origin = new BlockPos(origin).offset(repeat);
logDirect("Repeating build in vector " + repeat + ", new origin is " + origin);
System.out.println("a3");
//System.out.println("a3");
return onTick(calcFailed, isSafeToCancel);
}

Expand Down Expand Up @@ -821,7 +831,7 @@ public int lengthZ() {
noteRemoval(pos);
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true);
}
System.out.println("a");
//System.out.println("a");
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
List<BlockState> desirableOnHotbar = new ArrayList<>();
Expand All @@ -836,7 +846,7 @@ public int lengthZ() {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
}
//System.out.println("goal");
System.out.println("b");
//System.out.println("b");
stopProtectItemOfMissing();
return new PathingCommand(null, PathingCommandType.CANCEL_AND_SET_GOAL);
}
Expand All @@ -860,7 +870,7 @@ public int lengthZ() {
for (BlockState desired : noValidHotbarOption) {
if (valid(approxPlaceable.get(i), desired, true)) {
baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
System.out.println("c");
//System.out.println("c");
break outer;
}
}
Expand All @@ -881,7 +891,7 @@ public int lengthZ() {
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
}
}
System.out.println("big goal");
//System.out.println("big goal");
return new PathingCommandContext(goal, PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH, bcc);
}

Expand Down Expand Up @@ -1035,7 +1045,7 @@ private Goal assemble(BuilderCalculationContext bcc, List<BlockState> approxPlac
if (toBreak.isEmpty()) {
if (!missing.isEmpty()) {
this.pausedBecauseOfMissingMaterials = true;
System.out.println("prot called");
//System.out.println("prot called");
protectItemOfMissing();
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/baritone/process/CustomGoalProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import baritone.api.process.PathingCommandType;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.NotificationHelper;
import baritone.utils.Snake;

/**
* As set by ExampleBaritoneControl or something idk
Expand All @@ -44,6 +45,8 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC
*/
private State state;

private Snake snake;

public CustomGoalProcess(Baritone baritone) {
super(baritone);
}
Expand Down Expand Up @@ -76,6 +79,13 @@ public boolean isActive() {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

switch (this.state) {
case GOAL_SET:
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/baritone/process/ExploreProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package baritone.process;

import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.cache.ICachedWorld;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalComposite;
Expand All @@ -30,6 +31,7 @@
import baritone.cache.CachedWorld;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.NotificationHelper;
import baritone.utils.Snake;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
Expand All @@ -42,12 +44,10 @@
import net.minecraft.world.level.ChunkPos;

public final class ExploreProcess extends BaritoneProcessHelper implements IExploreProcess {

private BlockPos explorationOrigin;

private IChunkFilter filter;

private int distanceCompleted;
private Snake snake;

public ExploreProcess(Baritone baritone) {
super(baritone);
Expand Down Expand Up @@ -81,6 +81,13 @@ public IChunkFilter calcFilter() {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

if (calcFailed) {
logDirect("Failed");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnExploreFinished.value) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/baritone/process/FarmProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private boolean isNetherWart(ItemStack stack) {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
//VectorPrinter.print(this.getClass().descriptorString());
ArrayList<Block> scan = new ArrayList<>();
for (Harvest harvest : Harvest.values()) {
scan.add(harvest.block);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/baritone/process/FollowProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import baritone.utils.Snake;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;

Expand All @@ -41,13 +43,21 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo

private Predicate<Entity> filter;
private List<Entity> cache;
private Snake snake;

public FollowProcess(Baritone baritone) {
super(baritone);
}

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

scanWorld();
Goal goal = new GoalComposite(cache.stream().map(this::towards).toArray(Goal[]::new));
return new PathingCommand(goal, PathingCommandType.REVALIDATE_GOAL_AND_PATH);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/baritone/process/GetToBlockProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import java.util.*;

import baritone.utils.Snake;
import net.minecraft.core.BlockPos;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.level.block.Block;
Expand All @@ -45,6 +47,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG

private int tickCount = 0;
private int arrivalTickCount = 0;
private Snake snake;

public GetToBlockProcess(Baritone baritone) {
super(baritone);
Expand All @@ -67,6 +70,13 @@ public boolean isActive() {

@Override
public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

if (knownLocations == null) {
rescan(new ArrayList<>(), new CalculationContext(baritone));
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/baritone/process/MineProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import baritone.cache.WorldScanner;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface;
import baritone.utils.NotificationHelper;
import baritone.utils.*;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -63,6 +61,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
private GoalRunAway branchPointRunaway;
private int desiredQuantity;
private int tickCount;
private Snake snake;

public MineProcess(Baritone baritone) {
super(baritone);
Expand All @@ -75,6 +74,13 @@ public boolean isActive() {

@Override
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (snake == null) snake = new Snake();
snake.tick();
if (snake.passedLimits() && snake.getRunAwayCommand() != null) {
return snake.getRunAwayCommand();
}
snake.printCurrent();

if (desiredQuantity > 0) {
int curr = ctx.player().getInventory().items.stream()
.filter(stack -> filter.has(stack))
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/baritone/utils/RandomSpotNearby.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package baritone.utils;

import baritone.api.utils.BetterBlockPos;

import java.util.Random;

public class RandomSpotNearby {
private BetterBlockPos end;
private final Random rand;
private double r;
private double old_r;

public RandomSpotNearby(final double r) {
this.rand = new Random();
this.r = r;
this.old_r = r;
}

private final double MAX_DIST_INCREASE() {
return old_r * 2;
}

private BetterBlockPos calc(final BetterBlockPos start) {
final double phi = rand.nextInt(360) + rand.nextDouble();
final double radius = rand.nextInt((int) Math.round(r)) + rand.nextDouble(); //rand.nextDouble(r) + rand.nextDouble();
final int x = (int) Math.round(radius * Math.sin(phi));
final int z = (int) Math.round(radius * Math.cos(phi));

this.end = new BetterBlockPos(start.getX() + x, start.getY(), start.getZ() + z);
return this.end;
}

public BetterBlockPos next(final BetterBlockPos start) {
this.r = (this.r - this.old_r > MAX_DIST_INCREASE()) ? this.old_r : this.r;
return next(start, 0.3d);
}

public BetterBlockPos next(final BetterBlockPos start, final double increaseRadius) {
this.r += increaseRadius;
return calc(start);
}
}
Loading

0 comments on commit f652734

Please sign in to comment.