entity.js
entity.js
/**
* All methods below return void meaning they don't require a set
return value to function.
* These mostly are similar to KubeJS' normal events where you may do
things on certain events your entities call!
*/
.tick(entity => {
if (entity.age % 100 != 0) return
})
.lavaHurt(entity => {
// Heal the entity by 20 health points
entity.heal(20);
})
.doAutoAttackOnTouch(context => {
// Attack the target entity with a damage value of 1
context.target.attack(1);
})
.ate(entity => {
// Log a message when the entity eats something
console.log(`${entity.type} just ate!`)
})
.dropCustomDeathLoot(context => {
// Drop custom loot (iron ingot) when the entity dies with a
looting multiplier of 2
if (context.lootingMultiplier == 2)
context.entity.block.popItemFromFace('minecraft:iron_ingot', 'up')
})
.eat(context => {
// Heal the entity when it eats something
context.entity.heal(20)
})
.lerpTo(context => {
const { x, y, z, yaw, pitch, entity, delta } = context;
// Set the entity's position directly to the target position if
the entity is freezing
if (entity.isFreezing()) entity.setPosition(x, y, z);
})
.onAddedToWorld(entity => {
// Teleport the entity slightly above its current position when
added to the world
let namespace = entity.getLevel().dimension.namespace
let path = entity.getLevel().dimension.path
entity.teleportTo(`${namespace}:${path}`, entity.x, entity.y + 1,
entity.z, 1, 1)
})
.onBlockedByShield(context => {
const { entity, target } = context
// Log a message when the target is blocked by a shield
console.log(`${target} Get blocked!`)
})
.onClientRemoval(entity => {
// Log a message when the entity is removed on the client side
console.log(`${entity} was removed on the client`)
})
.onDeath(context => {
// Place a diamond ore block below the entity when it dies
context.entity.block.down.set('minecraft:diamond_ore')
})
.onDecreaseAirSupply(entity => {
if (entity.age % 20 != 0) return
// Log the entity's remaining air supply when it decreases
})
.onEffectAdded(context => {
// Log the description ID of an added effect
console.log(context.effect.descriptionId)
})
.onEffectRemoved(context => {
// Log the description ID of a removed effect
console.log(context.effect.descriptionId)
})
.onEnterCombat(entity => {
// Log a message when the entity enters combat
console.log(`${entity} just entered combat`)
})
.onEquipItem(context => {
// Log the ID of the item being equipped by the entity
if (context.entity.age % 100 != 0) return
console.log(context.currentStack.id)
})
.onFlap(entity => {
// Place a gold ore block below the entity when it flaps
entity.block.down.set('minecraft:gold_ore')
})
.positionRider(context => {
const { entity, passenger, moveFunction } = context
// Position the entity with the moveFunction() method
})
.onHurt(context => {
// Log the amount of damage received by the entity
console.log(context.damageAmount)
})
.onIncreaseAirSupply(entity => {
})
.onItemPickup(context => {
// Log the ID of the item picked up by the entity
console.log(context.itemEntity.id)
})
.onLeaveCombat(entity => {
// Log a message when the entity leaves combat
console.log(`${entity} just left combat!`)
})
.onLivingFall(context => {
// Log a message when the entity falls
console.log(`${context.entity} just fell ${context.distance}
blocks!`)
})
.onLivingHeal(context => {
// Log a message when the entity heals
console.log(`${context.entity} just gained ${context.healAmount}
health!`)
})
.onLivingJump(entity => {
// Log a message when the entity jumps
console.log(`${entity} just jumped!`)
})
.onRemovedFromWorld(entity => {
// Log a message when the entity is removed from the world
console.log(`${entity} was just removed from the world!`)
})
.onSpawnChildFromBreeding(context => {
// Log a message when the entity breeds with another entity
console.log(`${context.entity} mated with ${context.mate}!
*blush*`)
})
.onSprint(entity => {
// Log a message when the entity starts sprinting
console.log(`${entity} is sprinting!`)
})
.onStartSleeping(context => {
// Log a message when the entity starts sleeping at a specific
position
console.log(`Sleeping at ${context.blockPos}`)
})
.onStopRiding(entity => {
// Drop a diamond above the entity when it stops riding
entity.block.popItemFromFace('minecraft:diamond', 'up')
})
.onStopSleeping(entity => {
// Log a message when the entity stops sleeping
console.log(`Stopped sleeping at ${entity.pos}`)
})
.onTargetChanged(context => {
//Only firing every 100 ticks to reduce log spam.
if (context.entity.age % 100 != 0) return
// Log a message when the entity's target changes
if (context.target == null) return
console.log(`${context.target} is being targeted!`)
})
.playerTouch(context => {
// Attack the player when touched by the entity
context.player.attack(1)
})
.rideTick(entity => {
// Log a message every 100 ticks if the entity is a vehicle
if (entity.age % 100 != 0) return
console.log(entity.isVehicle())
})
.thunderHit(context => {
// Heal the entity when struck by lightning
context.entity.heal(15)
})
.onTamed(entity => {
// Do stuff when the entity is tamed.
})
.tameOverride(context => {
const { entity, player } = context
// Mimic the vanilla way of setting the uuid when the entity is
tamed.
entity.setOwnerUUID(player.getUUID());
})
//Default vanilla implimentation of tickDeath removes the entity from
the world after 20 ticks
/*.tickDeath(entity => {
// Override the tickDeath method in the entity
})*/
.onInteract(context => global.interact(context))
})
/**
*
* @param {Internal.ContextUtils$MobInteractContext} context
* @returns
*/
global.interact = context => {
if (context.player.isShiftKeyDown()) return
context.player.startRiding(context.entity);
}