All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.chestmc.entity.EntityRegistry.kt Maven / Gradle / Ivy

package net.chestmc.entity

import net.chestmc.common.extensions.handler
import net.minecraft.server.Entity
import net.minecraft.server.EntityTypes
import net.minecraft.server.World
import org.bukkit.Location
import kotlin.reflect.KClass

/**
 * A registry used to register custom entities.
 */
object EntityRegistry {

  /**
   * Spawns a custom entity at the specified location.a
   */
  inline fun  spawn(loc: Location): T {
    return T::class.java.getConstructor(World::class.java).newInstance(loc.world.handler).apply {
      setPosition(loc.x, loc.y, loc.z)
      world.addEntity(this)
    }
  }

  /**
   * Register a new custom entity of the specified java class.
   *
   * Note that the class must be annoted with [Mob].
   */
  fun  register(value: Class) {
    val mob = value.getAnnotation(Mob::class.java) ?: error("The entity class $value is not annoted with ${Mob::class}")
    EntityTypes.c[mob.name] = value
    EntityTypes.d[value] = mob.name
    EntityTypes.f[value] = mob.type.typeId.toInt()
  }

  /**
   * Register a new custom entity of the specified kotlin class.
   *
   * Note that the class must be annoted with [Mob].
   */
  fun  register(value: KClass) = register(value.java)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy