[ci skip] spotlessApply with the new settings

This commit is contained in:
Raven Szewczyk committed 2023-01-30 13:37:30 +00:00
1 parent 0cc3fa06c2
commit 655636b7e9
231 files changed
+10024 -8585

No files matched your search

@@ -4,14 +4,12 @@ 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;
}
public static <E> ArrayList<E> toArrayList(E[] array) {
ArrayList<E> list = new ArrayList<E>();
for (E e : array) {
list.add(e);
}
return list;
}
}
@@ -3,6 +3,7 @@ package modtweaker2.utils;
import java.util.List;
import modtweaker2.helpers.LogHelper;
import net.minecraft.item.crafting.IRecipe;
public abstract class BaseCraftingAddition extends BaseListAddition<IRecipe> {
@@ -10,11 +11,11 @@ public abstract class BaseCraftingAddition extends BaseListAddition<IRecipe> {
protected BaseCraftingAddition(String name, List<IRecipe> list) {
super(name, list);
}
protected BaseCraftingAddition(String name, List<IRecipe> list, List<IRecipe> recipes) {
super(name, list, recipes);
}
@Override
protected String getRecipeInfo(IRecipe recipe) {
return LogHelper.getStackDescription(recipe.getRecipeOutput());
@@ -8,28 +8,32 @@ import java.util.List;
import minetweaker.api.item.IIngredient;
import modtweaker2.helpers.LogHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
public class BaseCraftingRemoval extends BaseListRemoval<IRecipe> {
public BaseCraftingRemoval(String name, List<IRecipe> list, List<IRecipe> recipes) {
super(name, list, recipes);
}
public BaseCraftingRemoval(String name, List<IRecipe> list, List<IRecipe> recipes) {
super(name, list, recipes);
}
@Override
public String getRecipeInfo(IRecipe recipe) {
return LogHelper.getStackDescription(recipe.getRecipeOutput());
}
public static List<IRecipe> getRecipes(List<IRecipe> list, IIngredient ingredient) {
List<IRecipe> recipes = new LinkedList<IRecipe>();
for (IRecipe r : list) {
if (r != null && r.getRecipeOutput() != null && r.getRecipeOutput() instanceof ItemStack && matches(ingredient, toIItemStack(r.getRecipeOutput()))) {
if (r != null && r.getRecipeOutput() != null
&& r.getRecipeOutput() instanceof ItemStack
&& matches(ingredient, toIItemStack(r.getRecipeOutput()))) {
recipes.add(r);
}
}
return recipes;
}
}
}
@@ -9,23 +9,23 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
protected BaseListAddition(String name, List<T> list) {
super(name, list);
}
protected BaseListAddition(String name, List<T> list, List<T> recipies) {
this(name, list);
if(recipes != null) {
if (recipes != null) {
recipes.addAll(recipies);
}
}
@Override
public void apply() {
if(recipes.isEmpty()) {
if (recipes.isEmpty()) {
return;
}
for(T recipe : recipes) {
if(recipe != null) {
if(list.add(recipe)) {
for (T recipe : recipes) {
if (recipe != null) {
if (list.add(recipe)) {
successful.add(recipe);
} else {
LogHelper.logError(String.format("Error adding %s Recipe for %s", name, getRecipeInfo(recipe)));
@@ -35,17 +35,18 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
}
}
}
@Override
public void undo() {
if(this.successful.isEmpty()) {
if (this.successful.isEmpty()) {
return;
}
for(T recipe : successful) {
if(recipe != null) {
if(!list.remove(recipe)) {
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, this.getRecipeInfo(recipe)));
for (T recipe : successful) {
if (recipe != null) {
if (!list.remove(recipe)) {
LogHelper.logError(
String.format("Error removing %s Recipe for %s", name, this.getRecipeInfo(recipe)));
}
} else {
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
@@ -62,4 +63,4 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
public String describeUndo() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
}
}
@@ -4,98 +4,91 @@ import java.util.LinkedList;
import java.util.List;
public abstract class BaseListModification<T> extends BaseUndoable {
protected final List<T> list;
protected final LinkedList<T> recipes;
protected final LinkedList<T> successful;
protected BaseListModification(String name, List<T> list) {
super(name);
this.list = list;
this.recipes = new LinkedList<T>();
this.successful = new LinkedList<T>();
}
@Override
protected final LinkedList<T> recipes;
protected final LinkedList<T> successful;
protected BaseListModification(String name, List<T> list) {
super(name);
this.list = list;
this.recipes = new LinkedList<T>();
this.successful = new LinkedList<T>();
}
@Override
public boolean canUndo() {
if(recipes.isEmpty() || successful.isEmpty())
return false;
if (recipes.isEmpty() || successful.isEmpty()) return false;
return true;
}
@Override
protected String getRecipeInfo() {
if(!recipes.isEmpty())
{
StringBuilder sb = new StringBuilder();
for(T recipe : recipes) {
if(recipe != null) {
sb.append(getRecipeInfo(recipe)).append(", ");
}
}
if(sb.length() > 0 ) {
sb.setLength(sb.length() - 2);
}
return sb.toString();
}
return super.getRecipeInfo();
}
/**
* This method must be overwritten by the extending classes. It should return
* the name of the key item, for which the recipe is for. For example for machines
* which produce new items, it should return the name of the ouput. For machines
* which are processing items (like a pulverizer) it should return the name of the
* the input. Another example would be the name of the enchantmant for a thaumcraft
* infusion recipe.
*/
@Override
protected String getRecipeInfo() {
if (!recipes.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (T recipe : recipes) {
if (recipe != null) {
sb.append(getRecipeInfo(recipe)).append(", ");
}
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 2);
}
return sb.toString();
}
return super.getRecipeInfo();
}
/**
* This method must be overwritten by the extending classes. It should return the name of the key item, for which
* the recipe is for. For example for machines which produce new items, it should return the name of the ouput. For
* machines which are processing items (like a pulverizer) it should return the name of the the input. Another
* example would be the name of the enchantmant for a thaumcraft infusion recipe.
*/
protected abstract String getRecipeInfo(T recipe);
@Override
public int hashCode() {
return 37 * super.hashCode() ^ (list != null ? 43 * list.hashCode() : 0);
}
@Override
public boolean equals(Object obj) {
if(obj == this)
return true;
if (obj == null)
return false;
if (obj == this) return true;
if (obj == null) return false;
// Do both actions have the same base?
if(!super.equals(obj))
return false;
if (!(obj instanceof BaseListModification<?>))
return false;
BaseListModification<?> mod = (BaseListModification<?>)obj;
if (!super.equals(obj)) return false;
if (!(obj instanceof BaseListModification<?>)) return false;
BaseListModification<?> mod = (BaseListModification<?>) obj;
// Do both actions reference the same list?
if(this.list != mod.list) {
if (this.list != mod.list) {
return false;
}
// Do both actions contain the same recipes?
if(recipes.size() != mod.recipes.size()) {
if (recipes.size() != mod.recipes.size()) {
return false;
}
for(T recipe : recipes) {
for (T recipe : recipes) {
boolean found = false;
for(T otherRecipe : (List<T>)mod.recipes) {
if(equals(recipe, otherRecipe)) {
for (T otherRecipe : (List<T>) mod.recipes) {
if (equals(recipe, otherRecipe)) {
found = true;
break;
}
}
if(!found) {
if (!found) {
return false;
}
}
@@ -104,19 +97,18 @@ public abstract class BaseListModification<T> extends BaseUndoable {
}
/**
* Compares two recipes if they are equal. If the mod does not overwrite equals() in
* their recipe object, this method should be overwritten by the extending classes to
* add a custom equals method
* Compares two recipes if they are equal. If the mod does not overwrite equals() in their recipe object, this
* method should be overwritten by the extending classes to add a custom equals method
*/
protected boolean equals(T recipe, T otherRecipe) {
if(recipe == otherRecipe) {
if (recipe == otherRecipe) {
return true;
}
if(!recipe.equals(otherRecipe)) {
if (!recipe.equals(otherRecipe)) {
return false;
}
return true;
}
}
}
@@ -5,28 +5,28 @@ import java.util.List;
import modtweaker2.helpers.LogHelper;
public abstract class BaseListRemoval<T> extends BaseListModification<T> {
protected BaseListRemoval(String name, List<T> list) {
super(name, list);
}
protected BaseListRemoval(String name, List<T> list, List<T> recipies) {
this(name, list);
if(recipes != null) {
if (recipes != null) {
recipes.addAll(recipies);
}
}
@Override
public void apply() {
if(recipes.isEmpty()) {
if (recipes.isEmpty()) {
return;
}
for(T recipe : this.recipes) {
if(recipe != null) {
if(this.list.remove(recipe)) {
for (T recipe : this.recipes) {
if (recipe != null) {
if (this.list.remove(recipe)) {
successful.add(recipe);
} else {
LogHelper.logError(String.format("Error removing %s Recipe for %s", name, getRecipeInfo(recipe)));
@@ -36,15 +36,15 @@ public abstract class BaseListRemoval<T> extends BaseListModification<T> {
}
}
}
@Override
public void undo() {
if(successful.isEmpty()) {
if (successful.isEmpty()) {
return;
}
for(T recipe : successful) {
if(recipe != null) {
if(!list.add(recipe)) {
for (T recipe : successful) {
if (recipe != null) {
if (!list.add(recipe)) {
LogHelper.logError(String.format("Error restoring %s Recipe for %s", name, getRecipeInfo(recipe)));
}
} else {
@@ -55,11 +55,19 @@ public abstract class BaseListRemoval<T> extends BaseListModification<T> {
@Override
public String describe() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
return String.format(
"[ModTweaker2] Removing %d %s Recipe(s) for %s",
this.recipes.size(),
this.name,
this.getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %s", this.recipes.size(), this.name, this.getRecipeInfo());
return String.format(
"[ModTweaker2] Restoring %d %s Recipe(s) for %s",
this.recipes.size(),
this.name,
this.getRecipeInfo());
}
}
}
@@ -8,14 +8,14 @@ import java.util.Map.Entry;
import modtweaker2.helpers.LogHelper;
public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
protected final HashMap<K, V> overwritten;
protected BaseMapAddition(String name, Map<K, V> map) {
super(name, map);
this.overwritten = new HashMap<K, V>();
}
protected BaseMapAddition(String name, Map<K, V> map, Map<K, V> recipes) {
this(name, map);
this.recipes.putAll(recipes);
@@ -23,44 +23,50 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
@Override
public void apply() {
if(recipes.isEmpty())
return;
for(Entry<K, V> entry : recipes.entrySet()) {
if (recipes.isEmpty()) return;
for (Entry<K, V> entry : recipes.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
V oldValue = map.put(key, value);
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe for %s", name, getRecipeInfo( new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
if (oldValue != null) {
LogHelper.logWarning(
String.format(
"Overwritten %s Recipe for %s",
name,
getRecipeInfo(new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
overwritten.put(key, oldValue);
}
successful.put(key, value);
}
}
@Override
public void undo() {
if(successful.isEmpty() && overwritten.isEmpty())
return;
if (successful.isEmpty() && overwritten.isEmpty()) return;
for(Entry<K, V> entry : successful.entrySet()) {
for (Entry<K, V> entry : successful.entrySet()) {
K key = entry.getKey();
V value = map.remove(key);
if(value == null) {
if (value == null) {
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
}
}
for(Entry<K, V> entry : overwritten.entrySet()) {
for (Entry<K, V> entry : overwritten.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
V oldValue = map.put(key, value);
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe which should not exist for %s", name, getRecipeInfo(new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
if (oldValue != null) {
LogHelper.logWarning(
String.format(
"Overwritten %s Recipe which should not exist for %s",
name,
getRecipeInfo(new AbstractMap.SimpleEntry<K, V>(entry.getKey(), value))));
}
}
}
@@ -5,10 +5,11 @@ import java.util.Map;
import java.util.Map.Entry;
public abstract class BaseMapModification<K, V> extends BaseUndoable {
protected Map<K, V> map;
protected final HashMap<K, V> recipes;
protected final HashMap<K, V> successful;
protected BaseMapModification(String name, Map<K, V> map) {
super(name);
this.map = map;
@@ -20,35 +21,32 @@ public abstract class BaseMapModification<K, V> extends BaseUndoable {
public boolean canUndo() {
return !recipes.isEmpty();
}
@Override
protected String getRecipeInfo() {
if(!recipes.isEmpty())
{
if (!recipes.isEmpty()) {
StringBuilder sb = new StringBuilder();
for(Entry<K, V> recipe : recipes.entrySet()) {
if(recipe != null) {
for (Entry<K, V> recipe : recipes.entrySet()) {
if (recipe != null) {
sb.append(getRecipeInfo(recipe)).append(", ");
}
}
if(sb.length() > 0) {
if (sb.length() > 0) {
sb.setLength(sb.length() - 2);
}
return sb.toString();
}
return super.getRecipeInfo();
}
/**
* This method must be overwritten by the extending classes. It should return
* the name of the key item, for which the recipe is for. For example for machines
* which produce new items, it should return the name of the ouput. For machines
* which are processing items (like a pulverizer) it should return the name of the
* the input. Another example would be the name of the enchantmant for a thaumcraft
* infusion recipe.
* This method must be overwritten by the extending classes. It should return the name of the key item, for which
* the recipe is for. For example for machines which produce new items, it should return the name of the ouput. For
* machines which are processing items (like a pulverizer) it should return the name of the the input. Another
* example would be the name of the enchantmant for a thaumcraft infusion recipe.
*/
protected abstract String getRecipeInfo(Entry<K, V> recipe);
}
@@ -6,50 +6,49 @@ import java.util.Map.Entry;
import modtweaker2.helpers.LogHelper;
public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
protected BaseMapRemoval(String name, Map<K, V> map) {
super(name, map);
}
protected BaseMapRemoval(String name, Map<K, V> map, Map<K, V> recipes) {
this(name, map);
if(recipes != null) {
if (recipes != null) {
this.recipes.putAll(recipes);
}
}
@Override
public void apply() {
if(recipes.isEmpty())
return;
for(K key : recipes.keySet()) {
if (recipes.isEmpty()) return;
for (K key : recipes.keySet()) {
V oldValue = map.remove(key);
if(oldValue != null) {
if (oldValue != null) {
successful.put(key, oldValue);
} else {
LogHelper.logError(String.format("Error removing %s Recipe : null object", name));
}
}
}
@Override
public void undo() {
if(successful.isEmpty())
return;
for(Entry<K, V> entry : successful.entrySet()) {
if(entry != null) {
if (successful.isEmpty()) return;
for (Entry<K, V> entry : successful.entrySet()) {
if (entry != null) {
V oldValue = map.put(entry.getKey(), entry.getValue());
if(oldValue != null) {
LogHelper.logWarning(String.format("Overwritten %s Recipe for %s while restoring.", name, getRecipeInfo(entry)));
if (oldValue != null) {
LogHelper.logWarning(
String.format("Overwritten %s Recipe for %s while restoring.", name, getRecipeInfo(entry)));
}
}
}
}
@Override
public String describe() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
@@ -7,7 +7,7 @@ import minetweaker.IUndoableAction;
public class BaseMultiModification extends BaseUndoable {
protected final LinkedList<IUndoableAction> actions;
protected BaseMultiModification(String name) {
super(name);
this.actions = new LinkedList<IUndoableAction>();
@@ -15,16 +15,15 @@ public class BaseMultiModification extends BaseUndoable {
@Override
public void apply() {
for(IUndoableAction action : actions) {
for (IUndoableAction action : actions) {
action.apply();
}
}
@Override
public boolean canUndo() {
for(IUndoableAction action : actions) {
if(!action.canUndo())
return false;
for (IUndoableAction action : actions) {
if (!action.canUndo()) return false;
}
return true;
@@ -42,7 +41,7 @@ public class BaseMultiModification extends BaseUndoable {
@Override
public void undo() {
for(IUndoableAction action : actions) {
for (IUndoableAction action : actions) {
action.undo();
}
}
@@ -4,59 +4,57 @@ import minetweaker.IUndoableAction;
public abstract class BaseUndoable implements IUndoableAction {
// Holds the name of the mod / machine this action manipulates
protected final String name;
// Basic indicator, if the action was successful and can be reverted
protected boolean success = false;
// Holds the name of the mod / machine this action manipulates
protected final String name;
// Basic indicator, if the action was successful and can be reverted
protected boolean success = false;
protected BaseUndoable(String name) {
this.name = name;
}
protected String getRecipeInfo() {
return "Unknown item";
}
@Override
public boolean canUndo() {
return success;
}
@Override
public String describe() {
return String.format("[ModTweaker2] Altering %s Recipe(s) for %s", this.name, this.getRecipeInfo());
}
protected BaseUndoable(String name) {
this.name = name;
}
protected String getRecipeInfo() {
return "Unknown item";
}
@Override
public boolean canUndo() {
return success;
}
@Override
public String describe() {
return String.format("[ModTweaker2] Altering %s Recipe(s) for %s", this.name, this.getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Reverting %s Recipe(s) changes for %s", this.name, this.getRecipeInfo());
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if(!(obj instanceof BaseUndoable)) {
return false;
}
BaseUndoable u = (BaseUndoable)obj;
if(!name.equals(u.name))
return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (!(obj instanceof BaseUndoable)) {
return false;
}
BaseUndoable u = (BaseUndoable) obj;
if (!name.equals(u.name)) return false;
return true;
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public Object getOverrideKey() {
return null;
}
}
}
@@ -5,6 +5,7 @@ import java.util.ArrayList;
import cpw.mods.fml.common.Loader;
public class TweakerPlugin {
private static ArrayList<String> isLoaded = new ArrayList<String>();
public static void register(String mod, Class<?> clazz) {
@@ -25,5 +26,5 @@ public class TweakerPlugin {
public static boolean isLoaded(String string) {
return isLoaded.contains(string);
}
}