diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index e9a3c7cc1..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md new file mode 100644 index 000000000..55e5ad06f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -0,0 +1,25 @@ +--- +name: Bug report +about: Please file a separate report for each issue +title: Please add a brief but descriptive title +labels: bug +assignees: '' +--- + +## Some information +Operating system: +Java version: +Minecraft version: +Baritone version: +Forge mods (if used): + +## Exception, error or logs +You can find your logs in `%appdata%/.minecraft/logs/` (Windows) or `/Library/Application\ Support/minecraft/logs` (Mac). + +## How to reproduce +Add your steps to reproduce the issue/bug experienced here. + +## Final checklist +- [ ] I have included the version of Minecraft I'm running, baritone's version and forge mods (if used). +- [ ] I have included logs, exceptions and / or steps to reproduce the issue. +- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 000000000..2482fd4c3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,13 @@ +--- +name: Question +about: Please file a separate report for each question +title: Please add a brief but descriptive title +labels: question +assignees: '' +--- + +## What do you need help with? +With as much detail as possible, describe your question and what you may need help with. + +## Final checklist +- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/suggestion.md b/.github/ISSUE_TEMPLATE/suggestion.md new file mode 100644 index 000000000..da61c638d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/suggestion.md @@ -0,0 +1,19 @@ +--- +name: Suggestion +about: Please file a separate report for each suggestion +title: Please add a brief but descriptive title +labels: enhancement +assignees: '' +--- + +## Describe your suggestion +With as much detail as possible, describe what your suggestion would do for Baritone. + +## Settings +If applicable, what settings/customizability should be offered to tweak the functionality of your suggestion. + +## Context +Describe how your suggestion would improve Baritone, or the reason behind it being added. + +## Final checklist +- [ ] I have not used any OwO's or UwU's in this issue. \ No newline at end of file diff --git a/README.md b/README.md index 4f41d72b2..db5be4c23 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,40 @@ # Baritone -[![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone) -[![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases) +[![Build Status](https://travis-ci.com/cabaletta/baritone.svg?branch=master)](https://travis-ci.com/cabaletta/baritone/) +[![Release](https://img.shields.io/github/release/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/releases/) [![License](https://img.shields.io/badge/license-LGPL--3.0%20with%20anime%20exception-green.svg)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/a73d037823b64a5faf597a18d71e3400)](https://www.codacy.com/app/leijurv/baritone?utm_source=github.com&utm_medium=referral&utm_content=cabaletta/baritone&utm_campaign=Badge_Grade) -[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone) -[![GitHub All Releases](https://img.shields.io/github/downloads/cabaletta/baritone/total.svg)](https://github.com/cabaletta/baritone/releases) -[![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://minecraft.gamepedia.com/1.12.2) -[![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://minecraft.gamepedia.com/1.13.2) +[![HitCount](http://hits.dwyl.com/cabaletta/baritone.svg)](http://hits.dwyl.com/cabaletta/baritone/) +[![GitHub All Releases](https://img.shields.io/github/downloads/cabaletta/baritone/total.svg)](https://github.com/cabaletta/baritone/releases/) +[![Minecraft](https://img.shields.io/badge/MC-1.12.2-green.svg)](https://github.com/cabaletta/baritone/tree/master/) +[![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://github.com/cabaletta/baritone/tree/1.13.2/) [![Code of Conduct](https://img.shields.io/badge/%E2%9D%A4-code%20of%20conduct-blue.svg?style=flat)](https://github.com/cabaletta/baritone/blob/master/CODE_OF_CONDUCT.md) [![Known Vulnerabilities](https://snyk.io/test/github/cabaletta/baritone/badge.svg?targetFile=build.gradle)](https://snyk.io/test/github/cabaletta/baritone?targetFile=build.gradle) -[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues) +[![Contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/cabaletta/baritone/issues/) [![Issues](https://img.shields.io/github/issues/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues/) [![GitHub issues-closed](https://img.shields.io/github/issues-closed/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/issues?q=is%3Aissue+is%3Aclosed) [![Pull Requests](https://img.shields.io/github/issues-pr/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/pulls/) ![Code size](https://img.shields.io/github/languages/code-size/cabaletta/baritone.svg) ![GitHub repo size](https://img.shields.io/github/repo-size/cabaletta/baritone.svg) -<<<<<<< HEAD -![](https://tokei.rs/b1/github/cabaletta/baritone?category=code) -[![Minecraft](https://img.shields.io/badge/MC-1.13.2-brightgreen.svg)](https://minecraft.gamepedia.com/1.13.2) -======= ![Lines of Code](https://tokei.rs/b1/github/cabaletta/baritone?category=code) ->>>>>>> master [![GitHub contributors](https://img.shields.io/github/contributors/cabaletta/baritone.svg)](https://github.com/cabaletta/baritone/graphs/contributors/) [![GitHub commits](https://img.shields.io/github/commits-since/cabaletta/baritone/v1.0.0.svg)](https://github.com/cabaletta/baritone/commit/) [![Impact integration](https://img.shields.io/badge/Impact%20integration-v1.2.6%20/%20v1.3.2-brightgreen.svg)](https://impactdevelopment.github.io/) -[![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax) +[![ForgeHax integration](https://img.shields.io/badge/ForgeHax%20%22integration%22-scuffed-yellow.svg)](https://github.com/fr1kin/ForgeHax/) [![WWE integration](https://img.shields.io/badge/WWE%20%22integration%22-master%3F-green.svg)](https://wweclient.com/) [![Future integration](https://img.shields.io/badge/Future%20integration-Soon™%3F%3F%3F-red.svg)](https://futureclient.net/) -[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com) -[![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com) +[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](http://forthebadge.com/) +[![forthebadge](https://forthebadge.com/images/badges/mom-made-pizza-rolls.svg)](http://forthebadge.com/) A Minecraft pathfinder bot. Baritone is the pathfinding system used in [Impact](https://impactdevelopment.github.io/) since 4.4. There's a [showcase video](https://www.youtube.com/watch?v=yI8hgW_m6dQ) made by @Adovin#3153 on Baritone's integration into Impact. [Here's](https://www.youtube.com/watch?v=StquF69-_wI) a video I made showing off what it can do. +The easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone. The second easiest way (for 1.12.2 only) is to install the forge jar from [releases](https://github.com/cabaletta/baritone/releases). Otherwise, see [Installation & setup](SETUP.md). Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. + This project is an updated version of [MineBot](https://github.com/leijurv/MineBot/), the original version of the bot for Minecraft 1.8.9, rebuilt for 1.12.2 and 1.13.2. Baritone focuses on reliability and particularly performance (it's over [30x faster](https://github.com/cabaletta/baritone/pull/180#issuecomment-423822928) than MineBot at calculating paths). -Have committed at least once a day for the last 10 months =D 🦀 +Have committed at least once a day for the last 11 months =D 🦀 1Leijurv3DWTrGAfmmiTphjhXLvQiHg7K2 @@ -49,15 +46,15 @@ Here are some links to help to get started: - [Installation & setup](SETUP.md) -- [API Javadocs](https://baritone.leijurv.com) +- [API Javadocs](https://baritone.leijurv.com/) - [Settings](https://baritone.leijurv.com/baritone/api/Settings.html#field.detail) -- [Baritone chat control usage](USAGE.md) +- [Usage (chat control)](USAGE.md) # API -The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com). +The API is heavily documented, you can find the Javadocs for the latest release [here](https://baritone.leijurv.com/). Please note that usage of anything located outside of the ``baritone.api`` package is not supported by the API release jar. @@ -78,7 +75,7 @@ That's what it's for, sure! (As long as usage is in compliance with the LGPL 3.0 ## How is it so fast? -Magic. (Hours of [leijurv](https://github.com/leijurv) enduring excruciating pain) +Magic. (Hours of [leijurv](https://github.com/leijurv/) enduring excruciating pain) ## Why is it called Baritone? diff --git a/SETUP.md b/SETUP.md index 1767e2c5b..aca5f6c5a 100644 --- a/SETUP.md +++ b/SETUP.md @@ -1,5 +1,9 @@ # Installation +The easiest way to install Baritone is to install [Impact](https://impactdevelopment.github.io/), which comes with Baritone. + +Once Baritone is installed, look [here](USAGE.md) for instructions on how to use it. + ## Prebuilt official releases These releases are not always completely up to date with latest features, and are only released from `master`. (so if you want `backfill-2` branch for example, you'll have to build it yourself) diff --git a/USAGE.md b/USAGE.md index ce8924a74..865670b63 100644 --- a/USAGE.md +++ b/USAGE.md @@ -16,9 +16,6 @@ To disable direct chat control (with no prefix), turn off the `chatControl` sett To toggle a boolean setting, just say its name in chat (for example saying `allowBreak` toggles whether Baritone will consider breaking blocks). For a numeric setting, say its name then the new value (like `primaryTimeoutMS 250`). It's case insensitive. To reset a setting to its default value, say `acceptableThrowawayItems reset`. To reset all settings, say `reset`. To see all settings that have been modified from their default values, say `modified`. - - - Some common examples: - `thisway 1000` then `path` to go in the direction you're facing for a thousand blocks - `goal x y z` or `goal x z` or `goal y`, then `path` to go to a certain coordinate @@ -31,6 +28,7 @@ Some common examples: - `follow playerName` to follow a player. `follow` to follow the entity you're looking at (only works if it hitting range). `followplayers` to follow any players in range (combine with Kill Aura for a fun time). - `save waypointName` to save a waypoint. `goto waypointName` to go to it. - `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). +- `schematica` to build the schematic that is currently open in schematica - `tunnel` to dig just straight ahead and make a tunnel - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). diff --git a/build.gradle b/build.gradle index 6c3a51c44..85a61f347 100755 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ */ group 'baritone' -version '1.3.2' +version '1.3.3' buildscript { repositories { @@ -66,6 +66,14 @@ sourceSets { compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output } + + schematica_api { + compileClasspath += main.compileClasspath + } + + main { + compileClasspath += schematica_api.output + } } task sourceJar(type: Jar, dependsOn: classes) { diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 5e2f8b03c..461168a1e 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -33,6 +33,12 @@ # need to keep mixin names -keep class baritone.launch.** { *; } +#try to keep usage of schematica in separate classes +-keep class baritone.utils.schematic.schematica.** +#proguard doesnt like it when it cant find our fake schematica classes +-dontwarn baritone.utils.schematic.schematica.** + + # Keep - Applications. Keep all application classes, along with their 'main' # methods. -keepclasseswithmembers public class * { diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index a356922cc..2c892d982 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -128,5 +128,8 @@ public interface IBaritone { */ IEventBus getGameEventHandler(); + /** + * Open click + */ void openClick(); } diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 6146ac7fb..5f6d91838 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -231,6 +231,11 @@ public final class Settings { */ public final Setting rightClickSpeed = new Setting<>(4); + /** + * How many degrees to randomize the yaw every tick. Set to 0 to disable + */ + public final Setting randomLooking = new Setting<>(2d); + /** * This is the big A* setting. * As long as your cost heuristic is an *underestimate*, it's guaranteed to find you the best path. diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java index 8b15fba1c..90aba4eaf 100644 --- a/src/api/java/baritone/api/process/IBuilderProcess.java +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -54,6 +54,8 @@ public interface IBuilderProcess extends IBaritoneProcess { return build(schematicFile, file, origin); } + void buildOpenSchematic(); + void pause(); void resume(); diff --git a/src/api/java/baritone/api/utils/BlockUtils.java b/src/api/java/baritone/api/utils/BlockUtils.java index 19ea8f4d1..57ab3e4cc 100644 --- a/src/api/java/baritone/api/utils/BlockUtils.java +++ b/src/api/java/baritone/api/utils/BlockUtils.java @@ -39,9 +39,6 @@ public class BlockUtils { } public static Block stringToBlockRequired(String name) { - if (name.equals("lit_redstone_ore")) { // workaround for Impact 4.6 only - return stringToBlockRequired("redstone_ore"); - } Block block = stringToBlockNullable(name); Objects.requireNonNull(block); return block; diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java index c4a92f2af..de1fa2174 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControl.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControl.java @@ -35,6 +35,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientChunkProvider; import net.minecraft.crash.CrashReport; import net.minecraft.entity.Entity; +import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -292,6 +293,10 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener logDirect(success ? "Loaded" : "Unable to load"); return true; } + if (msg.startsWith("schematica")) { + baritone.getBuilderProcess().buildOpenSchematic(); + return true; + } if (msg.equals("come")) { customGoalProcess.setGoalAndPath(new GoalBlock(new BlockPos(Helper.mc.getRenderViewEntity()))); logDirect("Coming"); @@ -404,11 +409,34 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener } return true; } + if (msg.startsWith("followentities")) { + baritone.getFollowProcess().follow(Entity.class::isInstance); + logDirect("Following any entities"); + return true; + } if (msg.startsWith("followplayers")) { baritone.getFollowProcess().follow(PlayerEntity.class::isInstance); // O P P A logDirect("Following any players"); return true; } + if (msg.startsWith("followentity")) { + String name = msg.substring(12).trim(); + Optional toFollow = Optional.empty(); + for (Entity entity : ctx.world().loadedEntityList) { + String entityName = entity.getName().getFormattedText().trim().toLowerCase(); + if ((entityName.contains(name) || name.contains(entityName)) && !(entity instanceof ItemEntity || entity instanceof PlayerEntity)) { // We dont want it following players while `#follow` exists. + toFollow = Optional.of(entity); + } + } + if (!toFollow.isPresent()) { + logDirect("Entity not found"); + return true; + } + Entity effectivelyFinal = toFollow.get(); + baritone.getFollowProcess().follow(effectivelyFinal::equals); + logDirect("Following entity " + toFollow.get()); + return true; + } if (msg.startsWith("follow")) { String name = msg.substring(6).trim(); Optional toFollow = Optional.empty(); @@ -688,7 +716,6 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener goal = new GoalBlock(playerFeet); break; case 1: - goal = new GoalYLevel(parseOrDefault(params[0], playerFeet.y)); break; case 2: diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 3e608107d..979934cbc 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -160,11 +160,11 @@ public class SettingsUtil { private final Settings.Setting setting; - public ParserContext(Settings.Setting setting) { + private ParserContext(Settings.Setting setting) { this.setting = setting; } - final Settings.Setting getSetting() { + private Settings.Setting getSetting() { return this.setting; } } diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 73e5e6e57..44715f4c5 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -32,6 +32,7 @@ import java.util.List; public final class BaritoneProvider implements IBaritoneProvider { private final Baritone primary = new Baritone(); + private final List all = Collections.singletonList(primary); @Override public IBaritone getPrimaryBaritone() { @@ -40,8 +41,7 @@ public final class BaritoneProvider implements IBaritoneProvider { @Override public List getAllBaritones() { - // TODO return a CopyOnWriteArrayList - return Collections.singletonList(primary); + return all; } @Override diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index d6833a58f..2a8a4935b 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -50,6 +50,13 @@ public final class LookBehavior extends Behavior implements ILookBehavior { @Override public void updateTarget(Rotation target, boolean force) { this.target = target; + if (!force) { + double rand = Math.random() - 0.5; + if (Math.abs(rand) < 0.1) { + rand *= 4; + } + this.target = new Rotation(this.target.getYaw() + (float) (rand * Baritone.settings().randomLooking.value), this.target.getPitch()); + } this.force = force || !Baritone.settings().freeLook.value; } diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 7c8e4291e..237c460b4 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -303,6 +303,9 @@ public final class CachedWorld implements ICachedWorld, Helper { } catch (InterruptedException e) { e.printStackTrace(); break; + } catch (Throwable th) { + // in the case of an exception, keep consuming from the queue so as not to leak memory + th.printStackTrace(); } } } diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index a021d8cce..95d6ec393 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -23,15 +23,14 @@ import baritone.api.pathing.movement.IMovement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.*; import baritone.api.utils.input.Input; +import baritone.behavior.PathingBehavior; import baritone.utils.BlockStateInterface; import net.minecraft.entity.item.FallingBlockEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; public abstract class Movement implements IMovement, MovementHelper { @@ -62,6 +61,8 @@ public abstract class Movement implements IMovement, MovementHelper { public List toPlaceCached = null; public List toWalkIntoCached = null; + private Set validPositionsCached = null; + private Boolean calculatedWhileLoaded; protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) { @@ -99,6 +100,20 @@ public abstract class Movement implements IMovement, MovementHelper { this.cost = cost; } + protected abstract Set calculateValidPositions(); + + public Set getValidPositions() { + if (validPositionsCached == null) { + validPositionsCached = calculateValidPositions(); + Objects.requireNonNull(validPositionsCached); + } + return validPositionsCached; + } + + protected boolean playerInValidPosition() { + return getValidPositions().contains(ctx.playerFeet()) || getValidPositions().contains(((PathingBehavior) baritone.getPathingBehavior()).pathStart()); + } + /** * Handles the execution of the latest Movement * State, and offers a Status to the calling class. diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index edd26c32a..98c502e2e 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -89,7 +89,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block instanceof AirBlock) { // early return for most common case return true; } - if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof SkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock) { + if (block == Blocks.FIRE || block == Blocks.TRIPWIRE || block == Blocks.COBWEB || block == Blocks.END_PORTAL || block == Blocks.COCOA || block instanceof AbstractSkullBlock || block == Blocks.BUBBLE_COLUMN || block instanceof ShulkerBoxBlock || block instanceof SlabBlock || block instanceof TrapDoorBlock) { return false; } if (Baritone.settings().blocksToAvoid.value.contains(block)) { @@ -137,7 +137,7 @@ public interface MovementHelper extends ActionCosts, Helper { // every block that overrides isPassable with anything more complicated than a "return true;" or "return false;" // has already been accounted for above // therefore it's safe to not construct a blockpos from our x, y, z ints and instead just pass null - return state.allowsMovement(null, null, PathType.LAND); + return state.allowsMovement(null, BlockPos.ZERO, PathType.LAND); // workaround for future compatibility =P } /** diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index 4ed671760..9ca5e0432 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -31,6 +31,8 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FallingBlock; import net.minecraft.util.Direction; +import com.google.common.collect.ImmutableSet; +import java.util.Set; public class MovementAscend extends Movement { @@ -51,6 +53,17 @@ public class MovementAscend extends Movement { return cost(context, src.x, src.y, src.z, dest.x, dest.z); } + @Override + protected Set calculateValidPositions() { + BetterBlockPos prior = new BetterBlockPos(src.subtract(getDirection()).up()); // sometimes we back up to place the block, also sprint ascends, also skip descend to straight ascend + return ImmutableSet.of(src, + src.up(), + dest, + prior, + prior.up() + ); + } + public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { BlockState toPlace = context.get(destX, y, destZ); double additionalPlacementCost = 0; @@ -143,6 +156,10 @@ public class MovementAscend extends Movement { @Override public MovementState updateState(MovementState state) { + if (ctx.playerFeet().y < src.y) { + // this check should run even when in preparing state (breaking blocks) + return state.setStatus(MovementStatus.UNREACHABLE); + } super.updateState(state); // TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump // for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly) @@ -150,14 +167,10 @@ public class MovementAscend extends Movement { return state; } - if (ctx.playerFeet().equals(dest)) { + if (ctx.playerFeet().equals(dest) || ctx.playerFeet().equals(dest.add(getDirection().down()))) { return state.setStatus(MovementStatus.SUCCESS); } - if (ctx.playerFeet().y < src.y) { - return state.setStatus(MovementStatus.UNREACHABLE); - } - BlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace); if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) { ticksWithoutPlacement++; diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index 1e28f5429..5d5e39c17 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -29,6 +29,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.pathing.MutableMoveResult; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -37,6 +38,8 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import java.util.Set; + public class MovementDescend extends Movement { private int numTicks = 0; @@ -61,6 +64,11 @@ public class MovementDescend extends Movement { return result.cost; } + @Override + protected Set calculateValidPositions() { + return ImmutableSet.of(src, dest.up(), dest); + } + public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { double totalCost = 0; BlockState destDown = context.get(destX, y - 1, destZ); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index f53748c52..7ebfd5013 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -28,6 +28,7 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.pathing.MutableMoveResult; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -36,6 +37,7 @@ import net.minecraft.util.math.BlockPos; import java.util.ArrayList; import java.util.List; +import java.util.Set; public class MovementDiagonal extends Movement { @@ -64,6 +66,16 @@ public class MovementDiagonal extends Movement { return result.cost; } + @Override + protected Set calculateValidPositions() { + BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z); + BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z); + if (dest.y != src.y) { // only if allowDiagonalDescend + return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down()); + } + return ImmutableSet.of(src, dest, diagA, diagB); + } + public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { BlockState destInto = context.get(destX, y, destZ); if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) { @@ -172,8 +184,9 @@ public class MovementDiagonal extends Movement { } if (ctx.playerFeet().equals(dest)) { - state.setStatus(MovementStatus.SUCCESS); - return state; + return state.setStatus(MovementStatus.SUCCESS); + } else if (!playerInValidPosition() && !(MovementHelper.isLiquid(ctx, src) && getValidPositions().contains(ctx.playerFeet().up()))) { + return state.setStatus(MovementStatus.UNREACHABLE); } if (sprint()) { state.setInput(Input.SPRINT, true); @@ -182,7 +195,7 @@ public class MovementDiagonal extends Movement { return state; } - public boolean sprint() { + private boolean sprint() { if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) { return false; } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 1429ecba2..89c692e85 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -24,10 +24,13 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import java.util.Set; + public class MovementDownward extends Movement { private int numTicks = 0; @@ -47,6 +50,11 @@ public class MovementDownward extends Movement { return cost(context, src.x, src.y, src.z); } + @Override + protected Set calculateValidPositions() { + return ImmutableSet.of(src, dest); + } + public static double cost(CalculationContext context, int x, int y, int z) { if (!context.allowDownward) { return COST_INF; @@ -73,6 +81,8 @@ public class MovementDownward extends Movement { if (ctx.playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); + } else if (!playerInValidPosition()) { + return state.setStatus(MovementStatus.UNREACHABLE); } double diffX = ctx.player().posX - (dest.getX() + 0.5); double diffZ = ctx.player().posZ - (dest.getZ() + 0.5); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/pathing/movement/movements/MovementFall.java index 1e6cc95d6..0ee9b778e 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementFall.java @@ -43,7 +43,9 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import java.util.HashSet; import java.util.Optional; +import java.util.Set; public class MovementFall extends Movement { @@ -64,6 +66,16 @@ public class MovementFall extends Movement { return result.cost; } + @Override + protected Set calculateValidPositions() { + Set set = new HashSet<>(); + set.add(src); + for (int y = src.y - dest.y; y >= 0; y--) { + set.add(dest.up(y)); + } + return set; + } + private boolean willPlaceBucket() { CalculationContext context = new CalculationContext(baritone); MutableMoveResult result = new MutableMoveResult(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 725bb7c22..ae3077a7a 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -35,6 +35,9 @@ import net.minecraft.fluid.Fluids; import net.minecraft.fluid.WaterFluid; import net.minecraft.util.Direction; +import java.util.HashSet; +import java.util.Set; + public class MovementParkour extends Movement { private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{}; @@ -175,6 +178,17 @@ public class MovementParkour extends Movement { return res.cost; } + @Override + protected Set calculateValidPositions() { + Set set = new HashSet<>(); + for (int i = 0; i <= dist; i++) { + for (int y = 0; y < 2; y++) { + set.add(src.offset(direction, i).up(y)); + } + } + return set; + } + @Override public boolean safeToCancel(MovementState state) { // once this movement is instantiated, the state is default to PREPPING @@ -213,7 +227,7 @@ public class MovementParkour extends Movement { state.setStatus(MovementStatus.SUCCESS); } } else if (!ctx.playerFeet().equals(src)) { - if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - ctx.playerFeet().getY() > 0.0001) { + if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - src.y > 0.0001) { if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true) == PlaceResult.READY_TO_PLACE) { // go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory state.setInput(Input.CLICK_RIGHT, true); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index d3bfb5218..52b1dddd3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -30,11 +30,14 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.*; import net.minecraft.state.properties.SlabType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import java.util.Set; + public class MovementPillar extends Movement { public MovementPillar(IBaritone baritone, BetterBlockPos start, BetterBlockPos end) { @@ -46,6 +49,11 @@ public class MovementPillar extends Movement { return cost(context, src.x, src.y, src.z); } + @Override + protected Set calculateValidPositions() { + return ImmutableSet.of(src, dest); + } + public static double cost(CalculationContext context, int x, int y, int z) { BlockState fromState = context.get(x, y, z); Block from = fromState.getBlock(); diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index b275c163b..b25d95bd3 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -30,12 +30,16 @@ import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.*; import net.minecraft.fluid.WaterFluid; import net.minecraft.state.properties.SlabType; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import java.util.Optional; +import java.util.Set; + public class MovementTraverse extends Movement { /** @@ -58,6 +62,11 @@ public class MovementTraverse extends Movement { return cost(context, src.x, src.y, src.z, dest.x, dest.z); } + @Override + protected Set calculateValidPositions() { + return ImmutableSet.of(src, dest); + } + public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { BlockState pb0 = context.get(destX, y + 1, destZ); BlockState pb1 = context.get(destX, y, destZ); @@ -196,9 +205,10 @@ public class MovementTraverse extends Movement { boolean ladder = fd == Blocks.LADDER || fd == Blocks.VINE; if (pb0.getBlock() instanceof DoorBlock || pb1.getBlock() instanceof DoorBlock) { - if ((pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest) - || pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src)) - && !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock()))) { + boolean notPassable = pb0.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, src, dest) || pb1.getBlock() instanceof DoorBlock && !MovementHelper.isDoorPassable(ctx, dest, src); + boolean canOpen = !(Blocks.IRON_DOOR.equals(pb0.getBlock()) || Blocks.IRON_DOOR.equals(pb1.getBlock())); + + if (notPassable && canOpen) { return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), positionsToBreak[0]), ctx.playerRotations()), true)) .setInput(Input.CLICK_RIGHT, true); } @@ -209,8 +219,10 @@ public class MovementTraverse extends Movement { : !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1] : null; if (blocked != null) { - return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), blocked), ctx.playerRotations()), true)) - .setInput(Input.CLICK_RIGHT, true); + Optional rotation = RotationUtils.reachable(ctx, blocked); + if (rotation.isPresent()) { + return state.setTarget(new MovementState.MovementTarget(rotation.get(), true)).setInput(Input.CLICK_RIGHT, true); + } } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 7710dcea3..4c7721024 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -99,14 +99,13 @@ public class PathExecutor implements IPathExecutor, Helper { if (pathPosition >= path.length()) { return true; // stop bugging me, I'm done } - BetterBlockPos whereShouldIBe = path.positions().get(pathPosition); + Movement movement = (Movement) path.movements().get(pathPosition); BetterBlockPos whereAmI = ctx.playerFeet(); - if (!whereShouldIBe.equals(whereAmI) && !Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip - for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks - if (whereAmI.equals(path.positions().get(i))) { - logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); + if (!movement.getValidPositions().contains(whereAmI)) { + for (int i = 0; i < pathPosition && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks + if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) { int previousPos = pathPosition; - pathPosition = Math.max(i - 1, 0); // previous step might not actually be done + pathPosition = i; for (int j = pathPosition; j <= previousPos; j++) { path.movements().get(j).reset(); } @@ -115,9 +114,9 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } } - for (int i = pathPosition + 3; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) + for (int i = pathPosition + 3; i < path.length() - 1; i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) // also don't check pathPosition+2 because reasons - if (whereAmI.equals(path.positions().get(i))) { + if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) { if (i - pathPosition > 2) { logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i); } @@ -146,38 +145,6 @@ public class PathExecutor implements IPathExecutor, Helper { cancel(); return false; } - //this commented block is literally cursed. - /*Out.log(actions.get(pathPosition)); - if (pathPosition < actions.size() - 1) {//if there are two ActionBridges in a row and they are at right angles, walk diagonally. This makes it so you walk at 45 degrees along a zigzag path instead of doing inefficient zigging and zagging - if ((actions.get(pathPosition) instanceof ActionBridge) && (actions.get(pathPosition + 1) instanceof ActionBridge)) { - ActionBridge curr = (ActionBridge) actions.get(pathPosition); - ActionBridge next = (ActionBridge) actions.get(pathPosition + 1); - if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two movement are not parallel, so this is a right angle - if (curr.amIGood() && next.amIGood()) {//nothing in the way - BlockPos cornerToCut1 = new BlockPos(next.to.getX() - next.from.getX() + curr.from.getX(), next.to.getY(), next.to.getZ() - next.from.getZ() + curr.from.getZ()); - BlockPos cornerToCut2 = cornerToCut1.up(); - //Block corner1 = Baritone.get(cornerToCut1).getBlock(); - //Block corner2 = Baritone.get(cornerToCut2).getBlock(); - //Out.gui("Cutting conner " + cornerToCut1 + " " + corner1, Out.Mode.Debug); - if (!Action.avoidWalkingInto(cornerToCut1) && !Action.avoidWalkingInto(cornerToCut2)) { - double x = (next.from.getX() + next.to.getX() + 1.0D) * 0.5D; - double z = (next.from.getZ() + next.to.getZ() + 1.0D) * 0.5D; - MovementManager.clearMovement(); - if (!MovementManager.forward && curr.oneInTen != null && curr.oneInTen) { - MovementManager.clearMovement(); - MovementManager.forward = LookManager.lookAtCoords(x, 0, z, false); - } else { - MovementManager.moveTowardsCoords(x, 0, z); - } - if (MovementManager.forward && !MovementManager.backward) { - thePlayer.setSprinting(true); - } - return false; - } - } - } - } - }*/ //long start = System.nanoTime() / 1000000L; BlockStateInterface bsi = new BlockStateInterface(ctx); for (int i = pathPosition - 10; i < pathPosition + 10; i++) { @@ -204,10 +171,10 @@ public class PathExecutor implements IPathExecutor, Helper { HashSet newPlace = new HashSet<>(); HashSet newWalkInto = new HashSet<>(); for (int i = pathPosition; i < path.movements().size(); i++) { - Movement movement = (Movement) path.movements().get(i); - newBreak.addAll(movement.toBreak(bsi)); - newPlace.addAll(movement.toPlace(bsi)); - newWalkInto.addAll(movement.toWalkInto(bsi)); + Movement m = (Movement) path.movements().get(i); + newBreak.addAll(m.toBreak(bsi)); + newPlace.addAll(m.toPlace(bsi)); + newWalkInto.addAll(m.toWalkInto(bsi)); } toBreak = newBreak; toPlace = newPlace; @@ -218,7 +185,14 @@ public class PathExecutor implements IPathExecutor, Helper { if (end - start > 0) { System.out.println("Recalculating break and place took " + (end - start) + "ms"); }*/ - IMovement movement = path.movements().get(pathPosition); + if (pathPosition < path.movements().size() - 1) { + IMovement next = path.movements().get(pathPosition + 1); + if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) { + logDebug("Pausing since destination is at edge of loaded chunks"); + clearKeys(); + return true; + } + } boolean canCancel = movement.safeToCancel(); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { costEstimateIndex = pathPosition; @@ -232,7 +206,7 @@ public class PathExecutor implements IPathExecutor, Helper { } } } - double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext()); + double currentCost = movement.recalculateCost(behavior.secretInternalGetCalculationContext()); if (currentCost >= ActionCosts.COST_INF && canCancel) { logDebug("Something has changed in the world and this movement has become impossible. Cancelling."); cancel(); @@ -284,11 +258,13 @@ public class PathExecutor implements IPathExecutor, Helper { private Tuple closestPathPos(IPath path) { double best = -1; BlockPos bestPos = null; - for (BlockPos pos : path.positions()) { - double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos); - if (dist < best || best == -1) { - best = dist; - bestPos = pos; + for (IMovement movement : path.movements()) { + for (BlockPos pos : ((Movement) movement).getValidPositions()) { + double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos); + if (dist < best || best == -1) { + best = dist; + bestPos = pos; + } } } return new Tuple<>(best, bestPos); @@ -451,7 +427,7 @@ public class PathExecutor implements IPathExecutor, Helper { if (current instanceof MovementFall) { Tuple data = overrideFall((MovementFall) current); if (data != null) { - BlockPos fallDest = data.getB(); + BetterBlockPos fallDest = new BetterBlockPos(data.getB()); if (!path.positions().contains(fallDest)) { throw new IllegalStateException(); } diff --git a/src/main/java/baritone/process/BackfillProcess.java b/src/main/java/baritone/process/BackfillProcess.java index 4bb8b9317..f1e01d5b2 100644 --- a/src/main/java/baritone/process/BackfillProcess.java +++ b/src/main/java/baritone/process/BackfillProcess.java @@ -84,12 +84,14 @@ public final class BackfillProcess extends BaritoneProcessHelper { // patience baritone.getLookBehavior().updateTarget(fake.getTarget().getRotation().get(), true); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + default: + throw new IllegalStateException(); } } return new PathingCommand(null, PathingCommandType.DEFER); // cede to other process } - public void amIBreakingABlockHMMMMMMM() { + private void amIBreakingABlockHMMMMMMM() { if (!ctx.getSelectedBlock().isPresent()) { return; } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 368c9a509..eaf196fe1 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -35,6 +35,7 @@ import baritone.utils.BlockStateInterface; import baritone.utils.PathingCommandContext; import baritone.utils.schematic.AirSchematic; import baritone.utils.schematic.Schematic; +import baritone.utils.schematic.schematica.SchematicaHelper; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import net.minecraft.block.AirBlock; import net.minecraft.block.BlockState; @@ -110,6 +111,20 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return true; } + @Override + public void buildOpenSchematic() { + if (SchematicaHelper.isSchematicaPresent()) { + Optional> schematic = SchematicaHelper.getOpenSchematic(); + if (schematic.isPresent()) { + this.build(schematic.get().getA().toString(), schematic.get().getA(), schematic.get().getB()); + } else { + logDirect("No schematic currently open"); + } + } else { + logDirect("Schematica is not present"); + } + } + public void clearArea(BlockPos corner1, BlockPos corner2) { BlockPos origin = new BlockPos(Math.min(corner1.getX(), corner2.getX()), Math.min(corner1.getY(), corner2.getY()), Math.min(corner1.getZ(), corner2.getZ())); int widthX = Math.abs(corner1.getX() - corner2.getX()) + 1; @@ -158,7 +173,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } BlockState curr = bcc.bsi.get0(x, y, z); - if (!(curr.getBlock() instanceof AirBlock) && !valid(curr, desired)) { + if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired)) { BetterBlockPos pos = new BetterBlockPos(x, y, z); Optional rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); if (rot.isPresent()) { diff --git a/src/main/java/baritone/process/ExploreProcess.java b/src/main/java/baritone/process/ExploreProcess.java index aa7e2c2a6..54c2a6987 100644 --- a/src/main/java/baritone/process/ExploreProcess.java +++ b/src/main/java/baritone/process/ExploreProcess.java @@ -122,6 +122,7 @@ public final class ExploreProcess extends BaritoneProcessHelper implements IExpl break; // note: this breaks the switch not the for case EXPLORED: continue; // note: this continues the for + default: } int centerX = ((chunkX + dx) << 4) + 8; int centerZ = ((chunkZ + dz) << 4) + 8; diff --git a/src/main/java/baritone/process/FarmProcess.java b/src/main/java/baritone/process/FarmProcess.java index d7bce3ae9..60623357b 100644 --- a/src/main/java/baritone/process/FarmProcess.java +++ b/src/main/java/baritone/process/FarmProcess.java @@ -24,6 +24,7 @@ import baritone.api.pathing.goals.GoalComposite; import baritone.api.process.IFarmProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.utils.RayTraceUtils; import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; import baritone.api.utils.input.Input; @@ -36,7 +37,10 @@ import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -50,6 +54,9 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro private boolean active; + private List locations; + private int tickCount; + private static final List FARMLAND_PLANTABLE = Arrays.asList( Items.BEETROOT_SEEDS, Items.MELON_SEEDS, @@ -61,17 +68,16 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro private static final List PICKUP_DROPPED = Arrays.asList( Items.BEETROOT_SEEDS, - Items.WHEAT, + Items.BEETROOT, Items.MELON_SEEDS, Items.MELON_SLICE, + Blocks.MELON.asItem(), Items.WHEAT_SEEDS, Items.WHEAT, Items.PUMPKIN_SEEDS, + Blocks.PUMPKIN.asItem(), Items.POTATO, Items.CARROT, - Items.BEETROOT, - Blocks.PUMPKIN.asItem(), - Blocks.MELON.asItem(), Items.NETHER_WART, Blocks.SUGAR_CANE.asItem(), Blocks.CACTUS.asItem() @@ -89,6 +95,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro @Override public void farm() { active = true; + locations = null; } private enum Harvest { @@ -160,9 +167,12 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro if (Baritone.settings().replantNetherWart.value) { scan.add(Blocks.SOUL_SAND); } - - List locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 4); - + if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) { + Baritone.getExecutor().execute(() -> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 10)); + } + if (locations == null) { + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } List toBreak = new ArrayList<>(); List openFarmland = new ArrayList<>(); List bonemealable = new ArrayList<>(); @@ -212,11 +222,14 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro boolean soulsand = openSoulsand.contains(pos); Optional rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vec3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance()); if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) { - baritone.getLookBehavior().updateTarget(rot.get(), true); - if (ctx.isLookingAt(pos)) { - baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); + RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance()); + if (result instanceof BlockRayTraceResult && ((BlockRayTraceResult) result).getFace() == Direction.UP) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + if (ctx.isLookingAt(pos)) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } - return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } } for (BlockPos pos : bonemealable) { diff --git a/src/main/java/baritone/process/FollowProcess.java b/src/main/java/baritone/process/FollowProcess.java index 072943bd8..728858e9d 100644 --- a/src/main/java/baritone/process/FollowProcess.java +++ b/src/main/java/baritone/process/FollowProcess.java @@ -82,7 +82,12 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo } private void scanWorld() { - cache = Stream.of(ctx.world().loadedEntityList, ctx.world().getPlayers()).flatMap(List::stream).filter(this::followable).filter(this.filter).distinct().collect(Collectors.toCollection(ArrayList::new)); + cache = Stream.of(ctx.world().loadedEntityList, ctx.world().getPlayers()) + .flatMap(List::stream) + .filter(this::followable) + .filter(this.filter) + .distinct() + .collect(Collectors.toCollection(ArrayList::new)); } @Override diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index f1da9117e..16b2f3f94 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -95,6 +95,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } } + if (!Baritone.settings().allowBreak.value) { + logDirect("Unable to mine when allowBreak is false!"); + cancel(); + return null; + } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain @@ -110,7 +115,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro .filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof AirBlock)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =( .min(Comparator.comparingDouble(ctx.playerFeet()::distanceSq)); baritone.getInputOverrideHandler().clearAllKeys(); - if (shaft.isPresent()) { + if (shaft.isPresent() && ctx.player().onGround) { BlockPos pos = shaft.get(); BlockState state = baritone.bsi.get0(pos); if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) { @@ -391,6 +396,10 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro @Override public void mine(int quantity, Block... blocks) { this.mining = blocks == null || blocks.length == 0 ? null : Arrays.asList(blocks); + if (mining != null && !Baritone.settings().allowBreak.value) { + logDirect("Unable to mine when allowBreak is false!"); + mining = null; + } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); this.blacklist = new ArrayList<>(); diff --git a/src/main/java/baritone/utils/BlockBreakHelper.java b/src/main/java/baritone/utils/BlockBreakHelper.java index 2b734f73f..52a487c6d 100644 --- a/src/main/java/baritone/utils/BlockBreakHelper.java +++ b/src/main/java/baritone/utils/BlockBreakHelper.java @@ -39,7 +39,7 @@ public final class BlockBreakHelper implements Helper { this.playerContext = playerContext; } - public void tryBreakBlock(BlockPos pos, Direction side) { + private void tryBreakBlock(BlockPos pos, Direction side) { if (playerContext.playerController().onPlayerDamageBlock(pos, side)) { playerContext.player().swingArm(Hand.MAIN_HAND); } diff --git a/src/main/java/baritone/utils/GuiClick.java b/src/main/java/baritone/utils/GuiClick.java index 4429a8e7b..1a62c071d 100644 --- a/src/main/java/baritone/utils/GuiClick.java +++ b/src/main/java/baritone/utils/GuiClick.java @@ -77,7 +77,6 @@ public class GuiClick extends Screen implements Helper { currentMouseOver = ((BlockRayTraceResult) result).getPos(); } } - } @Override @@ -131,7 +130,7 @@ public class GuiClick extends Screen implements Helper { } } - public Vec3d toWorld(double x, double y, double z) { + private Vec3d toWorld(double x, double y, double z) { boolean result = gluUnProject((float) x, (float) y, (float) z, MODELVIEW, PROJECTION, VIEWPORT, (FloatBuffer) TO_WORLD_BUFFER.clear()); if (result) { return new Vec3d(TO_WORLD_BUFFER.get(0), TO_WORLD_BUFFER.get(1), TO_WORLD_BUFFER.get(2)); diff --git a/src/main/java/baritone/utils/PathRenderer.java b/src/main/java/baritone/utils/PathRenderer.java index 40b09ea97..0c88693d3 100644 --- a/src/main/java/baritone/utils/PathRenderer.java +++ b/src/main/java/baritone/utils/PathRenderer.java @@ -112,8 +112,6 @@ public final class PathRenderer implements Helper { } //drawManySelectionBoxes(player, Collections.singletonList(behavior.pathStart()), partialTicks, Color.WHITE); - //long start = System.nanoTime(); - // Render the current path, if there is one if (current != null && current.getPath() != null) { @@ -124,8 +122,6 @@ public final class PathRenderer implements Helper { drawPath(next.getPath(), 0, renderView, partialTicks, Baritone.settings().colorNextPath.value, Baritone.settings().fadePath.value, 10, 20); } - //long split = System.nanoTime(); - // If there is a path calculation currently running, render the path calculation process behavior.getInProgress().ifPresent(currentlyRunning -> { currentlyRunning.bestPathSoFar().ifPresent(p -> { @@ -137,11 +133,6 @@ public final class PathRenderer implements Helper { drawManySelectionBoxes(renderView, Collections.singletonList(mr.getDest()), Baritone.settings().colorMostRecentConsidered.value); }); }); - //long end = System.nanoTime(); - //System.out.println((end - split) + " " + (split - start)); - // if (end - start > 0) { - // System.out.println("Frame took " + (split - start) + " " + (end - split)); - //} } public static void drawPath(IPath path, int startIndex, Entity player, float partialTicks, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) { diff --git a/src/main/java/baritone/utils/PathingControlManager.java b/src/main/java/baritone/utils/PathingControlManager.java index 92b66c491..14d921d0f 100644 --- a/src/main/java/baritone/utils/PathingControlManager.java +++ b/src/main/java/baritone/utils/PathingControlManager.java @@ -92,7 +92,7 @@ public class PathingControlManager implements IPathingControlManager { p.secretInternalSetGoal(null); return; } - if (inControlThisTick != inControlLastTick && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) { + if (!Objects.equals(inControlThisTick, inControlLastTick) && command.commandType != PathingCommandType.REQUEST_PAUSE && inControlLastTick != null && !inControlLastTick.isTemporary()) { // if control has changed from a real process to another real process, and the new process wants to do something p.cancelSegmentIfSafe(); // get rid of the in progress stuff from the last process @@ -126,7 +126,7 @@ public class PathingControlManager implements IPathingControlManager { } } - public void postTick() { + private void postTick() { // if we did this in pretick, it would suck // we use the time between ticks as calculation time // therefore, we only cancel and recalculate after the tick for the current path has executed diff --git a/src/main/java/baritone/utils/PlayerMovementInput.java b/src/main/java/baritone/utils/PlayerMovementInput.java index c2e2db2a5..f41e0f629 100644 --- a/src/main/java/baritone/utils/PlayerMovementInput.java +++ b/src/main/java/baritone/utils/PlayerMovementInput.java @@ -23,7 +23,7 @@ import net.minecraft.util.MovementInput; public class PlayerMovementInput extends MovementInput { private final InputOverrideHandler handler; - public PlayerMovementInput(InputOverrideHandler handler) { + PlayerMovementInput(InputOverrideHandler handler) { this.handler = handler; } @@ -31,7 +31,7 @@ public class PlayerMovementInput extends MovementInput { this.moveStrafe = 0.0F; this.moveForward = 0.0F; - jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam + jump = handler.isInputForcedDown(Input.JUMP); // oppa gangnam style if (this.forwardKeyDown = handler.isInputForcedDown(Input.MOVE_FORWARD)) { this.moveForward++; diff --git a/src/main/java/baritone/utils/pathing/Avoidance.java b/src/main/java/baritone/utils/pathing/Avoidance.java index 2cee04c56..f6dd669aa 100644 --- a/src/main/java/baritone/utils/pathing/Avoidance.java +++ b/src/main/java/baritone/utils/pathing/Avoidance.java @@ -22,6 +22,9 @@ import baritone.api.utils.BetterBlockPos; import baritone.api.utils.IPlayerContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import net.minecraft.entity.MobEntity; +import net.minecraft.entity.monster.EndermanEntity; +import net.minecraft.entity.monster.SpiderEntity; +import net.minecraft.entity.monster.ZombiePigmanEntity; import net.minecraft.util.math.BlockPos; import java.util.ArrayList; @@ -70,6 +73,9 @@ public class Avoidance { if (mobCoeff != 1.0D) { ctx.world().loadedEntityList.stream() .filter(entity -> entity instanceof MobEntity) + .filter(entity -> (!(entity instanceof SpiderEntity)) || ctx.player().getBrightness() < 0.5) + .filter(entity -> !(entity instanceof ZombiePigmanEntity) || ((ZombiePigmanEntity) entity).isAngry()) + .filter(entity -> !(entity instanceof EndermanEntity) || ((EndermanEntity) entity).isScreaming()) .forEach(entity -> res.add(new Avoidance(new BlockPos(entity), mobCoeff, Baritone.settings().mobAvoidanceRadius.value))); } return res; diff --git a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java b/src/main/java/baritone/utils/pathing/SegmentedCalculator.java deleted file mode 100644 index 22dab0b17..000000000 --- a/src/main/java/baritone/utils/pathing/SegmentedCalculator.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.utils.pathing; - -import baritone.Baritone; -import baritone.api.pathing.calc.IPath; -import baritone.api.pathing.goals.Goal; -import baritone.api.utils.BetterBlockPos; -import baritone.api.utils.PathCalculationResult; -import baritone.cache.CachedWorld; -import baritone.pathing.calc.AStarPathFinder; -import baritone.pathing.calc.AbstractNodeCostSearch; -import baritone.pathing.movement.CalculationContext; -import baritone.pathing.path.SplicedPath; -import net.minecraft.util.Direction; - -import java.util.Optional; -import java.util.function.Consumer; - -/** - * Calculate and splice many path segments to reach a goal - * - * @author leijurv - */ -public class SegmentedCalculator { - private final BetterBlockPos start; - private final Goal goal; - private final CalculationContext context; - - private SegmentedCalculator(BetterBlockPos start, Goal goal, CalculationContext context) { - this.start = start; - this.goal = goal; - this.context = context; - } - - private Optional doCalc() { - Optional soFar = Optional.empty(); - while (true) { - PathCalculationResult result = segment(soFar.orElse(null)); - switch (result.getType()) { - case SUCCESS_SEGMENT: - case SUCCESS_TO_GOAL: - break; - case FAILURE: // if path calculation failed, we're done - case EXCEPTION: // if path calculation threw an exception, we're done - return soFar; - default: // CANCELLATION and null should not be possible, nothing else has access to this, so it can't have been canceled - throw new IllegalStateException(); - } - IPath segment = result.getPath().orElseThrow(IllegalStateException::new); // path calculation result type is SUCCESS_SEGMENT, so the path must be present - IPath combined = soFar.map(previous -> (IPath) SplicedPath.trySplice(previous, segment, true).orElseThrow(IllegalStateException::new)).orElse(segment); - loadAdjacent(combined.getDest().getX(), combined.getDest().getZ()); - soFar = Optional.of(combined); - if (result.getType() == PathCalculationResult.Type.SUCCESS_TO_GOAL) { - return soFar; - } - } - } - - private void loadAdjacent(int blockX, int blockZ) { - BetterBlockPos bp = new BetterBlockPos(blockX, 64, blockZ); - CachedWorld cached = (CachedWorld) context.getBaritone().getPlayerContext().worldData().getCachedWorld(); - for (int i = 0; i < 4; i++) { - // pathing thread is not allowed to load new cached regions from disk - // it checks if every chunk is loaded before getting blocks from it - // so you see path segments ending at multiples of 512 (plus or minus one) on either x or z axis - // this loads every adjacent chunk to the segment end, so it can continue into the next cached region - BetterBlockPos toLoad = bp.offset(Direction.byHorizontalIndex(i), 16); - cached.tryLoadFromDisk(toLoad.x >> 9, toLoad.z >> 9); - } - } - - private PathCalculationResult segment(IPath previous) { - BetterBlockPos segmentStart = previous != null ? previous.getDest() : start; - AbstractNodeCostSearch search = new AStarPathFinder(segmentStart.x, segmentStart.y, segmentStart.z, goal, new Favoring(previous, context), context); // this is on another thread, so cannot include mob avoidances. - return search.calculate(Baritone.settings().primaryTimeoutMS.value, Baritone.settings().failureTimeoutMS.value); // use normal time settings, not the plan ahead settings, so as to not overwhelm the computer - } - - public static void calculateSegmentsThreaded(BetterBlockPos start, Goal goal, CalculationContext context, Consumer onCompletion, Runnable onFailure) { - Baritone.getExecutor().execute(() -> { - Optional result; - try { - result = new SegmentedCalculator(start, goal, context).doCalc(); - } catch (Exception ex) { - ex.printStackTrace(); - result = Optional.empty(); - } - if (result.isPresent()) { - onCompletion.accept(result.get()); - } else { - onFailure.run(); - } - }); - } -} diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java new file mode 100644 index 000000000..fd0ace8ca --- /dev/null +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicAdapter.java @@ -0,0 +1,52 @@ +/* + * 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.utils.schematic.schematica; + +import baritone.api.utils.ISchematic; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public final class SchematicAdapter implements ISchematic { + private final SchematicWorld schematic; + + public SchematicAdapter(SchematicWorld schematicWorld) { + this.schematic = schematicWorld; + } + + @Override + public IBlockState desiredState(int x, int y, int z) { + return schematic.getSchematic().getBlockState(new BlockPos(x, y, z)); + } + + @Override + public int widthX() { + return schematic.getSchematic().getWidth(); + } + + @Override + public int heightY() { + return schematic.getSchematic().getHeight(); + } + + @Override + public int lengthZ() { + return schematic.getSchematic().getLength(); + } +} diff --git a/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java new file mode 100644 index 000000000..63b85670b --- /dev/null +++ b/src/main/java/baritone/utils/schematic/schematica/SchematicaHelper.java @@ -0,0 +1,45 @@ +/* + * 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.utils.schematic.schematica; + +import baritone.api.utils.ISchematic; +import com.github.lunatrius.schematica.Schematica; +import com.github.lunatrius.schematica.proxy.ClientProxy; +import net.minecraft.util.Tuple; +import net.minecraft.util.math.BlockPos; + +import java.util.Optional; + +public enum SchematicaHelper { + ; + + public static boolean isSchematicaPresent() { + try { + Class.forName(Schematica.class.getName()); + return true; + } catch (ClassNotFoundException | NoClassDefFoundError ex) { + return false; + } + } + + public static Optional> getOpenSchematic() { + return Optional.ofNullable(ClientProxy.schematic) + .map(world -> new Tuple<>(new SchematicAdapter(world), world.position)); + } + +} diff --git a/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java new file mode 100644 index 000000000..280b38a6a --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/core/util/math/MBlockPos.java @@ -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 . + */ + +package com.github.lunatrius.core.util.math; + +import net.minecraft.util.math.BlockPos; + +public class MBlockPos extends BlockPos { + MBlockPos() { + super(6, 6, 6); + } + + @Override + public int getX() { + throw new LinkageError("LOL"); + } + + @Override + public int getY() { + throw new LinkageError("LOL"); + } + + @Override + public int getZ() { + throw new LinkageError("LOL"); + } +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java new file mode 100644 index 000000000..7d786dbd4 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/Schematica.java @@ -0,0 +1,24 @@ +/* + * 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 com.github.lunatrius.schematica; + +import com.github.lunatrius.schematica.proxy.CommonProxy; + +public class Schematica { + public static CommonProxy proxy; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java new file mode 100644 index 000000000..6430dbfcc --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/api/ISchematic.java @@ -0,0 +1,31 @@ +/* + * 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 com.github.lunatrius.schematica.api; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; + +public interface ISchematic { + IBlockState getBlockState(BlockPos var1); + + int getWidth(); + + int getHeight(); + + int getLength(); +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java new file mode 100644 index 000000000..80c1b2a21 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/client/world/SchematicWorld.java @@ -0,0 +1,29 @@ +/* + * 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 com.github.lunatrius.schematica.client.world; + +import com.github.lunatrius.core.util.math.MBlockPos; +import com.github.lunatrius.schematica.api.ISchematic; + +public class SchematicWorld { + public final MBlockPos position = (MBlockPos)(Object)"cringe"; + + public ISchematic getSchematic() { + throw new LinkageError("LOL"); + } +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java new file mode 100644 index 000000000..191d01109 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/ClientProxy.java @@ -0,0 +1,24 @@ +/* + * 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 com.github.lunatrius.schematica.proxy; + +import com.github.lunatrius.schematica.client.world.SchematicWorld; + +public class ClientProxy extends CommonProxy { + public static SchematicWorld schematic; +} diff --git a/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java new file mode 100644 index 000000000..eb3c034e8 --- /dev/null +++ b/src/schematica_api/java/com/github/lunatrius/schematica/proxy/CommonProxy.java @@ -0,0 +1,20 @@ +/* + * 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 com.github.lunatrius.schematica.proxy; + +public abstract class CommonProxy {}