Casts
Overview
Objects retrieved from NovoScript can be casted to higher-level objects, if they are inheriting the base object. It's similar to the way Java does it.
For example, if you have an Entity object, retrieved from mc.theWorld.getLoadedEntityList()
, you can check if the object is of type EntityLivingBase
, cast it to the higher-level object and retrieve the newly-assigned properties:
mc.theWorld.getLoadedEntityList()
.forEach((entity) => {
// Not every entity in this list is an Animal/Player/Mob!
if(entity.is('EntityLivingBase')) {
// Example: print the entity's hurt time, which is only available for
// living entities - EntitiyLivingBase
client.clientChatMessage(entity.getName() + ": " + entity.as('EntityLivingBase').hurtTime);
}
});
Required Methods
Type
Name
Description
Signature
function
as
Casts an object (T) to the object's inherit (? extends T
). Throws ClassCastException if the cast failed.
? extends T(string)
function
is
Checks if an object can be casted to a higher type.
boolean(string)
Last updated
Was this helpful?