package dev.isxander.yacl3.api; import dev.isxander.yacl3.gui.image.ImageRenderer; import dev.isxander.yacl3.impl.OptionDescriptionImpl; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import java.nio.file.Path; import java.util.Collection; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; /** * Provides all information for the description panel in the GUI. * This provides no functional benefit, and is purely for UX. */ public interface OptionDescription { /** * The description of the option, this is automatically wrapped and supports all styling, * including {@link net.minecraft.network.chat.ClickEvent}s and {@link net.minecraft.network.chat.HoverEvent}s. * @return The description of the option, with all lines merged with \n. */ Component text(); /** * The image to display with the description. If the Optional is empty, no image has been provided. * Usually, the image renderers are constructed asynchronously, so this method returns a {@link CompletableFuture}. *
* Image renderers are cached throughout the whole lifecycle of the game, and should not be generated more than once
* per image. See {@link ImageRenderer#getOrMakeAsync(ResourceLocation, Supplier)} for implementation details.
*/
CompletableFuture
* However, THIS IS NOT API SAFE! As part of the gui package, things
* may change that could break compatibility with future versions of YACL.
* A helpful utility (that is also not API safe) is {@link dev.isxander.yacl3.gui.image.ImageRendererManager#registerOrGetImage(ResourceLocation, Supplier)}
* which will cache the image renderer for the whole game lifecycle and construct it asynchronously to the render thread.
* @param image the image renderer to display
* @return this builder
*/
Builder customImage(CompletableFuture
* However, THIS IS NOT API SAFE! As part of the gui package, things
* may change that could break compatibility with future versions of YACL.
* A helpful utility (that is also not API safe) is {@link dev.isxander.yacl3.gui.image.ImageRendererManager#registerOrGetImage(ResourceLocation, Supplier)}
* which will cache the image renderer for the whole game lifecycle and construct it asynchronously to the render thread.
* @param image the image renderer to display
* @return this builder
*/
default Builder customImage(ImageRenderer image) {
return this.customImage(CompletableFuture.completedFuture(Optional.of(image)));
}
/**
* Sets an animated GIF image to display with the description. This is backed by a regular minecraft resource
* in your mod's /assets folder.
*
* @param image the location of the image to display from the resource manager
* @return this builder
*/
@Deprecated
Builder gifImage(ResourceLocation image);
/**
* Sets an animated GIF image to display with the description. This is backed by a file on disk.
* The width and height is automatically determined from the image processing.
*
* @param path the absolute path to the image file
* @param uniqueLocation the unique identifier for the image, used for caching and resource manager registrar
* @return this builder
*/
@Deprecated
Builder gifImage(Path path, ResourceLocation uniqueLocation);
OptionDescription build();
}
}