Skip to content

Commit

Permalink
Added EMI category removing support
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Jun 27, 2024
1 parent cb75f61 commit d165674
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,47 @@
import dev.latvian.mods.kubejs.recipe.viewer.RecipeViewerEvents;
import dev.latvian.mods.kubejs.recipe.viewer.server.RecipeViewerData;
import dev.latvian.mods.kubejs.script.ScriptType;
import net.minecraft.resources.ResourceLocation;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

@EmiEntrypoint
public class KubeJSEMIPlugin implements EmiPlugin {
@Override
public void register(EmiRegistry registry) {
var remote = RecipeViewerData.remote;

registry.removeRecipes(r -> remote.removedGlobalRecipes().contains(r.getId()));
if (remote != null) {
var removedCategories = Set.copyOf(remote.removedCategories());
var globalRemovedRecipes = Set.copyOf(remote.removedGlobalRecipes());
var removedRecipes = new HashMap<ResourceLocation, Set<ResourceLocation>>();

for (var data : remote.categoryData()) {
removedRecipes.put(data.category(), Set.copyOf(data.removedRecipes()));
}

registry.removeRecipes(r -> {
var cat = r.getCategory().getId();

if (cat == null) {
return false;
}

if (removedCategories.contains(cat)) {
return true;
}

var id = r.getId();

if (id == null) {
return false;
}

return globalRemovedRecipes.contains(id) || removedRecipes.getOrDefault(cat, Set.of()).contains(id);
});
}

for (var type : RecipeViewerEntryType.ALL_TYPES.get()) {
if (RecipeViewerEvents.REMOVE_ENTRIES.hasListeners(type)) {
Expand Down

0 comments on commit d165674

Please sign in to comment.