Icons
Overview
Apollo adds three different icon builders, ItemStackIcon
, SimpleResourceLocation
and AdvancedResourceLocationIcon
for creating various types of icon entries.
ItemStackIcon
Builder
The ItemStackIcon
builder is used to assign an icon using a specified ItemStack name or ID. This will utilize the texture present in the player's resource pack as the icon.
If you're using a custom resource pack and want to make the icon appear as a model, you can set the customModelData
to the models data value. On versions below 1.13 customModelData
sets the durability instead.
If your server accepts players on Minecraft versions higher than 1.8.8
then you need to use itemName
.
public final class ItemStackIcon extends Icon {
/**
* Returns the icon {@link String} item name.
*
* @return the icon item name
* @since 1.0.0
*/
String itemName;
/**
* Returns the icon {@link Integer} item id.
*
* @return the icon item id
* @since 1.0.0
*/
int itemId;
/**
* Returns the icon {@link Integer} custom model data.
*
* @return the icon custom model data
* @since 1.0.7
*/
int customModelData;
}
Sample Code
public static ItemStackIcon itemStackIdIconExample() {
return ItemStackIcon.builder()
.itemId(Material.ENDER_PEARL.getId())
.build();
}
public static ItemStackIcon itemStackNameIconExample() {
return ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build();
}
SimpleResourceLocation
Builder
If you're using a custom resource pack and want to create an icon, you can use the SimpleResourceLocation
builder.
The supplied resource location should point to a texture in the resource pack, or the path to an svg
file in the resource pack.
public final class SimpleResourceLocationIcon extends Icon {
/**
* Returns the icon {@link String} resource location.
*
* <p>Represents a path to an icon that will appear for the player.</p>
*
* @return the icon resource location
* @since 1.0.0
*/
String resourceLocation;
/**
* Returns the icon {@link Integer} size.
*
* <p>Size of the image height and width (in pixels).</p>
*
* @return the icon size
* @since 1.0.0
*/
int size;
}
Sample Code
public static SimpleResourceLocationIcon simpleResourceLocationIconExample() {
return SimpleResourceLocationIcon.builder()
.resourceLocation("icons/server-logo.png") // Resource path location
.size(16) // Represents both height and width
.build();
}
AdvancedResourceLocationIcon
Builder
If you have a TextureAtlas (opens in a new tab), also known as sprite-sheet or image sprite, you can use the AdvancedResourceLocationIcon
builder.
public final class AdvancedResourceLocationIcon extends Icon {
/**
* Returns the icon {@link String} resource location.
*
* <p>Represents a path to an icon that will appear for the player.</p>
*
* @return the icon resource location
* @since 1.0.0
*/
String resourceLocation;
/**
* Returns the icon width {@link Float}.
*
* <p>Size of the image width (in pixels).</p>
*
* @return the icon width
* @since 1.0.0
*/
float width;
/**
* Returns the icon height {@link Float}.
*
* <p>Size of the image height (in pixels).</p>
*
* @return the icon height
* @since 1.0.0
*/
float height;
/**
* Returns the icon min u {@link Float}.
*
* <p>Range of 0-1 (the x location on a TextureAtlas).</p>
*
* @return the icon min u
* @since 1.0.0
*/
float minU;
/**
* Returns the icon max u {@link Float}.
*
* <p>Range of 0-1 (the x location on a TextureAtlas).</p>
*
* @return the icon max u
* @since 1.0.0
*/
float maxU;
/**
* Returns the icon min v {@link Float}.
*
* <p>Range of 0-1 (the y location on a TextureAtlas).</p>
*
* @return the icon min v
* @since 1.0.0
*/
float minV;
/**
* Returns the icon max v {@link Float}.
*
* <p>Range of 0-1 (the y location on a TextureAtlas).</p>
*
* @return the icon max v
* @since 1.0.0
*/
float maxV;
}
Sample Code
public static AdvancedResourceLocationIcon advancedResourceLocationIconExample() {
return AdvancedResourceLocationIcon.builder()
.resourceLocation("icons/server-sprite.png")
.width(512)
.height(512)
.minU(1)
.maxU(1)
.minV(1)
.maxV(1)
.build();
}