Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| efa7fec3ae | |||
| a73f2ccbd9 | |||
| 136f175b12 | |||
| 0515a34b63 | |||
| 392ca87a66 | |||
| c7260580d5 | |||
| f5d49af0a1 | |||
| 5d300244ea | |||
| 2b27d3e03d | |||
| bddc598e88 | |||
| d3f677d82d | |||
| a00255d4b0 | |||
| b77e7651e7 | |||
| 88b8b88474 | |||
| dc010b07a2 | |||
| bd084ee100 | |||
| 866a704100 | |||
| 0e228149f6 | |||
| ad254f9364 | |||
| 94fd115734 | |||
| 5d148e56e6 | |||
| 90a388f04c | |||
| 2024f31def | |||
| ec063cc955 | |||
| 12f6f1e846 | |||
| 0f94b958bc | |||
| 9753b3e3ba | |||
| c0e4061c45 | |||
| 386dbf84dd | |||
| 8df51839d1 | |||
| c2671c38b0 | |||
| f553078672 | |||
| 61aac18212 | |||
| 78ba6a7aae | |||
| 71c0e5c36f | |||
| 4a800dc3ee | |||
| b38d2c9680 | |||
| 24a3034514 | |||
| 90e41977a7 | |||
| f57899838a | |||
| 09c8799eb4 | |||
| a776cabb24 | |||
| c268e0523f | |||
| 24a8435c61 | |||
| 0105b5046e | |||
| ea75b6f0b9 | |||
| 73b4b09b67 | |||
| 3973a2eb4e | |||
| 5a0f23c150 | |||
| b51760360a | |||
| d4a4de62ba | |||
| da0c0fd0d0 | |||
| 886a60ae61 | |||
| fef0182991 | |||
| 0309de04ef | |||
| 2afd0ddc03 | |||
| eddbb9eba2 | |||
| 05a5d89376 | |||
| 953414933b | |||
| 5256f2a6a4 | |||
| 12fa664052 | |||
| d63f8d9f83 |
@@ -155,6 +155,9 @@ dependencies {
|
||||
}
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.12'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.12'
|
||||
}
|
||||
|
||||
mixin {
|
||||
|
||||
@@ -830,6 +830,13 @@ public final class Settings {
|
||||
*/
|
||||
public final Setting<Boolean> mineScanDroppedItems = new Setting<>(true);
|
||||
|
||||
// Hyritone start
|
||||
/**
|
||||
* Detect ore locations with a separate world seed.
|
||||
*/
|
||||
public final Setting<Boolean> mineWithSeed = new Setting<>(false);
|
||||
// Hyritone end
|
||||
|
||||
/**
|
||||
* While mining, wait this number of milliseconds after mining an ore to see if it will drop an item
|
||||
* instead of immediately going onto the next one
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.api.event.listener;
|
||||
|
||||
import baritone.api.event.events.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* An implementation of {@link IGameEventListener} that has all methods
|
||||
@@ -71,4 +72,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
||||
|
||||
@Override
|
||||
default void onPathEvent(PathEvent event) {}
|
||||
|
||||
@Override
|
||||
default void onBlockBreak(BlockPos pos) {}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ package baritone.api.event.listener;
|
||||
import baritone.api.event.events.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.screen.DeathScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@@ -137,4 +137,11 @@ public interface IGameEventListener {
|
||||
* @param event The event
|
||||
*/
|
||||
void onPathEvent(PathEvent event);
|
||||
|
||||
/**
|
||||
* This is called when the player breaks blocks.
|
||||
*
|
||||
* @param pos Block position
|
||||
*/
|
||||
void onBlockBreak(BlockPos pos);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ public class LaunchTesting {
|
||||
attemptLogin(arguments, System.getenv("username"), System.getenv("password"));
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
arguments.put("username", "TestUser");
|
||||
|
||||
List<String> argsArray = new ArrayList<>();
|
||||
arguments.forEach((k, v) -> {
|
||||
argsArray.add("--" + k);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.launch.mixins;
|
||||
|
||||
import baritone.utils.accessor.IMouse;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.MouseHelper;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static org.hydev.hyritone.utils.MiscUtils.sleep;
|
||||
|
||||
/**
|
||||
* Mixin to control mouse operations
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-21!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-21 13:54
|
||||
*/
|
||||
@Mixin(MouseHelper.class)
|
||||
public abstract class MixinMouse implements IMouse
|
||||
{
|
||||
@Shadow
|
||||
protected abstract void mouseButtonCallback(long window, int button, int action, int mods);
|
||||
|
||||
@Shadow @Final private Minecraft minecraft;
|
||||
|
||||
@Inject(method = "mouseButtonCallback", at = @At("HEAD"), cancellable = true)
|
||||
private void inject(long window, int button, int action, int mods, CallbackInfo info)
|
||||
{
|
||||
System.out.println(window + " | " + button + " | " + action + " | " + mods + " | " + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void rightClick()
|
||||
{
|
||||
new Thread(() ->
|
||||
{
|
||||
rightHold();
|
||||
sleep((long) (70 + Math.random() * 10));
|
||||
rightRelease();
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void leftClick()
|
||||
{
|
||||
new Thread(() ->
|
||||
{
|
||||
leftHold();
|
||||
sleep((long) (70 + Math.random() * 10));
|
||||
leftRelease();
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rightHold()
|
||||
{
|
||||
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 1, 1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rightRelease()
|
||||
{
|
||||
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 1, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leftHold()
|
||||
{
|
||||
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 0, 1, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leftRelease()
|
||||
{
|
||||
mouseButtonCallback(minecraft.getMainWindow().getHandle(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -17,16 +17,28 @@
|
||||
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.utils.accessor.IPlayerControllerMP;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.PlayerController;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(PlayerController.class)
|
||||
public abstract class MixinPlayerController implements IPlayerControllerMP {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft mc;
|
||||
|
||||
@Accessor
|
||||
@Override
|
||||
public abstract void setIsHittingBlock(boolean isHittingBlock);
|
||||
@@ -38,4 +50,20 @@ public abstract class MixinPlayerController implements IPlayerControllerMP {
|
||||
@Invoker
|
||||
@Override
|
||||
public abstract void callSyncCurrentPlayItem();
|
||||
|
||||
@Inject(
|
||||
method = "onPlayerDestroyBlock",
|
||||
at = @At(value = "TAIL")
|
||||
)
|
||||
public void onPlayerDestroyBlock(BlockPos pos, CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
// Check if the block is broken
|
||||
if (!cir.getReturnValue()) return;
|
||||
|
||||
// Call event
|
||||
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(this.mc.player);
|
||||
if (baritone != null) {
|
||||
baritone.getGameEventHandler().onBlockBreak(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import baritone.utils.*;
|
||||
import baritone.command.manager.CommandManager;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.hydev.hyritone.Hyritone;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -87,6 +88,8 @@ public class Baritone implements IBaritone {
|
||||
|
||||
public BlockStateInterface bsi;
|
||||
|
||||
public Hyritone hyritone;
|
||||
|
||||
Baritone() {
|
||||
this.gameEventHandler = new GameEventHandler(this);
|
||||
|
||||
@@ -121,6 +124,9 @@ public class Baritone implements IBaritone {
|
||||
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
||||
this.gameEventHandler.registerEventListener(BaritoneAutoTest.INSTANCE);
|
||||
}
|
||||
|
||||
// Hyritone
|
||||
this.hyritone = new Hyritone(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.command.defaults;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.ICommand;
|
||||
import org.hydev.hyritone.seedxray.SeedXrayCommand;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -64,7 +65,10 @@ public final class DefaultCommands {
|
||||
new WaypointsCommand(baritone),
|
||||
new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"),
|
||||
new CommandAlias(baritone, "home", "Set goal to your home waypoint", "waypoints goal home"),
|
||||
new SelCommand(baritone)
|
||||
new SelCommand(baritone),
|
||||
|
||||
// Hyritone
|
||||
new SeedXrayCommand(baritone)
|
||||
));
|
||||
ExecutionControlCommands prc = new ExecutionControlCommands(baritone);
|
||||
commands.add(prc.pauseCommand);
|
||||
|
||||
@@ -25,6 +25,7 @@ import baritone.api.event.listener.IGameEventListener;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.cache.WorldProvider;
|
||||
import baritone.utils.BlockStateInterface;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
@@ -161,4 +162,9 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
public final void registerEventListener(IGameEventListener listener) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
||||
public final void onBlockBreak(BlockPos blockPos)
|
||||
{
|
||||
listeners.forEach(l -> l.onBlockBreak(blockPos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,11 +36,13 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.hydev.hyritone.Hyritone;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static baritone.Baritone.settings;
|
||||
import static baritone.api.pathing.movement.ActionCosts.COST_INF;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
/**
|
||||
* Mine blocks of a certain type
|
||||
@@ -83,7 +85,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
}
|
||||
if (calcFailed) {
|
||||
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
|
||||
if (!knownOreLocations.isEmpty() && settings().blacklistClosestOnFailure.value) {
|
||||
logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...");
|
||||
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)).ifPresent(blacklist::add);
|
||||
knownOreLocations.removeIf(blacklist::contains);
|
||||
@@ -93,19 +95,19 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!Baritone.settings().allowBreak.value) {
|
||||
if (!settings().allowBreak.value) {
|
||||
logDirect("Unable to mine when allowBreak is false!");
|
||||
cancel();
|
||||
return null;
|
||||
}
|
||||
updateLoucaSystem();
|
||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
|
||||
int mineGoalUpdateInterval = settings().mineGoalUpdateInterval.value;
|
||||
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
|
||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||
CalculationContext context = new CalculationContext(baritone, true);
|
||||
Baritone.getExecutor().execute(() -> rescan(curr, context));
|
||||
}
|
||||
if (Baritone.settings().legitMine.value) {
|
||||
if (settings().legitMine.value) {
|
||||
addNearby();
|
||||
}
|
||||
Optional<BlockPos> shaft = curr.stream()
|
||||
@@ -144,7 +146,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
Map<BlockPos, Long> copy = new HashMap<>(anticipatedDrops);
|
||||
ctx.getSelectedBlock().ifPresent(pos -> {
|
||||
if (knownOreLocations.contains(pos)) {
|
||||
copy.put(pos, System.currentTimeMillis() + Baritone.settings().mineDropLoiterDurationMSThanksLouca.value);
|
||||
copy.put(pos, System.currentTimeMillis() + settings().mineDropLoiterDurationMSThanksLouca.value);
|
||||
}
|
||||
});
|
||||
// elaborate dance to avoid concurrentmodificationexcepption since rescan thread reads this
|
||||
@@ -168,7 +170,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
|
||||
private PathingCommand updateGoal() {
|
||||
boolean legit = Baritone.settings().legitMine.value;
|
||||
boolean legit = settings().legitMine.value;
|
||||
List<BlockPos> locs = knownOreLocations;
|
||||
if (!locs.isEmpty()) {
|
||||
CalculationContext context = new CalculationContext(baritone);
|
||||
@@ -183,7 +185,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return null;
|
||||
}
|
||||
// only in non-Xray mode (aka legit mode) do we do this
|
||||
int y = Baritone.settings().legitMineYLevel.value;
|
||||
int y = settings().legitMineYLevel.value;
|
||||
if (branchPoint == null) {
|
||||
/*if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
|
||||
// cool, path is over and we are at desired y
|
||||
@@ -211,7 +213,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
if (filter == null) {
|
||||
return;
|
||||
}
|
||||
if (Baritone.settings().legitMine.value) {
|
||||
if (settings().legitMine.value) {
|
||||
return;
|
||||
}
|
||||
List<BlockPos> dropped = droppedItemsScan();
|
||||
@@ -231,7 +233,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
return true;
|
||||
}
|
||||
BlockState state = context.bsi.get0(pos);
|
||||
if (Baritone.settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) {
|
||||
if (settings().internalMiningAirException.value && state.getBlock() instanceof AirBlock) {
|
||||
return true;
|
||||
}
|
||||
return filter.has(state) && plausibleToBreak(context, pos);
|
||||
@@ -239,7 +241,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
|
||||
private Goal coalesce(BlockPos loc, List<BlockPos> locs, CalculationContext context) {
|
||||
boolean assumeVerticalShaftMine = !(baritone.bsi.get0(loc.up()).getBlock() instanceof FallingBlock);
|
||||
if (!Baritone.settings().forceInternalMining.value) {
|
||||
if (!settings().forceInternalMining.value) {
|
||||
if (assumeVerticalShaftMine) {
|
||||
// we can get directly below the block
|
||||
return new GoalThreeBlocks(loc);
|
||||
@@ -300,7 +302,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
}
|
||||
|
||||
public List<BlockPos> droppedItemsScan() {
|
||||
if (!Baritone.settings().mineScanDroppedItems.value) {
|
||||
if (!settings().mineScanDroppedItems.value) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<BlockPos> ret = new ArrayList<>();
|
||||
@@ -319,39 +321,52 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
public static List<BlockPos> searchWorld(CalculationContext ctx, BlockOptionalMetaLookup filter, int max, List<BlockPos> alreadyKnown, List<BlockPos> blacklist, List<BlockPos> dropped) {
|
||||
List<BlockPos> locs = new ArrayList<>();
|
||||
List<Block> untracked = new ArrayList<>();
|
||||
for (BlockOptionalMeta bom : filter.blocks()) {
|
||||
Block block = bom.getBlock();
|
||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
||||
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
|
||||
|
||||
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(
|
||||
// Check mine with seed
|
||||
if (!settings().mineWithSeed.value)
|
||||
{
|
||||
// Search the actual world
|
||||
for (BlockOptionalMeta bom : filter.blocks()) {
|
||||
Block block = bom.getBlock();
|
||||
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
|
||||
BetterBlockPos pf = ctx.baritone.getPlayerContext().playerFeet();
|
||||
|
||||
// maxRegionDistanceSq 2 means adjacent directly or adjacent diagonally; nothing further than that
|
||||
locs.addAll(ctx.worldData.getCachedWorld().getLocationsOf(
|
||||
BlockUtils.blockToString(block),
|
||||
Baritone.settings().maxCachedWorldScanCount.value,
|
||||
settings().maxCachedWorldScanCount.value,
|
||||
pf.x,
|
||||
pf.z,
|
||||
2
|
||||
));
|
||||
} else {
|
||||
untracked.add(block);
|
||||
));
|
||||
} else {
|
||||
untracked.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
locs = prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
locs = prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
|
||||
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
|
||||
if (!untracked.isEmpty() || (settings().extendCacheOnThreshold.value && locs.size() < max)) {
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
|
||||
ctx.getBaritone().getPlayerContext(),
|
||||
filter,
|
||||
max,
|
||||
10,
|
||||
32
|
||||
)); // maxSearchRadius is NOT sq
|
||||
)); // maxSearchRadius is NOT sq
|
||||
}
|
||||
|
||||
locs.addAll(alreadyKnown);
|
||||
locs = prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add seed ores
|
||||
locs.addAll(Hyritone.seedServerCache.cacheBlocks);
|
||||
locs = prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
}
|
||||
|
||||
locs.addAll(alreadyKnown);
|
||||
|
||||
return prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
return locs;
|
||||
}
|
||||
|
||||
private void addNearby() {
|
||||
@@ -368,7 +383,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
// is an x-ray and it'll get caught
|
||||
if (filter.has(bsi.get0(x, y, z))) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
|
||||
if ((settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
|
||||
knownOreLocations.add(pos);
|
||||
}
|
||||
}
|
||||
@@ -392,7 +407,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
.distinct()
|
||||
|
||||
// remove any that are within loaded chunks that aren't actually what we want
|
||||
.filter(pos -> !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
|
||||
.filter(pos -> settings().mineWithSeed.value || !ctx.bsi.worldContainsLoadedChunk(pos.getX(), pos.getZ()) || filter.has(ctx.get(pos.getX(), pos.getY(), pos.getZ())) || dropped.contains(pos))
|
||||
|
||||
// Hyritone: remove air
|
||||
.filter(pos -> !settings().mineWithSeed.value || !ctx.get(pos).isAir() || dropped.contains(pos))
|
||||
|
||||
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
||||
.filter(pos -> MineProcess.plausibleToBreak(ctx, pos))
|
||||
@@ -400,7 +418,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
.filter(pos -> !blacklist.contains(pos))
|
||||
|
||||
.sorted(Comparator.comparingDouble(new BlockPos(ctx.getBaritone().getPlayerContext().player())::distanceSq))
|
||||
.collect(Collectors.toList());
|
||||
.collect(toList());
|
||||
|
||||
if (locs.size() > max) {
|
||||
return locs.subList(0, max);
|
||||
@@ -425,11 +443,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
@Override
|
||||
public void mine(int quantity, BlockOptionalMetaLookup filter) {
|
||||
this.filter = filter;
|
||||
if (filter != null && !Baritone.settings().allowBreak.value) {
|
||||
|
||||
// Hyritone start - #1: Users are not idiots, if they disabled allow break, it's not for mining.
|
||||
/*if (filter != null && !Baritone.settings().allowBreak.value) {
|
||||
logDirect("Unable to mine when allowBreak is false!");
|
||||
this.mine(quantity, (BlockOptionalMetaLookup) null);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
// Hyritone end
|
||||
|
||||
this.desiredQuantity = quantity;
|
||||
this.knownOreLocations = new ArrayList<>();
|
||||
this.blacklist = new ArrayList<>();
|
||||
|
||||
@@ -33,6 +33,9 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkSection;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import org.hydev.hyritone.Hyritone;
|
||||
|
||||
import static org.hydev.hyritone.utils.MiscUtils.posId;
|
||||
|
||||
/**
|
||||
* Wraps get for chuck caching capability
|
||||
@@ -98,6 +101,16 @@ public class BlockStateInterface {
|
||||
|
||||
public BlockState get0(int x, int y, int z) { // Mickey resigned
|
||||
|
||||
// Hyritone: Replace the block with seed block
|
||||
if (Baritone.settings().mineWithSeed.value)
|
||||
{
|
||||
String key = posId(new BlockPos(x, y, z));
|
||||
if (Hyritone.seedServerCache.blocksMap.containsKey(key))
|
||||
{
|
||||
return Hyritone.seedServerCache.blocksMap.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Invalid vertical position
|
||||
if (y < 0 || y >= 256) {
|
||||
return AIR;
|
||||
|
||||
@@ -36,7 +36,6 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
|
||||
@@ -224,7 +223,7 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
double minZ, maxZ;
|
||||
double minY, maxY;
|
||||
double y1, y2;
|
||||
double y = MathHelper.cos((float) (((float) ((System.nanoTime() / 100000L) % 20000L)) / 20000F * Math.PI * 2));
|
||||
double y = 1;
|
||||
if (goal instanceof IGoalRenderPos) {
|
||||
BlockPos goalPos = ((IGoalRenderPos) goal).getGoalPos();
|
||||
minX = goalPos.getX() + 0.002 - renderPosX;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.accessor;
|
||||
|
||||
/**
|
||||
* Duck interface for the mixin that controls mouse operations.
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-21!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-21 13:53
|
||||
*/
|
||||
public interface IMouse
|
||||
{
|
||||
void rightClick();
|
||||
void rightHold();
|
||||
void rightRelease();
|
||||
|
||||
void leftClick();
|
||||
void leftHold();
|
||||
void leftRelease();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 org.hydev.hyritone;
|
||||
|
||||
import baritone.Baritone;
|
||||
import org.hydev.hyritone.seedxray.SeedServerCache;
|
||||
|
||||
/**
|
||||
* TODO: Write a description for this class!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-19!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-19 13:42
|
||||
*/
|
||||
public class Hyritone
|
||||
{
|
||||
public static SeedServerCache seedServerCache;
|
||||
|
||||
public Hyritone(Baritone baritone)
|
||||
{
|
||||
seedServerCache = new SeedServerCache(baritone);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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 org.hydev.hyritone.seedxray;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.utils.PathRenderer;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static baritone.api.utils.Helper.mc;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.hydev.hyritone.utils.MiscUtils.debug;
|
||||
import static org.hydev.hyritone.utils.MiscUtils.posId;
|
||||
|
||||
/**
|
||||
* TODO: Write a description for this class!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-19!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-19 12:35
|
||||
*/
|
||||
public class SeedServerCache extends Behavior
|
||||
{
|
||||
public static CloseableHttpClient http = HttpClients.createDefault();
|
||||
|
||||
public BetterBlockPos cacheLocation;
|
||||
public List<BlockPos> cacheBlocks = new ArrayList<>();
|
||||
public Map<String, BlockState> blocksMap = new HashMap<>();
|
||||
|
||||
public boolean enabled = false;
|
||||
public String blockToFind = "diamond_ore";
|
||||
public boolean updating = false;
|
||||
|
||||
public int ticks = 100;
|
||||
|
||||
public SeedServerCache(Baritone baritone)
|
||||
{
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for updates every tick
|
||||
*
|
||||
* @param event Tick event
|
||||
*/
|
||||
@Override
|
||||
public void onTick(TickEvent event)
|
||||
{
|
||||
if (mc.player == null) return;
|
||||
if (updating || !enabled) return;
|
||||
|
||||
// Update cache every 5 seconds (5 * 20 = 100 ticks)
|
||||
ticks ++;
|
||||
|
||||
if (ticks > 100)
|
||||
{
|
||||
ticks = 0;
|
||||
new Thread(this::updateCache).start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update cached blocks
|
||||
*/
|
||||
public void updateCache()
|
||||
{
|
||||
// Prevent duplicate calls to update
|
||||
updating = true;
|
||||
|
||||
cacheLocation = new BetterBlockPos(mc.player.getPositionVec().x, mc.player.getPositionVec().y + 0.1251, mc.player.getPositionVec().z);
|
||||
|
||||
// Get request
|
||||
HttpGet get = new HttpGet("http://localhost:12255/api/get-locations-of");
|
||||
get.setHeader("world", "world");
|
||||
get.setHeader("block", blockToFind);
|
||||
get.setHeader("maximum", "64");
|
||||
get.setHeader("center-x", "" + cacheLocation.getX());
|
||||
get.setHeader("center-y", "" + cacheLocation.getY());
|
||||
get.setHeader("center-z", "" + cacheLocation.getZ());
|
||||
get.setHeader("max-search-rad", "64");
|
||||
get.setHeader("y-min", "3");
|
||||
get.setHeader("y-max", "16");
|
||||
|
||||
debug("==============================================");
|
||||
debug("Getting block data from seed exploit server...");
|
||||
|
||||
try (CloseableHttpResponse response = http.execute(get))
|
||||
{
|
||||
// Exited
|
||||
if (mc.world == null) return;
|
||||
|
||||
ArrayList<BlockPos> blocks = new ArrayList<>();
|
||||
JsonArray array = new JsonParser().parse(IOUtils.toString(response.getEntity().getContent(), UTF_8)).getAsJsonArray();
|
||||
array.forEach(j ->
|
||||
{
|
||||
JsonObject obj = j.getAsJsonObject();
|
||||
blocks.add(new BlockPos(obj.get("x").getAsInt(), obj.get("y").getAsInt(), obj.get("z").getAsInt()));
|
||||
});
|
||||
|
||||
// Only add it if it is not air in the client world
|
||||
cacheBlocks = blocks.stream().filter(b -> !mc.world.getBlockState(b).isAir()).collect(toList());
|
||||
|
||||
// Update blocks map
|
||||
Map<String, BlockState> map = new HashMap<>();
|
||||
cacheBlocks.forEach(b -> map.put(posId(b), Blocks.DIAMOND_ORE.getDefaultState()));
|
||||
blocksMap = map;
|
||||
|
||||
debug("Found " + cacheBlocks.size() + " valid ores.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
updating = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderPass(RenderEvent event)
|
||||
{
|
||||
if (!enabled) return;
|
||||
|
||||
// Render xray
|
||||
PathRenderer.drawManySelectionBoxes(event.getModelViewStack(), Helper.mc.getRenderViewEntity(), cacheBlocks, Color.cyan);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockPos pos)
|
||||
{
|
||||
// Remove block from list
|
||||
if (!cacheBlocks.removeIf(b -> posId(b).equals(posId(pos)))) return;
|
||||
|
||||
// Remove block from map
|
||||
blocksMap.remove(posId(pos));
|
||||
|
||||
// Remove block from server
|
||||
HttpGet get = new HttpGet("http://localhost:12255/api/remove-block");
|
||||
get.setHeader("world", "world");
|
||||
get.setHeader("x", "" + pos.getX());
|
||||
get.setHeader("y", "" + pos.getY());
|
||||
get.setHeader("z", "" + pos.getZ());
|
||||
|
||||
new Thread(() ->
|
||||
{
|
||||
try (CloseableHttpResponse response = http.execute(get))
|
||||
{
|
||||
System.out.println(IOUtils.toString(response.getEntity().getContent(), UTF_8));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 org.hydev.hyritone.seedxray;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.hydev.hyritone.Hyritone.seedServerCache;
|
||||
import static org.hydev.hyritone.utils.MiscUtils.print;
|
||||
|
||||
/**
|
||||
* TODO: Write a description for this class!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-19!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-19 12:29
|
||||
*/
|
||||
public class SeedXrayCommand extends Command
|
||||
{
|
||||
public SeedXrayCommand(IBaritone baritone) {
|
||||
super(baritone, "seedxray");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException
|
||||
{
|
||||
if (Baritone.settings().mineWithSeed.value = seedServerCache.enabled = !seedServerCache.enabled)
|
||||
{
|
||||
print("Seed xray enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
print("Seed xray disabled");
|
||||
|
||||
// Reset status
|
||||
seedServerCache.ticks = 100;
|
||||
seedServerCache.enabled = false;
|
||||
seedServerCache.blocksMap = new HashMap<>();
|
||||
seedServerCache.cacheLocation = null;
|
||||
seedServerCache.cacheBlocks = new ArrayList<>();
|
||||
seedServerCache.updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortDesc() {
|
||||
return "Hyritone: Find ores from the seed server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLongDesc() {
|
||||
return Arrays.asList(
|
||||
"This function draws ESP boxes around the ores that exists in the seed server that are not mined.",
|
||||
"",
|
||||
"Usage:",
|
||||
"> seedxray"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.hydev.hyritone.task;
|
||||
|
||||
/**
|
||||
* A task waiting to be executed.
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 18:06
|
||||
*/
|
||||
public interface Task
|
||||
{
|
||||
/**
|
||||
* Execute the task
|
||||
*/
|
||||
void execute(TaskRunState state);
|
||||
|
||||
/**
|
||||
* Stop the task
|
||||
*/
|
||||
default void stop()
|
||||
{
|
||||
// Default nothing to do
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.hydev.hyritone.task;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Instances of this class contains lists of tasks to be executed in order.
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 18:05
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TaskList extends ArrayList<Task>
|
||||
{
|
||||
public final String name;
|
||||
|
||||
public TaskList(String name, Task... tasks)
|
||||
{
|
||||
this(name);
|
||||
Collections.addAll(this, tasks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package org.hydev.hyritone.task;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* This class is used to manage tasks.
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 19:03
|
||||
*/
|
||||
@Getter
|
||||
public class TaskManager
|
||||
{
|
||||
private TaskRunState runState = null;
|
||||
|
||||
/**
|
||||
* Run a task list
|
||||
*
|
||||
* @param list Task list
|
||||
* @return Successfully started or not
|
||||
*/
|
||||
public boolean run(TaskList list)
|
||||
{
|
||||
// Check already started
|
||||
if (runState != null) return false;
|
||||
|
||||
// Reset values
|
||||
runState = new TaskRunState(null, list, 0);
|
||||
|
||||
// Create thread
|
||||
runState.thread = new Thread(() ->
|
||||
{
|
||||
// Execute step by step
|
||||
while (runState.step < list.size())
|
||||
{
|
||||
list.get(runState.step).execute(runState);
|
||||
runState.step++;
|
||||
}
|
||||
|
||||
// Finished
|
||||
stop();
|
||||
}, "Hyritone Task");
|
||||
|
||||
// Start async
|
||||
runState.thread.start();
|
||||
|
||||
// Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the task list
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
// Not started
|
||||
if (runState == null) return;
|
||||
|
||||
// Stop thread
|
||||
runState.thread.interrupt();
|
||||
|
||||
// Stop task
|
||||
if (runState.getStep() < runState.getTaskList().size())
|
||||
{
|
||||
runState.getTaskList().get(runState.getStep()).stop();
|
||||
}
|
||||
|
||||
runState = null;
|
||||
}
|
||||
|
||||
// TODO: pause
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.hydev.hyritone.task;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static baritone.api.utils.Helper.mc;
|
||||
|
||||
/**
|
||||
* This class contains preset tasks
|
||||
* TODO: Make a UI for task list!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 18:23
|
||||
*/
|
||||
public class TaskPresets
|
||||
{
|
||||
// Map<name.toLowerCase(), taskList>
|
||||
public static Map<String, TaskList> presets = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a task list
|
||||
*
|
||||
* @param list Task list
|
||||
*/
|
||||
public static void register(TaskList list)
|
||||
{
|
||||
presets.put(list.name.toLowerCase(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get preset by name
|
||||
*
|
||||
* @param name Lowercase name
|
||||
* @return Task list by name, null if not found
|
||||
*/
|
||||
public static TaskList getPreset(String name)
|
||||
{
|
||||
if (presets.containsKey(name.toLowerCase()))
|
||||
{
|
||||
return presets.get(name.toLowerCase());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load presets from file
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static void reloadPresets()
|
||||
{
|
||||
Path filePath = new File(mc.gameDir, "./Hyritone/").toPath();
|
||||
Files.createDirectories(filePath);
|
||||
|
||||
presets.clear();
|
||||
|
||||
try
|
||||
{
|
||||
Files.walk(filePath, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(path ->
|
||||
{
|
||||
try
|
||||
{
|
||||
String json = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
|
||||
TaskList list = new Gson().fromJson(json, TaskList.class);
|
||||
presets.put(list.name.toLowerCase(), list);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException | UncheckedIOException e)
|
||||
{
|
||||
System.err.println("Error when loading hyritone json.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.hydev.hyritone.task;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* TODO: Write a description for this class!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 20:38
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class TaskRunState
|
||||
{
|
||||
public Thread thread;
|
||||
public TaskList taskList;
|
||||
public int step;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Task " + thread.getId() + " is executing step " + step + " of " + taskList.size() + " " +
|
||||
"| Current Task: " + taskList.get(step).getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.hydev.hyritone.task.defaults;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.hydev.hyritone.task.Task;
|
||||
import org.hydev.hyritone.task.TaskRunState;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Run task if condition is met
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-25!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-25 17:44
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TaskCondition implements Task
|
||||
{
|
||||
private final Function<TaskRunState, Boolean> condition;
|
||||
private final Task taskIf;
|
||||
private final Task taskElse;
|
||||
|
||||
@Override
|
||||
public void execute(TaskRunState state)
|
||||
{
|
||||
if (condition.apply(state))
|
||||
{
|
||||
if (taskIf != null)
|
||||
{
|
||||
taskIf.execute(state);
|
||||
}
|
||||
}
|
||||
else if (taskElse != null)
|
||||
{
|
||||
taskElse.execute(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.hydev.hyritone.task.defaults;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.hydev.hyritone.task.Task;
|
||||
import org.hydev.hyritone.task.TaskRunState;
|
||||
|
||||
/**
|
||||
* Task to delay for some seconds
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 18:21
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TaskDelay implements Task
|
||||
{
|
||||
private final long delay;
|
||||
|
||||
@Override
|
||||
public void execute(TaskRunState state)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(delay);
|
||||
}
|
||||
catch (InterruptedException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.hydev.hyritone.task.defaults;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.hydev.hyritone.task.Task;
|
||||
import org.hydev.hyritone.task.TaskRunState;
|
||||
import org.hydev.hyritone.utils.PlayerUtils;
|
||||
|
||||
/**
|
||||
* Interact with blocks (Eg. chests)
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 23:10
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TaskInteract implements Task
|
||||
{
|
||||
private final long x;
|
||||
private final long y;
|
||||
private final long z;
|
||||
|
||||
@Override
|
||||
public void execute(TaskRunState state)
|
||||
{
|
||||
PlayerUtils.interact(new BlockPos(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.hydev.hyritone.task.defaults;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.hydev.hyritone.task.Task;
|
||||
import org.hydev.hyritone.task.TaskRunState;
|
||||
|
||||
/**
|
||||
* Replay from some index
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 20:37
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class TaskReplay implements Task
|
||||
{
|
||||
private final int step;
|
||||
|
||||
@Override
|
||||
public void execute(TaskRunState state)
|
||||
{
|
||||
state.step = step - 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.hydev.hyritone.task.defaults;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.hydev.hyritone.task.Task;
|
||||
import org.hydev.hyritone.task.TaskRunState;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.hydev.hyritone.utils.MiscUtils.sleep;
|
||||
|
||||
/**
|
||||
* Wait for a condition to complete
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-25!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-25 12:29
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class TaskWaitFor implements Task
|
||||
{
|
||||
private final Function<TaskRunState, Boolean> condition;
|
||||
private long timeout = 10 * 60 * 1000;
|
||||
private long interval = 100;
|
||||
|
||||
@Override
|
||||
public void execute(TaskRunState state)
|
||||
{
|
||||
// Timeout detection
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// Run
|
||||
while (true)
|
||||
{
|
||||
if (condition.apply(state)) return;
|
||||
sleep(interval);
|
||||
|
||||
if (System.currentTimeMillis() - startTime > timeout) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 org.hydev.hyritone.utils;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
|
||||
import static baritone.api.utils.Helper.mc;
|
||||
|
||||
/**
|
||||
* TODO: Write a description for this class!
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-02-19!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-02-19 13:28
|
||||
*/
|
||||
public class MiscUtils
|
||||
{
|
||||
public static void print(String text)
|
||||
{
|
||||
if (mc.player == null) return;
|
||||
|
||||
mc.player.sendMessage(new StringTextComponent("§3§l[§bHyritone§3§l] §r" + text));
|
||||
System.out.println("Log: " + text);
|
||||
}
|
||||
|
||||
public static void debug(String text)
|
||||
{
|
||||
print("§8[§7Debug§8]§7 " + text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an identifier for a block pos that's unique for each xyz
|
||||
*
|
||||
* @param pos Block position
|
||||
* @return Stringify
|
||||
*/
|
||||
public static String posId(BlockPos pos)
|
||||
{
|
||||
return String.format("[%s,%s,%s]", pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep without exceptions
|
||||
*
|
||||
* @param ms Time in ms
|
||||
*/
|
||||
public static void sleep(long ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package org.hydev.hyritone.utils;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.utils.accessor.IMouse;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.multiplayer.PlayerController;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.network.play.client.CAnimateHandPacket;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
/**
|
||||
* Utils for controlling the player.
|
||||
* <p>
|
||||
* Class created by the HyDEV Team on 2020-01-24!
|
||||
*
|
||||
* @author HyDEV Team (https://github.com/HyDevelop)
|
||||
* @author Hykilpikonna (https://github.com/hykilpikonna)
|
||||
* @author Vanilla (https://github.com/VergeDX)
|
||||
* @since 2020-01-24 22:34
|
||||
*/
|
||||
public class PlayerUtils
|
||||
{
|
||||
public static ClientPlayerEntity player() { return Helper.mc.player; }
|
||||
public static ClientWorld world() { return Helper.mc.world; }
|
||||
public static IMouse mouse() { return (IMouse) Helper.mc.mouseHelper; }
|
||||
public static PlayerController controller() { return Helper.mc.playerController; }
|
||||
|
||||
/**
|
||||
* Get player's eye vector
|
||||
*
|
||||
* @return Eye vector
|
||||
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
|
||||
*/
|
||||
public static Vec3d getEyesPos()
|
||||
{
|
||||
assert player() != null;
|
||||
|
||||
return new Vec3d(player().getPosX(),
|
||||
player().getPosY() + player().getEyeHeight(player().getPose()),
|
||||
player().getPosZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get what does it take to rotate to a direction
|
||||
*
|
||||
* @param vec Final direction
|
||||
* @return Rotation required
|
||||
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
|
||||
*/
|
||||
public static Rotation getNeededRotations(Vec3d vec)
|
||||
{
|
||||
Vec3d eyesPos = getEyesPos();
|
||||
|
||||
double diffX = vec.x - eyesPos.x;
|
||||
double diffY = vec.y - eyesPos.y;
|
||||
double diffZ = vec.z - eyesPos.z;
|
||||
|
||||
double diffXZ = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
|
||||
float yaw = (float)Math.toDegrees(Math.atan2(diffZ, diffX)) - 90F;
|
||||
float pitch = (float)-Math.toDegrees(Math.atan2(diffY, diffXZ));
|
||||
|
||||
return new Rotation(yaw, pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate
|
||||
*
|
||||
* @param rotation Relative rotation
|
||||
*/
|
||||
public static void rotate(Rotation rotation)
|
||||
{
|
||||
player().rotationYaw = rotation.getYaw();
|
||||
player().rotationPitch = rotation.getPitch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate to face one block
|
||||
*
|
||||
* @param pos Block position
|
||||
* @return Direction
|
||||
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
|
||||
*/
|
||||
public static Direction rotateToBlock(BlockPos pos)
|
||||
{
|
||||
Direction side = null;
|
||||
Direction[] sides = Direction.values();
|
||||
|
||||
Vec3d eyesPos = getEyesPos();
|
||||
Vec3d relCenter = world().getBlockState(pos).getShape(world(), pos).getBoundingBox().getCenter();
|
||||
Vec3d center = new Vec3d(pos).add(relCenter);
|
||||
|
||||
Vec3d[] hitVecs = new Vec3d[sides.length];
|
||||
for (int i = 0; i < sides.length; i++)
|
||||
{
|
||||
Vec3i dirVec = sides[i].getDirectionVec();
|
||||
Vec3d relHitVec = new Vec3d(relCenter.x * dirVec.getX(),
|
||||
relCenter.y * dirVec.getY(), relCenter.z * dirVec.getZ());
|
||||
hitVecs[i] = center.add(relHitVec);
|
||||
}
|
||||
|
||||
BlockState state = world().getBlockState(pos);
|
||||
for (int i = 0; i < sides.length; i++)
|
||||
{
|
||||
// check line of sight
|
||||
if (world().rayTraceBlocks(eyesPos, hitVecs[i], pos, state.getShape(world(), pos), state) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
side = sides[i];
|
||||
break;
|
||||
}
|
||||
|
||||
if (side == null)
|
||||
{
|
||||
double distanceSqToCenter = eyesPos.squareDistanceTo(center);
|
||||
for (int i = 0; i < sides.length; i++)
|
||||
{
|
||||
// check if side is facing towards player
|
||||
if (eyesPos.squareDistanceTo(hitVecs[i]) >= distanceSqToCenter)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
side = sides[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// player is inside of block, side doesn't matter
|
||||
if (side == null)
|
||||
{
|
||||
side = sides[0];
|
||||
}
|
||||
|
||||
// Rotate
|
||||
rotate(getNeededRotations(hitVecs[side.ordinal()]));
|
||||
|
||||
return side;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interact
|
||||
*
|
||||
* @param pos Block
|
||||
*/
|
||||
public static void interact(BlockPos pos)
|
||||
{
|
||||
rotateToBlock(pos);
|
||||
mouse().rightClick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dig the block at direction
|
||||
*
|
||||
* @param pos Block position
|
||||
* @param side Direction
|
||||
* @return Dig success or not
|
||||
* @author Wurst7 https://github.com/Wurst-Imperium/Wurst7
|
||||
*/
|
||||
public static boolean dig(BlockPos pos, Direction side)
|
||||
{
|
||||
// damage block
|
||||
if (!controller().onPlayerDamageBlock(pos, side))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// swing arm
|
||||
player().connection.sendPacket(new CAnimateHandPacket(Hand.MAIN_HAND));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dig the block at direction
|
||||
*
|
||||
* @param pos Block position
|
||||
* @return Dig success or not
|
||||
*/
|
||||
public static boolean dig(BlockPos pos)
|
||||
{
|
||||
return dig(pos, rotateToBlock(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay between swapping items from inv to chest.
|
||||
*
|
||||
* @return Delay between 80 to 120
|
||||
*/
|
||||
public static int chestDelay()
|
||||
{
|
||||
return (int) (80 + Math.random() * 40);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user