[Feature] Disable any Recipe using a dataPack file.

You can add a new File `bclib/config/recipes.json` to your datapack with the following content to disable any recipe (by Id):

```json
{
  "disable": [
    "minecraft:jungle_chest_boat",
    "bclib:test_star"
  ]
}
```
This commit is contained in:
Frank 2023-04-13 17:33:42 +02:00
parent 48a0049faf
commit 5f92964f9d
2 changed files with 53 additions and 15 deletions

View file

@ -3,16 +3,20 @@ package org.betterx.bclib.mixin.common;
import org.betterx.bclib.recipes.BCLRecipeManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.Container;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeManager;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import com.google.gson.JsonElement;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map;
@ -32,4 +36,15 @@ public abstract class RecipeManagerMixin {
) {
info.setReturnValue(BCLRecipeManager.getSortedRecipe(type, inventory, level, this::byType));
}
@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At("HEAD"))
public void bcl_interceptApply(
Map<ResourceLocation, JsonElement> map,
ResourceManager resourceManager,
ProfilerFiller profiler,
CallbackInfo info
) {
BCLRecipeManager.removeDisabledRecipes(resourceManager, map);
}
}