mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 12:32:29 +00:00
Close #68
This commit is contained in:
1 parent
6afd56b8ea
commit
fe2cd5ee4a
5 files changed
+272
-264
No files matched your search
@@ -9,14 +9,14 @@ import stanhebben.zenscript.annotations.ZenMethod;
|
||||
* Transformations can be used to modify an ingredient after it is used in a
|
||||
* crafting recipe. It could reuse the item, damage it or consume multiple
|
||||
* items.
|
||||
*
|
||||
*
|
||||
* @author Stan Hebben
|
||||
*/
|
||||
@ZenExpansion("minetweaker.item.IIngredient")
|
||||
public class IngredientTransform {
|
||||
/**
|
||||
* Makes the item reusable. Prevents consumption of the item upon crafting.
|
||||
*
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return reuse transformer
|
||||
*/
|
||||
@@ -33,7 +33,7 @@ public class IngredientTransform {
|
||||
/**
|
||||
* Damages the item. Also makes the item reusable. Will damage the item for
|
||||
* 1 point upon crafting and consume it when broken.
|
||||
*
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @return damage transformer
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ public class IngredientTransform {
|
||||
* Upon reaching maximum damage, the item will be consumed. Take care to set
|
||||
* the proper condition such that an almost-broken item becomes invalid for
|
||||
* crafting.
|
||||
*
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param damage damage to be applied
|
||||
* @return damage transformer
|
||||
@@ -81,7 +81,7 @@ public class IngredientTransform {
|
||||
/**
|
||||
* Causes the item to be replaced upon crafting. Can be used, for instance,
|
||||
* to return empty bottles or buckets.
|
||||
*
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param withItem replacement item
|
||||
* @return replacement transformer
|
||||
@@ -105,7 +105,7 @@ public class IngredientTransform {
|
||||
* Causes multiple items to be consumed. Take care to set a condition for a
|
||||
* minimum stack size too, as otherwise smaller stacks would still be
|
||||
* accepted for input.
|
||||
*
|
||||
*
|
||||
* @param ingredient target value
|
||||
* @param amount consumption amount
|
||||
* @return consuming transformer
|
||||
@@ -122,7 +122,7 @@ public class IngredientTransform {
|
||||
|
||||
/**
|
||||
* Makes sure there is no return value.
|
||||
*
|
||||
*
|
||||
* @param ingredient
|
||||
* @return
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ public class IngredientTransform {
|
||||
/**
|
||||
* Gives an item back to the player. Also clears the inventory slot at that
|
||||
* position.
|
||||
*
|
||||
*
|
||||
* @param ingredient
|
||||
* @param givenItem
|
||||
* @return
|
||||
|
||||
@@ -6,288 +6,294 @@
|
||||
|
||||
package minetweaker.api.recipes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan
|
||||
*/
|
||||
public class ShapedRecipe implements ICraftingRecipe {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
private final byte[] posy;
|
||||
private final boolean mirrored;
|
||||
private final IRecipeFunction function;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final byte[] posx;
|
||||
private final byte[] posy;
|
||||
private final boolean mirrored;
|
||||
private final IRecipeFunction function;
|
||||
|
||||
private final IItemStack output;
|
||||
private final IIngredient[] ingredients;
|
||||
private final IItemStack output;
|
||||
private final IIngredient[] ingredients;
|
||||
|
||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
|
||||
int numIngredients = 0;
|
||||
for (IIngredient[] row : ingredients) {
|
||||
for (IIngredient ingredient : row) {
|
||||
if (ingredient != null) {
|
||||
numIngredients++;
|
||||
}
|
||||
}
|
||||
}
|
||||
public ShapedRecipe(IItemStack output, IIngredient[][] ingredients, IRecipeFunction function, boolean mirrored) {
|
||||
int numIngredients = 0;
|
||||
for(IIngredient[] row : ingredients) {
|
||||
for(IIngredient ingredient : row) {
|
||||
if(ingredient != null) {
|
||||
numIngredients++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.posx = new byte[numIngredients];
|
||||
this.posy = new byte[numIngredients];
|
||||
this.output = output;
|
||||
this.ingredients = new IIngredient[numIngredients];
|
||||
this.function = function;
|
||||
this.posx = new byte[numIngredients];
|
||||
this.posy = new byte[numIngredients];
|
||||
this.output = output;
|
||||
this.ingredients = new IIngredient[numIngredients];
|
||||
this.function = function;
|
||||
|
||||
int width1 = 0;
|
||||
int height1 = ingredients.length;
|
||||
int width1 = 0;
|
||||
int height1 = ingredients.length;
|
||||
|
||||
int ix = 0;
|
||||
for (int j = 0; j < ingredients.length; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
width1 = Math.max(width1, row.length);
|
||||
int ix = 0;
|
||||
for(int j = 0; j < ingredients.length; j++) {
|
||||
IIngredient[] row = ingredients[j];
|
||||
width1 = Math.max(width1, row.length);
|
||||
|
||||
for (int i = 0; i < row.length; i++) {
|
||||
if (row[i] != null) {
|
||||
this.posx[ix] = (byte) i;
|
||||
this.posy[ix] = (byte) j;
|
||||
this.ingredients[ix] = row[i];
|
||||
ix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < row.length; i++) {
|
||||
if(row[i] != null) {
|
||||
this.posx[ix] = (byte) i;
|
||||
this.posy[ix] = (byte) j;
|
||||
this.ingredients[ix] = row[i];
|
||||
ix++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.width = width1;
|
||||
this.height = height1;
|
||||
this.mirrored = mirrored;
|
||||
}
|
||||
this.width = width1;
|
||||
this.height = height1;
|
||||
this.mirrored = mirrored;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public boolean isMirrored() {
|
||||
return mirrored;
|
||||
}
|
||||
public boolean isMirrored() {
|
||||
return mirrored;
|
||||
}
|
||||
|
||||
public IIngredient[] getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
public IIngredient[] getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public byte[] getIngredientsX() {
|
||||
return posx;
|
||||
}
|
||||
public byte[] getIngredientsX() {
|
||||
return posx;
|
||||
}
|
||||
|
||||
public byte[] getIngredientsY() {
|
||||
return posy;
|
||||
}
|
||||
public byte[] getIngredientsY() {
|
||||
return posy;
|
||||
}
|
||||
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
public IItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
if (inventory.getStackCount() != ingredients.length) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(ICraftingInventory inventory) {
|
||||
if(inventory.getStackCount() != ingredients.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
@Override
|
||||
public IItemStack getCraftingResult(ICraftingInventory inventory) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, false);
|
||||
}
|
||||
}
|
||||
return doRecipe(inventory, stacks, i, j, output, false);
|
||||
}
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
return doRecipe(inventory, stacks, i, j, output, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return doRecipe(inventory, stacks, i, j, output, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for (IIngredient ingredient : ingredients) {
|
||||
if (ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean hasTransformers() {
|
||||
for(IIngredient ingredient : ingredients) {
|
||||
if(ingredient.hasTransformers()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
@Override
|
||||
public void applyTransformers(ICraftingInventory inventory, IPlayer byPlayer) {
|
||||
IItemStack[] stacks = new IItemStack[ingredients.length];
|
||||
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(posx[k] + i, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, false, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
doRecipeTransformers(inventory, stacks, i, j, false, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (mirrored) {
|
||||
for (int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out: for (int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if (item == null)
|
||||
continue out;
|
||||
if(mirrored) {
|
||||
for(int i = 0; i <= inventory.getWidth() - width; i++) {
|
||||
out:
|
||||
for(int j = 0; j <= inventory.getHeight() - height; j++) {
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
IItemStack item = inventory.getStack(inventory.getWidth() - (posx[k] + i) - 1, posy[k] + j);
|
||||
if(item == null)
|
||||
continue out;
|
||||
|
||||
if (!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
if(!ingredients[k].matches(item))
|
||||
continue out;
|
||||
stacks[k] = item;
|
||||
}
|
||||
|
||||
doRecipeTransformers(inventory, stacks, i, j, true, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
doRecipeTransformers(inventory, stacks, i, j, true, byPlayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommandString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("recipes.addShaped(");
|
||||
result.append(output);
|
||||
result.append(", [");
|
||||
@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];
|
||||
}
|
||||
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(", ");
|
||||
}
|
||||
for(int i = 0; i < ingredientsArray.length; i++) {
|
||||
if(i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
|
||||
result.append("[");
|
||||
result.append("[");
|
||||
|
||||
for (int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if (j > 0)
|
||||
result.append(", ");
|
||||
for(int j = 0; j < ingredientsArray[i].length; j++) {
|
||||
if(j > 0)
|
||||
result.append(", ");
|
||||
|
||||
result.append(ingredientsArray[i][j]);
|
||||
}
|
||||
result.append(ingredientsArray[i][j]);
|
||||
}
|
||||
|
||||
result.append("]");
|
||||
}
|
||||
result.append("]");
|
||||
}
|
||||
|
||||
result.append("]);");
|
||||
return result.toString();
|
||||
}
|
||||
result.append("]);");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
IItemStack output,
|
||||
boolean mirrored) {
|
||||
// determine output and apply transformations
|
||||
private IItemStack doRecipe(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
IItemStack output,
|
||||
boolean mirrored) {
|
||||
// determine output and apply transformations
|
||||
|
||||
if (function != null) {
|
||||
Map<String, IItemStack> tagged = new HashMap<String, IItemStack>();
|
||||
for (int k = 0; k < ingredients.length; k++) {
|
||||
if (ingredients[k].getMark() != null) {
|
||||
tagged.put(ingredients[k].getMark(), stacks[k]);
|
||||
}
|
||||
}
|
||||
if(function != null) {
|
||||
Map<String, IItemStack> tagged = new HashMap<String, IItemStack>();
|
||||
for(int k = 0; k < ingredients.length; k++) {
|
||||
if(ingredients[k].getMark() != null) {
|
||||
tagged.put(ingredients[k].getMark(), stacks[k]);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: supply dimension
|
||||
output = function.process(output, tagged, new CraftingInfo(inventory, null));
|
||||
System.out.println("Ouput: " + output);
|
||||
}
|
||||
// TODO: supply dimension
|
||||
output = function.process(output, tagged, new CraftingInfo(inventory, null));
|
||||
System.out.println("Ouput: " + output);
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
if(output == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* for (int i = 0; i < ingredients.length; i++) { IItemStack transformed
|
||||
* for (int i = 0; i < ingredients.length; i++) { IItemStack transformed
|
||||
* = ingredients[i].applyTransform(stacks[i]); if (transformed !=
|
||||
* stacks[i]) { if (mirrored) { inventory.setStack( inventory.getWidth()
|
||||
* - (offx + posx[i]) - 1, offy + posy[i], transformed); } else {
|
||||
@@ -295,30 +301,30 @@ public class ShapedRecipe implements ICraftingRecipe {
|
||||
* }
|
||||
*/
|
||||
|
||||
return output;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private void doRecipeTransformers(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
boolean mirrored,
|
||||
IPlayer byPlayer) {
|
||||
for (int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i], byPlayer);
|
||||
if (transformed != stacks[i]) {
|
||||
if (mirrored) {
|
||||
inventory.setStack(
|
||||
inventory.getWidth() - (offx + posx[i]) - 1,
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
} else {
|
||||
inventory.setStack(
|
||||
offx + posx[i],
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void doRecipeTransformers(
|
||||
ICraftingInventory inventory,
|
||||
IItemStack[] stacks,
|
||||
int offx, int offy,
|
||||
boolean mirrored,
|
||||
IPlayer byPlayer) {
|
||||
for(int i = 0; i < ingredients.length; i++) {
|
||||
IItemStack transformed = ingredients[i].applyTransform(stacks[i], byPlayer);
|
||||
if(transformed != stacks[i]) {
|
||||
if(mirrored) {
|
||||
inventory.setStack(
|
||||
inventory.getWidth() - (offx + posx[i]) - 1,
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
} else {
|
||||
inventory.setStack(
|
||||
offx + posx[i],
|
||||
offy + posy[i],
|
||||
transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -21,7 +21,7 @@ public class ScriptProviderDirectory implements IScriptProvider {
|
||||
private final File directory;
|
||||
|
||||
public ScriptProviderDirectory(File directory) {
|
||||
if (directory == null)
|
||||
if(directory == null)
|
||||
throw new IllegalArgumentException("directory cannot be null");
|
||||
|
||||
this.directory = directory;
|
||||
@@ -30,25 +30,28 @@ public class ScriptProviderDirectory implements IScriptProvider {
|
||||
@Override
|
||||
public Iterator<IScriptIterator> getScripts() {
|
||||
List<IScriptIterator> scripts = new ArrayList<IScriptIterator>();
|
||||
if (directory.exists()) {
|
||||
for (File file : directory.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
if(directory.exists()) {
|
||||
for(File file : directory.listFiles()) {
|
||||
if(file.isDirectory()) {
|
||||
scripts.add(new ScriptIteratorDirectory(file));
|
||||
} else if (file.getName().endsWith(".zs")) {
|
||||
} else if(file.getName().endsWith(".zs")) {
|
||||
scripts.add(new ScriptIteratorSingle(file));
|
||||
} else if (file.getName().endsWith(".zip")) {
|
||||
} else if(file.getName().endsWith(".zip")) {
|
||||
try {
|
||||
scripts.add(new ScriptIteratorZip(file));
|
||||
} catch (IOException ex) {
|
||||
} catch(IOException ex) {
|
||||
MineTweakerAPI.logError("Could not load " + file.getName() + ": " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (scripts.size() > 1)
|
||||
if(scripts.size() > 1)
|
||||
scripts.sort(new Comparator<IScriptIterator>() {
|
||||
@Override
|
||||
public int compare(IScriptIterator sc, IScriptIterator sc1) {
|
||||
if(sc == null || sc1 == null) {
|
||||
return -1;
|
||||
}
|
||||
return sc.getName().compareTo(sc1.getName());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user