From 8df67786415d5f0eb8f4fb6802bf0b8a385d20c9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 15 Jun 2023 00:32:26 -0700 Subject: [PATCH] sort of integrated nether pathfinder --- build.gradle | 18 +++--- src/main/java/baritone/Elytra.java | 28 +++------ .../command/defaults/DefaultCommands.java | 3 +- .../command/defaults/ElytraCommand.java | 61 +++++++++++++++++++ .../java/baritone/utils/PathRenderer.java | 3 +- 5 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 src/main/java/baritone/command/defaults/ElytraCommand.java diff --git a/build.gradle b/build.gradle index 0ce05058c..7909911be 100755 --- a/build.gradle +++ b/build.gradle @@ -100,7 +100,9 @@ dependencies { exclude module: 'commons-io' exclude module: 'log4j-core' } + runtime launchCompile('dev.babbaj:nether-pathfinder:1.3') testImplementation 'junit:junit:4.12' + implementation 'dev.babbaj:nether-pathfinder:1.3' } mixin { @@ -153,16 +155,16 @@ install { def jarSAForgeName = String.format("%s-standalone-forge-%s", rootProject.name, version.toString()) artifacts { - archives file("$buildDir/libs/"+jarApiName+".jar") - archives file("$buildDir/libs/"+jarApiForgeName+".jar") - archives file("$buildDir/libs/"+jarSAName+".jar") - archives file("$buildDir/libs/"+jarSAForgeName+".jar") + archives file("$buildDir/libs/" + jarApiName + ".jar") + archives file("$buildDir/libs/" + jarApiForgeName + ".jar") + archives file("$buildDir/libs/" + jarSAName + ".jar") + archives file("$buildDir/libs/" + jarSAForgeName + ".jar") } repositories.mavenInstaller { - addFilter('api') { artifact, file -> artifact.name == "baritone-api" } - addFilter('api-forge') { artifact, file -> artifact.name == "baritone-api-forge" } - addFilter('standalone') { artifact, file -> artifact.name == "baritone-standalone" } - addFilter('standalone-forge') { artifact, file -> artifact.name == "baritone-standalone-forge" } + addFilter('api') { artifact, file -> artifact.name == "baritone-api" } + addFilter('api-forge') { artifact, file -> artifact.name == "baritone-api-forge" } + addFilter('standalone') { artifact, file -> artifact.name == "baritone-standalone" } + addFilter('standalone-forge') { artifact, file -> artifact.name == "baritone-standalone-forge" } } } diff --git a/src/main/java/baritone/Elytra.java b/src/main/java/baritone/Elytra.java index 2f724c692..5a8cae634 100644 --- a/src/main/java/baritone/Elytra.java +++ b/src/main/java/baritone/Elytra.java @@ -25,6 +25,7 @@ import baritone.api.utils.RotationUtils; import baritone.behavior.Behavior; import baritone.utils.BlockStateInterface; import com.mojang.realmsclient.util.Pair; +import dev.babbaj.pathfinder.NetherPathfinder; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityFireworkRocket; @@ -36,28 +37,16 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; import java.util.*; +import java.util.stream.Collectors; public class Elytra extends Behavior implements Helper { - public static List path = new ArrayList<>(); + public List path = new ArrayList<>(); - static { - - try { - DataInputStream in = new DataInputStream(new FileInputStream(new File("/Users/leijurv/Dropbox/nether-pathfinder/build/test"))); - int count = in.readInt(); - System.out.println("Count: " + count); - for (int i = 0; i < count; i++) { - path.add(new BetterBlockPos((int) in.readDouble(), (int) in.readDouble(), (int) in.readDouble())); - } - removeBacktracks(); - } catch (Exception e) { - throw new RuntimeException(e); - } + public void path(BlockPos destination) { + path = Arrays.stream(NetherPathfinder.pathFind(146008555100680L, false, false, ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z, destination.getX(), destination.getY(), destination.getZ())).mapToObj(BlockPos::fromLong).map(BetterBlockPos::new).collect(Collectors.toList()); + removeBacktracks(); } public int playerNear; @@ -211,6 +200,9 @@ public class Elytra extends Behavior implements Helper { if (event.getType() == TickEvent.Type.OUT) { return; } + if (path.isEmpty()) { + return; + } fixNearPlayer(); baritone.getInputOverrideHandler().clearAllKeys(); lines.clear(); @@ -425,7 +417,7 @@ public class Elytra extends Behavior implements Helper { //System.out.println(playerNear); } - public static void removeBacktracks() { + public void removeBacktracks() { Map positionFirstSeen = new HashMap<>(); for (int i = 0; i < path.size(); i++) { BetterBlockPos pos = path.get(i); diff --git a/src/main/java/baritone/command/defaults/DefaultCommands.java b/src/main/java/baritone/command/defaults/DefaultCommands.java index 901fda713..b8e3c924b 100644 --- a/src/main/java/baritone/command/defaults/DefaultCommands.java +++ b/src/main/java/baritone/command/defaults/DefaultCommands.java @@ -66,7 +66,8 @@ public final class DefaultCommands { new WaypointsCommand(baritone), new CommandAlias(baritone, "sethome", "Sets your home waypoint", "waypoints save home"), new CommandAlias(baritone, "home", "Path to your home waypoint", "waypoints goto home"), - new SelCommand(baritone) + new SelCommand(baritone), + new ElytraCommand(baritone) )); ExecutionControlCommands prc = new ExecutionControlCommands(baritone); commands.add(prc.pauseCommand); diff --git a/src/main/java/baritone/command/defaults/ElytraCommand.java b/src/main/java/baritone/command/defaults/ElytraCommand.java new file mode 100644 index 000000000..2d2e3f0ee --- /dev/null +++ b/src/main/java/baritone/command/defaults/ElytraCommand.java @@ -0,0 +1,61 @@ +/* + * 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 . + */ + +package baritone.command.defaults; + +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 baritone.api.pathing.goals.GoalXZ; +import baritone.api.process.ICustomGoalProcess; +import net.minecraft.util.math.BlockPos; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class ElytraCommand extends Command { + + public ElytraCommand(IBaritone baritone) { + super(baritone, "elytra"); + } + + @Override + public void execute(String label, IArgConsumer args) throws CommandException { + ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess(); + args.requireMax(0); + GoalXZ goal = (GoalXZ) customGoalProcess.getGoal(); + ((Baritone) baritone).elytra.path(new BlockPos(goal.getX(), 64, goal.getZ())); + } + + @Override + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { + return Stream.empty(); + } + + @Override + public String getShortDesc() { + return "elytra time"; + } + + @Override + public List getLongDesc() { + return Arrays.asList(); + } +} diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index bec8937a4..df0d5b0ca 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -18,7 +18,6 @@ package baritone.utils; import baritone.Baritone; -import baritone.Elytra; import baritone.api.BaritoneAPI; import baritone.api.event.events.RenderEvent; import baritone.api.pathing.goals.*; @@ -106,7 +105,7 @@ public final class PathRenderer implements IRenderer { drawPath(next.getPath().positions(), 0, settings.colorNextPath.value, settings.fadePath.value, 10, 20); } - drawPath(Elytra.path.subList(Math.max(behavior.baritone.elytra.playerNear - 30, 0), Math.min(behavior.baritone.elytra.playerNear + 30, Elytra.path.size())), 0, Color.RED, false, 0, 0); + drawPath(behavior.baritone.elytra.path.subList(Math.max(behavior.baritone.elytra.playerNear - 30, 0), Math.min(behavior.baritone.elytra.playerNear + 30, behavior.baritone.elytra.path.size())), 0, Color.RED, false, 0, 0); if (behavior.baritone.elytra.goal != null) { drawGoal(renderView, new GoalBlock(behavior.baritone.elytra.goal), partialTicks, Color.GREEN); }