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
comments and edge cases
  • Loading branch information
rycbar0 committed Jun 13, 2023
commit d8c8884bd1f86ab4c40a401fd5a9b459b6e764ab
19 changes: 15 additions & 4 deletions src/main/java/baritone/command/defaults/CraftCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,28 @@ public void execute(String label, IArgConsumer args) throws CommandException {

if (item == null) {//this is hacky, but it gets the job done for now. also we arnt interested in non craft-able items anyway
itemName = itemName.replace("_", " ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reverse the order to be [quantity] <item> like for #mine? That way you can try getting an integer (is there something called args.getAsOrDefault?) and then an item and if the item fails you can do args.rawRest instead of replacing underscores with spaces.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to first get the item by id or name and then do the same for both. You should at least move the item-by-name thingy into a helper method which returns just an item (no logging etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand the logic behind the first comment but not the second.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically I mean you should first get the item by either method (id or name) and then continue along the same code path for both cases.
Currently this is

get item by id
if that failed
      get by name
     handle all the resource counting
else
     handle all the resource counting slightly differently

and I think it should be

get item by id
if that failed
    get item by name
handle all the resource counting (the same for both)

Why should there be a difference between #craft wooden_sword and #craft wooden sword?
Not sure how easy that is though, due to the way you use items in the id case and recipes in the name case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it maybe doesnt make that much sense with a wooden sword as there only exist 1 wooden sword.
take the example of a red bed

if you type: #craft bed it will craft any bed this can be a white bed, a blue bed or a red bed.
if you type #craft red bed it wont find a item that is named like that so it searches a recipe that produces a item stack with that display name. note here that there are 2 recipes for red beds, one with red wool and one dying a white bed.

i use crafItem() if i want any instance of that item crafted and i use craftRecipe() if i want baritone to use that specific recipe to craft

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you get all recipes that produce the desired item (be it by name or id) and then use that collection of recipes from that point on? That way there is only one case (n recipes) instead of two. In general even if the user specified one exact item there can still be multiple recipes for it and the current recipe switching mechanism is sketchy (doesn't it even bypass what you said about #craft red bed because redBedRecipe.getRecipeOutput().getItem() == Items.BED and getting a recipe for that doesn't need to return redBedRecipe again?).

boolean recipeExists = false;
for (IRecipe recipe : CraftingManager.REGISTRY) {
if (recipe.getRecipeOutput().getDisplayName().equalsIgnoreCase(itemName)) {
baritone.getCraftingProcess().craftRecipe(recipe, amount);
return;
if (baritone.getCraftingProcess().canCraft(recipe, amount)) {
baritone.getCraftingProcess().craftRecipe(recipe, amount);
return;
} else { //a recipe exists but we cant craft it
recipeExists = true;
}
}
}
logDirect("invalid Item");
if (recipeExists) {
logDirect("Insufficient Resources");
} else {
logDirect("Invalid Item");
}
} else if (!baritone.getCraftingProcess().hasCraftingRecipe(item)) {
logDirect("no crafting recipe for "+item.getTranslationKey()+" found.");
} else {
} else if (baritone.getCraftingProcess().canCraft(item, amount)){
baritone.getCraftingProcess().craftItem(item, amount);
} else {
logDirect("Insufficient Resources");
}
}

Expand Down
28 changes: 15 additions & 13 deletions src/main/java/baritone/process/CraftingProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCa
onLostControl();
}
if (goal != null) {
//we are pathing to a table and therefor have to wait.
if (goal.isInGoal(ctx.playerFeet())) {
rightClick();
if (ctx.player().openContainer instanceof ContainerWorkbench) {
goal = null;
}
}
//we are pathing to a table and therefor have to wait.
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
} else if (placeAt != null) {
placeCraftingtableNearby();
Expand Down Expand Up @@ -269,25 +269,27 @@ private boolean rightClick() { //shamelessly copied from go to block process
bp = ((GoalGetToBlock)goal).getGoalPos();
break;
}
logDirect("error rightclick was called without being next to goal. will throw nullpointer & crash mc");
}
} else {
bp = ((GoalGetToBlock)goal).getGoalPos();
}
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), bp, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
baritone.getLookBehavior().updateTarget(reachable.get(), true);
if (bp.equals(ctx.getSelectedBlock().orElse(null))) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
System.out.println(ctx.player().openContainer);
if (!(ctx.player().openContainer instanceof ContainerPlayer)) {
baritone.getInputOverrideHandler().clearAllKeys();
return true;
if (bp != null) {
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), bp, ctx.playerController().getBlockReachDistance());
if (reachable.isPresent()) {
baritone.getLookBehavior().updateTarget(reachable.get(), true);
if (bp.equals(ctx.getSelectedBlock().orElse(null))) {
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
System.out.println(ctx.player().openContainer);
if (!(ctx.player().openContainer instanceof ContainerPlayer)) {
baritone.getInputOverrideHandler().clearAllKeys();
return true;
}
}
return false;
}
return false;
return true;
}
return true;
return false;
}

private void placeCraftingtableNearby() { //this code is so buggy im amazed that there are special cases where it works
Expand Down