LibJF/docs/libjf-data-manipulation-v0.md

1.6 KiB

libjf-data-manipulation-v0

libjf-data-manipulation-v0 provides code for modifying existing resources. It depends on libjf-unsafe-v0 to patch ResourcePack implementations, libjf-base and fabric-api-base

RecipeUtil

RecipeUtil provides to methods to end users:

  • removeRecipe blocks minecraft from loading recipes using the specified tag
  • removeRecipeFor blocks minecraft from loading recipes producing the specified output. (Look at the log to find out which ones it blocks)

UserResourceEvents

UserResourceEvents provides four events (CONTAINS, FIND_RESOURCE, OPEN, OPEN_ROOT) which get called every time the corresponding method is called on and ResourcePack. They allow modifying the resulting data. This is used in respackopts to manipulate resource loading. To temporarily disable these hooks, call the "disable" function, which invokes the lambda it is passed and disables the hooks while it is running

Examples

@Override
public void onInitialize() {
    // This should prevent resource packs from doing anything if my hooks are working and
    UserResourceEvents.OPEN.register((type, id, previous, pack) -> {
        if (pack instanceof DirectoryResourcePack) {
            LibJf.LOGGER.info(pack.getName() + " opened " + type.name() + "/" + id.toString());
        }
        return previous.get();
    });
    UserResourceEvents.CONTAINS.register((type, id, previous, pack) -> {
        if (pack instanceof DirectoryResourcePack) {
            return false;
        }
        return previous.get();
    });
    RecipeUtil.removeRecipeFor(Items.DIAMOND_SWORD);
}