From ceda14096c0a27ae69a9104197effdbde8d69a30 Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 15 Jan 2019 22:07:06 -0600 Subject: [PATCH] Builder Process API exposure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Professional style 💪 --- src/api/java/baritone/api/IBaritone.java | 11 +++-- .../baritone/api/process/IBuilderProcess.java | 49 +++++++++++++++++++ .../java/baritone/api}/utils/ISchematic.java | 34 +++++++++++-- src/main/java/baritone/Baritone.java | 1 + .../java/baritone/process/BuilderProcess.java | 27 ++++++---- .../java/baritone/utils/AirSchematic.java | 1 + src/main/java/baritone/utils/Schematic.java | 1 + 7 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 src/api/java/baritone/api/process/IBuilderProcess.java rename src/{main/java/baritone => api/java/baritone/api}/utils/ISchematic.java (56%) diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 6bdb7d10..a2f414e7 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -22,10 +22,7 @@ import baritone.api.behavior.IPathingBehavior; import baritone.api.cache.IWorldProvider; import baritone.api.event.listener.IEventBus; import baritone.api.pathing.calc.IPathingControlManager; -import baritone.api.process.ICustomGoalProcess; -import baritone.api.process.IFollowProcess; -import baritone.api.process.IGetToBlockProcess; -import baritone.api.process.IMineProcess; +import baritone.api.process.*; import baritone.api.utils.IInputOverrideHandler; import baritone.api.utils.IPlayerContext; @@ -53,6 +50,12 @@ public interface IBaritone { */ IMineProcess getMineProcess(); + /** + * @return The {@link IBuilderProcess} instance + * @see IBuilderProcess + */ + IBuilderProcess getBuilderProcess(); + /** * @return The {@link IPathingBehavior} instance * @see IPathingBehavior diff --git a/src/api/java/baritone/api/process/IBuilderProcess.java b/src/api/java/baritone/api/process/IBuilderProcess.java new file mode 100644 index 00000000..694c8752 --- /dev/null +++ b/src/api/java/baritone/api/process/IBuilderProcess.java @@ -0,0 +1,49 @@ +/* + * 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.api.process; + +import baritone.api.utils.ISchematic; +import net.minecraft.util.math.Vec3i; + +import java.io.File; + +/** + * @author Brady + * @since 1/15/2019 + */ +public interface IBuilderProcess extends IBaritoneProcess { + + /** + * Requests a build for the specified schematic, labeled as specified, with the specified origin. + * + * @param name A user-friendly name for the schematic + * @param schematic The object representation of the schematic + * @param origin The origin position of the schematic being built + */ + void build(String name, ISchematic schematic, Vec3i origin); + + /** + * Requests a build for the specified schematic, labeled as specified, with the specified origin. + * + * @param name A user-friendly name for the schematic + * @param schematic The file path of the schematic + * @param origin The origin position of the schematic being built + * @return Whether or not the schematic was able to load from file + */ + boolean build(String name, File schematic, Vec3i origin); +} diff --git a/src/main/java/baritone/utils/ISchematic.java b/src/api/java/baritone/api/utils/ISchematic.java similarity index 56% rename from src/main/java/baritone/utils/ISchematic.java rename to src/api/java/baritone/api/utils/ISchematic.java index 77ba8634..1f2cd874 100644 --- a/src/main/java/baritone/utils/ISchematic.java +++ b/src/api/java/baritone/api/utils/ISchematic.java @@ -15,11 +15,18 @@ * along with Baritone. If not, see . */ -package baritone.utils; +package baritone.api.utils; import net.minecraft.block.state.IBlockState; +/** + * Basic representation of a schematic. Provides the dimensions and + * the desired statefor a given position relative to the origin. + * + * @author leijurv + */ public interface ISchematic { + /** * Does the block at this coordinate matter to the schematic? *

@@ -28,20 +35,37 @@ public interface ISchematic { * However, in the case of something like a map art, anything that's below the level of the map art doesn't matter, * so this function should return false in that case. (i.e. it doesn't really have to be air below the art blocks) * - * @param x - * @param y - * @param z - * @return + * @param x The x position of the block, relative to the origin + * @param y The y position of the block, relative to the origin + * @param z The z position of the block, relative to the origin + * @return Whether or not the specified position is within the bounds of this schematic */ default boolean inSchematic(int x, int y, int z) { return x >= 0 && x < widthX() && y >= 0 && y < heightY() && z >= 0 && z < lengthZ(); } + /** + * Returns the desired block state at a given (X, Y, Z) position relative to the origin (0, 0, 0). + * + * @param x The x position of the block, relative to the origin + * @param y The y position of the block, relative to the origin + * @param z The z position of the block, relative to the origin + * @return The desired block state at the specified position + */ IBlockState desiredState(int x, int y, int z); + /** + * @return The width (X axis length) of this schematic + */ int widthX(); + /** + * @return The height (Y axis length) of this schematic + */ int heightY(); + /** + * @return The length (Z axis length) of this schematic + */ int lengthZ(); } \ No newline at end of file diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index ec745a27..18f61f7a 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -172,6 +172,7 @@ public class Baritone implements IBaritone { return this.followProcess; } + @Override public BuilderProcess getBuilderProcess() { return this.builderProcess; } diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 1ac201e1..cafbeee0 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -22,16 +22,17 @@ import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalBlock; import baritone.api.pathing.goals.GoalComposite; import baritone.api.pathing.goals.GoalGetToBlock; +import baritone.api.process.IBuilderProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.ISchematic; import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; import baritone.api.utils.input.Input; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; -import baritone.utils.ISchematic; import baritone.utils.PathingCommandContext; import baritone.utils.Schematic; import net.minecraft.block.state.IBlockState; @@ -54,7 +55,8 @@ import java.util.stream.Collectors; import static baritone.api.pathing.movement.ActionCosts.COST_INF; -public class BuilderProcess extends BaritoneProcessHelper { +public class BuilderProcess extends BaritoneProcessHelper implements IBuilderProcess { + public BuilderProcess(Baritone baritone) { super(baritone); } @@ -67,9 +69,20 @@ public class BuilderProcess extends BaritoneProcessHelper { public boolean build(String schematicFile) { File file = new File(new File(Minecraft.getMinecraft().gameDir, "schematics"), schematicFile); System.out.println(file + " " + file.exists()); + return build(schematicFile, file, ctx.playerFeet()); + } + @Override + public void build(String name, ISchematic schematic, Vec3i origin) { + this.name = name; + this.schematic = schematic; + this.origin = origin; + } + + @Override + public boolean build(String name, File schematic, Vec3i origin) { NBTTagCompound tag; - try (FileInputStream fileIn = new FileInputStream(file)) { + try (FileInputStream fileIn = new FileInputStream(schematic)) { tag = CompressedStreamTools.readCompressed(fileIn); } catch (IOException e) { e.printStackTrace(); @@ -78,16 +91,10 @@ public class BuilderProcess extends BaritoneProcessHelper { if (tag == null) { return false; } - build(schematicFile, parse(tag), ctx.playerFeet()); + build(name, parse(tag), origin); return true; } - public void build(String name, ISchematic schematic, Vec3i origin) { - this.name = name; - this.schematic = schematic; - this.origin = origin; - } - private static ISchematic parse(NBTTagCompound schematic) { return new Schematic(schematic); } diff --git a/src/main/java/baritone/utils/AirSchematic.java b/src/main/java/baritone/utils/AirSchematic.java index bced26e7..3d70f1b1 100644 --- a/src/main/java/baritone/utils/AirSchematic.java +++ b/src/main/java/baritone/utils/AirSchematic.java @@ -17,6 +17,7 @@ package baritone.utils; +import baritone.api.utils.ISchematic; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; diff --git a/src/main/java/baritone/utils/Schematic.java b/src/main/java/baritone/utils/Schematic.java index 3fef4b1e..0cae99ca 100644 --- a/src/main/java/baritone/utils/Schematic.java +++ b/src/main/java/baritone/utils/Schematic.java @@ -17,6 +17,7 @@ package baritone.utils; +import baritone.api.utils.ISchematic; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound;