Commit 0317dbdf by Jonathan Thomas

Update TextureLoader to only log missing textures a single time in teh log.

parent 453e9f1f
Pipeline #11958 passed with stage
in 21 seconds
......@@ -6,31 +6,33 @@ import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
/**
* The {@code TextureLoader} class registers and returns texture identifiers for resources
* contained for this mod. UI and Entity icons.
* contained for this mod. UI and Entity icons. Missing textures are logged once.
*/
public class TextureLoader {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
private static final Set<String> missingTextures = new HashSet<>();
public TextureLoader() {
}
public Identifier GetUI(String name) {
// Attempt to load texture resource
String texture_path = "textures/ui/" + name + ".png";
Identifier textureId = new Identifier("mobgpt", texture_path);
String texturePath = "textures/ui/" + name + ".png";
Identifier textureId = new Identifier("mobgpt", texturePath);
Optional<Resource> resource = MinecraftClient.getInstance().getResourceManager().getResource(textureId);
if (!resource.isEmpty()) {
if (resource.isPresent()) {
// Bind texture, and return Identity
MinecraftClient.getInstance().getTextureManager().bindTexture(textureId);
return textureId;
} else {
// Resource not found
LOGGER.info(texture_path + " was not found");
logMissingTextureOnce(texturePath);
return null;
}
}
......@@ -47,7 +49,16 @@ public class TextureLoader {
// Texture not found, log a message and return the "not_found" texture Identifier
Identifier notFoundTextureId = new Identifier("mobgpt", "textures/entity/not_found.png");
MinecraftClient.getInstance().getTextureManager().bindTexture(notFoundTextureId);
logMissingTextureOnce(texturePath);
return notFoundTextureId;
}
}
private void logMissingTextureOnce(String texturePath) {
// Check if the missing texture has already been logged
if (!missingTextures.contains(texturePath)) {
LOGGER.info(texturePath + " was not found");
missingTextures.add(texturePath);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment