fix #275: Added WeightedItemStack Handlers
This commit is contained in:
parent
1cf86b9c50
commit
4e92eddfd3
|
@ -1,14 +1,12 @@
|
|||
package modtweaker2.mods.appeng.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderEntry;
|
||||
import appeng.core.features.registries.entries.AppEngGrinderRecipe;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import modtweaker2.helpers.InputHelper;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.mods.appeng.AppliedEnergisticsHelper;
|
||||
|
@ -17,81 +15,116 @@ import modtweaker2.utils.BaseListRemoval;
|
|||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderEntry;
|
||||
import appeng.core.features.registries.entries.AppEngGrinderRecipe;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
@ZenClass("mods.appeng.Grinder")
|
||||
public class Grind {
|
||||
|
||||
protected static final String name = "Applied Energistics 2 Grinder";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
protected static final String name = "Applied Energistics 2 Grindstone";
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe for the Carpenter
|
||||
*
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe for the Grindstone
|
||||
* @param outputs
|
||||
* @param inputStack
|
||||
* @param turns
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(WeightedItemStack[] outputs, IItemStack inputStack, int turns) {
|
||||
IGrinderEntry recipe;
|
||||
if (outputs.length == 1)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputs[0].getStack()), turns);
|
||||
else if (outputs.length == 2)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputs[0].getStack()), InputHelper.toStack(outputs[1].getStack()), outputs[1].getChance(), turns);
|
||||
else if (outputs.length == 3)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputs[0].getStack()), InputHelper.toStack(outputs[1].getStack()), InputHelper.toStack(outputs[2].getStack()), outputs[1].getChance(), outputs[2].getChance(), turns);
|
||||
else {
|
||||
LogHelper.logWarning(String.format("No more then 3 output stacks are allowed in %s. Command ignored!", name, LogHelper.getStackDescription(toStack(inputStack))));
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the recipe is already present, we don't want to add duplicates
|
||||
for (IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if (r != null && AppliedEnergisticsHelper.equals(r, recipe)) {
|
||||
LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s. Command ignored!", name, LogHelper.getStackDescription(toStack(inputStack))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe for the Grindstone
|
||||
*
|
||||
* @param outputStack - Product of the Recipe
|
||||
* @param inputStack - Ingredient of the Recipe
|
||||
* @param inputStack - Ingredient of the Recipe
|
||||
* @param inputEnergy - Energy requirement of the Recipe
|
||||
* @optionalParam outputStack2 - Second product of the Recipe
|
||||
* @optionalParam outputStack2Chance - Chance for the acquirement of the second product
|
||||
* @optionalParam outputStack3 - Third product of the Recipe
|
||||
* @optionalParam outputStack3Chance - Chance for the acquirement of the third product
|
||||
* @param inputEnergy - Energy requirement of the Recipe
|
||||
**/
|
||||
@ZenMethod
|
||||
@Deprecated
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack outputStack, IItemStack inputStack, @Optional IItemStack outputStack2, @Optional float outputStack2Chance, @Optional IItemStack outputStack3, @Optional float outputStack3Chance, int inputEnergy) {
|
||||
if(inputStack == null || outputStack == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create recipe
|
||||
IGrinderEntry recipe;
|
||||
|
||||
if(outputStack2 != null && outputStack3 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), InputHelper.toStack(outputStack2), InputHelper.toStack(outputStack3), outputStack2Chance, outputStack3Chance, inputEnergy);
|
||||
else if(outputStack2 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), InputHelper.toStack(outputStack2), outputStack2Chance, inputEnergy);
|
||||
else
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), inputEnergy);
|
||||
|
||||
// Check if the recipe is already present, we don't want to add duplicates
|
||||
for(IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if(r != null && AppliedEnergisticsHelper.equals(r, recipe)) {
|
||||
LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s. Command ignored!", name, LogHelper.getStackDescription(toStack(inputStack))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (inputStack == null || outputStack == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create recipe
|
||||
IGrinderEntry recipe;
|
||||
|
||||
if (outputStack2 != null && outputStack3 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), InputHelper.toStack(outputStack2), InputHelper.toStack(outputStack3), outputStack2Chance, outputStack3Chance, inputEnergy);
|
||||
else if (outputStack2 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), InputHelper.toStack(outputStack2), outputStack2Chance, inputEnergy);
|
||||
else
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(inputStack), InputHelper.toStack(outputStack), inputEnergy);
|
||||
|
||||
// Check if the recipe is already present, we don't want to add duplicates
|
||||
for (IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if (r != null && AppliedEnergisticsHelper.equals(r, recipe)) {
|
||||
LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s. Command ignored!", name, LogHelper.getStackDescription(toStack(inputStack))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ZenMethod
|
||||
|
||||
@Deprecated
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack input, IItemStack output, int energy, @Optional IItemStack output2, @Optional float chance2, @Optional IItemStack output3, @Optional float chance3) {
|
||||
if(input == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create recipe
|
||||
IGrinderEntry recipe;
|
||||
|
||||
if(output2 != null && output3 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), InputHelper.toStack(output2), InputHelper.toStack(output3), chance2, chance3, energy);
|
||||
else if(output2 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), InputHelper.toStack(output2), chance2, energy);
|
||||
else
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), energy);
|
||||
|
||||
// Check if the recipe is already present, we don't want to add duplicates
|
||||
for(IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if(r != null && AppliedEnergisticsHelper.equals(r, recipe)) {
|
||||
LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s. Command ignored!", name, LogHelper.getStackDescription(toStack(input))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (input == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create recipe
|
||||
IGrinderEntry recipe;
|
||||
|
||||
if (output2 != null && output3 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), InputHelper.toStack(output2), InputHelper.toStack(output3), chance2, chance3, energy);
|
||||
else if (output2 != null)
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), InputHelper.toStack(output2), chance2, energy);
|
||||
else
|
||||
recipe = new AppEngGrinderRecipe(InputHelper.toStack(input), InputHelper.toStack(output), energy);
|
||||
|
||||
// Check if the recipe is already present, we don't want to add duplicates
|
||||
for (IGrinderEntry r : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if (r != null && AppliedEnergisticsHelper.equals(r, recipe)) {
|
||||
LogHelper.logWarning(String.format("Duplicate %s Recipe found for %s. Command ignored!", name, LogHelper.getStackDescription(toStack(input))));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
@ -103,46 +136,46 @@ public class Grind {
|
|||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IGrinderEntry recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean equals(IGrinderEntry recipe, IGrinderEntry otherRecipe) {
|
||||
return AppliedEnergisticsHelper.equals(recipe, otherRecipe);
|
||||
}
|
||||
@Override
|
||||
public String getRecipeInfo(IGrinderEntry recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean equals(IGrinderEntry recipe, IGrinderEntry otherRecipe) {
|
||||
return AppliedEnergisticsHelper.equals(recipe, otherRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Adds a shaped recipe for the Carpenter
|
||||
*
|
||||
* @param outputStack - Product of the Recipe
|
||||
/**
|
||||
* Removes a recipe for the Grindstone
|
||||
*
|
||||
* @param input - Product of the Recipe
|
||||
**/
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient outputStack) {
|
||||
if(outputStack == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get list of existing recipes, matching with parameter
|
||||
LinkedList<IGrinderEntry> result = new LinkedList<IGrinderEntry>();
|
||||
|
||||
for(IGrinderEntry entry : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if(entry != null && entry.getOutput() != null && matches(outputStack, toIItemStack(entry.getOutput()))) {
|
||||
result.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we found the recipes and apply the action
|
||||
if(!result.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(result));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", name, outputStack.toString()));
|
||||
}
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
if (input == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
// Get list of existing recipes, matching with parameter
|
||||
LinkedList<IGrinderEntry> result = new LinkedList<IGrinderEntry>();
|
||||
|
||||
for (IGrinderEntry entry : AEApi.instance().registries().grinder().getRecipes()) {
|
||||
if (entry != null && entry.getOutput() != null && matches(input, toIItemStack(entry.getOutput()))) {
|
||||
result.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we found the recipes and apply the action
|
||||
if (!result.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(result));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", name, input.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval<IGrinderEntry> {
|
||||
|
@ -152,7 +185,7 @@ public class Grind {
|
|||
|
||||
@Override
|
||||
public String getRecipeInfo(IGrinderEntry recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
package modtweaker2.mods.railcraft.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
|
@ -19,31 +12,63 @@ import modtweaker2.utils.BaseListAddition;
|
|||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
@ZenClass("mods.railcraft.BlastFurnace")
|
||||
public class BlastFurnace {
|
||||
|
||||
public static final String name = "Railcraft Blast Furnace";
|
||||
public static final String nameFuel = "Railcraft Blast Furnace (Fuel)";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public static final String name = "Railcraft Blast Furnace";
|
||||
public static final String nameFuel = "Railcraft Blast Furnace (Fuel)";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Add a recipe for the Blast Furnace
|
||||
*
|
||||
* @param output ItemStack result
|
||||
* @param input ItemStack input
|
||||
* @param cookTime time per item to process
|
||||
* @param matchEmptyNBT Set this to true, if you want to match only input items strictly without NBT Data)
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack output, IItemStack input, int cookTime, @Optional Boolean matchEmptyNBT) {
|
||||
if (matchEmptyNBT == null)
|
||||
if (toStack(input).stackTagCompound == null)
|
||||
matchEmptyNBT = false;
|
||||
else
|
||||
matchEmptyNBT = true;
|
||||
|
||||
if (input.getDamage() == OreDictionary.WILDCARD_VALUE)
|
||||
MineTweakerAPI.apply(new Add(RailcraftHelper.getBlastFurnaceRecipe(toStack(input), false, matchEmptyNBT, cookTime, toStack(output))));
|
||||
else
|
||||
MineTweakerAPI.apply(new Add(RailcraftHelper.getBlastFurnaceRecipe(toStack(input), true, matchEmptyNBT, cookTime, toStack(output))));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, int cookTime, IItemStack output) {
|
||||
if(input == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
if (input == null || output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(RailcraftHelper.getBlastFurnaceRecipe(toStack(input), matchDamage, matchNBT, cookTime, toStack(output))));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition<IBlastFurnaceRecipe> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Add(IBlastFurnaceRecipe recipe) {
|
||||
super(BlastFurnace.name, (List<IBlastFurnaceRecipe>)RailcraftHelper.furnace);
|
||||
public Add(IBlastFurnaceRecipe recipe) {
|
||||
super(BlastFurnace.name, (List<IBlastFurnaceRecipe>) RailcraftHelper.furnace);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
|
@ -57,110 +82,110 @@ public class BlastFurnace {
|
|||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient output) {
|
||||
if(output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
List<IBlastFurnaceRecipe> recipes = new LinkedList<IBlastFurnaceRecipe>();
|
||||
|
||||
for (IBlastFurnaceRecipe r : RailcraftHelper.furnace) {
|
||||
if (r != null && r.getOutput() != null && matches(output, toIItemStack(r.getOutput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", BlastFurnace.name, output.toString()));
|
||||
}
|
||||
if (output == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
List<IBlastFurnaceRecipe> recipes = new LinkedList<IBlastFurnaceRecipe>();
|
||||
|
||||
for (IBlastFurnaceRecipe r : RailcraftHelper.furnace) {
|
||||
if (r != null && r.getOutput() != null && matches(output, toIItemStack(r.getOutput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if (!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", BlastFurnace.name, output.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval<IBlastFurnaceRecipe> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Remove(List<IBlastFurnaceRecipe> recipes) {
|
||||
super(BlastFurnace.name, (List<IBlastFurnaceRecipe>)RailcraftHelper.furnace, recipes);
|
||||
super(BlastFurnace.name, (List<IBlastFurnaceRecipe>) RailcraftHelper.furnace, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IBlastFurnaceRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
@Override
|
||||
public String getRecipeInfo(IBlastFurnaceRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getOutput());
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addFuel(IIngredient itemInput) {
|
||||
if(itemInput == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> fuels = new LinkedList<ItemStack>();
|
||||
|
||||
for(IItemStack item : itemInput.getItems()) {
|
||||
|
||||
boolean match = false;
|
||||
|
||||
for(ItemStack fuel : RailcraftHelper.fuels) {
|
||||
if(StackHelper.matches(item, InputHelper.toIItemStack(fuel))) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!match && TileEntityFurnace.isItemFuel(InputHelper.toStack(item))) {
|
||||
fuels.add(InputHelper.toStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
if(!fuels.isEmpty()) {
|
||||
MineTweakerAPI.apply(new AddFuels(fuels));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s added.", nameFuel));
|
||||
}
|
||||
if (itemInput == null) {
|
||||
LogHelper.logError(String.format("Required parameters missing for %s Recipe.", name));
|
||||
return;
|
||||
}
|
||||
|
||||
List<ItemStack> fuels = new LinkedList<ItemStack>();
|
||||
|
||||
for (IItemStack item : itemInput.getItems()) {
|
||||
|
||||
boolean match = false;
|
||||
|
||||
for (ItemStack fuel : RailcraftHelper.fuels) {
|
||||
if (StackHelper.matches(item, InputHelper.toIItemStack(fuel))) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!match && TileEntityFurnace.isItemFuel(InputHelper.toStack(item))) {
|
||||
fuels.add(InputHelper.toStack(item));
|
||||
}
|
||||
}
|
||||
|
||||
if (!fuels.isEmpty()) {
|
||||
MineTweakerAPI.apply(new AddFuels(fuels));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s added.", nameFuel));
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddFuels extends BaseListAddition<ItemStack> {
|
||||
public AddFuels(List<ItemStack> fuels) {
|
||||
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ItemStack recipe) {
|
||||
return LogHelper.getStackDescription(recipe);
|
||||
}
|
||||
public AddFuels(List<ItemStack> fuels) {
|
||||
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ItemStack recipe) {
|
||||
return LogHelper.getStackDescription(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeFuel(IIngredient itemInput) {
|
||||
List<ItemStack> fuels = new LinkedList<ItemStack>();
|
||||
|
||||
for(ItemStack fuel : RailcraftHelper.fuels) {
|
||||
if(StackHelper.matches(itemInput, InputHelper.toIItemStack(fuel))) {
|
||||
fuels.add(fuel);
|
||||
}
|
||||
}
|
||||
|
||||
if(!fuels.isEmpty()) {
|
||||
MineTweakerAPI.apply(new RemoveFuels(fuels));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s found for argument %s.", nameFuel, itemInput.toString()));
|
||||
}
|
||||
List<ItemStack> fuels = new LinkedList<ItemStack>();
|
||||
|
||||
for (ItemStack fuel : RailcraftHelper.fuels) {
|
||||
if (StackHelper.matches(itemInput, InputHelper.toIItemStack(fuel))) {
|
||||
fuels.add(fuel);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fuels.isEmpty()) {
|
||||
MineTweakerAPI.apply(new RemoveFuels(fuels));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s found for argument %s.", nameFuel, itemInput.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveFuels extends BaseListRemoval<ItemStack> {
|
||||
public RemoveFuels(List<ItemStack> fuels) {
|
||||
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ItemStack recipe) {
|
||||
return LogHelper.getStackDescription(recipe);
|
||||
}
|
||||
public RemoveFuels(List<ItemStack> fuels) {
|
||||
super(BlastFurnace.nameFuel, RailcraftHelper.fuels, fuels);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRecipeInfo(ItemStack recipe) {
|
||||
return LogHelper.getStackDescription(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,84 +1,116 @@
|
|||
package modtweaker2.mods.railcraft.handlers;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.WeightedItemStack;
|
||||
import mods.railcraft.api.crafting.IRockCrusherRecipe;
|
||||
import modtweaker2.helpers.LogHelper;
|
||||
import modtweaker2.mods.railcraft.RailcraftHelper;
|
||||
import modtweaker2.utils.BaseListAddition;
|
||||
import modtweaker2.utils.BaseListRemoval;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import stanhebben.zenscript.annotations.Optional;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static modtweaker2.helpers.InputHelper.toIItemStack;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import static modtweaker2.helpers.StackHelper.matches;
|
||||
|
||||
@ZenClass("mods.railcraft.RockCrusher")
|
||||
public class RockCrusher {
|
||||
|
||||
public static final String name = "Railcraft Rock Crusher";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack[] output, double[] chances) {
|
||||
IRockCrusherRecipe recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), matchDamage, matchNBT);
|
||||
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
recipe.addOutput(toStack(output[i]), (float) chances[i]);
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition<IRockCrusherRecipe> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Add(IRockCrusherRecipe recipe) {
|
||||
super(RockCrusher.name, (List<IRockCrusherRecipe>)RailcraftHelper.crusher);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
public static final String name = "Railcraft Rock Crusher";
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IRockCrusherRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Add a recipe for the Rock Crusher
|
||||
*
|
||||
* @param output WeightedItemStack Array of outputs
|
||||
* @param input ItemStack input
|
||||
* @param matchEmptyNBT Set this to true, if you want to match only input items strictly without NBT Data)
|
||||
*/
|
||||
@ZenMethod
|
||||
public static void addRecipe(WeightedItemStack[] output, IItemStack input, @Optional Boolean matchEmptyNBT) {
|
||||
if (matchEmptyNBT == null)
|
||||
if (toStack(input).stackTagCompound == null)
|
||||
matchEmptyNBT = false;
|
||||
else
|
||||
matchEmptyNBT = true;
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<IRockCrusherRecipe> recipes = new LinkedList<IRockCrusherRecipe>();
|
||||
|
||||
for (IRockCrusherRecipe r : RailcraftHelper.crusher) {
|
||||
if (r.getInput() != null && matches(input, toIItemStack(r.getInput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if(!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", RockCrusher.name, input.toString()));
|
||||
}
|
||||
}
|
||||
IRockCrusherRecipe recipe;
|
||||
if (input.getDamage() == OreDictionary.WILDCARD_VALUE)
|
||||
recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), false, matchEmptyNBT);
|
||||
else
|
||||
recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), true, matchEmptyNBT);
|
||||
|
||||
private static class Remove extends BaseListRemoval<IRockCrusherRecipe> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Remove(List<IRockCrusherRecipe> recipes) {
|
||||
super("Rock Crusher", (List<IRockCrusherRecipe>)RailcraftHelper.crusher, recipes);
|
||||
}
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
recipe.addOutput(toStack(output[i].getStack()), output[i].getChance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IRockCrusherRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
}
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ZenMethod
|
||||
public static void addRecipe(IItemStack input, boolean matchDamage, boolean matchNBT, IItemStack[] output, double[] chances) {
|
||||
IRockCrusherRecipe recipe = RailcraftHelper.getRockCrusherRecipe(toStack(input), matchDamage, matchNBT);
|
||||
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
recipe.addOutput(toStack(output[i]), (float) chances[i]);
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(recipe));
|
||||
}
|
||||
|
||||
private static class Add extends BaseListAddition<IRockCrusherRecipe> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Add(IRockCrusherRecipe recipe) {
|
||||
super(RockCrusher.name, (List<IRockCrusherRecipe>) RailcraftHelper.crusher);
|
||||
recipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IRockCrusherRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ZenMethod
|
||||
public static void removeRecipe(IIngredient input) {
|
||||
List<IRockCrusherRecipe> recipes = new LinkedList<IRockCrusherRecipe>();
|
||||
|
||||
for (IRockCrusherRecipe r : RailcraftHelper.crusher) {
|
||||
if (r.getInput() != null && matches(input, toIItemStack(r.getInput()))) {
|
||||
recipes.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
if (!recipes.isEmpty()) {
|
||||
MineTweakerAPI.apply(new Remove(recipes));
|
||||
} else {
|
||||
LogHelper.logWarning(String.format("No %s Recipe found for %s. Command ignored!", RockCrusher.name, input.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Remove extends BaseListRemoval<IRockCrusherRecipe> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Remove(List<IRockCrusherRecipe> recipes) {
|
||||
super("Rock Crusher", (List<IRockCrusherRecipe>) RailcraftHelper.crusher, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipeInfo(IRockCrusherRecipe recipe) {
|
||||
return LogHelper.getStackDescription(recipe.getInput());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue