I’m begun in fabric modding and i want for my mod to load a resource pack when the mod is loaded.
Then, i found in the fabric api a code, i took for my mod here.
package com.name.exampleMod;
import java.util.Collection;
import java.util.function.Predicate;
import java.lang.Iterable;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
public class Concatenation implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "exampleMod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("HOI!!! fabric World !!!");
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return new Identifier("tutorial", "my_resources");
}
@Override
public void reload(ResourceManager manager) {
// Clear Caches Here
for(Identifier id : manager.findResources("my_resource_folder", path -> path.endsWith(".json"))) {
try(InputStream stream = manager.getResource(id).getInputStream()) {
// Consume the stream however you want, medium, rare, or well done.
} catch(Exception e) {
LOGGER.error("Error occurred while loading resource json" + id.toString(), e);
}
}
}
});
}
public static String getModId() {
return MOD_ID;
}
public static Logger getLogger() {
return LOGGER;
}
}
But i don’t know why i got this error “Can only iterate over an array or an instance of java.lang.Iterable” when i took the code from the documentation.
Here the link of the doc’s code : https://fabricmc.net/wiki/tutorial:custom_resources
When i got the error i tried to see where is the problem. And in my researches i saw that the problem can come from this function “.findRessource()”. The same function come from the minecraft api and this needs for argument a Predicate and the documentation tell the function needs for argument a Predicate. But, i don’t know if this is it.
Can i have some help ? And sorry for my bad english.
Mr. Potatoes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.