ModTweaker/src/main/java/modtweaker2/utils/BaseListAddition.java
Zixxl 40605f5fa9 Continuing work
- Fixed bugs in BaseMap-Addition/Removal
- Reworked handlers for TE Transposer & Smelter
- Added recipe logging for TE Transposer & Smelter
2015-07-03 17:09:37 +02:00

65 lines
1.8 KiB
Java

package modtweaker2.utils;
import java.util.List;
import modtweaker2.helpers.LogHelper;
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) {
recipes.addAll(recipies);
}
}
@Override
public void apply() {
if(recipes.isEmpty()) {
return;
}
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)));
}
} else {
LogHelper.logError(String.format("Error adding %s Recipe: null object", name));
}
}
}
@Override
public void undo() {
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)));
}
} else {
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
}
}
}
@Override
public String describe() {
return String.format("[ModTweaker2] Adding %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
@Override
public String describeUndo() {
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
}
}