Finished Botania pure daisy & brew support

This commit is contained in:
Zixxl committed 2015-07-15 10:32:32 +02:00
1 parent f65485cd60
commit aa6ad5dadc
3 files changed
+61 -5

No files matched your search

@@ -31,4 +31,44 @@ public class StringHelper {
return sb.toString();
}
public static String wildcardToRegex(String expression) {
if(expression == null) return null;
StringBuilder sb = new StringBuilder();
sb.append('^');
for(int i = 0; i < expression.length(); i ++) {
char c = expression.charAt(i);
switch(c) {
case '*':
sb.append(".*");
break;
case '?':
sb.append('.');
break;
case '(':
case ')':
case '[':
case ']':
case '$':
case '^':
case '.':
case '{':
case '}':
case '|':
case '\\':
sb.append('\\').append(c);
break;
default:
sb.append(c);
break;
}
}
sb.append('$');
return sb.toString();
}
}
@@ -2,11 +2,14 @@ package modtweaker2.mods.botania.handlers;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IIngredient;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.StringHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import stanhebben.zenscript.annotations.ZenClass;
@@ -55,9 +58,11 @@ public class Brew {
@ZenMethod
public static void removeRecipe(String brewName) {
List<RecipeBrew> recipes = new LinkedList<RecipeBrew>();
Matcher matcher = Pattern.compile(StringHelper.wildcardToRegex(brewName)).matcher("");
for(RecipeBrew recipe : BotaniaAPI.brewRecipes) {
if(recipe.getBrew().getKey().equalsIgnoreCase(brewName)) {
matcher.reset(recipe.getBrew().getKey());
if(matcher.matches()) {
recipes.add(recipe);
}
}
@@ -65,7 +70,7 @@ public class Brew {
if(!recipes.isEmpty()) {
MineTweakerAPI.apply(new Remove(recipes));
} else {
LogHelper.logWarning(String.format("No %s recipe found for %s. Command ignored!", name, brewName));
}
}
@@ -8,11 +8,11 @@ import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import modtweaker2.helpers.InputHelper;
import modtweaker2.helpers.LogHelper;
import modtweaker2.helpers.StackHelper;
import modtweaker2.utils.BaseListAddition;
import modtweaker2.utils.BaseListRemoval;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.Optional;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import vazkii.botania.api.BotaniaAPI;
@@ -33,6 +33,12 @@ public class PureDaisy {
}
Object input = InputHelper.toObject(blockInput);
if(input == null || (input instanceof ItemStack && !InputHelper.isABlock((ItemStack)input))) {
LogHelper.logError(String.format("Input must be a block or an oredict entry."));
return;
}
if(input instanceof ItemStack) input = Block.getBlockFromItem(((ItemStack)input).getItem());
ItemStack output = InputHelper.toStack(blockOutput);
@@ -55,11 +61,16 @@ public class PureDaisy {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static void removeRecipe(IIngredient input, @Optional IIngredient output) {
@ZenMethod
public static void removeRecipe(IIngredient output) {
List<RecipePureDaisy> recipes = new LinkedList<RecipePureDaisy>();
for(RecipePureDaisy recipe : BotaniaAPI.pureDaisyRecipes) {
recipes.add(recipe);
IItemStack out = InputHelper.toIItemStack(new ItemStack(recipe.getOutput(), 1, recipe.getOutputMeta()));
if(StackHelper.matches(output, out)) {
recipes.add(recipe);
}
}
if(!recipes.isEmpty()) {