Smeltery fix and various others

This commit is contained in:
jaredlll08 committed 2015-03-17 23:07:19 +02:00
1 parent 570e4f8607
commit 25feee0162
101 files changed
+2292 -1019

No files matched your search

@@ -0,0 +1,17 @@
package modtweaker2.utils;
import java.util.ArrayList;
public class ArrayUtils {
public static <E> ArrayList<E> toArrayList(E[] array) {
ArrayList<E> list = new ArrayList<E>();
for (E e : array) {
list.add(e);
}
return list;
}
}
@@ -0,0 +1,56 @@
package modtweaker2.utils;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import java.util.List;
import static modtweaker2.helpers.StackHelper.areEqual;
public abstract class BaseCraftingAddition extends BaseDescriptionAddition {
protected final List<IRecipe> list;
protected final boolean shapeless;
protected final ItemStack output;
protected final Object[] recipe;
public BaseCraftingAddition(String name, boolean shapeless, List list, ItemStack output, Object... recipe) {
super(name);
this.shapeless = shapeless;
this.output = output;
this.recipe = recipe;
this.list = list;
}
@Override
public void apply() {
if (shapeless) applyShapeless();
else applyShaped();
}
public abstract void applyShaped();
public abstract void applyShapeless();
@Override
public boolean canUndo() {
return list != null;
}
@Override
public void undo() {
IRecipe remove = null;
for (IRecipe recipe : list) {
if (recipe.getRecipeOutput() != null && areEqual(recipe.getRecipeOutput(), output)) {
remove = recipe;
break;
}
}
list.remove(remove);
}
@Override
public String getRecipeInfo() {
return output.getDisplayName();
}
}
@@ -0,0 +1,31 @@
package modtweaker2.utils;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import java.util.List;
import static modtweaker2.helpers.StackHelper.areEqual;
public class BaseCraftingRemoval extends BaseListRemoval {
public BaseCraftingRemoval(String name, List list, ItemStack stack) {
super(name, list, stack);
}
@Override
public void apply() {
for (IRecipe r : (List<IRecipe>) list) {
if (r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && areEqual(r.getRecipeOutput(), stack)) {
recipe = r;
break;
}
}
list.remove(recipe);
}
@Override
public String getRecipeInfo() {
return stack.getDisplayName();
}
}
@@ -0,0 +1,35 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
public abstract class BaseDescriptionAddition implements IUndoableAction {
protected String description;
public BaseDescriptionAddition(String description) {
this.description = description;
}
@Override
public boolean canUndo() {
return true;
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
return "Adding " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,35 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
public abstract class BaseDescriptionRemoval implements IUndoableAction {
protected String description;
public BaseDescriptionRemoval(String description) {
this.description = description;
}
@Override
public boolean canUndo() {
return true;
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
return "Restoring " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,65 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.List;
public abstract class BaseListAddition implements IUndoableAction {
protected final List list;
protected final Object recipe;
protected String description;
public BaseListAddition(String description, List list, Object recipe) {
this(list, recipe);
this.description = description;
}
public BaseListAddition(List list, Object recipe) {
this.list = list;
this.recipe = recipe;
}
@Override
public void apply() {
list.add(recipe);
}
@Override
public boolean canUndo() {
return list != null;
}
@Override
public void undo() {
list.remove(recipe);
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
if (recipe instanceof ItemStack)
return "Adding " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Adding " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Adding " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
if (recipe instanceof ItemStack)
return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,81 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.List;
public abstract class BaseListRemoval implements IUndoableAction {
protected final String description;
protected final List list;
protected final FluidStack fluid;
protected final ItemStack stack;
protected Object recipe;
public BaseListRemoval(String description, List list, ItemStack stack, FluidStack fluid) {
this.list = list;
this.stack = stack;
this.description = description;
this.fluid = fluid;
}
public BaseListRemoval(String description, List list, ItemStack stack) {
this(description, list, stack, null);
}
public BaseListRemoval(String description, List list, FluidStack fluid) {
this(description, list, null, fluid);
}
public BaseListRemoval(List list, ItemStack stack) {
this(null, list, stack);
}
public BaseListRemoval(List list, FluidStack stack) {
this(null, list, stack);
}
public BaseListRemoval(String description, List list) {
this(description, list, null, null);
}
@Override
public boolean canUndo() {
return list != null;
}
@Override
public void undo() {
list.add(recipe);
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
if (recipe instanceof ItemStack)
return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
if (recipe instanceof ItemStack)
return "Restoring " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Restoring " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Restoring " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,67 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.Map;
public abstract class BaseMapAddition implements IUndoableAction {
protected final Map map;
protected String description;
protected Object key;
protected Object recipe;
public BaseMapAddition(Map map, Object key, Object recipe) {
this(null, map, key, recipe);
}
public BaseMapAddition(String description, Map map, Object key, Object recipe) {
this.map = map;
this.key = key;
this.recipe = recipe;
this.description = description;
}
@Override
public void apply() {
map.put(key, recipe);
}
@Override
public boolean canUndo() {
return map != null;
}
@Override
public void undo() {
map.remove(key);
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
if (recipe instanceof ItemStack)
return "Adding " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Adding " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Adding " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
if (recipe instanceof ItemStack)
return "Removing " + description + " Recipe for :" + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Removing " + description + " Recipe for :" + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,73 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.Map;
public abstract class BaseMapRemoval implements IUndoableAction {
protected final Map map;
protected Object stack;
protected String description;
protected Object key;
protected Object recipe;
public BaseMapRemoval(Object stack, Map map, Object key) {
this(null, map, key, stack);
}
public BaseMapRemoval(String description, Map map, Object stack) {
this(description, map, null, stack);
}
public BaseMapRemoval(String description, Map map, Object key, Object stack) {
this.stack = stack;
this.map = map;
this.key = key;
this.description = description;
}
@Override
public void apply() {
recipe = map.get(key);
map.remove(key);
}
@Override
public boolean canUndo() {
return map != null;
}
@Override
public void undo() {
map.put(key, recipe);
}
public String getRecipeInfo() {
return "Unknown Item";
}
@Override
public String describe() {
if (recipe instanceof ItemStack)
return "Removing " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Removing " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
if (recipe instanceof ItemStack)
return "Restoring " + description + " Recipe for : " + ((ItemStack) recipe).getDisplayName();
else if (recipe instanceof FluidStack)
return "Restoring " + description + " Recipe for : " + ((FluidStack) recipe).getFluid().getLocalizedName();
else return "Restoring " + description + " Recipe for : " + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,83 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import java.util.ArrayList;
import java.util.List;
public abstract class BaseMultipleListRemoval implements IUndoableAction {
protected final Position pos;
protected final String description;
protected final List list;
protected final Object search;
protected ArrayList<Object> recipes;
public BaseMultipleListRemoval(String description, List list, Object search, Position pos) {
this.pos = pos;
this.description = description;
this.list = list;
this.search = search;
}
//Return whether the items are equal or not
protected abstract boolean isEqual(Object recipe, Object search);
@Override
public void apply() {
//Create a new list
recipes = new ArrayList();
for (Object o : list) {
if (isEqual(o, search)) {
//If we want the last position, reset the array
if (pos == Position.LAST) {
recipes = new ArrayList();
}
recipes.add(o);
//If we want the first position, exit the loop
if (pos == Position.FIRST) {
break;
}
}
}
//Remove all the recipes that were considered valid for removal
for (Object o : recipes) {
list.remove(o);
}
}
@Override
public boolean canUndo() {
return recipes != null;
}
@Override
public void undo() {
for (Object o : recipes) {
list.add(o);
}
}
public abstract String getRecipeInfo();
@Override
public String describe() {
return "Removing " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public String describeUndo() {
return "Restoring " + description + " Recipe for :" + getRecipeInfo();
}
@Override
public Object getOverrideKey() {
return null;
}
public static enum Position {
ALL, FIRST, LAST;
}
}
@@ -0,0 +1,56 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
import modtweaker2.helpers.ReflectionHelper;
public abstract class BaseSetVar implements IUndoableAction {
protected final String description;
protected final Class clazz;
protected final String field;
protected final int original;
protected final int newValue;
protected Object object;
public BaseSetVar(String description, Class clazz, Object object, String field, int original, int newValue) {
this(description, clazz, field, original, newValue);
this.object = object;
}
public BaseSetVar(String description, Class clazz, String field, int original, int newValue) {
this.description = description;
this.clazz = clazz;
this.field = field;
this.original = original;
this.newValue = newValue;
}
@Override
public void apply() {
ReflectionHelper.setPrivateValue(clazz, object, field, newValue);
}
@Override
public boolean canUndo() {
return true;
}
@Override
public void undo() {
ReflectionHelper.setPrivateValue(clazz, object, field, original);
}
@Override
public String describe() {
return "Setting " + description + " to " + newValue;
}
@Override
public String describeUndo() {
return "Setting " + description + " to the default value of " + original;
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,15 @@
package modtweaker2.utils;
import minetweaker.IUndoableAction;
public abstract class BaseUndoable implements IUndoableAction {
@Override
public boolean canUndo() {
return true;
}
@Override
public Object getOverrideKey() {
return null;
}
}
@@ -0,0 +1,24 @@
package modtweaker2.utils;
import java.util.ArrayList;
import cpw.mods.fml.common.Loader;
public class TweakerPlugin {
private static ArrayList<String> isLoaded = new ArrayList();
public static void register(String mod, Class clazz) {
if (Loader.isModLoaded(mod)) {
try {
clazz.newInstance();
isLoaded.add(mod);
} catch (Exception e) {
isLoaded.remove(mod);
}
}
}
public static boolean isLoaded(String string) {
return isLoaded.contains(string);
}
}