Builder Process API exposure

Professional style 💪
This commit is contained in:
Brady 2019-01-15 22:07:06 -06:00
parent d5b393d6bd
commit ceda14096c
No known key found for this signature in database
GPG Key ID: 73A788379A197567
7 changed files with 105 additions and 19 deletions

View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}

View File

@ -15,11 +15,18 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
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?
* <p>
@ -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();
}

View File

@ -172,6 +172,7 @@ public class Baritone implements IBaritone {
return this.followProcess;
}
@Override
public BuilderProcess getBuilderProcess() {
return this.builderProcess;
}

View File

@ -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);
}

View File

@ -17,6 +17,7 @@
package baritone.utils;
import baritone.api.utils.ISchematic;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;

View File

@ -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;