Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

API: Texture

William Blake Galbreath edited this page Nov 19, 2022 · 2 revisions

Textures

Texture's are basically just images that can be drawn on the screen.

You can use textures that are already loaded in the game (from vanilla, or other mods) or load new ones in directly from the internet.

Textures require 2 parameters. First one is a unique Key that we use to identify it. The second is where the image file is located.

Vanilla Textures

For example, to use a vanilla texture:

// without namespace
Texture texture = new Texture(Key.of("some:unique_key"), "textures/gui/options_background.png");
// or with the namespace
Texture texture = new Texture(Key.of("some:unique_key"), "minecraft:textures/gui/options_background.png");

Modded Textures

To use a loaded image from another mod just use the mod_id for the namespace:

Texture texture = new Texture(Key.of("some:unique_key"), "mod_id:textures/path/image.png");

External Textures

To use an external image from the internet, just use the url (beginning with http:// or https://)

Texture texture = new Texture(Key.of("some:unique_key"), "https://avatars.githubusercontent.com/u/332527?v=4");

Preloading Textures

If you are using textures from the internet, they will have to be loaded into memory during runtime. Normally textures are loaded when the game does that huge loading bar overlay (starting the game and loading resource packs), and takes quite some time to do.

We offer you a TextureManager where you can preload your textures into. This makes using them in your GUIs just as fast and efficient as using native vanilla textures.

public void onEnable() {
    Texture texture = new Texture("my_plugin:hayley", "https://pl3x.net/hayley.png");
    Guithium.api().getTextureManager().add(texture);
}
Clone this wiki locally