Home Getting Started With Scripts Using this wiki Commands CTGUI Global functions Bracket Handlers
ContentTweaker Commands WalkThrough

MaterialSystem

The MaterialSystem is used to create new or retrieve existing Materials from within CT.

Importing the package

It might be required for you to import the package if you encounter any issues, so better be safe than sorry and add the import.
import mods.contenttweaker.MaterialSystem;

IPartType

Create

script.zs
createPartType(String name, IRegisterMaterialPart registerMaterialPart)

Required Parameters:

  • String name: The part type’s name → e.g. “dense_gear”
  • IRegisterMaterialPart registerMaterialPart → A function that handles how the Material parts will be created.

Retrieve

script.zs
getPartType(String name);

Required Parameters:

  • String name: The part type’s name → e.g. “gear” For a list of all available part types check the part type page.

IMaterial

Create

Unlike the PartType, you cannot directly create a Material, instead you need to use a MaterialBuilder. Check the MaterialBuilder entry for info on what exactly to do with these.

script.zs
val MB MaterialSystem.getMaterialBuilder();
MB.setName("Urubuntium");
MB.setColor(0);
MB.setHasEffect(false);
var builtMaterial = MB.build();

Retrieve

script.zs
getMaterial(String name);

Required Parameters:

  • String name: The Material’s name → e.g. “Platinum”

IPart

Create

Unlike the PartType, you cannot directly create a Part, instead you need to use a PartBuilder. Check the Part entry for info on what exactly to do with these.

script.zs
val PB = MaterialSystem.getPartBuilder();

Retrieve

script.zs
getPart(String name);

Required Parameters:

  • String name: The Part’s name

IPartDataPiece

Create

script.zs
createPartDataPiece(String name, boolean required)

Required Parameters:

  • String name: The Data Piece’s name
  • boolean required: Is the data piece required?

Register multiple MaterialParts

Even though you can also do this using the Material’s own functionality, this Method allows you to register Parts for a given Material

script.zs
registerPartsForMaterial(Material material, String[] partNames);

Required Parameters:

  • Material material: The material that the registered parts should be made of
  • String[] partNames: The names of the parts that should be registered → e.g. [“gear”, “ingot”]

Retrieve already registered things:

You can use these methods to retrieve a map using strings as keys and the object as values:

Method NameReturn Type
Method Name
getMaterialParts()
Return Type
Map<String, IMaterialPart>
Method Name
getMaterials()
Return Type
Map<String, IMaterial>
Method Name
getParts()
Return Type
Map<String, IPart>
Method Name
getPartType()
Return Type
Map<String, IPartType>
script.zs
import mods.contenttweaker.MaterialPart;
val part = MaterialSystem.getMaterialPart("name"); //as MaterialPart
val partMap = MaterialSystem.getMaterialPartsByRegex(".*"); //as MaterialPart[string]