mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
- Added /mt recipes command
- Added /mt recipes hand command - Removed COMMAND: in front of lines generated from commands
This commit is contained in:
1 parent
f5e467e9a4
commit
9fcf4b9a4e
25 files changed
+617
-42
No files matched your search
@@ -33,6 +33,7 @@ import minetweaker.api.mods.IMod;
|
||||
import minetweaker.api.oredict.IOreDict;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
import minetweaker.api.recipes.ICraftingRecipe;
|
||||
import minetweaker.api.recipes.IFurnaceManager;
|
||||
import minetweaker.api.recipes.IRecipeManager;
|
||||
import minetweaker.api.server.ICommandFunction;
|
||||
@@ -180,6 +181,56 @@ public class MineTweakerImplementationAPI {
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("recipes", new MineTweakerCommand(
|
||||
"recipes",
|
||||
new String[] {
|
||||
"/minetweaker recipes",
|
||||
" Lists all crafting recipes in the game",
|
||||
"/minetweaker recipes hand",
|
||||
" Lists all crafting recipes for the item in your hand",
|
||||
" Also copies the recipes to clipboard"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player)
|
||||
{
|
||||
if (arguments.length == 0) {
|
||||
if (player != null) {
|
||||
player.sendChat("Generating recipe list, this could take a while...");
|
||||
}
|
||||
|
||||
MineTweakerAPI.logCommand("Recipes:");
|
||||
for (ICraftingRecipe recipe : MineTweakerAPI.recipes.getAll()) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
player.sendChat("Recipe list generated; see minetweaker.log in your minecraft dir");
|
||||
}
|
||||
} else if (arguments[0].equals("hand") && player != null) {
|
||||
IItemStack item = player.getCurrentItem();
|
||||
|
||||
List<ICraftingRecipe> recipes = MineTweakerAPI.recipes.getRecipesFor(item.anyAmount());
|
||||
if (recipes.isEmpty()) {
|
||||
player.sendChat("No crafting recipes found for that item");
|
||||
} else {
|
||||
StringBuilder recipesString = new StringBuilder();
|
||||
|
||||
for (ICraftingRecipe recipe : recipes) {
|
||||
MineTweakerAPI.logCommand(recipe.toCommandString());
|
||||
player.sendChat(recipe.toCommandString());
|
||||
recipesString.append(recipe.toCommandString()).append("\n");
|
||||
}
|
||||
|
||||
copyToClipboard(recipesString.toString());
|
||||
}
|
||||
} else {
|
||||
if (player != null) {
|
||||
player.sendChat("Invalid arguments for recipes command");
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
minetweakerCommands.put("inventory", new MineTweakerCommand(
|
||||
"inventory",
|
||||
new String[] {
|
||||
@@ -201,7 +252,9 @@ public class MineTweakerImplementationAPI {
|
||||
"hand",
|
||||
new String[] {
|
||||
"/minetweaker hand",
|
||||
" Outputs the name of the item in your hand"
|
||||
" Outputs the name of the item in your hand",
|
||||
" Also copies the name to clipboard and prints",
|
||||
" oredict entries"
|
||||
}, new ICommandFunction() {
|
||||
@Override
|
||||
public void execute(String[] arguments, IPlayer player) {
|
||||
|
||||
@@ -157,6 +157,14 @@ public interface IItemStack extends IIngredient {
|
||||
@ZenMethod
|
||||
public IItemStack withAmount(int amount);
|
||||
|
||||
/**
|
||||
* Creates an item stack with wildcard stack size.
|
||||
*
|
||||
* @return new, modified item stack
|
||||
*/
|
||||
@ZenMethod
|
||||
public IItemStack anyAmount();
|
||||
|
||||
/**
|
||||
* Creates an item stack with the given nbt tag. Ignores existing tags.
|
||||
*
|
||||
|
||||
@@ -38,7 +38,7 @@ public class FileLogger implements ILogger {
|
||||
@Override
|
||||
public void logCommand(String message) {
|
||||
try {
|
||||
writer.write("COMMAND: " + message + "\n");
|
||||
writer.write(message + "\n");
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface ICraftingRecipe {
|
||||
public boolean hasTransformers();
|
||||
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer);
|
||||
|
||||
public String toCommandString();
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.List;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenGetter;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
/**
|
||||
@@ -14,6 +16,23 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
*/
|
||||
@ZenClass("minetweaker.recipes.IRecipeManager")
|
||||
public interface IRecipeManager {
|
||||
/**
|
||||
* Returns all crafting recipes.
|
||||
*
|
||||
* @return all crafting recipes
|
||||
*/
|
||||
@ZenGetter("all")
|
||||
public List<ICraftingRecipe> getAll();
|
||||
|
||||
/**
|
||||
* Returns all crafting recipes resulting in the given ingredient.
|
||||
*
|
||||
* @param ingredient ingredient to find
|
||||
* @return crafting recipes for the given item(s)
|
||||
*/
|
||||
@ZenMethod
|
||||
public List<ICraftingRecipe> getRecipesFor(IIngredient ingredient);
|
||||
|
||||
/**
|
||||
* Removes all crafting recipes crafting the specified item.
|
||||
*
|
||||
|
||||
@@ -217,6 +217,39 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
|
||||
IIngredient[][] ingredientsArray = new IIngredient[height][width];
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
ingredientsArray[posy[i]][posx[i]] = ingredients[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < ingredientsArray.length; i++) {
|
||||
if (i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
result.append("[");
|
||||
|
||||
for (int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if (j > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredientsArray[i][j]);
|
||||
}
|
||||
|
||||
result.append("]");
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
|
||||
@@ -80,6 +80,26 @@ public class ShapelessRecipe implements ICraftingRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
result.append("recipes.addShapeless(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
if (i > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredients[i]);
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorders ingredients to match the given shapeless recipe.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class UnknownRecipe implements ICraftingRecipe {
|
||||
private final IItemStack output;
|
||||
|
||||
public UnknownRecipe(IItemStack output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
return "// unknown recipe type for " + output;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user