Fix Custom Recipe not being registered.

Fix conflict from api not working.
Add remove api for custom recipe, material group and conflict.
This commit is contained in:
alexcrea 2024-07-09 20:21:36 +02:00
parent a40d2c6530
commit 6f1e53f68e
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
8 changed files with 93 additions and 10 deletions

View file

@ -41,7 +41,7 @@ public class ConflictAPI {
EnchantConflictGroup conflict = builder.build();
// Register conflict
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict);
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);
// Add conflict to gui
EnchantConflictGui.INSTANCE.updateValueForGeneric(conflict, true);
@ -110,6 +110,25 @@ public class ConflictAPI {
return result;
}
/**
* Remove a conflict.
*
* @param conflict The conflict to remove
* @return True if successful.
*/
public static boolean removeConflict(@NotNull EnchantConflictGroup conflict){
// Remove from registry
ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict);
// Write as null and save to file
ConfigHolder.CONFLICT_HOLDER.getConfig().set(conflict.getName(), null);
prepareSaveTask();
// Remove from gui
EnchantConflictGui.INSTANCE.removeGeneric(conflict);
return true;
}
/**
* Prepare a task to save conflict configuration.

View file

@ -11,6 +11,9 @@ import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
import java.util.Collections;
import java.util.List;
/**
* Custom Anvil api for custom anvil recipes.
*/
@SuppressWarnings("unused")
public class CustomAnvilRecipeApi {
@ -47,16 +50,39 @@ public class CustomAnvilRecipeApi {
return false;
}
// Add to registry
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanAddNew(recipe);
// Save to file
recipe.saveToFile(false, false);
prepareSaveTask();
// Update gui
// Add from gui
CustomRecipeConfigGui.INSTANCE.updateValueForGeneric(recipe, true);
return true;
}
/**
* Remove a custom anvil recipe.
*
* @param recipe The recipe to remove
* @return True if successful.
*/
public static boolean removeRecipe(@NotNull AnvilCustomRecipe recipe){
// Remove from registry
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanRemove(recipe);
// Write as null and save to file
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(recipe.getName(), null);
prepareSaveTask();
// Remove from gui
CustomRecipeConfigGui.INSTANCE.removeGeneric(recipe);
return true;
}
/**
* Prepare a task to save custom recipe configuration.
*/

View file

@ -121,6 +121,30 @@ public class MaterialGroupApi {
}
/**
* Remove a material group.
* Caution ! It will not be removed from depending conflict or other material group at runtime.
* For that reason, it is not recommended to use this function.
*
* @param group The recipe to remove
* @return True if successful.
*/
public static boolean removeGroup(@NotNull AbstractMaterialGroup group){
// Remove from registry
ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName());
// Write as null and save to file
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName(), null);
prepareSaveTask();
// Remove from gui
if(group instanceof IncludeGroup includeGroup){
GroupConfigGui.INSTANCE.removeGeneric(includeGroup);
}
return true;
}
/**
* Prepare a task to reload every conflict.
*/

View file

@ -118,10 +118,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
// Remove from enchantment
for (CAEnchantment enchantment : this.enchantConflict.getEnchants()) {
enchantment.removeConflict(this.enchantConflict);
}
manager.conflictList.remove(this.enchantConflict);
manager.removeConflict(this.enchantConflict);
// Remove from parent
this.parent.removeGeneric(this.enchantConflict);