Novoline
  • Main Page
  • Scripting
    • Introduction
      • Casts
      • Security
      • Globals
      • Object Members
    • Client API
    • Objects
      • Features
        • Feature Settings
      • Settings
      • Minecraft
        • Entities
        • Packets
          • Play Serverbound
          • Play Clientbound
        • MathHelper
    • Events
    • Examples
Powered by GitBook
On this page
  • Overview
  • Required Methods

Was this helpful?

  1. Scripting
  2. Introduction

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)

PreviousIntroductionNextSecurity

Last updated 3 years ago

Was this helpful?