Skip to content

NovaMaterial

NovaMaterial is the material class for items and blocks added by Nova.

Getting a NovaMaterial by name

To get a NovaMaterial you first have to get the NovaMaterialRegistry using the previously retrieved Nova instance.

val materialRegistry = Nova.materialRegistry
NovaMaterialRegistry materialRegistry = nova.getMaterialRegistry(); // (1)!
  1. "nova" is the previously retrieved Nova instance, preferably saved in a field/variable.
    You can also call Nova.getNova().getMaterialRegistry()

Using this registry, you can now get a NovaMaterial by id. It needs to be in the format namespace:name.

val material = materialRegistry.get("nova:wrench") // (1)!
  1. This will throw an exception if the material is not found. However, wrench always exists.
    If you're unsure or processing user input use getOrNull instead.
NovaMaterial material = materialRegistry.get("nova:wrench"); // (1)!
  1. This will throw an exception if the material is not found. However, wrench always exists.
    If you're unsure or processing user input use getOrNull instead.

Info

The same methods also exist for getting a NovaMaterial from an ItemStack.

If you want to retrieve all materials with a certain name and ignore the namespace, you can do this:

val materials = materialRegistry.getNonNamespaced("wrench")
List<NovaMaterial> materials = materialRegistry.getNonNamespaced("wrench");

Getting the id of a material

Example for nova:wrench:

val id = material.id

val namespace = id.namespace // "nova"
val name = id.name // "wrench"
val idString = id.toString() // "nova:wrench"
NamespacedId id = material.getId();

String namespace = id.getNamespace(); // "nova"
String name = id.getName(); // "wrench"
String idString = id.toString(); // "nova:wrench"

Getting the translated name of a material

Nova uses the resource pack to translate items client side. However, if you still need to get the translated name of a material, you can use NovaMaterial.getLocalizedName(locale). The locale is the language code of the language you want to get the name in. The code is the same as the language code used by Minecraft.

Info

If the given language code could not be found or is invalid, the english name of the material will be returned.

Example for nova:wrench:

val name = material.getLocalizedName("de_de") // "Schraubenschlüssel"
String name = material.getLocalizedName("de_de"); // "Schraubenschlüssel"