Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crafting command #3960

Draft
wants to merge 44 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e14afe5
Create CraftCommand.java
strubium May 18, 2023
aa18fdf
Update CraftCommand.java
strubium May 18, 2023
5c0fe9c
Update Settings.java
strubium May 18, 2023
15efa2b
More info in description
strubium May 18, 2023
4c5a5da
Update DefaultCommands.java
strubium May 18, 2023
31976c1
Add chat notifier
strubium May 18, 2023
6e71d89
Merge pull request #5 from strubium/master
rycbar0 May 22, 2023
1547431
prototype
rycbar0 May 25, 2023
a443dcc
not sure if this goes in the right direction
rycbar0 May 25, 2023
e7a36ec
resolving some mixin problems
rycbar0 May 26, 2023
98c1d64
revert some changes as they didnt worked out.
rycbar0 May 28, 2023
645dbc4
Update CraftingProcess.java
strubium Jun 2, 2023
5c61f53
Merge pull request #6 from strubium/patch-1
rycbar0 Jun 6, 2023
b009df2
craft-ability check
rycbar0 Jun 7, 2023
13c31c1
refactoring
rycbar0 Jun 7, 2023
c34eb89
small fix
rycbar0 Jun 8, 2023
49a33d0
remove autocraft setting because unused
rycbar0 Jun 8, 2023
79e417e
refactoring CraftingProcess
rycbar0 Jun 8, 2023
8d1b2c7
delete mixins because unused
rycbar0 Jun 8, 2023
1cb53c7
delete mixins because unused
rycbar0 Jun 8, 2023
c1f2d0c
revert changes on GetToBlockProcess
rycbar0 Jun 8, 2023
6d34c50
im hard at my limit here
rycbar0 Jun 8, 2023
f5c50df
i need help
rycbar0 Jun 8, 2023
f79077f
its amazing that it works sometimes
rycbar0 Jun 9, 2023
eae2dc3
delete extra line
rycbar0 Jun 11, 2023
ecfbc49
craft command
rycbar0 Jun 11, 2023
48dc674
getting closer to a finished product
rycbar0 Jun 11, 2023
0a85399
todos
rycbar0 Jun 11, 2023
4e71b04
codacy and selecting crafting table
rycbar0 Jun 13, 2023
d8c8884
comments and edge cases
rycbar0 Jun 13, 2023
857acd4
copying a good part of builder process
rycbar0 Jun 14, 2023
4285f53
small tweaks
rycbar0 Jun 14, 2023
8c40be4
i think its ready
rycbar0 Jun 14, 2023
49e7892
Merge branch 'cabaletta:master' into crafting
rycbar0 Jun 14, 2023
7eed809
Merge remote-tracking branch 'origin/crafting' into crafting
rycbar0 Jun 14, 2023
32bd0b4
changes on CraftCommand
rycbar0 Jun 15, 2023
15a4cc3
changes on CraftingProcess
rycbar0 Jun 15, 2023
df3f7a3
changes on CraftingProcess II
rycbar0 Jun 17, 2023
29d1df4
add recipe switching for item crafting
rycbar0 Jun 17, 2023
1ef0feb
ready for round two
rycbar0 Jun 17, 2023
913ae06
Merge remote-tracking branch 'upstream/master' into crafting
rycbar0 Jun 18, 2023
fbd1e0c
oopsie
rycbar0 Jun 18, 2023
6ddfdd5
change CraftCommand
rycbar0 Jun 20, 2023
927fa43
CraftingProcess uses now List<IRecipe>
rycbar0 Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
prototype
  • Loading branch information
