mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-20 04:19:44 +00:00
Continuing work
- Fixed bugs in BaseMap-Addition/Removal - Reworked handlers for TE Transposer & Smelter - Added recipe logging for TE Transposer & Smelter
This commit is contained in:
1 parent
149d52bb6c
commit
40605f5fa9
13 files changed
+380
-265
No files matched your search
@@ -25,13 +25,13 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
|
||||
|
||||
for(T recipe : recipes) {
|
||||
if(recipe != null) {
|
||||
if(this.list.add(recipe)) {
|
||||
if(list.add(recipe)) {
|
||||
successful.add(recipe);
|
||||
} else {
|
||||
LogHelper.logError(String.format("Error adding %s Recipe for %s", this.name, this.getRecipeInfo(recipe)));
|
||||
LogHelper.logError(String.format("Error adding %s Recipe for %s", name, getRecipeInfo(recipe)));
|
||||
}
|
||||
} else {
|
||||
LogHelper.logError(String.format("Error adding %s Recipe: null object", this.name));
|
||||
LogHelper.logError(String.format("Error adding %s Recipe: null object", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,22 +44,22 @@ public abstract class BaseListAddition<T> extends BaseListModification<T> {
|
||||
|
||||
for(T recipe : successful) {
|
||||
if(recipe != null) {
|
||||
if(!this.list.remove(recipe)) {
|
||||
LogHelper.logError(String.format("Error removing %s Recipe for %s", this.name, this.getRecipeInfo(recipe)));
|
||||
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", this.name));
|
||||
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", this.recipes.size(), this.name, this.getRecipeInfo());
|
||||
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", this.recipes.size(), this.name, this.getRecipeInfo());
|
||||
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
|
||||
|
||||
protected BaseMapAddition(String name, Map<K, V> map, Map<K, V> recipes) {
|
||||
this(name, map);
|
||||
recipes.putAll(recipes);
|
||||
this.recipes.putAll(recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,37 +27,39 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
|
||||
return;
|
||||
|
||||
for(Entry<K, V> entry : recipes.entrySet()) {
|
||||
V value = map.put(entry.getKey(), entry.getValue());
|
||||
if(value != null) {
|
||||
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))));
|
||||
overwritten.put(entry.getKey(), value);
|
||||
overwritten.put(key, oldValue);
|
||||
}
|
||||
successful.put(entry.getKey(), entry.getValue());
|
||||
|
||||
successful.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo() {
|
||||
if(successful.isEmpty() || overwritten.isEmpty())
|
||||
if(successful.isEmpty() && overwritten.isEmpty())
|
||||
return;
|
||||
|
||||
for(K key : recipes.keySet()) {
|
||||
map.remove(key);
|
||||
}
|
||||
|
||||
|
||||
for(Entry<K, V> entry : successful.entrySet()) {
|
||||
V value = map.remove(entry.getKey());
|
||||
|
||||
K key = entry.getKey();
|
||||
V value = map.remove(key);
|
||||
|
||||
if(value == null) {
|
||||
LogHelper.logError(String.format("Error removing %s Recipe: null object", name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(Entry<K, V> entry : overwritten.entrySet()) {
|
||||
V value = map.put(entry.getKey(), entry.getValue());
|
||||
K key = entry.getKey();
|
||||
V value = entry.getValue();
|
||||
V oldValue = map.put(key, value);
|
||||
|
||||
if(value != null) {
|
||||
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))));
|
||||
}
|
||||
}
|
||||
@@ -65,11 +67,11 @@ public abstract class BaseMapAddition<K, V> extends BaseMapModification<K, V> {
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return String.format("Adding %d %s Recipe(s) for %d", recipes.size(), name, getRecipeInfo());
|
||||
return String.format("Adding %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return String.format("Removing %d %s Recipe(s) for %d", recipes.size(), name, getRecipeInfo());
|
||||
return String.format("Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public abstract class BaseMapModification<K, V> extends BaseUndoable {
|
||||
protected final Map<K, V> map;
|
||||
protected Map<K, V> map;
|
||||
protected final HashMap<K, V> recipes;
|
||||
protected final HashMap<K, V> successful;
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
|
||||
return;
|
||||
|
||||
for(K key : recipes.keySet()) {
|
||||
V value = map.remove(key);
|
||||
V oldValue = map.remove(key);
|
||||
|
||||
if(value != null) {
|
||||
successful.put(key, value);
|
||||
if(oldValue != null) {
|
||||
successful.put(key, oldValue);
|
||||
} else {
|
||||
LogHelper.logError(String.format("Error removing %s Recipe : null object", name));
|
||||
}
|
||||
@@ -42,8 +42,8 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
|
||||
|
||||
for(Entry<K, V> entry : successful.entrySet()) {
|
||||
if(entry != null) {
|
||||
V value = map.put(entry.getKey(), entry.getValue());
|
||||
if(value != 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)));
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,11 @@ public abstract class BaseMapRemoval<K, V> extends BaseMapModification<K, V> {
|
||||
|
||||
@Override
|
||||
public String describe() {
|
||||
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %d", this.recipes.size(), this.name);
|
||||
return String.format("[ModTweaker2] Removing %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo() {
|
||||
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %d", this.recipes.size(), this.name);
|
||||
return String.format("[ModTweaker2] Restoring %d %s Recipe(s) for %s", recipes.size(), name, getRecipeInfo());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user