-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
rycbar0
wants to merge
44
commits into
cabaletta:master
Choose a base branch
from
rycbar0:crafting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+638
−1
Draft
Add Crafting command #3960
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
e14afe5
Create CraftCommand.java
strubium aa18fdf
Update CraftCommand.java
strubium 5c0fe9c
Update Settings.java
strubium 15efa2b
More info in description
strubium 4c5a5da
Update DefaultCommands.java
strubium 31976c1
Add chat notifier
strubium 6e71d89
Merge pull request #5 from strubium/master
rycbar0 1547431
prototype
rycbar0 a443dcc
not sure if this goes in the right direction
rycbar0 e7a36ec
resolving some mixin problems
rycbar0 98c1d64
revert some changes as they didnt worked out.
rycbar0 645dbc4
Update CraftingProcess.java
strubium 5c61f53
Merge pull request #6 from strubium/patch-1
rycbar0 b009df2
craft-ability check
rycbar0 13c31c1
refactoring
rycbar0 c34eb89
small fix
rycbar0 49a33d0
remove autocraft setting because unused
rycbar0 79e417e
refactoring CraftingProcess
rycbar0 8d1b2c7
delete mixins because unused
rycbar0 1cb53c7
delete mixins because unused
rycbar0 c1f2d0c
revert changes on GetToBlockProcess
rycbar0 6d34c50
im hard at my limit here
rycbar0 f5c50df
i need help
rycbar0 f79077f
its amazing that it works sometimes
rycbar0 eae2dc3
delete extra line
rycbar0 ecfbc49
craft command
rycbar0 48dc674
getting closer to a finished product
rycbar0 0a85399
todos
rycbar0 4e71b04
codacy and selecting crafting table
rycbar0 d8c8884
comments and edge cases
rycbar0 857acd4
copying a good part of builder process
rycbar0 4285f53
small tweaks
rycbar0 8c40be4
i think its ready
rycbar0 49e7892
Merge branch 'cabaletta:master' into crafting
rycbar0 7eed809
Merge remote-tracking branch 'origin/crafting' into crafting
rycbar0 32bd0b4
changes on CraftCommand
rycbar0 15a4cc3
changes on CraftingProcess
rycbar0 df3f7a3
changes on CraftingProcess II
rycbar0 29d1df4
add recipe switching for item crafting
rycbar0 1ef0feb
ready for round two
rycbar0 913ae06
Merge remote-tracking branch 'upstream/master' into crafting
rycbar0 fbd1e0c
oopsie
rycbar0 6ddfdd5
change CraftCommand
rycbar0 927fa43
CraftingProcess uses now List<IRecipe>
rycbar0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.command.datatypes; | ||
|
||
import baritone.api.command.exception.CommandException; | ||
import baritone.api.command.helpers.TabCompleteHelper; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* @author ZacSharp | ||
* written for a yet unmerged #pickUp command | ||
*/ | ||
public enum ItemById implements IDatatypeFor<Item> { | ||
INSTANCE; | ||
|
||
@Override | ||
public Item get(IDatatypeContext ctx) throws CommandException { | ||
Item item; | ||
if ((item = Item.getByNameOrId(ctx.getConsumer().getString())) == null) { | ||
throw new IllegalArgumentException("No item found by that id"); | ||
} | ||
return item; | ||
} | ||
|
||
@Override | ||
public Stream<String> tabComplete(IDatatypeContext ctx) throws CommandException { | ||
return new TabCompleteHelper() | ||
.append(Item.REGISTRY.getKeys().stream().map(ResourceLocation::toString)) | ||
.filterPrefixNamespaced(ctx.getConsumer().getString()) | ||
.sortAlphabetically() | ||
.stream(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 net.minecraft.item.Item; | ||
import net.minecraft.item.crafting.IRecipe; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Allows you to craft items. | ||
*/ | ||
public interface ICraftingProcess extends IBaritoneProcess { | ||
|
||
/** | ||
* Executes the crafting of the requested item such that we obtain the requested amount. | ||
* @param item that should be crafted | ||
* @param amount how much of that item is wanted. | ||
*/ | ||
void craftItem(Item item, int amount); | ||
|
||
/** | ||
* Executes the crafting of the requested recipe such that we obtain the requested amount of output. | ||
* @param recipe recipe that should be used. | ||
* @param amount how many result items are wanted. | ||
*/ | ||
void craftRecipe(IRecipe recipe, int amount); | ||
|
||
/** | ||
* @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 recipes that result in the provided Item. | ||
*/ | ||
List<IRecipe> getCraftingRecipes(Item item); | ||
|
||
/** | ||
* @param item that should be crafted. | ||
* @param amount how much of this item should be crafted. | ||
* @return Can we craft this item the requested amount of times? | ||
*/ | ||
boolean canCraft(Item item, int amount); | ||
|
||
/** | ||
* @param recipe that should be crafted. | ||
* @param amount how much output is wanted. | ||
* @return Can we craft this recipe to get the requested amount of output? | ||
*/ | ||
boolean canCraft(IRecipe recipe, int amount); | ||
|
||
/** | ||
* @param recipe the recipe we want to craft. | ||
* @return Do we need a crafting table or can we craft it in our inventory? | ||
*/ | ||
boolean canCraftInInventory(IRecipe recipe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/baritone/command/defaults/CraftCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.command.defaults; | ||
|
||
import baritone.api.IBaritone; | ||
import baritone.api.command.Command; | ||
import baritone.api.command.argument.IArgConsumer; | ||
import baritone.api.command.datatypes.ItemById; | ||
import baritone.api.command.exception.CommandException; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.crafting.CraftingManager; | ||
import net.minecraft.item.crafting.IRecipe; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class CraftCommand extends Command { | ||
|
||
protected CraftCommand(IBaritone baritone) { | ||
super(baritone, "craft"); | ||
} | ||
|
||
@Override | ||
public void execute(String label, IArgConsumer args) throws CommandException { | ||
int amount = args.getAsOrDefault(Integer.class, 1); | ||
|
||
Item item = args.getAsOrNull(Item.class); | ||
|
||
if (item == null) { | ||
String itemName = args.rawRest(); | ||
//boolean recipeExists = false; | ||
for (IRecipe recipe : CraftingManager.REGISTRY) { | ||
if (recipe.getRecipeOutput().getDisplayName().equalsIgnoreCase(itemName)) { | ||
if (baritone.getCraftingProcess().canCraft(recipe, amount)) { | ||
baritone.getCraftingProcess().craftRecipe(recipe, amount); | ||
return; | ||
} /*else { //a recipe exists but we cant craft it | ||
recipeExists = true; | ||
}/**/ | ||
} | ||
}/* | ||
if (recipeExists) { | ||
logDirect("Insufficient Resources"); | ||
} else { | ||
logDirect("Invalid Item"); | ||
}/**/ | ||
} else if (!baritone.getCraftingProcess().hasCraftingRecipe(item)) { | ||
logDirect("no crafting recipe for "+item.getTranslationKey()+" found."); | ||
} else if (!baritone.getCraftingProcess().canCraft(item, amount)){ | ||
logDirect("Insufficient Resources"); | ||
} else { | ||
baritone.getCraftingProcess().craftItem(item, amount); | ||
} | ||
} | ||
|
||
@Override | ||
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException { | ||
while (args.has(2)) { | ||
if (args.peekDatatypeOrNull(ItemById.INSTANCE) == null) { | ||
return Stream.empty(); | ||
} | ||
args.get(); | ||
} | ||
return args.tabCompleteDatatype(ItemById.INSTANCE); | ||
} | ||
|
||
@Override | ||
public String getShortDesc() { | ||
return "Craft a item."; | ||
} | ||
|
||
@Override | ||
public List<String> getLongDesc() { | ||
return Arrays.asList( | ||
"Go to a crafting table and craft a item.", | ||
"", | ||
"Usage:", | ||
"> craft [quantity] <item> - Go to a crafting table, and craft a item.", | ||
"Examples:", | ||
"> craft 17 planks -> will craft 20 planks out of any logs you have.", | ||
"> craft oak wood planks -> will craft 4 oak wood planks." | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll take that as my fault. The method I wanted was
getDatatypeForOrNull
(basically the same but works without the wrapper arg parser) and I should have looked it up instead of guessing a name which ended up existing with slightly different functionality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no IDatatypeFor for Integers so i would have to add that before i could use getDatatypeForOrDefault() which in my opinion is nonsense. For the item, what is wrong with getAsOrNull()? i will do it but i dont understand why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can freely mix datatypes and arg types so you can use
getAsOrDefault
for the integer andgetDatatypeForOrNull
for the item. That way you don't need to create a new parser for either of them.