Sort new enchantment in gui on add.

This commit is contained in:
alexcrea 2024-07-24 19:13:23 +02:00
parent b70887c5ca
commit a6c2d5f148
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
2 changed files with 42 additions and 2 deletions

View file

@ -53,6 +53,46 @@ public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFa
);
}
@Override
public void updateValueForGeneric(CAEnchantment generic, boolean shouldUpdate) {
updateValueForGeneric(generic, shouldUpdate, true);
}
public void updateValueForGeneric(CAEnchantment generic, boolean shouldUpdate, boolean prepareSorting) {
if(!prepareSorting) {
super.updateValueForGeneric(generic, shouldUpdate);
return;
}
if(!this.factoryMap.containsKey(generic)){
// We need to sort elements again
super.updateValueForGeneric(generic, false);
// Clear page then refill all of them
this.firstPage.clear();
this.pages.clear();
this.pages.add(this.firstPage);
for (CAEnchantment enchantment : getEveryDisplayableInstanceOfGeneric()) {
GuiItem item = this.guiItemMap.get(enchantment);
if(item == null) {
updateValueForGeneric(enchantment, false, false);
}else {
addToPage(item);
}
}
if(shouldUpdate) update();
}else{
super.updateValueForGeneric(generic, shouldUpdate);
}
}
// Unused methods
@Override

View file

@ -118,8 +118,8 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
this.pages.clear();
this.pages.add(this.firstPage);
for (T conflict : getEveryDisplayableInstanceOfGeneric()) {
updateValueForGeneric(conflict, false);
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
updateValueForGeneric(generic, false);
}
update();