MaterialSystem
Link to materialsystem
The MaterialSystem is used to create new or retrieve existing Materials from within CT.
Импорт пакета
Link to импорт-пакета
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;
Create
Link to create
ZenScript CopycreatePartType(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
Link to retrieve
ZenScript CopygetPartType(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.
Create
Link to create-1
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.
ZenScript Copyval MB MaterialSystem.getMaterialBuilder();
MB.setName("Urubuntium");
MB.setColor(0);
MB.setHasEffect(false);
var builtMaterial = MB.build();
Retrieve
Link to retrieve-1
ZenScript CopygetMaterial(String name);
Required Parameters:
- String name: The Material's name → e.g. "Platinum"
Create
Link to create-2
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.
ZenScript Copyval PB = MaterialSystem.getPartBuilder();
Retrieve
Link to retrieve-2
ZenScript CopygetPart(String name);
Required Parameters:
- String name: The Part's name
Create
Link to create-3
CopycreatePartDataPiece(String name, boolean required)
Required Parameters:
- String name: The Data Piece's name
- boolean required: Is the data piece required?
Register multiple MaterialParts
Link to 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
ZenScript CopyregisterPartsForMaterial(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:
Link to retrieve-already-registered-things
You can use these methods to retrieve a map using strings as keys and the object as values:
Method Name | Возвращаемый тип |
---|---|
Method Name getMaterialParts() | Возвращаемый тип Map<String, IMaterialPart> |
Method Name getMaterials() | Возвращаемый тип Map<String, IMaterial> |
Method Name getParts() | Возвращаемый тип Map<String, IPart> |
Method Name getPartType() | Возвращаемый тип Map<String, IPartType> |
Copyimport mods.contenttweaker.MaterialPart;
val part = MaterialSystem.getMaterialPart("name"); //as MaterialPart
val partMap = MaterialSystem.getMaterialPartsByRegex(".*"); //as MaterialPart[string]