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
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
getting closer to a finished product
  • Loading branch information
rycbar0 committed Jun 11, 2023
commit 48dc6749230f2d912b644a24bc6b232cabc2b469
44 changes: 27 additions & 17 deletions src/main/java/baritone/process/CraftingProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package baritone.process;

import baritone.Baritone;
import baritone.api.pathing.goals.*;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalComposite;
import baritone.api.pathing.goals.GoalGetToBlock;
import baritone.api.process.ICraftingProcess;
import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType;
Expand Down Expand Up @@ -112,7 +114,9 @@ public void craftItem(Item item, int amount) {
if (canCraft(item, amount)) {
this.amount = amount;
logDirect("Crafting now " + amount + "x [" + recipe.getRecipeOutput().getDisplayName() + "]");
getACraftingTable();
if (!canCraftInInventory(recipe)) {
getACraftingTable();
}
} else {
logDirect("Insufficient resources.");
}
Expand All @@ -123,7 +127,10 @@ public void craftRecipe(IRecipe recipe, int amount) {
if (canCraft(recipe, amount)) {
this.recipe = recipe;
this.amount = amount;
getACraftingTable();
logDirect("Crafting now " + amount + "x [" + recipe.getRecipeOutput().getDisplayName() + "]");
if (!canCraftInInventory(recipe)) {
getACraftingTable();
}
} else {
logDirect("Insufficient resources.");
}
Expand Down Expand Up @@ -159,8 +166,6 @@ public boolean canCraft(Item item, int amount) {
}
}
return false;
//we maybe still be able to craft but need to mix ingredients.
//example we have 1 oak plank and 1 spruce plank and want to make sticks. this statement could be wrong.
}

@Override
Expand All @@ -170,15 +175,14 @@ public boolean canCraft(IRecipe recipe, int amount) {
for (ItemStack stack : ctx.player().inventory.mainInventory) {
recipeItemHelper.accountStack(stack);
}
//could be inlined but i think that would be not very readable
int outputCount = recipe.getRecipeOutput().getCount();
int times = amount % outputCount == 0 ? amount / outputCount : (amount / outputCount) + 1;
return recipeItemHelper.canCraft(recipe, null, times);
}

@Override
public boolean canCraftInInventory(IRecipe recipe) {
return recipe.canFit(2,2);
return recipe.canFit(2,2) && !ctx.player().isCreative();
}

private void moveItemsToCraftingGrid() {
Expand All @@ -203,36 +207,43 @@ private void takeResultFromOutput() {

if (amount <= 0) {
logDirect("Done");
//we finished crafting
ctx.player().closeScreen();
onLostControl();
}
}

private int getInputCount() {
int stackSize = Integer.MAX_VALUE;
for (int i = 0; i < 9; i++) {
ItemStack itemStack = ((ContainerWorkbench) baritone.getPlayerContext().player().openContainer).craftMatrix.getStackInSlot(i);
if (itemStack.getItem() != Item.getItemFromBlock(Blocks.AIR)) {
stackSize = Math.min(itemStack.getCount(), stackSize);
if (ctx.player().openContainer instanceof ContainerPlayer) {
for (int i = 0; i < 4; i++) {
ItemStack itemStack = ((ContainerPlayer) ctx.player().openContainer).craftMatrix.getStackInSlot(i);
if (itemStack.getItem() != Item.getItemFromBlock(Blocks.AIR)) {
stackSize = Math.min(itemStack.getCount(), stackSize);
}
}
} else if (ctx.player().openContainer instanceof ContainerWorkbench) {
for (int i = 0; i < 9; i++) {
ItemStack itemStack = ((ContainerWorkbench) ctx.player().openContainer).craftMatrix.getStackInSlot(i);
if (itemStack.getItem() != Item.getItemFromBlock(Blocks.AIR)) {
stackSize = Math.min(itemStack.getCount(), stackSize);
}
}
} else {
throw new RuntimeException("Expected a crafting Inventory");
}
return stackSize == Integer.MAX_VALUE ? 0 : stackSize;
}

private void getACraftingTable() {
List<BlockPos> knownLocations = MineProcess.searchWorld(new CalculationContext(baritone, false), new BlockOptionalMetaLookup(Blocks.CRAFTING_TABLE), 64, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
rycbar0 marked this conversation as resolved.
Show resolved Hide resolved
if (knownLocations.isEmpty()) {
//logDirect("There are no crafting tables nearby,");
if (hasCraftingTable()) {
//logDirect("but player has crafting table in inventory.");
placeAt = ctx.playerFeet().north();
} else {
//logDirect("cant do shit.");
logDirect("Recipe requires a crafting table.");
onLostControl();
}
} else {
//logDirect("Pathing now to crafting table");
goal = new GoalComposite(knownLocations.stream().map(this::createGoal).toArray(Goal[]::new));
}
}
Expand Down Expand Up @@ -289,7 +300,6 @@ private void placeCraftingtableNearby() { //this code is so buggy im amazed that
}
}
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
//do placing

placeAt = null;
getACraftingTable();
Expand Down