rycbar0 committed May 25, 2023
commit 1547431c1cfc402305e3cbbf53e7cbeece976d06
6 changes: 6 additions & 0 deletions src/api/java/baritone/api/IBaritone.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public interface IBaritone {
*/
IGetToBlockProcess getGetToBlockProcess();

/**
* @return The {@link IGetToBlockProcess} instance
* @see IGetToBlockProcess
*/
ICraftingProcess getCraftingProcess();

/**
* @return The {@link IWorldProvider} instance
* @see IWorldProvider
Expand Down
69 changes: 69 additions & 0 deletions src/api/java/baritone/api/process/ICraftingProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.BlockOptionalMeta;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.IRecipe;

import java.util.ArrayList;

/**
* but it rescans the world every once in a while so it doesn't get fooled by its cache
*/
public interface ICraftingProcess extends IBaritoneProcess {

//todo this is a copy paste of the IgetToBlockProcess and hasnt been cleand up


void getToBlock(BlockOptionalMeta block);

default void getToBlock(Block block) {
getToBlock(new BlockOptionalMeta(block));
}

boolean blacklistClosest();

/**
* @param item that should be crafted
* @return Can the item be crafted in a crafting table?
*/
boolean hasCraftingRecipe(Item item);

/**
* @param item that should be crafted
* @return List of all recipies that result in the provided Item.
*/
ArrayList<IRecipe> getCraftingRecipes(Item item);

/**
* Checks if the requested item can be crafted the requested amount of times.
* @param item that should be crafted
* @param amount how much of that item is wanted.
* @return
*/
boolean canCraft(Item item, int amount);

/**
* Executes the crafting of the requested item the requested amount of times.
* @param item that should be crafted
* @param amount how much of that item is wanted.
*/
void craft(Item item, int amount);
}
7 changes: 7 additions & 0 deletions src/main/java/baritone/Baritone.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class Baritone implements IBaritone {
private ExploreProcess exploreProcess;
private BackfillProcess backfillProcess;
private FarmProcess farmProcess;
private CraftingProcess craftingProcess;
private InventoryPauserProcess inventoryPauserProcess;

private PathingControlManager pathingControlManager;
Expand Down Expand Up @@ -116,6 +117,7 @@ public class Baritone implements IBaritone {
this.pathingControlManager.registerProcess(exploreProcess = new ExploreProcess(this));
this.pathingControlManager.registerProcess(backfillProcess = new BackfillProcess(this));
this.pathingControlManager.registerProcess(farmProcess = new FarmProcess(this));
this.pathingControlManager.registerProcess(craftingProcess = new CraftingProcess(this));
this.pathingControlManager.registerProcess(inventoryPauserProcess = new InventoryPauserProcess(this));
}

Expand Down Expand Up @@ -148,6 +150,11 @@ public GetToBlockProcess getGetToBlockProcess() {
return this.getToBlockProcess;
}

@Override
public CraftingProcess getCraftingProcess() {
return this.craftingProcess;
}

@Override
public IPlayerContext getPlayerContext() {
return this.playerContext;
Expand Down
43 changes: 28 additions & 15 deletions src/main/java/baritone/command/defaults/CraftCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
import baritone.api.IBaritone;
import baritone.api.command.Command;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.datatypes.BlockById;
import baritone.api.command.datatypes.ForBlockOptionalMeta;
import baritone.api.command.datatypes.RelativeCoordinate;
import baritone.api.command.datatypes.RelativeGoal;
import baritone.api.command.exception.CommandException;
import baritone.api.pathing.goals.Goal;
import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.BlockOptionalMeta;
import net.minecraft.item.Item;

import java.util.Arrays;
import java.util.List;
Expand All @@ -41,24 +35,43 @@ protected CraftCommand(IBaritone baritone) {

@Override
public void execute(String label, IArgConsumer args) throws CommandException {
logDirect("Crafting");
table = minecraft:crafting_table
baritone.getGetToBlockProcess().getToBlock(table);
//todo works for simple items like "stick" but items like "granite" aren't parsed because they are stone:1
rycbar0 marked this conversation as resolved.
Show resolved Hide resolved
Item item = Item.getByNameOrId(args.getString());

int amount = args.hasAny() ? args.getAs(Integer.class) : 1;

if (item == null) {
logDirect("invalid Item");
} else if (!baritone.getCraftingProcess().hasCraftingRecipe(item)) {
logDirect("no crafting recipe for "+item.getTranslationKey()+" found.");
/*todo missing feature check if we can craft before we walk to a crafting table
} else if (BaritoneAPI.getSettings().allowAutoCraft.value && !baritone.getCraftingProcess().canCraft(item, amount)) {
logDirect("trying to craft "+ item.getTranslationKey());
logDirect("not enough resources in inventory");
/**/
} else {
baritone.getCraftingProcess().craft(item, amount);
}
}

@Override
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
//todo add autocomplete for items
rycbar0 marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

@Override
public String getShortDesc() {
return "Go to a crafting table";
return "Craft a item.";
}

@Override
public List<String> getLongDesc() {
return Arrays.asList(
"The craft command tells Baritone to head towards the closest crafting table, then begin crafting. ",
"Requires allowInventory to be true",
"Go to a crafting table and craft a item.",
"",
"Usage:",
"> craft - Go to a crafting table, wherever it is in the world",
"> craft <item> <amount> - Go to a crafting table, and craft a item."
);
}
}
}
Loading