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

walkmc.extensions.Entities.kt Maven / Gradle / Ivy

@file:Suppress("NOTHING_TO_INLINE")

package walkmc.extensions

import net.minecraft.server.*
import org.bukkit.craftbukkit.entity.*
import org.bukkit.entity.*
import org.bukkit.entity.Entity
import org.bukkit.util.*
import walkmc.serializer.tag.impl.*

/**
 * Get the craft handler of this entity.
 */
inline val Entity.craftHandler get() = this as CraftEntity

/**
 * Applies the given [block] to the storage tag of this entity.
 */
inline fun Entity.applyStorage(block: CompoundTag.() -> Unit) {
   handler.customTag = handler.customTag.apply(block)
}

/**
 * Applies and changes the velocity of this player by the specified [velo].
 */
inline fun Entity.applyVelocity(velo: Vector = velocity, block: Vector.() -> Unit) {
   velocity = velo.apply(block)
}

/**
 * Transforms this entity root tag by the specified transform.
 */
inline fun Entity.applyTag(transform: NBTTagCompound.() -> Unit) =
   handler.readFromNBT(tag.apply(transform))

/**
 * Returns if this entity is baby or not.
 */
var Entity.isBaby: Boolean
   get() = when (this) {
      is Ageable -> !isAdult
      is Zombie -> isBaby
      else -> false
   }
   set(value) = when (this) {
      is Ageable -> if (value) setBaby() else setAdult()
      is Zombie -> isBaby = value
      else -> Unit
   }

/**
 * Returns if this entity is adult or not.
 */
var Entity.isAdult: Boolean
   get() = !isBaby
   set(value) {
      isBaby = !value
   }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy